All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
	Steven Rostedt <rostedt@goodmis.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Dmitry Vyukov <dvyukov@google.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-serial <linux-serial@vger.kernel.org>,
	SergeySenozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [RFC][PATCH 0/6] Use printk_safe context for TTY and UART port locks
Date: Wed, 20 Jun 2018 11:50:50 +0900	[thread overview]
Message-ID: <20180620025050.GE650@jagdpanzerIV> (raw)
In-Reply-To: <CA+55aFz9aGc-vGvKv_ZR2W2ZkZNSZfOHa0m_MbGH_a=x8oAW5Q@mail.gmail.com>

On (06/20/18 11:01), Linus Torvalds wrote:
> On Tue, Jun 19, 2018 at 5:30 PM Petr Mladek <pmladek@suse.com> wrote:
> >
> > To make it clear. This patch set adds yet another spin_lock API.
> > It behaves exactly as spin_lock_irqsafe()/spin_unlock_irqrestore()
> > but in addition it sets printk_context.
> >
> > This patchset forces safe context around TTY and UART locks.
> > In fact, the deferred context would be enough to prevent
> > all the mentioned deadlocks.
> 
> Please stop this garbage.

I'm guessing the message was addressed to me, not to Petr.
Let me explain myself.

> The rule is simple: DO NOT DO THAT THEN.
>
> Don't make recursive locks. Don't make random complexity.  Just stop
> doing the thing that hurts.

We didn't add any of those recursive printk()-s. Those are the things
like kmalloc()/scheduler/etc which tty/etc invoke that hurt.

> There is no valid reason why an UART driver should do a printk() of
> any sort inside the critical region where the console is locked.

It's not UART on its own that immediately calls into printk(), that would
be trivial to fix, it's all those subsystems that serial console driver
can call into.

For instance, kernel/workqueue.c - it may WARN_ON/printk in various cases.
And those WARNs/printks are OK. Except for one thing: workqueue can be
called from a serial console driver, which suddenly will turn those
WARNs/printks into illegal ones, due to possible deadlocks. And serial
consoles can call into WQ. Not directly, but via tty code.

A random example:

s3c24xx_serial_rx_chars_dma()
 spin_lock_irqsave(&port->lock, flags);
  tty_flip_buffer_push()
   __queue_work()
 spin_unlock_irqrestore(&port->lock, flags);

Should for some reason WQ warn/printk, we are done, because we will
end up taking the same port->lock:

  __queue_work()
    printk()
     call_console_drivers()
      spin_lock_irqsave(&port->lock, flags);

IOW, there is this tricky "we were called from a serial driver" context,
which is hard to track, but printk_safe can help us in those cases. There
are other examples. WQ is not the only thing serial drivers can call into.
So that's why I sent the patch set.

	-ss

  parent reply	other threads:[~2018-06-20  2:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-15  9:39 [RFC][PATCH 0/6] Use printk_safe context for TTY and UART port locks Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 1/6] printk: move printk_safe macros to printk header Sergey Senozhatsky
2018-06-18  6:27   ` Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 2/6] tty: add tty_port locking helpers Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 3/6] tty/pty: switch to tty_port helpers Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 4/6] serial: add uart port locking helpers Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 5/6] serial: switch to uart_port " Sergey Senozhatsky
2018-06-15  9:39 ` [RFC][PATCH 6/6] tty: 8250: " Sergey Senozhatsky
2018-06-18 13:38 ` [RFC][PATCH 0/6] Use printk_safe context for TTY and UART port locks Alan Cox
2018-06-19  0:53   ` Sergey Senozhatsky
2018-06-19  8:30     ` Petr Mladek
2018-06-19  8:59       ` Sergey Senozhatsky
2018-06-20  2:01       ` Linus Torvalds
2018-06-20  2:34         ` Steven Rostedt
2018-06-20  2:44           ` Linus Torvalds
2018-06-22 16:21             ` Alan Cox
2018-06-22 16:39               ` Peter Zijlstra
2018-06-23  5:21               ` Sergey Senozhatsky
2018-06-20  2:56           ` Sergey Senozhatsky
2018-06-20  2:50         ` Sergey Senozhatsky [this message]
2018-06-20  3:38           ` Linus Torvalds
2018-06-20  4:28             ` Sergey Senozhatsky
2018-06-28  2:55             ` Sergey Senozhatsky
2018-06-19  8:08   ` Peter Zijlstra

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=20180620025050.GE650@jagdpanzerIV \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.