[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLggDDXmD8Nj-r0_bbEfquuKfOeH7bJkcA4GA=kKk8=gi7w@mail.gmail.com>
Date: Fri, 26 Jul 2024 10:14:53 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: Miguel Ojeda <ojeda@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>,
Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Andreas Hindborg <a.hindborg@...sung.com>, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH] rust: mm: add abstractions for mm_struct and vm_area_struct
On Fri, Jul 26, 2024 at 10:11 AM Benno Lossin <benno.lossin@...ton.me> wrote:
>
> On 23.07.24 16:32, Alice Ryhl wrote:
> > +pub struct MmGet {
> > + mm: NonNull<bindings::mm_struct>,
> > +}
> > +
> > +impl MmGet {
> > + /// Lock the mmap read lock.
> > + #[inline]
> > + pub fn mmap_write_lock(&self) -> MmapWriteLock<'_> {
> > + // SAFETY: The pointer is valid since we hold a refcount.
> > + unsafe { bindings::mmap_write_lock(self.mm.as_ptr()) };
> > +
> > + // INVARIANT: We just acquired the write lock, so we can transfer to this guard.
> > + //
> > + // The signature of this function ensures that the `MmapWriteLock` will not outlive this
> > + // `mmget` refcount.
> > + MmapWriteLock {
> > + mm: self.mm,
> > + _lifetime: PhantomData,
> > + }
> > + }
> > +
> > + /// When dropping this refcount, use `mmput_async` instead of `mmput`.
>
> I don't get this comment.
The C side provides two ways to decrement the mmget refcount. One is
mmput and the other is mmput_async. The difference is that when the
refcount hits zero, mmput_async cleans up the mm_struct on the
workqueue, whereas mmput cleans it up immediately. This means that
mmput_async is safe in atomic context, but mmput is not.
Alice
Powered by blists - more mailing lists