Re: [PATCH 2/2] rust: sync: atomic: Add atomic operation helpers over raw pointers
From: Gary Guo
Date: Tue Jan 20 2026 - 08:26:04 EST
On Tue Jan 20, 2026 at 11:52 AM GMT, Boqun Feng wrote:
> In order to synchronize with C or external, atomic operations over raw
The sentence feels incomplete. Maybe "external memory"? Also "atomic operations
over raw pointers" isn't a full setence.
> pointers, althought previously there is always an `Atomic::from_ptr()`
You mean "already an"?
> to provide a `&Atomic<T>`. However it's more convenient to have helpers
> that directly perform atomic operations on raw pointers. Hence a few are
> added, which are basically a `Atomic::from_ptr().op()` wrapper.
>
> Note: for naming, since `atomic_xchg()` and `atomic_cmpxchg()` has a
> conflict naming to 32bit C atomic xchg/cmpxchg, hence they are just
> named as `xchg()` and `cmpxchg()`. For `atomic_load()` and
> `atomic_store()`, their 32bit C counterparts are `atomic_read()` and
> `atomic_set()`, so keep the `atomic_` prefix.
I still have reservation on if this is actually needed. Directly reading from C
should be rare enough that `Atomic::from_ptr().op()` isn't a big issue. To me,
`Atomic::from_ptr` has the meaning of "we know this is a field that needs atomic
access, but bindgen can't directly generate a `Atomic<T>`", and it will
encourage one to check if this is actually true, while `atomic_op` doesn't feel
the same.
That said, if it's decided that this is indeed needed, then
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
with the grammar in the commit message fixed.
Best,
Gary
>
> Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> ---
> rust/kernel/sync/atomic.rs | 104 +++++++++++++++++++++++++++
> rust/kernel/sync/atomic/predefine.rs | 46 ++++++++++++
> 2 files changed, 150 insertions(+)