public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
	<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
	<ojeda@kernel.org>, <peterz@infradead.org>, <will@kernel.org>
Cc: <a.hindborg@kernel.org>, <aliceryhl@google.com>,
	<bjorn3_gh@protonmail.com>, <dakr@kernel.org>, <gary@garyguo.net>,
	<lossin@kernel.org>, <mark.rutland@arm.com>,
	<rust-for-linux@vger.kernel.org>, <tmgross@umich.edu>
Subject: Re: [PATCH v2 3/4] rust: sync: atomic: Add i8/i16 load and store support
Date: Mon, 08 Dec 2025 12:08:23 +0900	[thread overview]
Message-ID: <DESI62R10XIZ.245BISU72Z2V8@nvidia.com> (raw)
In-Reply-To: <20251117001035.4068507-4-fujita.tomonori@gmail.com>

On Mon Nov 17, 2025 at 9:10 AM JST, FUJITA Tomonori wrote:
> Add atomic operation support for i8 and i16 types using volatile
> read/write and smp_load_acquire/smp_store_release helpers.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
>  rust/kernel/sync/atomic/internal.rs  | 48 ++++++++++++++++++++++++++++
>  rust/kernel/sync/atomic/predefine.rs | 14 +++++++-
>  2 files changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs
> index 6fdd8e59f45b..4c9f4f76dbdf 100644
> --- a/rust/kernel/sync/atomic/internal.rs
> +++ b/rust/kernel/sync/atomic/internal.rs
> @@ -263,3 +263,51 @@ fn fetch_add[acquire, release, relaxed](a: &AtomicRepr<Self>, v: Self::Delta) ->
>          }
>      }
>  );
> +
> +impl private::Sealed for i8 {}
> +impl private::Sealed for i16 {}
> +
> +impl AtomicImpl for i8 {
> +    type Delta = Self;
> +}
> +
> +impl AtomicImpl for i16 {
> +    type Delta = Self;
> +}

I'd suggest putting these next to the impls for `i32` and `i64`, for clarity.

> +
> +macro_rules! impl_atomic_only_load_and_store_ops {
> +    ($($ty:ty),* $(,)?) => {
> +        $(
> +            impl AtomicBasicOps for $ty {
> +                paste! {
> +                    #[inline(always)]
> +                    fn atomic_read(a: &AtomicRepr<Self>) -> Self {
> +                        // SAFETY: `a.as_ptr()` is valid and properly aligned.
> +                        unsafe { bindings::[< atomic_ $ty _load >](a.as_ptr().cast()) }
> +                    }
> +
> +                    #[inline(always)]
> +                    fn atomic_read_acquire(a: &AtomicRepr<Self>) -> Self {
> +                        // SAFETY: `a.as_ptr()` is valid and properly aligned.
> +                        unsafe { bindings::[< atomic_ $ty _load_acquire >](a.as_ptr().cast()) }
> +                    }
> +
> +                    // Generate atomic_set and atomic_set_release
> +                    #[inline(always)]
> +                    fn atomic_set(a: &AtomicRepr<Self>, v: Self) {
> +                        // SAFETY: `a.as_ptr()` is valid and properly aligned.
> +                        unsafe { bindings::[< atomic_ $ty _store >](a.as_ptr().cast(), v) }
> +                    }
> +
> +                    #[inline(always)]
> +                    fn atomic_set_release(a: &AtomicRepr<Self>, v: Self) {
> +                        // SAFETY: `a.as_ptr()` is valid and properly aligned.
> +                        unsafe { bindings::[< atomic_ $ty _store_release >](a.as_ptr().cast(), v) }
> +                    }
> +                }
> +            }
> +        )*
> +    };
> +}

Can you document this macro a bit, in particular the motivations for not
leveraging the existing ones (I guess this has to be with the new
helpers, but following the code through is a bit difficult without
comments).


  reply	other threads:[~2025-12-08  3:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17  0:10 [PATCH v2 0/4] rust: Add i8 and i16 atomic support FUJITA Tomonori
2025-11-17  0:10 ` [PATCH v2 1/4] rust: sync: Add i8/i16 atomic_load_acquire/atomic_store_release helpers FUJITA Tomonori
2025-12-08  3:01   ` Alexandre Courbot
2025-12-08 21:56     ` FUJITA Tomonori
2025-11-17  0:10 ` [PATCH v2 2/4] rust: helpers: Add i8/i16 relaxed atomic helpers FUJITA Tomonori
2025-11-17  0:10 ` [PATCH v2 3/4] rust: sync: atomic: Add i8/i16 load and store support FUJITA Tomonori
2025-12-08  3:08   ` Alexandre Courbot [this message]
2025-12-08 23:14     ` FUJITA Tomonori
2025-12-09  0:27       ` Alexandre Courbot
2025-12-09 23:31         ` FUJITA Tomonori
2025-12-10 23:16           ` Boqun Feng
2025-12-11  5:17             ` FUJITA Tomonori
2025-12-10 23:02       ` Boqun Feng
2025-12-11  4:46         ` FUJITA Tomonori
2025-11-17  0:10 ` [PATCH v2 4/4] rust: sync: atomic: Add store_release/load_acquire tests FUJITA Tomonori
2025-12-03  3:41 ` [PATCH v2 0/4] rust: Add i8 and i16 atomic support FUJITA Tomonori
2025-12-04  3:40   ` Boqun Feng
2025-12-04 13:12     ` FUJITA Tomonori

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=DESI62R10XIZ.245BISU72Z2V8@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=lossin@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --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