From: Benno Lossin <benno.lossin@proton.me>
To: Lyude Paul <lyude@redhat.com>, rust-for-linux@vger.kernel.org
Cc: "Danilo Krummrich" <dakr@redhat.com>,
airlied@redhat.com, "Ingo Molnar" <mingo@redhat.com>,
"Will Deacon" <will@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@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@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Aakash Sen Sharma" <aakashsensharma@gmail.com>,
"Valentin Obst" <kernel@valentinobst.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] rust: Introduce irq module
Date: Fri, 26 Jul 2024 19:39:21 +0000 [thread overview]
Message-ID: <6e13df3f-6132-43c3-aaba-98b9b9ddd48e@proton.me> (raw)
In-Reply-To: <27110c6b7d4674e1003417fc8b5a03bde1eed4ef.camel@redhat.com>
On 26.07.24 20:18, Lyude Paul wrote:
> On Fri, 2024-07-26 at 07:23 +0000, Benno Lossin wrote:
>> On 26.07.24 00:27, Lyude Paul wrote:
>>> +}
>>> +
>>> +/// Run the closure `cb` with interrupts disabled on the local CPU.
>>> +///
>>> +/// Interrupts will be re-enabled once the closure returns. If interrupts were already disabled on
>>> +/// this CPU, this is a no-op.
>>> +#[inline]
>>> +pub fn with_irqs_disabled<T, F>(cb: F) -> T
>>> +where
>>> + F: FnOnce(IrqDisabled<'_>) -> T,
>>> +{
>>> + // SAFETY: FFI call with no special requirements
>>
>> I vaguely remember that there were some problems with sleeping in IRQ
>> disabled contexts, is that me just misremembering (eg confusing it with
>> atomic context), or do we need to watch out for that?
>
> You're correct - sleeping isn't allowed in no-irq contexts.
>
>> Because if that is the case, then we would need to use klint.
>
> Ok - I've never used klint before but I'm happy to look into it and try to
> implement something for it.
I am not 100% up to date, last time I heard Gary (the maintainer/author
of klint) talk about it, I remember that it wasn't fully ready for this
stuff. Don't know if this has changed in the meantime.
I don't think this is anything that you can do much, since it's rather
complex, so I will just ping Gary on the status.
> FWIW too: I assume we would still want klint anyway, but I think it's at least
> worth mentioning the kernel does have a compile option for WARNing on sleeps
> in sleepless contexts
So the plan always was to not make it a hard error. Essentially instead
of having `unsafe` littered al over the place when you switch context,
klint would ensure (like the borrow checker for ownership) that
everything is fine.
>>> + let flags = unsafe { bindings::local_irq_save() };
>>> +
>>> + let ret = cb(IrqDisabled(PhantomData));
>>> +
>>> + // SAFETY: `flags` comes from our previous call to local_irq_save
>>> + unsafe { bindings::local_irq_restore(flags) };
>>
>> Just to make sure, this function only enables interrupts, if they were
>> enabled before the call to `local_irq_save` above, right?
>
> Correct - `local_irq_save()` only saves the CPU's current IRQ flags. So if
> interrupts were already disabled in the context we call `local_irq_save()`, we
> end up restoring the same IRQ-disabled flags on the processor when we get to
> `local_irq_restore()`. This is also why the closure interface for this is
> necessary - to ensure that nested interrupt flag saves are always undone in
> the reverse order to ensure this assumption always holds.
Thanks, that was exactly what I assumed.
---
Cheers,
Benno
next prev parent reply other threads:[~2024-07-26 19:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 22:27 [PATCH 0/3] rust: Add irq abstraction, IrqSpinLock Lyude Paul
2024-07-25 22:27 ` [PATCH 1/3] rust: Introduce irq module Lyude Paul
2024-07-26 5:39 ` Greg KH
2024-07-26 17:45 ` Lyude Paul
2024-07-26 7:23 ` Benno Lossin
2024-07-26 18:18 ` Lyude Paul
2024-07-26 19:39 ` Benno Lossin [this message]
2024-07-26 10:13 ` Trevor Gross
2024-07-26 21:21 ` Boqun Feng
2024-07-26 21:30 ` Benno Lossin
2024-07-26 21:40 ` Boqun Feng
2024-07-25 22:27 ` [PATCH 2/3] rust: sync: Introduce LockContainer trait Lyude Paul
2024-07-26 7:40 ` Benno Lossin
2024-07-26 18:20 ` Lyude Paul
2024-07-25 22:27 ` [PATCH 3/3] rust: sync: Add IrqSpinLock Lyude Paul
2024-07-26 7:48 ` Peter Zijlstra
2024-07-26 18:29 ` Lyude Paul
2024-07-26 20:21 ` Lyude Paul
2024-07-26 20:26 ` Peter Zijlstra
2024-07-27 11:21 ` kernel test robot
2024-07-26 5:39 ` [PATCH 0/3] rust: Add irq abstraction, IrqSpinLock Greg KH
2024-07-26 17:52 ` Lyude Paul
2024-07-26 18:47 ` Lyude Paul
2024-07-26 10:50 ` Trevor Gross
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=6e13df3f-6132-43c3-aaba-98b9b9ddd48e@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@samsung.com \
--cc=aakashsensharma@gmail.com \
--cc=airlied@redhat.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@redhat.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=kernel@valentinobst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=lyude@redhat.com \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
--cc=yakoyoku@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).