* [PATCH v1] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option
@ 2025-12-04 22:34 FUJITA Tomonori
2026-01-07 16:53 ` Gary Guo
0 siblings, 1 reply; 3+ messages in thread
From: FUJITA Tomonori @ 2025-12-04 22:34 UTC (permalink / raw)
To: ojeda
Cc: a.hindborg, aliceryhl, bjorn3_gh, boqun.feng, dakr, gary, lossin,
rust-for-linux, tmgross
Make warn_on() support DEBUG_BUGVERBOSE_DETAILED option, which was
introduced by the commit aec58b48517c ("bugs/core: Extend
__WARN_FLAGS() with the 'cond_str' parameter").
When the option is enabled, WARN splats now show the evaluated
warn_on() condition alongside the file path, e.g.:
------------[ cut here ]------------
WARNING: [val == 1] /linux/samples/rust/rust_minimal.rs:27 at _RNvXCsk7t4azzUqHP_12rust_minimalNtB2_11RustMinimalNtCs8pcx3n4
Modules linked in: rust_minimal(+)
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/bug.rs | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
index 36aef43e5ebe..a60db1ef4b48 100644
--- a/rust/kernel/bug.rs
+++ b/rust/kernel/bug.rs
@@ -11,15 +11,14 @@
#[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
#[cfg(CONFIG_DEBUG_BUGVERBOSE)]
macro_rules! warn_flags {
- ($flags:expr) => {
+ ($file:expr, $flags:expr) => {
const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
- const _FILE: &[u8] = file!().as_bytes();
// Plus one for null-terminator.
- static FILE: [u8; _FILE.len() + 1] = {
- let mut bytes = [0; _FILE.len() + 1];
+ static FILE: [u8; $file.len() + 1] = {
+ let mut bytes = [0; $file.len() + 1];
let mut i = 0;
- while i < _FILE.len() {
- bytes[i] = _FILE[i];
+ while i < $file.len() {
+ bytes[i] = $file[i];
i += 1;
}
bytes
@@ -50,7 +49,7 @@ macro_rules! warn_flags {
#[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
#[cfg(not(CONFIG_DEBUG_BUGVERBOSE))]
macro_rules! warn_flags {
- ($flags:expr) => {
+ ($file:expr, $flags:expr) => {
const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
// SAFETY:
@@ -75,7 +74,7 @@ macro_rules! warn_flags {
#[doc(hidden)]
#[cfg(all(CONFIG_BUG, CONFIG_UML))]
macro_rules! warn_flags {
- ($flags:expr) => {
+ ($file:expr, $flags:expr) => {
// SAFETY: It is always safe to call `warn_slowpath_fmt()`
// with a valid null-terminated string.
unsafe {
@@ -93,7 +92,7 @@ macro_rules! warn_flags {
#[doc(hidden)]
#[cfg(all(CONFIG_BUG, any(CONFIG_LOONGARCH, CONFIG_ARM)))]
macro_rules! warn_flags {
- ($flags:expr) => {
+ ($file:expr, $flags:expr) => {
// SAFETY: It is always safe to call `WARN_ON()`.
unsafe { $crate::bindings::WARN_ON(true) }
};
@@ -103,7 +102,7 @@ macro_rules! warn_flags {
#[doc(hidden)]
#[cfg(not(CONFIG_BUG))]
macro_rules! warn_flags {
- ($flags:expr) => {};
+ ($file:expr, $flags:expr) => {};
}
#[doc(hidden)]
@@ -116,10 +115,16 @@ pub const fn bugflag_taint(value: u32) -> u32 {
macro_rules! warn_on {
($cond:expr) => {{
let cond = $cond;
+
+ #[cfg(CONFIG_DEBUG_BUGVERBOSE_DETAILED)]
+ const _COND_STR: &[u8] = concat!("[", stringify!($cond), "] ", file!()).as_bytes();
+ #[cfg(not(CONFIG_DEBUG_BUGVERBOSE_DETAILED))]
+ const _COND_STR: &[u8] = file!().as_bytes();
+
if cond {
const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
- $crate::warn_flags!(WARN_ON_FLAGS);
+ $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
}
cond
}};
base-commit: 500920fa76819b4909a32081e153bce80ce74824
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option
2025-12-04 22:34 [PATCH v1] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option FUJITA Tomonori
@ 2026-01-07 16:53 ` Gary Guo
2026-01-08 1:22 ` FUJITA Tomonori
0 siblings, 1 reply; 3+ messages in thread
From: Gary Guo @ 2026-01-07 16:53 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, a.hindborg, aliceryhl, bjorn3_gh, boqun.feng, dakr, lossin,
rust-for-linux, tmgross
On Fri, 5 Dec 2025 07:34:05 +0900
FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:
> Make warn_on() support DEBUG_BUGVERBOSE_DETAILED option, which was
> introduced by the commit aec58b48517c ("bugs/core: Extend
> __WARN_FLAGS() with the 'cond_str' parameter").
>
> When the option is enabled, WARN splats now show the evaluated
> warn_on() condition alongside the file path, e.g.:
>
> ------------[ cut here ]------------
> WARNING: [val == 1] /linux/samples/rust/rust_minimal.rs:27 at _RNvXCsk7t4azzUqHP_12rust_minimalNtB2_11RustMinimalNtCs8pcx3n4
> Modules linked in: rust_minimal(+)
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
> rust/kernel/bug.rs | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
> index 36aef43e5ebe..a60db1ef4b48 100644
> --- a/rust/kernel/bug.rs
> +++ b/rust/kernel/bug.rs
> @@ -11,15 +11,14 @@
> #[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
> #[cfg(CONFIG_DEBUG_BUGVERBOSE)]
> macro_rules! warn_flags {
> - ($flags:expr) => {
> + ($file:expr, $flags:expr) => {
> const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
> - const _FILE: &[u8] = file!().as_bytes();
I think it'll be good to still keep
const _FILE: &[u8] = $file.as_bytes();
and have the caller just pass in `file!()` or `concat!(...)`. At least the
concat macro doesn't have to expanded multiple times in below.
Best,
Gary
> // Plus one for null-terminator.
> - static FILE: [u8; _FILE.len() + 1] = {
> - let mut bytes = [0; _FILE.len() + 1];
> + static FILE: [u8; $file.len() + 1] = {
> + let mut bytes = [0; $file.len() + 1];
> let mut i = 0;
> - while i < _FILE.len() {
> - bytes[i] = _FILE[i];
> + while i < $file.len() {
> + bytes[i] = $file[i];
> i += 1;
> }
> bytes
> @@ -50,7 +49,7 @@ macro_rules! warn_flags {
> #[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
> #[cfg(not(CONFIG_DEBUG_BUGVERBOSE))]
> macro_rules! warn_flags {
> - ($flags:expr) => {
> + ($file:expr, $flags:expr) => {
> const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
>
> // SAFETY:
> @@ -75,7 +74,7 @@ macro_rules! warn_flags {
> #[doc(hidden)]
> #[cfg(all(CONFIG_BUG, CONFIG_UML))]
> macro_rules! warn_flags {
> - ($flags:expr) => {
> + ($file:expr, $flags:expr) => {
> // SAFETY: It is always safe to call `warn_slowpath_fmt()`
> // with a valid null-terminated string.
> unsafe {
> @@ -93,7 +92,7 @@ macro_rules! warn_flags {
> #[doc(hidden)]
> #[cfg(all(CONFIG_BUG, any(CONFIG_LOONGARCH, CONFIG_ARM)))]
> macro_rules! warn_flags {
> - ($flags:expr) => {
> + ($file:expr, $flags:expr) => {
> // SAFETY: It is always safe to call `WARN_ON()`.
> unsafe { $crate::bindings::WARN_ON(true) }
> };
> @@ -103,7 +102,7 @@ macro_rules! warn_flags {
> #[doc(hidden)]
> #[cfg(not(CONFIG_BUG))]
> macro_rules! warn_flags {
> - ($flags:expr) => {};
> + ($file:expr, $flags:expr) => {};
> }
>
> #[doc(hidden)]
> @@ -116,10 +115,16 @@ pub const fn bugflag_taint(value: u32) -> u32 {
> macro_rules! warn_on {
> ($cond:expr) => {{
> let cond = $cond;
> +
> + #[cfg(CONFIG_DEBUG_BUGVERBOSE_DETAILED)]
> + const _COND_STR: &[u8] = concat!("[", stringify!($cond), "] ", file!()).as_bytes();
> + #[cfg(not(CONFIG_DEBUG_BUGVERBOSE_DETAILED))]
> + const _COND_STR: &[u8] = file!().as_bytes();
> +
> if cond {
> const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
>
> - $crate::warn_flags!(WARN_ON_FLAGS);
> + $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
> }
> cond
> }};
>
> base-commit: 500920fa76819b4909a32081e153bce80ce74824
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option
2026-01-07 16:53 ` Gary Guo
@ 2026-01-08 1:22 ` FUJITA Tomonori
0 siblings, 0 replies; 3+ messages in thread
From: FUJITA Tomonori @ 2026-01-08 1:22 UTC (permalink / raw)
To: gary
Cc: fujita.tomonori, ojeda, a.hindborg, aliceryhl, bjorn3_gh,
boqun.feng, dakr, lossin, rust-for-linux, tmgross
On Wed, 7 Jan 2026 16:53:44 +0000
Gary Guo <gary@garyguo.net> wrote:
> On Fri, 5 Dec 2025 07:34:05 +0900
> FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:
>
>> Make warn_on() support DEBUG_BUGVERBOSE_DETAILED option, which was
>> introduced by the commit aec58b48517c ("bugs/core: Extend
>> __WARN_FLAGS() with the 'cond_str' parameter").
>>
>> When the option is enabled, WARN splats now show the evaluated
>> warn_on() condition alongside the file path, e.g.:
>>
>> ------------[ cut here ]------------
>> WARNING: [val == 1] /linux/samples/rust/rust_minimal.rs:27 at _RNvXCsk7t4azzUqHP_12rust_minimalNtB2_11RustMinimalNtCs8pcx3n4
>> Modules linked in: rust_minimal(+)
>>
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
>> ---
>> rust/kernel/bug.rs | 27 ++++++++++++++++-----------
>> 1 file changed, 16 insertions(+), 11 deletions(-)
>>
>> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
>> index 36aef43e5ebe..a60db1ef4b48 100644
>> --- a/rust/kernel/bug.rs
>> +++ b/rust/kernel/bug.rs
>> @@ -11,15 +11,14 @@
>> #[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
>> #[cfg(CONFIG_DEBUG_BUGVERBOSE)]
>> macro_rules! warn_flags {
>> - ($flags:expr) => {
>> + ($file:expr, $flags:expr) => {
>> const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
>> - const _FILE: &[u8] = file!().as_bytes();
>
> I think it'll be good to still keep
>
> const _FILE: &[u8] = $file.as_bytes();
>
>
> and have the caller just pass in `file!()` or `concat!(...)`. At least the
> concat macro doesn't have to expanded multiple times in below.
Good point; I'll update v2 accordingly.
Thanks for the review!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-08 1:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-04 22:34 [PATCH v1] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option FUJITA Tomonori
2026-01-07 16:53 ` Gary Guo
2026-01-08 1:22 ` FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox