Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 048BFC433F5 for ; Thu, 11 Nov 2021 09:27:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF93261106 for ; Thu, 11 Nov 2021 09:27:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbhKKJ37 (ORCPT ); Thu, 11 Nov 2021 04:29:59 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:49884 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbhKKJ36 (ORCPT ); Thu, 11 Nov 2021 04:29:58 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 5B54C1FD29; Thu, 11 Nov 2021 09:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1636622827; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pl6aAvDoTx6EdeF3PlSqs4c8bMd7axYmKzOYDsF5224=; b=En04iaVMWrZRqB7CcOMiYmOz7s7M5ASxSf/5/slytEjXMAyyLB7xo155L8gXz04268QjUf MqZSRmmG478bkrPYtZs4dne43QMHz+h6EDa8HvEIC1+X+Ao26+F2SQ0UwmFG33a0q06jiJ uBC5LH7JDN2wEmUYYqQGljwjQFsGyi0= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C9647A3B84; Thu, 11 Nov 2021 09:27:06 +0000 (UTC) Date: Thu, 11 Nov 2021 10:27:06 +0100 From: Petr Mladek To: Peter Zijlstra , Sultan Alsawaf , Anton Vorontsov , Ben Segall , Colin Cross , Daniel Bristot de Oliveira , David Airlie , Dietmar Eggemann , dri-devel@lists.freedesktop.org, Ingo Molnar , John Ogness , Juri Lelli , Kees Cook , linux-kernel@vger.kernel.org, Maarten Lankhorst , Maxime Ripard , Mel Gorman , Sergey Senozhatsky , Steven Rostedt , Thomas Zimmermann , Tony Luck , Vincent Guittot , mkoutny@suse.com Subject: Re: printk deadlock due to double lock attempt on current CPU's runqueue Message-ID: References: <20211109213847.GY174703@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2021-11-10 10:37:26, Daniel Vetter wrote: > On Tue, Nov 09, 2021 at 10:38:47PM +0100, Peter Zijlstra wrote: > > On Tue, Nov 09, 2021 at 12:06:48PM -0800, Sultan Alsawaf wrote: > > > Hi, > > > > > > I encountered a printk deadlock on 5.13 which appears to still affect the latest > > > kernel. The deadlock occurs due to printk being used while having the current > > > CPU's runqueue locked, and the underlying framebuffer console attempting to lock > > > the same runqueue when printk tries to flush the log buffer. > > > > Yes, that's a known 'feature' of some consoles. printk() is in the > > process of being reworked to not call con->write() from the printk() > > calling context, which would go a long way towards fixing this. > > And it's getting worse by the year: > - direct scanout displays (i.e. just a few mmio writes and it will show > up) are on the way out at least in laptops, everyone gets self-refresh > (dp psr) under software control, so without being able to kick a kthread > off nothing shows up except more oopses printk() tries to avoid this problem by waking processes via irq_vork(). For example, it is used for waking userspace log daemons, see wake_up_klogd(). There is one hidden wake_up_process() in up() of @console_sem. It is "less" critical because it calls the wake_up() only when there is another process waiting for console_lock(). It must be a non-printk caller because printk() uses trylock and does not add waiters. So, there is a non-trivial chance to avoid the deadlock and the messages. I wonder if fbdev might use the same trick. > - because of the impendence mismatch between fbdev and drm-kms we even go > ever more this direction for dumb framebuffers, including the firmware > boot-up framebuffer simpledrm. This could perhaps be fixed with a new > dedicate console driver directly on top of drm-kms, but that's on the > wishlist for years and I don't see anyone typing that. > > So yeah for fbcon at least I think we really should throw out direct > con->write from printk completely. Yup, that would be great. Well, I guess that it would be available only for a panic mode when it will not race with other users? Best Regards, Petr