Re: [PATCH v2 2/2] locking/atomic/x86: Introduce arch_try_cmpxchg64

From: Uros Bizjak
Date: Sat May 14 2022 - 05:31:35 EST


On Sat, May 14, 2022 at 12:18 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Fri, May 13, 2022 at 05:30:09PM +0200, Uros Bizjak wrote:
>
>
> > +#define arch_try_cmpxchg64(ptr, po, n) \
> > + ((__typeof__(*(ptr)))__try_cmpxchg64((ptr), (unsigned long long *)(po), \
> > + (unsigned long long)(n)))
>
> That doesn't look right (unless it's so late I really can't read
> anymore, in which case ignore me and I'll try again on monday). But the
> return value of try_cmpxchg is bool, not typeof(*ptr).

No, you are right, I was too eager when copying the code from the
above arch_cmpxchg64 definition. Unfortunately, although the cast is
benign and the compiler figures out that the cast is unnecessary, it
doesn't warn here...

Actually, since __try_cmpxchg64 is already bool, we don't need any
cast here, and the definition can be substantially simplified.

Thank you for another pair of eyes - I did eyeball this code
extensively, but the issue slipped through somehow.

Patch v3 is in the works.

Thanks,
Uros.