From patchwork Mon Nov 7 14:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079868wru; Mon, 7 Nov 2022 06:23:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf7dXz9rjhfbJgrCpQpjaygW0QB0d0C8p0NiPVKciSPUMiuT3FEZk4E/HYMoHQGbBFXqBJ49 X-Received: by 2002:a17:902:788f:b0:188:641b:5372 with SMTP id q15-20020a170902788f00b00188641b5372mr18929617pll.159.1667830984202; Mon, 07 Nov 2022 06:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830984; cv=none; d=google.com; s=arc-20160816; b=DHZSa7ffYl/eHHzrZkiH6NMZY+mXaIPWahsb4115pFm6kljlgwCdjqIp5OZktmX5+4 6kPhk5HcFxIPdT/ZcRWw3inlquvqjAn5n2oyMvm9+cOmHVGUme3NuAJQqWO6Utuu3rG/ 0uebR+ygDrcx+OlxfQ5FpAv7Iu74V6x62OnlN/2G4uAZKu0Es/qWwUJAFCmSaM+MK4Zr Ch0W0Nj9G+iyIfhQml7qVLiEj+QmktL4MIn5t0vfI8ykL8XGLnltpFRP4shkHCjvwAM/ LRMBRCXPSJRHx9wlcqUhXtrNXZOgoGOoO49GPjvMKG0A52HVK8GIQmAePYAWxMGwWcMh iB1w== 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=9ntEDPcr5gl/sGw5Dmqd2ISJ+9btMVLz4NUDJ5QQuQk=; b=AgbTzz92tGNdWGHqVtTURqaMYsUUeIOkatdDxOaDpUx27gN0hGSedzsyxpJKxFGWBL iLHMPApUXLeMu7UcHHrXvl2IMJT+C5S4LT94qQ6XvgxZ4XOjM5shN53DpvHtJef/g64i rpMXfQEL9o2Q5EQsujVSOQCeT+O9Lzmo5y6AoLktJT0PlK7/N9bJIyNd6Y80SJO21ErW BUFqd4BbjA6OY4YCxetsC7TI9FdqxjaabkML4pLuPyG7Bdl8KZCQcZtptAKDQYaSQ/jj UVg0/dXCsC3/8basPdhokQLUvGtWKwKQkMebcJoO3gkJ/+otzLnBIEr+5AnrvCJL4Hp7 Po4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Psrm3reZ; 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 r10-20020a62e40a000000b0053fafd6a529si8971788pfh.24.2022.11.07.06.22.50; Mon, 07 Nov 2022 06:23:04 -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=Psrm3reZ; 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 S232313AbiKGOTm (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbiKGOSB (ORCPT ); Mon, 7 Nov 2022 09:18:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B38191D657 for ; Mon, 7 Nov 2022 06:16:59 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830618; 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=9ntEDPcr5gl/sGw5Dmqd2ISJ+9btMVLz4NUDJ5QQuQk=; b=Psrm3reZr9kysl9Tn1lMLhsfY5qgTs72dx39Z6TUhfscMIiI995txF022+vSD5ubntOOra Lk7d9/OReZRm3NO5slsFYAGRDlkIuIdmKVORh8P/5rOlpDCtj4pI7wgrKOFcDmY5RrytQ7 DMmvCxfhKvJUKTIV1QC/nxp0pouW2jG61Fs+YhHj6VGkMaAdMbELRvMPsZEVnJVKFMBdxK 4LEHJqSO5RYZb/bOVC3ku3CSNenc5aoSwbYarq9jcJU4lavnhL8K8hrNF9aqHLwjE/7VWz 3KMgrY6mHKNv2TutR6wldCW0Yf4+C1QJpoSDN5ICiEx7Lp+0MPN8/+Evd7t1AQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830618; 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=9ntEDPcr5gl/sGw5Dmqd2ISJ+9btMVLz4NUDJ5QQuQk=; b=TK0lbEVUCLYouE80PFUcyh3vWELMzkrRwFJphk6baU7GQtFKsT+iJFiBdoAfONEK2P50Yz ubFP0L2Gq5F/MPAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 39/40] printk: relieve console_lock of list synchronization duties Date: Mon, 7 Nov 2022 15:22:37 +0106 Message-Id: <20221107141638.3790965-40-john.ogness@linutronix.de> In-Reply-To: <20221107141638.3790965-1-john.ogness@linutronix.de> References: <20221107141638.3790965-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?1748847541916576676?= X-GMAIL-MSGID: =?utf-8?q?1748847541916576676?= The console_list_lock provides synchronization for console list and console->flags updates. All call sites that were using the console_lock for this synchronization have either switched to use the console_list_lock or the SRCU list iterator. Remove console_lock usage for console list updates and console->flags updates. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d74e6e609f7d..17765166ac42 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -86,8 +86,8 @@ EXPORT_SYMBOL(oops_in_progress); static DEFINE_MUTEX(console_mutex); /* - * console_sem protects console_list and console->flags updates, and also - * provides serialization for access to the entire console driver system. + * console_sem protects updates to console->seq and console_suspended, + * and also provides serialization for console printing. */ static DEFINE_SEMAPHORE(console_sem); HLIST_HEAD(console_list); @@ -2638,10 +2638,10 @@ static int console_cpu_notify(unsigned int cpu) } /** - * console_lock - lock the console system for exclusive use. + * console_lock - block the console subsystem from printing * - * Acquires a lock which guarantees that the caller has - * exclusive access to the console system and console_list. + * Acquires a lock which guarantees that no consoles will + * be in or enter their write() callback. * * Can sleep, returns nothing. */ @@ -2658,10 +2658,10 @@ void console_lock(void) EXPORT_SYMBOL(console_lock); /** - * console_trylock - try to lock the console system for exclusive use. + * console_trylock - try to block the console subsystem from printing * - * Try to acquire a lock which guarantees that the caller has exclusive - * access to the console system and console_list. + * Try to acquire a lock which guarantees that no consoles will + * be in or enter their write() callback. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2917,10 +2917,10 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove } /** - * console_unlock - unlock the console system + * console_unlock - unblock the console subsystem from printing * - * Releases the console_lock which the caller holds on the console system - * and the console driver list. + * Releases the console_lock which the caller holds to block printing of + * the console subsystem. * * While the console_lock was held, console output may have been buffered * by printk(). If this is the case, console_unlock(); emits @@ -3107,9 +3107,7 @@ void console_stop(struct console *console) { __pr_flush(console, 1000, true); console_list_lock(); - console_lock(); WRITE_ONCE(console->flags, console->flags & ~CON_ENABLED); - console_unlock(); console_list_unlock(); /* @@ -3125,9 +3123,7 @@ EXPORT_SYMBOL(console_stop); void console_start(struct console *console) { console_list_lock(); - console_lock(); WRITE_ONCE(console->flags, console->flags | CON_ENABLED); - console_unlock(); console_list_unlock(); __pr_flush(console, 1000, true); } @@ -3344,7 +3340,6 @@ void register_console(struct console *newcon) * Put this console in the list - keep the * preferred driver at the head of the list. */ - console_lock(); if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; @@ -3358,7 +3353,6 @@ void register_console(struct console *newcon) } else { hlist_add_behind_rcu(&newcon->node, console_list.first); } - console_unlock(); /* * No need to synchronize SRCU here! The caller does not rely @@ -3406,15 +3400,11 @@ static int unregister_console_locked(struct console *console) if (res > 0) return 0; - console_lock(); - /* Disable it unconditionally */ WRITE_ONCE(console->flags, console->flags & ~CON_ENABLED); - if (!console_is_registered_locked(console)) { - console_unlock(); + if (!console_is_registered_locked(console)) return -ENODEV; - } hlist_del_init_rcu(&console->node); @@ -3430,8 +3420,6 @@ static int unregister_console_locked(struct console *console) if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) WRITE_ONCE(console_first()->flags, console_first()->flags | CON_CONSDEV); - console_unlock(); - /* * Ensure that all SRCU list walks have completed. All contexts * must not be able to see this console in the list so that any