* [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO
@ 2026-01-05 12:42 Alice Ryhl
2026-01-05 12:42 ` [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers Alice Ryhl
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Alice Ryhl @ 2026-01-05 12:42 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Boqun Feng, Gary Guo, Peter Zijlstra,
Elle Rhumsaa, Andreas Hindborg, linux-block, FUJITA Tomonori,
Miguel Ojeda, Michael Turquette, Stephen Boyd, linux-clk,
Benno Lossin, Danilo Krummrich, Thomas Gleixner, Paul Moore,
Serge Hallyn, linux-security-module, Josh Poimboeuf, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Andrew Ballance, Andrew Morton,
Liam R. Howlett, maple-tree, linux-mm, Lorenzo Stoakes,
Uladzislau Rezki, Vitaly Wool, Rob Herring, devicetree,
Daniel Almeida, Michal Wilczynski, linux-pwm, Paul E. McKenney,
rcu, Will Deacon, Fiona Behrens, Greg Kroah-Hartman,
Vlastimil Babka, Christoph Lameter, David Rientjes, Ingo Molnar,
Waiman Long, Mitchell Levy, Frederic Weisbecker, Lyude Paul,
Anna-Maria Behnsen, John Stultz, linux-usb, Tejun Heo,
Lai Jiangshan, Matthew Wilcox, Tamir Duberstein, linux-fsdevel
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>
---
Changes in v2:
- Pick up Reviewed-by: Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>
- Update formatting in mm and slab patches.
- Add new helpers in files uaccess, pwm, and time.
- Drop any patches that have been merged.
- Link to v1: https://lore.kernel.org/r/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com
---
Alice Ryhl (27):
rust: barrier: 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: cred: add __rust_helper to helpers
rust: err: add __rust_helper to helpers
rust: jump_label: 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: processor: add __rust_helper to helpers
rust: pwm: 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: 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/barrier.c | 6 +++---
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/cred.c | 4 ++--
rust/helpers/err.c | 6 +++---
rust/helpers/jump_label.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/processor.c | 2 +-
rust/helpers/pwm.c | 6 +++---
rust/helpers/rbtree.c | 9 +++++----
rust/helpers/rcu.c | 4 ++--
rust/helpers/refcount.c | 10 +++++-----
rust/helpers/security.c | 26 +++++++++++++++-----------
rust/helpers/signal.c | 2 +-
rust/helpers/slab.c | 4 ++--
rust/helpers/spinlock.c | 13 +++++++------
rust/helpers/sync.c | 4 ++--
rust/helpers/task.c | 24 ++++++++++++------------
rust/helpers/time.c | 14 +++++++-------
rust/helpers/uaccess.c | 10 ++++++----
rust/helpers/usb.c | 3 ++-
rust/helpers/vmalloc.c | 2 +-
rust/helpers/wait.c | 2 +-
rust/helpers/workqueue.c | 8 +++++---
rust/helpers/xarray.c | 10 +++++-----
33 files changed, 136 insertions(+), 120 deletions(-)
---
base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
change-id: 20251202-define-rust-helper-f7b531813007
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers
2026-01-05 12:42 [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Alice Ryhl
@ 2026-01-05 12:42 ` Alice Ryhl
2026-01-05 15:26 ` Joel Fernandes
2026-01-05 15:41 ` [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Boqun Feng
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Alice Ryhl @ 2026-01-05 12:42 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, Alice Ryhl, Boqun Feng, Gary Guo, Paul E. McKenney,
rcu
This is needed to inline these helpers into Rust code.
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: rcu@vger.kernel.org
---
rust/helpers/rcu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/rust/helpers/rcu.c b/rust/helpers/rcu.c
index f1cec6583513497e996f74835ca2c6c3f4a8c954..481274c058577276e20093a1014fc49f4a40421b 100644
--- a/rust/helpers/rcu.c
+++ b/rust/helpers/rcu.c
@@ -2,12 +2,12 @@
#include <linux/rcupdate.h>
-void rust_helper_rcu_read_lock(void)
+__rust_helper void rust_helper_rcu_read_lock(void)
{
rcu_read_lock();
}
-void rust_helper_rcu_read_unlock(void)
+__rust_helper void rust_helper_rcu_read_unlock(void)
{
rcu_read_unlock();
}
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers
2026-01-05 12:42 ` [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers Alice Ryhl
@ 2026-01-05 15:26 ` Joel Fernandes
0 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes @ 2026-01-05 15:26 UTC (permalink / raw)
To: Alice Ryhl, rust-for-linux
Cc: linux-kernel, Boqun Feng, Gary Guo, Paul E. McKenney, rcu
On 1/5/2026 7:42 AM, Alice Ryhl wrote:
> This is needed to inline these helpers into Rust code.
>
> Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
> Reviewed-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Joel Fernandes (NVIDIA) <joel@joelfernandes.org>
Thanks.
> ---
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: rcu@vger.kernel.org
> ---
> rust/helpers/rcu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/rust/helpers/rcu.c b/rust/helpers/rcu.c
> index f1cec6583513497e996f74835ca2c6c3f4a8c954..481274c058577276e20093a1014fc49f4a40421b 100644
> --- a/rust/helpers/rcu.c
> +++ b/rust/helpers/rcu.c
> @@ -2,12 +2,12 @@
>
> #include <linux/rcupdate.h>
>
> -void rust_helper_rcu_read_lock(void)
> +__rust_helper void rust_helper_rcu_read_lock(void)
> {
> rcu_read_lock();
> }
>
> -void rust_helper_rcu_read_unlock(void)
> +__rust_helper void rust_helper_rcu_read_unlock(void)
> {
> rcu_read_unlock();
> }
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO
2026-01-05 12:42 [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2026-01-05 12:42 ` [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers Alice Ryhl
@ 2026-01-05 15:41 ` Boqun Feng
2026-01-26 5:08 ` Miguel Ojeda
2026-03-10 10:56 ` Miguel Ojeda
3 siblings, 0 replies; 6+ messages in thread
From: Boqun Feng @ 2026-01-05 15:41 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Gary Guo, Peter Zijlstra,
Elle Rhumsaa, Andreas Hindborg, linux-block, FUJITA Tomonori,
Miguel Ojeda, Michael Turquette, Stephen Boyd, linux-clk,
Benno Lossin, Danilo Krummrich, Thomas Gleixner, Paul Moore,
Serge Hallyn, linux-security-module, Josh Poimboeuf, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Andrew Ballance, Andrew Morton,
Liam R. Howlett, maple-tree, linux-mm, Lorenzo Stoakes,
Uladzislau Rezki, Vitaly Wool, Rob Herring, devicetree,
Daniel Almeida, Michal Wilczynski, linux-pwm, Paul E. McKenney,
rcu, Will Deacon, Fiona Behrens, Greg Kroah-Hartman,
Vlastimil Babka, Christoph Lameter, David Rientjes, Ingo Molnar,
Waiman Long, Mitchell Levy, Frederic Weisbecker, Lyude Paul,
Anna-Maria Behnsen, John Stultz, linux-usb, Tejun Heo,
Lai Jiangshan, Matthew Wilcox, Tamir Duberstein, linux-fsdevel
On Mon, Jan 05, 2026 at 12:42:13PM +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.
>
I queued the following into rust-sync:
rust: barrier: add __rust_helper to helpers
rust: blk: add __rust_helper to helpers
rust: completion: add __rust_helper to helpers
rust: cpu: add __rust_helper to helpers
rust: processor: add __rust_helper to helpers
rust: rcu: add __rust_helper to helpers
rust: refcount: 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: wait: add __rust_helper to helpers
Thanks!
Regards,
Boqun
> These changes were generated by adding __rust_helper and running
> ClangFormat. Unrelated formatting changes were removed manually.
>
[...]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO
2026-01-05 12:42 [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2026-01-05 12:42 ` [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers Alice Ryhl
2026-01-05 15:41 ` [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Boqun Feng
@ 2026-01-26 5:08 ` Miguel Ojeda
2026-03-10 10:56 ` Miguel Ojeda
3 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-01-26 5:08 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Boqun Feng, Gary Guo,
Peter Zijlstra, Elle Rhumsaa, Andreas Hindborg, linux-block,
FUJITA Tomonori, Miguel Ojeda, Michael Turquette, Stephen Boyd,
linux-clk, Benno Lossin, Danilo Krummrich, Thomas Gleixner,
Paul Moore, Serge Hallyn, linux-security-module, Josh Poimboeuf,
Jason Baron, Steven Rostedt, Ard Biesheuvel, Andrew Ballance,
Andrew Morton, Liam R. Howlett, maple-tree, linux-mm,
Lorenzo Stoakes, Uladzislau Rezki, Vitaly Wool, Rob Herring,
devicetree, Daniel Almeida, Michal Wilczynski, linux-pwm,
Paul E. McKenney, rcu, Will Deacon, Fiona Behrens,
Greg Kroah-Hartman, Vlastimil Babka, Christoph Lameter,
David Rientjes, Ingo Molnar, Waiman Long, Mitchell Levy,
Frederic Weisbecker, Lyude Paul, Anna-Maria Behnsen, John Stultz,
linux-usb, Tejun Heo, Lai Jiangshan, Matthew Wilcox,
Tamir Duberstein, linux-fsdevel
On Mon, Jan 5, 2026 at 1:42 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> rust: bug: add __rust_helper to helpers
> rust: err: 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: rbtree: add __rust_helper to helpers
> rust: slab: add __rust_helper to helpers
> rust: uaccess: add __rust_helper to helpers
> rust: workqueue: add __rust_helper to helpers
Applied these to `rust-next` -- thanks everyone!
If someone did not intend for me to take it even if the Acked-by is
there (e.g. perhaps Andrew wanted to pick those nevertheless?), then
please shout.
With this, and if I didn't miss any message (plus looking at
linux-next where I see Greg picked usb), then only clk and jump_label
remain (plus any new incoming one).
Let's see if we can get them done next cycle then.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO
2026-01-05 12:42 [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Alice Ryhl
` (2 preceding siblings ...)
2026-01-26 5:08 ` Miguel Ojeda
@ 2026-03-10 10:56 ` Miguel Ojeda
3 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-03-10 10:56 UTC (permalink / raw)
To: Alice Ryhl
Cc: rust-for-linux, linux-kernel, Boqun Feng, Gary Guo,
Peter Zijlstra, Elle Rhumsaa, Andreas Hindborg, linux-block,
FUJITA Tomonori, Miguel Ojeda, Michael Turquette, Stephen Boyd,
linux-clk, Benno Lossin, Danilo Krummrich, Thomas Gleixner,
Paul Moore, Serge Hallyn, linux-security-module, Josh Poimboeuf,
Jason Baron, Steven Rostedt, Ard Biesheuvel, Andrew Ballance,
Andrew Morton, Liam R. Howlett, maple-tree, linux-mm,
Lorenzo Stoakes, Uladzislau Rezki, Vitaly Wool, Rob Herring,
devicetree, Daniel Almeida, Michal Wilczynski, linux-pwm,
Paul E. McKenney, rcu, Will Deacon, Fiona Behrens,
Greg Kroah-Hartman, Vlastimil Babka, Christoph Lameter,
David Rientjes, Ingo Molnar, Waiman Long, Mitchell Levy,
Frederic Weisbecker, Lyude Paul, Anna-Maria Behnsen, John Stultz,
linux-usb, Tejun Heo, Lai Jiangshan, Matthew Wilcox,
Tamir Duberstein, linux-fsdevel
On Mon, Jan 5, 2026 at 1:42 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> rust: clk: add __rust_helper to helpers
> rust: jump_label: add __rust_helper to helpers
Applied these to `rust-next` -- thanks everyone!
With these, the series is complete.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-10 10:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05 12:42 [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Alice Ryhl
2026-01-05 12:42 ` [PATCH v2 16/27] rust: rcu: add __rust_helper to helpers Alice Ryhl
2026-01-05 15:26 ` Joel Fernandes
2026-01-05 15:41 ` [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Boqun Feng
2026-01-26 5:08 ` Miguel Ojeda
2026-03-10 10:56 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox