From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934142AbcATO7i (ORCPT ); Wed, 20 Jan 2016 09:59:38 -0500 Received: from lxorguk.ukuu.org.uk ([81.2.110.251]:52626 "EHLO lxorguk.ukuu.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751583AbcATO7h (ORCPT ); Wed, 20 Jan 2016 09:59:37 -0500 Date: Wed, 20 Jan 2016 14:58:43 +0000 From: One Thousand Gnomes To: Peter Zijlstra Cc: Dmitry Vyukov , Ingo Molnar , Greg Kroah-Hartman , Jiri Slaby , LKML , J Freyensee , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin , Eric Dumazet Subject: Re: tty: deadlock between n_tracerouter_receivebuf and flush_to_ldisc Message-ID: <20160120145843.4a51359e@lxorguk.ukuu.org.uk> In-Reply-To: <20160120120752.GQ3421@worktop> References: <20160115163300.063c224d@lxorguk.ukuu.org.uk> <20160120114430.GA25010@twins.programming.kicks-ass.net> <20160120120752.GQ3421@worktop> Organization: Intel Corporation X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.29; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > I read that, I didn't understand it. Which link is wrong and why? > > > And I don't understand how the following is a deadlock, since there is > > no cycle... > > > > Possible unsafe locking scenario: > > CPU0 CPU1 > > ---- ---- > > lock(&buf->lock); > > lock(&o_tty->termios_rwsem/1); > > lock(&buf->lock); > > lock(routelock); > > Ignore the stupid picture, it only really works for simple cases. There are two line disciplines using two different locking orders The two line disciplines never execute at once. A given tty is either using one or the other and there is a clear and correctly locked changeover. semantically its something a bit like foo(x) { if (x == 1) { lock(A) lock(B) } else { lock(B) lock(A) } Do stuff(); if (x == 1) { unlock(B) unlock(A) } else { unlock(A) unlock(B) } } with the guarantee made elsewhere that no instances of foo(1) and foo(0) are ever executing at the same time. That's not by dumb design - it's an interesting "nobody ever noticed this" turned up by the lock detector between two totaly unrelated bits of code. Alan