From patchwork Wed Oct 19 14:55:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 5656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379814wrs; Wed, 19 Oct 2022 08:11:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67rDpDTnxhHPe8V1VZqoEi/tQupptKGz34r7vExRUy/u08HttyjslfLQkSOIj6iMffPPcl X-Received: by 2002:a17:907:7635:b0:78d:c5e9:3e57 with SMTP id jy21-20020a170907763500b0078dc5e93e57mr7278222ejc.204.1666192299030; Wed, 19 Oct 2022 08:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192299; cv=none; d=google.com; s=arc-20160816; b=Ay+iE/l0QWTcEmyGP2EYmlBUtb3QdmP8ik4yYMvmV0EEyIIPW10/3JfMBfmOcZT72g oKXrVuetB+Hk3RIfaLd+7vIv6eDUzQZT8E53o4QUg1dNq+GHKg0WO2ms3KuJ+umvRQyQ e1tUY8GDPigOekuUZKBOjj0pJYUXB7AilGeFzmUy4x3CmklYkMQbYVAbjP4umjEbIJA9 WJSnn+L2IE1lQ+hTw0RN0kaWnkWVDiJNB8hGf18Gei2IhjMdXr4Avg49brI7L0knsT2Z aCQ9gCs8jkyGqg9x/EC0dg5yisr6jgIOBzxg5ueMBe5Fb2ptuDNi/y5AGM23tROMuKSP ivng== 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=dEfLDywQMbLFMveMIU5ztmggdkM8VKhqRGZUba4knEA=; b=pXnWDq3zOrbn7lyn8TYXiPj9PWaIUFwjbBsq3BiSpJK430xvHJa+4XH4nD6vHfC/VZ hmTAVSrjd36cgfKtRaEy/ML2ORExh0qC+4lGa7z8+HohtN6CQBZK8TjCgPrZupCpdHBt PRWuP2OtIfXvEeOcie8IKHVzb+0WBjQeI4m/2Nztbvu8iKdUAlnYtf6rrQuAsNh5L7T0 r8Zrlz1+tbtdwyeQvyY/exn+qKlW7L6NrNitFv0bPB5ZOkShJlNJb/fK9ekuNWMofs9t FFWEUj4ZDlQLtnxg4MWcFbRQ3Jca9tUh35bQc3wiN3PFJkfyc7RC5J9kDe9EX0ug8XiL ZHdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tvGWDuIb; dkim=neutral (no key) header.i=@linutronix.de header.b=zJjK8oc9; 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 e11-20020a056402104b00b004587cd5a5bdsi12978648edu.81.2022.10.19.08.11.12; Wed, 19 Oct 2022 08:11:39 -0700 (PDT) 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=tvGWDuIb; dkim=neutral (no key) header.i=@linutronix.de header.b=zJjK8oc9; 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 S231775AbiJSPGZ (ORCPT + 99 others); Wed, 19 Oct 2022 11:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiJSPFj (ORCPT ); Wed, 19 Oct 2022 11:05:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9676F1C2EB3 for ; Wed, 19 Oct 2022 07:59:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191379; 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=dEfLDywQMbLFMveMIU5ztmggdkM8VKhqRGZUba4knEA=; b=tvGWDuIbnMg81nElIpNQcHDQap243WbjOFmLBBssheT3WAcSo/uy+6Y/V1xLaZOuvbqvoP HGWUcc6muabTL3JhrtCL2O+nHHlD1uN8YVPQtxkig8QS8ESpv/V3WRMZA7Rxl4IIndi7hD szwUUd+8jDai9nm38yOHM416UH1skAKg+0nBI9frWXFXAUAQs4OkB5nXnBEBkEVbgTC1Rk qZ92WfVER0K26YNlgAgm71hLsBMCs+JmDbBTQmx0vFv52LhECZBDo3JbTp3eTUIpFu0dzy 5cZYtV6xxBzm2eo129s+wAAZgFZr0dg9IA7FHp+XlWd3FtdHSpugj1GkLYE18g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191379; 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=dEfLDywQMbLFMveMIU5ztmggdkM8VKhqRGZUba4knEA=; b=zJjK8oc9MpyW+AN+CgjCFO34fO7H6UGzAb1JPwNkz17MJ2pO3wmfGFId0+ak7aOpZp8Q+5 uWrTfF0L395aPXBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 32/38] printk: __pr_flush: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:54 +0206 Message-Id: <20221019145600.1282823-33-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-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?1747129256312228335?= X-GMAIL-MSGID: =?utf-8?q?1747129256312228335?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. 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 809c43e596d8..2faa6e3e2fb8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3454,6 +3454,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; @@ -3464,9 +3465,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)) @@ -3475,6 +3482,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