From patchwork Mon Nov 14 16:29:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238457wru; Mon, 14 Nov 2022 08:31:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5M2xDXcwTD6wBi0DY7HeE55COA+zDf6c9u/tWXJm7fb5mvWfgSb4hnlIlMJNtu0N+tieSS X-Received: by 2002:a17:90a:8004:b0:212:c384:d386 with SMTP id b4-20020a17090a800400b00212c384d386mr14332889pjn.79.1668443515518; Mon, 14 Nov 2022 08:31:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443515; cv=none; d=google.com; s=arc-20160816; b=wftW/QymPKMXnGaTzTBcLkyDdpF9BaghB0fkyShsVWCmMZes+WUIKXMKvsLkspUS8r M1EGUNZtE3hi1FdXXVU0Ahj/iatvR2jaBQY8HWsZ3K75VL8jVvjegYHJvoy+alccG05i jle5kdalFiZ2dwivNTGMtmtBAcE77Kefa/Du8CocYuekOWofyjeqsHnbnYR4p8ZHawON lPobVF1BCwaA0vBlLkGWhUUvzmT+2NW1TD2qIBXCNP6ZizsrJOp6xpcSgkKfrAqbmsAz Nvhd0O4Yl+UBT+XMYXL6F+It+UWXvcx1hvPSHvFv9UAov2NNUJI/KWo40vOXvOBNrjpR E2Ew== 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=Sr4Rb8/irsO6atWCsVQ24xHdSmPtYmTwR59M1VXqDPvB332mTQncVbIVURAGnTDfu+ HYszHzze/Kg/i7QSk5LcM2iQS8cqAV+wwsRd1Ewk4fnX+iIOkIR15in3ikNFff5df12W qHj2UDhehk3FmweqLHpEG6fhDrh1HL7CbALvcwQFdk2G/c3AAgYsTZ1SHs1lgaq+CMDr DNwIAy1QbAgUUIaPBJtcBIu/+sBSsD7jsVYLVaS9sTTyA94eQUJJbVqmcMlIA1eeJBaw IHMbo6iEnTnENiN0qHcsCb7lX6413pxnUw8Q992hYnTl8W48atWTjFV1tbYwTQtCwGpO NsFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bbR2W4gq; dkim=neutral (no key) header.i=@linutronix.de header.b=0FQ3W38V; 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 bm18-20020a656e92000000b0047688fc8acdsi2614165pgb.474.2022.11.14.08.31.11; Mon, 14 Nov 2022 08:31:55 -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=bbR2W4gq; dkim=neutral (no key) header.i=@linutronix.de header.b=0FQ3W38V; 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 S237690AbiKNQar (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237569AbiKNQ3v (ORCPT ); Mon, 14 Nov 2022 11:29:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD1FC2252D 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=1668443382; 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=bbR2W4gqB1076ROKgh/MNgK01Tzv0Le3BX+Zotvf/ft2eI7wlxLJhjLW27gCrMzbsLG/gK G6r5Ad9lmV0s2P8unlytWuKvcYuADR72fClD57tKzaEOi4ndiE3ME2QYSR4JJ9wNEherg6 7tC8+dinHlxyjiWfl9whO2u8jrBXBwL6pikjf/NN3WKm/FcyiDbUCLXKoz1CWpWWPlciex Fyals1BFl9+dtKFxw0Yn3wBjC1bSlRo93qnu9ieRsXPWK+JWE8S+SlJy9Iyq8NrItyqIwB PdLhEsG4AH8UF/7XHTyr/lxgxttkKw6egNT60YIJaHsVGkarmdfNjMo+y8sF9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443382; 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=0FQ3W38V4gG8pEPSTtVp12zhC1wqEbepo4UKy77fjui7MHnQj6A/VCbbcUMV+WhYXnre+L x+7lL5FXwnoLC6DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 19/39] printk: console_device: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:12 +0106 Message-Id: <20221114162932.141883-20-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?1749489827596886112?= X-GMAIL-MSGID: =?utf-8?q?1749489827596886112?= Use srcu console list iteration for console list traversal. It is acceptable because the consoles might come and go at any time. Strict synchronizing with console registration code would not bring any advantage over srcu. 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 f536233d8234..fb609a19f797 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3076,15 +3076,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; }