* [PATCH 00/46] Allow inlining C helpers into Rust when using LTO
@ 2025-12-02 19:37 Alice Ryhl
2025-12-02 19:37 ` [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Alice Ryhl @ 2025-12-02 19:37 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Greg Kroah-Hartman, Dave Ertman,
Ira Weiny, Leon Romanovsky, Peter Zijlstra, Boqun Feng,
Elle Rhumsaa, Carlos Llamas, Yury Norov, Andreas Hindborg,
linux-block, FUJITA Tomonori, Miguel Ojeda, Michael Turquette,
Stephen Boyd, linux-clk, Benno Lossin, Danilo Krummrich,
Thomas Gleixner, Rafael J. Wysocki, Viresh Kumar, linux-pm,
Paul Moore, Serge Hallyn, linux-security-module, Daniel Almeida,
Abdiel Janulgue, Robin Murphy, Lyude Paul, Alexander Viro,
Christian Brauner, Jan Kara, linux-fsdevel, Josh Poimboeuf,
Jason Baron, Steven Rostedt, Ard Biesheuvel, Brendan Higgins,
David Gow, Rae Moar, linux-kselftest, Andrew Morton,
Liam R. Howlett, Andrew Ballance, maple-tree, linux-mm,
Lorenzo Stoakes, Uladzislau Rezki, Vitaly Wool, Rob Herring,
Saravana Kannan, devicetree, Bjorn Helgaas,
Krzysztof Wilczyński, linux-pci, Remo Senekowitsch,
Paul E. McKenney, rcu, Will Deacon, Fiona Behrens, Gary Guo,
Liam Girdwood, Mark Brown, Alexandre Courbot, Vlastimil Babka,
Christoph Lameter, David Rientjes, Ingo Molnar, Waiman Long,
Mitchell Levy, Frederic Weisbecker, Anna-Maria Behnsen,
John Stultz, linux-usb, Tejun Heo, Lai Jiangshan, Matthew Wilcox,
Tamir Duberstein
This patch series adds __rust_helper to every single rust helper. The
patches do not depend on each other, so maintainers please go ahead and
pick up any patches relevant to your subsystem! Or provide your Acked-by
so that Miguel can pick them up.
These changes were generated by adding __rust_helper and running
ClangFormat. Unrelated formatting changes were removed manually.
Why is __rust_helper needed?
============================
Currently, C helpers cannot be inlined into Rust even when using LTO
because LLVM detects slightly different options on the codegen units.
* LLVM doesn't want to inline functions compiled with
`-fno-delete-null-pointer-checks` with code compiled without. The C
CGUs all have this enabled and Rust CGUs don't. Inlining is okay since
this is one of the hardening features that does not change the ABI,
and we shouldn't have null pointer dereferences in these helpers.
* LLVM doesn't want to inline functions with different list of builtins. C
side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so
they should be compatible, but LLVM does not perform inlining due to
attributes mismatch.
* clang and Rust doesn't have the exact target string. Clang generates
`+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will
complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64
always enable these features, so they are in fact the same target
string, but LLVM doesn't understand this and so inlining is inhibited.
This can be bypassed with `--ignore-tti-inline-compatible`, but this
is a hidden option.
(This analysis was written by Gary Guo.)
How is this fixed?
==================
To fix this we need to add __always_inline to all helpers when compiling
with LTO. However, it should not be added when running bindgen as
bindgen will ignore functions marked inline. To achieve this, we are
using a #define called __rust_helper that is defined differently
depending on whether bindgen is running or not.
Note that __rust_helper is currently always #defined to nothing.
Changing it to __always_inline will happen separately in another patch
series.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (46):
rust: auxiliary: add __rust_helper to helpers
rust: barrier: add __rust_helper to helpers
rust: binder: add __rust_helper to helpers
rust: bitmap: add __rust_helper to helpers
rust: bitops: add __rust_helper to helpers
rust: blk: add __rust_helper to helpers
rust: bug: add __rust_helper to helpers
rust: clk: add __rust_helper to helpers
rust: completion: add __rust_helper to helpers
rust: cpu: add __rust_helper to helpers
rust: cpufreq: add __rust_helper to helpers
rust: cpumask: add __rust_helper to helpers
rust: cred: add __rust_helper to helpers
rust: device: add __rust_helper to helpers
rust: dma: add __rust_helper to helpers
rust: drm: add __rust_helper to helpers
rust: err: add __rust_helper to helpers
rust: fs: add __rust_helper to helpers
rust: io: add __rust_helper to helpers
rust: irq: add __rust_helper to helpers
rust: jump_label: add __rust_helper to helpers
rust: kunit: add __rust_helper to helpers
rust: maple_tree: add __rust_helper to helpers
rust: mm: add __rust_helper to helpers
rust: of: add __rust_helper to helpers
rust: pci: add __rust_helper to helpers
rust: pid_namespace: add __rust_helper to helpers
rust: platform: add __rust_helper to helpers
rust: poll: add __rust_helper to helpers
rust: processor: add __rust_helper to helpers
rust: property: add __rust_helper to helpers
rust: rbtree: add __rust_helper to helpers
rust: rcu: add __rust_helper to helpers
rust: refcount: add __rust_helper to helpers
rust: regulator: add __rust_helper to helpers
rust: scatterlist: add __rust_helper to helpers
rust: security: add __rust_helper to helpers
rust: slab: add __rust_helper to helpers
rust: sync: add __rust_helper to helpers
rust: task: add __rust_helper to helpers
rust: time: add __rust_helper to helpers
rust: uaccess: add __rust_helper to helpers
rust: usb: add __rust_helper to helpers
rust: wait: add __rust_helper to helpers
rust: workqueue: add __rust_helper to helpers
rust: xarray: add __rust_helper to helpers
rust/helpers/auxiliary.c | 6 +++--
rust/helpers/barrier.c | 6 ++---
rust/helpers/binder.c | 13 ++++-----
rust/helpers/bitmap.c | 6 +++--
rust/helpers/bitops.c | 11 +++++---
rust/helpers/blk.c | 4 +--
rust/helpers/bug.c | 4 +--
rust/helpers/build_bug.c | 2 +-
rust/helpers/clk.c | 24 +++++++++--------
rust/helpers/completion.c | 2 +-
rust/helpers/cpu.c | 2 +-
rust/helpers/cpufreq.c | 3 ++-
rust/helpers/cpumask.c | 32 +++++++++++++---------
rust/helpers/cred.c | 4 +--
rust/helpers/device.c | 16 +++++------
rust/helpers/dma.c | 15 ++++++-----
rust/helpers/drm.c | 7 ++---
rust/helpers/err.c | 6 ++---
rust/helpers/fs.c | 2 +-
rust/helpers/io.c | 64 +++++++++++++++++++++++---------------------
rust/helpers/irq.c | 6 +++--
rust/helpers/jump_label.c | 2 +-
rust/helpers/kunit.c | 2 +-
rust/helpers/maple_tree.c | 3 ++-
rust/helpers/mm.c | 20 +++++++-------
rust/helpers/mutex.c | 13 ++++-----
rust/helpers/of.c | 2 +-
rust/helpers/page.c | 9 ++++---
rust/helpers/pci.c | 13 +++++----
rust/helpers/pid_namespace.c | 8 +++---
rust/helpers/platform.c | 2 +-
rust/helpers/poll.c | 5 ++--
rust/helpers/processor.c | 2 +-
rust/helpers/property.c | 2 +-
rust/helpers/rbtree.c | 5 ++--
rust/helpers/rcu.c | 4 +--
rust/helpers/refcount.c | 10 +++----
rust/helpers/regulator.c | 24 ++++++++++-------
rust/helpers/scatterlist.c | 12 +++++----
rust/helpers/security.c | 26 ++++++++++--------
rust/helpers/signal.c | 2 +-
rust/helpers/slab.c | 14 +++++-----
rust/helpers/spinlock.c | 13 ++++-----
rust/helpers/sync.c | 4 +--
rust/helpers/task.c | 24 ++++++++---------
rust/helpers/time.c | 12 ++++-----
rust/helpers/uaccess.c | 8 +++---
rust/helpers/usb.c | 3 ++-
rust/helpers/vmalloc.c | 7 ++---
rust/helpers/wait.c | 2 +-
rust/helpers/workqueue.c | 8 +++---
rust/helpers/xarray.c | 10 +++----
52 files changed, 280 insertions(+), 226 deletions(-)
---
base-commit: 54e3eae855629702c566bd2e130d9f40e7f35bde
change-id: 20251202-define-rust-helper-f7b531813007
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
@ 2025-12-02 19:37 ` Alice Ryhl
2025-12-04 21:07 ` Andrew Ballance
2025-12-02 19:37 ` [PATCH 24/46] rust: mm: " Alice Ryhl
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Alice Ryhl @ 2025-12-02 19:37 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Andrew Morton, Liam R. Howlett,
Andrew Ballance, maple-tree, linux-mm
This is needed to inline these helpers into Rust code.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Andrew Ballance <andrewjballance@gmail.com>
Cc: maple-tree@lists.infradead.org
Cc: linux-mm@kvack.org
---
rust/helpers/maple_tree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/rust/helpers/maple_tree.c b/rust/helpers/maple_tree.c
index 1dd9ac84a13feed53c0ed5eec6805517081d0673..5586486a76e0de60969af1510b4b0428392920e6 100644
--- a/rust/helpers/maple_tree.c
+++ b/rust/helpers/maple_tree.c
@@ -2,7 +2,8 @@
#include <linux/maple_tree.h>
-void rust_helper_mt_init_flags(struct maple_tree *mt, unsigned int flags)
+__rust_helper void rust_helper_mt_init_flags(struct maple_tree *mt,
+ unsigned int flags)
{
mt_init_flags(mt, flags);
}
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 24/46] rust: mm: add __rust_helper to helpers
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2025-12-02 19:37 ` [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
@ 2025-12-02 19:37 ` Alice Ryhl
2025-12-03 1:43 ` Boqun Feng
2025-12-02 19:38 ` [PATCH 46/46] rust: xarray: " Alice Ryhl
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Alice Ryhl @ 2025-12-02 19:37 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Andrew Morton, Lorenzo Stoakes,
Liam R. Howlett, Uladzislau Rezki, Vitaly Wool, linux-mm
This is needed to inline these helpers into Rust code.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Uladzislau Rezki <urezki@gmail.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.se>
Cc: linux-mm@kvack.org
---
rust/helpers/mm.c | 20 ++++++++++----------
rust/helpers/page.c | 9 +++++----
rust/helpers/vmalloc.c | 7 ++++---
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/rust/helpers/mm.c b/rust/helpers/mm.c
index 81b510c96fd2692dcb7ab4705f790bd3a41a630e..b5540997bd20d4398e2838956ed70b2fb61c5661 100644
--- a/rust/helpers/mm.c
+++ b/rust/helpers/mm.c
@@ -3,48 +3,48 @@
#include <linux/mm.h>
#include <linux/sched/mm.h>
-void rust_helper_mmgrab(struct mm_struct *mm)
+__rust_helper void rust_helper_mmgrab(struct mm_struct *mm)
{
mmgrab(mm);
}
-void rust_helper_mmdrop(struct mm_struct *mm)
+__rust_helper void rust_helper_mmdrop(struct mm_struct *mm)
{
mmdrop(mm);
}
-void rust_helper_mmget(struct mm_struct *mm)
+__rust_helper void rust_helper_mmget(struct mm_struct *mm)
{
mmget(mm);
}
-bool rust_helper_mmget_not_zero(struct mm_struct *mm)
+__rust_helper bool rust_helper_mmget_not_zero(struct mm_struct *mm)
{
return mmget_not_zero(mm);
}
-void rust_helper_mmap_read_lock(struct mm_struct *mm)
+__rust_helper void rust_helper_mmap_read_lock(struct mm_struct *mm)
{
mmap_read_lock(mm);
}
-bool rust_helper_mmap_read_trylock(struct mm_struct *mm)
+__rust_helper bool rust_helper_mmap_read_trylock(struct mm_struct *mm)
{
return mmap_read_trylock(mm);
}
-void rust_helper_mmap_read_unlock(struct mm_struct *mm)
+__rust_helper void rust_helper_mmap_read_unlock(struct mm_struct *mm)
{
mmap_read_unlock(mm);
}
-struct vm_area_struct *rust_helper_vma_lookup(struct mm_struct *mm,
- unsigned long addr)
+__rust_helper struct vm_area_struct *
+rust_helper_vma_lookup(struct mm_struct *mm, unsigned long addr)
{
return vma_lookup(mm, addr);
}
-void rust_helper_vma_end_read(struct vm_area_struct *vma)
+__rust_helper void rust_helper_vma_end_read(struct vm_area_struct *vma)
{
vma_end_read(vma);
}
diff --git a/rust/helpers/page.c b/rust/helpers/page.c
index 7144de5a61dbdb3006a668961cd1b09440e74908..f8463fbed2a2670ddfd4c23dc922b46b0913c3a2 100644
--- a/rust/helpers/page.c
+++ b/rust/helpers/page.c
@@ -4,23 +4,24 @@
#include <linux/highmem.h>
#include <linux/mm.h>
-struct page *rust_helper_alloc_pages(gfp_t gfp_mask, unsigned int order)
+__rust_helper struct page *rust_helper_alloc_pages(gfp_t gfp_mask,
+ unsigned int order)
{
return alloc_pages(gfp_mask, order);
}
-void *rust_helper_kmap_local_page(struct page *page)
+__rust_helper void *rust_helper_kmap_local_page(struct page *page)
{
return kmap_local_page(page);
}
-void rust_helper_kunmap_local(const void *addr)
+__rust_helper void rust_helper_kunmap_local(const void *addr)
{
kunmap_local(addr);
}
#ifndef NODE_NOT_IN_PAGE_FLAGS
-int rust_helper_page_to_nid(const struct page *page)
+__rust_helper int rust_helper_page_to_nid(const struct page *page)
{
return page_to_nid(page);
}
diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c
index 7d7f7336b3d2f5a32e6a2b6cf8407da37775cfd9..469ebf2f41c94744e2a2719d7c0eb7d4d7dc58ff 100644
--- a/rust/helpers/vmalloc.c
+++ b/rust/helpers/vmalloc.c
@@ -2,9 +2,10 @@
#include <linux/vmalloc.h>
-void * __must_check __realloc_size(2)
-rust_helper_vrealloc_node_align(const void *p, size_t size, unsigned long align,
- gfp_t flags, int node)
+__rust_helper void *__must_check __realloc_size(2)
+ rust_helper_vrealloc_node_align(const void *p, size_t size,
+ unsigned long align, gfp_t flags,
+ int node)
{
return vrealloc_node_align(p, size, align, flags, node);
}
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 46/46] rust: xarray: add __rust_helper to helpers
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2025-12-02 19:37 ` [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
2025-12-02 19:37 ` [PATCH 24/46] rust: mm: " Alice Ryhl
@ 2025-12-02 19:38 ` Alice Ryhl
2025-12-03 1:47 ` [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Boqun Feng
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Alice Ryhl @ 2025-12-02 19:38 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Andrew Morton, Matthew Wilcox,
Tamir Duberstein, Andreas Hindborg, linux-fsdevel, linux-mm
This is needed to inline these helpers into Rust code.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Tamir Duberstein <tamird@gmail.com>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
---
rust/helpers/xarray.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/helpers/xarray.c b/rust/helpers/xarray.c
index 60b299f11451d2c4a75e50e25dec4dac13f143f4..08979b3043410ff89d2adc0b2597825115c5100f 100644
--- a/rust/helpers/xarray.c
+++ b/rust/helpers/xarray.c
@@ -2,27 +2,27 @@
#include <linux/xarray.h>
-int rust_helper_xa_err(void *entry)
+__rust_helper int rust_helper_xa_err(void *entry)
{
return xa_err(entry);
}
-void rust_helper_xa_init_flags(struct xarray *xa, gfp_t flags)
+__rust_helper void rust_helper_xa_init_flags(struct xarray *xa, gfp_t flags)
{
return xa_init_flags(xa, flags);
}
-int rust_helper_xa_trylock(struct xarray *xa)
+__rust_helper int rust_helper_xa_trylock(struct xarray *xa)
{
return xa_trylock(xa);
}
-void rust_helper_xa_lock(struct xarray *xa)
+__rust_helper void rust_helper_xa_lock(struct xarray *xa)
{
return xa_lock(xa);
}
-void rust_helper_xa_unlock(struct xarray *xa)
+__rust_helper void rust_helper_xa_unlock(struct xarray *xa)
{
return xa_unlock(xa);
}
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 24/46] rust: mm: add __rust_helper to helpers
2025-12-02 19:37 ` [PATCH 24/46] rust: mm: " Alice Ryhl
@ 2025-12-03 1:43 ` Boqun Feng
2025-12-03 9:03 ` Alice Ryhl
0 siblings, 1 reply; 10+ messages in thread
From: Boqun Feng @ 2025-12-03 1:43 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Andrew Morton, Lorenzo Stoakes,
Liam R. Howlett, Uladzislau Rezki, Vitaly Wool, linux-mm
On Tue, Dec 02, 2025 at 07:37:48PM +0000, Alice Ryhl wrote:
> This is needed to inline these helpers into Rust code.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
[...]
> --- a/rust/helpers/vmalloc.c
> +++ b/rust/helpers/vmalloc.c
> @@ -2,9 +2,10 @@
>
> #include <linux/vmalloc.h>
>
> -void * __must_check __realloc_size(2)
> -rust_helper_vrealloc_node_align(const void *p, size_t size, unsigned long align,
> - gfp_t flags, int node)
> +__rust_helper void *__must_check __realloc_size(2)
> + rust_helper_vrealloc_node_align(const void *p, size_t size,
The indent here seems to be incorrect?
Regards,
Boqun
> + unsigned long align, gfp_t flags,
> + int node)
> {
> return vrealloc_node_align(p, size, align, flags, node);
> }
>
> --
> 2.52.0.158.g65b55ccf14-goog
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 00/46] Allow inlining C helpers into Rust when using LTO
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
` (2 preceding siblings ...)
2025-12-02 19:38 ` [PATCH 46/46] rust: xarray: " Alice Ryhl
@ 2025-12-03 1:47 ` Boqun Feng
2025-12-03 14:33 ` Gary Guo
2025-12-04 10:05 ` (subset) " Christian Brauner
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-12-03 1:47 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Greg Kroah-Hartman, Dave Ertman,
Ira Weiny, Leon Romanovsky, Peter Zijlstra, Elle Rhumsaa,
Carlos Llamas, Yury Norov, Andreas Hindborg, linux-block,
FUJITA Tomonori, Miguel Ojeda, Michael Turquette, Stephen Boyd,
linux-clk, Benno Lossin, Danilo Krummrich, Thomas Gleixner,
Rafael J. Wysocki, Viresh Kumar, linux-pm, Paul Moore,
Serge Hallyn, linux-security-module, Daniel Almeida,
Abdiel Janulgue, Robin Murphy, Lyude Paul, Alexander Viro,
Christian Brauner, Jan Kara, linux-fsdevel, Josh Poimboeuf,
Jason Baron, Steven Rostedt, Ard Biesheuvel, Brendan Higgins,
David Gow, Rae Moar, linux-kselftest, Andrew Morton,
Liam R. Howlett, Andrew Ballance, maple-tree, linux-mm,
Lorenzo Stoakes, Uladzislau Rezki, Vitaly Wool, Rob Herring,
Saravana Kannan, devicetree, Bjorn Helgaas,
Krzysztof Wilczy´nski, linux-pci, Remo Senekowitsch,
Paul E. McKenney, rcu, Will Deacon, Fiona Behrens, Gary Guo,
Liam Girdwood, Mark Brown, Alexandre Courbot, Vlastimil Babka,
Christoph Lameter, David Rientjes, Ingo Molnar, Waiman Long,
Mitchell Levy, Frederic Weisbecker, Anna-Maria Behnsen,
John Stultz, linux-usb, Tejun Heo, Lai Jiangshan, Matthew Wilcox,
Tamir Duberstein
On Tue, Dec 02, 2025 at 07:37:24PM +0000, Alice Ryhl wrote:
> This patch series adds __rust_helper to every single rust helper. The
> patches do not depend on each other, so maintainers please go ahead and
> pick up any patches relevant to your subsystem! Or provide your Acked-by
> so that Miguel can pick them up.
>
> These changes were generated by adding __rust_helper and running
> ClangFormat. Unrelated formatting changes were removed manually.
>
> Why is __rust_helper needed?
> ============================
>
> Currently, C helpers cannot be inlined into Rust even when using LTO
> because LLVM detects slightly different options on the codegen units.
>
> * LLVM doesn't want to inline functions compiled with
> `-fno-delete-null-pointer-checks` with code compiled without. The C
> CGUs all have this enabled and Rust CGUs don't. Inlining is okay since
> this is one of the hardening features that does not change the ABI,
> and we shouldn't have null pointer dereferences in these helpers.
>
> * LLVM doesn't want to inline functions with different list of builtins. C
> side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so
> they should be compatible, but LLVM does not perform inlining due to
> attributes mismatch.
>
> * clang and Rust doesn't have the exact target string. Clang generates
> `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will
> complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64
> always enable these features, so they are in fact the same target
> string, but LLVM doesn't understand this and so inlining is inhibited.
> This can be bypassed with `--ignore-tti-inline-compatible`, but this
> is a hidden option.
>
> (This analysis was written by Gary Guo.)
>
> How is this fixed?
> ==================
>
> To fix this we need to add __always_inline to all helpers when compiling
> with LTO. However, it should not be added when running bindgen as
> bindgen will ignore functions marked inline. To achieve this, we are
> using a #define called __rust_helper that is defined differently
> depending on whether bindgen is running or not.
>
> Note that __rust_helper is currently always #defined to nothing.
> Changing it to __always_inline will happen separately in another patch
> series.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
For the whole series:
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> ---
[...]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 24/46] rust: mm: add __rust_helper to helpers
2025-12-03 1:43 ` Boqun Feng
@ 2025-12-03 9:03 ` Alice Ryhl
0 siblings, 0 replies; 10+ messages in thread
From: Alice Ryhl @ 2025-12-03 9:03 UTC (permalink / raw)
To: Boqun Feng
Cc: rust-for-linux, linux-kernel, Andrew Morton, Lorenzo Stoakes,
Liam R. Howlett, Uladzislau Rezki, Vitaly Wool, linux-mm
On Tue, Dec 02, 2025 at 05:43:10PM -0800, Boqun Feng wrote:
> On Tue, Dec 02, 2025 at 07:37:48PM +0000, Alice Ryhl wrote:
> > This is needed to inline these helpers into Rust code.
> >
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > ---
> [...]
> > --- a/rust/helpers/vmalloc.c
> > +++ b/rust/helpers/vmalloc.c
> > @@ -2,9 +2,10 @@
> >
> > #include <linux/vmalloc.h>
> >
> > -void * __must_check __realloc_size(2)
> > -rust_helper_vrealloc_node_align(const void *p, size_t size, unsigned long align,
> > - gfp_t flags, int node)
> > +__rust_helper void *__must_check __realloc_size(2)
> > + rust_helper_vrealloc_node_align(const void *p, size_t size,
>
> The indent here seems to be incorrect?
This is what I got from ClangFormat, but your suggestion does look
better, so I'll update it.
Alice
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 00/46] Allow inlining C helpers into Rust when using LTO
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
` (3 preceding siblings ...)
2025-12-03 1:47 ` [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Boqun Feng
@ 2025-12-03 14:33 ` Gary Guo
2025-12-04 10:05 ` (subset) " Christian Brauner
5 siblings, 0 replies; 10+ messages in thread
From: Gary Guo @ 2025-12-03 14:33 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Greg Kroah-Hartman, Dave Ertman,
Ira Weiny, Leon Romanovsky, Peter Zijlstra, Boqun Feng,
Elle Rhumsaa, Carlos Llamas, Yury Norov, Andreas Hindborg,
linux-block, FUJITA Tomonori, Miguel Ojeda, Michael Turquette,
Stephen Boyd, linux-clk, Benno Lossin, Danilo Krummrich,
Thomas Gleixner, Rafael J. Wysocki, Viresh Kumar, linux-pm,
Paul Moore, Serge Hallyn, linux-security-module, Daniel Almeida,
Abdiel Janulgue, Robin Murphy, Lyude Paul, Alexander Viro,
Christian Brauner, Jan Kara, linux-fsdevel, Josh Poimboeuf,
Jason Baron, Steven Rostedt, Ard Biesheuvel, Brendan Higgins,
David Gow, Rae Moar, linux-kselftest, Andrew Morton,
Liam R. Howlett, Andrew Ballance, maple-tree, linux-mm,
Lorenzo Stoakes, Uladzislau Rezki, Vitaly Wool, Rob Herring,
Saravana Kannan, devicetree, Bjorn Helgaas,
Krzysztof Wilczyński, linux-pci, Remo Senekowitsch,
Paul E. McKenney, rcu, Will Deacon, Fiona Behrens, Liam Girdwood,
Mark Brown, Alexandre Courbot, Vlastimil Babka,
Christoph Lameter, David Rientjes, Ingo Molnar, Waiman Long,
Mitchell Levy, Frederic Weisbecker, Anna-Maria Behnsen,
John Stultz, linux-usb, Tejun Heo, Lai Jiangshan, Matthew Wilcox,
Tamir Duberstein
On Tue, 02 Dec 2025 19:37:24 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> This patch series adds __rust_helper to every single rust helper. The
> patches do not depend on each other, so maintainers please go ahead and
> pick up any patches relevant to your subsystem! Or provide your Acked-by
> so that Miguel can pick them up.
>
> These changes were generated by adding __rust_helper and running
> ClangFormat. Unrelated formatting changes were removed manually.
>
> Why is __rust_helper needed?
> ============================
>
> Currently, C helpers cannot be inlined into Rust even when using LTO
> because LLVM detects slightly different options on the codegen units.
>
> * LLVM doesn't want to inline functions compiled with
> `-fno-delete-null-pointer-checks` with code compiled without. The C
> CGUs all have this enabled and Rust CGUs don't. Inlining is okay since
> this is one of the hardening features that does not change the ABI,
> and we shouldn't have null pointer dereferences in these helpers.
>
> * LLVM doesn't want to inline functions with different list of builtins. C
> side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so
> they should be compatible, but LLVM does not perform inlining due to
> attributes mismatch.
>
> * clang and Rust doesn't have the exact target string. Clang generates
> `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will
> complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64
> always enable these features, so they are in fact the same target
> string, but LLVM doesn't understand this and so inlining is inhibited.
> This can be bypassed with `--ignore-tti-inline-compatible`, but this
> is a hidden option.
>
> (This analysis was written by Gary Guo.)
>
> How is this fixed?
> ==================
>
> To fix this we need to add __always_inline to all helpers when compiling
> with LTO. However, it should not be added when running bindgen as
> bindgen will ignore functions marked inline. To achieve this, we are
> using a #define called __rust_helper that is defined differently
> depending on whether bindgen is running or not.
>
> Note that __rust_helper is currently always #defined to nothing.
> Changing it to __always_inline will happen separately in another patch
> series.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> Alice Ryhl (46):
> rust: auxiliary: add __rust_helper to helpers
> rust: barrier: add __rust_helper to helpers
> rust: binder: add __rust_helper to helpers
> rust: bitmap: add __rust_helper to helpers
> rust: bitops: add __rust_helper to helpers
> rust: blk: add __rust_helper to helpers
> rust: bug: add __rust_helper to helpers
> rust: clk: add __rust_helper to helpers
> rust: completion: add __rust_helper to helpers
> rust: cpu: add __rust_helper to helpers
> rust: cpufreq: add __rust_helper to helpers
> rust: cpumask: add __rust_helper to helpers
> rust: cred: add __rust_helper to helpers
> rust: device: add __rust_helper to helpers
> rust: dma: add __rust_helper to helpers
> rust: drm: add __rust_helper to helpers
> rust: err: add __rust_helper to helpers
> rust: fs: add __rust_helper to helpers
> rust: io: add __rust_helper to helpers
> rust: irq: add __rust_helper to helpers
> rust: jump_label: add __rust_helper to helpers
> rust: kunit: add __rust_helper to helpers
> rust: maple_tree: add __rust_helper to helpers
> rust: mm: add __rust_helper to helpers
> rust: of: add __rust_helper to helpers
> rust: pci: add __rust_helper to helpers
> rust: pid_namespace: add __rust_helper to helpers
> rust: platform: add __rust_helper to helpers
> rust: poll: add __rust_helper to helpers
> rust: processor: add __rust_helper to helpers
> rust: property: add __rust_helper to helpers
> rust: rbtree: add __rust_helper to helpers
> rust: rcu: add __rust_helper to helpers
> rust: refcount: add __rust_helper to helpers
> rust: regulator: add __rust_helper to helpers
> rust: scatterlist: add __rust_helper to helpers
> rust: security: add __rust_helper to helpers
> rust: slab: add __rust_helper to helpers
> rust: sync: add __rust_helper to helpers
> rust: task: add __rust_helper to helpers
> rust: time: add __rust_helper to helpers
> rust: uaccess: add __rust_helper to helpers
> rust: usb: add __rust_helper to helpers
> rust: wait: add __rust_helper to helpers
> rust: workqueue: add __rust_helper to helpers
> rust: xarray: add __rust_helper to helpers
Thansk for sending this Alice! With this series in first, my series for
inlining helpers should be much easier to apply.
For the whole series:
Reviewed-by: Gary Guo <gary@garyguo.net>
Best,
Gary
>
> rust/helpers/auxiliary.c | 6 +++--
> rust/helpers/barrier.c | 6 ++---
> rust/helpers/binder.c | 13 ++++-----
> rust/helpers/bitmap.c | 6 +++--
> rust/helpers/bitops.c | 11 +++++---
> rust/helpers/blk.c | 4 +--
> rust/helpers/bug.c | 4 +--
> rust/helpers/build_bug.c | 2 +-
> rust/helpers/clk.c | 24 +++++++++--------
> rust/helpers/completion.c | 2 +-
> rust/helpers/cpu.c | 2 +-
> rust/helpers/cpufreq.c | 3 ++-
> rust/helpers/cpumask.c | 32 +++++++++++++---------
> rust/helpers/cred.c | 4 +--
> rust/helpers/device.c | 16 +++++------
> rust/helpers/dma.c | 15 ++++++-----
> rust/helpers/drm.c | 7 ++---
> rust/helpers/err.c | 6 ++---
> rust/helpers/fs.c | 2 +-
> rust/helpers/io.c | 64 +++++++++++++++++++++++---------------------
> rust/helpers/irq.c | 6 +++--
> rust/helpers/jump_label.c | 2 +-
> rust/helpers/kunit.c | 2 +-
> rust/helpers/maple_tree.c | 3 ++-
> rust/helpers/mm.c | 20 +++++++-------
> rust/helpers/mutex.c | 13 ++++-----
> rust/helpers/of.c | 2 +-
> rust/helpers/page.c | 9 ++++---
> rust/helpers/pci.c | 13 +++++----
> rust/helpers/pid_namespace.c | 8 +++---
> rust/helpers/platform.c | 2 +-
> rust/helpers/poll.c | 5 ++--
> rust/helpers/processor.c | 2 +-
> rust/helpers/property.c | 2 +-
> rust/helpers/rbtree.c | 5 ++--
> rust/helpers/rcu.c | 4 +--
> rust/helpers/refcount.c | 10 +++----
> rust/helpers/regulator.c | 24 ++++++++++-------
> rust/helpers/scatterlist.c | 12 +++++----
> rust/helpers/security.c | 26 ++++++++++--------
> rust/helpers/signal.c | 2 +-
> rust/helpers/slab.c | 14 +++++-----
> rust/helpers/spinlock.c | 13 ++++-----
> rust/helpers/sync.c | 4 +--
> rust/helpers/task.c | 24 ++++++++---------
> rust/helpers/time.c | 12 ++++-----
> rust/helpers/uaccess.c | 8 +++---
> rust/helpers/usb.c | 3 ++-
> rust/helpers/vmalloc.c | 7 ++---
> rust/helpers/wait.c | 2 +-
> rust/helpers/workqueue.c | 8 +++---
> rust/helpers/xarray.c | 10 +++----
> 52 files changed, 280 insertions(+), 226 deletions(-)
> ---
> base-commit: 54e3eae855629702c566bd2e130d9f40e7f35bde
> change-id: 20251202-define-rust-helper-f7b531813007
>
> Best regards,
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: (subset) [PATCH 00/46] Allow inlining C helpers into Rust when using LTO
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
` (4 preceding siblings ...)
2025-12-03 14:33 ` Gary Guo
@ 2025-12-04 10:05 ` Christian Brauner
5 siblings, 0 replies; 10+ messages in thread
From: Christian Brauner @ 2025-12-04 10:05 UTC (permalink / raw)
To: Alice Ryhl
Cc: Christian Brauner, linux-kernel, Greg Kroah-Hartman, Dave Ertman,
Ira Weiny, Leon Romanovsky, Peter Zijlstra, Boqun Feng,
Elle Rhumsaa, Carlos Llamas, Yury Norov, Andreas Hindborg,
linux-block, FUJITA Tomonori, Miguel Ojeda, Michael Turquette,
Stephen Boyd, linux-clk, Benno Lossin, Danilo Krummrich,
Thomas Gleixner, Rafael J. Wysocki, Viresh Kumar, linux-pm,
Paul Moore, Serge Hallyn, linux-security-module, Daniel Almeida,
Abdiel Janulgue, Robin Murphy, Lyude Paul, Alexander Viro,
Jan Kara, linux-fsdevel, Josh Poimboeuf, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Brendan Higgins, David Gow,
linux-kselftest, Andrew Morton, Liam R. Howlett, Andrew Ballance,
maple-tree, linux-mm, Lorenzo Stoakes, Uladzislau Rezki,
Vitaly Wool, Rob Herring, Saravana Kannan, devicetree,
Bjorn Helgaas, Krzysztof Wilczyński, linux-pci,
Remo Senekowitsch, Paul E. McKenney, rcu, Will Deacon,
Fiona Behrens, Gary Guo, Liam Girdwood, Mark Brown,
Alexandre Courbot, Vlastimil Babka, Christoph Lameter,
David Rientjes, Ingo Molnar, Waiman Long, Mitchell Levy,
Frederic Weisbecker, Anna-Maria Behnsen, John Stultz, linux-usb,
Tejun Heo, Lai Jiangshan, Matthew Wilcox, Tamir Duberstein,
Rae Moar, rust-for-linux
On Tue, 02 Dec 2025 19:37:24 +0000, Alice Ryhl wrote:
> This patch series adds __rust_helper to every single rust helper. The
> patches do not depend on each other, so maintainers please go ahead and
> pick up any patches relevant to your subsystem! Or provide your Acked-by
> so that Miguel can pick them up.
>
> These changes were generated by adding __rust_helper and running
> ClangFormat. Unrelated formatting changes were removed manually.
>
> [...]
Applied to the vfs-6.20.rust branch of the vfs/vfs.git tree.
Patches in the vfs-6.20.rust branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.20.rust
[18/46] rust: fs: add __rust_helper to helpers
https://git.kernel.org/vfs/vfs/c/02c444cc60e5
[27/46] rust: pid_namespace: add __rust_helper to helpers
https://git.kernel.org/vfs/vfs/c/f28a178408e4
[29/46] rust: poll: add __rust_helper to helpers
https://git.kernel.org/vfs/vfs/c/de98ed59d678
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers
2025-12-02 19:37 ` [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
@ 2025-12-04 21:07 ` Andrew Ballance
0 siblings, 0 replies; 10+ messages in thread
From: Andrew Ballance @ 2025-12-04 21:07 UTC (permalink / raw)
To: Alice Ryhl, rust-for-linux
Cc: linux-kernel, Andrew Morton, Liam R. Howlett, maple-tree, linux-mm
On 12/2/25 1:37 PM, Alice Ryhl wrote:
> This is needed to inline these helpers into Rust code.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
> Cc: Andrew Ballance <andrewjballance@gmail.com>
> Cc: maple-tree@lists.infradead.org
> Cc: linux-mm@kvack.org
> ---
> rust/helpers/maple_tree.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/rust/helpers/maple_tree.c b/rust/helpers/maple_tree.c
> index 1dd9ac84a13feed53c0ed5eec6805517081d0673..5586486a76e0de60969af1510b4b0428392920e6 100644
> --- a/rust/helpers/maple_tree.c
> +++ b/rust/helpers/maple_tree.c
> @@ -2,7 +2,8 @@
>
> #include <linux/maple_tree.h>
>
> -void rust_helper_mt_init_flags(struct maple_tree *mt, unsigned int flags)
> +__rust_helper void rust_helper_mt_init_flags(struct maple_tree *mt,
> + unsigned int flags)
> {
> mt_init_flags(mt, flags);
> }
>
Acked-by: Andrew Ballance <andrewjballance@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-12-04 21:07 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-02 19:37 [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2025-12-02 19:37 ` [PATCH 23/46] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
2025-12-04 21:07 ` Andrew Ballance
2025-12-02 19:37 ` [PATCH 24/46] rust: mm: " Alice Ryhl
2025-12-03 1:43 ` Boqun Feng
2025-12-03 9:03 ` Alice Ryhl
2025-12-02 19:38 ` [PATCH 46/46] rust: xarray: " Alice Ryhl
2025-12-03 1:47 ` [PATCH 00/46] Allow inlining C helpers into Rust when using LTO Boqun Feng
2025-12-03 14:33 ` Gary Guo
2025-12-04 10:05 ` (subset) " Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox