]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
LoongArch: Only use SC.Q when supported by the assembler
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Mon, 16 Mar 2026 02:36:00 +0000 (10:36 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Mon, 16 Mar 2026 02:36:00 +0000 (10:36 +0800)
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: f0e4b1b6e295 ("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>
arch/loongarch/Kconfig
arch/loongarch/include/asm/cmpxchg.h

index d211c6572b0a67ae699b831f9cf1cc49e4af4f1e..92068ff38685eb5a5b4bffe05357367bbfebcf70 100644 (file)
@@ -304,6 +304,9 @@ config AS_HAS_LBT_EXTENSION
 config AS_HAS_LVZ_EXTENSION
        def_bool $(as-instr,hvcl 0)
 
+config AS_HAS_SCQ_EXTENSION
+       def_bool $(as-instr,sc.q \$t0$(comma)\$t1$(comma)\$t2)
+
 config CC_HAS_ANNOTATE_TABLEJUMP
        def_bool $(cc-option,-mannotate-tablejump)
 
index 58cabab6d90d1a7f27beba820625fef6f695bcea..909f9274fe71aa47a5165584f11e038ceb3261d6 100644 (file)
@@ -238,6 +238,8 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, unsigned int
        arch_cmpxchg((ptr), (o), (n));                                  \
   })
 
+#ifdef CONFIG_AS_HAS_SCQ_EXTENSION
+
 union __u128_halves {
        u128 full;
        struct {
@@ -290,6 +292,9 @@ union __u128_halves {
        BUILD_BUG_ON(sizeof(*(ptr)) != 16);                             \
        __arch_cmpxchg128(ptr, o, n, "");                               \
 })
+
+#endif /* CONFIG_AS_HAS_SCQ_EXTENSION */
+
 #else
 #include <asm-generic/cmpxchg-local.h>
 #define arch_cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n))