arch/loongarch/Kconfig | 3 +++ arch/loongarch/include/asm/cmpxchg.h | 5 +++++ 2 files changed, 8 insertions(+)
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)
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/
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
arch/loongarch/Kconfig | 3 +++
arch/loongarch/include/asm/cmpxchg.h | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index d211c6572b0a..92068ff38685 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -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)
diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/asm/cmpxchg.h
index 58cabab6d90d..909f9274fe71 100644
--- a/arch/loongarch/include/asm/cmpxchg.h
+++ b/arch/loongarch/include/asm/cmpxchg.h
@@ -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))
---
base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
change-id: 20260218-loongarch-scq-2434ec5aec4d
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Hi LoongArch maintainers,
On Wed, Feb 25, 2026 at 11:09:39AM +0100, Thomas Weißschuh wrote:
> 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)
>
> 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/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> arch/loongarch/Kconfig | 3 +++
> arch/loongarch/include/asm/cmpxchg.h | 5 +++++
> 2 files changed, 8 insertions(+)
(...)
This is still broken in mainline. Any chance to get this patch to Linus?
Thomas
On Mon, Mar 9, 2026 at 3:07 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> Hi LoongArch maintainers,
>
> On Wed, Feb 25, 2026 at 11:09:39AM +0100, Thomas Weißschuh wrote:
> > 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)
> >
> > 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/
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > ---
> > arch/loongarch/Kconfig | 3 +++
> > arch/loongarch/include/asm/cmpxchg.h | 5 +++++
> > 2 files changed, 8 insertions(+)
>
> (...)
>
> This is still broken in mainline. Any chance to get this patch to Linus?
Now queued for loongarch-fixes, sorry for the late response.
Huacai
>
>
> Thomas
>
On Wed, Feb 25, 2026 at 6:09 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> 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)
>
> 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/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
Acked-by: Hengqi Chen <hengqi.chen@gmail.com>
Tested-by: Hengqi Chen <hengqi.chen@gmail.com>
> arch/loongarch/Kconfig | 3 +++
> arch/loongarch/include/asm/cmpxchg.h | 5 +++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index d211c6572b0a..92068ff38685 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -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)
>
> diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/asm/cmpxchg.h
> index 58cabab6d90d..909f9274fe71 100644
> --- a/arch/loongarch/include/asm/cmpxchg.h
> +++ b/arch/loongarch/include/asm/cmpxchg.h
> @@ -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))
>
> ---
> base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
> change-id: 20260218-loongarch-scq-2434ec5aec4d
>
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
On Wed, 2026-02-25 at 11:09 +0100, Thomas Weißschuh wrote:
> 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)
>
> 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/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
I have written something similar (only the identifier of the config
entry is different), but I just didn't get the time to set up an old
toolchain and test it.
Reviewed-by: Xi Ruoyao <xry111@xry111.site>
> ---
> arch/loongarch/Kconfig | 3 +++
> arch/loongarch/include/asm/cmpxchg.h | 5 +++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index d211c6572b0a..92068ff38685 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -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)
>
> diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/asm/cmpxchg.h
> index 58cabab6d90d..909f9274fe71 100644
> --- a/arch/loongarch/include/asm/cmpxchg.h
> +++ b/arch/loongarch/include/asm/cmpxchg.h
> @@ -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))
>
> ---
> base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
> change-id: 20260218-loongarch-scq-2434ec5aec4d
>
> Best regards,
--
Xi Ruoyao <xry111@xry111.site>
© 2016 - 2026 Red Hat, Inc.