2022-04-22 12:25:40

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 4/9] s390/irq: utilize RCU instead of irq_lock_sparse() in show_msi_interrupt()

On Wed, Apr 20, 2022 at 10:05:16PM +0800, Pingfan Liu wrote:
> irq_desc can be accessed safely in RCU read section as demonstrated by
> kstat_irqs_usr(). And raw_spin_lock_irqsave() context can provide a rcu
> read section, which can be utilized to get rid of irq_lock_sparse().
>
> Signed-off-by: Pingfan Liu <[email protected]>
> Cc: Heiko Carstens <[email protected]>
> Cc: Vasily Gorbik <[email protected]>
> Cc: Alexander Gordeev <[email protected]>
> Cc: Christian Borntraeger <[email protected]>
> Cc: Sven Schnelle <[email protected]>
> Cc: Sebastian Andrzej Siewior <[email protected]>
> Cc: [email protected]
> To: [email protected]
> ---
> arch/s390/kernel/irq.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
> index 3033f616e256..6302dc7874cf 100644
> --- a/arch/s390/kernel/irq.c
> +++ b/arch/s390/kernel/irq.c
> @@ -205,12 +205,13 @@ static void show_msi_interrupt(struct seq_file *p, int irq)
> unsigned long flags;
> int cpu;
>
> - irq_lock_sparse();
> + raw_spin_lock_irqsave(&desc->lock, flags);
> desc = irq_to_desc(irq);

How is this supposed to work? desc get's initialized after its random
stack value has been used as a pointer to lock something...


2022-04-22 19:10:07

by Pingfan Liu

[permalink] [raw]
Subject: Re: [PATCH 4/9] s390/irq: utilize RCU instead of irq_lock_sparse() in show_msi_interrupt()

On Wed, Apr 20, 2022 at 08:16:37PM +0200, Heiko Carstens wrote:
> On Wed, Apr 20, 2022 at 10:05:16PM +0800, Pingfan Liu wrote:
> > irq_desc can be accessed safely in RCU read section as demonstrated by
> > kstat_irqs_usr(). And raw_spin_lock_irqsave() context can provide a rcu
> > read section, which can be utilized to get rid of irq_lock_sparse().
> >
> > Signed-off-by: Pingfan Liu <[email protected]>
> > Cc: Heiko Carstens <[email protected]>
> > Cc: Vasily Gorbik <[email protected]>
> > Cc: Alexander Gordeev <[email protected]>
> > Cc: Christian Borntraeger <[email protected]>
> > Cc: Sven Schnelle <[email protected]>
> > Cc: Sebastian Andrzej Siewior <[email protected]>
> > Cc: [email protected]
> > To: [email protected]
> > ---
> > arch/s390/kernel/irq.c | 11 +++++------
> > 1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
> > index 3033f616e256..6302dc7874cf 100644
> > --- a/arch/s390/kernel/irq.c
> > +++ b/arch/s390/kernel/irq.c
> > @@ -205,12 +205,13 @@ static void show_msi_interrupt(struct seq_file *p, int irq)
> > unsigned long flags;
> > int cpu;
> >
> > - irq_lock_sparse();
> > + raw_spin_lock_irqsave(&desc->lock, flags);
> > desc = irq_to_desc(irq);
>
> How is this supposed to work? desc get's initialized after its random
> stack value has been used as a pointer to lock something...

Oops. You are right. What about using rcu_read_lock() directly?


diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index 3033f616e256..45393919fe61 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -205,7 +205,7 @@ static void show_msi_interrupt(struct seq_file *p, int irq)
unsigned long flags;
int cpu;

- irq_lock_sparse();
+ rcu_read_lock();
desc = irq_to_desc(irq);
if (!desc)
goto out;
@@ -224,7 +224,7 @@ static void show_msi_interrupt(struct seq_file *p, int irq)
seq_putc(p, '\n');
raw_spin_unlock_irqrestore(&desc->lock, flags);
out:
- irq_unlock_sparse();
+ rcu_read_unlock();
}

/*


Thanks,

Pingfan