Re: mainline build failure for loongarch allmodconfig with gcc-12

From: Linus Torvalds
Date: Tue Aug 23 2022 - 15:25:55 EST


On Tue, Aug 23, 2022 at 1:34 AM Sudip Mukherjee (Codethink)
<sudipm.mukherjee@xxxxxxxxx> wrote:
>
> I have been trying to build loongarch as part of my nightly builds, and
> I can build loongson3_defconfig without any error. But allmodconfig fails
> with the error:
>
> In function '__cmpxchg',
> inlined from 'ssh_seq_next' at drivers/platform/surface/aggregator/controller.c:61:9,

Looks like ssh_seq_next() wants to do an atomic cmpxchg() on a single
byte value, and the Loongarch implementation only does 4- and 8-byte
versions.

It looks like loongarch - from its MIPS heritage - inherited the "we
can't do atomics on byte variables", so that it needs the same strange
"do bytes as word accesses with mask-and-shifts".

For MIPS, the code is in __xchg_small() in arch/mips/kernel/cmpxchg.c.

Alpha has something similar, except it's all done in inline asm in
arch/alpha/include/asm/xchg.h (look for "____cmpxchg(_u8," in there.

Of course, we could just add a Kconfig variable like
"ARCH_LACKS_BYTE_ATOMICS" and make that driver depend on it not being
true, and just have Loongarch set it.

But I think loongarch should just implement the byte masking stuff.
Particularly since I suspect it can just copy the MIPS code as-is.

Linus