From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Raul Rangel <rrangel@google.com>,
Tony Lindgren <tony@atomide.com>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
kurt@linutronix.de, "S, Shirish" <Shirish.S@amd.com>,
Peter Zijlstra <peterz@infradead.org>,
John Ogness <john.ogness@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: UART/TTY console deadlock
Date: Tue, 30 Jun 2020 19:55:12 +0900 [thread overview]
Message-ID: <20200630105512.GA530@jagdpanzerIV.localdomain> (raw)
In-Reply-To: <20200630102141.GA11587@alley>
On (20/06/30 12:21), Petr Mladek wrote:
> > So... Do we need to hold uart->port when we disable port->irq? What do we
> > race with? Module removal? The function bumps device PM counter (albeit
> > for UART_CAP_RPM ports only).
>
> Honestly, I do not see where a PM counter gets incremented.
serial8250_do_startup()
serial8250_rpm_get()
pm_runtime_get_sync(p->port.dev)
But this does not happen for all ports, just for UART_CAP_RPM ones.
> Anyway, __disable_irq_nosync() does nothing when
> irq_get_desc_buslock() returns NULL. And irq_get_desc_buslock()
> takes desc->lock when desc exist. This should be enough to
> synchronize any calls.
>
> > But, at the same time, we do a whole bunch
> > of unprotected port->FOO accesses in serial8250_do_startup(). We even set
> > the IRQF_SHARED up->port.irqflags without grabbing the port->lock:
> >
> > up->port.irqflags |= IRQF_SHARED;
> > spin_lock_irqsave(&port->lock, flags);
> > if (up->port.irqflags & IRQF_SHARED)
> > disable_irq_nosync(port->irq);
>
> Yup, this looks suspicious. We set a flag in port.irqflags and take the lock
> only when the flag was set. Either everything needs to be done under
> the lock or the lock is not needed.
>
> Well, I might have missed something. I do not fully understand meaning
> and relation of all the structures.
>
> Anyway, I believe that this is a false positive. If I get it correctly
> serial8250_do_startup() must be called before the serial port could
> be registered as a console. It means that it could not be called
> from inside printk().
From my understanding, I'm afraid we are talking about actual deadlock
here, not about false positive report. Quoting the original email:
: We are trying an S3 suspend stress test and occasionally while
: entering S3 we get a console deadlock.
[..]
> > drivers/tty/serial/8250/8250_port.c | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> > index d64ca77d9cfa..ad30991e1b3b 100644
> > --- a/drivers/tty/serial/8250/8250_port.c
> > +++ b/drivers/tty/serial/8250/8250_port.c
> > @@ -2275,6 +2275,11 @@ int serial8250_do_startup(struct uart_port *port)
> >
> > if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) {
> > unsigned char iir1;
> > + bool irq_shared = up->port.irqflags & IRQF_SHARED;
> > +
> > + if (irq_shared)
> > + disable_irq_nosync(port->irq);
> > +
> > /*
> > * Test for UARTs that do not reassert THRE when the
> > * transmitter is idle and the interrupt has already
> > @@ -2284,8 +2289,6 @@ int serial8250_do_startup(struct uart_port *port)
> > * allow register changes to become visible.
> > */
> > spin_lock_irqsave(&port->lock, flags);
> > - if (up->port.irqflags & IRQF_SHARED)
> > - disable_irq_nosync(port->irq);
> >
> > wait_for_xmitr(up, UART_LSR_THRE);
> > serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> > @@ -2297,9 +2300,9 @@ int serial8250_do_startup(struct uart_port *port)
> > iir = serial_port_in(port, UART_IIR);
> > serial_port_out(port, UART_IER, 0);
> >
> > - if (port->irqflags & IRQF_SHARED)
> > - enable_irq(port->irq);
> > spin_unlock_irqrestore(&port->lock, flags);
> > + if (irq_shared)
> > + enable_irq(port->irq);
> >
> > /*
> > * If the interrupt is not reasserted, or we otherwise
>
> I think that it might be safe but I am not 100% sure, sigh.
Yeah, I'm not 100%, but I'd give it a try.
-ss
next prev parent reply other threads:[~2020-06-30 10:55 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 17:30 UART/TTY console deadlock Raul Rangel
2020-06-22 17:37 ` Andy Shevchenko
2020-06-30 3:58 ` Sergey Senozhatsky
2020-06-30 10:21 ` Petr Mladek
2020-06-30 10:55 ` Sergey Senozhatsky [this message]
2020-06-30 11:40 ` Andy Shevchenko
2020-06-30 12:22 ` Petr Mladek
2020-06-30 13:05 ` Sergey Senozhatsky
2020-06-30 18:02 ` Tony Lindgren
2020-07-01 6:44 ` S, Shirish
2020-07-02 3:48 ` S, Shirish
2020-07-02 6:11 ` Greg Kroah-Hartman
2020-07-02 6:14 ` S, Shirish
2020-07-02 6:34 ` Sergey Senozhatsky
2020-07-02 7:11 ` Greg Kroah-Hartman
2020-07-02 5:12 ` Sergey Senozhatsky
2020-07-02 5:40 ` Sergey Senozhatsky
2020-07-02 8:20 ` Andy Shevchenko
2020-07-03 10:53 ` Sergey Senozhatsky
2020-07-04 11:37 ` Andy Shevchenko
2020-07-02 16:05 ` Tony Lindgren
2020-07-03 10:32 ` Sergey Senozhatsky
2020-07-04 11:35 ` Andy Shevchenko
2020-07-04 11:59 ` Andy Shevchenko
2020-07-06 11:31 ` Kurt Kanzenbach
2020-07-06 14:43 ` Sergey Senozhatsky
2020-07-08 7:40 ` Kurt Kanzenbach
2020-07-08 8:07 ` Sergey Senozhatsky
2020-07-08 9:52 ` Petr Mladek
2020-07-09 13:22 ` Sergey Senozhatsky
2020-07-14 16:16 ` Raul Rangel
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=20200630105512.GA530@jagdpanzerIV.localdomain \
--to=sergey.senozhatsky@gmail.com \
--cc=Shirish.S@amd.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=kurt@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=rrangel@google.com \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=tony@atomide.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).