Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp204523lfu; Wed, 30 Mar 2022 20:51:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFcP81zF0uCbbBX75FoNYTgSd2csoFNwKuutOgKsRY8qJeAcY1/lj14v89JIoFG8PklkbN X-Received: by 2002:a62:cf82:0:b0:4fa:e33e:4225 with SMTP id b124-20020a62cf82000000b004fae33e4225mr3173361pfg.25.1648698717454; Wed, 30 Mar 2022 20:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648698717; cv=none; d=google.com; s=arc-20160816; b=i0/LCMpDZIiErilVd0D87JEZZyz3aiBHdpRaSgvBuGnvyUrP7IpgZygUx0Crj9zODX t+vX7nNhHqSD0u9cO/h59Ll2N96PWTYwbXxx+f2jBkkamQdlzqIsCTsrv3j+Ak1i504Q TOorFW99juSuXeyaBuZ76a9ItY9WcwaScKO9yTtmYr78uRjpCuGyk3b4Q30Q5EZR1eaT QL8E1frTSl3FioGFppPTo9CWcH9ME7Q74mSJV0HrBhaBCoYv/kUIdL0iMC/QImF0mOjd M/458J5l8MdxBXzFYd7IRDx0VI3PcuHsTbYnqNUk0up8LOayVuxawG+0eiJ6l4rvOOHx 0pJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Af196VdAWXNTHnr0FKJKV/wGVy+XmAMN/WxWLTrX5pc=; b=y6wqDVjKbPQh/Nx0C8P6zp6e5qdGZvP5DIpJl0zzDcTteMpe6Q7SttXRwkEZRQHSet eBCeTSQIbldkOM69Sr7TLk1Hixd1hZ3scwCA0eLmqog8x33I0ClAyptLvRk6fxg/dMjt tbjwX9VfjTPSozjMqSEd7r/yuHtjhiQZ1m+mpzoD3zljpExAGau8dFdPF36q5k92xp+x 3EDOhz678hlRBKnui1vgNebrpvtU5ojZ5PjBMs1TftWtq2bObphGwiQLapyV428Pdonv Yexnz4zREG2W1P9tbhN8Lxr4Y0QGQlUUC9DVhWW2gPDmuT6saWnIFNeaVPEHgTFE5zx7 GkLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MvqMI68l; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s5-20020a17090302c500b00153b2d1646asi23885519plk.114.2022.03.30.20.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:51:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MvqMI68l; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1AFF155BC2; Wed, 30 Mar 2022 20:05:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244742AbiC3L77 (ORCPT + 99 others); Wed, 30 Mar 2022 07:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344676AbiC3LxX (ORCPT ); Wed, 30 Mar 2022 07:53:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60C6326C2DD; Wed, 30 Mar 2022 04:49:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DFC88B81C23; Wed, 30 Mar 2022 11:49:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A607EC36AE3; Wed, 30 Mar 2022 11:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640963; bh=YGc7WmUAaF+RqDeiav9aNLIe7E7IZAsP7q1KD+SY1pU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MvqMI68lgYD0ndtSuGX8lSNdIK9yZ3pgUrlQ6qvM7P33CKaBhSGsJ3Al/3vu2W8HA WIwYYgt27JwH4l2/Tbe91EWdJtVn5+xbCPBFmftgQQaHhdIhz6jJUbwvFsoO3vJNri o7EQGSMr3//6ekkkS1Dobfxxcq3cliV7CUhzj6rPwcNaooGCXfdqr01lGASEeLxW2J F8WnIZJU7wlib9YSU+F2A63/Zs1eIj0jP+CoCALJAyOgdcAijdEfW/wW8t0YKEcyKh MEy7auzcddKZVM58P4pSAglcBwkLQn4AwlF4dRgrPFnKGLWUJX/5oelFVGmb+wfPN2 h8JMn4PklNzkw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stephen Brennan , Petr Mladek , Sergey Senozhatsky , Sasha Levin , linux@roeck-us.net, gregkh@linuxfoundation.org Subject: [PATCH AUTOSEL 5.16 33/59] printk: Drop console_sem during panic Date: Wed, 30 Mar 2022 07:48:05 -0400 Message-Id: <20220330114831.1670235-33-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Stephen Brennan [ Upstream commit 8ebc476fd51e6c0fd3174ec1959a20ba99d4c5e5 ] If another CPU is in panic, we are about to be halted. Try to gracefully abandon the console_sem, leaving it free for the panic CPU to grab. Suggested-by: Petr Mladek Signed-off-by: Stephen Brennan Reviewed-by: Petr Mladek Reviewed-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/20220202171821.179394-5-stephen.s.brennan@oracle.com Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f7c4c53a2c35..92eb7785e6e7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2588,6 +2588,25 @@ static int have_callable_console(void) return 0; } +/* + * Return true when this CPU should unlock console_sem without pushing all + * messages to the console. This reduces the chance that the console is + * locked when the panic CPU tries to use it. + */ +static bool abandon_console_lock_in_panic(void) +{ + if (!panic_in_progress()) + return false; + + /* + * We can use raw_smp_processor_id() here because it is impossible for + * the task to be migrated to the panic_cpu, or away from it. If + * panic_cpu has already been set, and we're not currently executing on + * that CPU, then we never will be. + */ + return atomic_read(&panic_cpu) != raw_smp_processor_id(); +} + /* * Can we actually use the console at this time on this cpu? * @@ -2736,6 +2755,10 @@ void console_unlock(void) if (handover) return; + /* Allow panic_cpu to take over the consoles safely */ + if (abandon_console_lock_in_panic()) + break; + if (do_cond_resched) cond_resched(); } @@ -2753,7 +2776,7 @@ void console_unlock(void) * flush, no worries. */ retry = prb_read_valid(prb, next_seq, NULL); - if (retry && console_trylock()) + if (retry && !abandon_console_lock_in_panic() && console_trylock()) goto again; } EXPORT_SYMBOL(console_unlock); -- 2.34.1