From nobody Tue Apr 7 22:02:25 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 A5FB7C43217 for ; Wed, 16 Nov 2022 16:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237931AbiKPQWy (ORCPT ); Wed, 16 Nov 2022 11:22:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B0C953EE9 for ; Wed, 16 Nov 2022 08:22:06 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615725; 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=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=kayQnh7l4s1491kWSKsE/fOVnX9St78ObnsuaLA1l80ClxwMsYALUbty4DW6fqOiG5YVUa lg4IoP9w8yOjeLX4z39itvhtah+ckgU060CVoM7oO6lzA0XOWohgesE7+MLAwzzUJK/9JF McJBvjt14QhEPdiWLpuZ2QRn5X3tI4qkl6flh3vUgYemOXjw+A7Nn1pEGjBPY1b4VcBawz 2Z5IFC9i4PVN4C+bUtIZNOF368QeWu3VNuuCp2Ld/5LafIGNTU41lOfmP3m3JDB9I1pgXb avVBlbxv32SlYFsQFcml1Ss+YxWCCDK3kqlG/eEGkZdBzvGBB3Vovt0cuvdKmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615725; 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=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=p+tlMt2fKLrSZ7uozDnyug3YD7ymR7gPSP52ARH76IKRuFjFDWwCw/QeQIfwzypdQBhSZB c2vSgXnuvgiNAuDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 16/40] printk: __pr_flush: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:28 +0106 Message-Id: <20221116162152.193147-17-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: 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. 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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3a7b1931b7c9..6666cc27a014 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3560,6 +3560,7 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre struct console *c; u64 last_diff =3D 0; u64 printk_seq; + int cookie; u64 diff; u64 seq; =20 @@ -3570,9 +3571,15 @@ static bool __pr_flush(struct console *con, int time= out_ms, bool reset_on_progre for (;;) { diff =3D 0; =20 + /* + * Hold the console_lock to guarantee safe access to + * console->seq and to prevent changes to @console_suspended + * until all consoles have been processed. + */ console_lock(); =20 - for_each_console(c) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (con && con !=3D c) continue; if (!console_is_usable(c)) @@ -3581,6 +3588,7 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre if (printk_seq < seq) diff +=3D seq - printk_seq; } + console_srcu_read_unlock(cookie); =20 /* * If consoles are suspended, it cannot be expected that they --=20 2.30.2