LoongArch: Avoid using $r0/$r1 as "mask" for csrxchg

commit 52c22661c79a7b6af7fad9f77200738fc6c51878 upstream.

When building kernel with LLVM there are occasionally such errors:

In file included from ./include/linux/spinlock.h:59:
In file included from ./include/linux/irqflags.h:17:
arch/loongarch/include/asm/irqflags.h:38:3: error: must not be $r0 or $r1
   38 |                 "csrxchg %[val], %[mask], %[reg]\n\t"
      |                 ^
<inline asm>:1:16: note: instantiated into assembly here
    1 |         csrxchg $a1, $ra, 0
      |                       ^

To prevent the compiler from allocating $r0 or $r1 for the "mask" of the
csrxchg instruction, the 'q' constraint must be used but Clang < 21 does
not support it. So force to use $t0 in the inline asm, in order to avoid
using $r0/$r1 while keeping the backward compatibility.

Cc: stable@vger.kernel.org
Link: https://github.com/llvm/llvm-project/pull/141037
Reviewed-by: Yanteng Si <si.yanteng@linux.dev>
Suggested-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Huacai Chen
2025-05-30 21:45:48 +08:00
committed by Greg Kroah-Hartman
parent 782baee5d9
commit 099cfcb98f

View File

@@ -14,40 +14,48 @@
static inline void arch_local_irq_enable(void) static inline void arch_local_irq_enable(void)
{ {
u32 flags = CSR_CRMD_IE; u32 flags = CSR_CRMD_IE;
register u32 mask asm("t0") = CSR_CRMD_IE;
__asm__ __volatile__( __asm__ __volatile__(
"csrxchg %[val], %[mask], %[reg]\n\t" "csrxchg %[val], %[mask], %[reg]\n\t"
: [val] "+r" (flags) : [val] "+r" (flags)
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD) : [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
: "memory"); : "memory");
} }
static inline void arch_local_irq_disable(void) static inline void arch_local_irq_disable(void)
{ {
u32 flags = 0; u32 flags = 0;
register u32 mask asm("t0") = CSR_CRMD_IE;
__asm__ __volatile__( __asm__ __volatile__(
"csrxchg %[val], %[mask], %[reg]\n\t" "csrxchg %[val], %[mask], %[reg]\n\t"
: [val] "+r" (flags) : [val] "+r" (flags)
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD) : [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
: "memory"); : "memory");
} }
static inline unsigned long arch_local_irq_save(void) static inline unsigned long arch_local_irq_save(void)
{ {
u32 flags = 0; u32 flags = 0;
register u32 mask asm("t0") = CSR_CRMD_IE;
__asm__ __volatile__( __asm__ __volatile__(
"csrxchg %[val], %[mask], %[reg]\n\t" "csrxchg %[val], %[mask], %[reg]\n\t"
: [val] "+r" (flags) : [val] "+r" (flags)
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD) : [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
: "memory"); : "memory");
return flags; return flags;
} }
static inline void arch_local_irq_restore(unsigned long flags) static inline void arch_local_irq_restore(unsigned long flags)
{ {
register u32 mask asm("t0") = CSR_CRMD_IE;
__asm__ __volatile__( __asm__ __volatile__(
"csrxchg %[val], %[mask], %[reg]\n\t" "csrxchg %[val], %[mask], %[reg]\n\t"
: [val] "+r" (flags) : [val] "+r" (flags)
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD) : [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
: "memory"); : "memory");
} }