Skip to content

Commit c8b8f3c

Browse files
t-8chchenhuacai
authored andcommitted
LoongArch: Only use SC.Q when supported by the assembler
The 128-bit atomic cmpxchg implementation uses the SC.Q instruction. Older versions of GNU AS do not support that instruction, erroring out: ERROR:root:{standard input}: Assembler messages: {standard input}:4831: Error: no match insn: sc.q $t0,$t1,$r14 {standard input}:6407: Error: no match insn: sc.q $t0,$t1,$r23 {standard input}:10856: Error: no match insn: sc.q $t0,$t1,$r14 make[4]: *** [../scripts/Makefile.build:289: mm/slub.o] Error 1 (Binutils 2.41) So test support for SC.Q in Kconfig and disable the atomics if the instruction is not available. Fixes: f0e4b1b ("LoongArch: Add 128-bit atomic cmpxchg support") Closes: https://lore.kernel.org/lkml/20260216082834-edc51c46-7b7a-4295-8ea5-4d9a3ca2224f@linutronix.de/ Reviewed-by: Xi Ruoyao <xry111@xry111.site> Acked-by: Hengqi Chen <hengqi.chen@gmail.com> Tested-by: Hengqi Chen <hengqi.chen@gmail.com> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent f338e77 commit c8b8f3c

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

arch/loongarch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ config AS_HAS_LBT_EXTENSION
304304
config AS_HAS_LVZ_EXTENSION
305305
def_bool $(as-instr,hvcl 0)
306306

307+
config AS_HAS_SCQ_EXTENSION
308+
def_bool $(as-instr,sc.q \$t0$(comma)\$t1$(comma)\$t2)
309+
307310
config CC_HAS_ANNOTATE_TABLEJUMP
308311
def_bool $(cc-option,-mannotate-tablejump)
309312

arch/loongarch/include/asm/cmpxchg.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, unsigned int
238238
arch_cmpxchg((ptr), (o), (n)); \
239239
})
240240

241+
#ifdef CONFIG_AS_HAS_SCQ_EXTENSION
242+
241243
union __u128_halves {
242244
u128 full;
243245
struct {
@@ -290,6 +292,9 @@ union __u128_halves {
290292
BUILD_BUG_ON(sizeof(*(ptr)) != 16); \
291293
__arch_cmpxchg128(ptr, o, n, ""); \
292294
})
295+
296+
#endif /* CONFIG_AS_HAS_SCQ_EXTENSION */
297+
293298
#else
294299
#include <asm-generic/cmpxchg-local.h>
295300
#define arch_cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n))

0 commit comments

Comments
 (0)