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;