From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753160AbcLJKhe (ORCPT ); Sat, 10 Dec 2016 05:37:34 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:60364 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753083AbcLJKhb (ORCPT ); Sat, 10 Dec 2016 05:37:31 -0500 From: Arnd Bergmann To: Russell King Cc: netdev@vger.kernel.org, Pablo Neira Ayuso , "Paul E. McKenney" , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] ARM: add cmpxchg64 helper for ARMv7-M Date: Sat, 10 Dec 2016 11:36:34 +0100 Message-Id: <20161210103646.1407256-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:7/BSL9+hTwe/fua2zCTLIUFv4VKWV9SpP75EDYTjtRCJTrmGqwQ gny5pq14kBz0YtJ9b1cUA4hqooVVNNA23tA43R985upc6wJtzCQda+Idy2tZ1KV2YdNcd1v e63hdN3//bRhb5Ck9mfx1e54Xs91uk1RGhVMSRaytb7uJtuaxv7g4ijtkn3farZaKtPthFb N8Gn3qADoruLy/SYsExAA== X-UI-Out-Filterresults: notjunk:1;V01:K0:4i6R0Hyrrp8=:fEB0hd8q8ucGuXoFBpubPM 5zHTcOnL9nlydm1Sdqcj64NDmEOezYdDyZLqmgYD8VMSXrHhJAK+g+D2OMrou5JnKX32VbN21 MXYZTEiyYckt/RUEu55uRGqmVyXbYkclJ+pfZQkei49Wp8rVOCCG467YzXHa3qBJno6FbN9XK sZpEWsj+yjZntviocKVWK4E+FgwhK2VR+r8RlBSyQPQ+N1Hp8yaWV4wKqPWAGdezPVZdBOEeL gLdk6/qnGJp0daUs4pZUxThcH5N6PCF07sW5gSDL5MrMViSKW0Opm02zycbZNF6fbkyPl3C1s 3Dfq5ijUqoRbnoKb6PyCWFrSnmiE03yBuYMgzDpRjUzOBUxsttgm2DhJJPBmcaix17E1n060z hnmZYXMol/zXVqzMhkgsmtTMD+4iexQLyA/WbD7xJX5g11/8Kga83JLuSRUpQzBlpPXA93NN3 JW10EhxP7C+Rj+8qeBOXrf24pgdv6ZxNBol4ds6xM7hBUE+W4JN9x9RX3dGaOJv5wZhEk90y0 BqiCHBH11R+yBE78yzQRBiUGeJAHEGm5cZ00gQOvqN/YwNk0uxAFd5nMv7uspeEw56ViZHp+a vQha47P3iCZLC6uzLUZK3eyFfbsNZT98uCw4JkARtZ3H9jDq4IYRC9yASCsrHQ0znJJW2EkAp hInmDKKtJouWcSxZY0D20NFbYsskK9k2lMXTbbRaUDkC5AMXKGYU8GRHkZV+PjqTK1Bs= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A change to the netfilter code in net-next introduced the first caller of cmpxchg64 that can get built on ARMv7-M, leading to an error from the assembler that points out the lack of 64-bit atomics on this architecture: /tmp/ccMe7djj.s: Assembler messages: /tmp/ccMe7djj.s:367: Error: selected processor does not support `ldrexd r0,r1,[lr]' in Thumb mode /tmp/ccMe7djj.s:371: Error: selected processor does not support `strexd ip,r2,r3,[lr]' in Thumb mode /tmp/ccMe7djj.s:389: Error: selected processor does not support `ldrexd r8,r9,[r7]' in Thumb mode /tmp/ccMe7djj.s:393: Error: selected processor does not support `strexd lr,r0,r1,[r7]' in Thumb mode scripts/Makefile.build:299: recipe for target 'net/netfilter/nft_counter.o' failed This makes ARMv7-M use the same emulation from asm-generic/cmpxchg-local.h that we use on architectures earlier than ARMv6K, to fix the build. The 32-bit atomics are available on ARMv7-M and we keep using them there. This ARM specific change is probably something we should do regardless of the netfilter code. However, looking at the new nft_counter_reset() function in nft_counter.c, this looks incorrect to me not just on ARMv7-M but also on other architectures, with at least the following possible race: CPU A CPU B u64_stats_fetch_begin_irq u64_stats_update_begin fetch(upper 32 bits) fetch(old) cmpxchg64(counter, old, 0); fetch(lower 32 bits) u64_stats_fetch_retry_irq == true store(upper 32 bits) fetch(old) cmpxchg64(counter, old, 0); store(lower 32 bits) u64_stats_update_end u64_stats_fetch_retry_irq == true fetch(old) cmpxchg64(counter, old, 0); u64_stats_fetch_retry_irq == false In this example, the data returned by __nft_counter_reset() is zero as we overwrite the per-cpu counter value during the retries. Fixes: 43da04a593d8 ("netfilter: nf_tables: atomic dump and reset for stateful objects") Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/cmpxchg.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h index 97882f9bad12..12215515ba02 100644 --- a/arch/arm/include/asm/cmpxchg.h +++ b/arch/arm/include/asm/cmpxchg.h @@ -240,6 +240,7 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr, sizeof(*(ptr))); \ }) +#ifndef CONFIG_CPU_V7M static inline unsigned long long __cmpxchg64(unsigned long long *ptr, unsigned long long old, unsigned long long new) @@ -273,6 +274,18 @@ static inline unsigned long long __cmpxchg64(unsigned long long *ptr, #define cmpxchg64_local(ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n)) +#else + +/* ARMv7-M has 32-bit ldrex/strex but no ldrexd/strexd */ + +#define cmpxchg64(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) +#define cmpxchg64_relaxed(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) +#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) + +#include + +#endif + #endif /* __LINUX_ARM_ARCH__ >= 6 */ #endif /* __ASM_ARM_CMPXCHG_H */ -- 2.9.0