From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751180AbdFDJDO convert rfc822-to-8bit (ORCPT ); Sun, 4 Jun 2017 05:03:14 -0400 Received: from mout.gmx.net ([212.227.17.22]:50198 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005AbdFDJDH (ORCPT ); Sun, 4 Jun 2017 05:03:07 -0400 Message-ID: <1496566972.16375.10.camel@gmx.de> Subject: Re: [bisected] Re: tty lockdep trace From: Mike Galbraith To: Greg Kroah-Hartman Cc: Dave Jones , Linux Kernel , Jiri Slaby , Vegard Nossum Date: Sun, 04 Jun 2017 11:02:52 +0200 In-Reply-To: <20170604083225.GA2959@kroah.com> References: <20170531172117.nj5fwgqspibg7rs6@codemonkey.org.uk> <1496471632.11868.1.camel@gmx.de> <20170604083225.GA2959@kroah.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 Mime-Version: 1.0 Content-Transfer-Encoding: 8BIT X-Provags-ID: V03:K0:c6vNvndfxY4+vf56ztUQe/cup0+Mtjiheap4BlII7VOnvL+GjON 7TnGqgUViZ+GoYiIu0yf0EsdhiFq7lSQOKHg97cTSTKAI207uq/xVIIrgVpatolR2LB+ukk 6RRuHSrxoInnT5HVhcvmPU0OUSMPnJNN8PlWSLnzhOWwSBEu3FLCLaloY9R0EnL2hB9M/tx 5D6eWgCw8POdf9yecABXA== X-UI-Out-Filterresults: notjunk:1;V01:K0:xkRYTUJRDuI=:RarxZEhgL9b1VIX2Vlm4CV Y/VLiDNbuS2mrvQOLgwSz8+AoWHsaXwnjqHZaY0r24jNaf1cBp/Mc0KrZ9ekxmMXBN+SsUOi9 /wqczroeVpKBcRsxXsFRPcFI2Y3WvyNHcKT2vq0gLmCGmwCxLl0t7qD2cvdPy8vDPMJ3l0HQA PU7cANF+63aCIN1AUY62yFYemKYWJzsE+IQcgepPFMffAIgBf+olmgmGkSSDzz9Zgwy6slWLC R3FIOy3zga7jxOxbinTJGMmMFw63lBpYIJA7LgFh5fzXRlO0k7slsfczRcljrbX3LU6rdPrYh nyA5jSAxVt5q0fTYlrjrJ6HktZBNQo/oFdP0IFzw+0iMK+lPEH9wnC/5hSUGwp779IXtYo4Az y+psFjCl6bc6u4JzQ5Tf7gSL0u0xJZbM0PTYEdyhfJoSbt+0XfpDFrE4D2Cvll9v3dc0h+Bth j5xSSndWqtoPGIBk2FxWiwECRGCPFJW2bVoGp2beKsyexJhZUDVyYvFQVWG00PPX+qoGpY6B9 Ra/j3YIP9dy6F3O5TMdAbIvnuMCU52LEujtJjFWCMovP7nTdFarorYsrekcmi8jMW2RP9MR4X 23390LO9ZQ/LWOMytf9y1MHA22LqpJS7koykyQzsPg67dPlNBkD1EX36aQ4sEYnDV3nUcPI3N RHJ9E5xfy3P5Ok3bKxMEhQI8AxQC9Aip8BwfdyiN+Vtcl60AbyKtsP4sAz4ekp/TE9EFwQSU+ TJ71rLEIOdyZhjta+M50Q34KTxoZGoKOnx8w0/U/FpS9f2adrh+pjMfLzfpf9ultOQr5galgH dniPFXA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > 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);