Message ID | 20221019145600.1282823-32-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp380907wrs; Wed, 19 Oct 2022 08:13:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76r26HsFFBJrgZVzCsHtFuajAI0MUFcbFc6Y2Wczc9vAbUg2rBUrxMdvPgtM7g5XswM27k X-Received: by 2002:a17:907:608f:b0:78e:1b60:60e2 with SMTP id ht15-20020a170907608f00b0078e1b6060e2mr7241542ejc.382.1666192416847; Wed, 19 Oct 2022 08:13:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192416; cv=none; d=google.com; s=arc-20160816; b=NaZ8iWcMYT+B6CXlsRPwiH8fLWmWJSaCw77Z+oYOWVcEUvD3ptPT4y0ut7R6BgdHzY a5NFzvKSOFhvU3uEJjKD1Ob1FBirjfiSEOnjUGPhALcnKa86PBhYKCcYDzsFECkY9LTU G/7mHRhLc3X+vsZs4epnyRbbM55iABuxhDQ7NjrXssjCYsZAEyLMwFKaL08QEXoEphvs KYcavtq/Vg+iBTYZfhDIsMBoKY6YpiPk45fEhIIIZV+sg6xMwvYWQI9sGNlof2IsJXqD JO+zF5Wa7DMVToerXFttfb4B9bbqIoHTKqzHRnrF6UFVzsXZTTuodDAIJ79IvLrv+9VS 3cKg== 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=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=OVIvGhAy2uiqOVJXj+fVSHQORqEyF/3DyOkrpugn0Zckg0OsUpMpnJwspZwGytw9uo oeG7L7Qqoq6313VZB2aSsvqbJz4YiG8uU/B/c426NKqf7j0+ShW4A2SXbo9xdTD3i4Zs 0s9PuwUNG6YdjE9pVNYO0QoyKYNkjFiRUiDJC0FMzvWizeS5gKk57gFtkHAtM6Q/dnlw iNsMUzy4EUGkRPQN3FUu14QKmdtgPFSwdbUQ9RWf0Db23ZVU76XEFh3Zj4kNRwVsL7As U/aW6Kn3YPBawChsUPZ0ei7IbVrFk0cROEjnryQIl1ZwUIRysANiGSKioS46sdgyYUej WoPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="gEk/56dy"; dkim=neutral (no key) header.i=@linutronix.de; 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 gs19-20020a1709072d1300b00783d5a93880si14237860ejc.503.2022.10.19.08.13.08; Wed, 19 Oct 2022 08:13:36 -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="gEk/56dy"; dkim=neutral (no key) header.i=@linutronix.de; 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 S232209AbiJSPHc (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbiJSPFs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 11:05:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EAA2205CC for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:59:28 -0700 (PDT) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191378; 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=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=gEk/56dyVdJxDt/J7kVgFStcKjvZrGcgIOwQYk0XwQKdK8FsV0Y9dvc9y2PrxlYjtuLQT3 fSJL3lf/BuDtIhc+l6cIXdtEsuXqSJu6EpaxJSdLt15yliOrYrRp1+h7ASkvcNnkIleiOK WZ+Tm++vLlUFSJX9OqsxsxRrd4s4tFKvj3VUqZdNFTfb3Xhi8xUPk8f1Hr6A5xGkJiRoR+ A2sCQpxxeuWpEagnAVMwC/rga5HRcHoOkPCaPZzrNI1r1Nzz5TeNQX3rrKHlEpNHJHjOfV JKp1j4/HoOOs0hPNpCf8W0nyoa5ouc48VUQum9WrHC4viYimonEL+j+iP2L95A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191378; 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=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=Hy5IF74AngV6AgkVUBSfbWawZSbLHUumgqjJi1aW8Es4tyHbxXvp1fWUJHJOyfgmdOtGqL +/HMreGlQbQCBDAQ== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org Subject: [PATCH printk v2 31/38] printk: register_console: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:53 +0206 Message-Id: <20221019145600.1282823-32-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 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747129380124459195?= X-GMAIL-MSGID: =?utf-8?q?1747129380124459195?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
Use srcu console list iteration for console list traversal. Now
the traversal at the beginning of register_console() is safe.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
Comments
On Wed 2022-10-19 17:01:53, John Ogness wrote: > Use srcu console list iteration for console list traversal. Now > the traversal at the beginning of register_console() is safe. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> That said, I think that we could omit this patch. It does not harm. It prevents a crash when iterating the list but it is only small part of the races here. For example, it sets "realcon_enabled" but the list might change before the value is used. Also the later hlist_empty(&console_list) and !console_first->device checks are not secure against each other. The real solution is the introduction of console_list_lock in 33th patch. That patch removes the rcu read lock. From this POV, this patch is just unnecessary churn. Best Regards, Petr
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 410ad9d5649c..809c43e596d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3188,20 +3188,23 @@ void register_console(struct console *newcon) struct console *con; bool bootcon_enabled = false; bool realcon_enabled = false; + int cookie; int err; - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { if (WARN(con == newcon, "console '%s%d' already registered\n", - con->name, con->index)) + con->name, con->index)) { + console_srcu_read_unlock(cookie); return; - } + } - for_each_console(con) { if (con->flags & CON_BOOT) bootcon_enabled = true; else realcon_enabled = true; } + console_srcu_read_unlock(cookie); /* Do not register boot consoles when there already is a real one. */ if (newcon->flags & CON_BOOT && realcon_enabled) {