[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z9ejLCnJHvaRWgQ4@Mac.home>
Date: Sun, 16 Mar 2025 21:21:00 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Antonio Hickey <contact@...e-forge.io>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Antonio Hickey <contact@...oniohickey.com>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 09/16] rust: workqueue: refactor to use `&raw
[const|mut]`
On Sun, Mar 16, 2025 at 02:14:18AM -0400, Antonio Hickey wrote:
> Replacing all occurrences of `addr_of!(place)` and `addr_of_mut!(place)`
> with `&raw const place` and `&raw mut place` respectively.
>
> This will allow us to reduce macro complexity, and improve consistency
> with existing reference syntax as `&raw const`, `&raw mut` are similar
> to `&`, `&mut` making it fit more naturally with other existing code.
>
> Suggested-by: Benno Lossin <benno.lossin@...ton.me>
> Link: https://github.com/Rust-for-Linux/linux/issues/1148
> Signed-off-by: Antonio Hickey <contact@...oniohickey.com>
> ---
> rust/kernel/workqueue.rs | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs
> index 0cd100d2aefb..4e27df324d26 100644
> --- a/rust/kernel/workqueue.rs
> +++ b/rust/kernel/workqueue.rs
> @@ -401,9 +401,10 @@ pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl PinInit<Self
> pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct {
> // SAFETY: The caller promises that the pointer is aligned and not dangling.
> //
> - // A pointer cast would also be ok due to `#[repr(transparent)]`. We use `addr_of!` so that
> - // the compiler does not complain that the `work` field is unused.
> - unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).work)) }
> + // A pointer cast would also be ok due to `#[repr(transparent)]`. We use
> + // `&raw const (*ptr).work` so that the compiler does not complain that the
> + // `work` field is unused.
I think we can actually use the pointer casting here. Because now we use
pin-init for Work initialization, so `work` field is always used.
Could you replace this with a:
// CAST: `Work` is transparent to `bindings::work_struct`.
ptr.cast_mut().cast()
in a separate patch?
Thanks!
Regards,
Boqun
> + unsafe { Opaque::raw_get(&raw const (*ptr).work) }
> }
> }
>
> @@ -510,7 +511,7 @@ macro_rules! impl_has_work {
> unsafe fn raw_get_work(ptr: *mut Self) -> *mut $crate::workqueue::Work<$work_type $(, $id)?> {
> // SAFETY: The caller promises that the pointer is not dangling.
> unsafe {
> - ::core::ptr::addr_of_mut!((*ptr).$field)
> + &raw mut (*ptr).$field
> }
> }
> }
> --
> 2.48.1
>
Powered by blists - more mailing lists