Skip to content

Commit e43b40b

Browse files
chenhuacaiintel-lab-lkp
authored andcommitted
LoongArch: Avoid using $r0/$r1 as "mask" for csrxchg
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: [email protected] Link: llvm/llvm-project#141037 Reviewed-by: Yanteng Si <[email protected]> Suggested-by: WANG Rui <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent b142743 commit e43b40b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

arch/loongarch/include/asm/irqflags.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,48 @@
1414
static inline void arch_local_irq_enable(void)
1515
{
1616
u32 flags = CSR_CRMD_IE;
17+
register u32 mask asm("t0") = CSR_CRMD_IE;
18+
1719
__asm__ __volatile__(
1820
"csrxchg %[val], %[mask], %[reg]\n\t"
1921
: [val] "+r" (flags)
20-
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
22+
: [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
2123
: "memory");
2224
}
2325

2426
static inline void arch_local_irq_disable(void)
2527
{
2628
u32 flags = 0;
29+
register u32 mask asm("t0") = CSR_CRMD_IE;
30+
2731
__asm__ __volatile__(
2832
"csrxchg %[val], %[mask], %[reg]\n\t"
2933
: [val] "+r" (flags)
30-
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
34+
: [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
3135
: "memory");
3236
}
3337

3438
static inline unsigned long arch_local_irq_save(void)
3539
{
3640
u32 flags = 0;
41+
register u32 mask asm("t0") = CSR_CRMD_IE;
42+
3743
__asm__ __volatile__(
3844
"csrxchg %[val], %[mask], %[reg]\n\t"
3945
: [val] "+r" (flags)
40-
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
46+
: [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
4147
: "memory");
4248
return flags;
4349
}
4450

4551
static inline void arch_local_irq_restore(unsigned long flags)
4652
{
53+
register u32 mask asm("t0") = CSR_CRMD_IE;
54+
4755
__asm__ __volatile__(
4856
"csrxchg %[val], %[mask], %[reg]\n\t"
4957
: [val] "+r" (flags)
50-
: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
58+
: [mask] "r" (mask), [reg] "i" (LOONGARCH_CSR_CRMD)
5159
: "memory");
5260
}
5361

0 commit comments

Comments
 (0)