[PATCH v2] ARM: mutex: use generic xchg-based implementation for ARMv6+

Nicolas Pitre nico at fluxnic.net
Fri Jul 13 13:35:17 EDT 2012


On Fri, 13 Jul 2012, Will Deacon wrote:

> The open-coded mutex implementation for ARMv6+ cores suffers from a
> severe lack of barriers, so in the uncontended case we don't actually
> protect any accesses performed during the critical section.
> 
> Furthermore, the code is largely a duplication of the ARMv6+ atomic_dec
> code but optimised to remove a branch instruction, as the mutex fastpath
> was previously inlined. Now that this is executed out-of-line, we can
> reuse the atomic access code for the locking (in fact, we use the xchg
> code as this produces shorter critical sections).
> 
> This patch uses the generic xchg based implementation for mutexes on
> ARMv6+, which introduces barriers to the lock/unlock operations and also
> has the benefit of removing a fair amount of inline assembly code.
> 
> Acked-by: Arnd Bergmann <arnd at arndb.de>
> Acked-by: Nicolas Pitre <nico at linaro.org>
> Reported-by: Shan Kang <kangshan0910 at gmail.com>
> Signed-off-by: Will Deacon <will.deacon at arm.com>
> ---
> 
> Ok, so here's v2 following the feedback from Arnd and Nico. We now use
> the xchg-based version for all versions of the architecture and I've
> updated the commit message to reflect both that and also to remove the
> bit about avoiding the slowpath on frivolous CPUs!

Looks great.  You probably should tag it for stable as well.


Nicolas



More information about the linux-arm-kernel mailing list