Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1657058

Re: [bisected] Re: tty lockdep trace

From Mike Galbraith <efault@gmx.de>
Newsgroups linux.kernel
Subject Re: [bisected] Re: tty lockdep trace
Date 2017-06-04 13:40 +0200
Message-ID <tOC2Z-4oc-9@gated-at.bofh.it> (permalink)
References <tNfBw-7MH-9@gated-at.bofh.it> <tOaT7-3vS-3@gated-at.bofh.it> <tOzeO-2mD-3@gated-at.bofh.it> <tOzHQ-2Og-5@gated-at.bofh.it> <tOADT-3sO-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, 2017-06-04 at 12:00 +0200, Vegard Nossum wrote:
> 
> I don't know how you did it, but this passes my testing (reproducers for
> both the original issue and the lockdep splat/hang).

I suppose I can sign it off, see if that inspires anyone to come up
with something better.

drivers/tty: Fix 925bb1ce47f4 circular locking dependency

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.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Fixes: 925bb1ce47f4 ("tty: fix port buffer locking")
---
 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);
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

tty lockdep trace Dave Jones <davej@codemonkey.org.uk> - 2017-05-31 19:30 +0200
  [bisected] Re: tty lockdep trace Mike Galbraith <efault@gmx.de> - 2017-06-03 08:40 +0200
    Re: [bisected] Re: tty lockdep trace Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-04 10:40 +0200
      Re: [bisected] Re: tty lockdep trace Mike Galbraith <efault@gmx.de> - 2017-06-04 11:10 +0200
        Re: [bisected] Re: tty lockdep trace Vegard Nossum <vegard.nossum@oracle.com> - 2017-06-04 12:10 +0200
          Re: [bisected] Re: tty lockdep trace Mike Galbraith <efault@gmx.de> - 2017-06-04 13:40 +0200
            Re: [bisected] Re: tty lockdep trace Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-06-05 17:10 +0200
              Re: [bisected] Re: tty lockdep trace Mike Galbraith <efault@gmx.de> - 2017-06-05 17:50 +0200
          [patch] tty: fix port buffer locking V2 Mike Galbraith <efault@gmx.de> - 2017-06-05 07:00 +0200
            Re: [patch] tty: fix port buffer locking V2 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-05 08:50 +0200
              Re: [patch] tty: fix port buffer locking V2 Mike Galbraith <efault@gmx.de> - 2017-06-05 09:20 +0200

csiph-web