From patchwork Mon Nov 7 14:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078759wru; Mon, 7 Nov 2022 06:21:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM4i6XtJIZ4xhwLcSUADt9lu+2YReBfHGWFGl5CpF1t5AZjIIj8tz3bWTu5yt299TS76VRaC X-Received: by 2002:a05:6a00:4c9c:b0:56b:a9bd:ee4f with SMTP id eb28-20020a056a004c9c00b0056ba9bdee4fmr50802958pfb.35.1667830865976; Mon, 07 Nov 2022 06:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830865; cv=none; d=google.com; s=arc-20160816; b=jCm/RQ1cFeb6dYfye90hDkfLF5yul5zVi8OieuQei3Yx0ZigNrDabpgWtStDJfLC2r YJPK4TTqTiBYi9Zcdm94g7WY1mZYg4OuB2X6k5etetuZcUbW/7gFQXkCFcCHUBd4KxpB xeLbLWUjG0DH5PT59UGxcZc+61UWzclLz1vAm8XX5lYTlPm6LbpzlDMTtP+wEZiVuuDk 2tsD9aHmjounqaUQP5q+HjRxcPEFLULy3Pxn1Bf3W+D2guNlUxrAtljLEpb8wBM15RHA qyqD4k5EEJuakOgy8VflzyAEY6xHyCGuFXgwJ4COPWbC3h8Z+HNX3CkjGwbvCdooNV1G acag== 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=eiV0lB4PHD+wq8ihYIBCP4Hs9zHSZAucHIdl/L7PQQqdfpg6pl9sMW9XH6u6catxnp 0sYNzVHxMVh+Ji7cONJwQuOtQpRNd4lBZcNTMM7oIYNLd6lcDL0pSaCulY1f847bxPzY 9FZ+okLlvPUSVD50IfZAJeLRtzuCN/9jmzmCqBeO2LIW9KYz0hqjZpADxJc3m/1tdRRZ hG5qTquJvlR0N4P+nWm94bXfChMfUoV4iZxe7WeCSorkMvIYt/qwAEAs8yOfN0No9EZ3 IHtG7le2HKCM07EWGZ2HPsdmUoMP/jlACm3xykqYqfJpSISlmUFyznE5slPTFpnh7I/9 G3ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tm+UuDKt; 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::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 v25-20020a637a19000000b0044c3e11a7b4si10487051pgc.42.2022.11.07.06.20.52; Mon, 07 Nov 2022 06:21:05 -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=tm+UuDKt; 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::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 S231776AbiKGOSJ (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbiKGOQv (ORCPT ); Mon, 7 Nov 2022 09:16:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6962C1CFF6 for ; Mon, 7 Nov 2022 06:16:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830609; 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=tm+UuDKtm5l/qfvFtCtQkn9+nlKUcd0FMXZwD/N0Ka1Icck0LpqfBGD9XYIber/RZs2qhm di7pV0GPtm9HLj2VN4zQQ2SG4AQsQ7KDTN7oTSSXMUSgMC76bCTv33CsLyPFuJKxJ/Fa+t HAly7gRr8pJDDNXZDcmYVA5Bvu3BgltddUkB9SaGquUj74b+E2iL9noXigLGIo4ugQpYrb hS11fUQ9DrkkzLMWBqNv9gMH9oHCEUQLdgimCX/zlb23mazp4o9jGoOujZ1ZwrYKmDAUR7 xx0ohCgWc+/kEsyZAgSOGLlGLOchupmxtVFr+xNcYKWclhzqII9kmYFiwHJQIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830609; 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=DhOptzRogvtegO49HBlRx8o5kp/lMWiItSCsCgg5oU7r5sY//CNAld05WMBSfbp9FmujYZ BBk/NKS2y2FRUqDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 19/40] printk: console_device: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:17 +0106 Message-Id: <20221107141638.3790965-20-john.ogness@linutronix.de> In-Reply-To: <20221107141638.3790965-1-john.ogness@linutronix.de> References: <20221107141638.3790965-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?1748847418529124084?= X-GMAIL-MSGID: =?utf-8?q?1748847418529124084?= 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index de86a502b50b..ec50777d0301 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3029,15 +3029,25 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver = NULL; + int cookie; + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); - for_each_console(c) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver = c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; }