Skip to contentSkip to conversation

riscv: Fix local irq restore when flags indicates irq disabled

PATCH In review Xu Lu 2 participants 2 messages Jun 18, 2024 RISC-V

lore
Share & tools
lore

Xu Lu

author
#0 lore raw

PATCH 1/1 riscv: Fix local irq restore when flags indicates irq disabled

When arch_local_irq_restore() is called with flags indicating irqs disabled, we need to clear SR_IE bit in CSR_STATUS, whereas current implementation based on csr_set() function only sets SR_IE bit of CSR_STATUS when SR_IE bit of flags is high and does nothing when SR_IE bit of flags is low.

This commit supplies csr clear operation when calling irq restore function with flags indicating irq disabled.

Fixes 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI")
---
 arch/riscv/include/asm/irqflags.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +4 -1
index 6fd8cbfcfcc7..f3aad7bfadb7 100644
@@ -48,7 +48,10 @@ static inline int arch_irqs_disabled(void)
 /* set interrupt enabled status */
 static inline void arch_local_irq_restore(unsigned long flags)
 {
-	csr_set(CSR_STATUS, flags & SR_IE);
+	if (flags & SR_IE)
+		csr_set(CSR_STATUS, SR_IE);
+	else
+		csr_clear(CSR_STATUS, SR_IE);
 }
 
 #endif /* _ASM_RISCV_IRQFLAGS_H */
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · Xu Lu

When arch_local_irq_restore() is called with flags indicating irqs disabled, we need to clear SR_IE bit in CSR_STATUS, whereas current implementation based on csr_set() function only sets SR_IE bit of CSR_STATUS when SR_IE bit of flags is high and does nothing when SR_IE bit of flags is low.

That shouldn't matter; arch_local_irq_restore() should *never* be called from a context with IRQs enabled, and so arch_local_irq_restore() never needs to disable IRQs. Either it enables IRQs or it leaves IRQs disabled, but it never needs to explicitly disable IRQs.

See CONFIG_DEBUG_IRQFLAGS and the commit that introduced it:

997acaf6b4b59c6a ("lockdep: report broken irq restoration")

I don't believe this patch is necessary.

Mark.

Quoted 30 lines

This commit supplies csr clear operation when calling irq restore function with flags indicating irq disabled.

Fixes 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI")
---
 arch/riscv/include/asm/irqflags.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +4 -1
index 6fd8cbfcfcc7..f3aad7bfadb7 100644
@@ -48,7 +48,10 @@ static inline int arch_irqs_disabled(void)
 /* set interrupt enabled status */
 static inline void arch_local_irq_restore(unsigned long flags)
 {
-	csr_set(CSR_STATUS, flags & SR_IE);
+	if (flags & SR_IE)
+		csr_set(CSR_STATUS, SR_IE);
+	else
+		csr_clear(CSR_STATUS, SR_IE);
 }
 
 #endif /* _ASM_RISCV_IRQFLAGS_H */
Signature · 1 line
2.20.1