From: Zhi Wang <zhiw@nvidia.com>
To: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <andrewjballance@gmail.com>, <daniel.almeida@collabora.com>,
<dakr@kernel.org>, <aliceryhl@google.com>, <ojeda@kernel.org>,
<boqun@kernel.org>, <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<a.hindborg@kernel.org>, <tmgross@umich.edu>, <cjia@nvidia.com>,
<smitra@nvidia.com>, <ankita@nvidia.com>, <aniketa@nvidia.com>,
<kwankhede@nvidia.com>, <targupta@nvidia.com>, <kjaju@nvidia.com>,
<alkumar@nvidia.com>, <acourbot@nvidia.com>,
<jhubbard@nvidia.com>, <zhiwang@kernel.org>,
Zhi Wang <zhiw@nvidia.com>
Subject: [PATCH v3 2/5] rust: jump label: add support for nested arguments
Date: Thu, 1 Oct 2026 17:59:37 +0300 [thread overview]
Message-ID: <20261001145940.1077801-3-zhiw@nvidia.com> (raw)
In-Reply-To: <20261001145940.1077801-1-zhiw@nvidia.com>
From: Andrew Ballance <andrewjballance@gmail.com>
allows for nested arguments to be used with the static_branch macro.
e.g. `outer.inner.key` can now be accessed by the macro
Link: https://lore.kernel.org/rust-for-linux/20250620210533.400889-2-andrewjballance@gmail.com/
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
[Zhi: Rebase; extend the host-test stub in the same way and document
the initialized-key and storage requirements for Rust-defined callsites.]
Signed-off-by: Zhi Wang <zhiw@nvidia.com>
---
rust/kernel/jump_label.rs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/rust/kernel/jump_label.rs b/rust/kernel/jump_label.rs
index f54cedcb6fd5..9bda169e82cd 100644
--- a/rust/kernel/jump_label.rs
+++ b/rust/kernel/jump_label.rs
@@ -16,12 +16,15 @@
///
/// # Safety
///
-/// The macro must be used with a real static key defined by C.
+/// The static variable must contain an initialized `static_key_false` at the specified field.
+/// Its storage must remain valid while the key is registered with the jump label code. Updates
+/// to the key must use the C static-key APIs.
#[macro_export]
macro_rules! static_branch_unlikely {
- ($key:path, $keytyp:ty, $field:ident) => {{
+ ($key:path, $keytyp:ty, $($field:ident).+) => {{
let _key: *const $keytyp = ::core::ptr::addr_of!($key);
- let _key: *const $crate::bindings::static_key_false = ::core::ptr::addr_of!((*_key).$field);
+ let _key: *const $crate::bindings::static_key_false =
+ ::core::ptr::addr_of!((*_key)$(.$field)+);
let _key: *const $crate::bindings::static_key = _key.cast();
#[cfg(not(CONFIG_JUMP_LABEL))]
@@ -30,7 +33,7 @@ macro_rules! static_branch_unlikely {
}
#[cfg(CONFIG_JUMP_LABEL)]
- $crate::jump_label::arch_static_branch! { $key, $keytyp, $field, false }
+ $crate::jump_label::arch_static_branch! { $key, $keytyp, $($field).+, false }
}};
}
pub use static_branch_unlikely;
@@ -47,14 +50,14 @@ macro_rules! static_branch_unlikely {
#[cfg(not(testlib))]
#[cfg(CONFIG_JUMP_LABEL)]
macro_rules! arch_static_branch {
- ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {
+ ($key:path, $keytyp:ty, $($field:ident).+, $branch:expr) => {'my_label: {
$crate::asm!(
include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_static_branch_asm.rs"));
l_yes = label {
break 'my_label true;
},
symb = sym $key,
- off = const ::core::mem::offset_of!($keytyp, $field),
+ off = const ::core::mem::offset_of!($keytyp, $($field).+),
branch = const $crate::jump_label::bool_to_int($branch),
);
@@ -67,7 +70,7 @@ macro_rules! arch_static_branch {
#[cfg(testlib)]
#[cfg(CONFIG_JUMP_LABEL)]
macro_rules! arch_static_branch {
- ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {
+ ($key:path, $keytyp:ty, $($field:ident).+, $branch:expr) => {
// The asm falls through until patched, which never happens on the host.
false
};
--
2.53.0
next prev parent reply other threads:[~2026-10-01 15:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 14:59 [PATCH v3 0/5] Rust dynamic debug support for pr_debug! and dev_dbg! Zhi Wang
2026-10-01 14:59 ` [PATCH v3 1/5] gpu: nova-core: validate firmware versions before debug logging Zhi Wang
2026-10-01 14:59 ` Zhi Wang [this message]
2026-10-01 14:59 ` [PATCH v3 3/5] dynamic_debug: expose printing declarations with the core enabled Zhi Wang
2026-10-01 14:59 ` [PATCH v3 4/5] rust: print: add dynamic debug support to pr_debug! Zhi Wang
2026-10-01 14:59 ` [PATCH v3 5/5] rust: device: add dynamic debug support to dev_dbg! Zhi Wang
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=20261001145940.1077801-3-zhiw@nvidia.com \
--to=zhiw@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=alkumar@nvidia.com \
--cc=andrewjballance@gmail.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=cjia@nvidia.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=kjaju@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=smitra@nvidia.com \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=zhiwang@kernel.org \
/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
all inboxes | Powered by JetHome®