linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Johan Hovold' <johan@kernel.org>,
	"tiantao (H)" <tiantao6@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tian Tao <tiantao6@hisilicon.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"jirislaby@kernel.org" <jirislaby@kernel.org>,
	"afaerber@suse.de" <afaerber@suse.de>,
	"manivannan.sadhasivam@linaro.org"
	<manivannan.sadhasivam@linaro.org>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tty: serial: replace spin_lock_irqsave by spin_lock in hard IRQ
Date: Sat, 21 Nov 2020 16:17:30 +0100	[thread overview]
Message-ID: <X7kviiRwuxvPxC8O@localhost> (raw)
In-Reply-To: <40a52ea2273146b98b3ae3439a22d1eb@AcuMS.aculab.com>

On Fri, Nov 20, 2020 at 08:00:05PM +0000, David Laight wrote:
> From: Johan Hovold
> > Sent: 20 November 2020 12:50
> > 
> > On Fri, Nov 20, 2020 at 07:25:03PM +0800, tiantao (H) wrote:
> > > 在 2020/11/20 16:23, Johan Hovold 写道:
> > > > On Thu, Nov 19, 2020 at 05:01:29PM +0800, Tian Tao wrote:
> > > >> The code has been in a irq-disabled context since it is hard IRQ. There
> > > >> is no necessity to do it again.
> > > >>
> > > >> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> > > >> ---
> > > >>   drivers/tty/serial/owl-uart.c | 5 ++---
> > > >>   1 file changed, 2 insertions(+), 3 deletions(-)
> > > >>
> > > >> diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c
> > > >> index c149f8c3..472fdaf 100644
> > > >> --- a/drivers/tty/serial/owl-uart.c
> > > >> +++ b/drivers/tty/serial/owl-uart.c
> > > >> @@ -251,10 +251,9 @@ static void owl_uart_receive_chars(struct uart_port *port)
> > > >>   static irqreturn_t owl_uart_irq(int irq, void *dev_id)
> > > >>   {
> > > >>   	struct uart_port *port = dev_id;
> > > >> -	unsigned long flags;
> > > >>   	u32 stat;
> > > >>
> > > >> -	spin_lock_irqsave(&port->lock, flags);
> > > >> +	spin_lock(&port->lock);
> > > >
> > > > Same thing here; this will break with forced irq threading (i.e.
> > > > "threadirqs") since the console code can still end up being called from
> > > > interrupt context.
> > 
> > > As the following code shows, owl_uart_irq does not run in the irq
> > > threading context.
> > >   ret = request_irq(port->irq, owl_uart_irq, IRQF_TRIGGER_HIGH,
> > >                          "owl-uart", port);
> > >          if (ret)
> > >                  return ret;
> > 
> > It still runs in a thread when interrupts are forced to be threaded
> > using the kernel parameter "threadirqs".
> > 
> > We just had a revert of a change like yours after lockdep reported the
> > resulting lock inversion with forced interrupt threading.
> > 
> > Whether drivers should have to care about "threadirqs" is a somewhat
> > different question. Not sure how that's even supposed to work generally
> > unless we mass-convert drivers to spin_lock_irqsave() (or mark their
> > interrupts IRQF_NO_THREAD).
> 
> Isn't that backwards?
> 
> You need to use the 'irqsave' variant in code that might run with
> interrupts enabled because an interrupt might try to acquire the
> same lock having interrupted the code that already holds the lock.
> 
> If interrupts run as separate threads that can never happen.
> So in that case all code can use the non-irqsave call.
> 
> So either lockdep is broken or you have a different bug.

Not all interrupts run as threads with "threadirqs" so the lock can
potentially still be taken in hard IRQ context also with forced
threading.

For console drivers this can even happen for the same interrupt as the
generic interrupt code can call printk(), and so can any other handler
that isn't threaded (e.g. hrtimers or explicit IRQF_NO_THREAD).

If a driver exposes an interface that can be called in hard IRQ context,
it must use spin_lock_irqsave() in its interrupt handler (or use
IRQF_NO_THREAD) because of "threadirqs".

Johan

      reply	other threads:[~2020-11-21 15:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19  9:01 [PATCH] tty: serial: replace spin_lock_irqsave by spin_lock in hard IRQ Tian Tao
2020-11-19  9:03 ` Jiri Slaby
2020-11-20  8:23 ` Johan Hovold
2020-11-20 11:25   ` tiantao (H)
2020-11-20 12:49     ` Johan Hovold
2020-11-20 20:00       ` David Laight
2020-11-21 15:17         ` Johan Hovold [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X7kviiRwuxvPxC8O@localhost \
    --to=johan@kernel.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=afaerber@suse.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=tglx@linutronix.de \
    --cc=tiantao6@hisilicon.com \
    --cc=tiantao6@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).