From patchwork Wed Nov 16 16:21:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp234166wru; Wed, 16 Nov 2022 08:27:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ziVIrLTqr+gj2sZQEFx3zZfOaAH7nBNt71sEHwjWysRqU03ZEUwpxHHtdKFmBnti5hJVt X-Received: by 2002:a17:902:8645:b0:186:5a0c:85a2 with SMTP id y5-20020a170902864500b001865a0c85a2mr9606976plt.79.1668616040006; Wed, 16 Nov 2022 08:27:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616039; cv=none; d=google.com; s=arc-20160816; b=Z+8P7+K1CiRovH8u6EI6UNxV3+a9YGbs6wC+F4+4lvpsf9xexXNrIiCshJAqvleE5D 6ETZSRyC8LNTfSDXYcYjki75k4uzmc/bi8g3NwGSYyhwZxTfPBb1PyidqMjcpgfcP6ie dWEHE+9K6UWua3fxr+o4VZuuNzK5ZzARPQBL99Fl2IIjDplH5HS8UtCqJRMGxLMj6xVf dPJpdiH8J4gp6mE1Mm4Q0fjvRqREIyD2sWbgM4HN5KAUmIovuByL5pMKGdZX175yNpBx BzPKy+TAYgCws+aRRgr+nMjpeerThuKiPkSNLHnGIxcP5blGH04ZVmqaiCdrd8+Cef9K 8Rkw== 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=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=lXNPdy4z+BmrHlZ7D63YIomLvysf1WkdfT5M7szXrOP+ZuWyDoWHGgzpdasS2v1Jwb 6vSefMRg8Loghvpc6nnHg98C2x0bTSWrBcwP7CVkL9xNfAxRY8gH8cTp9a4zAVdSczGQ OqzlR4On5ARpE0li5PNmX5BeEV7IKbBoEUpk7QdszSeVNIkmQdTDzv9xBMMLvp4bCwxH 3nRhMzfC+migpXliPvJpoQVvxYlhESeV3nPfHi5h+6/YkBEpgcD8X2nOB9ZNXcSEL4Ny dxhqdFnU5cOaxQg+F93EYQFt4xke/8Da4++qn8U3wDFobr3dXFpKlbNPEOJSxJAeYFIT e27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sTxOuw9r; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PvcnYVBP; 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 e23-20020a63db17000000b0047632d0ec49si12067684pgg.347.2022.11.16.08.27.07; Wed, 16 Nov 2022 08:27:19 -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=sTxOuw9r; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PvcnYVBP; 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 S238781AbiKPQXz (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234352AbiKPQWc (ORCPT ); Wed, 16 Nov 2022 11:22:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB50D56ED1 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=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=sTxOuw9rM214SMJzCfx+HKjrQUF/mTpRzM+B/lCLL7hyaTNlBpzwQSvIRhqwSfvgVD3Gyc sEApjwVJ0WqCozTqqEmj8agYVaXrcRjFI6kA07+VBbZ/tugYhMlixLEXmdtlH5RMehAbRQ fwdca4X+pSWesLAEXIaGDjkVvY2xCPj9KvORWxMbaQh7p1cUdEIyUcUrjugxCTM2kQPISn M37p6pf5xACQyEWa2nmO91fuX+/YB7y6cja8uO3qwXbk3ILTnyh/a04thRTfHdghRW/ALT JENYXZt4FPJebfRLVlJunL12KjZF6j2IqFPnttypTPpI6OKx2XdzoM5f2EjgGw== 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=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=PvcnYVBPLntB2fGmHVVPmL6WouNpD04Mu+Xc6JN2IjcZpqlc32gguaNIJ3bsNkK0Gb4S8x U9YLMPZmn0BliHBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 19/40] printk: console_flush_on_panic: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:31 +0106 Message-Id: <20221116162152.193147-20-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 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?1749670733154901985?= X-GMAIL-MSGID: =?utf-8?q?1749670733154901985?= With SRCU it is now safe to traverse the console list, even if the console_trylock() failed. However, overwriting console->seq when console_trylock() failed is still an issue. Switch to SRCU iteration and document remaining issue with console->seq. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b4be3b08d909..1a805ebdfe94 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3049,21 +3049,22 @@ void console_flush_on_panic(enum con_flush_mode mode) console_may_schedule = 0; if (mode == CONSOLE_REPLAY_ALL) { - struct hlist_node *tmp; struct console *c; + int cookie; u64 seq; seq = prb_first_valid_seq(prb); - /* - * This cannot use for_each_console() because it's not established - * that the current context has console locked and neither there is - * a guarantee that there is no concurrency in that case. - * - * Open code it for documentation purposes and pretend that - * it works. - */ - hlist_for_each_entry_safe(c, tmp, &console_list, node) + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + /* + * If the above console_trylock() failed, this is an + * unsynchronized assignment. But in that case, the + * kernel is in "hope and pray" mode anyway. + */ c->seq = seq; + } + console_srcu_read_unlock(cookie); } console_unlock(); }