Re: [PATCH] LoongArch: detect and disable sc.q if erratic

From: Xi Ruoyao

Date: Thu Apr 02 2026 - 04:11:01 EST


On Thu, 2026-04-02 at 08:39 +0200, Thomas Weißschuh wrote:
> On 2026-04-02 12:47:30+0800, Xi Ruoyao wrote:
>
> (...)
>
> > +/*
> > + * Some LoongArch has broken sc.q which incorrectly handles the upper word
> > + * when the lower word is zero. Newer firmware versions (such as the 202602
> > + * release from Loongson) seem to contain a workaround for this issue.
> > + *
> > + * Disable sc.q if erratic to ensure reliability and compatibility.
> > + */
> > +static bool sc_q_is_sane(void)
> > +{
> > + struct {
> > + long word[2];
> > + } __aligned(16) mem;
> > + register long tmp;
> > +
> > + asm (
> > + "1:ll.d\t$r0, %[mem]\n\t"
> > + "move\t%[tmp], $r0\n\t"
> > + "sc.q\t%[tmp], %[one], %[mem]\n\t"
>
> This probably needs to be gated behind CONFIG_AS_HAS_SCQ_EXTENSION to
> avoid errors on older toolchains.

I guess I'd code the insn with .word instead...

This also affects HWCAP, and I don't want the userspace to see neither a
false positive nor a false negative simply because the kernel was built
with an old toolchain.

--
Xi Ruoyao <xry111@xxxxxxxxxxx>