From patchwork Mon Nov 14 16:29:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238475wru; Mon, 14 Nov 2022 08:31:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eB9Y41xFYjyAcBRirhdPz0pH1q99mPEpK8l0bprhafqaJdz1rHjNn3tSYB9P1LB9y/hEA X-Received: by 2002:a17:90b:2691:b0:213:971d:9022 with SMTP id pl17-20020a17090b269100b00213971d9022mr14635728pjb.47.1668443517753; Mon, 14 Nov 2022 08:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443517; cv=none; d=google.com; s=arc-20160816; b=lFfanLIhab2hjttqIgbnwiVxRj85mDeSrAnAoOOcXZz8ivAEZEj4CDeDEu3hJLSG0l 2BqtD05fELUlQo/Op7f2WeSW4E99MLIIeXbyl08PdYeTAsC72bU0AZoIj5TYbdQE1liI PwT7nR2hBbx9WJKOUcfWgjV6A2zQ4haMCMFOqvB7zRfuLT91HgznzXhWed6/d95+Szr3 hxBEzbNUODbI09bjVU08Lh6nXyC+82oniYuyFirTJE5NNw5+jaGqHX3X7Gn3mwBRZ67b fnU5K1jza4GUGTJxIpfD8eXOPaLMkO68QyAPp8ExDxPzwPianvh3VC7lj+6/oJAV1wqJ Q34Q== 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=OWU2uTvZal427et8+V84bsVk1DFNlekUzUNvOYIclVCWlKSvV81yX/yAji7p4LVTFq s0YBxcgXSVs/rVXQNxDOOAMVTGD35vEuVhxdsVPsEM+wLZgkrYay6sY3l9BRxcL4ZXS0 H8ce/loPHuqTkQtRaGETdpDgtr71UG+umEGabLbcBVIivYCRoj/x6rwR0vHuTqNKPgsM hdkxvk7VtHGxmMNgZgAJeKHL+TN+iEoHax3EvRAQaM0cPCruZb3x8Z1rxz/2EEbUSUsn pSQnSY6uMyUk8xLg90Syl1VXa1bdh6MhB8Kr1Zf+0y9FxSmJopD21LQsn+B0EJqUZzPZ 9yPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jkUNUusO; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a635d09000000b0046f0ae1bb8fsi9585324pgb.785.2022.11.14.08.31.19; Mon, 14 Nov 2022 08:31:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jkUNUusO; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237676AbiKNQaj (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237565AbiKNQ3u (ORCPT ); Mon, 14 Nov 2022 11:29:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8302183B for ; Mon, 14 Nov 2022 08:29:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443381; 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=jkUNUusOa/rDiW2kEjSYqIAHPvnAj0abKXtBCPnj584XACyyvzV5ZH44XLMH/6YFLzlBpm 307DWV5o/1MAT/hEvez85x/1QquMLgESndw0eclq3j6Pl8c23CjghF1wKJNCzuacJPoWMm t4lJOQJJ4MDdacZSgV+Kwz402KPfe/3kuN+oETlDp7DOce4+lG9OxxB68naMHDidDwUy0o /L7PY47fuINkEYgNlN2EdKuwEO0KabdJjQeWzq5vzOhggaizQ3HgoY36jS9DInC4A3aOVs 6+eiz2LZey/G0NOThgwe9aQm3JzXt9RX2zSI+J8CpRa/b2S7s/HIto/+ipbQUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443381; 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=6DT15jpBvvNOo7s7TIRJhL3KxV1amiVrLZFlRKfmiI6C04XMwZ2GNcWmwUPxZgcpSlkNs7 wUeDm3Q+7LaGrqBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 17/39] printk: console_unblank: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:10 +0106 Message-Id: <20221114162932.141883-18-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749489830049898432?= X-GMAIL-MSGID: =?utf-8?q?1749489830049898432?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index bc563972e468..7304cbcd6dd4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2999,10 +2999,14 @@ EXPORT_SYMBOL(console_conditional_schedule); void console_unblank(void) { struct console *c; + int cookie; /* - * console_unblank can no longer be called in interrupt context unless - * oops_in_progress is set to 1.. + * Stop console printing because the unblank() callback may + * assume the console is not within its write() callback. + * + * If @oops_in_progress is set, this may be an atomic context. + * In that case, attempt a trylock as best-effort. */ if (oops_in_progress) { if (down_trylock_console_sem() != 0) @@ -3012,9 +3016,14 @@ void console_unblank(void) console_locked = 1; console_may_schedule = 0; - for_each_console(c) - if ((c->flags & CON_ENABLED) && c->unblank) + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank) c->unblank(); + } + console_srcu_read_unlock(cookie); + console_unlock(); if (!oops_in_progress)