From nobody Mon Apr 13 17:03:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 995A2C433FE for ; Mon, 14 Nov 2022 16:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237692AbiKNQat (ORCPT ); Mon, 14 Nov 2022 11:30:49 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D NULL; + int cookie; =20 + /* + * 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 =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver =3D c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } --=20 2.30.2