From: Christian Schrefl <chrisi.schrefl@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Lee Jones" <lee@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Benno Lossin" <lossin@kernel.org>
Cc: "Gerald Wisböck" <gerald.wisboeck@feather.ink>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/3] rust: miscdevice: add additional data to `MiscDeviceRegistration`
Date: Sat, 7 Jun 2025 22:10:56 +0200 [thread overview]
Message-ID: <e613d12e-92d1-4746-9012-5194fa1cbecf@gmail.com> (raw)
In-Reply-To: <20250607-b4-rust_miscdevice_registrationdata-v5-2-b77b5b7aab5b@gmail.com>
On 07.06.25 2:07 PM, Christian Schrefl wrote:
> @@ -178,18 +214,29 @@ impl<T: MiscDevice> MiscdeviceVTable<T> {> // SAFETY: The open call of a file can access the private data.
> let misc_ptr = unsafe { (*raw_file).private_data };
>
> - // SAFETY: This is a miscdevice, so `misc_open()` set the private data to a pointer to the
> - // associated `struct miscdevice` before calling into this method. Furthermore,
> - // `misc_open()` ensures that the miscdevice can't be unregistered and freed during this
> - // call to `fops_open`.
> - let misc = unsafe { &*misc_ptr.cast::<MiscDeviceRegistration<T>>() };
> + // This is a miscdevice, so `misc_open()` sets the private data to a pointer to the
> + // associated `struct miscdevice` before calling into this method.
> + let misc_ptr = misc_ptr.cast::<Opaque<bindings::miscdevice>>();
> +
> + // SAFETY:
> + // * `misc_open()` ensures that the `struct miscdevice` can't be unregistered and freed
> + // during this call to `fops_open`.
> + // * The `misc_ptr` always points to the `inner` field of a `MiscDeviceRegistration<T>`.
> + // * The `MiscDeviceRegistration<T>` is valid until the `struct miscdevice` was
> + // unregistered.
> + // * `MiscDeviceRegistration<T>` is `Send` since `MiscDeviceRegistration::register` has a
> + // `Self: Send` bound and is the only way to create a `MiscDeviceRegistration`. This
> + // means that a reference to it can be shared between contexts.
> + // TODO: add `assert_sync` for `MiscDeviceRegistration<T>` and
> + // `MiscDeviceRegistration<T>::Data`.
After trying this out it this needs `: Sync` bounds on this impl block and
the `MiscDeviceOptions::into_raw` in addition to the register function.
That's not great, but could be worse.
> + let registration = unsafe { &*container_of!(misc_ptr, MiscDeviceRegistration<T>, inner) };
>
> // SAFETY:
> // * This underlying file is valid for (much longer than) the duration of `T::open`.
> // * There is no active fdget_pos region on the file on this thread.
> let file = unsafe { File::from_raw_file(raw_file) };
>
> - let ptr = match T::open(file, misc) {
> + let ptr = match T::open(file, registration) {
> Ok(ptr) => ptr,
> Err(err) => return err.to_errno(),
> };
next prev parent reply other threads:[~2025-06-07 20:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-07 12:07 [PATCH v5 0/3] rust: miscdevice: add additional data to MiscDeviceRegistration Christian Schrefl
2025-06-07 12:07 ` [PATCH v5 1/3] rust: implement `Wrapper<T>` for `Opaque<T>` Christian Schrefl
2025-06-08 11:42 ` Miguel Ojeda
2025-06-08 11:43 ` Christian Schrefl
2025-06-07 12:07 ` [PATCH v5 2/3] rust: miscdevice: add additional data to `MiscDeviceRegistration` Christian Schrefl
2025-06-07 20:10 ` Christian Schrefl [this message]
2025-06-07 12:07 ` [PATCH v5 3/3] rust: miscdevice: adjust the `rust_misc_device` sample to use `Data` Christian Schrefl
2025-06-08 11:19 ` [PATCH v5 0/3] rust: miscdevice: add additional data to MiscDeviceRegistration Danilo Krummrich
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=e613d12e-92d1-4746-9012-5194fa1cbecf@gmail.com \
--to=chrisi.schrefl@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gerald.wisboeck@feather.ink \
--cc=gregkh@linuxfoundation.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@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 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®