Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp354824rwp; Wed, 12 Jul 2023 14:34:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3ILNjYbWlAyUrBveqaUT6rk35ORpmbC0A9iDntW0Wm5+lzg23pgWOjc6Yc60wkNdDWTu/ X-Received: by 2002:a17:90b:1215:b0:262:ebb9:dd59 with SMTP id gl21-20020a17090b121500b00262ebb9dd59mr18794140pjb.20.1689197673475; Wed, 12 Jul 2023 14:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689197673; cv=none; d=google.com; s=arc-20160816; b=GV0qzJPMBerYBzhgep7vNM2LtTymos0HRa6D3MIIjhAqepjIoTLWhPUZ/g0WMhAIS0 HuQ+uEUp2XUJwdEr7p4m/j4pOkJ6ptZOOnONKd+FhcrnMJL17ItI2rC98rBKS1GKFNNE u77OTkDY33fSdSLDzMiHBM1KAA5iHSnsHaHgYpfT3iF0o1oPJcBoLzR/o/AsatYoSO9s TR98N7YHwDQ5Qc1p9Hp30EJmU5nrxI84kLf1ossJz2aCvZUdZuDk7WRTnFy2CeXCcLnj lJCi5Jw+bjf1vzaziZ3tfdOChlpwe4gN4qIkERsEOMldzeyFtuXEc/fgyF/0b7/u8Kix Petg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=7/jsuRRgpKVi1Dyg8tuPASmeiuQU2l99KQrKwfJWYio=; fh=HVRBJStvoKWbFco6Jta18xe5UAVCwWVs9OvJstciom4=; b=PewTLbeeaJHBsruaxu0sbHLcrmYABfEiB91+Kla6UKi4SLZ/hCYtSxuOPinampQUG+ L/2xVbtA2Anb+Fr3FyORx//iEUd/KYNAjAYcBAg6dqw1tT79AuvKTBycV6O+wIq4nQw0 V4FgU1dHN23JPnOiBSQHRV9etvogqLIaV0hl/ocbT5nqDDpoZ7yBN7ItcnUdOCuGAK0d OtrvCGFyrgEzSDLf6CRFc3xQxieszIPTCwSjbn15yIdCWSJFemoeEi+I1MZFJPRjEnoE OAk4D0l7VX6UUiMzC0092kKSM+iyRpcN76sAbjsY7kYYX2L8FztNuxluyf7MjbeiuED7 0mmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zBdPbDU5; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a17090a9c0700b00263d1729212si11756403pjp.85.2023.07.12.14.34.21; Wed, 12 Jul 2023 14:34:33 -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=@linutronix.de header.s=2020 header.b=zBdPbDU5; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233096AbjGLVNr (ORCPT + 99 others); Wed, 12 Jul 2023 17:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbjGLVMf (ORCPT ); Wed, 12 Jul 2023 17:12:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADAFD2D5A for ; Wed, 12 Jul 2023 14:11:56 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689196313; h=from:from:reply-to:subject:subject: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=7/jsuRRgpKVi1Dyg8tuPASmeiuQU2l99KQrKwfJWYio=; b=zBdPbDU5kwGUJZfCdfJDaVfe9tUCMLOr+V/SgtGFcgZdR896Z/4izPg8GfUOQ1ENSE6dKf ctPYxqucX2m9EJwoiMdGE7eZZdHDEZ1DeDbYxmBggNVq6NCG+5nrqXwh+G9SGEM2iDevLV QD7apwP8HIbwB9k3CeFagYONHQWIaBbHiHlXF4385d9SsjV3bm+YBGAnv3IHO4aaj699ce Ax4gHRulsceJBeE9suuJJrS606GLK53BDi69dJAclNwdPChsYTIE4YJYT8PEyFuc8w/YdC 82zStTPQY+dh2R9SDSyeKyb+JkQpM90KS7Z8cty/lISA6pzZnaKyIeRWj72z5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689196313; h=from:from:reply-to:subject:subject: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=7/jsuRRgpKVi1Dyg8tuPASmeiuQU2l99KQrKwfJWYio=; b=aSW59uS2VueQlyWb+RkWeQsdzdJI2lImPJxTlftYjAUlwsaiGb0TRsXD9xmcW1RcM8fnst VoplwGI4h/Hh11DA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v2 2/5] printk: Add NMI safety to console_flush_on_panic() and console_unblank() In-Reply-To: References: <20230710134524.25232-1-john.ogness@linutronix.de> <20230710134524.25232-3-john.ogness@linutronix.de> Date: Wed, 12 Jul 2023 23:17:49 +0206 Message-ID: <878rbkrg16.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 2023-07-11, Petr Mladek wrote: > Just to be sure. The semaphore is not NMI safe because even the > trylock takes an internal spin lock. Am I right, please? Yes, that is one of the reasons. Sergey mentioned another (waking a task on up()). > Alternative solution would be to make down_trylock() NMI safe > by using raw_spin_trylock_irqsave() for the internal lock. NMI contexts are only allowed to take raw spinlocks if those spinlocks are only used from NMI context. Otherwise you could have deadlock: raw_spin_lock() --- NMI --- raw_spin_lock() Using a trylock does not avoid the deadlock danger. > Another question is whether we want to call c->unblank() > in NMI even when down_trylock() was NMI safe. It seems that it > is implemented only for struct console vt_console_driver. > I am pretty sure that it takes more internal locks which > are not NMI safe either. Yes, it does. As an example, it calls mod_timer(), which is also not NMI safe. Clearly the unblank() callback must not be called in NMI context. > Finally, it is not only about NMI. Any locks might cause a deadlock > in panic() in any context. It is because other CPUs are stopped > and might block some locks. With the atomic/threaded model this is not true. The port ownership can be safely taken over from stopped CPUs. > In my opinion, we should handle c->unblank() in panic() the same way > as c->write() in panic(). I do not agree. Clearly unblank() is not NMI safe. Also, in current mainline code, console_unblank() will already give up if the trylock failed (rather than ignoring the lock, like write() does). So console_unblank() might as well also give up if in NMI context. John