From: Boqun Feng <boqun.feng@gmail.com>
To: Antonio Hickey <contact@byte-forge.io>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Antonio Hickey" <contact@antoniohickey.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 09/16] rust: workqueue: refactor to use `&raw [const|mut]`
Date: Sun, 16 Mar 2025 21:21:00 -0700 [thread overview]
Message-ID: <Z9ejLCnJHvaRWgQ4@Mac.home> (raw)
In-Reply-To: <20250316061429.817126-10-contact@antoniohickey.com>
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@proton.me>
> Link: https://github.com/Rust-for-Linux/linux/issues/1148
> Signed-off-by: Antonio Hickey <contact@antoniohickey.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
>
next prev parent reply other threads:[~2025-03-17 4:21 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-16 6:14 [PATCH v4 00/16] rust: refactor to utilize `&raw [const|mut]` Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 01/16] rust: enable `raw_ref_op` feature Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 02/16] rust: init: refactor to use `&raw [const|mut]` Antonio Hickey
2025-03-16 10:14 ` Benno Lossin
2025-03-16 6:14 ` [PATCH v4 03/16] rust: list: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 04/16] rust: task: " Antonio Hickey
2025-03-17 4:00 ` Boqun Feng
2025-03-16 6:14 ` [PATCH v4 05/16] rust: faux: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 06/16] rust: platform: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 07/16] rust: pci: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 08/16] rust: kunit: " Antonio Hickey
2025-03-18 8:02 ` David Gow
2025-03-20 1:39 ` Antonio Hickey
2025-03-20 23:15 ` Miguel Ojeda
2025-03-21 2:28 ` David Gow
2025-03-21 17:06 ` Boqun Feng
2025-03-21 19:04 ` Miguel Ojeda
2025-03-21 19:01 ` Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 09/16] rust: workqueue: " Antonio Hickey
2025-03-17 4:21 ` Boqun Feng [this message]
2025-03-17 4:32 ` Boqun Feng
2025-03-16 6:14 ` [PATCH v4 10/16] rust: rbtree: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 11/16] rust: net: phy: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 12/16] rust: sync: arc: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 13/16] rust: jump_label: " Antonio Hickey
2025-03-16 6:14 ` [PATCH v4 14/16] rust: fs: file: " Antonio Hickey
2025-03-17 4:33 ` Boqun Feng
2025-03-16 6:14 ` [PATCH v4 15/16] rust: block: " Antonio Hickey
2025-03-17 4:04 ` Boqun Feng
2025-03-16 6:14 ` [PATCH v4 16/16] rust: clippy: disable `addr_of[_mut]!` macros Antonio Hickey
2025-03-16 9:50 ` Benno Lossin
2025-03-16 12:57 ` Tamir Duberstein
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=Z9ejLCnJHvaRWgQ4@Mac.home \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=contact@antoniohickey.com \
--cc=contact@byte-forge.io \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.