Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v5 3/4] rust: serdev: Replace `active` mutex with receive pause
Date: Thu, 22 Oct 2026 12:04:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-181411@kernel.org> (raw)
In-Reply-To: <20261022-rust_serdev_probe_refactor-v5-3-a27d862a415a@posteo.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] rust: serdev: mutable borrow of shared ref in remove_callback()
--

commit 7873e32e25475629867563ba84c28fd279d7f25d
Author: Markus Probst <markus.probst@posteo.de>

rust: serdev: Replace active mutex with receive pause

This commit replaces the active mutex in the Rust serdev abstraction with
serdev_device_pause_rx() and serdev_device_resume_rx() to fix race
conditions during probe failure and driver unbind.

> diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
> index 17ca504b7f8d6..c16d6593a8d2d 100644
> --- a/rust/kernel/serdev.rs
> +++ b/rust/kernel/serdev.rs
[ ... ]
> @@ -231,6 +198,12 @@ extern "C" fn remove_callback(sdev: *mut bindings::serdev_device) {
>          let data_pinned = unsafe { Pin::new_unchecked(data.assume_init_ref()) };
>  
>          T::unbind(sdev, data_pinned);
> +
> +        // SAFETY: `sdev.as_raw()` is guaranteed to be a valid pointer to `serdev_device`.
> +        unsafe { bindings::serdev_device_pause_rx(sdev.as_raw()) };
> +
> +        // SAFETY: We already established that `data` is guaranteed to be initialized.
> +        unsafe { data.assume_init_drop() };
>      }

[Severity: Medium]
Does Adapter::remove_callback() in rust/kernel/serdev.rs fail to compile
when building this commit with CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS=y?

Earlier in Adapter::remove_callback(), data is bound as an immutable
shared reference of type &MaybeUninit<T::Data<'_>>:

    let data = unsafe { &*private_data.driver.get() };
    let data_pinned = unsafe { Pin::new_unchecked(data.assume_init_ref()) };

    T::unbind(sdev, data_pinned);

Because MaybeUninit::assume_init_drop(&mut self) requires a mutable
reference, calling data.assume_init_drop() fails with rustc error E0596
(cannot borrow *data as mutable, as it is behind a & reference).

Since receive_buf_callback() can still run concurrently during T::unbind()
and create a shared reference to *private_data.driver.get() before
serdev_device_pause_rx() is called, data cannot be changed to a mutable
reference at the start of remove_callback().

Although a later commit in this series ("rust: serdev: Simplify callbacks")
refactors PrivateData to store T::Data directly and removes the
assume_init_drop() call, should this commit dereference the UnsafeCell
pointer directly after serdev_device_pause_rx() establishes exclusive
access:

    unsafe { (*private_data.driver.get()).assume_init_drop() };

so that git bisection and standalone backporting remain unbroken?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261022-rust_serdev_probe_refactor-v5-0-a27d862a415a@posteo.de?part=3

  reply	other threads:[~2026-10-22 12:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 11:51 [PATCH v5 0/4] rust: serdev: Refactor Markus Probst
2026-10-22 11:51 ` [PATCH v5 1/4] tty: serdev: Add mutex lock Markus Probst
2026-10-22 12:19   ` sashiko-bot
2026-10-22 11:51 ` [PATCH v5 2/4] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-10-22 11:59   ` sashiko-bot
2026-10-22 11:51 ` [PATCH v5 3/4] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-10-22 12:04   ` sashiko-bot [this message]
2026-10-22 12:14     ` Markus Probst
2026-10-22 11:51 ` [PATCH v5 4/4] rust: serdev: Simplify callbacks Markus Probst
2026-10-22 12:00   ` sashiko-bot

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=sashiko-outbox-181411@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-serial@vger.kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.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