lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgg0wh2D5e9Qt6Jg7Cy1-2m2gR0-uDRL5ufoN1HYGNxutw@mail.gmail.com>
Date: Fri, 26 Jul 2024 10:33:05 +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:26 AM Benno Lossin <benno.lossin@...ton.me> wrote:
>
> On 26.07.24 10:14, Alice Ryhl wrote:
> > 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.
>
> 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ