Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6675779rwp; Tue, 18 Jul 2023 04:22:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGTQQWzkmta27DUuqqJLl9GEEOEKgjL3fx2KU2birinu4CSoPeNF0CY4RtfOARI+A7WV4zk X-Received: by 2002:a05:6a00:1941:b0:682:713e:e510 with SMTP id s1-20020a056a00194100b00682713ee510mr15507613pfk.27.1689679330833; Tue, 18 Jul 2023 04:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689679330; cv=none; d=google.com; s=arc-20160816; b=dgxFTseik8NWCRESApl22jerHCTE+g8sYOjBeNjdtMlwpUOARMI08m7DGUr4xhxGlx ACCjjD7I6rrhPGBnTdhOflQqDu14HQNl+Gj4x+njki8Tq3UPrYiZKJ+MN3MmRsyJumSq R0SeksMWdUYqEqsT1YECMa7e4+IZVtWhnFxZbVC440MKe4X/RrR4qzjlUSdkCAkkbN05 4YmxHL6vEOn4PcM1ntuXeEqyN83PAQ8vShhbNHZAlNaq3mmY7iRNBDQlXucbG0gT5vpe EIyhxMdrtyVrFcX3ESrjsoTb2Ur0MBNKr5hxnwo2chGbCaayk5wto5RcGtTtq2RSxPSI qMpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YwF2Nf8weX8GOZqx7IRoWLwhlbkAR6nO1T17tt5sLB4=; fh=oPFVAToQkY6bsl1Vt24pO33VB3QR8tT4rK/qyEfOsuk=; b=YC2RWx5HLFtzevcxXfrGwo6W/OmzJ7E4gZzbOiJ8oGI31+i85MvgHGOkL13GSGNpHO ss3lngk6u1RKyS1jryHSt2X4FU6hT7UlOCQm+MpM9zoDH4tUa3cF9MCXo+suUiXsbNJF ZqBCAB1TioJg8ZrSJYPg/F8KqDBlfm053gQvtsSZanT3V5pF/Pkk0ucsnbbWm28ojQ3G UYZIdB9RQgX6a8++X+dLjhCZzHvdKlGjT2tpsM88jup70NWn7eM3sUeODRguhi/XwC5i ELFmo69YYpnco9ruI4Q0nhoOEWP96Ij3sxKb5hb9DH9XRmw9IIJmcPfnFeIyg+OoyFYx IJdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pZCpWVWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a056a00085100b0067b77e7f472si1381598pfk.402.2023.07.18.04.21.57; Tue, 18 Jul 2023 04:22:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pZCpWVWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbjGRKVR (ORCPT + 99 others); Tue, 18 Jul 2023 06:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjGRKVP (ORCPT ); Tue, 18 Jul 2023 06:21:15 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA06128 for ; Tue, 18 Jul 2023 03:21:13 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 97A1A1FDA9; Tue, 18 Jul 2023 10:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1689675672; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YwF2Nf8weX8GOZqx7IRoWLwhlbkAR6nO1T17tt5sLB4=; b=pZCpWVWkezRTIbLFi8VdLk8MWjn95m+lvAlEFzLjXbSu8NV1OaS0pWRzuCTxQESCE8dKdW 41A79gWL0fNbVuWNym5/VGr1Yjv43VV78Wcu38pS/ls6dSbRwSeCOFFWbfyzgqvtrqSyam gUhhmEzvGMcGmDR/4Xul5akp6l3Vwww= Received: from suse.cz (unknown [10.100.208.146]) (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 2F80F2C142; Tue, 18 Jul 2023 10:21:12 +0000 (UTC) Date: Tue, 18 Jul 2023 12:21:11 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v3 2/7] printk: Reduce console_unblank() usage in unsafe scenarios Message-ID: References: <20230717194607.145135-1-john.ogness@linutronix.de> <20230717194607.145135-3-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230717194607.145135-3-john.ogness@linutronix.de> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2023-07-17 21:52:02, John Ogness wrote: > A semaphore is not NMI-safe, even when using down_trylock(). Both > down_trylock() and up() are using internal spinlocks and up() > might even call wake_up_process(). > > In the panic() code path it gets even worse because the internal > spinlocks of the semaphore may have been taken by a CPU that has > been stopped. > > To reduce the risk of deadlocks caused by the console semaphore in > the panic path, make the following changes: > > - First check if any consoles have implemented the unblank() > callback. If not, then there is no reason to take the console > semaphore anyway. (This check is also useful for the non-panic > path since the locking/unlocking of the console lock can be > quite expensive due to console printing.) > > - If the panic path is in NMI context, bail out without attempting > to take the console semaphore or calling any unblank() callbacks. > Bailing out is acceptable because console_unblank() would already > bail out if the console semaphore is contended. The alternative of > ignoring the console semaphore and calling the unblank() callbacks > anyway is a bad idea because these callbacks are also not NMI-safe. > > If consoles with unblank() callbacks exist and console_unblank() is > called from a non-NMI panic context, it will still attempt a > down_trylock(). This could still result in a deadlock if one of the > stopped CPUs is holding the semaphore internal spinlock. But this > is a risk that the kernel has been (and continues to be) willing > to take. > > Signed-off-by: John Ogness Reviewed-by: Petr Mladek Best Regards, Petr