Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp849160rwb; Wed, 16 Nov 2022 08:25:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf56vKjzMiGSpz8ZzavklNoy2z8HOtgOVCJVuw4ztRTH/jBTYANPE4epQZfW39KZXA/OHKcM X-Received: by 2002:aa7:dd0a:0:b0:461:524f:a8f4 with SMTP id i10-20020aa7dd0a000000b00461524fa8f4mr20130258edv.260.1668615923464; Wed, 16 Nov 2022 08:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615923; cv=none; d=google.com; s=arc-20160816; b=Qv0C9wNdFfofnjP8hh4NUNKBW065R8hxOENK2aea9mfLaaePs+eRy774dm1mSIebeA R5va/CCtRxlihPgXetR5lWN7B5LPZp39DrIEH1kdPnH+dwcon1tiTB6k0q5Q68orsNw3 JRblbaO8cn+fOx0E7ML4gNIKmE3gi6tPmEBeaZLOhWSWv9an/7V9RTBfUhWvTKNFbJ4v 5QbmQFM+ARegZvsRFM2l3XmkiTTzqWckoqf2HLaHZUuu+SzRGy5ASEyDtdWdnITw4aFd 0LgF6fzlyUPlstrBclns4tXGRksUgd0uekntjnTYWNJjPDKTKBvFjY63Sa1enoFkyM7/ 7HKA== 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=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=HSpQVfGwDL+j1BUK8EmzWjn3YvHZ6Q4tlON1EFiYxCEV6rv30tsAvzAGs5bdqLXk7j kn6liIb3GMRIANsAYynjOBJFjgr3FS5V+8Vh7O5n62OV39GmxCe6A3OLB4Dl692KD6ip pS4RUbPQrQex8xP7N0TB9vSa2NUdkVhXcM9h1jBd64/7c/n0o9M32mLzJL0GAfPIVwP3 3hX5DEi/G4R92otrWHVI6tQus7tlddEa2l3bg9hwoBqwKlwXNyHnl8btdD1DSrraS67C w9bFXp1H/9p/r8GXq+XqC961tb4BYOPm42ZiNw4eEf89haSD+vORAoh/VTKvIJgOV+tO wSnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kayQnh7l; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa6-20020a170907868600b007a45e4f4ff0si15830128ejc.885.2022.11.16.08.24.59; Wed, 16 Nov 2022 08:25:23 -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=kayQnh7l; 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 S233296AbiKPQWx (ORCPT + 92 others); Wed, 16 Nov 2022 11:22:53 -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: 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. 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 timeout_ms, bool reset_on_progre struct console *c; u64 last_diff = 0; u64 printk_seq; + int cookie; u64 diff; u64 seq; @@ -3570,9 +3571,15 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre for (;;) { diff = 0; + /* + * 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(); - for_each_console(c) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (con && con != c) continue; if (!console_is_usable(c)) @@ -3581,6 +3588,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre if (printk_seq < seq) diff += seq - printk_seq; } + console_srcu_read_unlock(cookie); /* * If consoles are suspended, it cannot be expected that they -- 2.30.2