rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Benno Lossin <benno.lossin@proton.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.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>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: mm: add abstractions for mm_struct and vm_area_struct
Date: Fri, 26 Jul 2024 10:33:05 +0200	[thread overview]
Message-ID: <CAH5fLgg0wh2D5e9Qt6Jg7Cy1-2m2gR0-uDRL5ufoN1HYGNxutw@mail.gmail.com> (raw)
In-Reply-To: <324d3628-a537-431f-8dd4-f33184600537@proton.me>

On Fri, Jul 26, 2024 at 10:26 AM Benno Lossin <benno.lossin@proton.me> wrote:
>
> On 26.07.24 10:14, Alice Ryhl wrote:
> > On Fri, Jul 26, 2024 at 10:11 AM Benno Lossin <benno.lossin@proton.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.
>
> I see, IMO this would be a better comment:
>
> /// Converts to this `MmGet` to `MmGetAsync`.
> ///
> /// `MmGetAsync` uses `mmput_async` instead of `mmput` for decrementing
> /// the refcount.
>
> Since from a Rust perspective, this is just a conversion function. Maybe
> the name should also reflect that ie `to_mm_get_async` or similar.

That sounds good to me.

Alice

  reply	other threads:[~2024-07-26  8:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 14:32 [PATCH] rust: mm: add abstractions for mm_struct and vm_area_struct Alice Ryhl
2024-07-23 14:50 ` Matthew Wilcox
2024-07-23 15:04   ` Alice Ryhl
2024-07-26  8:10 ` Benno Lossin
2024-07-26  8:14   ` Alice Ryhl
2024-07-26  8:26     ` Benno Lossin
2024-07-26  8:33       ` Alice Ryhl [this message]
2024-07-26  8:32   ` Alice Ryhl
2024-07-26 13:36     ` Benno Lossin
2024-07-26 19:04       ` Alice Ryhl

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=CAH5fLgg0wh2D5e9Qt6Jg7Cy1-2m2gR0-uDRL5ufoN1HYGNxutw@mail.gmail.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.gaynor@gmail.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@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).