Re: [RFC PATCH 2/3] rust: device add support for dynamic debug to pr_debug!

From: Andrew Ballance
Date: Thu Jun 12 2025 - 00:05:20 EST


On 6/11/25 4:38 PM, Alice Ryhl wrote:
Please define a STATIC_KEY_INIT_FALSE constant in
rust/kernel/jump_label.rs and refer to it. You can use mem::zeroed()
in the definition of the constant.

Will do for the v2.

No, we can't use mutable references like this. In Rust, the real
meaning of &mut is exclusive, not mutable. (And the real meaning of &
is shared.) We don't have exclusive access to the DEBUG_INFO static
here - the access is shared, so we must use &_ references instead of
&mut _ references here.

Note that by using Opaque, it's possible to mutate the value even if
it's behind a &_ reference.
#[repr(transparent)]
pub struct _Ddebug {
pub inner: Opaque<bindings::_ddebug>,
}
and then you can do DEBUG_INFO.inner.get() to obtain a mutable raw
pointer to the contents.


Unfortunately, static_branch_unlikely does not work with keys contained
within a Opaque, because it uses offset_of and sym. I can create a macro
specifically for dealing with Opaque::<type_that_contains_a_static_key>
because I imagine that many uses of static branch will end up wrapped
in an Opaque.

Best regards,
Andrew Ballance