* [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
@ 2026-08-07 22:14 Miguel Ojeda
2026-08-07 22:19 ` Miguel Ojeda
2026-08-07 22:43 ` FUJITA Tomonori
0 siblings, 2 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-08-07 22:14 UTC (permalink / raw)
To: Miguel Ojeda, Arnd Bergmann, Krzysztof Kozlowski,
Alexandre Belloni, Linus Walleij, Huacai Chen
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, rust-for-linux, Drew Fustini,
moderated for non-subscribers, soc, WANG Xuerui, loongarch,
stable
On arm and loongarch64, or under `CONFIG_BUG=n`, the upcoming SRCU
abstractions from commit
59cf3a5bda61 ("rust: sync: add SRCU abstraction")
use `warn_on!`, which in turn warns:
error: constant `WARN_ON_FLAGS` is never used
--> rust/kernel/bug.rs:126:19
|
126 | const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
| ^^^^^^^^^^^^^
|
::: rust/kernel/sync/srcu.rs:106:12
|
106 | if crate::warn_on!(
| ____________-
107 | | // SAFETY: By the type invariants, `self` contains a valid and pinned `struct srcu_struct`
108 | | // and `srcu_readers_active()` only checks the active reader count.
109 | | unsafe { bindings::srcu_readers_active(ptr) }
110 | | ) {
| |_________- in this macro invocation
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
= note: this error originates in the macro `crate::warn_on` (in Nightly builds, run with -Z macro-backtrace for more info)
The reason is that `warn_flags!` discards both arguments in those cases,
and so the `const` becomes unused. And since it is a macro, it went
unnoticed so far.
Thus fix it by simplifying by removing the `const`.
Cc: stable@vger.kernel.org
Fixes: dff64b072708 ("rust: Add warn_on macro")
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
Either this or adding an underscore.
rust/kernel/bug.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
index ed943960f851..874adb93cdfe 100644
--- a/rust/kernel/bug.rs
+++ b/rust/kernel/bug.rs
@@ -123,9 +123,10 @@ macro_rules! warn_on {
const _COND_STR: &str = file!();
if cond {
- const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
-
- $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
+ $crate::warn_flags!(
+ _COND_STR,
+ $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN)
+ );
}
cond
}};
base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-07 22:14 [PATCH] rust: bug: fix `dead_code` warning in `warn_on!` Miguel Ojeda
@ 2026-08-07 22:19 ` Miguel Ojeda
2026-08-07 22:43 ` FUJITA Tomonori
1 sibling, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-08-07 22:19 UTC (permalink / raw)
To: Miguel Ojeda, FUJITA Tomonori
Cc: Arnd Bergmann, Krzysztof Kozlowski, Alexandre Belloni,
Linus Walleij, Huacai Chen, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux, Drew Fustini,
moderated for non-subscribers, soc, WANG Xuerui, loongarch,
stable
On Sat, Aug 8, 2026 at 12:14 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> On arm and loongarch64, or under `CONFIG_BUG=n`, the upcoming SRCU
> abstractions from commit
>
> 59cf3a5bda61 ("rust: sync: add SRCU abstraction")
>
> use `warn_on!`, which in turn warns:
>
> error: constant `WARN_ON_FLAGS` is never used
> --> rust/kernel/bug.rs:126:19
> |
> 126 | const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
> | ^^^^^^^^^^^^^
> |
> ::: rust/kernel/sync/srcu.rs:106:12
> |
> 106 | if crate::warn_on!(
> | ____________-
> 107 | | // SAFETY: By the type invariants, `self` contains a valid and pinned `struct srcu_struct`
> 108 | | // and `srcu_readers_active()` only checks the active reader count.
> 109 | | unsafe { bindings::srcu_readers_active(ptr) }
> 110 | | ) {
> | |_________- in this macro invocation
> |
> = note: `-D dead-code` implied by `-D warnings`
> = help: to override `-D warnings` add `#[allow(dead_code)]`
> = note: this error originates in the macro `crate::warn_on` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> The reason is that `warn_flags!` discards both arguments in those cases,
> and so the `const` becomes unused. And since it is a macro, it went
> unnoticed so far.
>
> Thus fix it by simplifying by removing the `const`.
>
> Cc: stable@vger.kernel.org
> Fixes: dff64b072708 ("rust: Add warn_on macro")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Sorry, I forgot the Cc to Tomonori:
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-07 22:14 [PATCH] rust: bug: fix `dead_code` warning in `warn_on!` Miguel Ojeda
2026-08-07 22:19 ` Miguel Ojeda
@ 2026-08-07 22:43 ` FUJITA Tomonori
2026-08-07 23:21 ` Miguel Ojeda
1 sibling, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2026-08-07 22:43 UTC (permalink / raw)
To: ojeda
Cc: arnd, krzk, alexandre.belloni, linusw, chenhuacai, boqun, gary,
bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, rust-for-linux, fustini,
linux-arm-kernel, soc, kernel, loongarch, stable
On Sat, 8 Aug 2026 00:14:29 +0200
Miguel Ojeda <ojeda@kernel.org> wrote:
> On arm and loongarch64, or under `CONFIG_BUG=n`, the upcoming SRCU
> abstractions from commit
>
> 59cf3a5bda61 ("rust: sync: add SRCU abstraction")
>
> use `warn_on!`, which in turn warns:
>
> error: constant `WARN_ON_FLAGS` is never used
> --> rust/kernel/bug.rs:126:19
> |
> 126 | const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
> | ^^^^^^^^^^^^^
> |
> ::: rust/kernel/sync/srcu.rs:106:12
> |
> 106 | if crate::warn_on!(
> | ____________-
> 107 | | // SAFETY: By the type invariants, `self` contains a valid and pinned `struct srcu_struct`
> 108 | | // and `srcu_readers_active()` only checks the active reader count.
> 109 | | unsafe { bindings::srcu_readers_active(ptr) }
> 110 | | ) {
> | |_________- in this macro invocation
> |
> = note: `-D dead-code` implied by `-D warnings`
> = help: to override `-D warnings` add `#[allow(dead_code)]`
> = note: this error originates in the macro `crate::warn_on` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> The reason is that `warn_flags!` discards both arguments in those cases,
> and so the `const` becomes unused. And since it is a macro, it went
> unnoticed so far.
>
> Thus fix it by simplifying by removing the `const`.
>
> Cc: stable@vger.kernel.org
> Fixes: dff64b072708 ("rust: Add warn_on macro")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> Either this or adding an underscore.
>
> rust/kernel/bug.rs | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
> index ed943960f851..874adb93cdfe 100644
> --- a/rust/kernel/bug.rs
> +++ b/rust/kernel/bug.rs
> @@ -123,9 +123,10 @@ macro_rules! warn_on {
> const _COND_STR: &str = file!();
>
> if cond {
> - const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
> -
> - $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
> + $crate::warn_flags!(
> + _COND_STR,
> + $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN)
> + );
> }
> cond
> }};
>
> base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
> --
> 2.55.0
I sent a fix for this bug a few days ago:
https://lore.kernel.org/all/20260801024841.786664-1-tomo@flapping.org/
If you prefer the simpler version, v1 might work.
https://lore.kernel.org/all/20260720035510.4048145-1-tomo@flapping.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-07 22:43 ` FUJITA Tomonori
@ 2026-08-07 23:21 ` Miguel Ojeda
2026-08-08 5:30 ` FUJITA Tomonori
2026-08-09 14:41 ` Gary Guo
0 siblings, 2 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-08-07 23:21 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai, boqun,
gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, rust-for-linux, fustini,
linux-arm-kernel, soc, kernel, loongarch, stable
On Sat, Aug 8, 2026 at 12:43 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>
> I sent a fix for this bug a few days ago:
>
> https://lore.kernel.org/all/20260801024841.786664-1-tomo@flapping.org/
Ah, right, sorry! I also saw another one with `rusttest` for arm64 and
riscv64. Did you see that one? We probably need a `cfg(testlib)`
split.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-07 23:21 ` Miguel Ojeda
@ 2026-08-08 5:30 ` FUJITA Tomonori
2026-08-08 19:40 ` Miguel Ojeda
2026-08-09 14:41 ` Gary Guo
1 sibling, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2026-08-08 5:30 UTC (permalink / raw)
To: miguel.ojeda.sandonis
Cc: tomo, ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai,
boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross,
dakr, daniel.almeida, tamird, acourbot, work, rust-for-linux,
fustini, linux-arm-kernel, soc, kernel, loongarch, stable
On Sat, 8 Aug 2026 01:21:23 +0200
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> On Sat, Aug 8, 2026 at 12:43 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>>
>> I sent a fix for this bug a few days ago:
>>
>> https://lore.kernel.org/all/20260801024841.786664-1-tomo@flapping.org/
>
> Ah, right, sorry! I also saw another one with `rusttest` for arm64 and
> riscv64. Did you see that one? We probably need a `cfg(testlib)`
> split.
Is this the one you saw?
error: invalid instruction mnemonic 'brk'
--> rust/kernel/bug.rs:63:17
|
63 | / concat!(
64 | | "/* {size} */",
65 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")),
66 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs")));
| |_______________________________________________________________________________________________________^
|
note: instantiated into assembly here
--> <inline asm>:1:115
|
1 | /* 8 */.pushsection __bug_table,"aw"; .align 2; 14470: .long 14471f - .;.short 2305;.align 2; .popsection; 14471:brk 0x800
| ^^^
It shows up when `make rusttest` runs with `ARCH=` set to an
architecture other than the host's.
I posted a `cfg(testlib)` split for it:
https://lore.kernel.org/all/20260808022608.1125174-1-tomo@flapping.org/
While at it, a question: what is `rusttest` meant to cover when
`ARCH=` is not the host's?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-08 5:30 ` FUJITA Tomonori
@ 2026-08-08 19:40 ` Miguel Ojeda
2026-08-09 0:50 ` FUJITA Tomonori
0 siblings, 1 reply; 9+ messages in thread
From: Miguel Ojeda @ 2026-08-08 19:40 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai, boqun,
gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, rust-for-linux, fustini,
linux-arm-kernel, soc, kernel, loongarch, stable
On Sat, Aug 8, 2026 at 7:30 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>
> Is this the one you saw?
Yeah, exactly.
> I posted a `cfg(testlib)` split for it:
>
> https://lore.kernel.org/all/20260808022608.1125174-1-tomo@flapping.org/
Thanks! It seems good to me.
> While at it, a question: what is `rusttest` meant to cover when
> `ARCH=` is not the host's?
`rusttest` is meant to run tests on the host, regardless of the target.
There aren't many tests there nowadays, since most of them moved to
the actual kernel when we got support for that, but we can still do
there things like testing proc macros.
We could also use it for more things in the future, perhaps...
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-08 19:40 ` Miguel Ojeda
@ 2026-08-09 0:50 ` FUJITA Tomonori
2026-08-09 3:01 ` Miguel Ojeda
0 siblings, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2026-08-09 0:50 UTC (permalink / raw)
To: miguel.ojeda.sandonis
Cc: tomo, ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai,
boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross,
dakr, daniel.almeida, tamird, acourbot, work, rust-for-linux,
fustini, linux-arm-kernel, soc, kernel, loongarch, stable
On Sat, 8 Aug 2026 21:40:49 +0200
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>> I posted a `cfg(testlib)` split for it:
>>
>> https://lore.kernel.org/all/20260808022608.1125174-1-tomo@flapping.org/
>
> Thanks! It seems good to me.
Thanks!
>> While at it, a question: what is `rusttest` meant to cover when
>> `ARCH=` is not the host's?
>
> `rusttest` is meant to run tests on the host, regardless of the target.
Then `jump_label.rs` needs the same treatment?
`arch_static_branch!` embeds the generated arch asm too. It is not a
problem today only because, like `warn_on!` until now, it has no user
inside the `kernel` crate itself.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-09 0:50 ` FUJITA Tomonori
@ 2026-08-09 3:01 ` Miguel Ojeda
0 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-08-09 3:01 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai, boqun,
gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, rust-for-linux, fustini,
linux-arm-kernel, soc, kernel, loongarch, stable
On Sun, Aug 9, 2026 at 2:50 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>
> Then `jump_label.rs` needs the same treatment?
>
> `arch_static_branch!` embeds the generated arch asm too. It is not a
> problem today only because, like `warn_on!` until now, it has no user
> inside the `kernel` crate itself.
Yeah, I think we should do it to avoid surprises later.
Good eyes!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
2026-08-07 23:21 ` Miguel Ojeda
2026-08-08 5:30 ` FUJITA Tomonori
@ 2026-08-09 14:41 ` Gary Guo
1 sibling, 0 replies; 9+ messages in thread
From: Gary Guo @ 2026-08-09 14:41 UTC (permalink / raw)
To: Miguel Ojeda, FUJITA Tomonori
Cc: ojeda, arnd, krzk, alexandre.belloni, linusw, chenhuacai, boqun,
gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, rust-for-linux, fustini,
linux-arm-kernel, soc, kernel, loongarch, stable
On Sat Aug 8, 2026 at 12:21 AM BST, Miguel Ojeda wrote:
> On Sat, Aug 8, 2026 at 12:43 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>>
>> I sent a fix for this bug a few days ago:
>>
>> https://lore.kernel.org/all/20260801024841.786664-1-tomo@flapping.org/
>
> Ah, right, sorry! I also saw another one with `rusttest` for arm64 and
> riscv64. Did you see that one? We probably need a `cfg(testlib)`
> split.
I am not sure how much value does `rusttest` still provide, given that KUnit can
test much more stuff in an actual envirionment. The fact that we have to do
special casing does suggest to me that we might want to remove it.
Best,
Gary
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-08-09 14:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 22:14 [PATCH] rust: bug: fix `dead_code` warning in `warn_on!` Miguel Ojeda
2026-08-07 22:19 ` Miguel Ojeda
2026-08-07 22:43 ` FUJITA Tomonori
2026-08-07 23:21 ` Miguel Ojeda
2026-08-08 5:30 ` FUJITA Tomonori
2026-08-08 19:40 ` Miguel Ojeda
2026-08-09 0:50 ` FUJITA Tomonori
2026-08-09 3:01 ` Miguel Ojeda
2026-08-09 14:41 ` Gary Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox