From: Markus Probst <markus.probst@posteo.de>
To: Gary Guo <gary@garyguo.net>, Danilo Krummrich <dakr@kernel.org>
Cc: "Ayush Singh" <ayush@beagleboard.org>,
"Johan Hovold" <johan@kernel.org>,
"Alex Elder" <elder@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Eric Biggers" <ebiggers@kernel.org>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
greybus-dev@lists.linaro.org, linux-serial@vger.kernel.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
driver-core@lists.linux.dev
Subject: Re: [PATCH 5/5] rust: serdev: Pause receive callback before calling unbind
Date: Sun, 06 Sep 2026 22:51:41 +0000 [thread overview]
Message-ID: <78d42a2753ae84e4983e9a7b118188f9cc8bdf3d.camel@posteo.de> (raw)
In-Reply-To: <DL8IAYDEO7VG.1HPQR4U9S7H2Q@garyguo.net>
[-- Attachment #1: Type: text/plain, Size: 2619 bytes --]
On Sun, 2026-09-06 at 21:13 +0100, Gary Guo wrote:
> On Sun Sep 6, 2026 at 5:20 PM BST, Danilo Krummrich wrote:
> > On Sun Sep 6, 2026 at 5:55 PM CEST, Markus Probst wrote:
> > > @@ -200,10 +203,14 @@ extern "C" fn receive_buf_callback(
> > > // INVARIANT: `sdev` is valid for the duration of `receive_buf_callback()`.
> > > let sdev = unsafe { &*sdev.cast::<Device<device::BoundInternal>>() };
> > >
> > > - // SAFETY: `receive_buf_callback` is only ever called after a successful call to
> > > - // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called
> > > - // and stored a `Pin<KBox<PrivateData<'_, T>>>`.
> > > - let private_data = unsafe { sdev.as_ref().drvdata_borrow::<PrivateData<'_, T>>() };
> > > + // SAFETY:
> > > + // - `receive_buf_callback` is only ever called after a successful call to `probe_callback`,
> > > + // hence it's guaranteed that `Device::set_drvdata()` has been called and stored a
> > > + // `Pin<KBox<PrivateData<'_, T>>>`.
> > > + // - `unbind_callback` calls `serdev_device_pause_rx` before accessing the driver data,
> > > + // which guarantees that this function will not overlap with it. Thus we have exclusive
> > > + // access.
> > > + let private_data = unsafe { sdev.as_ref().drvdata_borrow_mut::<PrivateData<'_, T>>() };
> >
> > This would break the driver core's lifetime design. Any kind of registration
> > (such as class device, auxiliary, IRQ, etc.) may borrow fields from the bus
> > device private data. The whole design is based on the guarantee that we never
> > construct a mutable reference of the bus device private data.
>
> Mutable references should be fine (of course, provided that the bus actually
> serialize callbacks).
The calls do not overlap.
>
> It's only problematic now because in absence of pin-init self-reference, the
> immutable borrow is the only mechanism that prevent user from having multiple
> mutable borrow of the data fields.
Why is having multiple mutable borrows, assuming they are from
different fields, problematic?
>
> Say this code:
>
> struct MyDeviceData<'a> {
> foo: Resource<'a>,
> bar: Resource<'foo>,
> baz: Resource<'bar>,
> }
>
> pin-init would make `foo` and `bar` be only visible immutably in the projection,
> even from `Pin<&mut MyDeviceData<'_>>`, so the design is still sound.
So its only problematic, if the driver data is not pinned?
Thanks
- Markus Probst
>
> Best,
> Gary
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
prev parent reply other threads:[~2026-09-06 22:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-06 15:55 [PATCH 0/5] rust: serdev: Refactor Markus Probst
2026-09-06 15:55 ` [PATCH 1/5] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-09-06 16:08 ` sashiko-bot
2026-09-06 15:55 ` [PATCH 2/5] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-09-06 16:09 ` sashiko-bot
2026-09-06 15:55 ` [PATCH 3/5] rust: serdev: Simplify callbacks Markus Probst
2026-09-06 16:13 ` sashiko-bot
2026-09-06 15:55 ` [PATCH 4/5] rust: Add `Device::drvdata_borrow_mut` Markus Probst
2026-09-06 16:08 ` sashiko-bot
2026-09-06 15:55 ` [PATCH 5/5] rust: serdev: Pause receive callback before calling unbind Markus Probst
2026-09-06 16:11 ` sashiko-bot
2026-09-06 16:20 ` Danilo Krummrich
2026-09-06 17:36 ` Markus Probst
2026-09-06 20:13 ` Gary Guo
2026-09-06 22:51 ` Markus Probst [this message]
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=78d42a2753ae84e4983e9a7b118188f9cc8bdf3d.camel@posteo.de \
--to=markus.probst@posteo.de \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=ayush@beagleboard.org \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=ebiggers@kernel.org \
--cc=elder@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=jirislaby@kernel.org \
--cc=johan@kernel.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.dev \
/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