Re: [PATCHv2 11/11] arm64: use instrumented atomics

From: Mark Rutland
Date: Wed Jul 04 2018 - 12:37:32 EST


On Wed, Jul 04, 2018 at 04:24:22PM +0100, Will Deacon wrote:
> On Mon, Jun 25, 2018 at 11:59:52AM +0100, Mark Rutland wrote:
> > Now that the generic atomic headers provide instrumented wrappers of all
> > the atomics implemented by arm64, let's migrate arm64 over to these.
> >
> > The additional instrumentation will help to find bugs (e.g. when fuzzing
> > with Syzkaller).
> >
> > Mostly this change involes adding an arch_ prefix to a number of
> > function names and macro definitions. Due to the way we call the LL/SC
> > atomics via the LSE atomic wrappers, this requires adding an arch_
> > prefix to some arm64-specific atomic primitives.
> >
> > Some unusual whitespace in the cmpxchg wrappers is fixed up as part of
> > the change.
> >
> > Signed-off-by: Mark Rutland <mark.rutland@xxxxxxx>
> > Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> > Cc: Will Deacon <will.deacon@xxxxxxx>
> > ---
> > arch/arm64/include/asm/atomic.h | 237 ++++++++++++++++++-----------------
> > arch/arm64/include/asm/atomic_lse.h | 51 ++++----
> > arch/arm64/include/asm/cmpxchg.h | 106 ++++++++--------
> > arch/arm64/include/asm/lse.h | 2 +-
> > arch/arm64/include/asm/sync_bitops.h | 16 +--
> > 5 files changed, 212 insertions(+), 200 deletions(-)
>
> This is mostly straightforward, but the cmpxchg/cmpxchg_double cases grow
> an 'arch' prefix which suggests that they're part of the API with the core
> atomics and also makes them horribly ugly.

I agree this isn't nice.

> This just looks to be an artifact of __LL_SC_CALL pasting that in. Can
> you drop that auto pasting of 'arch', and instead change the
> non-cmpxchg-case callers of the macro to include the arch prefix
> instead, please?

That leads to having an arch___llsc_ prefix in some cases, which is
equally hideous.

How about I remove the prefix mangling entirely, and always give
functions an __llsc_ or __lse_ prefix. Then, unify the two in our
atomic.h with:

#ifdef CONFIG_ARM64_LSE
#define ATOMIC_PFX __lse_
#else
#define ATOMIC_PFX __ll_sc_
#endif

#define arch_atomic_foo ATOMIC_PFX##atomic_foo
#define arch_atomic_bar ATOMIC_PFX##atomic_bar

... which clearly delineates the implementation from core API.

Does that sound ok to you?

Thanks,
Mark.