From patchwork Wed Oct 19 14:55:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 5649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379437wrs; Wed, 19 Oct 2022 08:10:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wSIqE39SPnbdZwEDwuQBlzAgWFweUbAfvVaHwqumYHdXn9oHFCP3AlHSypwFU+ijBZkBH X-Received: by 2002:a17:907:980e:b0:78d:b6d8:f53c with SMTP id ji14-20020a170907980e00b0078db6d8f53cmr7440928ejc.70.1666192251855; Wed, 19 Oct 2022 08:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192251; cv=none; d=google.com; s=arc-20160816; b=N1MmE5/6GOGEHLTSnWX23ZuYcOhQM1Nk+EzxXzBSsFR2rnVthx+ifDM+gmbuX5dmQT htwiSDy7r9XHwA0K15QTHhfVRPl9/oVUB/uURYGrgAIPTsn5L8tMwRooLnTQSAlH1nK6 7kZm0nYbc5hIww1yD3csKj8yOAToJMfYWNvgNiUDmcYw48r1sWboyuoWDUE422tCDqxH ICvxOF0f4mxj+pNrAGPQm09ywKsi0RVtwgsA/osoU0k1nsx8AZE2o7mXc/JNLiTxb7WQ nQ5QLkwaiTJvidndAeMluGkjsDTf0TuR0OArmETdhJSrUMZ1mqvnGdS0Lbmc21FDWuXm h3wA== 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=s9ex8lzRPv2fLvIIrbPhNI07gh3HOaIObjp42xbSQhM=; b=qfjc2xlo8uvgxRaf0ZVNL6OiAvCY4/dJMsTPmexzpb7RosgcBhVyLpT6GgcdUA7fjH APfjEqC5q9/XoAVGezeNfwZqgt9ZH6GHmUMlU1+Dep0A4v/aimk4YYxjDiDgEdY4VsI1 Egmc9knSIXF8uqS38o6oGrMFRhEXEMe9pYrWygaaHw4zspqpL5V01t62p5LdhE3ZmNc2 W0/eNEsRINt1jQuv7H+KSyPhfjjkpiQW64zDiOARulUgmqtF5TZUtRngH24zKULu8OYk DcDS//aflwtV+VwPNsCJlyujOA5yad3kfTHt9vZjI66fz2sJ7eE9i2Nl7KxZQng/nkbO HeMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dV8eeJVk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3QTHJMOI; 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 nb35-20020a1709071ca300b0078dce6e5cf8si11982320ejc.436.2022.10.19.08.10.21; Wed, 19 Oct 2022 08:10:51 -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=dV8eeJVk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3QTHJMOI; 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 S231625AbiJSPHN (ORCPT + 99 others); Wed, 19 Oct 2022 11:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbiJSPFr (ORCPT ); Wed, 19 Oct 2022 11:05:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 169E0201AE for ; Wed, 19 Oct 2022 07:59:27 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191377; 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=s9ex8lzRPv2fLvIIrbPhNI07gh3HOaIObjp42xbSQhM=; b=dV8eeJVkJqnYI4Tntl1R3l7jZCsG9aTkqgpLBzaep2kY0IpfWQ7AkgrFxuD0Aa3hlViZnt ZZRK5iRTG84EysIrt3V4DA4GmMpvfrR4x9fqaPMgBv4GmPgnJmb14MJFSFl0uFVMr9q71p oSDQNSWKNoB8WJZ8deTwEu0BfGAlvwRs+SgN/tNjuqT+X5J1YgCdw6HanP40357h5g2B4A 6YNAFBkSg15DyUCvdL3htD/Ho6Tf0MCwFafxoCOOfoRR0aeGRkfoFItU243LcFdgK+9JP1 hERXGmQ7msAr35hPgWEk40C+RcKtWqBob98VeE5EsrIjw0MHnYs/pQEyU7BwPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191377; 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=s9ex8lzRPv2fLvIIrbPhNI07gh3HOaIObjp42xbSQhM=; b=3QTHJMOIlL3X1RHmjXFjR8ZUj0J6xFSmlHeAL+ESJ8836arfruLwiyCsruxtdvCScpYlAN bsHq2FAjEV58YVCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 29/38] printk: console_flush_on_panic: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:51 +0206 Message-Id: <20221019145600.1282823-30-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?1747129206665228152?= X-GMAIL-MSGID: =?utf-8?q?1747129206665228152?= 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 0c37ab208395..e478cb92e7ba 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2998,21 +2998,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(); }