From patchwork Tue Sep 19 23:08:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3810183vqi; Tue, 19 Sep 2023 18:50:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6hEzgZRN7J5EUqYZIToQ1TJ2ioLL/z/xRJpJmo7o7RnSm4Nypg53CbPVoXd4syH+mUV68 X-Received: by 2002:a05:6a21:1f1d:b0:141:69d:8041 with SMTP id ry29-20020a056a211f1d00b00141069d8041mr1080410pzb.48.1695174639955; Tue, 19 Sep 2023 18:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695174639; cv=none; d=google.com; s=arc-20160816; b=pUAY9TaoD4c25qWAKFbko7QM6P+3SwibF/pcXrffjoyreZ5jhjhFAs3LBeh8OmnXhs kpEei+FuFzN8iYx4F8dj7o2WqzjWzRqf0n9WupwgYdl0jK0Gc7L0XVWdH+TNYLHzm/eQ 9pmkyCVBSLExAb5sOlwFcrJEw2oQa3/+uxfTb8wr5wTFDf6VJaLA/Y8WjQVXdRro2PNf Zqchi+XuLu0be/4RZgn3yyYKf/UfBYKUgouZtl9OmDBK9Ffa6p/YNqM/Y+e4hSFIDuT/ xTTtXZuzGnYujoRCa0ygC7+43Ivsk7C87VbdjXUHFXzkMoXcQp15H1/w6+Lg1Db+Feyv tiFg== 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:dkim-signature :dkim-signature:from; bh=e6s92XPeyfqns55O5jTkIEvWDYrDl5XhKnlZmE2CK28=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=MMCYKSJGNyyrycvZ8vfpw7RHp4NmTEPBKVoBIbf5yTSKPQ+EmaeyPhf9xSCKSxTe/P 5WPjQZPn/P93XXDfQaJlNz8mlXWIrqsmL9k6IKMNTd4PpTpKEnbfC4HVA4W9+941HqEs KA6d+YxBITkMA6Bgwa1hlXX039kYgUiEw60rtllXcxw4XvOr7364xibYzjw4GvpUWFC8 J22tB6Feg07+OMxQeWf0Y5SdwjXQUdlfwXifC6/JuB7RBjim6CM/Z8/DKcHfVxqygUD/ RF34yecnJbEfSsasn8w7P9qCGXKSgOh2QKza8F7CuhZExdjjxZ5225/7Fi3pZW73BG5C 0iDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TCq9eqDs; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id m3-20020a1709026bc300b001b876d46162si10606795plt.38.2023.09.19.18.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 18:50:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TCq9eqDs; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B39CF81CE845; Tue, 19 Sep 2023 16:09:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233295AbjISXJR (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjISXJP (ORCPT ); Tue, 19 Sep 2023 19:09:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A691EC0 for ; Tue, 19 Sep 2023 16:09:09 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e6s92XPeyfqns55O5jTkIEvWDYrDl5XhKnlZmE2CK28=; b=TCq9eqDsqo0un0UaFjxqttMu3RMPLZSB9CkxIOG/WIB5Drk8kKi0ikcoiJBqHLTUpifdkI y6bgwn/oAdNbCUmZeKACu8985q0G8FXdjbEPDHBMXyYlTEv/dfjTI6kenyvqJ25pObxl+z ZRhSg/3Oo4GQaK8ri+kjLy8s6eKaDfP62yATQQfw4Bu2M4HbBRBuf57R/9qqClcRQI6RdP 6mZ1xACNUaiyDBNWBez3re4R6fjn3lMgh8pgaeSVMvvgXbLY2j5mE8EmZqPJMp39wcY1yK XqT55KfMlDR8MWRSmdJH0EPGk9ZIcqKFZVPOAZOavzohrwPsIW4BwiaJfF5Oug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e6s92XPeyfqns55O5jTkIEvWDYrDl5XhKnlZmE2CK28=; b=aJOnXX1y9yMgTN5DhG/zR/7w8B9ntRqWNcINCTcBXeIXy2+O++8ZkJliBJGSN9OC6I+Edo trSa+VAvG/mokAAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 01/11] printk: Make console_is_usable() available to nbcon Date: Wed, 20 Sep 2023 01:14:46 +0206 Message-Id: <20230919230856.661435-2-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777519443333164019 X-GMAIL-MSGID: 1777519443333164019 Move console_is_usable() as-is into internal.h so that it can be used by nbcon printing functions as well. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 32 ++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 30 ------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6c2afee5ef62..6e8c1b02adae 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -78,6 +78,36 @@ bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +/* + * Check if the given console is currently capable and allowed to print + * records. + * + * Requires the console_srcu_read_lock. + */ +static inline bool console_is_usable(struct console *con) +{ + short flags = console_srcu_read_flags(con); + + if (!(flags & CON_ENABLED)) + return false; + + if ((flags & CON_SUSPENDED)) + return false; + + if (!con->write) + return false; + + /* + * Console drivers may assume that per-cpu resources have been + * allocated. So unless they're explicitly marked as being able to + * cope (CON_ANYTIME) don't call them until this CPU is officially up. + */ + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) + return false; + + return true; +} + #else #define PRINTK_PREFIX_MAX 0 @@ -99,6 +129,8 @@ static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } +static inline bool console_is_usable(struct console *con) { return false; } + #endif /* CONFIG_PRINTK */ extern struct printk_buffers printk_shared_pbufs; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 778359b21761..b6cfae75a574 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2679,36 +2679,6 @@ int is_console_locked(void) } EXPORT_SYMBOL(is_console_locked); -/* - * Check if the given console is currently capable and allowed to print - * records. - * - * Requires the console_srcu_read_lock. - */ -static inline bool console_is_usable(struct console *con) -{ - short flags = console_srcu_read_flags(con); - - if (!(flags & CON_ENABLED)) - return false; - - if ((flags & CON_SUSPENDED)) - return false; - - if (!con->write) - return false; - - /* - * Console drivers may assume that per-cpu resources have been - * allocated. So unless they're explicitly marked as being able to - * cope (CON_ANYTIME) don't call them until this CPU is officially up. - */ - if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) - return false; - - return true; -} - static void __console_unlock(void) { console_locked = 0; From patchwork Tue Sep 19 23:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3772964vqi; Tue, 19 Sep 2023 17:23:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMUq5PjH3i8Mz+YQAbdzuRGIkFcgK6gkztasWRguUPB8IKIgVbqi3vU1A7As245tnB4e0D X-Received: by 2002:a05:6a00:1915:b0:68f:da2a:637b with SMTP id y21-20020a056a00191500b0068fda2a637bmr1353845pfi.19.1695169399550; Tue, 19 Sep 2023 17:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695169399; cv=none; d=google.com; s=arc-20160816; b=BZoCIbvL5DghPeDdkg5fk5cpLGQdi7wcZv2YUQudi2MFNPlmQmufYnWDqBX8rvEjHM ErYwKJS9ZVySCxoqoZoT9Dn6WuW5WLDO1pSP/sKcEahJN1tukvT8eViF4ih1cPxo6a4K 6CX2Xl56MiphtCrMJMFtcqeZOCA44pktXvxZD7VdfmDd65rkZnFhZTfgQhtUJT3cu0No AQn+LnteoCZbNqHKokf6a/neNZIvDomD0b2twFrA4qmMFcLfx1AiTohExGgOhRfXl88T s8c+2q6zOc/58dhZREtVZcUQIAuwJCTzaPBAxmQMljvJHKAO6fGnqdCLJynQyqJz9Iq4 MMMw== 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:dkim-signature :dkim-signature:from; bh=fFf1kFlBgEjf3N0WbcHTHhbAP/Zmjn3VBhye6lfUWfg=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=CK1nhvj/+LNfKPEjbDAoMyS5tiYehBqsIO+3tfW5HfGTMDZy5l1POtdSNrGUX1nIOb jBmAomc3hFjjYp+i0PQY/6dncH+rJx2f2bByN8485b6LhyrnoxVbbXeTRipt8FLigmdA doyXu5KoogMb5svnZ+u+aealFrr0IFGUfKBZ1hMY2oIAXpzc4JdUBNFL8eTD0I56ZTUG VvhPwr5QkoiO3PBoB76I50AyuPgms1wIdLB0VqPb/9TDFcoBlzOJf9kHQ2X9cODfpcff vGrGqCWZKdptscN0eBVkoPWJ0iY1o29cw6ao4kzEVRioXIaeokFWjcIWojUcv/hqKDlK hqeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Ji/Nc38y"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bt10-20020a056a00438a00b0068e4358d041si10458689pfb.175.2023.09.19.17.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 17:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Ji/Nc38y"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D9EF382A8567; Tue, 19 Sep 2023 16:09:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233502AbjISXJW (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233128AbjISXJQ (ORCPT ); Tue, 19 Sep 2023 19:09:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9368C4 for ; Tue, 19 Sep 2023 16:09:10 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fFf1kFlBgEjf3N0WbcHTHhbAP/Zmjn3VBhye6lfUWfg=; b=Ji/Nc38yfLVaVLklKC8ElmecwukK9eYHd/xy+zRdEHUz1FlAV5pEXIJiRvrf92e6/AffdU 3xSJZ9Rmc45lH6uh0CZvwv6VUYkSCGWl8Y3muVrFyNtA9tMp3vgrGqkpU2otzGFlzyPrnU aF72eJLOGgDavU7eZAugt5TQywfa+A4gIBvhsrh2MooZO735vePLxRGKGQZON7CSknjmWt G46xk49I3KWLkkVTzifElnnaTT13vJjniJlmQTeEwB2dGAQtzrlQ3jxX2ZBJIVf+RzXI2v jiSMfDQLTD2/3kQC1xOiLdWgn3W+w9Z9vKc0aOesag4So0OJvmSeaSf9EB8GqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fFf1kFlBgEjf3N0WbcHTHhbAP/Zmjn3VBhye6lfUWfg=; b=X8lELKW72ir/HEJ6adxk6nez4Z4oqG/cjZChnCPxzeFYkIeq3RqfDNN27LHnpOW3wYlgjY M5XJwZRtIwTzaFDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 02/11] printk: Let console_is_usable() handle nbcon Date: Wed, 20 Sep 2023 01:14:47 +0206 Message-Id: <20230919230856.661435-3-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777513948351843871 X-GMAIL-MSGID: 1777513948351843871 The nbcon consoles use a different printing callback. For nbcon consoles, check for the write_atomic() callback instead of write(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6e8c1b02adae..69c8861be92c 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -80,6 +80,8 @@ void nbcon_free(struct console *con); /* * Check if the given console is currently capable and allowed to print + * records. Note that this function does not consider the current context, + * which can also play a role in deciding if @con can be used to print * records. * * Requires the console_srcu_read_lock. @@ -94,8 +96,13 @@ static inline bool console_is_usable(struct console *con) if ((flags & CON_SUSPENDED)) return false; - if (!con->write) - return false; + if (flags & CON_NBCON) { + if (!con->write_atomic) + return false; + } else { + if (!con->write) + return false; + } /* * Console drivers may assume that per-cpu resources have been From patchwork Tue Sep 19 23:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3739763vqi; Tue, 19 Sep 2023 16:09:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvkClofG05Htd+Pl5nSkjApT/AP4ai4zSYoOgyhSrPTsqPwmDzxcKMtpCg2E6ZHFg6NA6l X-Received: by 2002:a05:6870:589a:b0:1c8:b82b:cbdb with SMTP id be26-20020a056870589a00b001c8b82bcbdbmr921192oab.33.1695164989828; Tue, 19 Sep 2023 16:09:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695164989; cv=none; d=google.com; s=arc-20160816; b=tVt7bVzeRaM2AONkMDWgmBYY8HsmYcJDNrpri733iBxPtBKRI3ojpPQedENgNIXIVI CIyrbpdBbH1q0Qhtd7n1V3wfpT56k83Wb2EnqmJNdDMCJFgj+TWRlnIA0B5KPLJUHX2k qGEfQcfbu9lUyLEJVVZqv9vrvJKMt8TbQZYVRPsRtxBPaY8Oba43XDqJaVG77ZHwxB4g 769U4vb/n7A14bUxr94Vf32ed6CXj10pK5ujyTrFv2w99VH0SiZXAOhvJSB5ic2E2iQs w4GXB/nWOLXhXXF8r+eOrBl5/5BJtbcHk4xJmHNOSWpt9hSjEUEUajF6vOFWX/epkjxT df/A== 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:dkim-signature :dkim-signature:from; bh=zprfWcxtWmGsW80DlqzMcGe9h+c0hqNmqd+wr5GO9aw=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=AV6iHZ5648H1/MKh6OMYoHYCWlUQQw+YVy7lpYPDrONe9nXhf2N+gxR3vJE01EhxLQ B4SSD/xkYOS5kN2AltV6YVq6uG4OLpm3pYM+Q92xkZBbYxEIJMJ42V+7bXgB5Jid5nPu hc/K8WdoY2zvJ3Qm5WlPJCOpNYSI/uSnmBxmHLMiADfs/m3rLmTezp1DUmAVY0jP9EXD JgMtVjoMp5ciqmGQ2QQiJwnBhgdCDRFvAUIPhKtzZIGuPPAdwAk+a+QK6LGQ6Oe8ivmz A91eJOiXTjiJQvbwMa1BJGQbQ1aTeghPiwSa9xyZ+KVqJkcAfoaH9Tg02FOJvROugUec lxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NqrWEArT; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id z11-20020a6553cb000000b005774bb908d0si10213843pgr.132.2023.09.19.16.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 16:09:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NqrWEArT; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A4CA5828D011; Tue, 19 Sep 2023 16:09:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233558AbjISXJ0 (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233297AbjISXJS (ORCPT ); Tue, 19 Sep 2023 19:09:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30E4CC9 for ; Tue, 19 Sep 2023 16:09:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zprfWcxtWmGsW80DlqzMcGe9h+c0hqNmqd+wr5GO9aw=; b=NqrWEArTVkOy9DG7b5frQSYQblAKGvpp22x32+WwFYR9zB6qW/0fsQSr7IV39IfV37Da7q Q+hj7kJKWiQnEpNbIZbY5vEwLvjA/N/ELDLTHQNpTLDoRkoGgE7HBGX1u+cvrTsbASjCJw yIhIM5NDscnXHQNRStawJyeFrYHLO6bT+WgpyE10s1QsoIslZhViDxVOWo/wApqHgnr9rb A72Alx8CHXUD3IR9/KZaidJ0Rwmdmv18/i4JOu52dYZ8ZbW90yp4EaVK+p5/VRqHRdTYJ+ EGyTfSRGNH9BMpOuvHbq3b/GT+568tcM1kHqWz5ivbxYiGbKCk9MpV6Ey1aJdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zprfWcxtWmGsW80DlqzMcGe9h+c0hqNmqd+wr5GO9aw=; b=rVZGFDSbIEtHTnitVDxJl51V5moAMlVq4GL6Rmxzwt9+Kz/f6jDOnmo/CBN8p5GEZunxnH 7Y73EIQfaJ1N5cBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 03/11] printk: Add @flags argument for console_is_usable() Date: Wed, 20 Sep 2023 01:14:48 +0206 Message-Id: <20230919230856.661435-4-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777509324252011759 X-GMAIL-MSGID: 1777509324252011759 The caller of console_is_usable() usually needs @console->flags for its own checks. Rather than having console_is_usable() read its own copy, make the caller pass in the @flags. This also ensures that the caller saw the same @flags value. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 8 ++------ kernel/printk/printk.c | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 69c8861be92c..6780911fa8f2 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -83,13 +83,9 @@ void nbcon_free(struct console *con); * records. Note that this function does not consider the current context, * which can also play a role in deciding if @con can be used to print * records. - * - * Requires the console_srcu_read_lock. */ -static inline bool console_is_usable(struct console *con) +static inline bool console_is_usable(struct console *con, short flags) { - short flags = console_srcu_read_flags(con); - if (!(flags & CON_ENABLED)) return false; @@ -136,7 +132,7 @@ static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } -static inline bool console_is_usable(struct console *con) { return false; } +static inline bool console_is_usable(struct console *con, short flags) { return false; } #endif /* CONFIG_PRINTK */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b6cfae75a574..6ef33cefa4d0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2929,9 +2929,10 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove cookie = console_srcu_read_lock(); for_each_console_srcu(con) { + short flags = console_srcu_read_flags(con); bool progress; - if (!console_is_usable(con)) + if (!console_is_usable(con, flags)) continue; any_usable = true; @@ -3754,7 +3755,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre * that they make forward progress, so only increment * @diff for usable consoles. */ - if (!console_is_usable(c)) + if (!console_is_usable(c, flags)) continue; if (flags & CON_NBCON) { From patchwork Tue Sep 19 23:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3834735vqi; Tue, 19 Sep 2023 19:56:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyBgiWXrd5r+Rd74rCf1imGPlvOtKhW+KkSR1aZr06s0AhuwaOLdVHjMOw76Ecj5pL/5a1 X-Received: by 2002:a05:6a20:1585:b0:154:9222:684a with SMTP id h5-20020a056a20158500b001549222684amr1557382pzj.24.1695178593899; Tue, 19 Sep 2023 19:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695178593; cv=none; d=google.com; s=arc-20160816; b=vCq8qY6FOV1wi6Kj7TTfLyamrWfRgTsI/AX5WPTueEsnpZW/enyViPImNlnb6rEaB7 04+n94j2GfyFSI4aVpSxBTrxza/k8pvqsc8WTqEGI5qnTmreNsy69oLSnZgA8crRPZMr M7X3yPIQwjARtL77EnX9IO4qWQHh9GBzgrAToMVYOjEJMihaM5h0qdcPIGxFCfBHjAPw fioz6kBn463B5Tv6t0Dh/xeEc3pDY/T/5Hv+bbZleVW+Gc/KVaVTSujABpLOG6+iPTw0 jNu3dH2f8KkNDz1QAHBfOiBuioZQMTmy06gQFMiD9vGkFei9oBypRkaW04nKVkXU/Cts RbRQ== 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:dkim-signature :dkim-signature:from; bh=RXYljq1O5mwfZU+NDYT3eBF6WGuYpS+t9+Qc7DTVOZs=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=AgkEy5WEfK2k/L5SnXvWMYEpvyBKFJu0CsE2H9cSyoGPk4b63RYshNz6RN0pGjqo0c CfYaghb1T/CnXK7y/d05mRAeJb0xaP/eH8SV6npCt0d/J3EQVOq4FFDLk8nYVrNFRtiN 7w1h+JQJF7OsaD5ic+Xgxzoo/xIgwiSOC6kANBM0Nv2mtVp578heAZWvgzWxwcKvefEx nTgcTkNtV4rem6YE8nHhyLNegkF+x2ZEvvv1jQfYQTQsVK1DsXeBvOv+Kw9Igk3tSXxC Te3jnBrI7HWCv8c5qsYGQCYGcPSB2ndobAHjFP4jC3q/UISmW1xB0F1rogb00FvaY6Nt NlWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0n9rSWKK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id br2-20020a17090b0f0200b002684bc84493si577722pjb.131.2023.09.19.19.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 19:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0n9rSWKK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D4FAB81D7A7F; Tue, 19 Sep 2023 16:09:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233675AbjISXJe (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233399AbjISXJU (ORCPT ); Tue, 19 Sep 2023 19:09:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACC62C0 for ; Tue, 19 Sep 2023 16:09:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RXYljq1O5mwfZU+NDYT3eBF6WGuYpS+t9+Qc7DTVOZs=; b=0n9rSWKKgFMMM8oe7OxgVm25UuFUBlbW3YAo2v2icNrgjeHRizUJRTeSvdYT/eGtVcIKJp vjFkpAkv6JhdILbdaNar/Oq0AUKclYJykk+XE3DwtMKMr8FEc7H+1SaJH25CtVSuHK98ez WwHcrluKf3t95h8bAz12tGmzMFDSf6+/jogu926ViKIIYtUAF+G1Tz8vx++q9tfw/Pj2o4 xounm7rjfOk6MvfeuxnCZ0PLv6l9SSFbqTHZQ5rbFR8jD+dXYcV+AhvyPeM6DKLRG4tBMs yIllyCVpEpRJEjNbm+qMif91wyzGcF33SOvNDJvM0qn2yVJvqmo/tDDJh/bNZg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RXYljq1O5mwfZU+NDYT3eBF6WGuYpS+t9+Qc7DTVOZs=; b=SF2ALktfgmDTzBDMjoVe+9Uw9oVXGPK8VIxJwdu/Otl/ztdreIl9fLaUgdg5d9EvAO66IX 8+xRq32MGQwOnXBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 04/11] printk: nbcon: Provide functions to mark atomic write sections Date: Wed, 20 Sep 2023 01:14:49 +0206 Message-Id: <20230919230856.661435-5-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777523589653532637 X-GMAIL-MSGID: 1777523589653532637 From: Thomas Gleixner WARN/OOPS/PANIC require printing out immediately since the regular printing method (and in the future, the printing threads) might not be able to run. Add per-CPU state to denote the priority/urgency of the output and provide functions to mark the beginning and end of sections where the urgent messages are generated. Note that when a CPU is in a priority elevated state, flushing only occurs when dropping back to a lower priority. This allows the full set of printk records (WARN/OOPS/PANIC output) to be stored in the ringbuffer before beginning to flush the backlog. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- include/linux/console.h | 4 ++ kernel/printk/nbcon.c | 89 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index e4fc6f7c1496..25a3ddd39083 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -452,10 +452,14 @@ static inline bool console_is_registered(const struct console *con) hlist_for_each_entry(con, &console_list, node) #ifdef CONFIG_PRINTK +extern enum nbcon_prio nbcon_atomic_enter(enum nbcon_prio prio); +extern void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio); extern bool nbcon_can_proceed(struct nbcon_write_context *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); #else +static inline enum nbcon_prio nbcon_atomic_enter(enum nbcon_prio prio) { return NBCON_PRIO_NONE; } +static inline void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio) { } static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index b96077152f49..9359906b575b 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -961,6 +961,95 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) return nbcon_context_exit_unsafe(ctxt); } +/** + * struct nbcon_cpu_state - Per CPU printk context state + * @prio: The current context priority level + * @nesting: Per priority nest counter + */ +struct nbcon_cpu_state { + enum nbcon_prio prio; + int nesting[NBCON_PRIO_MAX]; +}; + +static DEFINE_PER_CPU(struct nbcon_cpu_state, nbcon_pcpu_state); +static struct nbcon_cpu_state early_nbcon_pcpu_state __initdata; + +/** + * nbcon_get_cpu_state - Get the per CPU console state pointer + * + * Returns either a pointer to the per CPU state of the current CPU or to + * the init data state during early boot. + */ +static __ref struct nbcon_cpu_state *nbcon_get_cpu_state(void) +{ + if (!printk_percpu_data_ready()) + return &early_nbcon_pcpu_state; + + return this_cpu_ptr(&nbcon_pcpu_state); +} + +/** + * nbcon_atomic_enter - Enter a context that enforces atomic printing + * @prio: Priority of the context + * + * Return: The previous priority that needs to be fed into + * the corresponding nbcon_atomic_exit() + * Context: Any context. Disables migration. + */ +enum nbcon_prio nbcon_atomic_enter(enum nbcon_prio prio) +{ + struct nbcon_cpu_state *cpu_state; + enum nbcon_prio prev_prio; + + migrate_disable(); + + cpu_state = nbcon_get_cpu_state(); + + prev_prio = cpu_state->prio; + if (prio > prev_prio) + cpu_state->prio = prio; + + /* + * Increment the nesting on @cpu_state->prio (instead of + * @prio) so that a WARN() nested within a panic printout + * does not attempt to scribble state. + */ + cpu_state->nesting[cpu_state->prio]++; + + return prev_prio; +} + +/** + * nbcon_atomic_exit - Exit a context that enforces atomic printing + * @prio: Priority of the context to leave + * @prev_prio: Priority of the previous context for restore + * + * Context: Any context. Enables migration. + * + * @prev_prio is the priority returned by the corresponding + * nbcon_atomic_enter(). + */ +void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio) +{ + struct nbcon_cpu_state *cpu_state; + + cpu_state = nbcon_get_cpu_state(); + + /* + * Undo the nesting of nbcon_atomic_enter() at the CPU state + * priority. + */ + cpu_state->nesting[cpu_state->prio]--; + + /* + * Restore the previous priority, which was returned by + * nbcon_atomic_enter(). + */ + cpu_state->prio = prev_prio; + + migrate_enable(); +} + /** * nbcon_alloc - Allocate buffers needed by the nbcon console * @con: Console to allocate buffers for From patchwork Tue Sep 19 23:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3836558vqi; Tue, 19 Sep 2023 20:00:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDGFZEALQr0Frna/6QhaJPldVWZgqOpQset6BGQfiRfRigrpK1c8iNmCywqRVlP8HaIUWs X-Received: by 2002:a17:90a:7c01:b0:273:f584:40ca with SMTP id v1-20020a17090a7c0100b00273f58440camr1463265pjf.16.1695178854971; Tue, 19 Sep 2023 20:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695178854; cv=none; d=google.com; s=arc-20160816; b=c6WdtmSmuCRiF3bjASgWUreVuggriQqX9/wbRMobew7R9M0bwVCwxqrnA+TPg+u9Ks 5fkhu+Js1F6qnz3dgGV+FqSxqq09ozhonP6fVafr0St2PXtdgAgc4iumJbRXPXyJjBrw 9I4fwxaRgMO4C9mpFg6szG6QBc/KCoNvZdY2uAaPJtWYYrtIRwofCqgbVOfrlG7R4aJM s6aYjMWF2DnHydq1bBriaEJY5zIvI+Teqjzgf2fe18EQw8z1nyTwpYWjtDVCZt3y4daa yQgw0sJB4W0lhL4zDvEUwcBl5PU7wHKw7JpRGoIdL0UExI+Onm1uDYxPLBLOhdxTE6YD zE0A== 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:dkim-signature :dkim-signature:from; bh=2k78cqDo2n7jFkD6ttaAHGW5bS6OdfJnhB22UhQNM+I=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=d/GKuuQQ76UdhstA3Gl9MrSUvZHblKbQsoFlpdOgHpCz4eMu+20Iw05ytoSs5TGgxZ A9UI9IoxoEIFwEHWcltXksdXcwd3ju2Xgi5Iv83sfTP6+eqM5N5DyM8+8dy7iZ0IcN27 X+v8uccJrN+MJCAd2saKoANR8KeTlpTaoVZrQ50k0C8Pi4qT3hoh5VHvR+41sxPeWLc9 UiuLFomVerjv9hoNIEYIa56kz6gd52SUdWnZvOODT4q05Xned1l2ATS4JiEdDp8P5NCw GX1aU/WrRFVievMBdzFBnTwvFLYwgVuVZoBJddzT0TQ/60w5ZkPTxT57WrElL7QwSOQW tmmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wWn2bTaD; dkim=neutral (no key) header.i=@linutronix.de header.b=OXehBxL7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id n3-20020a17090ac68300b00274dc876792si568392pjt.98.2023.09.19.20.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 20:00:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wWn2bTaD; dkim=neutral (no key) header.i=@linutronix.de header.b=OXehBxL7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DA3C881CE846; Tue, 19 Sep 2023 16:09:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233472AbjISXJa (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233381AbjISXJU (ORCPT ); Tue, 19 Sep 2023 19:09:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AABD1C4 for ; Tue, 19 Sep 2023 16:09:13 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2k78cqDo2n7jFkD6ttaAHGW5bS6OdfJnhB22UhQNM+I=; b=wWn2bTaDLV85/e0NSwumigrW7EOYaHluwC1GA+TskQsBYIcgwTfiQTT1XIGsc4e7Lolo/J 8bfGthQvsDUkyYJHSpwZZRachIyaYxbumFVeA9NmNJHH/CwAWXf4w5AL0YU5147hNqZWMs cwXkq9TzbOcZ4M/fL9C8Alrocb9w10J/rM2a/kTH67o+rfbeo417CYM13QSNtkNqncxTvA 8uvDQ31BqcYhvRsKc6borUdAN5uZfCq3XKVP2c97K3K2gSlMitvIcoiNJHDkF+kaBawyd8 KYgteUKbOiAH+X4OLMG7cjGMHlRSXbXe10CxRsccwqCYVPs7hbvfiniuIJZoiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2k78cqDo2n7jFkD6ttaAHGW5bS6OdfJnhB22UhQNM+I=; b=OXehBxL7RFUdwevTFoCOQzppzyc04cD606hS5sOvQwxbLMn0eblxrkUeq0gSede7p1JRcf lr4ReQILCVn5jiBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 05/11] printk: nbcon: Provide function for atomic flushing Date: Wed, 20 Sep 2023 01:14:50 +0206 Message-Id: <20230919230856.661435-6-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777523863347067642 X-GMAIL-MSGID: 1777523863347067642 From: Thomas Gleixner Provide nbcon_atomic_flush() to perform atomic write flushing of all registered nbcon consoles. Like with legacy consoles, the nbcon consoles are flushed one record per console. This allows all nbcon consoles to generate pseudo-simultaneously, rather than one console waiting for the full ringbuffer to dump to another console before printing anything. Note that if the current CPU is in a nested elevated priority state (EMERGENCY/PANIC), nbcon_atomic_flush() does nothing. This is in case the printing itself generates urgent messages (OOPS/WARN/PANIC), that those messages are fully stored into the ringbuffer before any printing resumes. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- include/linux/printk.h | 6 +++ kernel/printk/nbcon.c | 101 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8ef499ab3c1e..58e5f34d6df1 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -192,6 +192,7 @@ void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; void printk_trigger_flush(void); +extern void nbcon_atomic_flush_all(void); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) @@ -271,6 +272,11 @@ static inline void dump_stack(void) static inline void printk_trigger_flush(void) { } + +static inline void nbcon_atomic_flush_all(void) +{ +} + #endif #ifdef CONFIG_SMP diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 9359906b575b..2a9ff18fc78c 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -571,7 +571,6 @@ static struct printk_buffers panic_nbcon_pbufs; * in an unsafe state. Otherwise, on success the caller may assume * the console is not in an unsafe state. */ -__maybe_unused static bool nbcon_context_try_acquire(struct nbcon_context *ctxt) { unsigned int cpu = smp_processor_id(); @@ -873,7 +872,6 @@ EXPORT_SYMBOL_GPL(nbcon_exit_unsafe); * When true is returned, @wctxt->ctxt.backlog indicates whether there are * still records pending in the ringbuffer, */ -__maybe_unused static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) { struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); @@ -988,6 +986,105 @@ static __ref struct nbcon_cpu_state *nbcon_get_cpu_state(void) return this_cpu_ptr(&nbcon_pcpu_state); } +/** + * nbcon_atomic_emit_one - Print one record for a console in atomic mode + * @wctxt: An initialized write context struct to use + * for this context + * + * Returns false if the given console could not print a record or there are + * no more records to print, otherwise true. + * + * This is an internal helper to handle the locking of the console before + * calling nbcon_emit_next_record(). + */ +static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); + + if (!nbcon_context_try_acquire(ctxt)) + return false; + + /* + * nbcon_emit_next_record() returns false when the console was + * handed over or taken over. In both cases the context is no + * longer valid. + */ + if (!nbcon_emit_next_record(wctxt)) + return false; + + nbcon_context_release(ctxt); + + return prb_read_valid(prb, ctxt->seq, NULL); +} + +/** + * __nbcon_atomic_flush_all - Flush all nbcon consoles in atomic mode + * @allow_unsafe_takeover: True, to allow unsafe hostile takeovers + */ +static void __nbcon_atomic_flush_all(bool allow_unsafe_takeover) +{ + struct nbcon_write_context wctxt = { }; + struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); + struct nbcon_cpu_state *cpu_state; + struct console *con; + bool any_progress; + int cookie; + + cpu_state = nbcon_get_cpu_state(); + + /* + * Let the outermost flush of this priority print. This avoids + * nasty hackery for nested WARN() where the printing itself + * generates one and ensures such nested messages are stored to + * the ringbuffer before any printing resumes. + * + * cpu_state->prio <= NBCON_PRIO_NORMAL is not subject to nesting + * and can proceed in order to allow any atomic printing for + * regular kernel messages. + */ + if (cpu_state->prio > NBCON_PRIO_NORMAL && + cpu_state->nesting[cpu_state->prio] != 1) + return; + + do { + any_progress = false; + + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { + short flags = console_srcu_read_flags(con); + bool progress; + + if (!(flags & CON_NBCON)) + continue; + + if (!console_is_usable(con, flags)) + continue; + + memset(ctxt, 0, sizeof(*ctxt)); + ctxt->console = con; + ctxt->spinwait_max_us = 2000; + ctxt->prio = cpu_state->prio; + ctxt->allow_unsafe_takeover = allow_unsafe_takeover; + + progress = nbcon_atomic_emit_one(&wctxt); + if (!progress) + continue; + any_progress = true; + } + console_srcu_read_unlock(cookie); + } while (any_progress); +} + +/** + * nbcon_atomic_flush_all - Flush all nbcon consoles in atomic mode + * + * Context: Any context where migration is disabled. + */ +void nbcon_atomic_flush_all(void) +{ + __nbcon_atomic_flush_all(false); +} + /** * nbcon_atomic_enter - Enter a context that enforces atomic printing * @prio: Priority of the context From patchwork Tue Sep 19 23:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3941514vqi; Wed, 20 Sep 2023 00:26:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwvpeGaE7PLTvUx5IpohD8dMk37ToMbCN2BOX7oQURfUgdhUalQNRkFefOHZnCjXv76KTn X-Received: by 2002:a17:90b:4f88:b0:268:557e:1848 with SMTP id qe8-20020a17090b4f8800b00268557e1848mr1845475pjb.2.1695194789360; Wed, 20 Sep 2023 00:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695194789; cv=none; d=google.com; s=arc-20160816; b=LJIFHQ1ZY9pcWvLYGg+fVIYOYqkACSmTuDWPWhXR9BBnmFacy/TpzFelsOpjK0afv1 Upk4J8ReseBR5L2vU9kdBtORTRfkaX4OAbQZHBpWS9cUPMt1k6LU/tKpk6ga6A1U+4sK ZE25GQjI8832SUBNWGaZR8eHTG1agIdEL2SxRuOUWccS3+jezZVvILqDffUhg+UwBiDI uC8LzhDkgU5fVdWkMDfSCkYL32hOlryYTUqdZUbRZEonCR1nMkcO8I4HL4LhXPpj8dsY vSf0NEROYI+vefPQqe1fStaKG3TVWNC+LyiMIKs8d4VESmIl0+btv3u/qlaPe3p3cda1 h2Rg== 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:dkim-signature :dkim-signature:from; bh=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=r7NJLIPhyXGfPiD+OA06xYYBzMeyPcUhkIhVnrunQtll0IBASfcyiieNiW3y7PS+pz qKQhSprfdcAJOQzOfuuoCE8b4M2D2gEJH5drpOzE/c3lHurLvgZ21M9XkA2YxWAa/Oku lUz7DkhjHv6e8frbukryoPDjAHTnaRRdMz02KWtSTYtQNOX3l6R+cG1JcleWAxxcZ8uJ e7nZe56kT+sqEd46i8y1dWvnlYlwJjYrQn47s3jCGGBqaYU0aqswjIeGX9+KuVrPcZhJ H9LsTQ3sk+KuhnSsLXWaIjcLxVcQ0cAN1N/Wkc8smKxhXeXTXL3E6qeuJ6/OdT/Kh6Aa GiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AcOxDy26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id mv16-20020a17090b199000b00262ebe643a2si940349pjb.186.2023.09.20.00.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 00:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AcOxDy26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3C7D981D7A78; Tue, 19 Sep 2023 16:09:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233660AbjISXJh (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbjISXJV (ORCPT ); Tue, 19 Sep 2023 19:09:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15213C6 for ; Tue, 19 Sep 2023 16:09:15 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; b=AcOxDy26/wZHBrY1PDymcspuNPgrI1Epe/gZj0sMxSW60NjlAnd6XQ6j36zzzT9zkdYknI SyHklaTdzHgcn9LBQa9GGeaoNOXlRJLOqVyOGnYrx+zkzbIjOj+rGfYaUoKZUHiO1i/fJH oRx2nLs96R3O1IprrRjd2SBLf/ZzZYM+KNEtDNGbqNxLXnoWFeL0oc2AHgyQV9MqCQR7Qi 5z3jbF9q+31Ek8GNWMxr5rL6OX2Euegaz4BAcEFUl5UJQycdekHwYzhpuVHgZpAp3Ui5WR RMvkiMCLnfrW7ohY4ApfANrEpdmBI0//+TmvQRYsEISQxTsj/D2MYWTr6R03sw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; b=gKmdzdskT7Ri+LOcvfojaRdY0IBLQEasZSxD8GXhIC5B7lEqTcovfFCrvzcWfX0+Tniup9 d/UYvefBi8WwQrAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 06/11] printk: nbcon: Wire up nbcon console atomic flushing Date: Wed, 20 Sep 2023 01:14:51 +0206 Message-Id: <20230919230856.661435-7-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777540571101023045 X-GMAIL-MSGID: 1777540571101023045 From: Thomas Gleixner Perform nbcon console atomic flushing at key call sites: nbcon_atomic_exit() - When exiting from the outermost atomic printing section. If the priority was NBCON_PRIO_PANIC, attempt a second flush allowing unsafe hostile takeovers. console_flush_on_panic() - Called from several call sites to trigger ringbuffer dumping in an urgent situation. console_flush_on_panic() - Typically the panic() function will take care of atomic flushing the nbcon consoles on panic. However, there are several users of console_flush_on_panic() outside of panic(). printk_trigger_flush() - Used in urgent situations to trigger a dump in an irq_work context. However, the atomic flushing part happens in the calling context since an alternative context is not required. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- kernel/printk/nbcon.c | 10 ++++++++++ kernel/printk/printk.c | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 2a9ff18fc78c..82e6a1678363 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1092,6 +1092,11 @@ void nbcon_atomic_flush_all(void) * Return: The previous priority that needs to be fed into * the corresponding nbcon_atomic_exit() * Context: Any context. Disables migration. + * + * When within an atomic printing section, no atomic printing occurs. This + * is to allow all emergency messages to be dumped into the ringbuffer before + * flushing the ringbuffer. The actual atomic printing occurs when exiting + * the outermost atomic printing section. */ enum nbcon_prio nbcon_atomic_enter(enum nbcon_prio prio) { @@ -1130,8 +1135,13 @@ void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio) { struct nbcon_cpu_state *cpu_state; + __nbcon_atomic_flush_all(false); + cpu_state = nbcon_get_cpu_state(); + if (cpu_state->prio == NBCON_PRIO_PANIC) + __nbcon_atomic_flush_all(true); + /* * Undo the nesting of nbcon_atomic_enter() at the CPU state * priority. diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 6ef33cefa4d0..419c0fabc481 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3159,6 +3159,8 @@ void console_flush_on_panic(enum con_flush_mode mode) console_srcu_read_unlock(cookie); } + nbcon_atomic_flush_all(); + console_flush_all(false, &next_seq, &handover); } @@ -3903,6 +3905,10 @@ void defer_console_output(void) void printk_trigger_flush(void) { + migrate_disable(); + nbcon_atomic_flush_all(); + migrate_enable(); + defer_console_output(); } From patchwork Tue Sep 19 23:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3739978vqi; Tue, 19 Sep 2023 16:10:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUYjcyPO91RKsuQ6O/zpYk9tEQTmchgadSZtEOfh9bvh7HtF0Px57SpKNo5DLBZbDrft/2 X-Received: by 2002:a17:902:ec8c:b0:1c3:dbad:52d4 with SMTP id x12-20020a170902ec8c00b001c3dbad52d4mr865987plg.33.1695165017526; Tue, 19 Sep 2023 16:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695165017; cv=none; d=google.com; s=arc-20160816; b=vUEh4wDpsDTa1cvz1BVBvEYzSrWc5SOR+w7LSAmciiX4boSqIFYLBDtpSqih4XifCP iri397rJhJsTy+kTCwWl/gX0BTkpE72/xrfsKqqYvx6SaSnnVY4fjTYn2AZuqe2OiLPv Vx4RAwZdFjTghQFsg8ng5SHotWT0BOExAimwWGRnkPFQ6dMgykb1cSvLmTePgyDJUvMB OVUAuNrM/qxjbITPvazllvqzKUbNhLQgdx2p44rD1L6Ee/HKyNSAagdioR4d/5mdjfdW +mqsrgsc29BfbitkVkCEioF8IJ0ITDFV/ox7izgiXDs8oTIM5ULm5ag/g991fGEZsa8+ Unaw== 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:dkim-signature :dkim-signature:from; bh=f7cOYAQI8bFPp8osUlYoxxP2Ba8k68CcPtU2QUq7Vj8=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=nG7508ZieGKV2hYV1rjz+1OulYqQQrAbPaXUR+avklgCGMkDFOGrtlqWlknYlrLNrz NXvQWrE5ViZGzWJVHo8nKVdKKH8Oqj8819k7E3mNWCEplXeRzyStvxMlJpgbhL/kxFZa lcNp6dBj4Cp1OE17SxTe3Ds926T5MDcq8vCCiBHrld+m/qIbx/rCYleeeZdastcRiPSW Q55Q7La6sVn7t6O3z4iPD1CHtkiRhH5GW1niKBCeqRqT/o7VXx4j0Ybb/2duvKN4oWZF nas45+pn5BZkVUst1tgQGe0OMy0/P3dAqnWwx7zs8QNJoNiRdKIpRq5ojshz5ZCaRKMu egYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0wJVDuRd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u6-20020a170902e5c600b001bdca6456c3si1974373plf.46.2023.09.19.16.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 16:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0wJVDuRd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 51590826F7E1; Tue, 19 Sep 2023 16:10:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbjISXKD (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjISXJW (ORCPT ); Tue, 19 Sep 2023 19:09:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E13DCA for ; Tue, 19 Sep 2023 16:09:16 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f7cOYAQI8bFPp8osUlYoxxP2Ba8k68CcPtU2QUq7Vj8=; b=0wJVDuRdeBg8KXv7SeT18I2SbRqNOuaWrFR18sqA1Qs0bwXzOLmQvI2BokJIiYRHrq4IQO dRLw90yNKjM3bJZpe+A7wT+Q3L4u3eDQlf2tYGqBJwq1f4UPwiCW16D4d5JSvwJQQNH+oY A1rgJS226R8X2BxamsHtB9Z9JQUWeGCQtTLLzVPSt6BK2vldKE/x1j02eTR1g0EJL1afve v+b3sB79UFDd3TNgdjS+TegOMa0pdaXi+So8hlARdRNfQoCn7OeJMDuToEm0h7ikEK5tdu lfjUFS7mkos3WyOC+tmY2sQurFZvqqMte57FoKDY/w3MCjdFJyATtpLimQ3+Ag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f7cOYAQI8bFPp8osUlYoxxP2Ba8k68CcPtU2QUq7Vj8=; b=lfk75Op2Kc+6bJGMuCyAAe07X6uD47Jj8MI6BoQE/nwM14DL61HyRbd6dJIcTkNbfSF/Qk axDXN3aUdZTc5SBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 07/11] printk: nbcon: Wire up nbcon into console_flush_all() Date: Wed, 20 Sep 2023 01:14:52 +0206 Message-Id: <20230919230856.661435-8-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:10:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777509353181572426 X-GMAIL-MSGID: 1777509353181572426 In atomic printing sections, the atomic nbcon consoles have their own behavior of allowing all urgent messages to be stored into the ringbuffer and then flushing afterwards. However, the nbcon consoles must also emit messages when not within atomic printing sections. For this, the existing console_flush_all() function can be used. Provide nbcon_console_emit_next_record(), which acts as the nbcon variant of console_emit_next_record(). Call this variant within console_flush_all() for nbcon consoles. Note that when in an atomic printing section, nbcon_console_emit_next_record() does nothing. This is because atomic printing sections will handle the nbcon flushing when exiting the outermost atomic printing section. Signed-off-by: John Ogness --- kernel/printk/internal.h | 2 ++ kernel/printk/nbcon.c | 46 ++++++++++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 26 +++++++++++++++-------- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6780911fa8f2..a3c6b5ce80e4 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -77,6 +77,7 @@ void nbcon_seq_force(struct console *con, u64 seq); bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +bool nbcon_console_emit_next_record(struct console *con); /* * Check if the given console is currently capable and allowed to print @@ -131,6 +132,7 @@ static inline void nbcon_seq_force(struct console *con, u64 seq) { } static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } +static bool nbcon_console_emit_next_record(struct console *con) { return false; } static inline bool console_is_usable(struct console *con, short flags) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 82e6a1678363..de473a1003d8 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1017,6 +1017,52 @@ static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) return prb_read_valid(prb, ctxt->seq, NULL); } +/** + * nbcon_console_emit_next_record - Print one record for an nbcon console + * in atomic mode + * @con: The console to print on + * + * Return: True if a record could be printed, otherwise false. + * + * This function is meant to be called by console_flush_all() to atomically + * print records on nbcon consoles. Essentially it is the nbcon version of + * console_emit_next_record(). + * + * This function also returns false if the current CPU is in an elevated + * atomic priority state in order to allow the CPU to get all of the + * emergency messages into the ringbuffer first. + */ +bool nbcon_console_emit_next_record(struct console *con) +{ + struct nbcon_cpu_state *cpu_state; + bool progress = false; + + migrate_disable(); + + cpu_state = nbcon_get_cpu_state(); + + /* + * Atomic printing from console_flush_all() only occurs if this + * CPU is not in an elevated atomic priority state. If it is, the + * atomic printing will occur when this CPU exits that state. This + * allows a set of emergency messages to be completely stored in + * the ringbuffer before this CPU begins flushing. + */ + if (cpu_state->prio <= NBCON_PRIO_NORMAL) { + struct nbcon_write_context wctxt = { }; + struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); + + ctxt->console = con; + ctxt->prio = NBCON_PRIO_NORMAL; + + progress = nbcon_atomic_emit_one(&wctxt); + } + + migrate_enable(); + + return progress; +} + /** * __nbcon_atomic_flush_all - Flush all nbcon consoles in atomic mode * @allow_unsafe_takeover: True, to allow unsafe hostile takeovers diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 419c0fabc481..e5e192318b8e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2930,24 +2930,32 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove cookie = console_srcu_read_lock(); for_each_console_srcu(con) { short flags = console_srcu_read_flags(con); + u64 printk_seq; bool progress; if (!console_is_usable(con, flags)) continue; any_usable = true; - progress = console_emit_next_record(con, handover, cookie); + if (flags & CON_NBCON) { + progress = nbcon_console_emit_next_record(con); + printk_seq = nbcon_seq_read(con); + } else { + progress = console_emit_next_record(con, handover, cookie); - /* - * If a handover has occurred, the SRCU read lock - * is already released. - */ - if (*handover) - return false; + /* + * If a handover has occurred, the SRCU read + * lock is already released. + */ + if (*handover) + return false; + + printk_seq = con->seq; + } /* Track the next of the highest seq flushed. */ - if (con->seq > *next_seq) - *next_seq = con->seq; + if (printk_seq > *next_seq) + *next_seq = printk_seq; if (!progress) continue; From patchwork Tue Sep 19 23:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3796735vqi; Tue, 19 Sep 2023 18:16:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6oePXyOaJWWY7AWy7KCRIa/+fSC/8/Omy1rXdoEFv45q5LgB2eaLm5B3zEv2LlpGxobcf X-Received: by 2002:a17:902:e80b:b0:1c2:36a:52aa with SMTP id u11-20020a170902e80b00b001c2036a52aamr1151621plg.30.1695172579720; Tue, 19 Sep 2023 18:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695172579; cv=none; d=google.com; s=arc-20160816; b=pF/0lRCE0WZW+AqzrStRFtey6EWr4x00QJF3/6BLVu4qJZG2YygOn19R3tBa59pFpk 7xbckxNBsY3lrX9kf8gFAoPO1UYY/JzUtAxHuHlBNyjlTWOrmzou+bnt0nZVCDCd2O4t seAbaI5bzTgq3ZV2/Ary8zvDji20fJ2yv2crP5WGiSF73GvUiA2iJmnz5fIOzD8JmMeQ P/shr1e2l1kCwOU/bVVLwFETPVhqqtsUUQpE40ErxKRZTPhCoAZNRia1KJFL4+SijNeW yXE5ekmPB7CU4vnukpQsnEGDiTqt6LDT9chabMKca8gySPQhae54oxtE9HOI4XnXT/ZM lQbg== 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:dkim-signature :dkim-signature:from; bh=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; fh=50vpCM4bvHEw9UCh4Qu+HIAsIf3yT3AMX/s0TvbsiwY=; b=AkF0BxeifpRPqxXV7Pf8qTs+M6mE+1zduyg1phHAJeOgw5g9RE7NvJiw+oFbnZecEb AwA7mu+RsjUUq17AjZjJa/dA67VeV8hBVYoZ3TiaMFtEce1FkjcShfyRET1Su4g8sb17 LOu/h6s+qNCrGIqLt2Nsja85VN6dI55X/LEtAn5rMaBVpnfZqLOcBSkN/sEVfY1o4TBi 8V1g3nQ7Ae+h7d7qg+bKlTYtQSMW9FRB/d+0HCO44yoWgT2B2NfHrY+S/8KO++rATXp4 X58rXjuej5VyeBJ8U9TiCrBYYe5QZ2NJCjcRrINXiLUaeHZMDNgEfTdC3WPlA37fTOxi lXSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P4Z6YRun; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bNsSiUAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x17-20020a170902ec9100b001b9e3a18270si9061223plg.420.2023.09.19.18.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 18:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P4Z6YRun; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bNsSiUAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B421180B79CA; Tue, 19 Sep 2023 16:11:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233702AbjISXKH (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233500AbjISXJW (ORCPT ); Tue, 19 Sep 2023 19:09:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A658D8 for ; Tue, 19 Sep 2023 16:09:17 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; b=P4Z6YRunkOPTZKgwIsuWd6MJHC5Jve4xUIDI+d4fkVbHEBJfHvFKY20lKV/ZbQVzzed+bN MfQvRsFkzDdxyBT+IZmKKKUteJ+8J5IBFw0fPuioztjOcPH0Fe+nnJIyu8aykUUn8Ctv8R Ugq8i2XNEq8PUibWlCTC35tFVw1vhjRNRzPnDtPbiCHzbeVy9+CUAhlAdhcdNIei8JnwXy /HE6mWR7bLz2wrXIziuD/LLifTzTCOL3NuTUodQradOkRCPWIM4TSHD3yWuMoHSeTypakZ mSWCGavnEgcD0wtISqPuMfA21Ucw8xbI5ZdrIOruL4WXyc8hMF1PqP1BX4eL6Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; b=bNsSiUAr27aTwxXnYRc2P3wJ8k9ud163o0Nv9sPPRSLsA4qNbE2RVUk0ZGHH862/gVt4Ad hKPFyylULklOIbDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Kees Cook , Luis Chamberlain , Andrew Morton , Peter Zijlstra , Josh Poimboeuf , Andy Shevchenko , "Guilherme G. Piccoli" , Arnd Bergmann Subject: [PATCH printk v2 08/11] panic: Add atomic write enforcement to warn/panic Date: Wed, 20 Sep 2023 01:14:53 +0206 Message-Id: <20230919230856.661435-9-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:11:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777517283057019209 X-GMAIL-MSGID: 1777517283057019209 From: Thomas Gleixner Invoke the atomic write enforcement functions for warn/panic to ensure that the information gets out to the consoles. For the panic case, add explicit intermediate atomic flush calls to ensure immediate flushing at important points. Otherwise the atomic flushing only occurs when dropping out of the elevated priority, which for panic may never happen. It is important to note that if there are any legacy consoles registered, they will be attempting to directly print from the printk-caller context, which may jeopardize the reliability of the atomic consoles. Optimally there should be no legacy consoles registered. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- kernel/panic.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 07239d4ad81e..86ed71ba8c4d 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -275,6 +275,7 @@ static void panic_other_cpus_shutdown(bool crash_kexec) */ void panic(const char *fmt, ...) { + enum nbcon_prio prev_prio; static char buf[1024]; va_list args; long i, i_next = 0, len; @@ -322,6 +323,8 @@ void panic(const char *fmt, ...) if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu) panic_smp_self_stop(); + prev_prio = nbcon_atomic_enter(NBCON_PRIO_PANIC); + console_verbose(); bust_spinlocks(1); va_start(args, fmt); @@ -382,6 +385,8 @@ void panic(const char *fmt, ...) if (_crash_kexec_post_notifiers) __crash_kexec(NULL); + nbcon_atomic_flush_all(); + console_unblank(); /* @@ -406,6 +411,7 @@ void panic(const char *fmt, ...) * We can't use the "normal" timers since we just panicked. */ pr_emerg("Rebooting in %d seconds..\n", panic_timeout); + nbcon_atomic_flush_all(); for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) { touch_nmi_watchdog(); @@ -424,6 +430,7 @@ void panic(const char *fmt, ...) */ if (panic_reboot_mode != REBOOT_UNDEFINED) reboot_mode = panic_reboot_mode; + nbcon_atomic_flush_all(); emergency_restart(); } #ifdef __sparc__ @@ -436,12 +443,16 @@ void panic(const char *fmt, ...) } #endif #if defined(CONFIG_S390) + nbcon_atomic_flush_all(); disabled_wait(); #endif pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); /* Do not scroll important messages printed above */ suppress_printk = 1; + + nbcon_atomic_exit(NBCON_PRIO_PANIC, prev_prio); + local_irq_enable(); for (i = 0; ; i += PANIC_TIMER_STEP) { touch_softlockup_watchdog(); @@ -652,6 +663,10 @@ struct warn_args { void __warn(const char *file, int line, void *caller, unsigned taint, struct pt_regs *regs, struct warn_args *args) { + enum nbcon_prio prev_prio; + + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + disable_trace_on_warning(); if (file) @@ -682,6 +697,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, /* Just a warning, don't kill lockdep. */ add_taint(taint, LOCKDEP_STILL_OK); + + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, prev_prio); } #ifdef CONFIG_BUG From patchwork Tue Sep 19 23:08:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3875888vqi; Tue, 19 Sep 2023 21:46:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfX4Qis6OTPMtSCQO7Fl0cUI9kYD1wNtUebiKY4ctg60B3TdacCDKLZRiWuP3BUCVsixEV X-Received: by 2002:a05:6a00:179f:b0:68e:3bc7:3101 with SMTP id s31-20020a056a00179f00b0068e3bc73101mr1997413pfg.2.1695185204456; Tue, 19 Sep 2023 21:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695185204; cv=none; d=google.com; s=arc-20160816; b=Tp3r9dGCxaiHnjSLy6x2LNiJdYffpXA2hd7086VLQvR9Qo6j85E3Qd3JLBt5/1fLQ6 Cc359ZVkPfu7KNe6ffmmjRzsqT5O2c59lD7rfoLWUFdTKYEqoe5erAENGI/J595cJM3J WVY3TyYEz69QXRLqU+nQ5RKnmwGlAKIeQkLx7Pqx37/2EKDYTK8u7HVxYnGv9XpgYWw5 vYWYt/gnQ6+rgIqmigpBWhvJqJAWpsfVCLaljob/eXbXbYV1JqCzN0/MjZ50jxwGAVUi x3q3eEIEAVIij5hIyqaqRkmBKzmcF9lK2LoBLBfiReS5i+NfHWs/tvBOMkcuna+E8Evm H3xA== 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:dkim-signature :dkim-signature:from; bh=3M6IXxDMcErVEoXMIDzEHrM+hhZey9Pc7y7dowbbNtk=; fh=3gevDrX7WuWUbena6o12/5hyTTSGeHznSST72uYLt3c=; b=RJkWIdtnK+Z3W01INSojVs/Z9zqkZWY4b9ZxucKhQd+olXS8hSSqSrAWlarFeb4Pug jSTeg6BknXI9o5ydcJPN4B8Gln7DR9ay0uBqyyp2bVQ1ZxhcRMIkQMbRBzUsV6TsKgJc wuhPfmk/bLL9LtxYQD6fwz/Teq7o4D4G2cFoMACAift+qr0KCODarZ9AZZ9OTxnLIok2 S0wCQy0ZueE3jlkYU/+GivhaT/ZUs7AdiBu5Ga25uA2UTiCI6M5VN/zmwN+YMYT0Au19 ApeLoVklOJHre8kscbDgT899HhIJB+DHpKsOjiecwiXod9K/VO0W0qhIVblfpYIYQs/S XnMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ykzLmHkU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id g7-20020a056a0023c700b006902507d409si11423086pfc.174.2023.09.19.21.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 21:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ykzLmHkU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9C1F8807070A; Tue, 19 Sep 2023 16:10:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbjISXKJ (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233578AbjISXJ1 (ORCPT ); Tue, 19 Sep 2023 19:09:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4637BF1 for ; Tue, 19 Sep 2023 16:09:18 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3M6IXxDMcErVEoXMIDzEHrM+hhZey9Pc7y7dowbbNtk=; b=ykzLmHkUV4QAIDn9PfSIf+5hV7yYHau/MwfSByro1+/RRo7xJ+fEdTKVzcdEcGiflpDxuO kjhSt3Zfya8Jid1zZi845nZJDhzpuhJEb0q3/Fcq++wddKi7Tl1uLEi4FT1haWi+es+l9Y dzyLYYnM4K/b0K0XJqsKPIPvLEv9kpe8Co4LCXg3656Db/fUAyCMJtb0z9Quatqcew/2r9 i1kjEQuv0D67WRfbU8ew0zqcZe5bBTk+IuMcU6gwgqjCNgnIZqAPxazLb5yAWxaixS3aCt QwchMoJlviiIAzHllzE1v4+PtMxza/htLXQLUVyF0UKwidvdTK9D5mLcm5cnUw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3M6IXxDMcErVEoXMIDzEHrM+hhZey9Pc7y7dowbbNtk=; b=NhLLwrLA38y5dN+KiT8IFLeDnAO76+WTX2vBcMJuxRtcbkK7T7OaHXmxLEaVWISZQUzkwD jr7HtmziecRcpUCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Kees Cook , Luis Chamberlain , Andrew Morton , Peter Zijlstra , Josh Poimboeuf , Arnd Bergmann , "Guilherme G. Piccoli" , Andy Shevchenko Subject: [PATCH printk v2 09/11] panic: Add atomic write enforcement to oops Date: Wed, 20 Sep 2023 01:14:54 +0206 Message-Id: <20230919230856.661435-10-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:10:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777516082772029010 X-GMAIL-MSGID: 1777530520964837278 Invoke the atomic write enforcement functions for oops to ensure that the information gets out to the consoles. Since there is no single general function that calls both oops_enter() and oops_exit(), the nesting feature of atomic write sections is taken advantage of in order to guarantee full coverage between the first oops_enter() and the last oops_exit(). It is important to note that if there are any legacy consoles registered, they will be attempting to directly print from the printk-caller context, which may jeopardize the reliability of the atomic consoles. Optimally there should be no legacy consoles registered. Signed-off-by: John Ogness --- kernel/panic.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 86ed71ba8c4d..e2879098645d 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -614,6 +614,10 @@ bool oops_may_print(void) return pause_on_oops_flag == 0; } +static atomic_t oops_cpu = ATOMIC_INIT(-1); +static int oops_nesting; +static enum nbcon_prio oops_prev_prio; + /* * Called when the architecture enters its oops handler, before it prints * anything. If this is the first CPU to oops, and it's oopsing the first @@ -630,6 +634,36 @@ bool oops_may_print(void) */ void oops_enter(void) { + enum nbcon_prio prev_prio; + int cpu = -1; + + /* + * If this turns out to be the first CPU in oops, this is the + * beginning of the outermost atomic section. Otherwise it is + * the beginning of an inner atomic section. + */ + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + + if (atomic_try_cmpxchg_relaxed(&oops_cpu, &cpu, smp_processor_id())) { + /* + * This is the first CPU in oops. Save the outermost + * @prev_prio in order to restore it on the outermost + * matching oops_exit(), when @oops_nesting == 0. + */ + oops_prev_prio = prev_prio; + + /* + * Enter an inner atomic section that ends at the end of this + * function. In this case, the nbcon_atomic_enter() above + * began the outermost atomic section. + */ + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + } + + /* Track nesting when this CPU is the owner. */ + if (cpu == -1 || cpu == smp_processor_id()) + oops_nesting++; + tracing_off(); /* can't trust the integrity of the kernel anymore: */ debug_locks_off(); @@ -637,6 +671,9 @@ void oops_enter(void) if (sysctl_oops_all_cpu_backtrace) trigger_all_cpu_backtrace(); + + /* Exit inner atomic section. */ + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, prev_prio); } static void print_oops_end_marker(void) @@ -652,6 +689,18 @@ void oops_exit(void) { do_oops_enter_exit(); print_oops_end_marker(); + + if (atomic_read(&oops_cpu) == smp_processor_id()) { + oops_nesting--; + if (oops_nesting == 0) { + atomic_set(&oops_cpu, -1); + + /* Exit outmost atomic section. */ + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, oops_prev_prio); + } + } + put_cpu(); + kmsg_dump(KMSG_DUMP_OOPS); } From patchwork Tue Sep 19 23:08:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3834607vqi; Tue, 19 Sep 2023 19:56:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8LBx8eu7BbCgJC7OKJDLgoSIvkP8wcARoRm/fRKklCcMD9QFQ92EO+Ef+Ez3WXn0DwwLh X-Received: by 2002:a17:903:4291:b0:1c5:64fd:a1c3 with SMTP id ju17-20020a170903429100b001c564fda1c3mr1113679plb.26.1695178575722; Tue, 19 Sep 2023 19:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695178575; cv=none; d=google.com; s=arc-20160816; b=RBQ1EmPCcQlSCpdAmRXFhBKkwRnyPiV1BkVr7l7R9imsT7GaLxA1mZEZEChg163Txa XSIOSx3bJrlc9VsOXWiPdZqGZmvfiYfdvJMd20PFaOqCZ+mgB3cApJ5VZOFBAtXZzI43 pO6p1HUq+YMY0/vavMYCb6RDl5rksuGnrhIkvz1faRY73+yfteY8aOly34eVAPQPz5a/ h+xELhkmiijei37clzz4lRdgyxI/CVyJLfbgrMiwYr72vYkH4h31H8eG8v1DrD2U1Ilg BJPPWMqgURsV8DoVhZTESr0k8tzVOvYNTRru/Mu261ZEux9tiA8EowO5SUgMRXW5fmBL cBZQ== 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:dkim-signature :dkim-signature:from; bh=ayShZA5Y6+vqpU4ni2cr8EGVcvIF6GWDCtcZG+RumvA=; fh=Zc51f6kezQIPGE+VpfICBLFP+oyouiLrY2CJAQIy7as=; b=O+MTAxFUmLPCQ/96kDiy3H/obo/0rTuG3f5N2+B632uavVmeBOccZtaljh0LpdBkzd 8PHc9jiElSRIRetZ6gwEvb1f1UcC9J/n4qYcUbHG7I2mEgRRGFXbB1fSjqn/ERAqQ3i9 WaUvqdZjrZSruWZqlFFI0qfjWt87I1Td2FdQ56dlxJS8BvMsFRoBpDr0HaHsVglvCPs0 +p5y9BOKUd2PW7u3MP5FrEihtedUvpSy9SwEML66VMpszHHL2nqF5SwpaHezi6ugSmmW +n61Vs82LlQ4zPsi/NJFJPpYxnTmX7Ivg4nv4lrVa1Ri4uP+LN0sdo8HME0HcFev2ruB EjQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qWi4MpNE; dkim=neutral (no key) header.i=@linutronix.de header.b=1RJuv2+v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m1-20020a170902d18100b001bf193a70b3si10448112plb.298.2023.09.19.19.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 19:56:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qWi4MpNE; dkim=neutral (no key) header.i=@linutronix.de header.b=1RJuv2+v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EC076821AD9E; Tue, 19 Sep 2023 16:10:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233711AbjISXKN (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233607AbjISXJ2 (ORCPT ); Tue, 19 Sep 2023 19:09:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3817F9; Tue, 19 Sep 2023 16:09:19 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayShZA5Y6+vqpU4ni2cr8EGVcvIF6GWDCtcZG+RumvA=; b=qWi4MpNE17XSTOZC15znu3okHtAskd1+gALDOCzTERnor7ZLmT4BWOTJ3SSSZacqDGfiOR cUYZw1W1x/dKVngg0utCkfIoE2HXz0xvGerwCc1bZkXBztclbspNQFbye0EHFyqn5q9emC DLqD5mEO2SkvCkj1goTYsLV0as0CCSyZ85xlxLCEO9cL6IOR+LMQxJv/M9T7PfhphXQjPS dmFqj/KfCTonrYTNj2gcEpjlHU0TAKebq5Opb9Y4rv+upIs/HzvcyhQ4K4DOJK1zyCSeWK jQLdDV04pCBe6+pHsDre7Bq+V5+/U1ZkkTYjAEMYlqqZL4wwdPGScwGttJdYDw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayShZA5Y6+vqpU4ni2cr8EGVcvIF6GWDCtcZG+RumvA=; b=1RJuv2+vauyF4pdXRf65q7Di4PvGlO48NYMcr4OCbk3zNzp+SBuVjXBekdVfdWPEbzx6t4 +dOdJccxuO8tY1DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org Subject: [PATCH printk v2 10/11] rcu: Add atomic write enforcement for rcu stalls Date: Wed, 20 Sep 2023 01:14:55 +0206 Message-Id: <20230919230856.661435-11-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:10:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777523569914306088 X-GMAIL-MSGID: 1777523569914306088 Invoke the atomic write enforcement functions for rcu stalls to ensure that the information gets out to the consoles. It is important to note that if there are any legacy consoles registered, they will be attempting to directly print from the printk-caller context, which may jeopardize the reliability of the atomic consoles. Optimally there should be no legacy consoles registered. Signed-off-by: John Ogness --- kernel/rcu/tree_stall.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h index 6f06dc12904a..0a58f8b233d8 100644 --- a/kernel/rcu/tree_stall.h +++ b/kernel/rcu/tree_stall.h @@ -8,6 +8,7 @@ */ #include +#include ////////////////////////////////////////////////////////////////////////////// // @@ -582,6 +583,7 @@ static void rcu_check_gp_kthread_expired_fqs_timer(void) static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps) { + enum nbcon_prio prev_prio; int cpu; unsigned long flags; unsigned long gpa; @@ -597,6 +599,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps) if (rcu_stall_is_suppressed()) return; + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + /* * OK, time to rat on our buddy... * See Documentation/RCU/stallwarn.rst for info on how to debug @@ -651,6 +655,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps) panic_on_rcu_stall(); rcu_force_quiescent_state(); /* Kick them all. */ + + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, prev_prio); } static void print_cpu_stall(unsigned long gps) From patchwork Tue Sep 19 23:08:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3821253vqi; Tue, 19 Sep 2023 19:17:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEQiLEtlJmTU7DLVxL9Q9Uz2hPeRZu1eNV+1uDc2HCGYmPkX2IgnnT/zdcllHbLyUTMfSo X-Received: by 2002:a05:6358:50cc:b0:143:21e8:11f2 with SMTP id m12-20020a05635850cc00b0014321e811f2mr1999505rwm.11.1695176273396; Tue, 19 Sep 2023 19:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695176273; cv=none; d=google.com; s=arc-20160816; b=tY3E0vuYuMvGq7++v95BbNiZEFsz7nnhoqYrTiSrtqMoorFWZeHbJ/rYDJBp6THbMM I0JcpcrTIVtQxRp9NK+WDzTSd42Qki/R/STZANCJ9BX63YjqjeSSpBynZ+A1FDIPOyUf rOijPaXF/+e2qXaxOboVDa8KjU2qedXDnCbN3MfDxSWrgixE1gm5fScDmRztV0/EvHnt PHYW0B02NFrK+gCGMO0U/kU/V5w3sCscgiMcTwjncQs6unbSUrSzrm8etq+Ut2FBFB98 3F745lqSiojsnAoYabeywOf9hOyoowDcBT5E1aaGjqGE8uG1PEJR8O+mL462gRnrZ8V8 PmIw== 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:dkim-signature :dkim-signature:from; bh=oTbjh+BCwK3ch0C9I9rGb2UB8TXtu3KoCP4n1cVIXrU=; fh=baLZk4VyAx6eqLoRrdDbCsrkF3EpnrHuPZYH860mNkA=; b=xFJgbrqD8F+n5n18uXNqtZ677LBeFe3yb0DWC8I+fA158PPThToWfzRuJ6xl6APer7 FG4ZWFMBer0phiDdr6U6eOA78DxKdPJaONAUWeeFBiqvLqix5wiWNnmhmyHq26k7p0Ve e8YD6TwD37Nw1Czz71ibdvHDcPoTg1C0dPN9T5LAXMSjymw0y3mSagZo5CgeJAPvB9qf SxWxfmLJY+Is4aEYqfg3nWuzXyWRIACYRUByT4IpMZPFLTA41/AS9Ozr3U/3nf5hBds4 RrBLeVPR1P6zpXewy8fgpmk0VHAdQo7KsBVX19AeCLJvinYnjojVabdbYRgsonPsZFVi 0w3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CWBMhviI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CPLhIrrf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id on11-20020a17090b1d0b00b00267d70fe0f7si551369pjb.23.2023.09.19.19.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 19:17:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CWBMhviI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CPLhIrrf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 01FA88075170; Tue, 19 Sep 2023 16:11:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233743AbjISXKS (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233637AbjISXJ3 (ORCPT ); Tue, 19 Sep 2023 19:09:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F93123 for ; Tue, 19 Sep 2023 16:09:21 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTbjh+BCwK3ch0C9I9rGb2UB8TXtu3KoCP4n1cVIXrU=; b=CWBMhviIBeB0aywq9Iy69hMDQxMEDISIoCiLV53lxHkko2TxoIvVObviV3JzALZYuskOuF vLup+KdFFXXpr7hN459KkJ29SwtjuHMyrA3BSs7Ujrhd+abfz1H8ytLUEW+eJeFy6awq36 2ENhovyBKC3vJZR4jV+OPnArx2KmR4sNhdzPBp/bzSrqb6EUEFX7E1fy6JAcJJv1yzxeLc A+iqlTdzrdh2m2RlOUFHJJgR68AsOVJpbN1YFDrFAjrkmHPhF2YQSdDMPxIPBZuTUOpH5X DjXVN0Jjlht76MiEJGEcYGxW/h7BnLOThqX2RssAMAXnyydqbgMJK2dhSHOkCA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTbjh+BCwK3ch0C9I9rGb2UB8TXtu3KoCP4n1cVIXrU=; b=CPLhIrrfnQOJB1t7QDK40++wEqAcYJmu2Ob8akLI6kcwcYqg0zr74n591slHOpJUudXLZ0 tBo8+S8PCFkJpEAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Subject: [PATCH printk v2 11/11] lockdep: Add atomic write enforcement for lockdep splats Date: Wed, 20 Sep 2023 01:14:56 +0206 Message-Id: <20230919230856.661435-12-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:11:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777521155574629847 X-GMAIL-MSGID: 1777521155574629847 Invoke the atomic write enforcement functions for lockdep splats to ensure that the information gets out to the consoles. It is important to note that if there are any legacy consoles registered, they will be attempting to directly print from the printk-caller context, which may jeopardize the reliability of the atomic consoles. Optimally there should be no legacy consoles registered. Signed-off-by: John Ogness --- kernel/locking/lockdep.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index e85b5ad3e206..5310a94e3efd 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -3967,9 +3968,13 @@ static void print_usage_bug(struct task_struct *curr, struct held_lock *this, enum lock_usage_bit prev_bit, enum lock_usage_bit new_bit) { + enum nbcon_prio prev_prio; + if (!debug_locks_off() || debug_locks_silent) return; + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + pr_warn("\n"); pr_warn("================================\n"); pr_warn("WARNING: inconsistent lock state\n"); @@ -3998,6 +4003,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, pr_warn("\nstack backtrace:\n"); dump_stack(); + + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, prev_prio); } /*