Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp862556rwb; Wed, 16 Nov 2022 08:36:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5yJOJJ6agVeVmzFrIuRNtoUXFHkmoWdRn8L/0c8MwCbI4EJ8iQPqC9DVc1LuOy2LDEEGRJ X-Received: by 2002:a05:6402:17d9:b0:458:ea8c:bfb4 with SMTP id s25-20020a05640217d900b00458ea8cbfb4mr20258712edy.419.1668616562425; Wed, 16 Nov 2022 08:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616562; cv=none; d=google.com; s=arc-20160816; b=0FinKOBWQyUZjRSGeU22CaEA7zS1ykDaw3hzqpaDSrfX5DnyVg5dKSKs29pFdYI3Xu FmHiOFGdYJYyv/LKl/kOuIfXP5K4Nps9Eco4oXzSJy7PvOTbz2GE3ZLkbtPZYiyNL+Nn Wn8x2rnrKN0W46ejfn/mgfAYNzLIJvJhtCPvt+l5txZwxouBJzHJerRKLxYpvsoLRVHq XkzX+1bDkkyYb0Tuby9DSgcKvxqnROsfv7RZBMi4uwd4EIhO0Aobq9VDI0mKvOqpWCm9 1nwJ1aSYBn/zOTuTRTsvDU35GtUxtoOnPGDzbHdZBWhOTGXwGzMAe9KTAGFOz1SFD0pm ArLg== 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=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=IAZxx3VZrE27YhYBzXeeIfNl3tEAInzfk4hqzYcrXQDsGZeTdox6GQVnpPLMJFq1Q4 dmvOIqFODk4VPKpvi/gwJQYp9qlIy6tWgP5UkQ3Ns1F052EWy57ggO9THvpP1uYa8P/F jkRhSzkgeaJ8+jTnx5ALkQUrAw3Uh8X6wDfGHJ7jrPOM7Ctvvtz5uPhrcBXaLZEWj+0K UYcsr8tUXHQcsHus1Y5CrvksJfyXev0EQ6xQgrZ1p4kRhCOm0XBIAiJs26yCnL4QcahY vZbu/bjldtTw2RN7ucN/2b9/isJ4Cn80VbMHZ6LheOF++0Ksp8093ZVMjUp7dHyV+QiN Ebvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="k/cRkSzu"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg40-20020a170907a42800b007a072b8240csi15043307ejc.927.2022.11.16.08.35.39; Wed, 16 Nov 2022 08:36:02 -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="k/cRkSzu"; 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 S238791AbiKPQYB (ORCPT + 91 others); Wed, 16 Nov 2022 11:24:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233472AbiKPQWd (ORCPT ); Wed, 16 Nov 2022 11:22:33 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E27326F5 for ; Wed, 16 Nov 2022 08:22:07 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615726; 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=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=k/cRkSzuFCT+qLGQGkimjidC2S2ewQnumtvJw+ZaIw2kd+mtyfYy9IDf+wRPav3Z6JAB3W yPERjIarGDkPzFRVqTufPPgKmx4BK0i6aseuo+Yjja1rFdrV5XJ5k1WBdOguLmdv5QsyPe eqKAPKqI82efDymKZ0fsPD7RNWXNLJgD+noCTM8rnZDqxJzmYGbZ1OMcv23JC9HGjJGwsN HxoYF605s6qqpxK94MpbPyh543sKAnGUO88n/4muBc6o+CsE3JHTcKrxHVdNm/l2MncEfQ HlU7VMMmg6t4dEy7gqKJPyPqx/BEtOpKYzOp3OYAYVAS+eMHhFFJ9uSEvzJL6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615726; 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=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=ZgnqSOHRDB9ITTyaqG0OzhGDy6iC+fOzqVTExO/t8Tiuha/tipl08vwtipSqjr/KO4CXCI YfEAjtozcg8gaaBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 20/40] printk: console_device: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:32 +0106 Message-Id: <20221116162152.193147-21-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 1a805ebdfe94..694c2da2919c 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; } -- 2.30.2