lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <90bfcb3e-dee1-4f78-a1b2-02ce99db4997@openatom.club>
Date: Wed, 5 Nov 2025 21:55:27 +0800
From: "Chen Miao" <chenmiao@...natom.club>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, 
	"Boqun Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>, 
	Björn Roy Baron <bjorn3_gh@...tonmail.com>, 
	"Benno Lossin" <lossin@...nel.org>, 
	"Andreas Hindborg" <a.hindborg@...nel.org>, 
	"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>, 
	"Steven Rostedt (Google)" <rostedt@...dmis.org>, 
	"open list:RUST" <rust-for-linux@...r.kernel.org>, 
	"open list" <linux-kernel@...r.kernel.org>, 
	<hust-os-kernel-patches@...glegroups.com>
Subject: Re: [PATCH] rust: kernel: Support more jump_label api

On 11/5/2025 9:38 PM, Alice Ryhl wrote:
> On Wed, Nov 05, 2025 at 09:28:39PM +0800, Chen Miao wrote:
>> On 11/4/2025 10:07 PM, Alice Ryhl wrote:
>>> On Tue, Nov 04, 2025 at 02:04:17AM +0000, chenmiao wrote:
>>>> The initial implementation of arch_static_branch was achieved by accessing
>>>> the offset from the original type. However, this approach extended the
>>>> path and introduced redundant calculations when dealing with types like
>>>> `static_key_true/false`, as shown below:
>>>>
>>>> ```
>>>> static_brach_unlikely(tp, tracepoint, key)
>>>>     => tracepoint->key->key
>>>>     => &tracepoint->key(static_key_false) == &tracepoint->key.key(static_key)
>>>>     => off: tracepoint->key - tracepoint
>>>> ```
>>>>
>>>> In practice, the implementation of `arch_static_branch` overlooked many
>>>> detailed descriptions. To improve clarity, additional comments have been
>>>> added to the original logic. The approach has been modified to directly
>>>> locate the corresponding `static_key` instead of using offsets, thereby
>>>> reducing  computational overhead.
>>>>
>>>> If finding the offset from the primitive type is necessary for this
>>>> implementation, I will abandon this change.
>>>>
>>>> Additionally, support for the `static_branch_enable/disable` APIs has been
>>>> introduced.
>>>>
>>>> Signed-off-by: chenmiao <chenmiao@...natom.club>
>>>> +    ($basety:ty, $branch:expr, $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 $basety = ::core::ptr::addr_of!((*_key).$field);
>>>>            let _key: *const $crate::bindings::static_key = _key.cast();
>>>>    
>>>>            #[cfg(not(CONFIG_JUMP_LABEL))]
>>>> @@ -30,7 +71,88 @@ 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, $branch }
>>>> +        }
>>> So ... this is changing from $key to _key. That's replacing the global
>>> variable with a local variable holding a pointer to the global variable.
>>> However, the arch_static_branch! macro uses the `sym` operand which
>>> requires you to pass it the global directly.
>>>
>>> Did you try this code? I don't believe it will work.
>>>
>>> Alice
>> I'm very sorry for making a fatal mistake. My misunderstanding of sym led to
>> this issue, so I shouldn't make any changes to that part. However, regarding
>> the other modifications, I believe it is necessary to support the direct
>> passing of structures similar to `static_key_false`, just as in C language.
> It sounds like you are adding a new use-case for this macro. Can you
> provide more information for this new feature? It is currently unclear
> to me exactly how this will be used.
>
> Alice

If there's a binding-required driver implementation in the future where a key 
function uses if (static_branch_unlikely(&zoned_enabled))— defined by 
DEFINE_STATIC_KEY_FALSE(zoned_enabled);— then in Rust we can directly 
implement it using if static_branch_unlikely!(zoned_enabled), without having 
to call it via if static_branch_unlikely!(zoned_enabled, 
bindings::static_key_false, key).

static_branch_unlikely!(zoned_enabled) instead of 
static_branch_unlikely!(zoned_enabled, bindings::static_key_false, key).

Chen Miao

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ