From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
<acourbot@nvidia.com>, <boqun.feng@gmail.com>
Cc: <alex.gaynor@gmail.com>, <ojeda@kernel.org>,
<peterz@infradead.org>, <will@kernel.org>,
<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: Tue, 09 Dec 2025 09:27:25 +0900 [thread overview]
Message-ID: <DET9DDRLLQYT.1LUXV5C3U6ABB@nvidia.com> (raw)
In-Reply-To: <20251209.081456.1519886345847572170.fujita.tomonori@gmail.com>
On Tue Dec 9, 2025 at 8:14 AM JST, FUJITA Tomonori wrote:
> On Mon, 08 Dec 2025 12:08:23 +0900
> "Alexandre Courbot" <acourbot@nvidia.com> wrote:
>
>> 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.
>
> I'm fine with either. Boqun, what do you think?
>
> The reason I didn't put i8/i16 next to i32/i64 is that I assume that
> i8/i16 won't support all the methods supported by i32/i64. I thought
> keeping them separate would make that distinction clearer.
The `AtomicImpl` blocks are the same, it is the macro-implemented blocks
that differ and these can come later. But having all the types and their
basic implementations at the same place helps understanding the basics
of what this module provides IMHO.
>
>>> +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).
>
> // Since i8 and i16 are not expected to support the full feature set
> // of i32 and i64, using the current declare_and_impl_atomic_methods!
> // would require refactoring it to handle specific types or splitting
> // the definitions. Furthermore, supporting Atomic<bool> will require
> // even more significant structural changes.
> //
> // To avoid premature refactoring, a separate macro for i8 and i16 is
> // used for now, leaving the existing macros untouched until the overall
> // design requirements are settled.
>
> makes sense?
Absolutely, thanks! Maybe also give a short explanation for *why* i8 and
i16 won't support the same feature set as i32 and i64.
next prev parent reply other threads:[~2025-12-09 0:27 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
2025-12-08 23:14 ` FUJITA Tomonori
2025-12-09 0:27 ` Alexandre Courbot [this message]
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=DET9DDRLLQYT.1LUXV5C3U6ABB@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