[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLghsH=JUm0+t=pj-MnTGGejwxaYiqYT-E-OQ=hZ=aX4oSw@mail.gmail.com>
Date: Thu, 12 Jun 2025 09:17:31 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Andrew Ballance <andrewjballance@...il.com>
Cc: jbaron@...mai.com, jim.cromie@...il.com, daniel.almeida@...labora.com,
acourbot@...dia.com, ojeda@...nel.org, alex.gaynor@...il.com,
boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
lossin@...nel.org, a.hindborg@...nel.org, tmgross@...ch.edu, dakr@...nel.org,
gregkh@...uxfoundation.org, rafael@...nel.org, rostedt@...dmis.org,
viresh.kumar@...aro.org, lina+kernel@...hilina.net, tamird@...il.com,
jubalh@...oru.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH 2/3] rust: device add support for dynamic debug to pr_debug!
On Thu, Jun 12, 2025 at 6:02 AM Andrew Ballance
<andrewjballance@...il.com> wrote:
>
> 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.
Ah, fair enough. In that case, you can also do this:
$crate::print::dynamic_debug::dynamic_pr_debug(
&raw mut DEBUG_INFO,
format_args!($($f)*)
);
using &raw mut creates a raw pointer directly without creating a
reference, so that also solves my concern.
Alice
Powered by blists - more mailing lists