linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: Fix local irq restore when flags indicates irq disabled
@ 2023-07-24 13:27 luxu.kernel
  2023-07-24 13:42 ` Ben Dooks
  0 siblings, 1 reply; 5+ messages in thread
From: luxu.kernel @ 2023-07-24 13:27 UTC (permalink / raw)
  To: paul.walmsley, palmer, aou; +Cc: linux-riscv, linux-kernel, 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.

Signed-off-by: luxu.kernel <luxu.kernel@bytedance.com>
---
 arch/riscv/include/asm/irqflags.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h
index 08d4d6a5b7e9..7c31fc3c3559 100644
--- a/arch/riscv/include/asm/irqflags.h
+++ b/arch/riscv/include/asm/irqflags.h
@@ -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 */
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv: Fix local irq restore when flags indicates irq disabled
  2023-07-24 13:27 [PATCH] riscv: Fix local irq restore when flags indicates irq disabled luxu.kernel
@ 2023-07-24 13:42 ` Ben Dooks
       [not found]   ` <20230724-anatomist-evade-ef89a12a491a@wendy>
  0 siblings, 1 reply; 5+ messages in thread
From: Ben Dooks @ 2023-07-24 13:42 UTC (permalink / raw)
  To: luxu.kernel, paul.walmsley, palmer, aou
  Cc: linux-riscv, linux-kernel, luxu.kernel

On 24/07/2023 14:27, luxu.kernel wrote:
> 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.
> 
> Signed-off-by: luxu.kernel <luxu.kernel@bytedance.com>

real-names are required for signoff

> ---
>   arch/riscv/include/asm/irqflags.h | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h
> index 08d4d6a5b7e9..7c31fc3c3559 100644
> --- a/arch/riscv/include/asm/irqflags.h
> +++ b/arch/riscv/include/asm/irqflags.h
> @@ -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 */

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

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

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv: Fix local irq restore when flags indicates irq disabled
       [not found]   ` <20230724-anatomist-evade-ef89a12a491a@wendy>
@ 2023-07-25  6:25     ` Xu Lu
  0 siblings, 0 replies; 5+ messages in thread
From: Xu Lu @ 2023-07-25  6:25 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Ben Dooks, paul.walmsley, palmer, aou, linux-riscv, linux-kernel,
	luxu.kernel

On Mon, Jul 24, 2023 at 10:03 PM Conor Dooley
<conor.dooley@microchip.com> wrote:
>
> On Mon, Jul 24, 2023 at 02:42:50PM +0100, Ben Dooks wrote:
> > On 24/07/2023 14:27, luxu.kernel wrote:
> > > 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.
> > >
> > > Signed-off-by: luxu.kernel <luxu.kernel@bytedance.com>
> >
> > real-names are required for signoff
>
> And the From: address needs to match the signof, here the From: address
> is a gmail one.
>
> > > ---
> > >   arch/riscv/include/asm/irqflags.h | 5 ++++-
> > >   1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h
> > > index 08d4d6a5b7e9..7c31fc3c3559 100644
> > > --- a/arch/riscv/include/asm/irqflags.h
> > > +++ b/arch/riscv/include/asm/irqflags.h
> > > @@ -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 */
> >
> > 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.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv: Fix local irq restore when flags indicates irq disabled
  2023-07-25  7:05 Xu Lu
@ 2023-08-09  6:05 ` Palmer Dabbelt
  0 siblings, 0 replies; 5+ messages in thread
From: Palmer Dabbelt @ 2023-08-09  6:05 UTC (permalink / raw)
  To: luxu.kernel; +Cc: Paul Walmsley, aou, linux-riscv, linux-kernel, luxu.kernel

On Tue, 25 Jul 2023 00:05:49 PDT (-0700), luxu.kernel@bytedance.com wrote:
> 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")
> Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
> ---
>  arch/riscv/include/asm/irqflags.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h
> index 08d4d6a5b7e9..7c31fc3c3559 100644
> --- a/arch/riscv/include/asm/irqflags.h
> +++ b/arch/riscv/include/asm/irqflags.h
> @@ -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);

Unless I'm missing something, the original version is correct: 
local_irq_restore() must be paired with a local_irq_save(), so we can 
only get here with interrupts disabled.

>  }
>
>  #endif /* _ASM_RISCV_IRQFLAGS_H */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] riscv: Fix local irq restore when flags indicates irq disabled
@ 2023-07-25  7:05 Xu Lu
  2023-08-09  6:05 ` Palmer Dabbelt
  0 siblings, 1 reply; 5+ messages in thread
From: Xu Lu @ 2023-07-25  7:05 UTC (permalink / raw)
  To: paul.walmsley, palmer, aou; +Cc: linux-riscv, linux-kernel, 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.

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")
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
 arch/riscv/include/asm/irqflags.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h
index 08d4d6a5b7e9..7c31fc3c3559 100644
--- a/arch/riscv/include/asm/irqflags.h
+++ b/arch/riscv/include/asm/irqflags.h
@@ -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 */
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-09  6:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-24 13:27 [PATCH] riscv: Fix local irq restore when flags indicates irq disabled luxu.kernel
2023-07-24 13:42 ` Ben Dooks
     [not found]   ` <20230724-anatomist-evade-ef89a12a491a@wendy>
2023-07-25  6:25     ` Xu Lu
2023-07-25  7:05 Xu Lu
2023-08-09  6:05 ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).