public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Galbraith <efault@gmx.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dave Jones <davej@codemonkey.org.uk>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Jiri Slaby <jslaby@suse.com>,
	Vegard Nossum <vegard.nossum@oracle.com>
Subject: Re: [bisected] Re: tty lockdep trace
Date: Sun, 04 Jun 2017 11:02:52 +0200	[thread overview]
Message-ID: <1496566972.16375.10.camel@gmx.de> (raw)
In-Reply-To: <20170604083225.GA2959@kroah.com>

On Sun, 2017-06-04 at 10:32 +0200, Greg Kroah-Hartman wrote:
> On Sat, Jun 03, 2017 at 08:33:52AM +0200, Mike Galbraith wrote:
> > On Wed, 2017-05-31 at 13:21 -0400, Dave Jones wrote:
> > > Just hit this during a trinity run.
> > 
> > 925bb1ce47f429f69aad35876df7ecd8c53deb7e is the first bad commit
> > commit 925bb1ce47f429f69aad35876df7ecd8c53deb7e
> > Author: Vegard Nossum <vegard.nossum@oracle.com>
> > Date:   Thu May 11 12:18:52 2017 +0200
> > 
> >     tty: fix port buffer locking
> 
> Now reverting this.  Oops, sorry, forgot to add Dave and your names to
> the patch revert.  The list of people who reported this was really long,
> many thanks for this.

If flush_to_ldisc() is the problem, and taking atomic_write_lock in
that path an acceptable solution, how about do that a bit differently
instead.  Lockdep stopped grumbling, vbox seems happy.

925bb1ce47f4 (tty: fix port buffer locking) upset lockdep by holding buf->lock
while acquiring tty->atomic_write_lock.  Move acquisition to flush_to_ldisc(),
taking it prior to taking buf->lock.  Costs a reference, but appeases lockdep.

Not-so-signed-off-by: /me
---
 drivers/tty/tty_buffer.c |   10 ++++++++++
 drivers/tty/tty_port.c   |    2 --
 2 files changed, 10 insertions(+), 2 deletions(-)

--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -465,7 +465,13 @@ static void flush_to_ldisc(struct work_s
 {
 	struct tty_port *port = container_of(work, struct tty_port, buf.work);
 	struct tty_bufhead *buf = &port->buf;
+	struct tty_struct *tty = READ_ONCE(port->itty);
+	struct tty_ldisc *disc = NULL;
 
+	if (tty)
+		disc = tty_ldisc_ref(tty);
+	if (disc)
+		mutex_lock(&tty->atomic_write_lock);
 	mutex_lock(&buf->lock);
 
 	while (1) {
@@ -501,6 +507,10 @@ static void flush_to_ldisc(struct work_s
 	}
 
 	mutex_unlock(&buf->lock);
+	if (disc) {
+		mutex_unlock(&tty->atomic_write_lock);
+		tty_ldisc_deref(disc);
+	}
 
 }
 
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -34,9 +34,7 @@ static int tty_port_default_receive_buf(
 	if (!disc)
 		return 0;
 
-	mutex_lock(&tty->atomic_write_lock);
 	ret = tty_ldisc_receive_buf(disc, p, (char *)f, count);
-	mutex_unlock(&tty->atomic_write_lock);
 
 	tty_ldisc_deref(disc);
 

  reply	other threads:[~2017-06-04  9:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 17:21 tty lockdep trace Dave Jones
2017-06-03  6:33 ` [bisected] " Mike Galbraith
2017-06-04  8:32   ` Greg Kroah-Hartman
2017-06-04  9:02     ` Mike Galbraith [this message]
2017-06-04 10:00       ` Vegard Nossum
2017-06-04 11:34         ` Mike Galbraith
2017-06-05 15:09           ` Alan Cox
2017-06-05 15:41             ` Mike Galbraith
2017-06-05  4:52         ` [patch] tty: fix port buffer locking V2 Mike Galbraith
2017-06-05  6:48           ` Greg Kroah-Hartman
2017-06-05  7:16             ` Mike Galbraith
2017-06-07  2:07           ` [lkp-robot] [tty] 52b03e644f: calltrace:flush_to_ldisc kernel test robot
2017-06-07  2:25             ` Mike Galbraith

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=1496566972.16375.10.camel@gmx.de \
    --to=efault@gmx.de \
    --cc=davej@codemonkey.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vegard.nossum@oracle.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