diff options
author | Vineet Gupta <vgupta@synopsys.com> | 2014-11-13 05:24:01 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-07-21 13:10:03 -0400 |
commit | 3e43ff498fb1a9f8a58c7746c207b8ffd9a9a87d (patch) | |
tree | 743688226545c2ad73c2f2a4d39a427af54ce2ef /arch | |
parent | eb1eecd100ce48d4f8368a0c475ecb937abd40ec (diff) |
ARC: add compiler barrier to LLSC based cmpxchg
commit d57f727264f1425a94689bafc7e99e502cb135b5 upstream.
When auditing cmpxchg call sites, Chuck noted that gcc was optimizing
away some of the desired LDs.
| do {
| new = old = *ipi_data_ptr;
| new |= 1U << msg;
| } while (cmpxchg(ipi_data_ptr, old, new) != old);
was generating to below
| 8015cef8: ld r2,[r4,0] <-- First LD
| 8015cefc: bset r1,r2,r1
|
| 8015cf00: llock r3,[r4] <-- atomic op
| 8015cf04: brne r3,r2,8015cf10
| 8015cf08: scond r1,[r4]
| 8015cf0c: bnz 8015cf00
|
| 8015cf10: brne r3,r2,8015cf00 <-- Branch doesn't go to orig LD
Although this was fixed by adding a ACCESS_ONCE in this call site, it
seems safer (for now at least) to add compiler barrier to LLSC based
cmpxchg
Reported-by: Chuck Jordan <cjordan@synopsys.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arc/include/asm/cmpxchg.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index c9b1f461a587..44fd531f4d7b 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h | |||
@@ -33,10 +33,11 @@ __cmpxchg(volatile void *ptr, unsigned long expected, unsigned long new) | |||
33 | " scond %3, [%1] \n" | 33 | " scond %3, [%1] \n" |
34 | " bnz 1b \n" | 34 | " bnz 1b \n" |
35 | "2: \n" | 35 | "2: \n" |
36 | : "=&r"(prev) | 36 | : "=&r"(prev) /* Early clobber, to prevent reg reuse */ |
37 | : "r"(ptr), "ir"(expected), | 37 | : "r"(ptr), /* Not "m": llock only supports reg direct addr mode */ |
38 | "r"(new) /* can't be "ir". scond can't take limm for "b" */ | 38 | "ir"(expected), |
39 | : "cc"); | 39 | "r"(new) /* can't be "ir". scond can't take LIMM for "b" */ |
40 | : "cc", "memory"); /* so that gcc knows memory is being written here */ | ||
40 | 41 | ||
41 | smp_mb(); | 42 | smp_mb(); |
42 | 43 | ||