Re: [PATCH v2] atomics: fix atomic64_{read_acquire,set_release} fallbacks

From: Mark Rutland
Date: Fri Feb 04 2022 - 06:16:11 EST


On Fri, Feb 04, 2022 at 08:20:25AM +0800, Boqun Feng wrote:
> On Thu, Feb 03, 2022 at 04:12:43PM +0000, Mark Rutland wrote:
> > diff --git a/include/linux/atomic/atomic-arch-fallback.h b/include/linux/atomic/atomic-arch-fallback.h
> > index a3dba31df01e..6db58d180866 100644
> > --- a/include/linux/atomic/atomic-arch-fallback.h
> > +++ b/include/linux/atomic/atomic-arch-fallback.h
> > @@ -151,7 +151,16 @@
> > static __always_inline int
> > arch_atomic_read_acquire(const atomic_t *v)
> > {
> > - return smp_load_acquire(&(v)->counter);
> > + int ret;
> > +
> > + if (__native_word(atomic_t)) {
> > + ret = smp_load_acquire(&(v)->counter);
> > + } else {
> > + ret = arch_atomic_read(v);
> > + __atomic_acquire_fence();
> > + }
> > +
> > + return ret;
> > }
> > #define arch_atomic_read_acquire arch_atomic_read_acquire
> > #endif
> > @@ -160,7 +169,12 @@ arch_atomic_read_acquire(const atomic_t *v)
> > static __always_inline void
> > arch_atomic_set_release(atomic_t *v, int i)
> > {
> > - smp_store_release(&(v)->counter, i);
> > + if (__native_word(atomic_t)) {
> > + smp_store_release(&(v)->counter, i);
> > + } else {
> > + __atomic_release_fence();
> > + arch_atomic_set(v, i);
> > + }
> > }
>
> The changes for atomic_t are not necessary, right? They are correct but
> "side effects" because of the change in scripts.

Correct -- those aren't necessary, but aren't harmful, and it's simpler to have
than than it is to special-case the scripts.

> If so, it's better to mention this somewhere.

Sure; how about I add the following to the commit message:

| Since the fallback templates are used to generate the atomic64_*() and
| atomic_*() operations, the __native_word() check is added to both. For
| the atomic_*() operations, which are always 32-bit, the __native_word()
| check is redundant but not harmful, as it is always true.

... ?

Thanks,
Mark.