Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2218571ybp; Thu, 10 Oct 2019 04:12:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyG57Tpvv8Nj7pZKn7Dt808fJ05hsj9+BKtxe32sU9E4fKeAGyj4rMX7/FUsWYbO1BDx8ST X-Received: by 2002:aa7:de02:: with SMTP id h2mr7545997edv.212.1570705947357; Thu, 10 Oct 2019 04:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570705947; cv=none; d=google.com; s=arc-20160816; b=ltLKght66sZXniQxXBI4/rxloA+/jHS1s4YJDBWQObBobgUaFMtxMB6i83cOEw5g2X C6pHhhErM01U5v8bC8U25i+4kjzGCi5cKxqybGV+QhZ5xewdLUhyo0WcZwKaBO2Ahhlv m75ru8gbJwR/Rii0PAH7hcNgc/0Qc8jgsXKRRGUq5RqsS9gMJccaU2CWfcOhaAv1AmMD nT0c5+IUsBl2yvgUejt4ToC4eL7TvvwgMv1TTsI7qAmaLXd0v6np25iIIsaQy7unqlko cGT6j80WDZ6PdouLK442kq9b+w/eF/OBtFt7ZsjiJ7p6G7t8oghnbUzzV2ucEcGlHFDD xc7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rrE3R/hd2LbtzGYONJO1VDtBqWyxfEqU6ytniLjor34=; b=kgpI7bT6myAt2GGlktibvQgWiI6Zq8gs/nMOtUt4RnOL0jMotNZz3DYDeFIwV2oA0r jgy/1hKX9GtEIf6jcGfRaUFeO9KsLlFLx2xwntBYOYcjSzoWZEtC6NXkpu+evXGgJPi2 4onO/g2s95SR9eANzi1BbLw2XPYsAtp7qye0wkRKmtrkNB8VKIb5/dB5yM5QtXVubGMz vxwb1urxr2BvwOE0jNDeoXNsOTmacMquyxqPnQ24lY+O6b485HW5kqzEHijhGBQUvJ4d ePySBRqu7oYHOtC5AH1JdsCTvpWT0T2iyG2aKqnVrHxRaHl8nxMsTs/R4H4hdVlIHYsd zmHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si3458723edm.103.2019.10.10.04.12.03; Thu, 10 Oct 2019 04:12:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbfJJLL0 (ORCPT + 99 others); Thu, 10 Oct 2019 07:11:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:57314 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726201AbfJJLL0 (ORCPT ); Thu, 10 Oct 2019 07:11:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 55FC3AE36; Thu, 10 Oct 2019 11:11:24 +0000 (UTC) Date: Thu, 10 Oct 2019 13:11:23 +0200 From: Petr Mladek To: Sergey Senozhatsky Cc: Christian Borntraeger , Heiko Carstens , rostedt@goodmis.org, peterz@infradead.org, Michal Hocko , linux-mm@kvack.org, Qian Cai , john.ogness@linutronix.de, akpm@linux-foundation.org, Vasily Gorbik , Peter Oberparleiter , david@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/page_isolation: fix a deadlock with printk() Message-ID: <20191010111123.ql7c4v6hmmplutgb@pathway.suse.cz> References: <20191007144937.GO2381@dhcp22.suse.cz> <20191008074357.f33f6pbs4cw5majk@pathway.suse.cz> <20191008082752.GB6681@dhcp22.suse.cz> <1570550917.5576.303.camel@lca.pw> <1157b3ae-006e-5b8e-71f0-883918992ecc@linux.ibm.com> <20191009142623.GE6681@dhcp22.suse.cz> <20191010051201.GA78180@jagdpanzerIV> <20191010082110.dreavjarni7mkvv6@pathway.suse.cz> <20191010083908.GA2521@jagdpanzerIV> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191010083908.GA2521@jagdpanzerIV> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2019-10-10 17:39:08, Sergey Senozhatsky wrote: > On (10/10/19 10:21), Petr Mladek wrote: > [..] > > > > Considering that console.write is called from essentially arbitrary code > > > > path IIUC then all the locks used in this path should be pretty much > > > > tail locks or console internal ones without external dependencies. > > > > > > That's a good expectation, but I guess it's not always the case. > > > > > > One example might be NET console - net subsystem locks, net device > > > drivers locks, maybe even some MM locks (skb allocations?). > > > > > > But even more "commonly used" consoles sometimes break that > > > expectation. E.g. 8250 > > > > > > serial8250_console_write() > > > serial8250_modem_status() > > > wake_up_interruptible() > > > > > > And so on. > > > > I think that the only maintainable solution is to call the console > > drivers in a well defined context (kthread). We have finally opened > > doors to do this change. > > Yeah, that's a pretty complex thing, I suspect. Panic flush to > netcon may deadlock if oops occurs under one of those "important > MM locks" (if any MM locks are actually involved in ATOMIC skb > allocation). If there are such MM locks, then I think flush_on_panic > issue can't be address by printing kthread or ->atomic_write callback. Sure, we could not rely on kthreads in panic(). In this situation any lock taken from console->write() callback is a possible source of a deadlock. Note that I say that the locks are the problem and not printk() called under these locks. It is because: + The experience shows that we could not prevent people from using printk() anywhere. + printk() might get called even when it is not used explicitly. For example, from NMI, IRQ, Oops. So, the best solution is to avoid as many locks in console->write() callbacks as possible. Especially this means as less dependencies on external subsystems as possible. MM is an obvious candidate. We should avoid calling MM not only because it uses locks but also because there might not be any available memory. Of course, there are better and worse console drivers. It is hard to expect that all will or can be made safe. From the printk() point of view, the defense against the problematic consoles might be: + Classify each console driver. Flush all messages to the most reliable consoles first and to the least reliable ones at last. + Prevent calling consoles when there is other way to preserve the messages over the reboot, e.g. crashdump or permanent memory. Of course, we will still need a way how to actively search for problems in advance. For example, printk() could use a fake lock even during the normal operation so that it could trigger lockdep splat. We could enable it after all the init calls are proceed to reduce the number of false positives. Hmm, this discussion probably belongs to another thread about printk() design. Anyway, it seems that removing MM from console->write() calls is a win-win solution. Best Regards, Petr