linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Alice Ryhl <aliceryhl@google.com>,
	 Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
	 Peter Zijlstra <peterz@infradead.org>,
	Elle Rhumsaa <elle@weathered-steel.dev>,
	 Andreas Hindborg <a.hindborg@kernel.org>,
	linux-block@vger.kernel.org,
	 FUJITA Tomonori <fujita.tomonori@gmail.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	 Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-clk@vger.kernel.org,  Benno Lossin <lossin@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	 Thomas Gleixner <tglx@linutronix.de>,
	Paul Moore <paul@paul-moore.com>,
	 Serge Hallyn <sergeh@kernel.org>,
	linux-security-module@vger.kernel.org,
	 Josh Poimboeuf <jpoimboe@kernel.org>,
	Jason Baron <jbaron@akamai.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	 Andrew Ballance <andrewjballance@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	maple-tree@lists.infradead.org,  linux-mm@kvack.org,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	 Uladzislau Rezki <urezki@gmail.com>,
	Vitaly Wool <vitaly.wool@konsulko.se>,
	 Rob Herring <robh@kernel.org>,
	devicetree@vger.kernel.org,
	 Daniel Almeida <daniel.almeida@collabora.com>,
	Michal Wilczynski <m.wilczynski@samsung.com>,
	 linux-pwm@vger.kernel.org,
	"Paul E. McKenney" <paulmck@kernel.org>,
	rcu@vger.kernel.org,  Will Deacon <will@kernel.org>,
	Fiona Behrens <me@kloenk.dev>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	 Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Ingo Molnar <mingo@redhat.com>,  Waiman Long <longman@redhat.com>,
	Mitchell Levy <levymitchell0@gmail.com>,
	 Frederic Weisbecker <frederic@kernel.org>,
	Lyude Paul <lyude@redhat.com>,
	 Anna-Maria Behnsen <anna-maria@linutronix.de>,
	John Stultz <jstultz@google.com>,
	linux-usb@vger.kernel.org,  Tejun Heo <tj@kernel.org>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	 Matthew Wilcox <willy@infradead.org>,
	Tamir Duberstein <tamird@gmail.com>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO
Date: Mon, 05 Jan 2026 12:42:13 +0000	[thread overview]
Message-ID: <20260105-define-rust-helper-v2-0-51da5f454a67@google.com> (raw)

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>



             reply	other threads:[~2026-01-05 12:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 12:42 Alice Ryhl [this message]
2026-01-05 12:42 ` [PATCH v2 10/27] rust: maple_tree: add __rust_helper to helpers Alice Ryhl
2026-01-05 15:09   ` Liam R. Howlett
2026-01-05 12:42 ` [PATCH v2 11/27] rust: mm: " Alice Ryhl
2026-01-05 15:10   ` Liam R. Howlett
2026-01-05 15:22     ` Lorenzo Stoakes
2026-01-05 12:42 ` [PATCH v2 27/27] rust: xarray: " Alice Ryhl
2026-01-05 15:26   ` Tamir Duberstein
2026-01-05 15:41 ` [PATCH v2 00/27] Allow inlining C helpers into Rust when using LTO Boqun Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260105-define-rust-helper-v2-0-51da5f454a67@google.com \
    --to=aliceryhl@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=a.hindborg@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrewjballance@gmail.com \
    --cc=anna-maria@linutronix.de \
    --cc=ardb@kernel.org \
    --cc=boqun.feng@gmail.com \
    --cc=cl@gentwo.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=elle@weathered-steel.dev \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbaron@akamai.com \
    --cc=jiangshanlai@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=jstultz@google.com \
    --cc=levymitchell0@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=m.wilczynski@samsung.com \
    --cc=maple-tree@lists.infradead.org \
    --cc=me@kloenk.dev \
    --cc=mingo@redhat.com \
    --cc=mturquette@baylibre.com \
    --cc=ojeda@kernel.org \
    --cc=paul@paul-moore.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=sergeh@kernel.org \
    --cc=tamird@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=vitaly.wool@konsulko.se \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox