Skip to contentSkip to conversation

riscv: Fix local irq restore when flags indicates irq disabled

PATCH In review luxu.kernel 3 participants 4 messages Jul 24, 2023 – Jul 25, 2023 RISC-V

lore
Share & tools
lore
#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.

---
 arch/riscv/include/asm/irqflags.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +4 -1
index 08d4d6a5b7e9..7c31fc3c3559 100644
@@ -49,7 +49,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 10 lines · luxu.kernel

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.

real-names are required for signoff

Quoted 10 lines
---
  arch/riscv/include/asm/irqflags.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +0 -0
index 08d4d6a5b7e9..7c31fc3c3559 100644
@@ -49,7 +49,10 @@ static inline int arch_irqs_disabled(void)
  /* set interrupt enabled status */

arch/riscv/include/asm/irqflags.h static inline int arch_irqs_disabled(void) · line 58

Quoted 10 lines
arch/riscv/include/asm/irqflags.h +4 -1
  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 */

I think this is correct, I wonder how long this has been going on without anyone noticing?

Signature · 10 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw
Quoted 7 lines · Ben Dooks
Quoted 6 lines · luxu.kernel

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.

Quoted 6 lines
Quoted 4 lines

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

real-names are required for signoff

And the From: address needs to match the signof, here the From: address is a gmail one.

Quoted 14 lines
Quoted 14 lines
---
  arch/riscv/include/asm/irqflags.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +1 -1
index 08d4d6a5b7e9..7c31fc3c3559 100644
@@ -49,7 +49,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)
Quoted 8 lines

arch/riscv/include/asm/irqflags.h static inline int arch_irqs_disabled(void) · line 58

Quoted 5 lines
arch/riscv/include/asm/irqflags.h +3 -0
+		csr_set(CSR_STATUS, SR_IE);
+	else
+		csr_clear(CSR_STATUS, SR_IE);
  }
  #endif /* _ASM_RISCV_IRQFLAGS_H */

I think this is correct, I wonder how long this has been going on without anyone noticing?

Code has been like this since 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI"), committed on Tue Sep 26 15:26:47 2017 -0700.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#3 lore raw
Quoted 42 lines · Conor Dooley
Quoted 7 lines · Ben Dooks
Quoted 6 lines · luxu.kernel

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.

Quoted 6 lines
Quoted 4 lines

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

real-names are required for signoff

And the From: address needs to match the signof, here the From: address is a gmail one.

Quoted 14 lines
Quoted 14 lines
---
  arch/riscv/include/asm/irqflags.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/include/asm/irqflags.h +1 -1
index 08d4d6a5b7e9..7c31fc3c3559 100644
@@ -49,7 +49,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)
Quoted 8 lines

arch/riscv/include/asm/irqflags.h static inline int arch_irqs_disabled(void) · line 58

Quoted 5 lines
arch/riscv/include/asm/irqflags.h +3 -0
+           csr_set(CSR_STATUS, SR_IE);
+   else
+           csr_clear(CSR_STATUS, SR_IE);
  }
  #endif /* _ASM_RISCV_IRQFLAGS_H */

I think this is correct, I wonder how long this has been going on without anyone noticing?

Quoted 2 lines

Code has been like this since 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI"), committed on Tue Sep 26 15:26:47 2017 -0700.

Thanks for your reply. I will resend the patch with real name and correct mailbox.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv