rust: move #define __rust_helper out of atomic.c
Subsystems (2)
Alice Ryhl
reviewerPATCH 1/1 rust: move #define __rust_helper out of atomic.c
We were lucky that atomic.c is the first file in helpers.c so that we may use the define from it in the follow-up headers [1], but this is fragile. Thus, move it to helpers.c.
---
When I send the next version of [PATCH 0/4] Inline helpers into Rust without full LTO, it will be based on top of this patch. Regardless of the timelines for the other series, I think it would be good to merge this patch soon.
--- rust/helpers/atomic.c | 5 ----- rust/helpers/helpers.c | 2 ++ scripts/atomic/gen-rust-atomic-helpers.sh | 5 ----- 3 files changed, 2 insertions(+), 10 deletions(-)
rust/helpers/atomic.c +0 -5
@@ -11,11 +11,6 @@#include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - __rust_helper intrust_helper_atomic_read (const atomic_t *v) {
rust/helpers/helpers.c +2 -0
@@ -7,6 +7,8 @@* Sorted alphabetically. */ +#define __rust_helper +#include "atomic.c" #include "auxiliary.c" #include "barrier.c"
scripts/atomic/gen-rust-atomic-helpers.sh +0 -5
@@ -47,11 +47,6 @@ cat << EOF #include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - EOF grep '^[a-z]' "$1" | while read name meta args; do
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20260107-move-rust_helper-define-63edcfb2bff3
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Boqun Feng
AppliedQuoted 4 lines · Alice Ryhl
We were lucky that
atomic.cis the first file inhelpers.cso that we may use the define from it in the follow-up headers [1], but this is fragile. Thus, move it tohelpers.c.
I reword a bit to make it clear that we need this changes for inline helpers:
In order to support inline helpers [1], we need to have __rust_helper defined for all helper files. Current we are lucky that atomic.c is the first file in helpers.c, but this is fragile. Thus, move it to helpers.c.
Let me know if you have futher suggestion.
scripts/atomic/gen-rust-atomic-helpers.sh
Quoted 46 lines
Signed-off-by Alice Ryhl <[email protected]>---
When I send the next version of [PATCH 0/4] Inline helpers into Rust without full LTO, it will be based on top of this patch. Regardless of the timelines for the other series, I think it would be good to merge this patch soon.--- rust/helpers/atomic.c | 5 ----- rust/helpers/helpers.c | 2 ++ scripts/atomic/gen-rust-atomic-helpers.sh | 5 ----- 3 files changed, 2 insertions(+), 10 deletions(-)rust/helpers/atomic.c +0
-5@@ -11,11 +11,6 @@#include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - __rust_helper intrust_helper_atomic_read (const atomic_t *v) {rust/helpers/helpers.c +2
-0@@ -7,6 +7,8 @@* Sorted alphabetically. */ +#define __rust_helper +#include "atomic.c" #include "auxiliary.c" #include "barrier.c" scripts/atomic/gen-rust-atomic-helpers.sh +0
-0
whenever we changed scripts/atomic/* we need to rerun scripts/atomic/gen-atomics.sh to calculate a new hash value of the generated files, so we are missing this:
rust/helpers/atomic.c +1 -1
@@ -1032,4 +1032,4 @@ rust_helper_atomic64_dec_if_positive(atomic64_t *v) }#endif /* _RUST_ATOMIC_API_H */ -// 615a0e0c98b5973a47fe4fa65e92935051ca00ed +// e4edb6174dd42a265284958f00a7cea7ddb464b1
I queued with this change for the rust-sync PR of 7.0, thanks!
Regards,
Boqun
Quoted 21 lines
scripts/atomic/gen-rust-atomic-helpers.sh +0
-6@@ -47,11 +47,6 @@ cat << EOF #include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - EOF grep '^[a-z]' "$1" | while read name meta args; do ---base-commit:
8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20260107-move-rust_helper-define-63edcfb2bff3Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Alice Ryhl
reviewerQuoted 10 lines · Boqun Feng
Quoted 4 lines · Alice Ryhl
We were lucky that
atomic.cis the first file inhelpers.cso that we may use the define from it in the follow-up headers [1], but this is fragile. Thus, move it tohelpers.c.I reword a bit to make it clear that we need this changes for inline helpers:
Quoted 6 lines
In order to support inline helpers [1], we need to have
__rust_helperdefined for all helper files. Current we are lucky thatatomic.cis the first file inhelpers.c, but this is fragile. Thus, move it tohelpers.c.Let me know if you have futher suggestion.
Sounds good to me.
Quoted 8 lines
scripts/atomic/gen-rust-atomic-helpers.sh
Quoted 4 lines
scripts/atomic/gen-rust-atomic-helpers.sh +0
-0whenever we changed
scripts/atomic/*we need to rerunscripts/atomic/gen-atomics.shto calculate a new hash value of the generated files, so we are missing this:
I tried running it but I got an error from grep about no file input or something like that. I couldn't figure out what argument I needed to pass to the script.
Quoted 11 lines
rust/helpers/atomic.c +1
-1@@ -1032,4 +1032,4 @@ rust_helper_atomic64_dec_if_positive(atomic64_t *v) }#endif /* _RUST_ATOMIC_API_H */ -// 615a0e0c98b5973a47fe4fa65e92935051ca00ed +// e4edb6174dd42a265284958f00a7cea7ddb464b1
Quoted 1 line
I queued with this change for the rust-sync PR of 7.0, thanks!
Thanks!
Alice
On Wed, Jan 07, 2026 at 06:20:02PM +0100, Alice Ryhl wrote:
[...]
Quoted 8 lines
Quoted 3 lines
whenever we changed
scripts/atomic/*we need to rerunscripts/atomic/gen-atomics.shto calculate a new hash value of the generated files, so we are missing this:I tried running it but I got an error from grep about no file input or something like that. I couldn't figure out what argument I needed to pass to the script.
$ cd <the kernel source> $ scripts/atomic/gen-atomics.sh
works for me (on my machine ;-))
Regards,
Boqun
[tip: locking/core] rust: helpers: Move #define __rust_helper out of atomic.c
In reply to Alice RyhlThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: abf2111d8d900c834993d443f59b836291b8d0fc Gitweb: https://git.kernel.org/tip/abf2111d8d900c834993d443f59b836291b8d0fc Author: Alice Ryhl <[email protected]> AuthorDate: Wed, 07 Jan 2026 14:14:13 Committer: Boqun Feng <[email protected]> CommitterDate: Fri, 09 Jan 2026 19:01:42 +08:00
rust: helpers: Move #define __rust_helper out of atomic.c
In order to support inline helpers [1], we need to have __rust_helper defined for all helper files. Current we are lucky that atomic.c is the first file in helpers.c, but this is fragile. Thus, move it to helpers.c.
[boqun: Reword the commit message and apply file hash changes]
--- rust/helpers/atomic.c | 7 +------ rust/helpers/helpers.c | 2 ++ scripts/atomic/gen-rust-atomic-helpers.sh | 5 ----- 3 files changed, 3 insertions(+), 11 deletions(-)
rust/helpers/atomic.c +1 -6
@@ -11,11 +11,6 @@#include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - __rust_helper intrust_helper_atomic_read (const atomic_t *v) {
@@ -1037,4 +1032,4 @@ rust_helper_atomic64_dec_if_positive(atomic64_t *v) }#endif /* _RUST_ATOMIC_API_H */ -// 615a0e0c98b5973a47fe4fa65e92935051ca00ed +// e4edb6174dd42a265284958f00a7cea7ddb464b1
rust/helpers/helpers.c +2 -0
@@ -7,6 +7,8 @@* Sorted alphabetically. */ +#define __rust_helper +#include "atomic.c" #include "atomic_ext.c" #include "auxiliary.c"
scripts/atomic/gen-rust-atomic-helpers.sh +0 -5
@@ -47,11 +47,6 @@ cat << EOF #include <linux/atomic.h> -// TODO: Remove this after INLINE_HELPERS support is added. -#ifndef __rust_helper -#define __rust_helper -#endif - EOF grep '^[a-z]' "$1" | while read name meta args; do