[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DF4ITDTG0RQH.8VVU1YY3RC6T@kernel.org>
Date: Mon, 22 Dec 2025 07:10:48 +0100
From: "Benno Lossin" <lossin@...nel.org>
To: "Lyude Paul" <lyude@...hat.com>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, "Thomas Gleixner" <tglx@...utronix.de>
Cc: "Boqun Feng" <boqun.feng@...il.com>, "Daniel Almeida"
<daniel.almeida@...labora.com>, "Miguel Ojeda" <ojeda@...nel.org>, "Alex
Gaynor" <alex.gaynor@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>,
"Andrew Morton" <akpm@...ux-foundation.org>, "Peter Zijlstra"
<peterz@...radead.org>, "Ingo Molnar" <mingo@...hat.com>, "Will Deacon"
<will@...nel.org>, "Waiman Long" <longman@...hat.com>
Subject: Re: [PATCH v16 10/17] rust: sync: Introduce lock::Backend::Context
On Mon Dec 15, 2025 at 6:57 PM CET, Lyude Paul wrote:
> Now that we've introduced an `InterruptDisabled` token for marking
> contexts in which IRQs are disabled, we can have a way to avoid
> `SpinLockIrq` disabling interrupts if the interrupts have already been
> disabled. Basically, a `SpinLockIrq` should work like a `SpinLock` if
> interrupts are disabled. So a function:
>
> (&'a SpinLockIrq, &'a InterruptDisabled) -> Guard<'a, .., SpinLockBackend>
>
> makes senses. Note that due to `Guard` and `InterruptDisabled` having the
> same lifetime, interrupts cannot be enabled while the Guard exists.
>
> Add a `lock_with()` interface for `Lock`, and an associate type of
> `Backend` to describe the context.
This message doesn't mention `Context`, which is included in the title
and the message itself isn't written in imperative style. I'd recommend
putting the `lock_with` in the title, since that is the important part.
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> Co-developed-by: Boqun Feng <boqun.feng@...il.com>
> Signed-off-by: Boqun Feng <boqun.feng@...il.com>
>
> ---
> V10:
> - Fix typos - Dirk
>
> rust/kernel/sync/lock.rs | 12 +++++++++++-
> rust/kernel/sync/lock/mutex.rs | 1 +
> rust/kernel/sync/lock/spinlock.rs | 4 +++-
> 3 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index 46a57d1fc309d..bf2d94c1999bd 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -44,6 +44,9 @@ pub unsafe trait Backend {
> /// [`unlock`]: Backend::unlock
> type GuardState;
>
> + /// The context which can be provided to acquire the lock with a different backend.
> + type Context<'a>;
> +
> /// Initialises the lock.
> ///
> /// # Safety
> @@ -168,8 +171,15 @@ pub unsafe fn from_raw<'a>(ptr: *mut B::State) -> &'a Self {
> }
>
> impl<T: ?Sized, B: Backend> Lock<T, B> {
> + /// Acquires the lock with the given context and gives the caller access to the data protected
> + /// by it.
I feel like this "it" could refer to both the lock and the context, so
it's best to repeat "the lock" here.
> + pub fn lock_with<'a>(&'a self, _context: B::Context<'a>) -> Guard<'a, T, B> {
> + todo!()
> + }
> +
> /// Acquires the lock and gives the caller access to the data protected by it.
> - pub fn lock(&self) -> Guard<'_, T, B> {
> + #[inline]
This change isn't in the message? Is it intended to be here or somewhere
else?
Cheers,
Benno
> + pub fn lock<'a>(&'a self) -> Guard<'a, T, B> {
> // SAFETY: The constructor of the type calls `init`, so the existence of the object proves
> // that `init` was called.
> let state = unsafe { B::lock(self.state.get()) };
Powered by blists - more mailing lists