[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250221160217.2a6772c3@eugeo>
Date: Fri, 21 Feb 2025 16:02:17 +0000
From: Gary Guo <gary@...yguo.net>
To: Tamir Duberstein <tamird@...il.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>, Andreas
Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, Trevor
Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, Will Deacon
<will@...nel.org>, Peter Zijlstra <peterz@...radead.org>, Mark Rutland
<mark.rutland@....com>, Lyude Paul <lyude@...hat.com>, Wedson Almeida Filho
<wedsonaf@...il.com>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 1/4] rust: implement `kernel::sync::Refcount`
On Wed, 19 Feb 2025 17:12:19 -0500
Tamir Duberstein <tamird@...il.com> wrote:
> On Wed, Feb 19, 2025 at 3:17 PM Gary Guo <gary@...yguo.net> wrote:
> >
> > This is a wrapping layer of `include/linux/refcount.h`. Currently the
> > kernel refcount has already been used in `Arc`, however it calls into
> > FFI directly.
> >
> > Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> > Reviewed-by: Boqun Feng <boqun.feng@...il.com>
> > Signed-off-by: Gary Guo <gary@...yguo.net>
> > ---
> > rust/helpers/refcount.c | 10 +++++
> > rust/kernel/sync.rs | 2 +
> > rust/kernel/sync/refcount.rs | 86 ++++++++++++++++++++++++++++++++++++
> > 3 files changed, 98 insertions(+)
> > create mode 100644 rust/kernel/sync/refcount.rs
> >
>
> <snip>
>
> > + /// Decrement a refcount.
> > + ///
> > + /// It will `WARN` on underflow and fail to decrement when saturated.
> > + ///
> > + /// Provides release memory ordering, such that prior loads and stores are done
> > + /// before.
> > + #[inline]
> > + pub fn dec(&self) {
> > + // SAFETY: `self.as_ptr()` is valid.
> > + unsafe { bindings::refcount_dec(self.as_ptr()) }
> > + }
> > +
> > + /// Decrement a refcount and test if it is 0.
> > + ///
> > + /// It will `WARN` on underflow and fail to decrement when saturated.
> > + ///
> > + /// Provides release memory ordering, such that prior loads and stores are done
> > + /// before, and provides an acquire ordering on success such that memory deallocation
> > + /// must come after.
> > + ///
> > + /// Returns true if the resulting refcount is 0, false otherwise.
> > + #[inline]
> > + #[must_use = "use `dec` instead you do not need to test if it is 0"]
>
> The word "if" seems to be missing?
Ack
>
> The C function comment includes this bit:
>
> * Use of this function is not recommended for the normal reference counting
> * use case in which references are taken and released one at a time. In these
> * cases, refcount_dec(), or one of its variants, should instead be used to
> * decrement a reference count.
>
> Do we need to include this warning?
I think you're referring to refcount_sub_and_test? This is
refcount_dec_and_test.
Best,
Gary
>
>
> [...]
Powered by blists - more mailing lists