From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <benno.lossin@proton.me>
Cc: "Lyude Paul" <lyude@redhat.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
"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>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Aakash Sen Sharma" <aakashsensharma@gmail.com>,
"Valentin Obst" <kernel@valentinobst.de>,
"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [PATCH v3 1/3] rust: Introduce irq module
Date: Thu, 15 Aug 2024 09:02:20 -0700 [thread overview]
Message-ID: <Zr4mjM9w16Qlef5B@boqun-archlinux> (raw)
In-Reply-To: <2b139d06-c0e0-4896-8747-d62499aec82f@proton.me>
On Thu, Aug 15, 2024 at 06:40:28AM +0000, Benno Lossin wrote:
[...]
> >>>>
> >>>> I haven't found a problem with `&IrqDisabled` as the closure parameter,
> >>>> but I may miss something.
> >>>
> >>> We could also use `&'a IrqDisabled` instead of `IrqDisabled<'a>` (note
> >>> the first one doesn't have a lifetime). But there is no behavioral
> >>> difference between the two. Originally the intended API was to use `&'a
> >>> IrqDisabled<'a>` as the closure parameter and `IrqDisabled<'a>` in
> >>> functions that require irqs being disabled. As long as we decide on a
> >>> consistent type, I don't mind either (since then we can avoid
> >>> reborrowing).
> >>>
> >>>> So the key ask from me is: it looks like we are on the same page that
> >>>> when `cb` returns, the IRQ should be in the same disabled state as when
> >>>> it gets called. So how do we express this "requirement" then? Type
> >>>> sytem, comments, safety comments?
> >>>
> >>> I don't think that expressing this in the type system makes sense, since
> >>> the type that we select (`&'a IrqDisabled` or `IrqDisabled<'a>`) will be
> >>> `Copy`. And thus you can just produce as many of those as you want.
> >>>
> >
> > Hmm.. on a second thought, `Copy` doesn't affect what I'm proposing
> > here, yes one could have as many `IrqDisabled<'a>` as one wants, but
> > making `cb` returns a `(IrqDisabled<'a>, T)` means the `cb` has to prove
> > at least one of the `IrqDisabled<'a>` exists, i.e. it must prove the irq
> > is still disabled, which the requirement of `with_irqs_disabled`, right?
>
> Yes, but that doesn't do anything. If the token is `Copy`, then we are
> not allowed to have the following API:
>
> fn enable_irq(irq: IrqDisabled<'_>);
>
> Since if the token is `Copy`, you can just copy it, call the function
> and still return an `IrqDisabled<'a>` to satisfy the closure. It only
> adds verbosity IMO.
>
OK, so I think I'm more clear on this, basically, we are all on the same
page that `cb` of `with_irqs_disabled()` should have the same irq
disable state before and after the call. And my proposal of putting this
into type system seems not worthwhile. However, I think that aligns with
something else I also want to propose: users should be allowed to change
the interrupt state inside `cb`, as long as 1) the state is recovered at
last and 2) not other soundness or invalid context issues. Basically, we
give the users as much freedom as possible.
So two things I want to make it clear in the document of
`with_irqs_diabled()`:
1. Users need to make sure the irq state remains the same when `cb`
returns.
2. It's up to the users whether the irq is entirely disabled inside
`cb`, but users have to do it correctly.
Thoughts? Lyude, I think #2 is different than what you have in mind, but
we actually make have users for this. Thoughts?
FYI the following is not uncommon in kernel:
local_irq_save(flags);
while (todo) {
todo = do_sth();
if (too_long) {
local_irq_restore(flags);
if (!irqs_disabled())
sleep();
local_irq_save(flags);
}
}
local_irq_restore(flags);
(of course, usually it makes more sense with local_irq_disable() and
local_irq_enable() here).
Regards,
Boqun
> > Or you're saying there could exist an `IrqDisabled<'a>` but the
> > interrupts are enabled?
>
> No.
>
> ---
> Cheers,
> Benno
>
next prev parent reply other threads:[~2024-08-15 16:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 0:09 [PATCH v3 0/3] rust: Add irq abstraction, SpinLockIrq Lyude Paul
2024-08-02 0:10 ` [PATCH v3 1/3] rust: Introduce irq module Lyude Paul
2024-08-14 17:10 ` Boqun Feng
2024-08-14 17:35 ` Boqun Feng
2024-08-14 19:38 ` Lyude Paul
2024-08-14 20:17 ` Boqun Feng
2024-08-14 20:44 ` Benno Lossin
2024-08-14 20:57 ` Boqun Feng
2024-08-15 4:53 ` Boqun Feng
2024-08-15 6:40 ` Benno Lossin
2024-08-15 16:02 ` Boqun Feng [this message]
2024-08-15 21:05 ` Lyude Paul
2024-08-15 21:31 ` Lyude Paul
2024-08-15 21:46 ` Benno Lossin
2024-08-15 22:13 ` Lyude Paul
2024-08-16 15:28 ` Boqun Feng
2024-08-15 21:41 ` Benno Lossin
2024-08-15 21:43 ` Lyude Paul
2024-08-15 20:31 ` Lyude Paul
2024-08-15 21:48 ` Benno Lossin
2024-08-26 11:21 ` Dirk Behme
2024-08-26 14:21 ` Boqun Feng
2024-08-26 14:59 ` Dirk Behme
2024-08-26 15:34 ` Boqun Feng
2024-08-02 0:10 ` [PATCH v3 2/3] rust: sync: Introduce lock::Backend::Context Lyude Paul
2024-08-20 10:26 ` Dirk Behme
2024-08-02 0:10 ` [PATCH v3 3/3] rust: sync: Add SpinLockIrq Lyude Paul
2024-08-13 20:26 ` [PATCH v3 0/3] rust: Add irq abstraction, SpinLockIrq Lyude Paul
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=Zr4mjM9w16Qlef5B@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=aakashsensharma@gmail.com \
--cc=airlied@redhat.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.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=tglx@linutronix.de \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
/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