public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Inline helpers into Rust without full LTO
@ 2026-02-03 11:34 Alice Ryhl
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
                   ` (4 more replies)
  0 siblings, 5 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-02-03 11:34 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Alice Ryhl,
	Matthew Maurer

Currently the only way for Rust code to call a static inline function is
to go through a helper in rust/helpers/. This introduces performance
costs due to additional function calls and also clutters backtraces and
flame graphs with helper symbols.

To get rid of these helper symbols, provide functionality to inline
helpers into Rust using llvm-link. This option complements full LTO, by
being much cheaper and avoiding incompatibility with BTF.

I ran a microbenchmark showing the benefit of this. All the benchmark
does is call refcount_inc() in a loop. This was chosen since refcounting
is quite hot in Binder. The results are that Rust spends 6.35 ns per
call vs 5.73 ns per call in C. When enabling this option, the two
languages become equally fast, and disassembly confirms the exact same
machine code is used (in particular there is no call to
rust_helper_refcount_inc). Benchmarking Binder also results in an
improvement from this change.

This patch is complementary to:
https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com/

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v2:
- Dropped merged patches.
- Generate two copies of helpers.bc, one for built-in and one for modules.
- Remove unused llvm-as tool.
- Add $(cmd_ld_single) to avoid breaking CONFIG_LTO builds (note that
  LTO does not happen over the language boundary, except for helpers).
- Improve Kconfig help message.
- Link to v1: https://lore.kernel.org/r/20251202-inline-helpers-v1-0-879dae33a66a@google.com

---
Gary Guo (3):
      kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
      rust: helpers: #define __rust_helper
      build: rust: provide an option to inline C helpers into Rust

 Makefile               |  3 ++-
 init/Kconfig           | 15 +++++++++++++++
 lib/Kconfig.debug      | 15 +++++++++++++++
 rust/Makefile          | 29 +++++++++++++++++++++++++----
 rust/exports.c         |  5 ++++-
 rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++
 scripts/Makefile.build |  7 ++++++-
 7 files changed, 96 insertions(+), 7 deletions(-)
---
base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215
change-id: 20251202-inline-helpers-996f4db65e18

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>



^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
@ 2026-02-03 11:34 ` Alice Ryhl
  2026-02-03 11:49   ` Will Deacon
                     ` (2 more replies)
  2026-02-03 11:34 ` [PATCH v2 2/3] rust: helpers: #define __rust_helper Alice Ryhl
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-02-03 11:34 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Alice Ryhl,
	Matthew Maurer

From: Gary Guo <gary@garyguo.net>

This config detects if Rust and Clang have matching LLVM major version.
All IR or bitcode operations (e.g. LTO) rely on LLVM major version to be
matching, otherwise it may generate errors, or worse, miscompile
silently due to change of IR semantics.

It's usually suggested to use the exact same LLVM version, but this can
be difficult to guarantee. Rust's suggestion [1] is also major-version
only, so I think this check is sufficient for the kernel.

Link: https://doc.rust-lang.org/rustc/linker-plugin-lto.html [1]
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 init/Kconfig | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index e95d43457851862afc8313389777e4dd9348c178..0e900d3d8be7874a33e0f44754a8d038e68d7e65 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
 	int
 	default $(rustc-llvm-version)
 
+config RUSTC_LLVM_MAJOR_VERSION
+	int
+	default $(shell,expr $(rustc-llvm-version) / 10000)
+
+config RUSTC_CLANG_LLVM_COMPATIBLE
+	bool
+	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
+	help
+	  This indicates whether Rust and Clang use LLVM of the same major
+	  version.
+
+	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
+	  LTO) requires the same LLVM major version to work properly. For best
+	  compatibility it is recommended that the exact same LLVM is used.
+
 config ARCH_HAS_CC_CAN_LINK
 	bool
 

-- 
2.53.0.rc1.225.gd81095ad13-goog



^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 2/3] rust: helpers: #define __rust_helper
  2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
@ 2026-02-03 11:34 ` Alice Ryhl
  2026-03-14  0:28   ` Nathan Chancellor
  2026-02-03 11:34 ` [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust Alice Ryhl
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 40+ messages in thread
From: Alice Ryhl @ 2026-02-03 11:34 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Alice Ryhl

From: Gary Guo <gary@garyguo.net>

Because of LLVM inling checks, it's generally not possible to inline a C
helper into Rust code, even with LTO:

* 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.

To fix this, we can add __always_inline on every helper, which skips
these LLVM inlining checks. For this purpose, introduce a new
__rust_helper macro that needs to be added to every helper.

Most helpers already have __rust_helper specified, but there are a few
missing. The only consequence of this is that those specific helpers do
not get inlined.

Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index a3c42e51f00a0990bea81ebce6e99bb397ce7533..e05c6e7e4abb7e6a4c4a3a417e35022dac1d9c58 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -7,7 +7,36 @@
  * Sorted alphabetically.
  */
 
+#include <linux/compiler_types.h>
+
+#ifdef __BINDGEN__
+// Omit `inline` for bindgen as it ignores inline functions.
 #define __rust_helper
+#else
+// The helper functions are all inline functions.
+//
+// We use `__always_inline` here to bypass LLVM inlining checks, in case the
+// helpers are inlined directly into Rust CGUs.
+//
+// The LLVM inlining checks are false positives:
+// * 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.
+#define __rust_helper __always_inline
+#endif
 
 #include "atomic.c"
 #include "atomic_ext.c"

-- 
2.53.0.rc1.225.gd81095ad13-goog



^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
  2026-02-03 11:34 ` [PATCH v2 2/3] rust: helpers: #define __rust_helper Alice Ryhl
@ 2026-02-03 11:34 ` Alice Ryhl
  2026-03-06 17:32   ` Alice Ryhl
  2026-03-14  0:34   ` Nathan Chancellor
  2026-03-17  8:25 ` [PATCH v2 0/3] Inline helpers into Rust without full LTO Andreas Hindborg
  2026-03-22 19:21 ` Miguel Ojeda
  4 siblings, 2 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-02-03 11:34 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Alice Ryhl,
	Matthew Maurer

From: Gary Guo <gary@garyguo.net>

A new experimental Kconfig option, `RUST_INLINE_HELPERS` is added to
allow C helpers (which were created to allow Rust to call into
inline/macro C functions without having to re-implement the logic in
Rust) to be inlined into Rust crates without performing global LTO.

If the option is enabled, the following is performed:
* For helpers, instead of compiling them to an object file to be linked
  into vmlinux, they're compiled to LLVM IR bitcode. Two versions are
  generated: one for built-in code (`helpers.bc`) and one for modules
  (`helpers_module.bc`, with -DMODULE defined). This ensures that C
  macros/inlines that behave differently for modules (e.g. static calls)
  function correctly when inlined.
* When a Rust crate or object is compiled, instead of generating an
  object file, LLVM bitcode is generated.
* llvm-link is invoked with --internalize to combine the helper bitcode
  with the crate bitcode. This step is similar to LTO, but this is much
  faster since it only needs to inline the helpers.
* clang is invoked to turn the combined bitcode into a final object file.
* Since clang may produce LLVM bitcode when LTO is enabled, and objtool
  requires ELF input, $(cmd_ld_single) is invoked to ensure the object
  is converted to ELF before objtool runs.

The --internalize flag tells llvm-link to treat all symbols in
helpers.bc using `internal` linkage [1]. This matches the behavior of
`clang` on `static inline` functions, and avoids exporting the symbol
from the object file.

To ensure that RUST_INLINE_HELPERS is not incompatible with BTF, we pass
the -g0 flag when building helpers. See commit 5daa0c35a1f0 ("rust:
Disallow BTF generation with Rust + LTO") for details.

We have an intended triple mismatch of `aarch64-unknown-none` vs
`aarch64-unknown-linux-gnu`, so we pass --suppress-warnings to llvm-link
to suppress it.

We add $(cmd_ld_single) before $(cmd_objtool). Otherwise objtool fails
to parse the resulting files as Elf when CONFIG_LTO is enabled.

I considered adding some sort of check that KBUILD_MODNAME is not
present in helpers_module.bc, but this is actually not so easy to carry
out because .bc files store strings in a weird binary format, so you
cannot just grep it for a string to check whether it ended up using
KBUILD_MODNAME anywhere.

Link: https://github.com/llvm/llvm-project/pull/170397 [1]
Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Co-developed-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Gary Guo <gary@garyguo.net>
Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 Makefile               |  3 ++-
 lib/Kconfig.debug      | 15 +++++++++++++++
 rust/Makefile          | 29 +++++++++++++++++++++++++----
 rust/exports.c         |  5 ++++-
 scripts/Makefile.build |  7 ++++++-
 5 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index c97f06ee0dda1c922aa23bd5249052591d528eb6..155db03cf489d931eefdb4bd7e3b93e5aa3ea2d6 100644
--- a/Makefile
+++ b/Makefile
@@ -519,6 +519,7 @@ OBJCOPY		= $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
 OBJDUMP		= $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
 READELF		= $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
 STRIP		= $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
+LLVM_LINK	= $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)
 else
 CC		= $(CROSS_COMPILE)gcc
 LD		= $(CROSS_COMPILE)ld
@@ -627,7 +628,7 @@ export RUSTC_BOOTSTRAP := 1
 export CLIPPY_CONF_DIR := $(srctree)
 
 export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
-export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
+export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINK
 export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
 export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
 export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 7570a694d54e6170ae6738634218b37e38a4b76a..c44c08b49f3a3c2e06fca42adeb9e04304e7a869 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -3551,6 +3551,21 @@ config RUST_KERNEL_DOCTESTS
 
 	  If unsure, say N.
 
+config RUST_INLINE_HELPERS
+	bool "Inline C helpers into Rust code"
+	depends on RUST && RUSTC_CLANG_LLVM_COMPATIBLE
+	depends on EXPERT
+	help
+	  Inlines C helpers into Rust code using Link Time Optimization.
+
+	  If this option is enabled, C helper functions declared in
+	  rust/helpers/ are inlined into Rust code, which is helpful for
+	  performance of Rust code. This requires a matching LLVM version for
+	  Clang and rustc.
+
+	  If you are sure that you're using Clang and rustc with matching LLVM
+	  versions, say Y. Otherwise say N.
+
 endmenu # "Rust"
 
 endmenu # Kernel hacking
diff --git a/rust/Makefile b/rust/Makefile
index 63464bd2c1e9734cd6e659f7ee3db58bf995d6dd..a6839f2d39feefcfea497384ae202a7c6b475942 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -6,15 +6,19 @@ rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
 obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
 always-$(CONFIG_RUST) += exports_core_generated.h
 
+ifdef CONFIG_RUST_INLINE_HELPERS
+always-$(CONFIG_RUST) += helpers/helpers.bc helpers/helpers_module.bc
+else
+obj-$(CONFIG_RUST) += helpers/helpers.o
+always-$(CONFIG_RUST) += exports_helpers_generated.h
+endif
 # Missing prototypes are expected in the helpers since these are exported
 # for Rust only, thus there is no header nor prototypes.
-obj-$(CONFIG_RUST) += helpers/helpers.o
 CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
 
 always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
 obj-$(CONFIG_RUST) += bindings.o pin_init.o kernel.o
-always-$(CONFIG_RUST) += exports_helpers_generated.h \
-    exports_bindings_generated.h exports_kernel_generated.h
+always-$(CONFIG_RUST) += exports_bindings_generated.h exports_kernel_generated.h
 
 always-$(CONFIG_RUST) += uapi/uapi_generated.rs
 obj-$(CONFIG_RUST) += uapi.o
@@ -480,6 +484,14 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ;
 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
 	$(call if_changed_dep,bindgen)
 
+quiet_cmd_rust_helper = HELPER  $@
+      cmd_rust_helper = \
+	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
+		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
+
+$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
+	+$(call if_changed_dep,rust_helper)
+
 rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(pfx|cfi|odr_asan)/ { printf $(2),$$3 }'
 
 quiet_cmd_exports = EXPORTS $@
@@ -561,12 +573,16 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
 	OBJTREE=$(abspath $(objtree)) \
 	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
 		$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
-		--emit=dep-info=$(depfile) --emit=obj=$@ \
+		--emit=dep-info=$(depfile) --emit=$(if $(link_helper),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) \
 		--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
 		--crate-type rlib -L$(objtree)/$(obj) \
 		--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
 		--sysroot=/dev/null \
+	$(if $(link_helper),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
+		$(obj)/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
+		$(CC) $(CLANG_FLAGS) $(KBUILD_CFLAGS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@) \
 	$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
+	$(cmd_ld_single) \
 	$(cmd_objtool)
 
 rust-analyzer:
@@ -696,4 +712,9 @@ $(obj)/kernel.o: $(obj)/kernel/generated_arch_warn_asm.rs $(obj)/kernel/generate
 endif
 endif
 
+ifdef CONFIG_RUST_INLINE_HELPERS
+$(obj)/kernel.o: private link_helper = 1
+$(obj)/kernel.o: $(obj)/helpers/helpers.bc
+endif
+
 endif # CONFIG_RUST
diff --git a/rust/exports.c b/rust/exports.c
index 587f0e776aba52854080f15aa91094b55996c072..1b52460b0f4eeef6df9081abb9b7e054a28c3c21 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -16,10 +16,13 @@
 #define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
 
 #include "exports_core_generated.h"
-#include "exports_helpers_generated.h"
 #include "exports_bindings_generated.h"
 #include "exports_kernel_generated.h"
 
+#ifndef CONFIG_RUST_INLINE_HELPERS
+#include "exports_helpers_generated.h"
+#endif
+
 // For modules using `rust/build_error.rs`.
 #ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
 EXPORT_SYMBOL_RUST_GPL(rust_build_error);
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 0c838c467c764e14a51ad132444544373e90a84c..7176d997ecab7c3ffd1e00400a8a79a8309485e1 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -343,7 +343,12 @@ rust_common_cmd = \
 # would not match each other.
 
 quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
-      cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
+      cmd_rustc_o_rs = $(rust_common_cmd) --emit=$(if $(CONFIG_RUST_INLINE_HELPERS),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) $< \
+	$(if $(CONFIG_RUST_INLINE_HELPERS),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
+		$(objtree)/rust/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
+		$(CC) $(CLANG_FLAGS) $(KBUILD_CFLAGS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@) \
+	$(cmd_ld_single) \
+	$(cmd_objtool)
 
 define rule_rustc_o_rs
 	$(call cmd_and_fixdep,rustc_o_rs)

-- 
2.53.0.rc1.225.gd81095ad13-goog



^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
@ 2026-02-03 11:49   ` Will Deacon
  2026-02-03 12:02     ` Alice Ryhl
  2026-03-05 10:12   ` Nicolas Schier
  2026-03-14  0:26   ` Nathan Chancellor
  2 siblings, 1 reply; 40+ messages in thread
From: Will Deacon @ 2026-02-03 11:49 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Matthew Maurer, elver

On Tue, Feb 03, 2026 at 11:34:08AM +0000, Alice Ryhl wrote:
> From: Gary Guo <gary@garyguo.net>
> 
> This config detects if Rust and Clang have matching LLVM major version.
> All IR or bitcode operations (e.g. LTO) rely on LLVM major version to be
> matching, otherwise it may generate errors, or worse, miscompile
> silently due to change of IR semantics.
> 
> It's usually suggested to use the exact same LLVM version, but this can
> be difficult to guarantee. Rust's suggestion [1] is also major-version
> only, so I think this check is sufficient for the kernel.
> 
> Link: https://doc.rust-lang.org/rustc/linker-plugin-lto.html [1]
> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  init/Kconfig | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index e95d43457851862afc8313389777e4dd9348c178..0e900d3d8be7874a33e0f44754a8d038e68d7e65 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
>  	int
>  	default $(rustc-llvm-version)
>  
> +config RUSTC_LLVM_MAJOR_VERSION
> +	int
> +	default $(shell,expr $(rustc-llvm-version) / 10000)
> +
> +config RUSTC_CLANG_LLVM_COMPATIBLE
> +	bool
> +	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
> +	help
> +	  This indicates whether Rust and Clang use LLVM of the same major
> +	  version.
> +
> +	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
> +	  LTO) requires the same LLVM major version to work properly. For best
> +	  compatibility it is recommended that the exact same LLVM is used.

Is cross-language LTO something we're actually looking at doing for the
kernel, or is this just stale help text given what you're using it for
in this series?

Will


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-02-03 11:49   ` Will Deacon
@ 2026-02-03 12:02     ` Alice Ryhl
  0 siblings, 0 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-02-03 12:02 UTC (permalink / raw)
  To: Will Deacon
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Matthew Maurer, elver

On Tue, Feb 03, 2026 at 11:49:08AM +0000, Will Deacon wrote:
> On Tue, Feb 03, 2026 at 11:34:08AM +0000, Alice Ryhl wrote:
> > From: Gary Guo <gary@garyguo.net>
> > 
> > This config detects if Rust and Clang have matching LLVM major version.
> > All IR or bitcode operations (e.g. LTO) rely on LLVM major version to be
> > matching, otherwise it may generate errors, or worse, miscompile
> > silently due to change of IR semantics.
> > 
> > It's usually suggested to use the exact same LLVM version, but this can
> > be difficult to guarantee. Rust's suggestion [1] is also major-version
> > only, so I think this check is sufficient for the kernel.
> > 
> > Link: https://doc.rust-lang.org/rustc/linker-plugin-lto.html [1]
> > Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> > Signed-off-by: Gary Guo <gary@garyguo.net>
> > Signed-off-by: Matthew Maurer <mmaurer@google.com>
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > ---
> >  init/Kconfig | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> > 
> > diff --git a/init/Kconfig b/init/Kconfig
> > index e95d43457851862afc8313389777e4dd9348c178..0e900d3d8be7874a33e0f44754a8d038e68d7e65 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
> >  	int
> >  	default $(rustc-llvm-version)
> >  
> > +config RUSTC_LLVM_MAJOR_VERSION
> > +	int
> > +	default $(shell,expr $(rustc-llvm-version) / 10000)
> > +
> > +config RUSTC_CLANG_LLVM_COMPATIBLE
> > +	bool
> > +	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
> > +	help
> > +	  This indicates whether Rust and Clang use LLVM of the same major
> > +	  version.
> > +
> > +	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
> > +	  LTO) requires the same LLVM major version to work properly. For best
> > +	  compatibility it is recommended that the exact same LLVM is used.
> 
> Is cross-language LTO something we're actually looking at doing for the
> kernel, or is this just stale help text given what you're using it for
> in this series?

I would like to see CONFIG_LTO actually perform cross-language inlining,
but it'd require doing something about both:

1. The issues mentioned in patch 2 of this series.
2. The issues mentioned in commit 5daa0c35a1f0 ("rust: Disallow BTF
   generation with Rust + LTO").

As for whether it's stale help text ... CONFIG_RUST_INLINE_HELPERS works
by performing cross-language LTO too. But I can see your point that it
would make sense to improve this wording given that we're not making
CONFIG_LTO work now.

Alice


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
  2026-02-03 11:49   ` Will Deacon
@ 2026-03-05 10:12   ` Nicolas Schier
  2026-03-05 10:51     ` Alice Ryhl
  2026-03-14  0:26   ` Nathan Chancellor
  2 siblings, 1 reply; 40+ messages in thread
From: Nicolas Schier @ 2026-03-05 10:12 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Matthew Maurer

On Tue, 03 Feb 2026 11:34:08 +0000, Alice Ryhl <aliceryhl@google.com> wrote:
> This config detects if Rust and Clang have matching LLVM major version.
> All IR or bitcode operations (e.g. LTO) rely on LLVM major version to be
> matching, otherwise it may generate errors, or worse, miscompile
> silently due to change of IR semantics.
> 
> It's usually suggested to use the exact same LLVM version, but this can
> be difficult to guarantee. Rust's suggestion [1] is also major-version
> only, so I think this check is sufficient for the kernel.
> 
> Link: https://doc.rust-lang.org/rustc/linker-plugin-lto.html [1]
> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> 
> ---
>  init/Kconfig | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index fa79feb8fe57..06f6b23c9fde 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
>  	int
>  	default $(rustc-llvm-version)
>  
> +config RUSTC_LLVM_MAJOR_VERSION
> +	int
> +	default $(shell,expr $(rustc-llvm-version) / 10000)
> +
> +config RUSTC_CLANG_LLVM_COMPATIBLE
> +	bool
> +	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
> +	help
> +	  This indicates whether Rust and Clang use LLVM of the same major
> +	  version.
> +
> +	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
> +	  LTO) requires the same LLVM major version to work properly. For best
> +	  compatibility it is recommended that the exact same LLVM is used.
> +
>  config ARCH_HAS_CC_CAN_LINK
>  	bool
>

Reviewed-by: Nicolas Schier <nsc@kernel.org>
Tested-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-03-05 10:12   ` Nicolas Schier
@ 2026-03-05 10:51     ` Alice Ryhl
  0 siblings, 0 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-03-05 10:51 UTC (permalink / raw)
  To: Nicolas Schier
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Matthew Maurer

On Thu, Mar 05, 2026 at 11:12:59AM +0100, Nicolas Schier wrote:
> Reviewed-by: Nicolas Schier <nsc@kernel.org>
> Tested-by: Nicolas Schier <nsc@kernel.org>

Thanks!


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-02-03 11:34 ` [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust Alice Ryhl
@ 2026-03-06 17:32   ` Alice Ryhl
  2026-03-14  0:40     ` Nathan Chancellor
  2026-03-14  0:34   ` Nathan Chancellor
  1 sibling, 1 reply; 40+ messages in thread
From: Alice Ryhl @ 2026-03-06 17:32 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Nicolas Schier, Andrew Morton, Uladzislau Rezki, rust-for-linux,
	linux-kernel, llvm, linux-kbuild, linux-mm, Matthew Maurer

On Tue, Feb 03, 2026 at 11:34:10AM +0000, Alice Ryhl wrote:
>  $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
>  	$(call if_changed_dep,bindgen)
>  
> +quiet_cmd_rust_helper = HELPER  $@
> +      cmd_rust_helper = \
> +	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
> +		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
> +
> +$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
> +	+$(call if_changed_dep,rust_helper)

I think this needs:

$(obj)/helpers/helpers.bc: private part-of-builtin := y
$(obj)/helpers/helpers_module.bc: private part-of-module := y

at least it seems to make a difference for AutoFDO.

Alice


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`
  2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
  2026-02-03 11:49   ` Will Deacon
  2026-03-05 10:12   ` Nicolas Schier
@ 2026-03-14  0:26   ` Nathan Chancellor
  2 siblings, 0 replies; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-14  0:26 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm, Matthew Maurer

On Tue, Feb 03, 2026 at 11:34:08AM +0000, Alice Ryhl wrote:
> From: Gary Guo <gary@garyguo.net>
> 
> This config detects if Rust and Clang have matching LLVM major version.
> All IR or bitcode operations (e.g. LTO) rely on LLVM major version to be
> matching, otherwise it may generate errors, or worse, miscompile
> silently due to change of IR semantics.
> 
> It's usually suggested to use the exact same LLVM version, but this can
> be difficult to guarantee. Rust's suggestion [1] is also major-version
> only, so I think this check is sufficient for the kernel.
> 
> Link: https://doc.rust-lang.org/rustc/linker-plugin-lto.html [1]
> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> Signed-off-by: Aliee Ryhl <aliceryhl@google.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  init/Kconfig | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index e95d43457851862afc8313389777e4dd9348c178..0e900d3d8be7874a33e0f44754a8d038e68d7e65 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
>  	int
>  	default $(rustc-llvm-version)
>  
> +config RUSTC_LLVM_MAJOR_VERSION
> +	int
> +	default $(shell,expr $(rustc-llvm-version) / 10000)
> +
> +config RUSTC_CLANG_LLVM_COMPATIBLE
> +	bool
> +	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
> +	help
> +	  This indicates whether Rust and Clang use LLVM of the same major
> +	  version.
> +
> +	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
> +	  LTO) requires the same LLVM major version to work properly. For best
> +	  compatibility it is recommended that the exact same LLVM is used.
> +
>  config ARCH_HAS_CC_CAN_LINK
>  	bool
>  
> 
> -- 
> 2.53.0.rc1.225.gd81095ad13-goog
> 


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 2/3] rust: helpers: #define __rust_helper
  2026-02-03 11:34 ` [PATCH v2 2/3] rust: helpers: #define __rust_helper Alice Ryhl
@ 2026-03-14  0:28   ` Nathan Chancellor
  0 siblings, 0 replies; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-14  0:28 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm

On Tue, Feb 03, 2026 at 11:34:09AM +0000, Alice Ryhl wrote:
> From: Gary Guo <gary@garyguo.net>
> 
> Because of LLVM inling checks, it's generally not possible to inline a C
> helper into Rust code, even with LTO:
> 
> * 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.
> 
> To fix this, we can add __always_inline on every helper, which skips
> these LLVM inlining checks. For this purpose, introduce a new
> __rust_helper macro that needs to be added to every helper.
> 
> Most helpers already have __rust_helper specified, but there are a few
> missing. The only consequence of this is that those specific helpers do
> not get inlined.
> 
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

>  rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
> index a3c42e51f00a0990bea81ebce6e99bb397ce7533..e05c6e7e4abb7e6a4c4a3a417e35022dac1d9c58 100644
> --- a/rust/helpers/helpers.c
> +++ b/rust/helpers/helpers.c
> @@ -7,7 +7,36 @@
>   * Sorted alphabetically.
>   */
>  
> +#include <linux/compiler_types.h>
> +
> +#ifdef __BINDGEN__
> +// Omit `inline` for bindgen as it ignores inline functions.
>  #define __rust_helper
> +#else
> +// The helper functions are all inline functions.
> +//
> +// We use `__always_inline` here to bypass LLVM inlining checks, in case the
> +// helpers are inlined directly into Rust CGUs.
> +//
> +// The LLVM inlining checks are false positives:
> +// * 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.
> +#define __rust_helper __always_inline
> +#endif
>  
>  #include "atomic.c"
>  #include "atomic_ext.c"
> 
> -- 
> 2.53.0.rc1.225.gd81095ad13-goog
> 


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-02-03 11:34 ` [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust Alice Ryhl
  2026-03-06 17:32   ` Alice Ryhl
@ 2026-03-14  0:34   ` Nathan Chancellor
  1 sibling, 0 replies; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-14  0:34 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm, Matthew Maurer

On Tue, Feb 03, 2026 at 11:34:10AM +0000, Alice Ryhl wrote:
> From: Gary Guo <gary@garyguo.net>
> 
> A new experimental Kconfig option, `RUST_INLINE_HELPERS` is added to
> allow C helpers (which were created to allow Rust to call into
> inline/macro C functions without having to re-implement the logic in
> Rust) to be inlined into Rust crates without performing global LTO.
> 
> If the option is enabled, the following is performed:
> * For helpers, instead of compiling them to an object file to be linked
>   into vmlinux, they're compiled to LLVM IR bitcode. Two versions are
>   generated: one for built-in code (`helpers.bc`) and one for modules
>   (`helpers_module.bc`, with -DMODULE defined). This ensures that C
>   macros/inlines that behave differently for modules (e.g. static calls)
>   function correctly when inlined.
> * When a Rust crate or object is compiled, instead of generating an
>   object file, LLVM bitcode is generated.
> * llvm-link is invoked with --internalize to combine the helper bitcode
>   with the crate bitcode. This step is similar to LTO, but this is much
>   faster since it only needs to inline the helpers.
> * clang is invoked to turn the combined bitcode into a final object file.
> * Since clang may produce LLVM bitcode when LTO is enabled, and objtool
>   requires ELF input, $(cmd_ld_single) is invoked to ensure the object
>   is converted to ELF before objtool runs.
> 
> The --internalize flag tells llvm-link to treat all symbols in
> helpers.bc using `internal` linkage [1]. This matches the behavior of
> `clang` on `static inline` functions, and avoids exporting the symbol
> from the object file.
> 
> To ensure that RUST_INLINE_HELPERS is not incompatible with BTF, we pass
> the -g0 flag when building helpers. See commit 5daa0c35a1f0 ("rust:
> Disallow BTF generation with Rust + LTO") for details.
> 
> We have an intended triple mismatch of `aarch64-unknown-none` vs
> `aarch64-unknown-linux-gnu`, so we pass --suppress-warnings to llvm-link
> to suppress it.
> 
> We add $(cmd_ld_single) before $(cmd_objtool). Otherwise objtool fails
> to parse the resulting files as Elf when CONFIG_LTO is enabled.

You mention this as the last bullet point above, so this paragraph can
probably be dropped.

> I considered adding some sort of check that KBUILD_MODNAME is not
> present in helpers_module.bc, but this is actually not so easy to carry
> out because .bc files store strings in a weird binary format, so you
> cannot just grep it for a string to check whether it ended up using
> KBUILD_MODNAME anywhere.
> 
> Link: https://github.com/llvm/llvm-project/pull/170397 [1]
> Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Co-developed-by: Matthew Maurer <mmaurer@google.com>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Co-developed-by: Alice Ryhl <aliceryhl@google.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  Makefile               |  3 ++-
>  lib/Kconfig.debug      | 15 +++++++++++++++
>  rust/Makefile          | 29 +++++++++++++++++++++++++----
>  rust/exports.c         |  5 ++++-
>  scripts/Makefile.build |  7 ++++++-
>  5 files changed, 52 insertions(+), 7 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index c97f06ee0dda1c922aa23bd5249052591d528eb6..155db03cf489d931eefdb4bd7e3b93e5aa3ea2d6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -519,6 +519,7 @@ OBJCOPY		= $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
>  OBJDUMP		= $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
>  READELF		= $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
>  STRIP		= $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
> +LLVM_LINK	= $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)

I don't have a strong preference but this could be alphabetized among
the binutils variables.

>  else
>  CC		= $(CROSS_COMPILE)gcc
>  LD		= $(CROSS_COMPILE)ld
> @@ -627,7 +628,7 @@ export RUSTC_BOOTSTRAP := 1
>  export CLIPPY_CONF_DIR := $(srctree)
>  
>  export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
> -export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
> +export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINK
>  export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
>  export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
>  export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 7570a694d54e6170ae6738634218b37e38a4b76a..c44c08b49f3a3c2e06fca42adeb9e04304e7a869 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -3551,6 +3551,21 @@ config RUST_KERNEL_DOCTESTS
>  
>  	  If unsure, say N.
>  
> +config RUST_INLINE_HELPERS
> +	bool "Inline C helpers into Rust code"
> +	depends on RUST && RUSTC_CLANG_LLVM_COMPATIBLE
> +	depends on EXPERT
> +	help
> +	  Inlines C helpers into Rust code using Link Time Optimization.
> +
> +	  If this option is enabled, C helper functions declared in
> +	  rust/helpers/ are inlined into Rust code, which is helpful for
> +	  performance of Rust code. This requires a matching LLVM version for
> +	  Clang and rustc.
> +
> +	  If you are sure that you're using Clang and rustc with matching LLVM
> +	  versions, say Y. Otherwise say N.
> +
>  endmenu # "Rust"
>  
>  endmenu # Kernel hacking
> diff --git a/rust/Makefile b/rust/Makefile
> index 63464bd2c1e9734cd6e659f7ee3db58bf995d6dd..a6839f2d39feefcfea497384ae202a7c6b475942 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -6,15 +6,19 @@ rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
>  obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
>  always-$(CONFIG_RUST) += exports_core_generated.h
>  
> +ifdef CONFIG_RUST_INLINE_HELPERS
> +always-$(CONFIG_RUST) += helpers/helpers.bc helpers/helpers_module.bc
> +else
> +obj-$(CONFIG_RUST) += helpers/helpers.o
> +always-$(CONFIG_RUST) += exports_helpers_generated.h
> +endif
>  # Missing prototypes are expected in the helpers since these are exported
>  # for Rust only, thus there is no header nor prototypes.
> -obj-$(CONFIG_RUST) += helpers/helpers.o
>  CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
>  
>  always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
>  obj-$(CONFIG_RUST) += bindings.o pin_init.o kernel.o
> -always-$(CONFIG_RUST) += exports_helpers_generated.h \
> -    exports_bindings_generated.h exports_kernel_generated.h
> +always-$(CONFIG_RUST) += exports_bindings_generated.h exports_kernel_generated.h
>  
>  always-$(CONFIG_RUST) += uapi/uapi_generated.rs
>  obj-$(CONFIG_RUST) += uapi.o
> @@ -480,6 +484,14 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ;
>  $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
>  	$(call if_changed_dep,bindgen)
>  
> +quiet_cmd_rust_helper = HELPER  $@
> +      cmd_rust_helper = \
> +	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
> +		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
> +
> +$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
> +	+$(call if_changed_dep,rust_helper)
> +
>  rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(pfx|cfi|odr_asan)/ { printf $(2),$$3 }'
>  
>  quiet_cmd_exports = EXPORTS $@
> @@ -561,12 +573,16 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
>  	OBJTREE=$(abspath $(objtree)) \
>  	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
>  		$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
> -		--emit=dep-info=$(depfile) --emit=obj=$@ \
> +		--emit=dep-info=$(depfile) --emit=$(if $(link_helper),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) \
>  		--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
>  		--crate-type rlib -L$(objtree)/$(obj) \
>  		--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
>  		--sysroot=/dev/null \
> +	$(if $(link_helper),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
> +		$(obj)/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
> +		$(CC) $(CLANG_FLAGS) $(KBUILD_CFLAGS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@) \
>  	$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
> +	$(cmd_ld_single) \
>  	$(cmd_objtool)
>  
>  rust-analyzer:
> @@ -696,4 +712,9 @@ $(obj)/kernel.o: $(obj)/kernel/generated_arch_warn_asm.rs $(obj)/kernel/generate
>  endif
>  endif
>  
> +ifdef CONFIG_RUST_INLINE_HELPERS
> +$(obj)/kernel.o: private link_helper = 1
> +$(obj)/kernel.o: $(obj)/helpers/helpers.bc
> +endif
> +
>  endif # CONFIG_RUST
> diff --git a/rust/exports.c b/rust/exports.c
> index 587f0e776aba52854080f15aa91094b55996c072..1b52460b0f4eeef6df9081abb9b7e054a28c3c21 100644
> --- a/rust/exports.c
> +++ b/rust/exports.c
> @@ -16,10 +16,13 @@
>  #define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
>  
>  #include "exports_core_generated.h"
> -#include "exports_helpers_generated.h"
>  #include "exports_bindings_generated.h"
>  #include "exports_kernel_generated.h"
>  
> +#ifndef CONFIG_RUST_INLINE_HELPERS
> +#include "exports_helpers_generated.h"
> +#endif
> +
>  // For modules using `rust/build_error.rs`.
>  #ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
>  EXPORT_SYMBOL_RUST_GPL(rust_build_error);
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 0c838c467c764e14a51ad132444544373e90a84c..7176d997ecab7c3ffd1e00400a8a79a8309485e1 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -343,7 +343,12 @@ rust_common_cmd = \
>  # would not match each other.
>  
>  quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
> -      cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
> +      cmd_rustc_o_rs = $(rust_common_cmd) --emit=$(if $(CONFIG_RUST_INLINE_HELPERS),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) $< \
> +	$(if $(CONFIG_RUST_INLINE_HELPERS),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
> +		$(objtree)/rust/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
> +		$(CC) $(CLANG_FLAGS) $(KBUILD_CFLAGS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@) \
> +	$(cmd_ld_single) \
> +	$(cmd_objtool)
>  
>  define rule_rustc_o_rs
>  	$(call cmd_and_fixdep,rustc_o_rs)
> 
> -- 
> 2.53.0.rc1.225.gd81095ad13-goog
> 


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-03-06 17:32   ` Alice Ryhl
@ 2026-03-14  0:40     ` Nathan Chancellor
  2026-03-14 11:22       ` Alice Ryhl
  0 siblings, 1 reply; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-14  0:40 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm, Matthew Maurer

On Fri, Mar 06, 2026 at 05:32:33PM +0000, Alice Ryhl wrote:
> On Tue, Feb 03, 2026 at 11:34:10AM +0000, Alice Ryhl wrote:
> >  $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
> >  	$(call if_changed_dep,bindgen)
> >  
> > +quiet_cmd_rust_helper = HELPER  $@
> > +      cmd_rust_helper = \
> > +	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
> > +		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
> > +
> > +$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
> > +	+$(call if_changed_dep,rust_helper)
> 
> I think this needs:
> 
> $(obj)/helpers/helpers.bc: private part-of-builtin := y
> $(obj)/helpers/helpers_module.bc: private part-of-module := y
> 
> at least it seems to make a difference for AutoFDO.

Would

  $(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: private is-kernel-object := y

work as well? Presumably, this is because c_flags only has the AutoFDO
flags when is-kernel-object is set, which is only true when
helpers/helpers.o is a part of obj-y.

Cheers,
Nathan


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-03-14  0:40     ` Nathan Chancellor
@ 2026-03-14 11:22       ` Alice Ryhl
  2026-03-16 21:34         ` Nathan Chancellor
  0 siblings, 1 reply; 40+ messages in thread
From: Alice Ryhl @ 2026-03-14 11:22 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm, Matthew Maurer

On Fri, Mar 13, 2026 at 05:40:12PM -0700, Nathan Chancellor wrote:
> On Fri, Mar 06, 2026 at 05:32:33PM +0000, Alice Ryhl wrote:
> > On Tue, Feb 03, 2026 at 11:34:10AM +0000, Alice Ryhl wrote:
> > >  $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
> > >  	$(call if_changed_dep,bindgen)
> > >  
> > > +quiet_cmd_rust_helper = HELPER  $@
> > > +      cmd_rust_helper = \
> > > +	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
> > > +		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
> > > +
> > > +$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
> > > +	+$(call if_changed_dep,rust_helper)
> > 
> > I think this needs:
> > 
> > $(obj)/helpers/helpers.bc: private part-of-builtin := y
> > $(obj)/helpers/helpers_module.bc: private part-of-module := y
> > 
> > at least it seems to make a difference for AutoFDO.
> 
> Would
> 
>   $(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: private is-kernel-object := y
> 
> work as well? Presumably, this is because c_flags only has the AutoFDO
> flags when is-kernel-object is set, which is only true when
> helpers/helpers.o is a part of obj-y.

I assume so, but isn't it more correct to set part-of-builtin and
part-of-module? I don't see any make rules making use of those directly
(instead of is-kernel-object) right now, but if someone adds such uses,
then this could become wrong, right?

Alice


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-03-14 11:22       ` Alice Ryhl
@ 2026-03-16 21:34         ` Nathan Chancellor
  2026-03-17  8:02           ` Miguel Ojeda
  0 siblings, 1 reply; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-16 21:34 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Alexandre Courbot, Will Deacon, Peter Zijlstra, Mark Rutland,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
	Andrew Morton, Uladzislau Rezki, rust-for-linux, linux-kernel,
	llvm, linux-kbuild, linux-mm, Matthew Maurer

On Sat, Mar 14, 2026 at 11:22:17AM +0000, Alice Ryhl wrote:
> On Fri, Mar 13, 2026 at 05:40:12PM -0700, Nathan Chancellor wrote:
> > On Fri, Mar 06, 2026 at 05:32:33PM +0000, Alice Ryhl wrote:
> > > On Tue, Feb 03, 2026 at 11:34:10AM +0000, Alice Ryhl wrote:
> > > >  $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
> > > >  	$(call if_changed_dep,bindgen)
> > > >  
> > > > +quiet_cmd_rust_helper = HELPER  $@
> > > > +      cmd_rust_helper = \
> > > > +	$(CC) $(filter-out $(CFLAGS_REMOVE_helpers/helpers.o), $(c_flags)) \
> > > > +		-c -g0 $< $(if $(filter %_module.bc,$@),-DMODULE) -emit-llvm -o $@
> > > > +
> > > > +$(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: $(src)/helpers/helpers.c FORCE
> > > > +	+$(call if_changed_dep,rust_helper)
> > > 
> > > I think this needs:
> > > 
> > > $(obj)/helpers/helpers.bc: private part-of-builtin := y
> > > $(obj)/helpers/helpers_module.bc: private part-of-module := y
> > > 
> > > at least it seems to make a difference for AutoFDO.
> > 
> > Would
> > 
> >   $(obj)/helpers/helpers.bc $(obj)/helpers/helpers_module.bc: private is-kernel-object := y
> > 
> > work as well? Presumably, this is because c_flags only has the AutoFDO
> > flags when is-kernel-object is set, which is only true when
> > helpers/helpers.o is a part of obj-y.
> 
> I assume so, but isn't it more correct to set part-of-builtin and
> part-of-module? I don't see any make rules making use of those directly
> (instead of is-kernel-object) right now, but if someone adds such uses,
> then this could become wrong, right?

Hmmm, yeah, I suppose so. Actually, adding those would allow you to drop
the manual inclusion of -DMODULE in cmd_rust_helper because it will be
included via modkern_cflags.

Cheers,
Nathan


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust
  2026-03-16 21:34         ` Nathan Chancellor
@ 2026-03-17  8:02           ` Miguel Ojeda
  0 siblings, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-17  8:02 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Alice Ryhl, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Alexandre Courbot, Will Deacon,
	Peter Zijlstra, Mark Rutland, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Nicolas Schier, Andrew Morton, Uladzislau Rezki,
	rust-for-linux, linux-kernel, llvm, linux-kbuild, linux-mm,
	Matthew Maurer

On Mon, Mar 16, 2026 at 10:34 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Hmmm, yeah, I suppose so. Actually, adding those would allow you to drop
> the manual inclusion of -DMODULE in cmd_rust_helper because it will be
> included via modkern_cflags.

Yeah, a week ago I asked Alice about simplifying to `is-kernel-object`
as well (mostly because I used it elsewhere in our `Makefile` in the
past), but similarly I ended up thinking that if we are OK using
directly `part-of-*`, then it would be better anyway.

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
                   ` (2 preceding siblings ...)
  2026-02-03 11:34 ` [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust Alice Ryhl
@ 2026-03-17  8:25 ` Andreas Hindborg
  2026-03-22 19:21 ` Miguel Ojeda
  4 siblings, 0 replies; 40+ messages in thread
From: Andreas Hindborg @ 2026-03-17  8:25 UTC (permalink / raw)
  To: Alice Ryhl, Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Trevor Gross, Danilo Krummrich, Alexandre Courbot, Will Deacon,
	Peter Zijlstra, Mark Rutland, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Nicolas Schier, Andrew Morton,
	Uladzislau Rezki, rust-for-linux, linux-kernel, llvm,
	linux-kbuild, linux-mm, Alice Ryhl, Matthew Maurer

Alice Ryhl <aliceryhl@google.com> writes:

> Currently the only way for Rust code to call a static inline function is
> to go through a helper in rust/helpers/. This introduces performance
> costs due to additional function calls and also clutters backtraces and
> flame graphs with helper symbols.
>
> To get rid of these helper symbols, provide functionality to inline
> helpers into Rust using llvm-link. This option complements full LTO, by
> being much cheaper and avoiding incompatibility with BTF.
>
> I ran a microbenchmark showing the benefit of this. All the benchmark
> does is call refcount_inc() in a loop. This was chosen since refcounting
> is quite hot in Binder. The results are that Rust spends 6.35 ns per
> call vs 5.73 ns per call in C. When enabling this option, the two
> languages become equally fast, and disassembly confirms the exact same
> machine code is used (in particular there is no call to
> rust_helper_refcount_inc). Benchmarking Binder also results in an
> improvement from this change.
>
> This patch is complementary to:
> https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com/
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>


Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>

Tested with the rust null block driver patch series [1]. I did a
few functional verification tests and a set of performance tests.

For the rnull driver, enabling helper inlining with this patch gives an
average speedup of 2% over the set of 120 workloads that we publish on
[2].

Best regards,
Andreas Hindborg

[1] https://lore.kernel.org/rust-for-linux/20260216-rnull-v6-19-rc5-send-v1-0-de9a7af4b469@kernel.org/
[2] https://rust-for-linux.com/null-block-driver



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
                   ` (3 preceding siblings ...)
  2026-03-17  8:25 ` [PATCH v2 0/3] Inline helpers into Rust without full LTO Andreas Hindborg
@ 2026-03-22 19:21 ` Miguel Ojeda
  2026-03-22 19:38   ` Miguel Ojeda
                     ` (4 more replies)
  4 siblings, 5 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-22 19:21 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
	Bill Wendling, Justin Stitt, David Gow, Russell King,
	Richard Weinberger, Anton Ivanov, Johannes Berg, aliceryhl
  Cc: linux-um, llvm, linux-arm-kernel, linux-kbuild, a.hindborg,
	acourbot, akpm, bjorn3_gh, boqun.feng, dakr, gary, linux-kernel,
	linux-mm, lossin, mark.rutland, mmaurer, nicolas.schier, ojeda,
	peterz, rust-for-linux, tmgross, urezki, will

On Tue, 03 Feb 2026 11:34:07 +0000 Alice Ryhl <aliceryhl@google.com> wrote:
>
> To get rid of these helper symbols, provide functionality to inline
> helpers into Rust using llvm-link. This option complements full LTO, by
> being much cheaper and avoiding incompatibility with BTF.

I have been testing this. I think we can go ahead with it, with a few
notes.

I will reply to a couple other bindings in separate emails to avoid
spamming people too much.

  - I will mark the Kconfig option as "(EXPERIMENTAL)", since that is
    what the commit message says and it allows us to be a bit
    conservative.


  - Clang passes `-Werror=unused-command-line-argument`, which means
    under arm (i.e. 32-bit) we get:

      clang: error: argument unused during compilation: '-U arm' [-Werror,-Wunused-command-line-argument]

    And under UML I see:

      clang: error: argument unused during compilation: '-I ./arch/um/include/shared' [-Werror,-Wunused-command-line-argument]
      clang: error: argument unused during compilation: '-I ./arch/x86/um/shared' [-Werror,-Wunused-command-line-argument]
      clang: error: argument unused during compilation: '-I ./arch/um/include/shared/skas' [-Werror,-Wunused-command-line-argument]

    So we would need e.g. `-Wno-unused-command-line-argument` there
    close to the `-Wno-override-module` one, unless Kbuild or
    ClangBuiltLinux thinks it is important to keep it for this case.

    On the other hand, regardless of whether we fix this (and another
    issue in a separate email found thanks to the UML build), we could
    instead add `depends on` listing explicitly the architectures where
    this is going to be actually tested. That way maintainers can decide
    whether they want to support it when they are ready. Thoughts?

    Cc'ing Nathan, Nicolas, Nick, Bill, Justin, David, UML, ARM.


  - If we use the `.bc` extension, we need to add a `.gitignore` for
    `.bc` files, and an exception for `kernel/time/timeconst.bc`.

    I guess we will not have too many `bc` scripts in the future for
    that to be a problem. On the other hand, we have the chance to use
    another extension (either for LLVM bitcode or for `bc` scripts).

    But please let me know on e.g. the Kbuild side if someone has
    concerns...


  - Do we want to have the `cmd_ld_single` step even if the new mode is
    not enabled? i.e. we are gating the other steps, so we could gate
    that one too easily, no?

        -       $(cmd_ld_single) \
        +       $(if $(link_helper),$(cmd_ld_single)) \

        -       $(cmd_ld_single) \
        +       $(if $(CONFIG_RUST_INLINE_HELPERS),$(cmd_ld_single)) \

    I mean, it only affects `CONFIG_LTO_CLANG` configs, which are on
    their own experimental as far as I can see, so it is probably fine
    as it is, but still, while making things unconditional on the caller
    is good, it is also a behaviour change for configs outside the thing
    introduced here, so I am asking.

    (We could use something like a `is-rust-object` to do it on the
    definition side, but I would leave that for later.)

Thanks!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:21 ` Miguel Ojeda
@ 2026-03-22 19:38   ` Miguel Ojeda
  2026-03-23 13:54     ` Mark Brown
  2026-03-22 19:46   ` Miguel Ojeda
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-22 19:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Daniel Almeida, Jean Delvare, ojeda
  Cc: linux-kernel, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-mm, linux-um, linux, llvm,
	lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
>
> I will reply to a couple other bindings in separate emails to avoid
> spamming people too much.

In a series of tests, in some cases, I noticed an `objtool` warning for
x86_64:

    rust/kernel.o: warning: objtool: _R..._9RegulatorNtB5_8DisabledE3get() is missing an ELF size annotation
    rust/kernel.o: warning: objtool: _R..._9RegulatorNtB5_7EnabledE3get() is missing an ELF size annotation

I noticed that it only happened when `CONFIG_REGULATOR` was disabled. It
seems that we have undefined behavior in `regulator.rs`...

We have `Regulator<Enabled/Disabled>::get()` which calls
`get_internal()` which calls the `regulator_get()` helper, which returns
`NULL` when `CONFIG_REGULATOR` is not set. Then the return value is
passed to `from_err_ptr` which checks `IS_ERR`, which returns false
(unlike `IS_ERR_OR_NULL`), and thus we return an `Ok(NULL)`, which we
then pass to `NonNull::new_unchecked`:

    // SAFETY: We can safely trust `inner` to be a pointer to a valid
    // regulator if `ERR_PTR` was not returned.
    let inner = unsafe { NonNull::new_unchecked(inner) };

So we should fix that -- it is there since its introduction in commit
9b614ceada7c ("rust: regulator: add a bare minimum regulator
abstraction"). How to fix that depends on whether the Rust abstraction
supposed to work transparently like the C API, I assume.

Now, two improvements I think we should independently do too:

  - The docs on `regulator_get()` don't say it may return `NULL`. It
    originally that case, but commit be1a50d4eba4 ("regulator: Let
    drivers know when they use the stub API") changed that without
    changing the docs.

    I mean, the "docs" are on the real function, but still, one may look
    into those and not realize the stub does something different.

    The implementation comment on the stub is also a bit contradictory.
    The original sentence (which still is there) says that nothing
    should look at the value, but then it goes onto say that drivers may
    actually look at the value.

  - On the Rust general infrastructure side, we should document more
    prominently that `from_err_ptr` may return `Ok(NULL)` just fine,
    since it calls `IS_ERR`. It may be obvious, since `NULL` is not an
    error value, but still, it could have perhaps prevented this issue.

    We should also include an example to the doctest showing and testing
    that particular case to drive the point home.

    I can add that as a "good first issue".

Cc'ing Liam, Mark, Daniel, Jean.

I hope that helps.

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:21 ` Miguel Ojeda
  2026-03-22 19:38   ` Miguel Ojeda
@ 2026-03-22 19:46   ` Miguel Ojeda
  2026-03-23  8:49     ` Marek Szyprowski
  2026-03-23  0:03   ` Miguel Ojeda
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-22 19:46 UTC (permalink / raw)
  To: Marek Szyprowski, Robin Murphy, Danilo Krummrich, Abdiel Janulgue,
	Daniel Almeida, Andreas Hindborg, Christoph Hellwig, ojeda
  Cc: iommu, driver-core, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
>
> I will reply to a couple other bindings in separate emails to avoid
> spamming people too much.

Under UML, I got `-Wstatic-in-inline` for `dma_free_attrs`:

      BINDGEN rust/bindings/bindings_generated.rs - due to target missing
    In file included from rust/helpers/helpers.c:59:
    rust/helpers/dma.c:17:2: warning: static function 'dma_free_attrs' is used in an inline function with external linkage [-Wstatic-in-inline]
       17 |         dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
          |         ^
    rust/helpers/dma.c:12:1: note: use 'static' to give inline function 'rust_helper_dma_free_attrs' internal linkage
       12 | __rust_helper void rust_helper_dma_free_attrs(struct device *dev, size_t size,
          | ^
          | static

For some reason, `dma_free_attrs` is not marked `inline` in
`include/linux/dma-mapping.h` to begin with, unlike the rest.

Unless I am missing something and there is a reason for that, it looks
like it has just been missing since it was added in commit ed6ccf10f24b
("dma-mapping: properly stub out the DMA API for !CONFIG_HAS_DMA").

Do you want a patch?

Cc'ing Marek, Robin, Danilo, Abdiel, Daniel, Andreas, Christoph.

I hope that helps!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:21 ` Miguel Ojeda
  2026-03-22 19:38   ` Miguel Ojeda
  2026-03-22 19:46   ` Miguel Ojeda
@ 2026-03-23  0:03   ` Miguel Ojeda
  2026-03-23  3:04     ` Andrew Lunn
  2026-03-23 10:03     ` Russell King (Oracle)
  2026-03-26  2:42   ` Nathan Chancellor
  2026-03-26  5:34   ` David Gow
  4 siblings, 2 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23  0:03 UTC (permalink / raw)
  To: ojeda
  Cc: a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov, bjorn3_gh,
	boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
>
>     On the other hand, regardless of whether we fix this (and another
>     issue in a separate email found thanks to the UML build), we could
>     instead add `depends on` listing explicitly the architectures where
>     this is going to be actually tested. That way maintainers can decide
>     whether they want to support it when they are ready. Thoughts?

Another one for arm 32-bit:

      LD      .tmp_vmlinux1
    ld.lld: error: undefined symbol: __aeabi_read_tp
    >>> referenced by uaccess.rs:349 (rust/kernel/uaccess.rs:349)
    >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
    >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
    >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
    >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
    >>>               drivers/android/binder/rust_binder_main.o:(rust_binder_main::rust_binder_ioctl) in archive vmlinux.a
    >>> referenced 36 more times

I think this reinforces the case that this is something that arch folks
should think about case by case, and decide if they want to try -- we
may want to start simple with x86_64 and arm64 or similar first.

Thanks!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23  0:03   ` Miguel Ojeda
@ 2026-03-23  3:04     ` Andrew Lunn
  2026-03-23  3:24       ` Miguel Ojeda
  2026-03-23 10:03     ` Russell King (Oracle)
  1 sibling, 1 reply; 40+ messages in thread
From: Andrew Lunn @ 2026-03-23  3:04 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov, bjorn3_gh,
	boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 01:03:27AM +0100, Miguel Ojeda wrote:
> On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
> >
> >     On the other hand, regardless of whether we fix this (and another
> >     issue in a separate email found thanks to the UML build), we could
> >     instead add `depends on` listing explicitly the architectures where
> >     this is going to be actually tested. That way maintainers can decide
> >     whether they want to support it when they are ready. Thoughts?
> 
> Another one for arm 32-bit:
> 
>       LD      .tmp_vmlinux1
>     ld.lld: error: undefined symbol: __aeabi_read_tp
>     >>> referenced by uaccess.rs:349 (rust/kernel/uaccess.rs:349)
>     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
>     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
>     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
>     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
>     >>>               drivers/android/binder/rust_binder_main.o:(rust_binder_main::rust_binder_ioctl) in archive vmlinux.a
>     >>> referenced 36 more times
> 
> I think this reinforces the case that this is something that arch folks
> should think about case by case, and decide if they want to try -- we
> may want to start simple with x86_64 and arm64 or similar first.

But is this an architecture thing?

The netlink binding required this, because many of the netlink API
calls are implemented in inline function. However, netlink is
architecture independent.

Rust is already fragmented, because it does not support all
architectures. Do we really want to make it even more fragmented by
having some bindings only work on a subset of the subset of
architectures?

	Andrew


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23  3:04     ` Andrew Lunn
@ 2026-03-23  3:24       ` Miguel Ojeda
  2026-03-23 12:54         ` Andrew Lunn
  0 siblings, 1 reply; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23  3:24 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 4:04 AM Andrew Lunn <andrew@lunn.ch> wrote:
>
> Rust is already fragmented, because it does not support all
> architectures. Do we really want to make it even more fragmented by
> having some bindings only work on a subset of the subset of
> architectures?

That is not the case. The `depends on` is not about putting them on
abstractions, but on this experimental build feature, which is gated
on `EXPERT` to begin with, because it uses a fairly exotic approach
involving LLVM bitcode, which carries potential pitfalls, like the
mismatches on the target string like one of the commit messages
mentions, and possibly others.

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:46   ` Miguel Ojeda
@ 2026-03-23  8:49     ` Marek Szyprowski
  2026-03-25  1:58       ` Miguel Ojeda
  0 siblings, 1 reply; 40+ messages in thread
From: Marek Szyprowski @ 2026-03-23  8:49 UTC (permalink / raw)
  To: Miguel Ojeda, Robin Murphy, Danilo Krummrich, Abdiel Janulgue,
	Daniel Almeida, Andreas Hindborg, Christoph Hellwig
  Cc: iommu, driver-core, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On 22.03.2026 20:46, Miguel Ojeda wrote:
> On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
>> I will reply to a couple other bindings in separate emails to avoid
>> spamming people too much.
> Under UML, I got `-Wstatic-in-inline` for `dma_free_attrs`:
>
>        BINDGEN rust/bindings/bindings_generated.rs - due to target missing
>      In file included from rust/helpers/helpers.c:59:
>      rust/helpers/dma.c:17:2: warning: static function 'dma_free_attrs' is used in an inline function with external linkage [-Wstatic-in-inline]
>         17 |         dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
>            |         ^
>      rust/helpers/dma.c:12:1: note: use 'static' to give inline function 'rust_helper_dma_free_attrs' internal linkage
>         12 | __rust_helper void rust_helper_dma_free_attrs(struct device *dev, size_t size,
>            | ^
>            | static
>
> For some reason, `dma_free_attrs` is not marked `inline` in
> `include/linux/dma-mapping.h` to begin with, unlike the rest.
>
> Unless I am missing something and there is a reason for that, it looks
> like it has just been missing since it was added in commit ed6ccf10f24b
> ("dma-mapping: properly stub out the DMA API for !CONFIG_HAS_DMA").
>
> Do you want a patch?

Yes please, this looks like an oversight.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23  0:03   ` Miguel Ojeda
  2026-03-23  3:04     ` Andrew Lunn
@ 2026-03-23 10:03     ` Russell King (Oracle)
  2026-03-23 13:26       ` Miguel Ojeda
  2026-03-26 10:10       ` Alice Ryhl
  1 sibling, 2 replies; 40+ messages in thread
From: Russell King (Oracle) @ 2026-03-23 10:03 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov, bjorn3_gh,
	boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 01:03:27AM +0100, Miguel Ojeda wrote:
> On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
> >
> >     On the other hand, regardless of whether we fix this (and another
> >     issue in a separate email found thanks to the UML build), we could
> >     instead add `depends on` listing explicitly the architectures where
> >     this is going to be actually tested. That way maintainers can decide
> >     whether they want to support it when they are ready. Thoughts?
> 
> Another one for arm 32-bit:
> 
>       LD      .tmp_vmlinux1
>     ld.lld: error: undefined symbol: __aeabi_read_tp
>     >>> referenced by uaccess.rs:349 (rust/kernel/uaccess.rs:349)
>     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
>     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
>     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
>     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
>     >>>               drivers/android/binder/rust_binder_main.o:(rust_binder_main::rust_binder_ioctl) in archive vmlinux.a
>     >>> referenced 36 more times

Why is Rust generating code for userspace thread accessors for kernel
space, where userspace threads are meaningless. This is totally wrong.
The kernel must not reference __aeabi_read_tp().

Note: I know nothing about Rust, but I know enough to say the above is
pointing to a fundamental issue in Rust for 32-bit ARM.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23  3:24       ` Miguel Ojeda
@ 2026-03-23 12:54         ` Andrew Lunn
  2026-03-23 13:13           ` Gary Guo
  2026-03-23 13:14           ` Miguel Ojeda
  0 siblings, 2 replies; 40+ messages in thread
From: Andrew Lunn @ 2026-03-23 12:54 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 04:24:59AM +0100, Miguel Ojeda wrote:
> On Mon, Mar 23, 2026 at 4:04 AM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > Rust is already fragmented, because it does not support all
> > architectures. Do we really want to make it even more fragmented by
> > having some bindings only work on a subset of the subset of
> > architectures?
> 
> That is not the case. The `depends on` is not about putting them on
> abstractions, but on this experimental build feature, which is gated
> on `EXPERT` to begin with, because it uses a fairly exotic approach
> involving LLVM bitcode, which carries potential pitfalls, like the
> mismatches on the target string like one of the commit messages
> mentions, and possibly others.

I'm not sure i follow this.

Maybe i should ask a different question.

You said:

> we
> may want to start simple with x86_64 and arm64 or similar first.

The current proposed code for netlink needs this feature, because it
needs access to inline C functions. Is the implication, following a
chain of dependencies, that netlink would only build on x86_64 and
arm64?

If you want netlink on um, arm32, riscv, loongarch you would need a
different implementation of the binding?

And a completely different question. Are there other work in progress
solutions to allow the use of inline C functions? For networking, in
particularly MAC and protocol code, anything which needs to access a
struct sk_buf, a solution to this problem will be required. Do you see
this "fairly exotic approach" as just a sort term bridge until some
other "boring approach" is ready?

	Andrew


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 12:54         ` Andrew Lunn
@ 2026-03-23 13:13           ` Gary Guo
  2026-03-23 13:28             ` Andrew Lunn
  2026-03-23 13:14           ` Miguel Ojeda
  1 sibling, 1 reply; 40+ messages in thread
From: Gary Guo @ 2026-03-23 13:13 UTC (permalink / raw)
  To: Andrew Lunn, Miguel Ojeda
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon Mar 23, 2026 at 12:54 PM GMT, Andrew Lunn wrote:
> On Mon, Mar 23, 2026 at 04:24:59AM +0100, Miguel Ojeda wrote:
>> On Mon, Mar 23, 2026 at 4:04 AM Andrew Lunn <andrew@lunn.ch> wrote:
>> >
>> > Rust is already fragmented, because it does not support all
>> > architectures. Do we really want to make it even more fragmented by
>> > having some bindings only work on a subset of the subset of
>> > architectures?
>> 
>> That is not the case. The `depends on` is not about putting them on
>> abstractions, but on this experimental build feature, which is gated
>> on `EXPERT` to begin with, because it uses a fairly exotic approach
>> involving LLVM bitcode, which carries potential pitfalls, like the
>> mismatches on the target string like one of the commit messages
>> mentions, and possibly others.
>
> I'm not sure i follow this.
>
> Maybe i should ask a different question.
>
> You said:
>
>> we
>> may want to start simple with x86_64 and arm64 or similar first.
>
> The current proposed code for netlink needs this feature, because it
> needs access to inline C functions. Is the implication, following a
> chain of dependencies, that netlink would only build on x86_64 and
> arm64?
>
> If you want netlink on um, arm32, riscv, loongarch you would need a
> different implementation of the binding?

It doesn't need this feature to build and function. It'll just be a bit slower
because inlining from C to Rust won't happen.

>
> And a completely different question. Are there other work in progress
> solutions to allow the use of inline C functions? For networking, in
> particularly MAC and protocol code, anything which needs to access a
> struct sk_buf, a solution to this problem will be required. Do you see
> this "fairly exotic approach" as just a sort term bridge until some
> other "boring approach" is ready?

The actually inlining itself is not exotic, it's exactly same as LTO, just in
smaller scale. Although, the way we do it is probably somewhat uncommon due all
the constraints that the kernel has (mostly due to loadable modules, so we
cannot perform a global LTO and thus need custom handling of LLVM bitcode).

Best,
Gary


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 12:54         ` Andrew Lunn
  2026-03-23 13:13           ` Gary Guo
@ 2026-03-23 13:14           ` Miguel Ojeda
  1 sibling, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23 13:14 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	linux, llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 1:55 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> The current proposed code for netlink needs this feature, because it
> needs access to inline C functions. Is the implication, following a
> chain of dependencies, that netlink would only build on x86_64 and
> arm64?
>
> If you want netlink on um, arm32, riscv, loongarch you would need a
> different implementation of the binding?

I still don't follow -- this new mode is opt-in, and only a couple
architectures (or whoever decides to support it) would be able to
opt-in. Nothing else changes.

> And a completely different question. Are there other work in progress
> solutions to allow the use of inline C functions? For networking, in
> particularly MAC and protocol code, anything which needs to access a
> struct sk_buf, a solution to this problem will be required. Do you see
> this "fairly exotic approach" as just a sort term bridge until some
> other "boring approach" is ready?

This series is really just a way to increase performance, i.e. it
doesn't really change what we can do.

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 10:03     ` Russell King (Oracle)
@ 2026-03-23 13:26       ` Miguel Ojeda
  2026-03-26 10:10       ` Alice Ryhl
  1 sibling, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23 13:26 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 11:03 AM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
>
> Why is Rust generating code for userspace thread accessors for kernel
> space, where userspace threads are meaningless. This is totally wrong.
> The kernel must not reference __aeabi_read_tp().
>
> Note: I know nothing about Rust, but I know enough to say the above is
> pointing to a fundamental issue in Rust for 32-bit ARM.

If it happens outside this patch series (i.e. the new opt-in mode),
then yeah, something is broken.

That is why I proposed to gate this new mode to the
architectures/configs where it is known to be OK (and where
maintainers may be OK with it etc.).

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 13:13           ` Gary Guo
@ 2026-03-23 13:28             ` Andrew Lunn
  2026-03-23 13:34               ` Miguel Ojeda
  2026-03-23 14:39               ` Alice Ryhl
  0 siblings, 2 replies; 40+ messages in thread
From: Andrew Lunn @ 2026-03-23 13:28 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl,
	anton.ivanov, bjorn3_gh, boqun.feng, dakr, david, johannes,
	justinstitt, linux-arm-kernel, linux-kbuild, linux-kernel,
	linux-mm, linux-um, linux, llvm, lossin, mark.rutland, mmaurer,
	morbo, nathan, nick.desaulniers+lkml, nicolas.schier, nsc, peterz,
	richard, rust-for-linux, tmgross, urezki, will

> > If you want netlink on um, arm32, riscv, loongarch you would need a
> > different implementation of the binding?
> 
> It doesn't need this feature to build and function. It'll just be a bit slower
> because inlining from C to Rust won't happen.

So it sounds like my understanding is out of date. When the first
Ethernet PHY driver was being merged, Rust could not access inline C
functions. The binding had to replicate the functionality. But you are
saying that Rust can now make use of inline C code, but not actually
inline it? It results in a function call?

What this feature does it actually allows inline C functions to be
inline? So it is just an optimisation?

	Andrew


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 13:28             ` Andrew Lunn
@ 2026-03-23 13:34               ` Miguel Ojeda
  2026-03-23 14:39               ` Alice Ryhl
  1 sibling, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23 13:34 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Gary Guo, Miguel Ojeda, a.hindborg, acourbot, akpm, aliceryhl,
	anton.ivanov, bjorn3_gh, boqun.feng, dakr, david, johannes,
	justinstitt, linux-arm-kernel, linux-kbuild, linux-kernel,
	linux-mm, linux-um, linux, llvm, lossin, mark.rutland, mmaurer,
	morbo, nathan, nick.desaulniers+lkml, nicolas.schier, nsc, peterz,
	richard, rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 2:28 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> So it sounds like my understanding is out of date. When the first
> Ethernet PHY driver was being merged, Rust could not access inline C
> functions. The binding had to replicate the functionality. But you are
> saying that Rust can now make use of inline C code, but not actually
> inline it? It results in a function call?
>
> What this feature does it actually allows inline C functions to be
> inline? So it is just an optimisation?

We have always been using the helpers to access the inline functions,
please see the top comment in `rust/helpers/helpers.c`:

   Non-trivial C macros cannot be used in Rust. Similarly, inlined C functions
   cannot be called either. This file explicitly creates functions ("helpers")
   that wrap those so that they can be called from Rust.

It doesn't duplicate the functionality, it simply forwards the call,
i.e. it is not as bad as a full copy-paste of the implementation.

This patch series aims to improve performance (cheaply in terms of
built time) because for Rust calling those helpers are not inline
anymore otherwise.

You may be referring, instead, to avoiding to have to write manually
the helper (the forwarder) -- for that, please see "Support static
inline functions in headers (by generating a wrapper)" at:

  https://github.com/Rust-for-Linux/linux/issues/353

(In fact, I had your previous mention of `skbuff.h` from Lore there :)

Assuming `--wrap-static-fns` works well etc., then it would be nice to
use it, yeah. But that is different from this patch series (and this
patch series would apply as well even if we use the automated wrappers
etc.).

I hope that clarifies.

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:38   ` Miguel Ojeda
@ 2026-03-23 13:54     ` Mark Brown
  2026-03-23 14:53       ` Miguel Ojeda
  0 siblings, 1 reply; 40+ messages in thread
From: Mark Brown @ 2026-03-23 13:54 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Liam Girdwood, Daniel Almeida, Jean Delvare, linux-kernel,
	a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov, bjorn3_gh,
	boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-mm, linux-um, linux, llvm,
	lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]

On Sun, Mar 22, 2026 at 08:38:30PM +0100, Miguel Ojeda wrote:

>   - The docs on `regulator_get()` don't say it may return `NULL`. It
>     originally that case, but commit be1a50d4eba4 ("regulator: Let
>     drivers know when they use the stub API") changed that without
>     changing the docs.

Callers should never treat NULL any differently to any other non-error
pointer, this is not a value intended for inspection by users.

>     The original sentence (which still is there) says that nothing
>     should look at the value, but then it goes onto say that drivers may
>     actually look at the value.

Having specific handling for NULLs is very much not a preferred
interface, and most things shouldn't.  The caller should probably have
it's own !CONFIG_REGULATOR checks rather than using the return value.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 13:28             ` Andrew Lunn
  2026-03-23 13:34               ` Miguel Ojeda
@ 2026-03-23 14:39               ` Alice Ryhl
  1 sibling, 0 replies; 40+ messages in thread
From: Alice Ryhl @ 2026-03-23 14:39 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Gary Guo, Miguel Ojeda, Miguel Ojeda, a.hindborg, acourbot, akpm,
	anton.ivanov, bjorn3_gh, boqun.feng, dakr, david, johannes,
	justinstitt, linux-arm-kernel, linux-kbuild, linux-kernel,
	linux-mm, linux-um, linux, llvm, lossin, mark.rutland, mmaurer,
	morbo, nathan, nick.desaulniers+lkml, nicolas.schier, nsc, peterz,
	richard, rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 02:28:25PM +0100, Andrew Lunn wrote:
> > > If you want netlink on um, arm32, riscv, loongarch you would need a
> > > different implementation of the binding?
> > 
> > It doesn't need this feature to build and function. It'll just be a bit slower
> > because inlining from C to Rust won't happen.
> 
> So it sounds like my understanding is out of date. When the first
> Ethernet PHY driver was being merged, Rust could not access inline C
> functions. The binding had to replicate the functionality. But you are
> saying that Rust can now make use of inline C code, but not actually
> inline it? It results in a function call?
> 
> What this feature does it actually allows inline C functions to be
> inline? So it is just an optimisation?

That's right, this series applies cross-language inlining to the helpers
we have for calling inline functions.

Sorry if I was unclear on the netlink patch series. I mentioned this
series because you told me that inlining is important for skbuff due to
performance (not for netlink though), and this series is necessary to
make such code on par with C perf-wise. But if you accept the function
call overhead from not having cross-language inlining, this series is
not needed.

Alice


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 13:54     ` Mark Brown
@ 2026-03-23 14:53       ` Miguel Ojeda
  0 siblings, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-23 14:53 UTC (permalink / raw)
  To: Miguel Ojeda, Liam Girdwood, Daniel Almeida, Jean Delvare,
	linux-kernel, a.hindborg, acourbot, akpm, aliceryhl, anton.ivanov,
	bjorn3_gh, boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-mm, linux-um, linux, llvm,
	lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 2:54 PM Mark Brown <broonie@kernel.org> wrote:
>
> Callers should never treat NULL any differently to any other non-error
> pointer, this is not a value intended for inspection by users.
>
> Having specific handling for NULLs is very much not a preferred
> interface, and most things shouldn't.  The caller should probably have
> it's own !CONFIG_REGULATOR checks rather than using the return value.

Yeah, that is the understanding I got from reading both the docs and
the comment, but I think the docs (i.e. not the comment in the stub)
could point that `NULL` is one possible pointer value (perhaps
including discouraging relying on particular values at the same time,
and perhaps mentioning `!CONFIG_REGULATOR`).

i.e. to me, "Pointer to a struct regulator corresponding to the
regulator producer," sounds in the docs a bit too much like it will be
a valid one... no?

Another perspective is that, when one reads the rendered docs:

  https://docs.kernel.org/driver-api/regulator.html#c.regulator_get

one sees the postconditions, but they happen to not apply in all cases
(in fact, perhaps not having the "Returns" there would increase the
chances one realizes that, but I understand that you want them to
treat it as fully opaque as much as possible).

It could also help things like AI review systems which may only notice
the docs and not the comment inside the stub.

Perhaps it could be at least a one-line comment in the real
definition, even if not in the rendered docs, to have a chance for
others to notice.

I don't know -- I hope that helps, in any case. Perhaps Daniel can
tell us what he thought when he was writing the code, as another
perspective, i.e. whether it was the docs or not the issue.

Thanks!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23  8:49     ` Marek Szyprowski
@ 2026-03-25  1:58       ` Miguel Ojeda
  0 siblings, 0 replies; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-25  1:58 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Miguel Ojeda, Robin Murphy, Danilo Krummrich, Abdiel Janulgue,
	Daniel Almeida, Andreas Hindborg, Christoph Hellwig, iommu,
	driver-core, acourbot, akpm, aliceryhl, anton.ivanov, bjorn3_gh,
	boqun.feng, david, gary, johannes, justinstitt, linux-arm-kernel,
	linux-kbuild, linux-kernel, linux-mm, linux-um, linux, llvm,
	lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 9:49 AM Marek Szyprowski
<m.szyprowski@samsung.com> wrote:
>
> Yes please, this looks like an oversight.

https://lore.kernel.org/rust-for-linux/20260325015548.70912-1-ojeda@kernel.org/

I hope that helps!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:21 ` Miguel Ojeda
                     ` (2 preceding siblings ...)
  2026-03-23  0:03   ` Miguel Ojeda
@ 2026-03-26  2:42   ` Nathan Chancellor
  2026-03-26  5:34   ` David Gow
  4 siblings, 0 replies; 40+ messages in thread
From: Nathan Chancellor @ 2026-03-26  2:42 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
	David Gow, Russell King, Richard Weinberger, Anton Ivanov,
	Johannes Berg, aliceryhl, linux-um, llvm, linux-arm-kernel,
	linux-kbuild, a.hindborg, acourbot, akpm, bjorn3_gh, boqun.feng,
	dakr, gary, linux-kernel, linux-mm, lossin, mark.rutland, mmaurer,
	nicolas.schier, peterz, rust-for-linux, tmgross, urezki, will

On Sun, Mar 22, 2026 at 08:21:59PM +0100, Miguel Ojeda wrote:
>   - Clang passes `-Werror=unused-command-line-argument`, which means
>     under arm (i.e. 32-bit) we get:
> 
>       clang: error: argument unused during compilation: '-U arm' [-Werror,-Wunused-command-line-argument]
> 
>     And under UML I see:
> 
>       clang: error: argument unused during compilation: '-I ./arch/um/include/shared' [-Werror,-Wunused-command-line-argument]
>       clang: error: argument unused during compilation: '-I ./arch/x86/um/shared' [-Werror,-Wunused-command-line-argument]
>       clang: error: argument unused during compilation: '-I ./arch/um/include/shared/skas' [-Werror,-Wunused-command-line-argument]
> 
>     So we would need e.g. `-Wno-unused-command-line-argument` there
>     close to the `-Wno-override-module` one, unless Kbuild or
>     ClangBuiltLinux thinks it is important to keep it for this case.

No, I don't think it is worth trying to make -Wunused-command-line-argument
work for this command. Just disable it. This mirrors what is being done
for cmd_cc_o_bc in the distributed ThinLTO:

  https://lore.kernel.org/20260316212930.120438-3-xur@google.com/

>     On the other hand, regardless of whether we fix this (and another
>     issue in a separate email found thanks to the UML build), we could
>     instead add `depends on` listing explicitly the architectures where
>     this is going to be actually tested. That way maintainers can decide
>     whether they want to support it when they are ready. Thoughts?
> 
>     Cc'ing Nathan, Nicolas, Nick, Bill, Justin, David, UML, ARM.

I do agree with some of the concerns that adding an architecure
dimension to this is a little complicated. I would rather try to flush
out those build problems with patches and keep it enabled for all
architectures. At the same time though, I understand that enabling it
for the "tier 1" architectures is a low barrier of entry for getting the
feature upstream, validated, and distributed to the majority of people
that would actually use and depend on it, so I ultimately leave that
call up to you.

>   - If we use the `.bc` extension, we need to add a `.gitignore` for
>     `.bc` files, and an exception for `kernel/time/timeconst.bc`.
> 
>     I guess we will not have too many `bc` scripts in the future for
>     that to be a problem. On the other hand, we have the chance to use
>     another extension (either for LLVM bitcode or for `bc` scripts).
> 
>     But please let me know on e.g. the Kbuild side if someone has
>     concerns...

No real concern on that front but .gitignore has a command to run when
modifying it, which will require a !timeconst.bc in a
kernel/time/.gitignore file.

Cheers,
Nathan


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-22 19:21 ` Miguel Ojeda
                     ` (3 preceding siblings ...)
  2026-03-26  2:42   ` Nathan Chancellor
@ 2026-03-26  5:34   ` David Gow
  4 siblings, 0 replies; 40+ messages in thread
From: David Gow @ 2026-03-26  5:34 UTC (permalink / raw)
  To: Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Russell King, Richard Weinberger,
	Anton Ivanov, Johannes Berg, aliceryhl
  Cc: linux-um, llvm, linux-arm-kernel, linux-kbuild, a.hindborg,
	acourbot, akpm, bjorn3_gh, boqun.feng, dakr, gary, linux-kernel,
	linux-mm, lossin, mark.rutland, mmaurer, nicolas.schier, peterz,
	rust-for-linux, tmgross, urezki, will

Le 23/03/2026 à 3:21 AM, Miguel Ojeda a écrit :
> On Tue, 03 Feb 2026 11:34:07 +0000 Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> To get rid of these helper symbols, provide functionality to inline
>> helpers into Rust using llvm-link. This option complements full LTO, by
>> being much cheaper and avoiding incompatibility with BTF.
> 
> I have been testing this. I think we can go ahead with it, with a few
> notes.
> 
> I will reply to a couple other bindings in separate emails to avoid
> spamming people too much.
> 
>    - I will mark the Kconfig option as "(EXPERIMENTAL)", since that is
>      what the commit message says and it allows us to be a bit
>      conservative.
> 
> 
>    - Clang passes `-Werror=unused-command-line-argument`, which means
>      under arm (i.e. 32-bit) we get:
> 
>        clang: error: argument unused during compilation: '-U arm' [-Werror,-Wunused-command-line-argument]
> 
>      And under UML I see:
> 
>        clang: error: argument unused during compilation: '-I ./arch/um/include/shared' [-Werror,-Wunused-command-line-argument]
>        clang: error: argument unused during compilation: '-I ./arch/x86/um/shared' [-Werror,-Wunused-command-line-argument]
>        clang: error: argument unused during compilation: '-I ./arch/um/include/shared/skas' [-Werror,-Wunused-command-line-argument]
> 
>      So we would need e.g. `-Wno-unused-command-line-argument` there
>      close to the `-Wno-override-module` one, unless Kbuild or
>      ClangBuiltLinux thinks it is important to keep it for this case.
> 
>      On the other hand, regardless of whether we fix this (and another
>      issue in a separate email found thanks to the UML build), we could
>      instead add `depends on` listing explicitly the architectures where
>      this is going to be actually tested. That way maintainers can decide
>      whether they want to support it when they are ready. Thoughts?
> 
>      Cc'ing Nathan, Nicolas, Nick, Bill, Justin, David, UML, ARM.
I'm quite happy personally to just have 
-Wno-unused-command-line-argument here, given that it otherwise is 
working pretty well on UML and 32-bit UML.

That being said, I expect it won't get a lot of testing (regardless of 
architecture) while it's hidden behind CONFIG_EXPERT.

Cheers,
-- David


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-23 10:03     ` Russell King (Oracle)
  2026-03-23 13:26       ` Miguel Ojeda
@ 2026-03-26 10:10       ` Alice Ryhl
  2026-03-26 13:47         ` Miguel Ojeda
  1 sibling, 1 reply; 40+ messages in thread
From: Alice Ryhl @ 2026-03-26 10:10 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Miguel Ojeda, a.hindborg, acourbot, akpm, anton.ivanov, bjorn3_gh,
	boqun.feng, dakr, david, gary, johannes, justinstitt,
	linux-arm-kernel, linux-kbuild, linux-kernel, linux-mm, linux-um,
	llvm, lossin, mark.rutland, mmaurer, morbo, nathan,
	nick.desaulniers+lkml, nicolas.schier, nsc, peterz, richard,
	rust-for-linux, tmgross, urezki, will

On Mon, Mar 23, 2026 at 10:03:26AM +0000, Russell King (Oracle) wrote:
> On Mon, Mar 23, 2026 at 01:03:27AM +0100, Miguel Ojeda wrote:
> > On Sun, 22 Mar 2026 20:21:59 +0100 Miguel Ojeda <ojeda@kernel.org> wrote:
> > >
> > >     On the other hand, regardless of whether we fix this (and another
> > >     issue in a separate email found thanks to the UML build), we could
> > >     instead add `depends on` listing explicitly the architectures where
> > >     this is going to be actually tested. That way maintainers can decide
> > >     whether they want to support it when they are ready. Thoughts?
> > 
> > Another one for arm 32-bit:
> > 
> >       LD      .tmp_vmlinux1
> >     ld.lld: error: undefined symbol: __aeabi_read_tp
> >     >>> referenced by uaccess.rs:349 (rust/kernel/uaccess.rs:349)
> >     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
> >     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
> >     >>>               samples/rust/rust_misc_device.o:(<rust_misc_device::RustMiscDevice as kernel::miscdevice::MiscDevice>::ioctl) in archive vmlinux.a
> >     >>> referenced by uaccess.rs:543 (rust/kernel/uaccess.rs:543)
> >     >>>               drivers/android/binder/rust_binder_main.o:(rust_binder_main::rust_binder_ioctl) in archive vmlinux.a
> >     >>> referenced 36 more times
> 
> Why is Rust generating code for userspace thread accessors for kernel
> space, where userspace threads are meaningless. This is totally wrong.
> The kernel must not reference __aeabi_read_tp().
> 
> Note: I know nothing about Rust, but I know enough to say the above is
> pointing to a fundamental issue in Rust for 32-bit ARM.

I noticed that the Makefile currently uses the arm-unknown-linux-gnueabi
target. It should probably not be -linux target to avoid this? Probably
it should just be armv7a-none-eabi, right? We gate HAVE_RUST on
CPU_32v7, so we should not need to consider the other variants.

Alice


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-26 10:10       ` Alice Ryhl
@ 2026-03-26 13:47         ` Miguel Ojeda
  2026-03-26 14:31           ` Christian Schrefl
  0 siblings, 1 reply; 40+ messages in thread
From: Miguel Ojeda @ 2026-03-26 13:47 UTC (permalink / raw)
  To: Alice Ryhl, Christian Schrefl, Ard Biesheuvel, Jamie Cunliffe,
	Will Deacon, Catalin Marinas
  Cc: Russell King (Oracle), Miguel Ojeda, a.hindborg, acourbot, akpm,
	anton.ivanov, bjorn3_gh, boqun.feng, dakr, david, gary, johannes,
	justinstitt, linux-arm-kernel, linux-kbuild, linux-kernel,
	linux-mm, linux-um, llvm, lossin, mark.rutland, mmaurer, morbo,
	nathan, nick.desaulniers+lkml, nicolas.schier, nsc, peterz,
	richard, rust-for-linux, tmgross, urezki

On Thu, Mar 26, 2026 at 11:10 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> I noticed that the Makefile currently uses the arm-unknown-linux-gnueabi
> target. It should probably not be -linux target to avoid this? Probably
> it should just be armv7a-none-eabi, right? We gate HAVE_RUST on
> CPU_32v7, so we should not need to consider the other variants.

I think Christian tried several targets back then and eventually
picked that one.

Christian: what was the reason to pick the `-linux-` one? e.g. was
there something you wanted to rely on that target spec that you
couldn't enable or disable via `rustc` flags or similar?

Cc'ing a few folks.

Thanks!

Cheers,
Miguel


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO
  2026-03-26 13:47         ` Miguel Ojeda
@ 2026-03-26 14:31           ` Christian Schrefl
  0 siblings, 0 replies; 40+ messages in thread
From: Christian Schrefl @ 2026-03-26 14:31 UTC (permalink / raw)
  To: Miguel Ojeda, Alice Ryhl, Ard Biesheuvel, Jamie Cunliffe,
	Will Deacon, Catalin Marinas
  Cc: Russell King (Oracle), Miguel Ojeda, a.hindborg, acourbot, akpm,
	anton.ivanov, bjorn3_gh, boqun.feng, dakr, david, gary, johannes,
	justinstitt, linux-arm-kernel, linux-kbuild, linux-kernel,
	linux-mm, linux-um, llvm, lossin, mark.rutland, mmaurer, morbo,
	nathan, nick.desaulniers+lkml, nicolas.schier, nsc, peterz,
	richard, rust-for-linux, tmgross, urezki

Hi Miguel,

On 3/26/26 2:47 PM, Miguel Ojeda wrote:
> On Thu, Mar 26, 2026 at 11:10 AM Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> I noticed that the Makefile currently uses the arm-unknown-linux-gnueabi
>> target. It should probably not be -linux target to avoid this? Probably
>> it should just be armv7a-none-eabi, right? We gate HAVE_RUST on
>> CPU_32v7, so we should not need to consider the other variants.
> 
> I think Christian tried several targets back then and eventually
> picked that one.
> 
> Christian: what was the reason to pick the `-linux-` one? e.g. was
> there something you wanted to rely on that target spec that you
> couldn't enable or disable via `rustc` flags or similar?

It should probably be fine to use armv7a-none-eabi. I've mostly used
arm-unknown-linux-gnueabi since I though it needed to match the
bindgen-target (which is -linux-gnu for all architectures) and 
because from what I understand clang also uses arm-linux-gnueabi [1].
Also when I selected the target I thought that we would also support
armv6, but since I had no v6 hardware to test on I disabled it.
[1]: https://github.com/Rust-for-Linux/linux/blob/rust-next/scripts/Makefile.clang#L4

Cheers,
Christian


^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2026-03-26 14:31 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 11:34 [PATCH v2 0/3] Inline helpers into Rust without full LTO Alice Ryhl
2026-02-03 11:34 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Alice Ryhl
2026-02-03 11:49   ` Will Deacon
2026-02-03 12:02     ` Alice Ryhl
2026-03-05 10:12   ` Nicolas Schier
2026-03-05 10:51     ` Alice Ryhl
2026-03-14  0:26   ` Nathan Chancellor
2026-02-03 11:34 ` [PATCH v2 2/3] rust: helpers: #define __rust_helper Alice Ryhl
2026-03-14  0:28   ` Nathan Chancellor
2026-02-03 11:34 ` [PATCH v2 3/3] build: rust: provide an option to inline C helpers into Rust Alice Ryhl
2026-03-06 17:32   ` Alice Ryhl
2026-03-14  0:40     ` Nathan Chancellor
2026-03-14 11:22       ` Alice Ryhl
2026-03-16 21:34         ` Nathan Chancellor
2026-03-17  8:02           ` Miguel Ojeda
2026-03-14  0:34   ` Nathan Chancellor
2026-03-17  8:25 ` [PATCH v2 0/3] Inline helpers into Rust without full LTO Andreas Hindborg
2026-03-22 19:21 ` Miguel Ojeda
2026-03-22 19:38   ` Miguel Ojeda
2026-03-23 13:54     ` Mark Brown
2026-03-23 14:53       ` Miguel Ojeda
2026-03-22 19:46   ` Miguel Ojeda
2026-03-23  8:49     ` Marek Szyprowski
2026-03-25  1:58       ` Miguel Ojeda
2026-03-23  0:03   ` Miguel Ojeda
2026-03-23  3:04     ` Andrew Lunn
2026-03-23  3:24       ` Miguel Ojeda
2026-03-23 12:54         ` Andrew Lunn
2026-03-23 13:13           ` Gary Guo
2026-03-23 13:28             ` Andrew Lunn
2026-03-23 13:34               ` Miguel Ojeda
2026-03-23 14:39               ` Alice Ryhl
2026-03-23 13:14           ` Miguel Ojeda
2026-03-23 10:03     ` Russell King (Oracle)
2026-03-23 13:26       ` Miguel Ojeda
2026-03-26 10:10       ` Alice Ryhl
2026-03-26 13:47         ` Miguel Ojeda
2026-03-26 14:31           ` Christian Schrefl
2026-03-26  2:42   ` Nathan Chancellor
2026-03-26  5:34   ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox