Linux Modules
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: "Petr Pavlu" <petr.pavlu@suse.com>,
	linux-modules@vger.kernel.org, ojeda@kernel.org,
	gary@garyguo.net
Subject: Re: [PATCH RFC 11/11] rust: device: enable dynamic debug for dev_dbg!()
Date: Sun, 11 Oct 2026 13:01:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-167239@kernel.org> (raw)
In-Reply-To: <20261011-rust-dyndbg-v1-11-832e4039b71f@weissschuh.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] rust: dev_dbg!() unconditionally evaluates formatting arguments and device expression
--

commit 8da2aef728fa950b65c5e5a0eaa3ddd52cf5dbeb
Author: Thomas Weißschuh <linux@weissschuh.net>

rust: device: enable dynamic debug for dev_dbg!()

Wire up dynamic debug to also work for the dev_dbg!() macro.

> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index 2d49063f4f7c8..db2c9adc5410e 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs

[ ... ]

> @@ -918,6 +918,15 @@ macro_rules! dev_dbg {
>      ($dev:expr, $($f:tt)*) => {
>          match (&$dev, $crate::prelude::fmt!($($f)*)) {
>              (dev, args) => {
> +                // TODO: Switch to cfg_select!() when that is usable.
> +                #[cfg(any(CONFIG_DYNAMIC_DEBUG, all(CONFIG_DYNAMIC_DEBUG_CORE, debug_assertions)))]
> +                $crate::dynamic_func_call!($crate::__format_string!($($f)*), || {
> +                    // SAFETY: klevel is null-terminated, uses one of the kernel constants.
> +                    unsafe { $crate::dev_printk!($crate::bindings::KERN_DEBUG, dev, args) }
> +                });

[Severity: Medium]
Does this unconditionally evaluate the formatting arguments and device
expression?

Since the match (&$dev, $crate::prelude::fmt!($($f)*)) block is placed
outside the dynamic debug conditional closure, the fmt! macro and $dev
expressions are evaluated before the closure is called.

This causes a performance regression by forcing runtime evaluation of all
arguments even when the dynamic debug branch is disabled, defeating the
zero-cost benefit of dynamic debug.

Could the match block be placed inside the conditionally executed closure
passed to dynamic_func_call!, and similarly placed inside the fallback
if cfg!(debug_assertions) block to properly defer evaluation?

> +
> +                #[cfg(not(any(CONFIG_DYNAMIC_DEBUG,
> +                          all(CONFIG_DYNAMIC_DEBUG_CORE, debug_assertions))))]
>                  if cfg!(debug_assertions) {
>                      // SAFETY: klevel is null-terminated, uses one of the kernel constants.
>                      unsafe { $crate::dev_printk!($crate::bindings::KERN_DEBUG, dev, args) }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011-rust-dyndbg-v1-0-832e4039b71f@weissschuh.net?part=11

      reply	other threads:[~2026-10-11 13:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 12:52 [PATCH RFC 00/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 01/11] rust: print: use CStr for __LOG_PREFIX Thomas Weißschuh
2026-10-11 13:01   ` Gary Guo
2026-10-11 14:43     ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 02/11] rust: sync: atomic: Add Atomic<u{8,16}> Thomas Weißschuh
2026-10-11 13:00   ` sashiko-bot
2026-10-11 13:04   ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 03/11] rust: num: Add Bounded::USABLE_BITS Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 04/11] samples: rust_print: add debug messages Thomas Weißschuh
2026-10-11 13:53   ` Miguel Ojeda
2026-10-11 14:48     ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 05/11] dyndbg: use u32 for struct _ddebug bitfields Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 06/11] dyndbg: make _ddebug::flags its own field Thomas Weißschuh
2026-10-11 13:23   ` Gary Guo
2026-10-11 14:47     ` Thomas Weißschuh
2026-10-11 15:44       ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 07/11] dyndbg: use READ_ONCE()/WRITE_ONCE() to access descriptor flags Thomas Weißschuh
2026-10-11 13:16   ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 08/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 13:08   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 09/11] rust: print: enable dynamic debug for pr_debug!() Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 10/11] rust: device: remove logging methods Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 11/11] rust: device: enable dynamic debug for dev_dbg!() Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-167239@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox