aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2025-12-04 11:04:24 +0100
committerChristian Brauner <brauner@kernel.org>2025-12-15 14:13:04 +0100
commit5334fc280735dcf5882511a219a99b5759e14870 (patch)
tree8ce87aa5d4c2a49a6623971d47e6bef9e4b11692
parent8f0b4cce4481fb22653697cced8d0d04027cb1e8 (diff)
parent268eaa8ab4ace3f3bc80fd91bb461e6b6c9da29e (diff)
downloadvfs-7.0.rust.tar.gz
Merge patch series "Allow inlining C helpers into Rust when using LTO"vfs-7.0.rust
Alice Ryhl <aliceryhl@google.com> says: This patch series adds __rust_helper to every single rust helper. These changes were generated by adding __rust_helper and running ClangFormat. Unrelated formatting changes were removed manually. Why is __rust_helper needed? ============================ Currently, C helpers cannot be inlined into Rust even when using LTO because LLVM detects slightly different options on the codegen units. * LLVM doesn't want to inline functions compiled with `-fno-delete-null-pointer-checks` with code compiled without. The C CGUs all have this enabled and Rust CGUs don't. Inlining is okay since this is one of the hardening features that does not change the ABI, and we shouldn't have null pointer dereferences in these helpers. * LLVM doesn't want to inline functions with different list of builtins. C side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so they should be compatible, but LLVM does not perform inlining due to attributes mismatch. * clang and Rust doesn't have the exact target string. Clang generates `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64 always enable these features, so they are in fact the same target string, but LLVM doesn't understand this and so inlining is inhibited. This can be bypassed with `--ignore-tti-inline-compatible`, but this is a hidden option. (This analysis was written by Gary Guo.) How is this fixed? ================== To fix this we need to add __always_inline to all helpers when compiling with LTO. However, it should not be added when running bindgen as bindgen will ignore functions marked inline. To achieve this, we are using a #define called __rust_helper that is defined differently depending on whether bindgen is running or not. Note that __rust_helper is currently always #defined to nothing. Changing it to __always_inline will happen separately in another patch series. * patches from https://patch.msgid.link/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com: rust: poll: add __rust_helper to helpers rust: pid_namespace: add __rust_helper to helpers rust: fs: add __rust_helper to helpers Link: https://patch.msgid.link/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r--rust/helpers/fs.c2
-rw-r--r--rust/helpers/pid_namespace.c8
-rw-r--r--rust/helpers/poll.c5
3 files changed, 9 insertions, 6 deletions
diff --git a/rust/helpers/fs.c b/rust/helpers/fs.c
index a75c9676337246..789d60fb8908b9 100644
--- a/rust/helpers/fs.c
+++ b/rust/helpers/fs.c
@@ -6,7 +6,7 @@
#include <linux/fs.h>
-struct file *rust_helper_get_file(struct file *f)
+__rust_helper struct file *rust_helper_get_file(struct file *f)
{
return get_file(f);
}
diff --git a/rust/helpers/pid_namespace.c b/rust/helpers/pid_namespace.c
index f41482bdec9a7c..f46ab779b5279f 100644
--- a/rust/helpers/pid_namespace.c
+++ b/rust/helpers/pid_namespace.c
@@ -3,18 +3,20 @@
#include <linux/pid_namespace.h>
#include <linux/cleanup.h>
-struct pid_namespace *rust_helper_get_pid_ns(struct pid_namespace *ns)
+__rust_helper struct pid_namespace *
+rust_helper_get_pid_ns(struct pid_namespace *ns)
{
return get_pid_ns(ns);
}
-void rust_helper_put_pid_ns(struct pid_namespace *ns)
+__rust_helper void rust_helper_put_pid_ns(struct pid_namespace *ns)
{
put_pid_ns(ns);
}
/* Get a reference on a task's pid namespace. */
-struct pid_namespace *rust_helper_task_get_pid_ns(struct task_struct *task)
+__rust_helper struct pid_namespace *
+rust_helper_task_get_pid_ns(struct task_struct *task)
{
struct pid_namespace *pid_ns;
diff --git a/rust/helpers/poll.c b/rust/helpers/poll.c
index 7e5b1751c2d526..78b3839b50f065 100644
--- a/rust/helpers/poll.c
+++ b/rust/helpers/poll.c
@@ -3,8 +3,9 @@
#include <linux/export.h>
#include <linux/poll.h>
-void rust_helper_poll_wait(struct file *filp, wait_queue_head_t *wait_address,
- poll_table *p)
+__rust_helper void rust_helper_poll_wait(struct file *filp,
+ wait_queue_head_t *wait_address,
+ poll_table *p)
{
poll_wait(filp, wait_address, p);
}