From patchwork Mon Nov 7 14:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077390wru; Mon, 7 Nov 2022 06:18:51 -0800 (PST) X-Google-Smtp-Source: AMsMyM7AfUDaQ4Soekwd8ItdcwUJdP7Zju2igwAUtSbeTvfSEFkZ1e/oZwHASoBq84x/cK5x2PNU X-Received: by 2002:a17:906:5e14:b0:7ad:cb09:ccbd with SMTP id n20-20020a1709065e1400b007adcb09ccbdmr40884373eju.245.1667830731658; Mon, 07 Nov 2022 06:18:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830731; cv=none; d=google.com; s=arc-20160816; b=KlBvu4m5zm/P55pwFProia4jJl3z+JVaElyskD1wXJGdAESA/Hix//Y+PP8wMHFffl higYzwkCtV59KfTIMx/xfjKEtalSjBaBk2BBvFbNNtlBP7A+D3vESnRlXG9+0ZtwDvr+ XjxjLFgW1OXnxVxI5tN18acqP4lMyTf1A1C7FkxIQ2uCbIx7uv9WqqU/eQ6DjJ7i5ws7 vQVMn6up3nRSAFXbqZozMIx1yucPSG0UDr0vjNj3oD3q/UhjwIzzrsUjNOB8PXezYmg6 cGpRDuxph7pqRo1089raseYT4tZoNDjHegQzNFa6DYCPXoW1YnDCtU6bmSULNfV/yr/8 p6Hw== 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=Hsx1u5F/1CiKvy2GFTZ4ZBzQ1rYlt65AF3SRkTuxsig=; b=IBknCJmel5Ks9PLPZpFR66yYjrP1z20JLfaEZHzuFsQPHJNY2PqPqN6PLW0IcO0eLB otOmz4APb7XwVMD5kPnUgmw9vgK1T5D/WpGDpavHmCDfu9jVKjpwKflzeOxD8SjptTyP vESGlrXRSetsJA/y/6T9mV304gg/WBrUryE5vyf45TIvxJIrxHrXCxeWJT5etscS9+oE Cvto53xsU1BP4sgCLSZhTc7xG3J7x5nGnU+DWNpOH1waJ6KxR9UKmUznXJQw58f+QOI0 FjvMx7L9Hurd4UzYDlhGMDZ0DrDH0KK8GbJEV9ayITWPgjTUwgXyIWJI0Nn07Uy1CAn5 fNXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gGZzuKnO; 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 dm5-20020a170907948500b0078e19e971b2si10802448ejc.915.2022.11.07.06.18.05; Mon, 07 Nov 2022 06:18:51 -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=gGZzuKnO; 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 S231918AbiKGOQq (ORCPT + 99 others); Mon, 7 Nov 2022 09:16:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbiKGOQn (ORCPT ); Mon, 7 Nov 2022 09:16:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F5E19C2A; Mon, 7 Nov 2022 06:16:42 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830600; 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=Hsx1u5F/1CiKvy2GFTZ4ZBzQ1rYlt65AF3SRkTuxsig=; b=gGZzuKnOEmjKPxnbVv/2pWVKTnVFnDA6n6uJGrTaFNs5ZYKCtrOZcWBE0nUslYYBrhiBFC wWXzKY0XCcdwU49sdLis2tWo+CqiLw27jBnhr7tjmFvfKL1ktOzUawjgzEsiy43FowPSV+ 2R9HP522uAqxmgAD/Z92yUxYQeOtbus8a/JAigqgIL9U1loZ5DnW140SsJvb8Ab/i7cokn 48tUsK+EubYJAZr2PCtGbTlP1T+9Z/al4ryuJnrvWsLq9PyqJYttnZWggUbaOgfsRQD3bQ FICdkdqh8pvtpKl3+PBEpjQJ6Ky3mRf3ya0jmwlyBd+Q6GZY4U1uV66yHgUUgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830600; 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=Hsx1u5F/1CiKvy2GFTZ4ZBzQ1rYlt65AF3SRkTuxsig=; b=O0NGeysRpJ2rTQa3JNmWJZLtFDJUBBFvVlOpA/ai0W0bs6FRiXV/Cp6mDv/3mE65r7hslX eRRyPQGXENizajAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org Subject: [PATCH printk v3 01/40] rcu: implement lockdep_rcu_enabled for !CONFIG_DEBUG_LOCK_ALLOC Date: Mon, 7 Nov 2022 15:21:59 +0106 Message-Id: <20221107141638.3790965-2-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?1748847277075414811?= X-GMAIL-MSGID: =?utf-8?q?1748847277075414811?= Provide an implementation for debug_lockdep_rcu_enabled() when CONFIG_DEBUG_LOCK_ALLOC is not enabled. This allows code to check if rcu lockdep debugging is available without needing an extra check if CONFIG_DEBUG_LOCK_ALLOC is enabled. Signed-off-by: John Ogness Acked-by: Paul E. McKenney Reviewed-by: Petr Mladek --- I also sent this patch to Paul as a suggestion. If it is not acceptable, I just need to add an ifdef CONFIG_DEBUG_LOCK_ALLOC into console_list_lock() of patch 21. include/linux/rcupdate.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 08605ce7379d..65178c40ab6f 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -340,6 +340,11 @@ static inline int rcu_read_lock_any_held(void) return !preemptible(); } +static inline int debug_lockdep_rcu_enabled(void) +{ + return 0; +} + #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ #ifdef CONFIG_PROVE_RCU From patchwork Mon Nov 7 14:16:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077360wru; Mon, 7 Nov 2022 06:18:49 -0800 (PST) X-Google-Smtp-Source: AMsMyM4DY4V/v45wGspQ5QJIVI9epViVN917+rh26OBFI+VUaQjDZmpeL5Jw7nX8As5RkMPehdKb X-Received: by 2002:a17:907:25c7:b0:77b:c193:9230 with SMTP id ae7-20020a17090725c700b0077bc1939230mr47541902ejc.316.1667830723990; Mon, 07 Nov 2022 06:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830723; cv=none; d=google.com; s=arc-20160816; b=muCPys+oVfSvlM6dpri/AV7RVyYCNh5o3/zIU2yEWmfaFgLPUOqv4yhftwnI5zDmCK JvG2DqXDDiyybHWEpUV9T9R4eFB/snv4tQs8YwEIyrAd/rnWzJsBcZ0FYM8cG/Mye2jv 9julYvx+VsRJMn+iRr8Qs5+ZhldEE3hTqQEhRoA86jdkyQH1pYyNluwOroXMP6kL5NhF TSNmEUiivcrc9+p3YBPegbSzXDAgUPDHd5O6D9vFc+LbBoBpMWzSmR8QRll+2X595XnR PaZDicOmKlfLbVGP2tu2dzmLbP/3GH8i+ts/Ok61+jn+5QiQCVeMvRByhiTuAF8z3RRp RHdQ== 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=dQqN7WWFfeRk0rEfRkWVolPjdsk8N//2uvtsWSdUdzA=; b=cFjLCl2o7GfRMWxKhKU+M+jqzInxoTGgZpBtGhJVGen8sUHnNns3nwFIV4oKOw/KS7 j41qXLPQWTVDNvbdpCzPcg5QSMhdRXd4uiwzU+x6OX/H8YakRMvTOeKuz34yf7AUD7nT EJPSKFGXsHhJ6kwuOYYDSpRGjNJ+5zLwbd/F7uYblHcxfoG0+/SfimNIhbBkblse+KVd CG0YBAU2qPjHiHjUM0yvRXJroacuEtJdsUlZVsq7FEvU4o7izht5OG73DsxKm8Z6EFva ZsSaIYqHG0OPZB73I35KkuB5Duja4IiwGEGOOR8Tacar4LsRpzkIdssAmQzt9wdbFi44 FX8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1AfBH1Y1; 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 kq2-20020a170906abc200b0078ddc074afdsi6850364ejb.577.2022.11.07.06.18.17; Mon, 07 Nov 2022 06:18:43 -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=1AfBH1Y1; 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 S232180AbiKGOQw (ORCPT + 99 others); Mon, 7 Nov 2022 09:16:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbiKGOQn (ORCPT ); Mon, 7 Nov 2022 09:16:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 187F71CFF6; Mon, 7 Nov 2022 06:16:42 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830601; 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=dQqN7WWFfeRk0rEfRkWVolPjdsk8N//2uvtsWSdUdzA=; b=1AfBH1Y1iFfphLxwLDzchu0JtFa4StD8+vHmibnAtoR7r0d9yVZ7XudeFA2hxeTHvPJNO1 ofQxZT3QO7S3AIt5J6jw1rTh+uGC+ykQ2zYmR+fMAtYm0/E/+eRNResYTvMXDWeXtDpBar RhKMrMIijaLU7Ul+Ipvhji9wlW6zaf4LkCuyg9BfVvQ86fLD3DZvTVIe3aP5cl9i7e1Ysy pPuGSq0stzuTH4IF+pPHEL72It1Z2+S8gqw5e/hO3s7QnrkrXM3RZ19pIP8Lh/W5WzcknX 74CdrAlyEh6Swq3T12qX0WpMC7JL0DFBPsUAxGiCsJktqmJZ7DgpuMEBJysaJA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830601; 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=dQqN7WWFfeRk0rEfRkWVolPjdsk8N//2uvtsWSdUdzA=; b=tjQDm3eXUbLBxw7+a927SUadjeYu0UPY5exQDo0Y3czHli8azPa+URgzRubTdplWFAe0Jt zSX0xI8ffcVGXtCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v3 02/40] serial: kgdboc: Lock console list in probe function Date: Mon, 7 Nov 2022 15:22:00 +0106 Message-Id: <20221107141638.3790965-3-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?1748847269115415315?= X-GMAIL-MSGID: =?utf-8?q?1748847269115415315?= From: Thomas Gleixner Unprotected list walks are not necessarily safe. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Douglas Anderson Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek Reviewed-by: Daniel Thompson --- drivers/tty/serial/kgdboc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 7aa37be3216a..e76f0186c335 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -193,6 +193,7 @@ static int configure_kgdboc(void) if (!p) goto noconfig; + console_lock(); for_each_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) == p && @@ -201,6 +202,7 @@ static int configure_kgdboc(void) break; } } + console_unlock(); kgdb_tty_driver = p; kgdb_tty_line = tty_line; From patchwork Mon Nov 7 14:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078219wru; Mon, 7 Nov 2022 06:20:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM7NhTGPlYDQQQuadkzzXBWxAgvuhcqDF37LRk3jqX4iaAAZAr5pnrDMDl2G1+uY9uIyccAK X-Received: by 2002:a17:902:7b98:b0:187:4889:7dcb with SMTP id w24-20020a1709027b9800b0018748897dcbmr29294937pll.79.1667830813075; Mon, 07 Nov 2022 06:20:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830813; cv=none; d=google.com; s=arc-20160816; b=bjKSUq+mSAWjW7ktLd2wGcGJBT+0CHALlodgxk8ui6nBdtqx2WLF1ehoJ+MhvBcn4S +2yGKsA4l8JwN2VO1uEzYxmOwOLAQMskNLnMq9jWTSLGm9XzltahIIeOz34Fq3PGBJDa fk4/Xd5rnlZgKQPhpdY+tvJt8IKUQD6WgcG3LRCqpun3J9QFnSicPXlS0h1zv0/EkeFI y369s1oQw4H4mniG+3VDfEx84uwCSYr5PQfJyNHxoRgdUBy5wf8wv+/hPpA8+A9USeYB Zla/Tn4gDHroaRl8DRozISkSrCnZ6eqG3IvZtg/XJFjSof5+hXJSZdBoNX12r0aR8Iyg Tc6g== 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=T3r0mxEJG1pEsgHAPMDMvdvodlCRUQmzeL9f0GYsAbQ=; b=A+cf5fCnWMYnE9G4be6NMUJ9BtU852wKvYjbRFpXPTLsJNpStiloTPrhpNqYYzZVQQ 3UogR+/VDSVMoMkb+sEMHUkqwidvXwDfyI0PBFROIWa4eE9HOx5iWWWvaqziaImx0S8H nD0+TxwCDzEmZIn8zqMDGYd8bit/TUPt310XgiBYucD2AvfyZo6aFZA22BqPcG3jr0Pb 6BYlJdtR6RtqABXKWmEH7F74SnLdWEs8Ob3wwF7Ab59x3iLb6w90QpK/km98AOxfcYKY G1iA+EzpJnSTwsTnMwpKbNbV7DVzLPKRVjMHTFNxDObfF9lkVP3bDn2B5McYaBWurQkz 3Lsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=j1VHUhY8; 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 eb19-20020a056a004c9300b0056c231e4447si9234636pfb.198.2022.11.07.06.19.58; Mon, 07 Nov 2022 06:20:13 -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=j1VHUhY8; 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 S232179AbiKGOQy (ORCPT + 99 others); Mon, 7 Nov 2022 09:16:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiKGOQo (ORCPT ); Mon, 7 Nov 2022 09:16:44 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51D0C1D0C6; Mon, 7 Nov 2022 06:16:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830602; 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=T3r0mxEJG1pEsgHAPMDMvdvodlCRUQmzeL9f0GYsAbQ=; b=j1VHUhY8eCYnCYEX+76EfAc1mp+xjsbKxH5Dw/rJT4iPgu7Tm7o/pDjQjiv5B4d8NWcT34 wPho9GcNbpyOOXaWVaA3uRikQPC+t/BloatelnThmMPRToc7Pu28dyzHf96yGsm+h4Q7Tv +qs9HP28Tmo1Vp1LL4taVNOJjD05Hy4FCKza5aKWPhwsGfANl/AnfwwhvHbGXeHm82GzhL FMjYX1EiPkhO2EHvhVFdYg71CmEUAro6zPBSOIUB76SWt5/EdPK/SB7FkqegwhSgkzKUyt MbyL3jUhBH9SiRzwmCDVV0yWS9MHtRiTmGLTKbD0pXGeAyz7m4C4BfSDwc6/8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830602; 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=T3r0mxEJG1pEsgHAPMDMvdvodlCRUQmzeL9f0GYsAbQ=; b=da3YoFgRS7AjRVL+TFlvyJSDJKZDRJoCFJov+D1UgwX3TrvV5NiMCQ4U54sldvdMsxGoCg 4St+6etVTwEXxCBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org, John Ogness Subject: [PATCH printk v3 03/40] printk: Convert console_drivers list to hlist Date: Mon, 7 Nov 2022 15:22:01 +0106 Message-Id: <20221107141638.3790965-4-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?1748847362236462493?= X-GMAIL-MSGID: =?utf-8?q?1748847362236462493?= From: Thomas Gleixner Replace the open coded single linked list with a hlist so a conversion to SRCU protected list walks can reuse the existing primitives. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 3 +- include/linux/console.h | 8 ++-- kernel/printk/printk.c | 101 ++++++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index dfe6ce3505ce..cf2e0788f9c7 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -74,8 +74,9 @@ static void *c_start(struct seq_file *m, loff_t *pos) static void *c_next(struct seq_file *m, void *v, loff_t *pos) { struct console *con = v; + ++*pos; - return con->next; + return hlist_entry_safe(con->node.next, struct console, node); } static void c_stop(struct seq_file *m, void *v) diff --git a/include/linux/console.h b/include/linux/console.h index 8c1686e2c233..7b5f21f9e469 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,6 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 #include +#include #include struct vc_data; @@ -154,14 +155,16 @@ struct console { u64 seq; unsigned long dropped; void *data; - struct console *next; + struct hlist_node node; }; +extern struct hlist_head console_list; + /* * for_each_console() allows you to iterate on each console */ #define for_each_console(con) \ - for (con = console_drivers; con != NULL; con = con->next) + hlist_for_each_entry(con, &console_list, node) extern int console_set_on_cmdline; extern struct console *early_console; @@ -174,7 +177,6 @@ enum con_flush_mode { extern int add_preferred_console(char *name, int idx, char *options); extern void register_console(struct console *); extern int unregister_console(struct console *); -extern struct console *console_drivers; extern void console_lock(void); extern int console_trylock(void); extern void console_unlock(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e4f1e7478b52..e6f0832e71f0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -79,13 +79,12 @@ int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); /* - * console_sem protects the console_drivers list, and also - * provides serialisation for access to the entire console - * driver system. + * console_sem protects console_list and console->flags updates, and also + * provides serialization for access to the entire console driver system. */ static DEFINE_SEMAPHORE(console_sem); -struct console *console_drivers; -EXPORT_SYMBOL_GPL(console_drivers); +HLIST_HEAD(console_list); +EXPORT_SYMBOL_GPL(console_list); /* * System may need to suppress printk message under certain @@ -2556,7 +2555,7 @@ static int console_cpu_notify(unsigned int cpu) * console_lock - lock the console system for exclusive use. * * Acquires a lock which guarantees that the caller has - * exclusive access to the console system and the console_drivers list. + * exclusive access to the console system and console_list. * * Can sleep, returns nothing. */ @@ -2576,7 +2575,7 @@ EXPORT_SYMBOL(console_lock); * console_trylock - try to lock the console system for exclusive use. * * Try to acquire a lock which guarantees that the caller has exclusive - * access to the console system and the console_drivers list. + * access to the console system and console_list. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2940,11 +2939,20 @@ 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; u64 seq; seq = prb_first_valid_seq(prb); - for_each_console(c) + /* + * 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) c->seq = seq; } console_unlock(); @@ -3081,6 +3089,9 @@ static void try_enable_default_console(struct console *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) +#define console_first() \ + hlist_entry(console_list.first, struct console, node) + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -3140,8 +3151,8 @@ void register_console(struct console *newcon) * flag set and will be first in the list. */ if (preferred_console < 0) { - if (!console_drivers || !console_drivers->device || - console_drivers->flags & CON_BOOT) { + if (hlist_empty(&console_list) || !console_first()->device || + console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); } } @@ -3169,20 +3180,22 @@ void register_console(struct console *newcon) } /* - * Put this console in the list - keep the - * preferred driver at the head of the list. + * Put this console in the list - keep the + * preferred driver at the head of the list. */ console_lock(); - if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) { - newcon->next = console_drivers; - console_drivers = newcon; - if (newcon->next) - newcon->next->flags &= ~CON_CONSDEV; - /* Ensure this flag is always set for the head of the list */ + if (hlist_empty(&console_list)) { + /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; + hlist_add_head(&newcon->node, &console_list); + + } else if (newcon->flags & CON_CONSDEV) { + /* Only the new head can have CON_CONSDEV set. */ + console_first()->flags &= ~CON_CONSDEV; + hlist_add_head(&newcon->node, &console_list); + } else { - newcon->next = console_drivers->next; - console_drivers->next = newcon; + hlist_add_behind(&newcon->node, console_list.first); } newcon->dropped = 0; @@ -3209,16 +3222,18 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && !keep_bootcon) { - for_each_console(con) + struct hlist_node *tmp; + + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (con->flags & CON_BOOT) unregister_console(con); + } } } EXPORT_SYMBOL(register_console); int unregister_console(struct console *console) { - struct console *con; int res; con_printk(KERN_INFO, console, "disabled\n"); @@ -3229,32 +3244,30 @@ int unregister_console(struct console *console) if (res > 0) return 0; - res = -ENODEV; console_lock(); - if (console_drivers == console) { - console_drivers=console->next; - res = 0; - } else { - for_each_console(con) { - if (con->next == console) { - con->next = console->next; - res = 0; - break; - } - } + + /* Disable it unconditionally */ + console->flags &= ~CON_ENABLED; + + if (hlist_unhashed(&console->node)) { + console_unlock(); + return -ENODEV; } - if (res) - goto out_disable_unlock; + hlist_del_init(&console->node); /* + * * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. + * + * + * The above makes no sense as there is no guarantee that the next + * console has any device attached. Oh well.... */ - if (console_drivers != NULL && console->flags & CON_CONSDEV) - console_drivers->flags |= CON_CONSDEV; + if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) + console_first()->flags |= CON_CONSDEV; - console->flags &= ~CON_ENABLED; console_unlock(); console_sysfs_notify(); @@ -3262,12 +3275,6 @@ int unregister_console(struct console *console) res = console->exit(console); return res; - -out_disable_unlock: - console->flags &= ~CON_ENABLED; - console_unlock(); - - return res; } EXPORT_SYMBOL(unregister_console); @@ -3317,10 +3324,11 @@ void __init console_init(void) */ static int __init printk_late_init(void) { + struct hlist_node *tmp; struct console *con; int ret; - for_each_console(con) { + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; @@ -3340,6 +3348,7 @@ static int __init printk_late_init(void) unregister_console(con); } } + ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); WARN_ON(ret < 0); From patchwork Mon Nov 7 14:16:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078306wru; Mon, 7 Nov 2022 06:20:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf6optLUNs94g4piid7nBdHNmyutMDsZf6JuCG211iaAPwnZ4njWx2XSBj49boIOm6kldJ54 X-Received: by 2002:a17:902:b10d:b0:188:7ffa:4680 with SMTP id q13-20020a170902b10d00b001887ffa4680mr6195675plr.156.1667830821875; Mon, 07 Nov 2022 06:20:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830821; cv=none; d=google.com; s=arc-20160816; b=CZERH1v8j5QqlW41n674gM17EBMtHDNDQJi3K9q8ym5Pfc4JXplpIMqtBdgv+g+m9V kQoXeun/P4apUvb0kicRhdVDCdjrE1bki9+7d0ZdZt976aPGVarAfpJBOhhEr+KGc0G8 ZXWwzZHQCPO+PQwGvnvkAWesLFtaDpohkfpksipvu9+7n8J9wigBDq2BJsKNsBGsudGI ZwjF/DU89bGNUxlHMtFsfOTAChpyBzPWYaoO5Cp4wiEuUGINrtt6OqFqzdhWJZSMzdK8 SgAc5hYKcdlRZPXDe0jCWGknlyITxi1vNWEF67ign4eNQLMIhnhqLL/3G2GpKyMoyOBZ SyTQ== 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=lrbpCQycb+/taI/uRVaujF070w6Ca/Xi2eD/NxYFOUA=; b=yuThyzB3zg5Z/ZPu2ZbT3wNcX6zqCbXgptQbhpTBD1AUGt3SswPXJrsJLXp4ysClvV Vy5v7iPrOrP2vOYM5aSlGAf3MWDaixp25ofY/tbYxt7yrk3tliyOvak5zbGQQczNxZsB aryAxJNUlk39b3tCD297ceot1gwaxLJ556Cpa7HepLzK2+fvMcxqhVKMjjr7Ml0eU1ho AMDtNvB6B1RUjGxtWMvK9peQYDrvKr9jyx80h6jFd43UZtR3JH3els8enPafS2U53VIe k2QBY68Oolj1UL34FGCiz/aZidRkmwJvlZ/bwnGoMmSsNcYJsUbPF1vBrZF/QjimLyCm U/Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HqvME5Z0; dkim=neutral (no key) header.i=@linutronix.de header.b=A8vINHDp; 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 a10-20020a170902b58a00b00186dcc389a8si9367624pls.329.2022.11.07.06.20.08; Mon, 07 Nov 2022 06:20:21 -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=HqvME5Z0; dkim=neutral (no key) header.i=@linutronix.de header.b=A8vINHDp; 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 S232243AbiKGORG (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbiKGOQp (ORCPT ); Mon, 7 Nov 2022 09:16:45 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98061D0DC for ; Mon, 7 Nov 2022 06:16:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830602; 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=lrbpCQycb+/taI/uRVaujF070w6Ca/Xi2eD/NxYFOUA=; b=HqvME5Z0n3Sq4uIE7mKgJdkv76kPDLd7hmC4sMytV1WdFRZz425hUdrdzhzIkrXq9WCVVj fskriOgAcC/vf3C/in8fRBYof57CsewAT5P3F+Iab6xXAvCT9UUTghXFBBc42+EjxKHINh SdgtUtF5YrQaXy9E+/kKVN7yRtiys93S2dOzaWg8wBaiFuKSOE+TC2w+rwhBfIPY6wXZky fOiIeEI8lkfA6przjc9IGVCUXUfxEuDQpVIP+A9NmT2lfp+3Vr09HXn61OS+3MEG9650RO LKTUSBM+9EdZSZPRfQC7gdjrN2KYNVgn3EtECEJ4ObWJsKp3Lh4xZdmf1Wdz2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830602; 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=lrbpCQycb+/taI/uRVaujF070w6Ca/Xi2eD/NxYFOUA=; b=A8vINHDp/X57Dv+RlcmMQXpe2//s+tDplkRKnVNA7KZvTtPQVciNTfI8YFjookeUoNft3N 9Jbx3/pBS2cnf9Bg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Miguel Ojeda , Greg Kroah-Hartman , "Paul E . McKenney" Subject: [PATCH printk v3 04/40] printk: Prepare for SRCU console list protection Date: Mon, 7 Nov 2022 15:22:02 +0106 Message-Id: <20221107141638.3790965-5-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?1748847371361042258?= X-GMAIL-MSGID: =?utf-8?q?1748847371361042258?= Provide an NMI-safe SRCU protected variant to walk the console list. Note that all console fields are now set before adding the console to the list to avoid the console becoming visible by SCRU readers before being fully initialized. This is a preparatory change for a new console infrastructure which operates independent of the console BKL. Suggested-by: Thomas Gleixner Signed-off-by: John Ogness Acked-by: Miguel Ojeda Reviewed-by: Paul E. McKenney Reviewed-by: Petr Mladek --- .clang-format | 1 + include/linux/console.h | 28 ++++++++++++- kernel/printk/printk.c | 87 ++++++++++++++++++++++++++++++++++------- 3 files changed, 100 insertions(+), 16 deletions(-) diff --git a/.clang-format b/.clang-format index 1247d54f9e49..04a675b56b57 100644 --- a/.clang-format +++ b/.clang-format @@ -222,6 +222,7 @@ ForEachMacros: - 'for_each_component_dais' - 'for_each_component_dais_safe' - 'for_each_console' + - 'for_each_console_srcu' - 'for_each_cpu' - 'for_each_cpu_and' - 'for_each_cpu_not' diff --git a/include/linux/console.h b/include/linux/console.h index 7b5f21f9e469..f4f0c9523835 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,7 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 #include -#include +#include #include struct vc_data; @@ -158,8 +158,34 @@ struct console { struct hlist_node node; }; +#ifdef CONFIG_DEBUG_LOCK_ALLOC +extern bool console_srcu_read_lock_is_held(void); +#else +static inline bool console_srcu_read_lock_is_held(void) +{ + return 1; +} +#endif + +extern int console_srcu_read_lock(void); +extern void console_srcu_read_unlock(int cookie); + extern struct hlist_head console_list; +/** + * for_each_console_srcu() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * Although SRCU guarantees the console list will be consistent, the + * struct console fields may be updated by other CPUs while iterating. + * + * Requires console_srcu_read_lock to be held. Can be invoked from + * any context. + */ +#define for_each_console_srcu(con) \ + hlist_for_each_entry_srcu(con, &console_list, node, \ + console_srcu_read_lock_is_held()) + /* * for_each_console() allows you to iterate on each console */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e6f0832e71f0..173f46a29252 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -85,6 +85,7 @@ EXPORT_SYMBOL(oops_in_progress); static DEFINE_SEMAPHORE(console_sem); HLIST_HEAD(console_list); EXPORT_SYMBOL_GPL(console_list); +DEFINE_STATIC_SRCU(console_srcu); /* * System may need to suppress printk message under certain @@ -104,6 +105,13 @@ static struct lockdep_map console_lock_dep_map = { }; #endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC +bool console_srcu_read_lock_is_held(void) +{ + return srcu_read_lock_held(&console_srcu); +} +#endif + enum devkmsg_log_bits { __DEVKMSG_LOG_BIT_ON = 0, __DEVKMSG_LOG_BIT_OFF, @@ -219,6 +227,32 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ +/** + * console_srcu_read_lock - Register a new reader for the + * SRCU-protected console list + * + * Use for_each_console_srcu() to iterate the console list + * + * Context: Any context. + */ +int console_srcu_read_lock(void) +{ + return srcu_read_lock_nmisafe(&console_srcu); +} +EXPORT_SYMBOL(console_srcu_read_lock); + +/** + * console_srcu_read_unlock - Unregister an old reader from + * the SRCU-protected console list + * + * Counterpart to console_srcu_read_lock() + */ +void console_srcu_read_unlock(int cookie) +{ + srcu_read_unlock_nmisafe(&console_srcu, cookie); +} +EXPORT_SYMBOL(console_srcu_read_unlock); + /* * Helper macros to handle lockdep when locking/unlocking console_sem. We use * macros instead of functions so that _RET_IP_ contains useful information. @@ -2989,6 +3023,14 @@ void console_stop(struct console *console) console_lock(); console->flags &= ~CON_ENABLED; console_unlock(); + + /* + * Ensure that all SRCU list walks have completed. All contexts must + * be able to see that this console is disabled so that (for example) + * the caller can suspend the port without risk of another context + * using the port. + */ + synchronize_srcu(&console_srcu); } EXPORT_SYMBOL(console_stop); @@ -3179,6 +3221,17 @@ void register_console(struct console *newcon) newcon->flags &= ~CON_PRINTBUFFER; } + newcon->dropped = 0; + if (newcon->flags & CON_PRINTBUFFER) { + /* Get a consistent copy of @syslog_seq. */ + mutex_lock(&syslog_lock); + newcon->seq = syslog_seq; + mutex_unlock(&syslog_lock); + } else { + /* Begin with next message. */ + newcon->seq = prb_next_seq(prb); + } + /* * Put this console in the list - keep the * preferred driver at the head of the list. @@ -3187,28 +3240,24 @@ void register_console(struct console *newcon) if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); } else if (newcon->flags & CON_CONSDEV) { /* Only the new head can have CON_CONSDEV set. */ console_first()->flags &= ~CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); } else { - hlist_add_behind(&newcon->node, console_list.first); - } - - newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { - /* Get a consistent copy of @syslog_seq. */ - mutex_lock(&syslog_lock); - newcon->seq = syslog_seq; - mutex_unlock(&syslog_lock); - } else { - /* Begin with next message. */ - newcon->seq = prb_next_seq(prb); + hlist_add_behind_rcu(&newcon->node, console_list.first); } console_unlock(); + + /* + * No need to synchronize SRCU here! The caller does not rely + * on all contexts being able to see the new console before + * register_console() completes. + */ + console_sysfs_notify(); /* @@ -3254,7 +3303,7 @@ int unregister_console(struct console *console) return -ENODEV; } - hlist_del_init(&console->node); + hlist_del_init_rcu(&console->node); /* * @@ -3269,6 +3318,14 @@ int unregister_console(struct console *console) 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 + * exit/cleanup routines can be performed safely. + */ + synchronize_srcu(&console_srcu); + console_sysfs_notify(); if (console->exit) From patchwork Mon Nov 7 14:16:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078360wru; Mon, 7 Nov 2022 06:20:27 -0800 (PST) X-Google-Smtp-Source: AMsMyM5WZwjGGaXqRgZ6dIpC8svP2HCMCzFYlydJQeRsitS0z0wkJSLtH6HArC1AkOpEb7gMxWr5 X-Received: by 2002:a63:5a41:0:b0:430:673e:1e13 with SMTP id k1-20020a635a41000000b00430673e1e13mr44494214pgm.435.1667830826671; Mon, 07 Nov 2022 06:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830826; cv=none; d=google.com; s=arc-20160816; b=YOXm3JR/gGjrJX3ablXDJPlRS5NV2hphDikMW6HO/Y3pOBvu5Z3RaehOIqny14xC4J LT7yKU1eYQDoSPMGxLmWf2J574jYZ8/FbIZGrIyBhEwRqTit+dFu2syGphkFVAl1v6qz 1u5QiRy1l+Rrev/kKv09W+vuKakSW2L0CsLWOYAi1CUAXfMHoRpOl7eVUAl4gtzX2FQu /W5ZjnSK8L4sfUeByqTs+WD8A9IKvfpVeGvqN9z0jgU1q43zlndJuZ6VbBNOQpWPvkMu EYkDq73PuTqmNmIY1eSZHiWMFn5cn1VsIpSaRzwBbAju3VNEHoUoOwVBdtS7yMqgyWLh dLlQ== 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=QwxZkT00jn7AKTWqevvdMwt3OrfkYTNuT2xBM9M5cy7VK3H5CTWOTTp8pu9cAIeu1N MgsgXT7jOOHvrntb1DdS2VzfoSP1YpmFAb5egM4anurpcXKN3XqxqLAaN/UoX8kkHEvB 5rw2w9EWK02YrxIb084ZMBcVB0qGhkfWlKMeoIWZebuld3+u5fyRnmxMcrLd72gwaOa8 NL9FUANmfZcfRwz/5hxYOP3P+qCE4veNEOuFpCTZi7Wo3E4L3B1CvAw325gxzN4dnV8a 92suq44QprhjJGD2bu/aQ9sP2NeN3zKJN2c7Z+9fkGD/2lCDzJ8a54A0dWEnFzg7XAW+ KGpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fjFDBOuE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=i2mJNvHh; 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 l70-20020a638849000000b0045cbd4e43b8si8136574pgd.511.2022.11.07.06.20.11; Mon, 07 Nov 2022 06:20:26 -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=fjFDBOuE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=i2mJNvHh; 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 S231809AbiKGORP (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbiKGOQq (ORCPT ); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CC71CFF6 for ; Mon, 7 Nov 2022 06:16:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830602; 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=fjFDBOuExj6AkzrBAgwGsZMWcQG7o8pcYxBeiRO9Hv5/MET+Urn/iU0k73K8KQVlMlUNpM FY+dleU7ocJj0ji81DsotW8vyOMG0D5M1iG7cmDJAaecNz7sH9SRPGHJJCmZcQBb+npM5o lJ0doKia/xvyGmtxJ5kwiPyMJtZqOe0h2Z2CxI35d7hqo2qKdthMC3yWtHOGMY88eLckEs 1Tz8RmJZ/H8/5654j9UFU19pDfIJWfawwbZHcQB+sptO2JpX6Oamb+OWlXEAFBWqGuOX3P n7AnRlDjpaJEB/ZcSIAtzUA/p3z/pTCXdt5NGwFbE/98sWE93QhtL7XkWfWFEQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830602; 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=i2mJNvHheKNDa4WvDo4khjz/Y4qbCG/JXNJubnpudAH/q8vUufrKnKB9RlhTArcA9d3SNr EtHCyjWatvPZE0AQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 05/40] printk: fix setting first seq for consoles Date: Mon, 7 Nov 2022 15:22:03 +0106 Message-Id: <20221107141638.3790965-6-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?1748847376993271412?= X-GMAIL-MSGID: =?utf-8?q?1748847376993271412?= It used to be that all consoles were synchronized with respect to which message they were printing. After commit a699449bb13b ("printk: refactor and rework printing logic"), all consoles have their own @seq for tracking which message they are on. That commit also changed how the initial sequence number was chosen. Instead of choosing the next non-printed message, it chose the sequence number of the next message that will be added to the ringbuffer. That change created a possibility that a non-boot console taking over for a boot console might skip messages if the boot console was behind and did not have a chance to catch up before being unregistered. Since it is not possible to know which boot console a console is taking over, use the lowest @seq of all the enabled boot consoles. If no boot consoles are available/enabled, begin with the next message that will be added to the ringbuffer. Also, since boot consoles are meant to be used at boot time, handle them the same as CON_PRINTBUFFER to ensure that no initial messages are skipped. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 173f46a29252..8974523f3107 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3222,14 +3222,26 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { + if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { /* Get a consistent copy of @syslog_seq. */ mutex_lock(&syslog_lock); newcon->seq = syslog_seq; mutex_unlock(&syslog_lock); } else { - /* Begin with next message. */ + /* Begin with next message added to ringbuffer. */ newcon->seq = prb_next_seq(prb); + + /* + * If an enabled boot console is not caught up, start with + * that message instead. That boot console will be + * unregistered shortly and may be the same device. + */ + for_each_console(con) { + if ((con->flags & (CON_BOOT | CON_ENABLED)) == (CON_BOOT | CON_ENABLED) && + con->seq < newcon->seq) { + newcon->seq = con->seq; + } + } } /* From patchwork Mon Nov 7 14:16:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077905wru; Mon, 7 Nov 2022 06:19:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ZXX0VzfZoJtEWvu/X4fbjDdyW4oPekfiETzCChCmXLp4W1pRuOV849+0ttt/LyMJ+RWiQ X-Received: by 2002:a17:907:3f9d:b0:7ae:587e:73aa with SMTP id hr29-20020a1709073f9d00b007ae587e73aamr10313292ejc.289.1667830780880; Mon, 07 Nov 2022 06:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830780; cv=none; d=google.com; s=arc-20160816; b=Jlp4VzuiRZhqrW20gIZjAtIMPdpuxNLToWVuaN4gtz/yeY+Pt9KSbhsFKD9LR3Osgx eyO6MBrRCsmWW2y4dRbsPfKGQ+mqubjhpfBOu6SmQbaKhCqzXZKyaJVkstM818RdOuLf +44g8cjrx+t4Vjg88Y9NZbHmr+NNvnyapiUCMHGgHYaiC8q0bxIQA4nJSo7pXdAyCE3w h/TXTUUUt5rlLWrIZA9jGXrXmP4g+k9biI+mqb/hhpME9En52c6uX7ZJvgV1FuLsHrLS sKSTle5bZEhH/XazZTsZxlU8+wQIxGY80Nbfd5jzg0Z3q0YJsV3KTeMWq6phc9/EFG+8 x9Aw== 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=6/paKzOHPdL7LtYxjVc5vEnqdv9ZQ5lgTtMtTQHWNnQ=; b=FsUlslfnAttvJwLfU6nzPTLKTV3ildKdE2mn/uA6l3wReN9+mky8KhWegEDkS5iImM jQgnB0qpR6N+PfRqPpbGQwcbm5tUBgdBXBN1iChTjcL5m7c3VHLIfR2rj/OEoTUpnAyg YT9Xyea5ZviHi4+1R9bDGL8lDolz4oDxgftm/B6SQJ+CipzzyUJ06JV2oS2EDRplgJIN CudlCe7MTMN5YBKDDtp5EMGTVCUdPpaxaciKBJGH7Ibu0qxWpGYXJM11ROpkM7vk1rBc rp5bJFufjGE5d7pmzAeRY7lKQ2/z70Az8Snbs4wwAKLyfIYlEBvgSS15E4HnWDwNhd9x o87A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kgfOV8TY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vWS9R1RB; 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 w18-20020a50fa92000000b00461d5afea01si8286588edr.165.2022.11.07.06.19.16; Mon, 07 Nov 2022 06:19:40 -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=kgfOV8TY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vWS9R1RB; 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 S231689AbiKGORK (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbiKGOQq (ORCPT ); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC151CFF1 for ; Mon, 7 Nov 2022 06:16:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830603; 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=6/paKzOHPdL7LtYxjVc5vEnqdv9ZQ5lgTtMtTQHWNnQ=; b=kgfOV8TY/LzEY5UzgRdT3BlvUS4J1DgI43rtqiBP9Hat6fe0tbknUSa2d0RAAIOO+gTscI 9gmZ/Oe5VTwP6nr6aI5cirDD8ru3D4TaVVzQzcKFr/nXfUWAbIm76g0tG7oACi1zAypM21 wSACcAaMqT+08PtymJMHqyyKDvN6rE0eGaya9a2kYmWdI+WL8S/v3bS5NYBqugmdS4eUgw 2PBFr7mml7AoQQIqx6L9iXf/WfFvtkQbEyOJtpgmt4m1tvzCh+5Ks6dDOcremWNzfpqzKp 9uTWvROhtIUwlxLIz7tHhRdcrNZtybOB6R8xqouGyYP+HcGLH3dnVTezBOcTHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830603; 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=6/paKzOHPdL7LtYxjVc5vEnqdv9ZQ5lgTtMtTQHWNnQ=; b=vWS9R1RBOLVJYj2nIE+UOu47k28bDRXb6conZQphvOjHz1Y9ErtSJTCEnA7Fn3BAEIUYkJ oQTGziecwCDdfmAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH printk v3 06/40] um: kmsg_dump: only dump when no output console available Date: Mon, 7 Nov 2022 15:22:04 +0106 Message-Id: <20221107141638.3790965-7-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?1748847328428193040?= X-GMAIL-MSGID: =?utf-8?q?1748847328428193040?= The initial intention of the UML kmsg_dumper is to dump the kernel buffers to stdout if there is no console available to perform the regular crash output. However, if ttynull was registered as a console, no crash output was seen. Commit e23fe90dec28 ("um: kmsg_dumper: always dump when not tty console") tried to fix this by performing the kmsg_dump unless the stdio console was behind /dev/console or enabled. But this allowed kmsg dumping to occur even if other non-stdio consoles will output the crash output. Also, a console being the driver behind /dev/console has nothing to do with a crash scenario. Restore the initial intention by dumping the kernel buffers to stdout only if a non-ttynull console is registered and enabled. Also add detailed comments so that it is clear why these rules are applied. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/um/kernel/kmsg_dump.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 0224fcb36e22..40abf1e9ccb1 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -17,13 +17,22 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, unsigned long flags; size_t len = 0; - /* only dump kmsg when no console is available */ + /* + * If no consoles are available to output crash information, dump + * the kmsg buffer to stdout. + */ + if (!console_trylock()) return; for_each_console(con) { - if(strcmp(con->name, "tty") == 0 && - (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) { + /* + * The ttynull console and disabled consoles are ignored + * since they cannot output. All other consoles are + * expected to output the crash information. + */ + if (strcmp(con->name, "ttynull") != 0 && + (con->flags & CON_ENABLED)) { break; } } From patchwork Mon Nov 7 14:16:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078737wru; Mon, 7 Nov 2022 06:21:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM47Xcpegjxz4PA1WJzA2glxmxloTcv50Gmi1M6cm+tPK3YQTPqmZG4tI28946kro17eafDm X-Received: by 2002:aa7:959d:0:b0:56d:27ac:778 with SMTP id z29-20020aa7959d000000b0056d27ac0778mr47648725pfj.29.1667830863308; Mon, 07 Nov 2022 06:21:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830863; cv=none; d=google.com; s=arc-20160816; b=XapO67MiYNftKPfZFCRKfpx8tlibGzBP39EXvouxGNWK16oUNOVoK0bjyFyBjIy7k/ +qFbb6NO8HPde15BlrGg7Cw15oPbYgfLbeI6eMwv/9V8KgfmYpuD/VR6/GUCHaa4ESK1 szQTC2yQeOJJSFg6mQoPwRJKiymund5qBBtkcl8Gg99X1fJuFGKbNRLpZcLIPRUzccMa WdzNSM/Ao20cjVMbB8Ri4ymMo05/PJCZd+w9iuSkx0g84buDdWli+cgao0c3cHfvxqsr srcrXdU0MLn3Nex6dLQTePKV411EopomqKMziebCC48gZwd1rV2DttPgzsvXIpf6Zjh7 5qew== 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=5TCVppZa0E2AuHd0nGaCpwvvOyi1zDUsbUnYVLs1Wys=; b=sdOBUBQ4B8Vjx6sVslZ5WloM5SRZp4MdQXs6XPftHevjyfeThgUW6HgvKI/cf9RstH g7FvzAlYD3x/9WQmE/1cZDshluh6OBRlZu2IqYfczCWQ++K41mPjpbyMi0l/bln5ybDY t9Te2iwSPQpsMeOqE56sd5u/Blxb/b6Q15mXtW97jdg5qfxhfgv4+cOFo/oFz8kBVj/y VHTEwCJrOQVyQdE5U9tfwl1nAbY70R/dhWNFWA+YaHqQk7iGfYegxJ1r7N3FQqJxnH3B 0g94mQT7A4WpPU665E/+uycNHArA66YXC0HWs/UQy5bdGxnj76CMW3lqbATkMDgu/8CZ 9NeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=q0O+msnT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yzRUX7qM; 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 v14-20020a63480e000000b00470693437c0si6574080pga.420.2022.11.07.06.20.44; Mon, 07 Nov 2022 06:21:03 -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=q0O+msnT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yzRUX7qM; 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 S232328AbiKGOSD (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232056AbiKGOQq (ORCPT ); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A9D41CFFE for ; Mon, 7 Nov 2022 06:16:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830603; 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=5TCVppZa0E2AuHd0nGaCpwvvOyi1zDUsbUnYVLs1Wys=; b=q0O+msnTIqJDVliJS2mLPmiTeN1bT4M4lS4vv1ta4Iles3swgem1QVh35gabpuNYnUkW9o kumUOwPGqpUFtE9uIVqJVyyJusic9EbpwXtVXM/DphHFhu7j/llHcsOvNhdoXOvKW8MwAQ J78ruFn8rKOWjEbg/78XMS7uTzmJ0ui6PHsH4xVdm6WM1flZAoz4X6TCt3/2V92m0+iDBx sC+yKZCWx+xbCVsF7NxRyQDNHLlA6cBfu2CHxYQN0D53Mjjz9COGM9xALCiHtPORtU1PtI 8M97XR5at4c2Z232jKNiAH5yZuym/gYqEsz5toH1Kq4UKFF4sVPpB5fzAj40Yw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830603; 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=5TCVppZa0E2AuHd0nGaCpwvvOyi1zDUsbUnYVLs1Wys=; b=yzRUX7qMIVq9AxG/h9VUumLt/k5928UDKof4oMa1D5IebwjjtNBshv84ecqWvcCu5r9Fi1 i2W2BEAaV5h3zaDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v3 07/40] console: introduce console_is_enabled() wrapper Date: Mon, 7 Nov 2022 15:22:05 +0106 Message-Id: <20221107141638.3790965-8-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?1748847414963371188?= X-GMAIL-MSGID: =?utf-8?q?1748847414963371188?= After switching to SRCU for console list iteration, some readers will begin readings console->flags as a data race. Locklessly reading console->flags provides a consistent value because there is at most one CPU modifying console->flags and that CPU is using only read-modify-write operations. The primary reason for readers to access console->flags is to check if the console is enabled. Introduce console_is_enabled() to mark such access as a data race. Signed-off-by: John Ogness --- include/linux/console.h | 27 +++++++++++++++++++++++++++ kernel/printk/printk.c | 10 +++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index f4f0c9523835..d9c636011364 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -172,6 +172,33 @@ extern void console_srcu_read_unlock(int cookie); extern struct hlist_head console_list; +/** + * console_is_enabled - Locklessly check if the console is enabled + * @con: struct console pointer of console to check + * + * Unless the caller is explicitly synchronizing against the console + * register/unregister/stop/start functions, this function should be + * used instead of manually readings console->flags and testing for + * the CON_ENABLED bit. + * + * This function provides the necessary READ_ONCE() and data_race() + * notation for locklessly reading the console flags. The READ_ONCE() + * in this function matches the WRITE_ONCE() when @flags are modified + * for registered consoles. + * + * Context: Any context. + */ +static inline bool console_is_enabled(const struct console *con) +{ + /* + * Locklessly reading console->flags provides a consistent + * read value because there is at most one CPU modifying + * console->flags and that CPU is using only read-modify-write + * operations to do so. + */ + return (data_race(READ_ONCE(con->flags)) & CON_ENABLED); +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8974523f3107..79811984da34 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3021,7 +3021,7 @@ void console_stop(struct console *console) { __pr_flush(console, 1000, true); console_lock(); - console->flags &= ~CON_ENABLED; + WRITE_ONCE(console->flags, console->flags & ~CON_ENABLED); console_unlock(); /* @@ -3037,7 +3037,7 @@ EXPORT_SYMBOL(console_stop); void console_start(struct console *console) { console_lock(); - console->flags |= CON_ENABLED; + WRITE_ONCE(console->flags, console->flags | CON_ENABLED); console_unlock(); __pr_flush(console, 1000, true); } @@ -3256,7 +3256,7 @@ void register_console(struct console *newcon) } else if (newcon->flags & CON_CONSDEV) { /* Only the new head can have CON_CONSDEV set. */ - console_first()->flags &= ~CON_CONSDEV; + WRITE_ONCE(console_first()->flags, console_first()->flags & ~CON_CONSDEV); hlist_add_head_rcu(&newcon->node, &console_list); } else { @@ -3308,7 +3308,7 @@ int unregister_console(struct console *console) console_lock(); /* Disable it unconditionally */ - console->flags &= ~CON_ENABLED; + WRITE_ONCE(console->flags, console->flags & ~CON_ENABLED); if (hlist_unhashed(&console->node)) { console_unlock(); @@ -3327,7 +3327,7 @@ int unregister_console(struct console *console) * console has any device attached. Oh well.... */ if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) - console_first()->flags |= CON_CONSDEV; + WRITE_ONCE(console_first()->flags, console_first()->flags | CON_CONSDEV); console_unlock(); From patchwork Mon Nov 7 14:16:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077514wru; Mon, 7 Nov 2022 06:19:04 -0800 (PST) X-Google-Smtp-Source: AMsMyM41q7StJPjsXYQbL1dqjBKyLFzPCmfOjiBta8yIlRjaqd4HUhuBX4G51/xRYj7U7XtToOfC X-Received: by 2002:a05:6402:1cca:b0:460:7d72:8f2 with SMTP id ds10-20020a0564021cca00b004607d7208f2mr51152761edb.205.1667830744258; Mon, 07 Nov 2022 06:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830744; cv=none; d=google.com; s=arc-20160816; b=hBzMIgjmqdt1SBHfBkxI4p4Nxun9pWyYks2xw0OOKX6O3SjU7EiVIVmLq6QxklAlsl 4svAJfiX7Hv/B48fJXl38x6dEIyYdsmPnM/V4U8lO3qDARU9HqfjrZnvcs6hfkjxzX75 zm3JaRHk8eEa7gXwAXD2JiEMqLbDE2gY753Hl9V4aiErcQjos9y2nEitdhHDbu4gy3Az jsLh8rdhrFH04K1hyYjIR/lbGNhQ+Rn7IeiGWbZ+wAIyT8YmyfQ4bulNgdH1GOca7EMV QntbpDP6912+eOhEUaUa4IScciT3mNlZWN+u9+06hP5c6OXldA3L6KXTw8vuoCCwRlAZ KAzg== 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=OOJ5rVozh2o4kPFAPBIzU10/hQr/WmijEHoN/lMfTbg=; b=E4QouAHtpRt0M7zhBCAIpX06zwzNA1ARof0uMSXgckPILmczqAefrn2ft8dgkU03x3 Em2NmwvNuOFb/0jBPyvALiG1GphIp9dKgZt8Nz1MbOhvqegMJ7dHEfzwkfmHQ5y+rvYB 0rcG4fnbQLXybKhHijebmQqT9EtltueGacMnuRO66hbwk1yjxly9ZpG8xEJoAEUMCQ8U Of/F9ltWNGGuf94wt/bnC3cM6caVLiG3wmZye3o7wikphjxMMBeqwkrNLrH1UkcxxeF/ +iw0cZ0e1nS91+wk/3an/ho1XMS2UqAi2zV78Dw/xllLwMef1NZUNi3cJ8F7ZqfTHFre PFwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HeyA6jwD; 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 n19-20020a170906165300b00711da52c6e4si6816401ejd.309.2022.11.07.06.18.34; Mon, 07 Nov 2022 06:19: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=HeyA6jwD; 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 S232249AbiKGORV (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbiKGOQq (ORCPT ); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C4B1D0DE for ; Mon, 7 Nov 2022 06:16:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830604; 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=OOJ5rVozh2o4kPFAPBIzU10/hQr/WmijEHoN/lMfTbg=; b=HeyA6jwDJkk3W2Q7mXT/ixKWhsA8ouQ5x3YmRFUo4cMH60xQZGJzZX4chawitd1iPMWjj5 e1xuQCVukVX/IsrCbyMingnYZs/NrFrV3g2vB9puzYxGOsFAttamfXWa2/AEzrwJLKJRcQ h/dTUY/sLCOQ3ALJOzLIKgc8o2cLApgCDYNxlsd1HDZTKaiK36/f73EdhXvxpB1sEQNFX4 eYvXjSX7BxLoMcYxICFQ40UmRRi6kb1tMPBwFVEy3dZUZg3OQvwWIsaDHdfaEX8N++xjka 4Cvw+xRujtByhc+iJy5WmkPysbqKCqQZ3Yo4U/3G0aDl6A+SZoOd5KpBwm5OTA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830604; 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=OOJ5rVozh2o4kPFAPBIzU10/hQr/WmijEHoN/lMfTbg=; b=g1QtfHWB/sN4/tDQrxu15t2rQx2DDWU9losLN3bT+0thLU62fNQqOH+iBtBaUXZTVGdnUB Hhw8EHn92GjSS5AQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 08/40] printk: use console_is_enabled() Date: Mon, 7 Nov 2022 15:22:06 +0106 Message-Id: <20221107141638.3790965-9-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?1748847290288021114?= X-GMAIL-MSGID: =?utf-8?q?1748847290288021114?= Replace (console->flags & CON_ENABLED) usage with console_is_enabled() if it involves a data race. Otherwise add comments mentioning why the wrapper is not used. Note that this is a preparatory change for when console_lock no longer provides synchronization for console->flags. Signed-off-by: John Ogness --- kernel/printk/printk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 79811984da34..f243bb56a3ba 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2660,7 +2660,7 @@ static bool abandon_console_lock_in_panic(void) */ static inline bool console_is_usable(struct console *con) { - if (!(con->flags & CON_ENABLED)) + if (!console_is_enabled(con)) return false; if (!con->write) @@ -2946,7 +2946,7 @@ void console_unblank(void) console_locked = 1; console_may_schedule = 0; for_each_console(c) - if ((c->flags & CON_ENABLED) && c->unblank) + if (console_is_enabled(c) && c->unblank) c->unblank(); console_unlock(); @@ -3104,8 +3104,11 @@ static int try_enable_preferred_console(struct console *newcon, * Some consoles, such as pstore and netconsole, can be enabled even * without matching. Accept the pre-enabled consoles only when match() * and setup() had a chance to be called. + * + * Note that reading @flags is race-free because the console is not + * yet added to the console list. */ - if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) + if ((newcon->flags & CON_ENABLED) && (c->user_specified == user_specified)) return 0; return -ENOENT; From patchwork Mon Nov 7 14:16:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078725wru; Mon, 7 Nov 2022 06:21:02 -0800 (PST) X-Google-Smtp-Source: AMsMyM4CiUxKIJpIwEQUqYXjZKnQNVGTL/bJOfleR78KrVhvujXoijRJTPK3wfRNY9dZdcxrsM+g X-Received: by 2002:a05:6402:51ca:b0:462:273b:6ad6 with SMTP id r10-20020a05640251ca00b00462273b6ad6mr35536283edd.119.1667830862477; Mon, 07 Nov 2022 06:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830862; cv=none; d=google.com; s=arc-20160816; b=YLYkGmQVSbhXX3rbTyzYa/SFrN7yUgF/GMKsImKTqsrXe3Tkrf8ToA7JDHWP/7l324 gNc8Qksr9mG6jlOHHvZ7jSGxgYwnehl89BQWXjEnptfFeilqleE58dnTHwbsMQ9KDO46 TilVq8BWgPGdh1j7zXzwHyUTdFKp//R6c4y7zJM6acpGJ8sa6WouxtPmomB+jKxFvbLj EIsC26yL+mG2QXyEiCv2RkkklMoZUaey5wsXVwqzsY53AcQgLPHB9LsIV12ohh4IL4Ic oMkzYQ43EA1hX3BMf6fuGqgHL5yV5txwb5KOWHHiS1T6KlGPRofHuo95ao51PuH+j4Ql S1Yg== 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=je6BJxg9zIGvpozBTcqdrPDtOdfb/xlqXdr2RuFn3Cs=; b=jrVNrZUKdjm0vUu7Dvhcp6QmJ3I0msgEqeVBpQNaB9dKZZN7B2tV8bn+OS5CVRldsw mE4GQy73MYW6ah3pAC3ZioljSzclpPDgC0H/JljcanE4KBw7zASjkMKVQs5oL8P3z0ll rMfVT45P3L+27V4Hx5sv8T3HeD4rDHdg1e9kUuRpuqn9Kg9O+baa+qmQXHxnpj2f/mmM efJyjiGM+yBlzf4pCvqkxzJLUYMGNKF1kIvzmtrhrbryX9Qi6lAmuczZ7uhTPUYweJ2X HZ5Zrekh/0fPmw8GVDEDUKMGeTBBNEYdfX7SDuggErHtK5EC9AwCumN6BWMNvF5WFvrS PrjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xStyNuRD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=fU3tEDpT; 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 nc18-20020a1709071c1200b00797e151e571si10907306ejc.36.2022.11.07.06.20.34; Mon, 07 Nov 2022 06:21:02 -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=xStyNuRD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=fU3tEDpT; 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 S232319AbiKGOSB (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbiKGOQq (ORCPT ); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51B01D0E5 for ; Mon, 7 Nov 2022 06:16:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830604; 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=je6BJxg9zIGvpozBTcqdrPDtOdfb/xlqXdr2RuFn3Cs=; b=xStyNuRDwQZqAStcI5UdpJk/G1E5RxVmu6uOQl+HxB1LsyG+UGrqEo1GBdH5tNIsVYbp31 0sGdsUMWqMJ/RIw/dqRua8mTPCiC2Bi6yXAUtwiWaId98XBGkDmKHPA2T1r7BIup48ey9t V9t+le50KAGrPTn4fCw91P4Os0mVXzm0RBzuzyUZYvXZ4/TFQS0VlpLfWhhNciYokn7bY0 x6OS3kQVIDIkRsGimBU+tA3J0nxK/4cLvsdYUYYb7XEy3sJM89hJF40SlQ4jDenQhvJNj1 T4y6vF+anyQgoWACwNMjdC5+tAh9Q1X1KynBM24kz9ifzeNZquHauzk0EDw2rQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830604; 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=je6BJxg9zIGvpozBTcqdrPDtOdfb/xlqXdr2RuFn3Cs=; b=fU3tEDpTAS3rUjjLodJQU8W30Uff0X7RCSHHMp6eNmbUMCNdxpTq68atryVxFBzRoHmaAA LJxSkx1rw4wUSjBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH printk v3 09/40] um: kmsg_dump: use console_is_enabled() Date: Mon, 7 Nov 2022 15:22:07 +0106 Message-Id: <20221107141638.3790965-10-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?1748847414478152884?= X-GMAIL-MSGID: =?utf-8?q?1748847414478152884?= Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness --- arch/um/kernel/kmsg_dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 40abf1e9ccb1..f0233e2f8de0 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -32,7 +32,7 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, * expected to output the crash information. */ if (strcmp(con->name, "ttynull") != 0 && - (con->flags & CON_ENABLED)) { + console_is_enabled(con)) { break; } } From patchwork Mon Nov 7 14:16:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078758wru; Mon, 7 Nov 2022 06:21:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM7y7iaz5ff1ZFnsKNXtUOniPbQkh3rPqPh/59NadoPzyqJ+nUPY/b60LOaZIovNUv6IPqvF X-Received: by 2002:a17:903:26cd:b0:188:4c74:e1de with SMTP id jg13-20020a17090326cd00b001884c74e1demr26865251plb.56.1667830865859; Mon, 07 Nov 2022 06:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830865; cv=none; d=google.com; s=arc-20160816; b=u05/eG5PyS3JsvTgCC++lYZ2lrdgOZqhCntpjRenj6n+/aLTJHsZHcT2nTTAaHldGH h8OYAbOBxc6oqGYXvVj9oioAzx13W2gsvr9mxTGuacmCsWwshA/tgzjX/123TWpZz0ra 5Mlv7WwoYpFGeSE9ly06RkmAHTOO5VA17cDoGIVa+mAx7ttKFxASw+4E7evB0/9tFrsH CPLDxmDPh8D3nBfLg8eTVWEd9zR4DjnW6hgIjzogFq7gT+HuWAkqaRx2u8TzfmF31iUz Jay2Q2brTnqgoxAxzpC8jwTT1C9VAusDKGreZLnmMkr5CQ/lCsVOISsFDUrmaI3wP/tv +0mQ== 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=vshPUjs+tNn2er+3l3r7gbH9xPovLwtdpxV7dKrVCmE=; b=cBhcUFuOLgijG1UHJbFaGeD0FJTvBdpbBRHBsJW9d/OMEHB0UjYEAOUFZU7vOWx2ne +pBaAyHRja9BZ7R25fYCbwp/xfqEMUyA5o2joRfXmktXJ5ptngqJZgvFimKLFr0f2LHF mjg36Hjr58LZL6CBixQZSQFiITvJQW+eIjWW+lNQbLit7JaI9Gm4OuvxeWPsE5dlRbuu Dg5E0rQiYzDtQtSlEU9qNJ+7GE6d0EvFVOQVJ7TXl9GvWU6xXeKRWxmgfCayFLCyyc5p gLA3VbvwYDMB0kH62UM0mQcDqq2JQ6MRGwKx+LalqYJ5+/+TPh7yWm8/qAc6vaktyUv/ nZPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zb1YAY8y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ZL1s3Yfc; 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 ls8-20020a17090b350800b00202eab3e1b5si18215193pjb.10.2022.11.07.06.20.51; Mon, 07 Nov 2022 06:21:05 -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=zb1YAY8y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ZL1s3Yfc; 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 S232258AbiKGORb (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232123AbiKGOQr (ORCPT ); Mon, 7 Nov 2022 09:16:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8781C1BE94 for ; Mon, 7 Nov 2022 06:16:46 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830605; 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=vshPUjs+tNn2er+3l3r7gbH9xPovLwtdpxV7dKrVCmE=; b=zb1YAY8yix2bhnE9pEpra80m87LTA6TzAm/0q2w3BOf6hMO2dBz7XVLtQC4AWi7Rx/T9Rq Aapv50ZZ4tgM5ZXneMvSzyhKYN5TLNn9FaVKB4bgNTg1txoIlhp1zXkvNt8eIksoMJEDk6 p5qPCcq4LL6MerdYTjAdkNHfjKLalhZ6aZNE9mYD43rhaqBSposGNpPQn1pQwvZS7sONZC Ul1tEqaeZGzVsQG81yIVl/TBsS8XEodDUC6fikF5eK9zJOjk1oHRNx4V+ZXNIDODyKjxv9 HCtzgOwxyP33M3cRS/eG/Bcp9S7W4kg1DWu74crGl0WGtsOpNvke0+xprx9CDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830605; 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=vshPUjs+tNn2er+3l3r7gbH9xPovLwtdpxV7dKrVCmE=; b=ZL1s3YfcydPxFz4H6XCS1dV85J+S6JAdu8CXSSZE4dwbrB21amSpVdsz60/p/XSVKBlY8m fXkhjhG8i2JCSECA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Luis Chamberlain , Aaron Tomlin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v3 10/40] kdb: kdb_io: use console_is_enabled() Date: Mon, 7 Nov 2022 15:22:08 +0106 Message-Id: <20221107141638.3790965-11-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?1748847417876192228?= X-GMAIL-MSGID: =?utf-8?q?1748847417876192228?= Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson Reviewed-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..550fe8b456ec 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -559,7 +559,7 @@ static void kdb_msg_write(const char *msg, int msg_len) } for_each_console(c) { - if (!(c->flags & CON_ENABLED)) + if (!console_is_enabled(c)) continue; if (c == dbg_io_ops->cons) continue; From patchwork Mon Nov 7 14:16:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078685wru; Mon, 7 Nov 2022 06:20:58 -0800 (PST) X-Google-Smtp-Source: AMsMyM5VHZd7YghPNyaP2Vi4+tq0svzEWTzgMHGoNrNIB93v7yd/jHL5IDFbz27wvEGw4wPfvsR1 X-Received: by 2002:a17:902:e945:b0:186:ba20:76e8 with SMTP id b5-20020a170902e94500b00186ba2076e8mr51384017pll.165.1667830858381; Mon, 07 Nov 2022 06:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830858; cv=none; d=google.com; s=arc-20160816; b=PF/JLiBKVtcBdtpMfuTcDhUCbx/rEUNubY4swk5xLsRHEyoLdOovrBmirjVkwG8gV5 xRtKUhpshYHp7FCWzUhTLz4REpa2f5kLsim4vZea+sQT/w7jPnXabqYSsGI0ccArlKfO Vev9wKIgqQpbmwO7T6fGxYNLOtu1qTmVmUqWRs7FZVC5UIu/jq+asM9PPIe9dIpley6k cWDNaJgSXPrnV4qVPpl0vB9S/UzzeQ1oinGgMAycZI0ENNAaUwwjslYNjf8AL+G2QaYC Nb+bOGuLmXTbVp21HWkgnY28TJS2JZ4uHrqZWfLa0pGl8p5w7iXeXQ3hNRXHRKsNYgAy pcmg== 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=jHu0DmQ8f1rgQbiyd2Suu9x07qh6zOdBEqqZ/26ftRk=; b=Z/0R5y0YiNEODEh3H+9B9jBOGUG2P0p2Rofh5A3ExbO2iaUbvLPn8YTEqjnFwEnAQC rEKR7bXDGS3TGy7t8wAuGkLd+jD1Ty5Qt/TldmO2vF8ymkSoEvcNaoZb/Gfs6ImRqaUU DN+epi1JXO8LdAl6AqzSlfjlgj5uutIUuxfXQ2CIdARMFqVDOGIw8nZIDshrPYW2LvoC 5m7XjiTD0cBtAUyZ4+u5ZhhhW4lw64eW8tHNvLf/YQ2ZeWZs8VL6SUs2bZTGwCVfRFHg +mt0P6rASJYUniW/xHRQ/V6W6U+7a4KR1DzZSLTpa7iREjz7dhTLjVi6r/b/q1yYfvg9 C8Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hGwj6giz; 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 t16-20020a634450000000b0045650ec7a49si10946329pgk.821.2022.11.07.06.20.44; Mon, 07 Nov 2022 06:20:58 -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=hGwj6giz; 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 S232304AbiKGORz (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbiKGOQr (ORCPT ); Mon, 7 Nov 2022 09:16:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A42C1D0E8 for ; Mon, 7 Nov 2022 06:16:47 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830605; 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=jHu0DmQ8f1rgQbiyd2Suu9x07qh6zOdBEqqZ/26ftRk=; b=hGwj6gizl96NQKwR498k6uAl6XSNfXs5DgtmC5L8WU7gQWVMnV7NlRaPDbm+f6yjkhmslu QucFR7Y2mtVq5FQDr4sTthdt7CY0EmINf9SVUOxmemZNSxstqrHpUbc6G88hCPT21Yegbw eqg3pL91M6+PPtd1gM+QJUhLzSCTMEpbM2aJhVq6e1aoD+8XkEN/nxIGyiR1B32A6BlAV6 m19ypo58YK7PSvx6wjWoCQiTVJgwBKEG3xfqcKheTXfurqjSDhZxeg3XVqGOZTLfPijIy1 IOG5h4UQmGKMeBTZ1D2406gA5WuWTokF1Wsn3rGlck+/9hA/SyrLA4qUBFxMzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830605; 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=jHu0DmQ8f1rgQbiyd2Suu9x07qh6zOdBEqqZ/26ftRk=; b=P9Gxvfan7DCC1ih4Knt2kaKzs4QeQhU+whuk/d07z5yqj/O+rOCCGJvNj0Wj3ZUD3GFgTP nGuJe2YaCbe55ACw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH printk v3 11/40] um: kmsg_dumper: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:09 +0106 Message-Id: <20221107141638.3790965-12-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?1748847410379052453?= X-GMAIL-MSGID: =?utf-8?q?1748847410379052453?= Rather than using the console_lock to guarantee safe console list traversal, use srcu console list iteration. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/um/kernel/kmsg_dump.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index f0233e2f8de0..b6acb3837f1d 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -16,16 +16,15 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, struct console *con; unsigned long flags; size_t len = 0; + int cookie; /* * If no consoles are available to output crash information, dump * the kmsg buffer to stdout. */ - if (!console_trylock()) - return; - - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { /* * The ttynull console and disabled consoles are ignored * since they cannot output. All other consoles are @@ -36,9 +35,7 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, break; } } - - console_unlock(); - + console_srcu_read_unlock(cookie); if (con) return; From patchwork Mon Nov 7 14:16:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077515wru; Mon, 7 Nov 2022 06:19:04 -0800 (PST) X-Google-Smtp-Source: AMsMyM7gi8ciUZ35moI5fsylRK9Hjbv7kJABV9CNItD284Oa+IdgeEegPWhVhh6uyNaFXaZthr4q X-Received: by 2002:aa7:c6c8:0:b0:460:e19b:ec12 with SMTP id b8-20020aa7c6c8000000b00460e19bec12mr50589061eds.209.1667830744249; Mon, 07 Nov 2022 06:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830744; cv=none; d=google.com; s=arc-20160816; b=bZrFay7EGjOfEnNgo3+Yakf5hZ8ypXawsB/jlE4hX9e6ZIy3j45VFeF0Z8BPrfcnAB ezEq/YTorHaU8hQCEd5e92zh3aNM77+wVRg2hljuNGoVbsuAfnL2pipkM5UcXwPlPNcJ 8I1++4pgMa98KO8Fq1OS3JM32N+6RApyFmzKGZPZqd9QzYRfRoIyohWYinE9MygT/8xw sEtFfre17Se4mquwLT/jLzbzpJZhmYdJL/WvVmNjgKOCwxIfMGmQ1lMGIbdTAsHNhBK/ yTzqvOZHjGKrl6m+5tZeCtg+5iL3hrekWylv8A1oq9jlR5hURKt/0jDX22V3Sst7DWyM kqFg== 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=UHuP0rbZWQQBzSmPTErQb30w1r8OemTOVXxBtKXD5zo=; b=Oc2rte8oPxAAeHamxH0ZZxTOCML1t+SL/Lf8XXKuEjBqYCTWoGMgic4rvJG28wFkcD jIKdwnqG5LAcakUjN21h5HzlF2PtwlJObYKAuOb73SEb86u+x2Oq98adjbcwiSttxm/w nYw5djve48MoGLOfSu6ux1u8lN+C+z/rv+h4OkImHc4I40PyQ9LlC12lyNnbZgnLR/F8 oMUflovt+AwtIZSUe3UOduYqCtnWPiScVqlCVZUDxeT4meQoiplzBeTb+VJZB2bEiA3m 0SYgsoVb4/1gdp8Oy5HI+PLErqBtj6H+WTtH7HjZdqUwaUnRb/AtlaCRO7aIK2Exnazh EgJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iNt4WLyb; 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 t18-20020a1709063e5200b007316ac034acsi7092130eji.834.2022.11.07.06.18.36; Mon, 07 Nov 2022 06:19: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=iNt4WLyb; 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 S232106AbiKGOR1 (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231773AbiKGOQs (ORCPT ); Mon, 7 Nov 2022 09:16:48 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E011D0ED; Mon, 7 Nov 2022 06:16:47 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830606; 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=UHuP0rbZWQQBzSmPTErQb30w1r8OemTOVXxBtKXD5zo=; b=iNt4WLybeNZ2mg/QU8nQRgYO3eRwjEe4TxpxeuViKZgOFqSLGdnxpB4EIHsbH38cw2h6Am kJVDUMhcmDfKwlcQItq60yXQiAM46j6B9Q30Uv+BDFud70sS99pVRWZsqjhTRdLZ1dBaFE UfhdVUIkj1KudfH6d1vG5YHIMtg+leLFlBPIIrj+Gzw03dt7+TXN3UcBPcTVmJ5kf31YVr G7mFekiqU9lb9lIMsaNunxvcSejZoGuF85W8nc+Rx/+O+XVwv+c9/Iu0yNjb2pkjvKZEFG FDPXkYTRkDp2Ifzzr8b9XUdgb2olC4aoS/elsnnplXFO8y8GhZMrmHrHM2DqiA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830606; 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=UHuP0rbZWQQBzSmPTErQb30w1r8OemTOVXxBtKXD5zo=; b=vWTVUpf3xvuqVwTe/KNxkvP7t8I4roXjMftkB13FmomVHEj3IjzCEpCFORfE4FT8CtCEsX KCLNz75VQR2R8iBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v3 12/40] tty: serial: kgdboc: document console_lock usage Date: Mon, 7 Nov 2022 15:22:10 +0106 Message-Id: <20221107141638.3790965-13-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?1748847290471976273?= X-GMAIL-MSGID: =?utf-8?q?1748847290471976273?= kgdboc_earlycon_init() uses the console_lock to ensure that no consoles are unregistered until the kgdboc_earlycon is setup. This is necessary because the trapping of the exit() callback assumes that the exit() callback is not called before the trap is setup. Explicitly document this non-typical console_lock usage. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Douglas Anderson Reviewed-by: Daniel Thompson Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index e76f0186c335..5be381003e58 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -530,6 +530,14 @@ static int __init kgdboc_earlycon_init(char *opt) * Look for a matching console, or if the name was left blank just * pick the first one we find. */ + + /* + * Hold the console_lock to guarantee that no consoles are + * unregistered until the kgdboc_earlycon setup is complete. + * Trapping the exit() callback relies on exit() not being + * called until the trap is setup. This also allows safe + * traversal of the console list and race-free reading of @flags. + */ console_lock(); for_each_console(con) { if (con->write && con->read && From patchwork Mon Nov 7 14:16:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078823wru; Mon, 7 Nov 2022 06:21:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7d5xn/vEdpwoK3qJG8FMtXJXOeFturvSYMEpgnFRKW1YfIQ4xw31Ah5oQd+La0kkU9xcr/ X-Received: by 2002:a17:903:124c:b0:188:835c:4f55 with SMTP id u12-20020a170903124c00b00188835c4f55mr4085217plh.64.1667830875463; Mon, 07 Nov 2022 06:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830875; cv=none; d=google.com; s=arc-20160816; b=ntDZXGYn2PNbo5DUg/ip5mWsoS+5PNblm/jbAUY7JWie0hklS2kYmZny/YZlbiD/PY mwNqm7Ko4XUamObCrIp/gb62/w7tkx5kmL+srRE5PAz2YCEVfq0T4N4q1c/mk4ORSIRB kJCNAUCSUc0czDkIdMILZaCWO8/Dgq1M9F3kQaqEsXpisGgCIdVJvC8c4sFQrSLUNZEa eiQNMSXTNkCDF4qHvXPObCSSTdce9N2DV8nSm5We2/EfdCE+hP/Lida8DUDgYdkBZoNf 3il+kmaYVCeP6+kQwqaWIln3+wxZYtB7rua+c71Xw6bIvi/TfRwB5RzX5Xq54vp4vABP rCgA== 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=dCcbZ2nZRP4FMVS4VfHiFcW5Scqwo3VptQivrT22/cY=; b=N9uOsYD6QjwTGfbZ+dGEYbP3bryiYMKzpzavMavem51LZzSMiF+XPl66JhgQATRkmx yVBoRTqwW2b0uG8OCuKCRpSNe+GArNiVIZqnVu67+Y3RPRZOAWfYobpMhMy71PqJCx+P unl67+2AAaej/Y7ir+jL/inh+4ZRtGzVwZv716kFQMbGXbAUw31AAQZpsXqrXuC+8TLG MoZ8ODOHZjD7xYsi4VfUh3/Yntkl4dehTr3h4j4+iNIVw+TaP3sE0NIl/U0GK85FSsBC a//taBAVUfpIuBZMalR/YC69JBxXFpcZWxI4vdyK8nDT783NWSe7fpr8tjM+iwNS1PIT kY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0d3z4xL9; 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 194-20020a6304cb000000b00429f2cb4a47si11758295pge.491.2022.11.07.06.21.02; Mon, 07 Nov 2022 06:21:15 -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=0d3z4xL9; 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 S232291AbiKGORw (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231968AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC67A1D0DC for ; Mon, 7 Nov 2022 06:16:47 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830606; 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=dCcbZ2nZRP4FMVS4VfHiFcW5Scqwo3VptQivrT22/cY=; b=0d3z4xL9MeTeQrkMA1tq1zT9HmredXjKfiAbW7rrtu69ZIzka1gnMp40KPeuojsXX3Nkr9 AZxEtIcS7R2Ezc3gu9mFGy9bLznQxPV/GWpN/5heML3RCJIhOWSZv8V9MjC7lsI0wd9e4w jJrKKPKFlBps/DuPHb/J6jyDYiVm/RAPKUHiuA97ydwbA48kWnvVAHxZSQJhkwrEbnwRid ZLi2s1anaVF8BNNITWyPc3TywgJZJ9i0QoavNfJPeAPqEd5YQiPxGJfXjBt/6dkKiPkbZQ GHGshCC10unhBdwLm/cN9x56+2c6GzWHyDc1YV49NuVb+3+IcBcubRxsqwUzqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830606; 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=dCcbZ2nZRP4FMVS4VfHiFcW5Scqwo3VptQivrT22/cY=; b=0BuRCrFb1lOtnGXdQk8YdKfvXzno2vWMkwrUfCthAamtrK5DjD0g+Mn8fyVA3k00ypBjwd hS7Z8rzULOsYtMBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v3 13/40] tty: tty_io: document console_lock usage Date: Mon, 7 Nov 2022 15:22:11 +0106 Message-Id: <20221107141638.3790965-14-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?1748847428067657017?= X-GMAIL-MSGID: =?utf-8?q?1748847428067657017?= show_cons_active() uses the console_lock to gather information on registered consoles. Since the console_lock is being used for multiple reasons, explicitly document these reasons. This will be useful when the console_lock is split into fine-grained locking. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/tty_io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index de06c3c2ff70..ee4da2fec328 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3526,6 +3526,16 @@ static ssize_t show_cons_active(struct device *dev, struct console *c; ssize_t count = 0; + /* + * Hold the console_lock to guarantee that no consoles are + * unregistered until all console processing is complete. + * This also allows safe traversal of the console list and + * race-free reading of @flags. + * + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); for_each_console(c) { if (!c->device) From patchwork Mon Nov 7 14:16:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078662wru; Mon, 7 Nov 2022 06:20:55 -0800 (PST) X-Google-Smtp-Source: AMsMyM5ndenX0VuVg5w3nsC/ovv6sAnVkbvk2J4Is1H/EOcBQiy94l5PYjISaN+DM/p3XK7NX9mI X-Received: by 2002:a17:902:d2c9:b0:186:f355:a42b with SMTP id n9-20020a170902d2c900b00186f355a42bmr50110681plc.58.1667830855672; Mon, 07 Nov 2022 06:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830855; cv=none; d=google.com; s=arc-20160816; b=ZbzHD4SQ7N1eJptmOuHGtJ8/5enbZunEBu22efDJTTbJhr71zY2mJM7e4TnsO+ArSI IPzu08pTy2Qf0KFJ2NSv4jaX1oANsSPGV9Ji+oaRLMDFLjPN8tcIM8st5NMpSoM6qBrH h3u9HWxxOTKYp4hyEZaA1e9QJcdvu7undd+tRH93QHhKDM+heRx8XqmoYfQy235BhIPj efBVRTWOBmqe1MQyBeH/K3erz9GPdMJoOnP5UalTauofFhkLzZ4efZntclpL6L9yc5Ry TcarjxDfYcoNLH//T/6jxus92UZZEzN3sB6FLueuEX8kuFDR+ISgekdBprMxb7mkQYKm xiAw== 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=I3yaMFjrCtNc3Px6vqfLokWlErUgA/SSe6zXZ59V8XY=; b=XylTgzFGGiw/CjeqD63Cl/o5w8VHWsgwWvby+wzi4CPgK1DI2qKUvQuzAoi6NqcS+Q AGGHz/VPAwYBC53RjOxfs74oFvUXAAekkErI8q/nUlkROj9d7Oo5H570UrPbZPgsrJ1y slbnvzB2U2MBGwk8aRohmFn0L6+SbMT0JzVs7/am5WBFVX9AWtMIoJGME/+Fhdq3/wA7 eCM0Y6/3UtrEoHRMdDIFBUHvHpMgLGbDQ4OvIsoWmTFIPDuZoM7kAbtiZqllzyawBhNo KweO7z54vk6tjpD9ZtinxEexSjTDRu4z7YrVc509miu5p6KEPgvfjY9JRQEwDbOcNoVi CNdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=W7M6kX4a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YNgZvTTc; 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 e14-20020a170902ed8e00b0018659963cdcsi9163344plj.514.2022.11.07.06.20.40; Mon, 07 Nov 2022 06:20:55 -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=W7M6kX4a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YNgZvTTc; 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 S232285AbiKGORp (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232148AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DE11D0FE; Mon, 7 Nov 2022 06:16:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830607; 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=I3yaMFjrCtNc3Px6vqfLokWlErUgA/SSe6zXZ59V8XY=; b=W7M6kX4aY2WaQhigk++ZxU/cDgnvB3Dl9STk1+geoLoCGHp7UPBDY5v+NeZ90ucRfC2HZc lDRqkLNmPbRjBpCbHs5tsKGthjWVMLdZWMxiNEI7NckgFq/qionlE3HamxH3X/5XmEp8i/ LvYvxgNjfgydovwy55cK34wbW767izonqt76pbi9y9xO0RkwY4CcHMM+xntUfQSktX66yz ojtVw2XzoK4YTR9iApgdp4QpWG0d3UrJirmW+3fYtI6H0PCdW8LnrEW/UfVs02EMFXShG/ ChC8lj5RsSsKp0+AoiQTwUUxu+kE5nZjTLQvr/wycTrZpqCOEAgBCZU8fBxvGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830607; 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=I3yaMFjrCtNc3Px6vqfLokWlErUgA/SSe6zXZ59V8XY=; b=YNgZvTTcrT+PyJJnxSALPiorJ0D8azX4yxEjkhd6xJt1i0DwjJgqovqxZLibOchEzYHoDL 88GvZxS2AnRgV7CQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org Subject: [PATCH printk v3 14/40] proc: consoles: document console_lock usage Date: Mon, 7 Nov 2022 15:22:12 +0106 Message-Id: <20221107141638.3790965-15-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?1748847407172052984?= X-GMAIL-MSGID: =?utf-8?q?1748847407172052984?= The console_lock is held throughout the start/show/stop procedure to print out device/driver information about all registered consoles. Since the console_lock is being used for multiple reasons, explicitly document these reasons. This will be useful when the console_lock is split into fine-grained locking. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index cf2e0788f9c7..46b305fa04ed 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -63,6 +63,15 @@ static void *c_start(struct seq_file *m, loff_t *pos) struct console *con; loff_t off = 0; + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + * + * Hold the console_lock to guarantee safe traversal of the + * console list. SRCU cannot be used because there is no + * place to store the SRCU cookie. + */ console_lock(); for_each_console(con) if (off++ == *pos) From patchwork Mon Nov 7 14:16:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078885wru; Mon, 7 Nov 2022 06:21:23 -0800 (PST) X-Google-Smtp-Source: AMsMyM4VAmqxRhbYpt8+y+2ajVljc2w5GK1G+77F3uj2qC9ogVyVGtTGy8HCuhFyguaciprCYCg4 X-Received: by 2002:a50:c21a:0:b0:463:c2ac:95f6 with SMTP id n26-20020a50c21a000000b00463c2ac95f6mr33060364edf.398.1667830883457; Mon, 07 Nov 2022 06:21:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830883; cv=none; d=google.com; s=arc-20160816; b=EDkFxvpmfWic+mOgxOHwD+JVqJ+de0dRIsDv5UJgvnt0wqCGMsTKV8TBkWjxlzxuki ttOgc6PtWed62IIs9/5gRCeN42KECVOhG+1aOZEq3BHdBLwJuZimQeKGZXmrsgXURvTy EMCdjPFb3kzCxWmGzjCokdfcBqVufwskGSoJTaZdAorLLTGfAPSUZR+JPsCRWIYMs7hi 1Wrw5XOu7FSCwFc4Y8JDH0EdNS/JVbfq7tx4USxfxTVEUy7L5anDDHfOi7ovxLIHKaCT QXD8NOrf1cyViCEG3FjAQw8IhsRTkp1ZEYFzWJlwEFeMAuLctagwPScraEeBBoakrXRI CZ2w== 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=U2GPFpr2f/EgmHJQ1BEIEBV2khJXpGWa1ibt3AAyHTmaN4vTdHPb9fBt3KFZVKPf3h NHeHlpd/eDPlk6WZWFNKkUsInCn5jyskhiAfH6dY7xWuedh5oT7UtXBMv8b9E04AzqgK hMLyocSiVgV86WzgtKRqyS0HHkCaq+iQHDCoNy2uL1ntmfBNdml/fuxa4k+JhrLu7qz2 zw/vebSHf/0sNCCmS5xH4ntMfF5ols8h3P3TvdmwCYPb1dFzHM/x0t7XWCA/3aQQGrUS VhxEA/8HT8klpsAM174Vgk1r7hkWviWka2y85t7RtIwQkQA06UNSaJpX5+1V/YFlxpst ZHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=O454Lsii; 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 f24-20020a50fe18000000b004596db363c4si8694329edt.264.2022.11.07.06.20.58; Mon, 07 Nov 2022 06:21:23 -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=O454Lsii; 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 S231635AbiKGORl (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B301D30C for ; Mon, 7 Nov 2022 06:16:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830607; 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=O454Lsiiz5kJngn+Di+jISdQqtthm9fMBo/qd09UHoJIP7fLkelSV+ixhOpLNJXHV7Mttq 4TLbFkmtL0Veo/xxWJ2Bmrg4+CnHd17YN8fNg8mNLvgdi/6EhGHArF+ZhnRQzr3fEE7Nmm GbTzv8SCm7paAxm0xNbxBqgHL/zrwCwfEdB1FVlcstzlumqZSXfwBX3uFiNjKqRqQDl3L2 vzay5KqNRDePj6PPYPtFXCOQFV5nRiemPTvZQ5XQ3F/2xXpq9zrCm18mG3kr5/w8GEsPMV DcZoEV0ZuTMkTu2GPrrzuDLeIZNuK6d3H3h3F1LtgkaRT/U/vnGhM9IYpHGuGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830607; 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=SK8wtl/kZYl5l8mJdOCBSFTMjd4QjXMFsXwUjuDGL17ezsD45pR6VKM5rHUjSYtgNFT7We be38PD4HSzVHtJDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v3 15/40] kdb: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:13 +0106 Message-Id: <20221107141638.3790965-16-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?1748847436705614979?= X-GMAIL-MSGID: =?utf-8?q?1748847436705614979?= Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/debug/kdb/kdb_io.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 550fe8b456ec..ed8289ce4fcb 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -545,6 +545,7 @@ static void kdb_msg_write(const char *msg, int msg_len) { struct console *c; const char *cp; + int cookie; int len; if (msg_len == 0) @@ -558,7 +559,15 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { + /* + * The console_srcu_read_lock() only provides safe console list + * traversal. The use of the ->write() callback relies on all other + * CPUs being stopped at the moment and console drivers being able to + * handle reentrance when @oops_in_progress is set. (Note that there + * is no guarantee for either criteria.) + */ + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!console_is_enabled(c)) continue; if (c == dbg_io_ops->cons) @@ -577,6 +586,7 @@ static void kdb_msg_write(const char *msg, int msg_len) --oops_in_progress; touch_nmi_watchdog(); } + console_srcu_read_unlock(cookie); } int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) From patchwork Mon Nov 7 14:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078616wru; Mon, 7 Nov 2022 06:20:50 -0800 (PST) X-Google-Smtp-Source: AMsMyM5yUCo35bX6gstHbP7xB0/0hlAfHzPv8Qx/6rOmXru3048ZOxjtLik86F+rocRir+2bsju4 X-Received: by 2002:a17:90a:1b44:b0:213:1035:f913 with SMTP id q62-20020a17090a1b4400b002131035f913mr50601814pjq.133.1667830850272; Mon, 07 Nov 2022 06:20:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830850; cv=none; d=google.com; s=arc-20160816; b=MhpeondkeER8ncw9aF+p1SH2/nQHd3v5p/6wuW+B8dAygZ8Z4Dov+5LPwsGNWhSuU6 oG1UqgfXI+5chMSBWr26PBrRJrCSgLyFlGtZvBALzQuL/baanEGs8UWhwCmM4bJ0MYl+ zSiA1RnE+KgeOmw6b7qsHfNNENpZgvme7RGLr86wylbsEXLQp2Lkot6p+W0BSR7FecG/ rv4KLk67ad4oPraLFcxqMaDYvuTtkg9xP6GQrR+bVqI5U+RpkJzJXV/g8rWmePAPwSiu o4YvYmYN3wN9TcTXo2Rf/HXE5IooCSJKiWTuew3U3o5ODkECc417POMedBTRpvvtjCKZ 4Jhw== 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=xRs4C//aZ2HeOzpawsvS7vlkF3dTyY5CM4DVXIq0isY=; b=BCYpsuyCdF+o92rt7WqyA5WdP1pd/qz+d0mpxo4K63i9Woy81Rbgj7u4lAEftACd/y 8gRScyEk2BEVa26A5uTUQ8lHR0d6UpngImkAwSQc1pEkCRlkkNIL+kcznKIfVrp1R83J UQShJF7UZtiuUKQYPUl+y8rwbtWIslg4YQCiqiQ1wp76jDK7jiRLnG7oz470MjrofrE8 6w5jrCuyf2KLhFn6wMBTTBwtlHVUX9A5COfmNYrXyqCWHetVMN53SPiMQ/olbjfdSRYd LlgRxKYEeNZUfwOvGyJVYOTw7NlDcSc0zKzRu7NhwZVr8BeWCrJMRWG+ZM+sHj3zJLvl TRQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=usUMqsoV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=d7F6mNSy; 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 j65-20020a62c544000000b0056c37608f45si8604944pfg.348.2022.11.07.06.20.34; Mon, 07 Nov 2022 06:20:50 -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=usUMqsoV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=d7F6mNSy; 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 S232178AbiKGORe (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3035E1CFF1 for ; Mon, 7 Nov 2022 06:16:49 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830607; 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=xRs4C//aZ2HeOzpawsvS7vlkF3dTyY5CM4DVXIq0isY=; b=usUMqsoVniWq0avuQYz9eeeEr5jUcenWNdeEP8xVS+WIyFz4wCB1NT1gJfbLt7NtHNvMJD 446Yw8X552fz5u5mB5x3KaHgSJL/JDyF/xPmhLFVCuS4KkF3v7xWl6RjjHhI/mnHgJgl+H EQxGk28Q3GWTXZxLM/AavIVUO8tiUEIDZpxx+3wpwZNuMcjjBfUYXe+qkjv0SNjyAKBcJ1 5EOreaWXO85SEdLcvXSn9UrMmqRdMOg/HpGsh8kwUAUwX/cd2na46I4X64nzWIyFamgC/k gbzNcV6sAxnw0yoB6ZZHX1WTzEYeUX37mFyi6qzHV/A/azYzm7zTL3t9ng+Kpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830607; 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=xRs4C//aZ2HeOzpawsvS7vlkF3dTyY5CM4DVXIq0isY=; b=d7F6mNSyIJFLXr/Aanksm2lDQMU1eoPxgVdNe39+reXUFd0ggAE3BxRUFId6Np03FfAXVN GdE4o4fTFbuXtCBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 16/40] printk: console_flush_all: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:14 +0106 Message-Id: <20221107141638.3790965-17-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?1748847401593565887?= X-GMAIL-MSGID: =?utf-8?q?1748847401593565887?= Guarantee safe iteration of the console list by using SRCU. Note that in the case of a handover, the SRCU read lock is also released. This is documented in the function description and as comments in the code. It is a bit tricky, but this preserves the lockdep lock ordering for the context handing over the console_lock: console_lock() | mutex_acquire(&console_lock_dep_map) <-- console lock | console_unlock() | console_flush_all() | | srcu_read_lock(&console_srcu) <-- srcu lock | | console_emit_next_record() | | | console_lock_spinning_disable_and_check() | | | | srcu_read_unlock(&console_srcu) <-- srcu unlock | | | | mutex_release(&console_lock_dep_map) <-- console unlock Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 48 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f243bb56a3ba..49b9ba00eae8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1847,13 +1847,13 @@ static void console_lock_spinning_enable(void) * safe to start busy waiting for the lock. Second, it checks if * there is a busy waiter and passes the lock rights to her. * - * Important: Callers lose the lock if there was a busy waiter. - * They must not touch items synchronized by console_lock - * in this case. + * Important: Callers lose both the console_lock and the SRCU read lock if + * there was a busy waiter. They must not touch items synchronized by + * console_lock or SRCU read lock in this case. * * Return: 1 if the lock rights were passed, 0 otherwise. */ -static int console_lock_spinning_disable_and_check(void) +static int console_lock_spinning_disable_and_check(int cookie) { int waiter; @@ -1872,6 +1872,12 @@ static int console_lock_spinning_disable_and_check(void) spin_release(&console_owner_dep_map, _THIS_IP_); + /* + * Preserve lockdep lock ordering. Release the SRCU read lock before + * releasing the console_lock. + */ + console_srcu_read_unlock(cookie); + /* * Hand off console_lock to waiter. The waiter will perform * the up(). After this, the waiter is the console_lock owner. @@ -2355,7 +2361,7 @@ static ssize_t msg_print_ext_body(char *buf, size_t size, char *text, size_t text_len, struct dev_printk_info *dev_info) { return 0; } static void console_lock_spinning_enable(void) { } -static int console_lock_spinning_disable_and_check(void) { return 0; } +static int console_lock_spinning_disable_and_check(int cookie) { return 0; } static void call_console_driver(struct console *con, const char *text, size_t len, char *dropped_text) { @@ -2697,16 +2703,18 @@ static void __console_unlock(void) * DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL. * * @handover will be set to true if a printk waiter has taken over the - * console_lock, in which case the caller is no longer holding the - * console_lock. Otherwise it is set to false. + * console_lock, in which case the caller is no longer holding both the + * console_lock and the SRCU read lock. Otherwise it is set to false. + * + * @cookie is the cookie from the SRCU read lock. * * Returns false if the given console has no next record to print, otherwise * true. * - * Requires the console_lock. + * Requires the console_lock and the SRCU read lock. */ static bool console_emit_next_record(struct console *con, char *text, char *ext_text, - char *dropped_text, bool *handover) + char *dropped_text, bool *handover, int cookie) { static int panic_console_dropped; struct printk_info info; @@ -2766,7 +2774,7 @@ static bool console_emit_next_record(struct console *con, char *text, char *ext_ con->seq++; - *handover = console_lock_spinning_disable_and_check(); + *handover = console_lock_spinning_disable_and_check(cookie); printk_safe_exit_irqrestore(flags); skip: return true; @@ -2803,6 +2811,7 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove bool any_usable = false; struct console *con; bool any_progress; + int cookie; *next_seq = 0; *handover = false; @@ -2810,7 +2819,8 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove do { any_progress = false; - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { bool progress; if (!console_is_usable(con)) @@ -2821,12 +2831,17 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove /* Extended consoles do not print "dropped messages". */ progress = console_emit_next_record(con, &text[0], &ext_text[0], NULL, - handover); + handover, cookie); } else { progress = console_emit_next_record(con, &text[0], NULL, &dropped_text[0], - handover); + handover, cookie); } + + /* + * If a handover has occurred, the SRCU read lock + * is already released. + */ if (*handover) return false; @@ -2840,14 +2855,19 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove /* Allow panic_cpu to take over the consoles safely. */ if (abandon_console_lock_in_panic()) - return false; + goto abandon; if (do_cond_resched) cond_resched(); } + console_srcu_read_unlock(cookie); } while (any_progress); return any_usable; + +abandon: + console_srcu_read_unlock(cookie); + return false; } /** From patchwork Mon Nov 7 14:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078542wru; Mon, 7 Nov 2022 06:20:44 -0800 (PST) X-Google-Smtp-Source: AMsMyM5Il1whCMAVR9sNBEOOLS2UttHUdhpBEZZtkTbB/DB/vzNIRIz1jpTdZQ67CECm+0oPc9yc X-Received: by 2002:a17:902:f685:b0:186:fa9c:2fdc with SMTP id l5-20020a170902f68500b00186fa9c2fdcmr51077898plg.25.1667830843868; Mon, 07 Nov 2022 06:20:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830843; cv=none; d=google.com; s=arc-20160816; b=prJ3mORMOWhRnGxDfir/eAaqSm4eUMtBcyPSLzDm4i9CJEstWpumWMLhclkz2pEPPb Bof3wyf7CX3hxDMUtJpWWMK8O9R8NSwZBIxuaPS1m1d0bjW3hQY3cGpY9TyzvV7FyfbO y8E3aRxPToMuRYryu72p1Yk5wxxq/m8GtP2UslkmbVZbyGfPe/2U6/WrlciJvPXCrDX3 r+N6UEmDIRIKVWDdBjeCCdbwq3VJUDw07IE++VlpkY4VtIcaOrSI8ceiP2vITwhSPn+v ZVXOXIte/y2Lsp1ztv/N6S0271Te/uufKyQMHnoCIKe8PoWLNmsMX98jjyBqw/T4qacM dWIg== 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=a+dMckPSOTswrJAevuczzlxBoDdFUTF9ehHS/Am7BVc=; b=NUhRCrIRPcDIfghN3e2SVF4hDOMujNAi+U2/2cuRyvfrcvdAypbAHyZi/gbHi0Xc+p zgsCXxYi2BdGC4+T7c5LbDFz8as/Aooh3pJlXV0Fy1T8mShb1IKks05uiRVUMrznimzw WADW8Dufx9xEUUizQXrDVDy/XtEg0n4zl8M5G4x5e1cOfZsiWXGeb9oJhuZEWDlzfcvK TeA45y7aWYP6FNXwwlERo6uuVW96TUa85s1S0vy7nMavBVEsk/HohGD1YP0XbNJsOgkc aIxygDjtwHGnXG+lhvxMs6Rwhuiv2LvVJsi/CD4pvhonc71TnrSuDh7FNaJyiB0vo9Tb +qKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="p5Y/D/EI"; 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 q19-20020a635053000000b0044b817adee1si10321439pgl.78.2022.11.07.06.20.27; Mon, 07 Nov 2022 06:20:43 -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="p5Y/D/EI"; 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 S232174AbiKGORi (ORCPT + 99 others); Mon, 7 Nov 2022 09:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886231D317 for ; Mon, 7 Nov 2022 06:16:49 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830608; 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=a+dMckPSOTswrJAevuczzlxBoDdFUTF9ehHS/Am7BVc=; b=p5Y/D/EInVPhXQh1fyzw62a7v7ilG2hBVvMEy5oz0pI0tKTHpq8rBapUnzJxc6CXViKuBM fjwYBUx8VvS36kgelTD/s5R30cFw80eGCepxLvc0xJU5zUw/pKEHUYt7Wf9Qc4lnpxgNua cuT4vnqNwbn21DFVQokA6zLmW5OCBYfALqXJCR9ePm0uZf9kXn8x0SZvh8c55kOMhSgsl7 zrI9rrsv4QrCsJKK0zEIGYtxTMQLvrHFb+T8azoBLyGutNmom45RkjqxZgeUblVhLz1982 URiRhxPP7CqjIGfTjAOCQWi+Xh5Medu17I/WeMzGxNS+IrTc+rb7Ld7diMkg/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830608; 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=a+dMckPSOTswrJAevuczzlxBoDdFUTF9ehHS/Am7BVc=; b=VHoFbIAsUVtwAr5/GMK+QqboXX/RIvDR8brYVDImSGAJFJ9Lh7qHt2gyxTyFPDqAPl8eZE b3TUGf+2XXXNFuDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 17/40] printk: console_unblank: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:15 +0106 Message-Id: <20221107141638.3790965-18-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?1748847394536976848?= X-GMAIL-MSGID: =?utf-8?q?1748847394536976848?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 49b9ba00eae8..c3191dc24742 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2952,10 +2952,14 @@ EXPORT_SYMBOL(console_conditional_schedule); void console_unblank(void) { struct console *c; + int cookie; /* - * console_unblank can no longer be called in interrupt context unless - * oops_in_progress is set to 1.. + * Stop console printing because the unblank() callback may + * assume the console is not within its write() callback. + * + * If @oops_in_progress is set, this may be an atomic context. + * In that case, attempt a trylock as best-effort. */ if (oops_in_progress) { if (down_trylock_console_sem() != 0) @@ -2965,9 +2969,14 @@ void console_unblank(void) console_locked = 1; console_may_schedule = 0; - for_each_console(c) + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (console_is_enabled(c) && c->unblank) c->unblank(); + } + console_srcu_read_unlock(cookie); + console_unlock(); if (!oops_in_progress) From patchwork Mon Nov 7 14:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077904wru; Mon, 7 Nov 2022 06:19:41 -0800 (PST) X-Google-Smtp-Source: AMsMyM7Z65X+EMHlueA3RtuOFe1gAey5Sc7vySDIYJdq3wmT7zQOXjgG/A8+uReH9cQOZDflHg/e X-Received: by 2002:a05:6402:1c0a:b0:463:3cda:3750 with SMTP id ck10-20020a0564021c0a00b004633cda3750mr45437611edb.341.1667830780834; Mon, 07 Nov 2022 06:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830780; cv=none; d=google.com; s=arc-20160816; b=VPc/1Q6Iohk6VpAIAX9tQ5ilYaq6lUX7gJSsYDBlYSNCVMSUgDccqSHOWY3hbPG4F6 MINUlW8mUqSSNLlsSLzr7BDDHTI6i9HH24UxDpPRUVK1tfmjdc9y7qGir2eAanoKHCOa yA4+n4lAG7hVwYb29LOGagAuNdtYDFSBGWBjiOZRdY8aLLsuqHtxvpGKmckQ4GzF9fcI 451RKXbKa0tOlQde+QcYKgWcDTw64GOjRRCA9/vAWOFPA0795vMTInTXNXOAOvZBg4m5 MukpeDhMDh4gsIp0UvOhPAvaZU3PNsmw6Edbyin29Eiir45rU6YZnJbyKJvsxCglL8To 35aA== 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=ytJB+9rgO+EqU8LkGZl4Tw4Z1RzQttqyi+dgPG2Y3pw=; b=WOkuzG4V6wPzHNX8wFS9viB8RI6wdAYZ1NyvQydMGrSXuLwc33fxzW+7LnCqcoLk69 pCUYRdXDU9RPDTlomQGXVVyrvBAv4CUKCAM1pSq9JsslKHydgr6P1+HuEUu3qQaLZ00a P10ieVPgMOfvTNPQWFDkbpkS9JdOjaeB1wQ4Sz+ZMgqcFLQJai6ei2h2ye0emh58ELN+ qQKqS+DKnOfw0LbMLlD1wFK4Ql1pNDju7lkPOVFphCw2hwgFX7nWu8GJCFmS2zSJTOk0 QWdcc49N/nAaiwbssk6PI44ea6ddg4ObOJCTR9Wro+JAl8BEZaFbz28JJSMxvDc+tVED 0FCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tvfgWdUO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SCvymT3g; 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 s6-20020a056402520600b00461d2ed78afsi12443507edd.563.2022.11.07.06.19.16; Mon, 07 Nov 2022 06:19:40 -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=tvfgWdUO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SCvymT3g; 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 S232334AbiKGOSM (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbiKGOQv (ORCPT ); Mon, 7 Nov 2022 09:16:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE2651D31E for ; Mon, 7 Nov 2022 06:16:49 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830608; 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=ytJB+9rgO+EqU8LkGZl4Tw4Z1RzQttqyi+dgPG2Y3pw=; b=tvfgWdUOKJ0foJ5Ejz1gne/uLe6ouS6lUxWKG3dZ78D1ctsy+KDk2k1UeJK+dflBFF5tQB LJErgvWTqWgYNJ9RiE82R/HpInSf3dywVtBQfWyimnALZtruD6kAAachO9zUSBlQXQb1v9 ZfIAI3z4F4+u62e+QbuPGSc8h1z/f7By8TMR80eErlPO0Zn0EXUBJWoLox4XFLfx8Zm9ve CykXIPWP1DQ21t9FMDfMu4wp5jEwrXyYbWVjSrn8/D4zdw/7E+f/JLOl6EPXRSLRF7k1io Eroz+kmQWCyOTDUSwy1xtwV2PvLWHmp99oxSnhexLUqROQFPb9YQGkMeuoYtMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830608; 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=ytJB+9rgO+EqU8LkGZl4Tw4Z1RzQttqyi+dgPG2Y3pw=; b=SCvymT3gXMX272XYBl/YKBg+avdcP3e+KZW6cTXiDF6OuHHUQtY/cy7sw6vjxvzae6HxQS 5FlXwyzw/ecLD+AQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 18/40] printk: console_flush_on_panic: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:16 +0106 Message-Id: <20221107141638.3790965-19-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?1748847328774505947?= X-GMAIL-MSGID: =?utf-8?q?1748847328774505947?= 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 c3191dc24742..de86a502b50b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3002,21 +3002,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(); } From patchwork Mon Nov 7 14:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078759wru; Mon, 7 Nov 2022 06:21:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM4i6XtJIZ4xhwLcSUADt9lu+2YReBfHGWFGl5CpF1t5AZjIIj8tz3bWTu5yt299TS76VRaC X-Received: by 2002:a05:6a00:4c9c:b0:56b:a9bd:ee4f with SMTP id eb28-20020a056a004c9c00b0056ba9bdee4fmr50802958pfb.35.1667830865976; Mon, 07 Nov 2022 06:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830865; cv=none; d=google.com; s=arc-20160816; b=jCm/RQ1cFeb6dYfye90hDkfLF5yul5zVi8OieuQei3Yx0ZigNrDabpgWtStDJfLC2r YJPK4TTqTiBYi9Zcdm94g7WY1mZYg4OuB2X6k5etetuZcUbW/7gFQXkCFcCHUBd4KxpB xeLbLWUjG0DH5PT59UGxcZc+61UWzclLz1vAm8XX5lYTlPm6LbpzlDMTtP+wEZiVuuDk 2tsD9aHmjounqaUQP5q+HjRxcPEFLULy3Pxn1Bf3W+D2guNlUxrAtljLEpb8wBM15RHA qyqD4k5EEJuakOgy8VflzyAEY6xHyCGuFXgwJ4COPWbC3h8Z+HNX3CkjGwbvCdooNV1G acag== 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=eiV0lB4PHD+wq8ihYIBCP4Hs9zHSZAucHIdl/L7PQQqdfpg6pl9sMW9XH6u6catxnp 0sYNzVHxMVh+Ji7cONJwQuOtQpRNd4lBZcNTMM7oIYNLd6lcDL0pSaCulY1f847bxPzY 9FZ+okLlvPUSVD50IfZAJeLRtzuCN/9jmzmCqBeO2LIW9KYz0hqjZpADxJc3m/1tdRRZ hG5qTquJvlR0N4P+nWm94bXfChMfUoV4iZxe7WeCSorkMvIYt/qwAEAs8yOfN0No9EZ3 IHtG7le2HKCM07EWGZ2HPsdmUoMP/jlACm3xykqYqfJpSISlmUFyznE5slPTFpnh7I/9 G3ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tm+UuDKt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 v25-20020a637a19000000b0044c3e11a7b4si10487051pgc.42.2022.11.07.06.20.52; Mon, 07 Nov 2022 06:21:05 -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=tm+UuDKt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S231776AbiKGOSJ (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbiKGOQv (ORCPT ); Mon, 7 Nov 2022 09:16:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6962C1CFF6 for ; Mon, 7 Nov 2022 06:16:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830609; 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=tm+UuDKtm5l/qfvFtCtQkn9+nlKUcd0FMXZwD/N0Ka1Icck0LpqfBGD9XYIber/RZs2qhm di7pV0GPtm9HLj2VN4zQQ2SG4AQsQ7KDTN7oTSSXMUSgMC76bCTv33CsLyPFuJKxJ/Fa+t HAly7gRr8pJDDNXZDcmYVA5Bvu3BgltddUkB9SaGquUj74b+E2iL9noXigLGIo4ugQpYrb hS11fUQ9DrkkzLMWBqNv9gMH9oHCEUQLdgimCX/zlb23mazp4o9jGoOujZ1ZwrYKmDAUR7 xx0ohCgWc+/kEsyZAgSOGLlGLOchupmxtVFr+xNcYKWclhzqII9kmYFiwHJQIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830609; 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=2zM6BbgfCfSCfos3tEUjJzU1n9XC3FM5vgqnoPMeSh4=; b=DhOptzRogvtegO49HBlRx8o5kp/lMWiItSCsCgg5oU7r5sY//CNAld05WMBSfbp9FmujYZ BBk/NKS2y2FRUqDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 19/40] printk: console_device: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:17 +0106 Message-Id: <20221107141638.3790965-20-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?1748847418529124084?= X-GMAIL-MSGID: =?utf-8?q?1748847418529124084?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index de86a502b50b..ec50777d0301 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3029,15 +3029,25 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver = NULL; + int cookie; + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); - for_each_console(c) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver = c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } From patchwork Mon Nov 7 14:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2080198wru; Mon, 7 Nov 2022 06:23:43 -0800 (PST) X-Google-Smtp-Source: AMsMyM6UPQzmrewTFvudZ/vuz5nOAnyIfsblJW4pQzh9at+V+S+q4wKuUKuFkZteJ/R+Y+Oi3kPy X-Received: by 2002:a17:90b:4ac5:b0:213:e936:a843 with SMTP id mh5-20020a17090b4ac500b00213e936a843mr42194820pjb.156.1667831023127; Mon, 07 Nov 2022 06:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667831023; cv=none; d=google.com; s=arc-20160816; b=E37L6Ml4+yNnz6OUYUcjfrfCeRhVN45jDERmL0Viy8x7k6FDsLl478MTtvW544Kllj SpTdff6xNUBJWoEYQEe3iTsHZWoRi0X0mo26hAWnlgAALYTv4wzXiC6syvhmrDe9A1lT fcqP0DtZmhlOc0YraAAqqX2TrbakzZvZNMj+Oh2LjLXhZKqbhLPLvXABASHuAMYYtMdg Vzi6RGubBLalvUI00ir33lYjl77d/Jl2MDJQ7DFKGETXJVhRodnlbCOeQnelhy4ycYMV 81egdzP3AmZA7qt7z67F/6eTzJl4ljlqpA/gBce76SGR4gxNXZ9oARJFURnpJVfOkVaJ IkfA== 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=HrXEQGG/m3o0hMbY11og/wMwGQrEN/gibAggQL0SPtA=; b=ymTxQyTtaqgVQ6A3U5rbeAbtJZigCzAybyTT0YLkstPgjV37Ek/9fAGst8dIYUsdih rdolvRZSR5B82qcBTisthc02GCAb1jB0FUXdBMrquSh5LxWyRjrjYPglqFHFFRrL+AKU kPz6sx4c3EuqWnhkaKT26ulDbG5N9WhcNBdMDE98qkfa5KQwQ7g3L9veg1VZY86+WThH VLLXHyWTDZorXm+7Pd9mo7x8JUWqQYRZhbjdxNV8lChF55ufFUgHPLq0uWoqqMWn+V3C 9ccW7S+pGnDoARv49lPuYTlffZq9oq++Wc1RWozFyp4qqfYghmqkB7Fcs0gtut5MKXVa um/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZJIABBsS; 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 d4-20020a623604000000b00536bbfa4994si9007994pfa.345.2022.11.07.06.23.30; Mon, 07 Nov 2022 06:23:43 -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=ZJIABBsS; 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 S232487AbiKGOTq (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbiKGOQv (ORCPT ); Mon, 7 Nov 2022 09:16:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B738F1D0DE for ; Mon, 7 Nov 2022 06:16:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830609; 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=HrXEQGG/m3o0hMbY11og/wMwGQrEN/gibAggQL0SPtA=; b=ZJIABBsSof8Zufabq1/Z2hKR4mPv7ugUtGQX7+O3byXTACBdSXeY81SZe1umutmD9nPJWt jM1rPfi7UDHWD/dtbCdpoKuBWs2IfwbtIoEDfFHhyO2QYZYvcOCY17sYycEx/GQ3PWDI17 GAehm9J+D2mvy90cX6OAGzIirBwlyvByKnAcFJdugWkgH4UxwjjTE3T6nhkolWCu7aYYNS nQPXmxzvv6/lRPxu/NvsGzZstvo17s8gIChTWNc9Yz3jMdoJYSi97QOtNk682v9hxuZDME uiDb2XL4XQLRbnO5PYf+lQU1O9E2z5NY472LZkYcFDA8IHv0JJdlid1UhqdCpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830609; 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=HrXEQGG/m3o0hMbY11og/wMwGQrEN/gibAggQL0SPtA=; b=YNb5nb/11Kv8fmBiMLgjRDH4ietWRBzey9gsumdX/y4uojIWEDAls7EIUZ1H+k1cNIEXEp 90sDo/rIBeMlVSBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 20/40] printk: __pr_flush: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:18 +0106 Message-Id: <20221107141638.3790965-21-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?1748847583129203591?= X-GMAIL-MSGID: =?utf-8?q?1748847583129203591?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. 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 ec50777d0301..d8ccb7b523e2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3480,6 +3480,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; @@ -3490,9 +3491,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)) @@ -3501,6 +3508,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 From patchwork Mon Nov 7 14:16:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2077957wru; Mon, 7 Nov 2022 06:19:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM5UtazAKuFGrYiZgY83x67QtAqi34yTYEGitmSTiBJkIfuDKzkHyZURMdRXkONggNfwULHt X-Received: by 2002:a17:907:70a:b0:750:bf91:caa3 with SMTP id xb10-20020a170907070a00b00750bf91caa3mr48592200ejb.711.1667830785039; Mon, 07 Nov 2022 06:19:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830785; cv=none; d=google.com; s=arc-20160816; b=hJQyEtR02EZt+gR8vA7VOqlMcLatHB6SOJbdlmd6/lRSL5USm9z1YLI3bDargUFEfb aIVP/DtKHptvPToJbBwlTrRyWsvaCz59oJnzHIsI6u5p0TmRrimy6IPfR4iIosCYkoSS ILR1p7A2IAd/9aQ/rCBLqbw+2/iOTB+5YB4r1/MGqrzvUu0zcyvzxOrKOkcSVugyBiif 0mjyKqhMmE3M9TX4m/wnuMnZeYet5+hoHgUIaLAArjTW//QWAAT288fXsYXRe/eOs3nU Tt3roMUlfdw8j7Bv8fwbfpRUs34y3IrUz/a2kKlYr04Krw3Dp7CO+rVrZJGrLJwYuOzK 60ow== 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=ngtNczYH2Al42VnARGnV9no8ylQKQpkMprF/75ICCho=; b=KM/oI6unsQIZmI20oZl5DB4fYLeHL5zSpU40yidTCQGlmG8YWnyC+aZT8YPgO5uvGS D8lKiX8canCFHRchkp3bHFV49BkvA2PvgW2xHJ4XJkCOAkilOTuQC9wyAtiwoaKGTPcw rxThZQnvF8q+Bb9r3066rnzpYs7SPVSgjvCLJHVqll2kiiM24IE5FumP+SdLW+FN4w39 dSZ7NfIPgj7MyloSvpo9P6gx4A2xyBbxxPKGSNSsN74OVUAoyucg0OiR2RC63ByUquqt POUMM9DqheAzKXXmio2DJZhAPtQFtea+XV9yeUN13CnhQ8Q0+CM8HT6ob9FYpOODhBxo PC+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=07HIDbcq; 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 q21-20020aa7da95000000b0045961c7dde9si8499939eds.63.2022.11.07.06.19.19; Mon, 07 Nov 2022 06:19:45 -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=07HIDbcq; 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 S232358AbiKGOSR (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232181AbiKGOQw (ORCPT ); Mon, 7 Nov 2022 09:16:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47BC71CFF0 for ; Mon, 7 Nov 2022 06:16:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830609; 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=ngtNczYH2Al42VnARGnV9no8ylQKQpkMprF/75ICCho=; b=07HIDbcq9ue5xw8Xba4Zoslyp/72IMH+EBXJQAIQRFnSVaOrqHUy5sgB9Lrp6AdNeir+77 E+NQMpzLlbrtY5pFDmEIyAov6t6Q/5nsMRYhKs8r/20uSVaQ+9gO2qNv6lRqjFokazpVN4 Xb6fuOLSif55aDSW7BPJkcz7kWLrNOPblKlaJnmy+D8kl80zMYnhbkV4aH4iaOCi7L24u+ jZfchVCZbjvzSpzazTQhyAlyWVx1vs9NHVXfHsVYdygffN02MSZl0Yb6ibPjYgVMV0VGra BzHJ98J2YpeF8SGAWC7NX8okN2JepYLtwoFi4xREN7d0qDG8w4/yVZQPicde7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830609; 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=ngtNczYH2Al42VnARGnV9no8ylQKQpkMprF/75ICCho=; b=Hz2aKQpH2SxIPxAQcxm3argR2rJV/FpFRd2AWnJSImJxBcMKhwWiKRmL+beifOuxCwmg6P B6y6TVOj4SxFU1AA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v3 21/40] printk: introduce console_list_lock Date: Mon, 7 Nov 2022 15:22:19 +0106 Message-Id: <20221107141638.3790965-22-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?1748847333430370971?= X-GMAIL-MSGID: =?utf-8?q?1748847333430370971?= Currently there exist races in register_console(), where the types of registered consoles are checked (without holding the console_lock) and then after acquiring the console_lock, it is assumed that the list has not changed. Also, some code that performs console_unregister() make similar assumptions. It might be possible to fix these races using the console_lock. But it would require a complex analysis of all console drivers to make sure that the console_lock is not taken in match() and setup() callbacks. And we really prefer to split up and reduce the responsibilities of console_lock rather than expand its complexity. Therefore, introduce a new console_list_lock to provide full synchronization for any console list changes. In addition, also use console_list_lock for synchronization of console->flags updates. All flags are either static or modified only during the console registration. There are only two exceptions. The first exception is CON_ENABLED, which is also modified by console_start()/console_stop(). Therefore, these functions must also take the console_list_lock. The second exception is when the flags are modified by the console driver init code before the console is registered. These will be ignored because they are not visible to the rest of the system via the console_drivers list. Note that one of the various responsibilities of the console_lock is also intended to provide console list and console->flags synchronization. Later changes will update call sites relying on the console_lock for these purposes. Once all call sites have been updated, the console_lock will be relieved of synchronizing console_list and console->flags updates. Suggested-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 23 +++++++++-- kernel/printk/printk.c | 87 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index d9c636011364..47be23be8a88 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -158,6 +158,14 @@ struct console { struct hlist_node node; }; +#ifdef CONFIG_LOCKDEP +extern void lockdep_assert_console_list_lock_held(void); +#else +static inline void lockdep_assert_console_list_lock_held(void) +{ +} +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC extern bool console_srcu_read_lock_is_held(void); #else @@ -170,6 +178,9 @@ static inline bool console_srcu_read_lock_is_held(void) extern int console_srcu_read_lock(void); extern void console_srcu_read_unlock(int cookie); +extern void console_list_lock(void) __acquires(console_mutex); +extern void console_list_unlock(void) __releases(console_mutex); + extern struct hlist_head console_list; /** @@ -213,10 +224,16 @@ static inline bool console_is_enabled(const struct console *con) hlist_for_each_entry_srcu(con, &console_list, node, \ console_srcu_read_lock_is_held()) -/* - * for_each_console() allows you to iterate on each console +/** + * for_each_console() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * The console list and the console->flags are immutable while iterating. + * + * Requires console_list_lock to be held. */ -#define for_each_console(con) \ +#define for_each_console(con) \ + lockdep_assert_console_list_lock_held(); \ hlist_for_each_entry(con, &console_list, node) extern int console_set_on_cmdline; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d8ccb7b523e2..31387ba3fa1a 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -78,6 +78,13 @@ EXPORT_SYMBOL(ignore_console_lock_warning); int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); +/* + * console_mutex protects console_list updates and console->flags updates. + * The flags are synchronized only for consoles that are registered, i.e. + * accessible via the console list. + */ +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. @@ -103,6 +110,11 @@ static int __read_mostly suppress_panic_printk; static struct lockdep_map console_lock_dep_map = { .name = "console_lock" }; + +void lockdep_assert_console_list_lock_held(void) +{ + lockdep_assert_held(&console_mutex); +} #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -227,6 +239,39 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ +/** + * console_list_lock - Lock the console list + * + * For console list or console->flags updates + */ +void console_list_lock(void) +{ + /* + * In unregister_console(), synchronize_srcu() is called with the + * console_list_lock held. Therefore it is not allowed that the + * console_list_lock is taken with the srcu_lock held. + * + * Whether or not this context is in the read-side critical section + * can only be detected if the appropriate debug options are enabled. + */ + WARN_ON_ONCE(debug_lockdep_rcu_enabled() && + srcu_read_lock_held(&console_srcu)); + + mutex_lock(&console_mutex); +} +EXPORT_SYMBOL(console_list_lock); + +/** + * console_list_unlock - Unlock the console list + * + * Counterpart to console_list_lock() + */ +void console_list_unlock(void) +{ + mutex_unlock(&console_mutex); +} +EXPORT_SYMBOL(console_list_unlock); + /** * console_srcu_read_lock - Register a new reader for the * SRCU-protected console list @@ -3060,9 +3105,11 @@ struct tty_driver *console_device(int *index) 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(); /* * Ensure that all SRCU list walks have completed. All contexts must @@ -3076,9 +3123,11 @@ 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); } EXPORT_SYMBOL(console_start); @@ -3177,6 +3226,8 @@ static void try_enable_default_console(struct console *newcon) #define console_first() \ hlist_entry(console_list.first, struct console, node) +static int unregister_console_locked(struct console *console); + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -3203,13 +3254,14 @@ void register_console(struct console *newcon) bool realcon_enabled = false; int err; + console_list_lock(); + for_each_console(con) { if (WARN(con == newcon, "console '%s%d' already registered\n", - con->name, con->index)) - return; - } + con->name, con->index)) { + goto unlock; + } - for_each_console(con) { if (con->flags & CON_BOOT) bootcon_enabled = true; else @@ -3220,7 +3272,7 @@ void register_console(struct console *newcon) if (newcon->flags & CON_BOOT && realcon_enabled) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); - return; + goto unlock; } /* @@ -3251,7 +3303,7 @@ void register_console(struct console *newcon) /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) - return; + goto unlock; /* * If we have a bootconsole, and are switching to a real console, @@ -3330,16 +3382,21 @@ void register_console(struct console *newcon) hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (con->flags & CON_BOOT) - unregister_console(con); + unregister_console_locked(con); } } +unlock: + console_list_unlock(); } EXPORT_SYMBOL(register_console); -int unregister_console(struct console *console) +/* Must be called under console_list_lock(). */ +static int unregister_console_locked(struct console *console) { int res; + lockdep_assert_console_list_lock_held(); + con_printk(KERN_INFO, console, "disabled\n"); res = _braille_unregister_console(console); @@ -3388,6 +3445,16 @@ int unregister_console(struct console *console) return res; } + +int unregister_console(struct console *console) +{ + int res; + + console_list_lock(); + res = unregister_console_locked(console); + console_list_unlock(); + return res; +} EXPORT_SYMBOL(unregister_console); /* @@ -3440,6 +3507,7 @@ static int __init printk_late_init(void) struct console *con; int ret; + console_list_lock(); hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; @@ -3457,9 +3525,10 @@ static int __init printk_late_init(void) */ pr_warn("bootconsole [%s%d] uses init memory and must be disabled even before the real one is ready\n", con->name, con->index); - unregister_console(con); + unregister_console_locked(con); } } + console_list_unlock(); ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); From patchwork Mon Nov 7 14:16:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2081139wru; Mon, 7 Nov 2022 06:25:31 -0800 (PST) X-Google-Smtp-Source: AMsMyM4qNyhep1QF/srOwebaKEy0MeD8TtJK+sffvJ4z5W/5PL5oRa1TQu4llTfxjBNfKxVBeKEq X-Received: by 2002:a05:6402:5207:b0:462:2426:48fc with SMTP id s7-20020a056402520700b00462242648fcmr51214408edd.93.1667831131581; Mon, 07 Nov 2022 06:25:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667831131; cv=none; d=google.com; s=arc-20160816; b=ED+ZkpgSnP3XbKrksg2v6GGaBNNtmIzt2nQv/IlhL3OOqG5igtklZbpykMNK9cV4ID BD8lWRfIrs5fRS6tVi8XDOQsF1J+Qbau+cVc5OarS+Gfr53lv1nPh6UEjW9VFKo4k/Qf mHbnbXBMm9potkL4zfyN4Y6I4daHr49Q/JTczpdTAvj1TdojEfdxZV+XO5NNRZjKeXon iO4fvbGPyQ9VYkc8sEQ7zZxL1sYc2KXGa+j7SO+5x98EMa0CFzezf+47o2DLlI1BvCA7 wrnbzydPfeg4xLXuqHgBLYg8xAHbZNI2aeXHGQQOrfP7XPeb4q+0743GDYw0skupcF1V qwKA== 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=nF9ItXxFwRvPMruy1z9DBE5scW8r/i0a6aD5QIaBD04=; b=IVITvDHX5daI2mQOIGR0pLDBhGuDZQ1CfWe4kLLmnwkpIJ5/SMuV6RDuESBV0xi6hx pPfCPvi0vecWZ3ZFkOTIFs8UV6zpw9CG66/Wyfnaks28LonrhYj0PrT6dmYxHlt6431q Ge1pVl+eEgI/poAOnAE5QglzrXFOYmDd4GX2fu6bH2IXecQudOBAdU9EOraK1b97C5Yj C//JIHdYcSqxp+9sbgzojo30EQ/VA1BZE8l/ANda+SVNOcsGIUGP5XLiTe/J94Fn029u +8rct92LmjkJZHavg7xnwgI/7YXPw92+RITqw5BxgBkBN1oU3L8D9TKE7WHLOYxkE/cy 4eHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4UvomhlS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="WH+/leZj"; 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 p25-20020a50cd99000000b00459a58216d8si8327630edi.504.2022.11.07.06.25.07; Mon, 07 Nov 2022 06:25:31 -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=4UvomhlS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="WH+/leZj"; 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 S232490AbiKGOTx (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232182AbiKGOQw (ORCPT ); Mon, 7 Nov 2022 09:16:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53161CFFE for ; Mon, 7 Nov 2022 06:16:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830610; 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=nF9ItXxFwRvPMruy1z9DBE5scW8r/i0a6aD5QIaBD04=; b=4UvomhlSZAvFX9ARbtGXTPtRcZnlbiu/Os6h1wdRy1FvTcQ6bQarj88zARfxWv83EAETG9 nf9/td7bOpBTfIDuxNdbLnqkaICA9JTZ6vRVCn5NdRYve1U4ImRGBrCvoLINW3lQZhkq0R XWlKuGl0YbQgyUvW2pIoJt1LN2c2ALoD2o1wQ4d0OpZYcP6tfw7/LInHCIy8n8+CHbA/3i 4gmwoCBlnoDkWAEBNYFPMkMGB9O+7CcB0/qfuIvx8+vocHNyPQpkvoBCx9ZvoQ3ETUCut3 9V48M+wRPHF9FZSvOg28q88hMORPAsWxQToGssYL6natRATqyCSp2F4QTw1IxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830610; 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=nF9ItXxFwRvPMruy1z9DBE5scW8r/i0a6aD5QIaBD04=; b=WH+/leZjumZ+rt5PP5ML58idCQJBWKJkxwo/rAmnAt7OoTZ9b62aec54aBDjDx/BwP7Ig2 EzYFB3SXZ0SQQhAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v3 22/40] console: introduce console_is_registered() Date: Mon, 7 Nov 2022 15:22:20 +0106 Message-Id: <20221107141638.3790965-23-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?1748847696359957396?= X-GMAIL-MSGID: =?utf-8?q?1748847696359957396?= Currently it is not possible for drivers to detect if they have already successfully registered their console. Several drivers have multiple paths that lead to console registration. To avoid attempting a 2nd registration (which leads to a WARN), drivers are implementing their own solution. Introduce console_is_registered() so drivers can easily identify if their console is currently registered. A _locked() variant is also provided if the caller is already holding the console_list_lock. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 28 ++++++++++++++++++++++++++++ kernel/printk/printk.c | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/console.h b/include/linux/console.h index 47be23be8a88..cdae70e27377 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -210,6 +210,34 @@ static inline bool console_is_enabled(const struct console *con) return (data_race(READ_ONCE(con->flags)) & CON_ENABLED); } +/* Variant of console_is_registered() when the console_list_lock is held. */ +static inline bool console_is_registered_locked(const struct console *con) +{ + lockdep_assert_console_list_lock_held(); + return !hlist_unhashed(&con->node); +} + +/* + * console_is_registered - Check if the console is registered + * @con: struct console pointer of console to check + * + * Context: Process context. May sleep while acquiring console list lock. + * Return: true if the console is in the console list, otherwise false. + * + * If false is returned for a console that was previously registered, it + * can be assumed that the console's unregistration is fully completed, + * including the exit() callback after console list removal. + */ +static inline bool console_is_registered(const struct console *con) +{ + bool ret; + + console_list_lock(); + ret = console_is_registered_locked(con); + console_list_unlock(); + return ret; +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 31387ba3fa1a..be40a9688403 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3410,7 +3410,7 @@ static int unregister_console_locked(struct console *console) /* Disable it unconditionally */ WRITE_ONCE(console->flags, console->flags & ~CON_ENABLED); - if (hlist_unhashed(&console->node)) { + if (!console_is_registered_locked(console)) { console_unlock(); return -ENODEV; } From patchwork Mon Nov 7 14:16:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078903wru; Mon, 7 Nov 2022 06:21:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM5IDvzJyZQTXMw5Q7G2lcyYU4U1g10kOS5qjdaLTeJnGwj6lJ2heubda0JTPugyhRpVH73C X-Received: by 2002:a17:90b:3a88:b0:213:f069:7197 with SMTP id om8-20020a17090b3a8800b00213f0697197mr39801525pjb.181.1667830884538; Mon, 07 Nov 2022 06:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830884; cv=none; d=google.com; s=arc-20160816; b=RBEH8E+SMfU4IvsiPbHP2Tu6jp5+jKHL6yYlQDsxZ048D+f1nUOQytPM4Qrf1m7B+U uFYrfQXvJq3NHMjWuST9VnjGoeXiZdRVXQwrVxExqYJJkmzz0AbhdDZrqnOTcNAR5rra IfOYzceFZdKs1v8MCijv3S+enYJMIoVOflWApBDC3YhzxwRgmjjqDcZs4YNOJjP+d/N0 aANcOx78aDGeVZb2UsCDP407x9OvEO/BTzjows5bZzXtKv72ckNM9CG5Kmao4SJBp509 ctHAr2/ttt2lJxJrm75F9kF33ndGpqLNWoK5Hm6AGnNoRFGLWJf9nMGGrgkURSJC6Co+ l1pw== 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=PZnHcm5NbZutAYnEPreYIvmpIgElStPef/CZZp0r/mfr5BKRpfHg8dnWTLjwpWPlRO UxO8EoxGqHv0l9L5WfWmhtzgw7cu8hQDJdWTK7RwWaMGAY+TV6jCz2z2wUoIjUPyzbe3 dEtgR0B/fxBIymjHn43e7JylrEECkbk8tuScy6ADG75A0S4fsWYNuvyB+AvkvQZ3PneK RnT/5QPpO8KEWbc0MC1Ge6mmNNeCB895PhwfaNN1Mxi1lYb3SsYw8jRNrewGHMtENKLw MRTiV2JWc9DrLwpNURK7KprP2tMNkxFe4LpXhgB8gvEV1AcMbusHNwMfWZBvTqPDOepx Wwdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=L11tUFib; 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 qe1-20020a17090b4f8100b00202b984842csi11602380pjb.35.2022.11.07.06.21.10; Mon, 07 Nov 2022 06:21:24 -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=L11tUFib; 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 S232022AbiKGOSV (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232194AbiKGOQx (ORCPT ); Mon, 7 Nov 2022 09:16:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3622D1BE94; Mon, 7 Nov 2022 06:16:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830610; 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=L11tUFib1G7F6mY3RRp/5bwlb4Vu20NYOHnRQlaHISa19VU6Kx3MU5faeHGQs3/pP3A1Hv twtd3bKm/hXohF2tydjSaXRXAC46xLsn0KJHs54ZdCdqlm60KzUmbR3tAyr1ZIlPF5TrCw ksUS5iL9ZwtE8sUU4vb40iTPqmqfE3fajjjN/ZLSdODJg2RR3PBZty8oy/Y0Dt93FUdfQA JK94MG1tQfJROwIp4xVvRjI77oM43QV+Xdy+VENbkmA5yJXVUBYyS0KebOZBua4ufJcnfE MPiaak6UX5FqziJ7Ulq7BNesF5q0KQ0nx604yhWALH6YIJsoKIxAYfd4Heqvhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830610; 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=Jzuhyq4WOiz8XELTHvXUgz9BZIWFKbOSmwVTT0Gs76CEl8Q2I+uYnQwlWUsGjK7sw9vEU1 FnPrlsZhC4v41xDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , =?utf-8?q?Ilpo_J=C3=A4?= =?utf-8?q?rvinen?= , Geert Uytterhoeven , Tony Lindgren , Lukas Wunner , linux-serial@vger.kernel.org Subject: [PATCH printk v3 23/40] serial_core: replace uart_console_enabled() with uart_console_registered() Date: Mon, 7 Nov 2022 15:22:21 +0106 Message-Id: <20221107141638.3790965-24-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?1748847437695747477?= X-GMAIL-MSGID: =?utf-8?q?1748847437695747477?= All users of uart_console_enabled() really want to know if a console is registered. It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. A _locked() variant is provided because uart_set_options() is always called with the console_list_lock held and must check if a console is registered in order to synchronize with kgdboc. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/8250/8250_core.c | 2 +- drivers/tty/serial/pic32_uart.c | 2 +- drivers/tty/serial/serial_core.c | 14 +++++++------- include/linux/serial_core.h | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 94fbf0add2ce..74568292186f 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -565,7 +565,7 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) up->port.dev = dev; - if (uart_console_enabled(&up->port)) + if (uart_console_registered(&up->port)) pm_runtime_get_sync(up->port.dev); serial8250_apply_quirks(up); diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c index 2beada66c824..1183b2a26539 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -919,7 +919,7 @@ static int pic32_uart_probe(struct platform_device *pdev) } #ifdef CONFIG_SERIAL_PIC32_CONSOLE - if (uart_console_enabled(port)) { + if (uart_console_registered(port)) { /* The peripheral clock has been enabled by console_setup, * so disable it till the port is used. */ diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 179ee199df34..b9fbbee598b8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2223,11 +2223,11 @@ uart_set_options(struct uart_port *port, struct console *co, /* * Ensure that the serial-console lock is initialised early. * - * Note that the console-enabled check is needed because of kgdboc, - * which can end up calling uart_set_options() for an already enabled + * Note that the console-registered check is needed because + * kgdboc can call uart_set_options() for an already registered * console via tty_find_polling_driver() and uart_poll_init(). */ - if (!uart_console_enabled(port) && !port->console_reinit) + if (!uart_console_registered_locked(port) && !port->console_reinit) uart_port_spin_lock_init(port); memset(&termios, 0, sizeof(struct ktermios)); @@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, * successfully registered yet, try to re-register it. * It may be that the port was not available. */ - if (port->cons && !(port->cons->flags & CON_ENABLED)) + if (port->cons && !console_is_registered(port->cons)) register_console(port->cons); /* @@ -2956,7 +2956,7 @@ static ssize_t console_show(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) - console = uart_console_enabled(uport); + console = uart_console_registered(uport); mutex_unlock(&port->mutex); return sprintf(buf, "%c\n", console ? 'Y' : 'N'); @@ -2978,7 +2978,7 @@ static ssize_t console_store(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) { - oldconsole = uart_console_enabled(uport); + oldconsole = uart_console_registered(uport); if (oldconsole && !newconsole) { ret = unregister_console(uport->cons); } else if (!oldconsole && newconsole) { @@ -3086,7 +3086,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) * If this port is in use as a console then the spinlock is already * initialised. */ - if (!uart_console_enabled(uport)) + if (!uart_console_registered(uport)) uart_port_spin_lock_init(uport); if (uport->cons && uport->dev) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index d657f2a42a7b..2f910f2bbe53 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -743,9 +743,20 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED; static inline int setup_earlycon(char *buf) { return 0; } #endif -static inline bool uart_console_enabled(struct uart_port *port) +/* Variant of uart_console_registered() when the console_list_lock is held. */ +static inline bool uart_console_registered_locked(struct uart_port *port) { - return uart_console(port) && (port->cons->flags & CON_ENABLED); + return uart_console(port) && console_is_registered_locked(port->cons); +} + +static inline bool uart_console_registered(struct uart_port *port) +{ + bool ret; + + console_list_lock(); + ret = uart_console_registered_locked(port); + console_list_unlock(); + return ret; } struct uart_port *uart_get_console(struct uart_port *ports, int nr, From patchwork Mon Nov 7 14:16:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079566wru; Mon, 7 Nov 2022 06:22:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM7dDV4jHhNe3sT07gncM1i7/oOXf+VRjr4+gZgcNbsDu0l2a41cczjEramV1y2lYBK8CSRv X-Received: by 2002:a17:907:62a7:b0:789:48ea:ddb0 with SMTP id nd39-20020a17090762a700b0078948eaddb0mr46327692ejc.575.1667830951853; Mon, 07 Nov 2022 06:22:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830951; cv=none; d=google.com; s=arc-20160816; b=EY6yVKeWzFxJepBB1SKegK5QrPn2m07rWqHV5co8LCSGqxczOTLTChVxrQO2nZNpoW 4mwe0UBypFwwZ5jdzc6fGhWYi7Mdepf8M4d+1saYU2OMoKNNsCXwKdqKGQJG+wr0vV3s shd+QEjrkJ2iEdSicoutSzwm8a+000Hh8HAyNSvJ2iPWpZy7PmR8oK/yOIaZ/ND1Pqhd RVUsFzNpRT6vFRVirnS04Xg9WrPIugbgjoLnFiX8n+iTcGYGw3PbWTDqUxN9xxFywx+7 aovRzXQl3n0msQd+pb+9qxhbOvS3L3Nkd0WIIo/zeA2C2w6zyPgk2/YDgE0CPLmCsjOk DBlA== 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=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=Cza9sFRKk8n5akjgJ2mmJdkQ9ugpKUuXfPju9qgUElhc6VgNX2o7MUD9NNfWqny6LO 5Ou18uauMtRV+/V+/VCMG9Xgyp7DOGblUCZkMG9aVitHoN8cWCwp6Vk7ZXvqwqxkmduu hyaoMpjpSYxBOzDIqIeveufdLdorVkpOdgZIFPXP1JqS5gzLMFeXrYiUCVFiAclR5QoH FSM/oMNB5nqA6hK0fbAKVhahRLrSTfsGUpOKV8iBIhskHymy2PmC1lLmK5mdS7iLfJvJ alttulEaHoh4swDcfqjMA+hng9a7mTc5GKnxtuZQcGZqWfa8deMUAUxAQOvLGa42t+3C nmcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vQeoLKWE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 eb6-20020a0564020d0600b0046453c39abdsi11312007edb.104.2022.11.07.06.22.06; Mon, 07 Nov 2022 06:22:31 -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=vQeoLKWE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232380AbiKGOSr (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232202AbiKGOQx (ORCPT ); Mon, 7 Nov 2022 09:16:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 943D71D0E0 for ; Mon, 7 Nov 2022 06:16:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830611; 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=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=vQeoLKWE1k4R6O3nMnBfOLEHIpwhVsbvXcVbHBj6NMymPvMJgyWKk8a+SWMhfut8ws1okf Rqf9Cz5bLPDfyH+IyWepofmoKnEQOGvQ1iHo3uNlukZnoFRP/pK5Sn5O02G21xpmFqMb+u hlTpVg1FSFH8SZ5WJyjH7IZ6QWr3b0vra6/IicriLiXUPXoi2kY+4Ry5gxKoUarCzr9z0L Jn/x7yIxlwj3fKZG/3gv9EsOyIpQRYwIlQqQP0/vFXqq5R1VhYgWlvhKaj+E2sPNiXxMoP PRI0wvXScmB0NbnXYTOF9ujFHajDe8JAN/lBQ8WvjFv+BmWum45rO42CvDc0XA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830611; 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=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=T64AeLS2skGi+8SZjeqwwtVGih9S8IofM6v6ACJ2ABibEKOmMbg6PouGq2vD32FeJ/mS4n /VBpHt26tQKzOUBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org Subject: [PATCH printk v3 24/40] tty: nfcon: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:22 +0106 Message-Id: <20221107141638.3790965-25-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?1748847508141054346?= X-GMAIL-MSGID: =?utf-8?q?1748847508141054346?= Currently CON_ENABLED is being (mis)used to identify if the console has been registered. This is not reliable because it can be set even though registration failed or it can be unset, even though the console is registered. Instead, use console_is_registered(). Signed-off-by: John Ogness Reviewed-by: Geert Uytterhoeven Acked-by: Geert Uytterhoeven --- arch/m68k/emu/nfcon.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c index 557d60867f98..292669fa480f 100644 --- a/arch/m68k/emu/nfcon.c +++ b/arch/m68k/emu/nfcon.c @@ -49,14 +49,14 @@ static void nfcon_write(struct console *con, const char *str, static struct tty_driver *nfcon_device(struct console *con, int *index) { *index = 0; - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; + return console_is_registered(con) ? nfcon_tty_driver : NULL; } static struct console nf_console = { .name = "nfcon", .write = nfcon_write, .device = nfcon_device, - .flags = CON_PRINTBUFFER, + .flags = CON_PRINTBUFFER | CON_ENABLED, .index = -1, }; @@ -106,10 +106,8 @@ static int __init nf_debug_setup(char *arg) return 0; stderr_id = nf_get_id("NF_STDERR"); - if (stderr_id) { - nf_console.flags |= CON_ENABLED; + if (stderr_id) register_console(&nf_console); - } return 0; } @@ -151,7 +149,7 @@ static int __init nfcon_init(void) nfcon_tty_driver = driver; - if (!(nf_console.flags & CON_ENABLED)) + if (!console_is_registered(&nf_console)) register_console(&nf_console); return 0; From patchwork Mon Nov 7 14:16:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079565wru; Mon, 7 Nov 2022 06:22:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf7+XkjWaZhRwxUIatCoo5wj724EP8mrG6DWnAwwr8ppW2lixSXi9wYo6wmjgg+hBmOVw08Q X-Received: by 2002:a17:907:6e14:b0:7ad:b45c:7e0d with SMTP id sd20-20020a1709076e1400b007adb45c7e0dmr1711980ejc.413.1667830951858; Mon, 07 Nov 2022 06:22:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830951; cv=none; d=google.com; s=arc-20160816; b=j8rksGShnoGDixOTYw3t9QgZquKTlkY2lSO2NPMiPL3AsXTDD3sQvEJ7QdmpPk5Cqw dsrE21L9lPtg7M/nWiz5S5yll6A5Iy4Htx8dVyDRXQAFt1QL6Z9LnFyYa4lYm6ssfntV Sdrqdb6MTq26W7AItF8if0Hv5fkJiXJpELpVgU5fdG0eLjm43ZdRtzO5jkjiSZPRsU5v OamshgGP/OiN4sTkDqzNsOJJ+mq3Fty0atEhuyVcHTRoyuUIVsNCjDGaF2s9xH3429As YNwBWpci6NyE3cdZi2/jOdrtvtkGLEhzU8J4ZTisQd11R9haxAMGtldABZCPg9fys/nO /48A== 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=LyZS5uMfYU/cffNHBb1twOFg15bMKL8z2VkdH4RqLnI=; b=qMOKg9gZqf7XyC6evVJrtfUntQF+/+cgJk8hc76GJTytx8GpFuUXl9ogxiOwQRYIGU UmfiotMS6y/9xHeHGBJbQ9CZPPSkUYOFsSfcXhmgDvQyJpbZ7jbzwIDiHsb58n4upC/u tCNIAowl9cVofKqW210c5DcdmuxWXdNq1J09Pbg3VrjJ3Py0IeoI95AxoFFK5x/kdYkT 0Qp/yL12pYSwzX7lhugOx/lp0BY5TR0Iyv+3/Vl+lIVsxwRhKp3N28qr4xQUPft4CfAt DkuK5bmAHhjRoNTyZvK7DInss4nlJ8s0UvE08PbtC+6vyHmqAnAqa8v2PTZlFNV4igqN 9BQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GnMxuG19; 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 e6-20020a17090658c600b007ae4c686a4esi11435077ejs.159.2022.11.07.06.22.06; Mon, 07 Nov 2022 06:22:31 -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=GnMxuG19; 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 S232222AbiKGOSp (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbiKGOQx (ORCPT ); Mon, 7 Nov 2022 09:16:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE9541D0DC; Mon, 7 Nov 2022 06:16:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830611; 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=LyZS5uMfYU/cffNHBb1twOFg15bMKL8z2VkdH4RqLnI=; b=GnMxuG19cPyqFuF8fXFkyp6BckB8w0fTGzzoUGJW8OTZHW07pe6cy3yQ25K6+xuc6WJkZa B0OrWffeC4/SJIQIT9xZt/HoXDv4h4MxdvAwssBmQqJM24HIhAIsPhBzkzGE9zvU33IcQT D2P3bTLx/IkzIFXS4KfIrlsBroeIvcJKo2YMSTI23KfFDdpTkFxT1gU7vbNMUyG3iHI6+h uN7ALdebM9zPKMj3un1XnXnedrgbRFVNUxpMdtNWUryG53Q34bInxDwv86YnyZ6srrhERh /7nrPnXmTf9zKKAlkUi4DAVF7yXXGyC6fbqRe/BupROVIvSHYPn7TPVztHThzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830611; 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=LyZS5uMfYU/cffNHBb1twOFg15bMKL8z2VkdH4RqLnI=; b=BXFh3bD41IX3Cmqunb4gjOg4lZQztyE321oMZc+jZMFZefEKXR4aE/imyimsbONLhG0A9F H3tEdsW+XTu/0VCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-efi@vger.kernel.org Subject: [PATCH printk v3 25/40] efi: earlycon: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:23 +0106 Message-Id: <20221107141638.3790965-26-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?1748847507746407267?= X-GMAIL-MSGID: =?utf-8?q?1748847507746407267?= The CON_ENABLED status of a console is a runtime setting that does not involve the console driver. Drivers must not assume that if the console is disabled then proper hardware management is not needed. For the EFI earlycon case, it is about remapping/unmapping memory for the framebuffer. Use console_is_registered() instead of checking CON_ENABLED. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/firmware/efi/earlycon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c index a52236e11e5f..4d6c5327471a 100644 --- a/drivers/firmware/efi/earlycon.c +++ b/drivers/firmware/efi/earlycon.c @@ -29,8 +29,8 @@ static void *efi_fb; */ static int __init efi_earlycon_remap_fb(void) { - /* bail if there is no bootconsole or it has been disabled already */ - if (!earlycon_console || !(earlycon_console->flags & CON_ENABLED)) + /* bail if there is no bootconsole or it was unregistered already */ + if (!earlycon_console || !console_is_registered(earlycon_console)) return 0; efi_fb = memremap(fb_base, screen_info.lfb_size, @@ -42,8 +42,8 @@ early_initcall(efi_earlycon_remap_fb); static int __init efi_earlycon_unmap_fb(void) { - /* unmap the bootconsole fb unless keep_bootcon has left it enabled */ - if (efi_fb && !(earlycon_console->flags & CON_ENABLED)) + /* unmap the bootconsole fb unless keep_bootcon left it registered */ + if (efi_fb && !console_is_registered(earlycon_console)) memunmap(efi_fb); return 0; } From patchwork Mon Nov 7 14:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078186wru; Mon, 7 Nov 2022 06:20:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM4A3Hg7KIEcjqhRCFlMJXX++MJX1H+mkOkqIw8aRwc4K/QS/pYfI7AXR4E3yIy2RXuuO85A X-Received: by 2002:a05:6402:548f:b0:457:ed40:5f58 with SMTP id fg15-20020a056402548f00b00457ed405f58mr50443321edb.408.1667830809869; Mon, 07 Nov 2022 06:20:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830809; cv=none; d=google.com; s=arc-20160816; b=Wy3zfXwsqGKt7x9+UqTdJFAkFGtHZnzgxndqcwv5FMfnH/wM8yez6xnDTnnhSVBAy4 7ef0Xr8KCDaRSkzSUdnYIOa4WSRv31GRWp+j5mihDTtstRz3tGVM2Cq05xX0HFKEtJ25 4FUiMjZ39IPiIC5l/va+WvVp3BNmT43dK1WxOIByAGv/+pOiri8zWUHED00E1knDTusT g4+VdZNqwBg1ZmercXDs4JbTIF1u3vBcth9evBtKeEJJxq3hsqcwIIxqVQGJppoBHcxt P8ibbZdr+3akm+v8AR2QH2TC3XS9CXyMOyq+0JiqPUnWxXsZHvdE9IkRmAaxaTpM93zX qzqw== 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=kStKa0WjYDeKLxGc8aWMlTa8ztLKd7SaO/mrohxpQTE=; b=oJWjkunKgqC81MMHWNxlt7rJKMnKYnW28NzEfjlh1LuHw3OnTtNlout2GzvS48tehK XgvLT3qsr9qEWxG8C1zs8re0lwoQ4NU2CD2uRyGF/IVjuVMoPVhv6kBQm5RjBEGBOhMd eDch2usMu2G3iT/JYMRfh5NDOr0jk4ZyfZ6JxB462E5MqH2P34X83dITi2FIbiyDV31N 0r0vxxjxsqiBoIg4OgZBnF7VltzTSr7TSIGxWboeVOAGiJz0oRnoNGyvDsD2l50se2ce 0bKpZSypb6TDr+8KESbfmTr0rwFzJwUCkjFDPmXhJk+COJeCW/k+RdlW0ntzILIOEsWG HnTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="pz/gQ/1s"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=l5i2HOU0; 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 lj14-20020a170906f9ce00b0078ae5192906si7236251ejb.193.2022.11.07.06.19.44; Mon, 07 Nov 2022 06:20:09 -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="pz/gQ/1s"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=l5i2HOU0; 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 S232369AbiKGOS0 (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232217AbiKGOQy (ORCPT ); Mon, 7 Nov 2022 09:16:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B541CFF1 for ; Mon, 7 Nov 2022 06:16:53 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830612; 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=kStKa0WjYDeKLxGc8aWMlTa8ztLKd7SaO/mrohxpQTE=; b=pz/gQ/1sVexBvgNtGDYjCRgwbJbEvU2eH4YV9pYimdcqvWP2I+B1duvHeKAbgYv5Lr07fJ 3nSzyHqOLORAovjTQxpM5UWGC5xmpELupKsgitL24XB/k/6CbYqbdrByQjGVG32ntimIJ1 USj7SHbao60ntXl7F0B8/Dgf2I0ETZl2HOE6SvWVzvw6syMMJ7jkBNFcCqtzk2ci0rb/h/ nzelv8Zhcyl2iQtUuncRNBpI6lOSso410y4Bkv7m8+4KFJrOnAiON98KbP8i6OKblxuMiU 1Npm/OYCrsXehm0v8UpG8OKzvnQOtYRcwsNbXQ+4ALpv4hu7eoaYI7SzAqD/Bw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830612; 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=kStKa0WjYDeKLxGc8aWMlTa8ztLKd7SaO/mrohxpQTE=; b=l5i2HOU0W5lz3c3aPgWHXD4IoEYHwPnmVudjTMsP1yxWvp9K9lwAxVDh5Sa/IY4JgVQe+k TL9RD2dZn3zPqhDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linuxppc-dev@lists.ozlabs.org Subject: [PATCH printk v3 26/40] tty: hvc: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:24 +0106 Message-Id: <20221107141638.3790965-27-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?1748847359407973863?= X-GMAIL-MSGID: =?utf-8?q?1748847359407973863?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/hvc/hvc_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 4802cfaa107f..a683e21df19c 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -264,8 +264,8 @@ static void hvc_port_destruct(struct tty_port *port) static void hvc_check_console(int index) { - /* Already enabled, bail out */ - if (hvc_console.flags & CON_ENABLED) + /* Already registered, bail out */ + if (console_is_registered(&hvc_console)) return; /* If this index is what the user requested, then register From patchwork Mon Nov 7 14:16:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078254wru; Mon, 7 Nov 2022 06:20:16 -0800 (PST) X-Google-Smtp-Source: AMsMyM7dS4GFrAM/0zz0nipa46IzoBdMwZGBeZGufiPpyZt027Z6JETopvANpLdPrZg0yf974pS7 X-Received: by 2002:a17:906:847b:b0:7a6:2ad9:298 with SMTP id hx27-20020a170906847b00b007a62ad90298mr47429368ejc.90.1667830816529; Mon, 07 Nov 2022 06:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830816; cv=none; d=google.com; s=arc-20160816; b=QfLFfYTjwuRaTCXVdWhrnmpIaAAveVZSxgykCqP7V8X1l8FSJ3F8gwdqIe4VQAn+N3 /4TmZ1bvnJH0RJyjfHX5zOKqG0kEj+LXpmpgsVjWqstC9VF85+dBySl2OMoA4iQ7/7Wy 5oOfWK67VvT+QkI5EVeZ/d3YAMIOBglnyzf57Fwe7Fns7AgM8O90O7PH4odfwWM5butx n4jdomOAlWYbsyNsqhgcR+ZvR5VRiD69FpdvgQbdYR1PI28YZGJdi7kQhcq4lf6ZuoAG YFPeQI58UetfqyAEJuI3bMp2IsNMj2zFY+iWBEBMD3UjoVIz1Qjd4AvpPgxacGLHogPB /zTg== 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=rIFVvGo20s9m3a2ORQZJ6diZh72O0KdKN/vykqpOG6M=; b=QblSDsidHT6EMHfyuSpdTNl3P9q/HAHRHsQPm1khcll5wSpbKQ65aHWgdX/H6ccxhd 2Y76wdREm97ojzF/xpCp+KROVFeYzVM9z3PAI3WxuSswhOOJt/RJcX7BFwKAx4XMIFiz sDUZ2Lw+S+tlc2A2zq7dmRSmUL4MPFE1hJDSBvcMePSOddt3cN2pp9HIl4VFOSkvPZGO 4aOmDAtJRSel/ZEf4VGv2Xr2H6FU53erj37KVEtGBV3M3+BJmF3VCqw2NULFVqwMjJOg 2O1/oJigyZJTrk2E4Vcf18X8EN47rnfoObc/ECHAwNodpHA3i61Lyd1JxgdSb+nPzeWr +Dtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MZJB5lX4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 o11-20020a50fd8b000000b0045fca739593si8381394edt.188.2022.11.07.06.19.49; Mon, 07 Nov 2022 06:20:16 -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=MZJB5lX4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232338AbiKGOSf (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbiKGOQy (ORCPT ); Mon, 7 Nov 2022 09:16:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE4911D0F7; Mon, 7 Nov 2022 06:16:53 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830612; 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=rIFVvGo20s9m3a2ORQZJ6diZh72O0KdKN/vykqpOG6M=; b=MZJB5lX42WcNqfQf/8Uy4aTmZOi552MX2XYZ5hG9OlguJgac67mF5BEXukX1d+qbynQc/L P13tXHiAAu9wRwaCfqN6TyjkrzUUkQNJA/l3DU53O6LkfVv5tI+qVxI2f8nZUIPn1b5S/E O3beP8Dac2x2r2ouaorlV9viccM6cVWYvKhliiBWguW38a07M6JzMV/CO5GqoyXLcp/hKW jHXOW3VMeEi4kzZGi3VPUxBDKxLeKLxdBzyFBTIAN8V4rNN9ZDGsAaQIH32Ozl5KcV6av/ 7DTDlBs1hTid01SHsrwLPYbWLGGbdYgc/xSMf9EqSBy9atMNjA4uSA1+zIlH3A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830612; 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=rIFVvGo20s9m3a2ORQZJ6diZh72O0KdKN/vykqpOG6M=; b=ALG9eKOl3s7Xt0eEnwNoL/F4GKWQMH6+qAGkok3zgVPzcLXBeHOOBayw+8bjy9jYTFLvj/ pW3IJBvcGaP2m1CA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v3 27/40] tty: serial: earlycon: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:25 +0106 Message-Id: <20221107141638.3790965-28-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?1748847366499662983?= X-GMAIL-MSGID: =?utf-8?q?1748847366499662983?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/earlycon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index a5f380584cda..4f6e9bf57169 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -181,7 +181,7 @@ int __init setup_earlycon(char *buf) if (!buf || !buf[0]) return -EINVAL; - if (early_con.flags & CON_ENABLED) + if (console_is_registered(&early_con)) return -EALREADY; again: @@ -253,7 +253,7 @@ int __init of_setup_earlycon(const struct earlycon_id *match, bool big_endian; u64 addr; - if (early_con.flags & CON_ENABLED) + if (console_is_registered(&early_con)) return -EALREADY; spin_lock_init(&port->lock); From patchwork Mon Nov 7 14:16:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079630wru; Mon, 7 Nov 2022 06:22:40 -0800 (PST) X-Google-Smtp-Source: AMsMyM5rvfyRlW6V+wkd/A++eApGNGPz9q+IHVllG9JYupc4CNGmETUyKqz6BemhRBoVRLaWDe3Z X-Received: by 2002:a05:6402:1710:b0:463:69ac:a679 with SMTP id y16-20020a056402171000b0046369aca679mr40744976edu.184.1667830960141; Mon, 07 Nov 2022 06:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830960; cv=none; d=google.com; s=arc-20160816; b=CP/Tu1fAqW9xB0SX7qSBRgQNcF4OHVMMH87oCGDCwHsWIHWuYE2dsU2vAC+u1yjMAM sukzlh4TqjqlD+CILtZ6BVbsKza/9cKmSsCbMxss54jGH9xkQ7noxuvD8gO4gBJc+Nm+ tam4ltTxlfqGILFElWAHdFXpDCUBKAOzJc+RgsslU4RlOyhcPI580nFlFZynV/9xUHWH lbFuhQ5OFtt4/rupwU4bXOyIGY8tmfCajpiPth91S7Nox04LhVTbk5ArP/qz19YkyMtU uJCvYk5iTamy6babBNRRkQtNr4Zo7hiaHzEHHNuG+UJjguVk9zRZhf7pHHhMSbQ3oYLZ OAUA== 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=4rGpLRcOY1creCvrfbqnEjYKevj7W16ctfWNljowJxQ=; b=oRVMmdC1nNomWY1sQmkc8w6kphEXy5iGliIoaFOAPWuq/2fhtnTO/z7O6V3sjQi/sq p/bcvV5S6iNhmWrRBk1onsKKgIprBT5OCEVPGDBJBd2ebsVqcvyXnOhugk88auTXwYqY cca2iqjSvl+HWWt0WYxiPbIC5mdVriYo6BPj7lRa2IOIxGiVCrx1yf3Ynbh45+bCN+PP cWWQtRHUNYDFyYi5IJEYWhwDGPSJVKfXj1YuoDhw9mXtoX0CO2MnA3E6pdg+YEay1ItP oWFds8AbW7nlVwXuopUGupcTFDjN0RHjF3zm2F6nc9rpCSNyLWmZh2P/ihnc24j77b2l ekIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vZt3kVua; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=eMtcNfNi; 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 sd6-20020a170906ce2600b007aa8a5131a3si6288440ejb.181.2022.11.07.06.22.08; Mon, 07 Nov 2022 06:22:40 -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=vZt3kVua; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=eMtcNfNi; 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 S232383AbiKGOSx (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiKGOQ4 (ORCPT ); Mon, 7 Nov 2022 09:16:56 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6260F1D307; Mon, 7 Nov 2022 06:16:54 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830613; 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=4rGpLRcOY1creCvrfbqnEjYKevj7W16ctfWNljowJxQ=; b=vZt3kVuam9R9etVm3fVrEDFZRNLO6OuUaHAFGZLCS/ARafi7y9g+tZ3JIlBY4xViYlIDUD XVgslok4nnZBYTbZ1KDUHfVATLHiT/SL4wXCc9ayaNzxG2p11l9DT1lmoXu7hWOMdXm/4Y 0T6pvnDP0vP7VuAMopEbQ5TSnXdFNYBvj4udWeynojuCdS88R+oe6dMqSs9g4sdPGpG6ix 9N+cwJPjdLZHSCou9vTvLp55ApNi5p4xygKM2NnfO78PHp2jFGdV0Hnr9x1hfTdK2hb/FG N+YPS9cFQgpiVZ7dtdl/tAKCAH/BZCVRl5uyKE9bVw44ukqfBB4KkUa/3taocQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830613; 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=4rGpLRcOY1creCvrfbqnEjYKevj7W16ctfWNljowJxQ=; b=eMtcNfNim/ymbtlno+leS1ndXvplDak5vcnkw8YUVpPhIM1oojFhJO7IXBUaMMuEQIJ3mR WGpBhCUMEGgilwAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v3 28/40] tty: serial: pic32_uart: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:26 +0106 Message-Id: <20221107141638.3790965-29-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?1748847517226875150?= X-GMAIL-MSGID: =?utf-8?q?1748847517226875150?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/pic32_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c index 1183b2a26539..c38754d593ca 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -843,7 +843,7 @@ console_initcall(pic32_console_init); */ static int __init pic32_late_console_init(void) { - if (!(pic32_console.flags & CON_ENABLED)) + if (!console_is_registered(&pic32_console)) register_console(&pic32_console); return 0; From patchwork Mon Nov 7 14:16:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079593wru; Mon, 7 Nov 2022 06:22:37 -0800 (PST) X-Google-Smtp-Source: AMsMyM7GFhtVtkCVG8sxfjqNkGBZNfHQ2aB00dBNGOHGMDhgXKDQCeW5g3IkVe3hxzQ2mXKQi7sx X-Received: by 2002:a17:906:5e51:b0:7ae:32ca:78c9 with SMTP id b17-20020a1709065e5100b007ae32ca78c9mr17063798eju.166.1667830956950; Mon, 07 Nov 2022 06:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830956; cv=none; d=google.com; s=arc-20160816; b=GG7y+3iL3QKNQ0B7awEY5YEP4rB97d8uu6cP+EifKSWEfAA6b7P+/DWzcw0S1hwYci /UuZgwSKaEP+UQssu3OUJPpWjlsaS4VdScEBM7POjOJGyc9VyH+XdELZkhfp90L6myh9 tkuRPhRO/piDoIoRIJNomdRQXSeQmWLJiPIFm5v6wzOF3nzkcCNxjzud5n27TAWSxQxM iDU97luCd4dRHVGorKwW5bh/NQqIrC9ov412msPhpragI9TqMeDLD18u5QLafFK5bZBe 056MTEDHoefh137ODLq8dyvA0IFDi0aI1EEqMoJirN8i/fdw5yepoTZCg9Ucqg1svWjp WyUQ== 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=CoILEQrelgclmLZ3I9Bp0tGORaTvK064dNQM6uNGkhM=; b=DBoEEyVlC8IQ+9DA5Gae2wkgPaptx422rvcE5jopItDF71rbWU92T5padqmBYBb7Os DUKRN8DsCQHyXkPM9tPr68nlqAW1nNAjf7/a31iQ1oYY0h88lrH/TSOzjz/h7YC+Zm0N epW8FA4cKgGCB9lz5Bou3b1SbonfdiEwtquKsIoLI3PjAITw76d7kMU4lNtKF+Ydv3cB UDEKko+bJa4f1X5hcH5TfJpYRTFi3gYhAyChzjMDIJUCxcf0uTf2EiYXOia4Xbs/07wX btPZ455cTCA2e9jL5gzHHbhvdkh+FSIRUfHagdEofSaXpdbAfwW7cG42JeoLSL/WVcKS K/TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Hxxn3M2Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 gs17-20020a1709072d1100b0078da5f6ed9esi11533505ejc.779.2022.11.07.06.22.12; Mon, 07 Nov 2022 06:22:36 -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=Hxxn3M2Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232246AbiKGOS5 (ORCPT + 99 others); Mon, 7 Nov 2022 09:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbiKGOQ4 (ORCPT ); Mon, 7 Nov 2022 09:16:56 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBFCB1CFF0; Mon, 7 Nov 2022 06:16:54 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830613; 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=CoILEQrelgclmLZ3I9Bp0tGORaTvK064dNQM6uNGkhM=; b=Hxxn3M2YEUZ39fDg1K8VMLHgr24Bztgip7MtE5GFTWejedYOTXhyeCdbJCq8S0SVuwAxFc 3oTBTm6DkBylJdeMGlliYzNR85r8VodFZFrkpYgdM65qN8DKhBX8uCJKr2UqDetCyshPao sAJYhlBlmDpL8nYkXuOroyEJswxN5o/4Ys7rc9rj86+MCORH/s9u3VNaae6lCg2dWGxRx6 hfp2r5D2XnHf/wFBhotQFHJQB1yknP8uirmLq2S7vyMZsBouryFE3yk9PyOVdqCpOY6Yf0 HAq3GA2+wRvxbwPNHnKGakc19IHLEWvlOWTujQcmh1kULfUo3DCYrP4LRMsIMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830613; 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=CoILEQrelgclmLZ3I9Bp0tGORaTvK064dNQM6uNGkhM=; b=KQEYSXXDSnadzvFVpp56SFo7RXRXwHEShMf1hEj55GJAlbhKPlEHgKaDRBj6yuP6iS7AQ6 vpWqnAdI6D3taZBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Alim Akhtar , Greg Kroah-Hartman , Jiri Slaby , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH printk v3 29/40] tty: serial: samsung_tty: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:27 +0106 Message-Id: <20221107141638.3790965-30-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?1748847513491711951?= X-GMAIL-MSGID: =?utf-8?q?1748847513491711951?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/samsung_tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index 77d1363029f5..9c252c9ca95a 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1732,7 +1732,7 @@ static void __init s3c24xx_serial_register_console(void) static void s3c24xx_serial_unregister_console(void) { - if (s3c24xx_serial_console.flags & CON_ENABLED) + if (console_is_registered(&s3c24xx_serial_console)) unregister_console(&s3c24xx_serial_console); } From patchwork Mon Nov 7 14:16:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079823wru; Mon, 7 Nov 2022 06:22:59 -0800 (PST) X-Google-Smtp-Source: AMsMyM7vb6dHm4H5XbEOfKJSIuVR1q510zGfOKu141U53LMI3Zh9zPv5IRmlwX4cJrVoCPySDtxI X-Received: by 2002:a05:6402:1ccd:b0:459:aa70:9e12 with SMTP id ds13-20020a0564021ccd00b00459aa709e12mr50448610edb.206.1667830979316; Mon, 07 Nov 2022 06:22:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830979; cv=none; d=google.com; s=arc-20160816; b=UNmginfkX58llNL/9zrXcDRBduuD4xg7RugFuaUtCgGsBKznvr1NIau/KsRomvl6sf CIPCMelRL/YWyc0XANeXT3geFGGEIKNfBzFYzz+BvjI4/bMl+x8wZarg06h3jXHRGhqi ndPBpR79NOM+Q+IEOfXs4by3yYErD4A1znK19ClrM78gHkDmw5D+ywyuhKe7KyYlTBN1 bnb0/W3tbjs1TbC2yy1TlEj7UVrIvj2MKdjbKmG3voZ+FXum4RChgVqBq8w6Ux1NSbjB RZGGV3dajonqpItXo1BC/6Grmins8pWDCAWXjIHA3o9noDne31oGSoZtcyk+57jfzR4G bjYw== 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=yx/DFCpNBgX6OWBk9yiOlgcjm4ySqR68jcfyCdumqVE=; b=xOMeDIPzFIZz5K8eQyLzRbuspTBCvvCgC/QdYQ4q5gQrXfDjnxYfICKJmB4aoGshJN +PbRNpdo1bsWPwvgAOj5ZZXGlooycHaoH1Qo1iwkzlTkUZqha6AQkiDvhFwgiE4VcE6G XcHlUdXK+yvokvHVbi899Eoik8HeoGWwGkzfHTvt86vvs1dxxk4P036tQw+bi3SVvB9K Twl0o0FwlRf7r3C7+iTO+eE76ZYYdExojyg/El8Sc/TqBta60ZrmyulUuuBwB09CoMzF XUPnaeksT4bhuq2kd5MDMAbZB31YFG9GzhtX0ke7lHNrTO2Eowh+rAhaLdvN29yzo06G 5heQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RwsDLfjO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 m22-20020a056402431600b0045d03c18e5bsi11582229edc.560.2022.11.07.06.22.34; Mon, 07 Nov 2022 06:22:59 -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=RwsDLfjO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232398AbiKGOTA (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbiKGOQ4 (ORCPT ); Mon, 7 Nov 2022 09:16:56 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688871BE94; Mon, 7 Nov 2022 06:16:55 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830614; 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=yx/DFCpNBgX6OWBk9yiOlgcjm4ySqR68jcfyCdumqVE=; b=RwsDLfjO6P/9jgKRgz3idn17Rse6DcJyvmEF99pKAn+m89IIv/rL+ewmMLnsbzlze/PPhf xbhN7RALZQjSju4ionne5siq/3B+wVv/dHr7EQe72v/ahvzE6lPGATLVQ5v/cCBWiDrH1R N9ymsPzyrfVCeWZtinJg4mkwATpsOqGeq2f40LfKS7EVBNu9aPuOrGf1TwrfO7BlKUG7da yNtoEDcVs5XBVWJslZaGkeDa7mgggQ+GLzypRERytrX4KoHPipjBDeMy14tJjapPYrdVFF ZLed3exlDX2omJt6OHNDpbt0CfL4AAHGj2VL1sQQs4bzLP+ctkVWJtqLtsBJkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830614; 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=yx/DFCpNBgX6OWBk9yiOlgcjm4ySqR68jcfyCdumqVE=; b=KiZOPxkkpXsT1r8oIQ23HB7CG/MNqWqgZoYb11rwfEFel9/QBfZxbw/TR1RrKjqA95BbDo WF8ujwxtqJiGpPCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Michal Simek , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH printk v3 30/40] tty: serial: xilinx_uartps: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:28 +0106 Message-Id: <20221107141638.3790965-31-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?1748847537019222556?= X-GMAIL-MSGID: =?utf-8?q?1748847537019222556?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/xilinx_uartps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index 2eff7cff57c4..0cbd1892c53b 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1631,7 +1631,7 @@ static int cdns_uart_probe(struct platform_device *pdev) #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /* This is not port which is used for console that's why clean it up */ if (console_port == port && - !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) { + !console_is_registered(cdns_uart_uart_driver.cons)) { console_port = NULL; cdns_uart_console.index = -1; } From patchwork Mon Nov 7 14:16:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078726wru; Mon, 7 Nov 2022 06:21:02 -0800 (PST) X-Google-Smtp-Source: AMsMyM6gkk7NW8NO7WTnziJ7yQOtChx5spKo7XtFH3WsBrKDx3ClV2MFI7qCQEqldPrLQ9ECp+qu X-Received: by 2002:a05:6402:d0b:b0:458:a244:4e99 with SMTP id eb11-20020a0564020d0b00b00458a2444e99mr50879728edb.46.1667830862569; Mon, 07 Nov 2022 06:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830862; cv=none; d=google.com; s=arc-20160816; b=VG9yDBHiJPzlZuGjy1ymhA3wxUsr1ujWzMjmZqW4BU8XgVITVnVgDQlTSHt8kDpCK+ QEdQYL+1fGN9bTJH56A0qGOQuL7U1DheOhsFXDGCQ1OQRb/MwH3sb8ENtmpdkiSCO6qS C/WBE8nrg5YWgD3tozEY3pB9gKI0Q2Bdp+eEVMzm7f0Zvc1GxGT16TYpLdsLY9pUYk+f g2x3hZt/byNtDDSsr/8p/JFhjNhnVNHHjHykbkL6qwKo5IeuBp5MgX8hZgqK3zP0AOj6 pHbVpC3gf3trrKC+t23oHBLffnYHQlR/mrYwOUMyabG3S1ZQMrGWCijmg7Z6STsvsTMo 7prA== 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=P10TJPbg68YDEXoOUqzWZ7KHPqodrJaA+f/MK/G+CxEJKKjS6uqi9Ze2Qq0li5tgV3 780yQ1cJADE4osBsh2h6GGbqMOYdH9Hd/yqnjiWpT/g+Lz5C91n22MBLx4SHjcWmGX9q fWnkuMuxZxBqi/WcASB7e768XTKmrUrY7MLvmMsA1w77eGaRMePx/KdF5Wmi6v28KdSJ 6FN3QlVCJa+OqkIbWRky47fwkeEYVJfmBFRlbwPn8HLitR2YTJvIRQZBS16+u90gxt7x O7R4kfiOfxZccHHQyp2cUuiWZkGrERg3AmpOEkk5Dtuban2dlVZQs6dhnqDpYINVIVLl IkXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DuF+bg8y; 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 y8-20020a056402270800b00457f31c1a10si10565673edd.584.2022.11.07.06.20.34; Mon, 07 Nov 2022 06:21:02 -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=DuF+bg8y; 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 S232426AbiKGOTJ (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232173AbiKGORR (ORCPT ); Mon, 7 Nov 2022 09:17:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E96F21D0DE; Mon, 7 Nov 2022 06:16:55 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830614; 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=DuF+bg8yJFtPqiLv6Lzgpcy64Jm33Cwtcx+KWAV2sOjl/URNXsG3YczPD3PcntqIncaoNm 3L02VXPjSR0TLj81YxGQ6LZTk2ZUQgybRBMeGeMQDocitnvSD5SblrY1yZr8k9abFb8bmg gAhPc5V5zOLxiZVcFHsLlxF9SQpoJ+RG1/ECiIUdLg5WUvgKJQrcwqG9k2eHQzP8MRYPm4 MIiW7DQ1W4OFrx0lTMbt7t5JTV6Gg5M9AyPUvsoYVKdwCRoXfjlbxoSD96u2v1M/DZD9Qq xv2lLd2kENVAJNMJ/kje/5OI0ZYJ6COhsYtTUrsTB9jcA1Y/3Yh5grch75ZZ0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830614; 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=tNP8S8uaOeL8Ez4ZLxuS/B4XuCm99BrOZr9dwAEZbjlXPrmbmY57RQ59QmcB9FIUCSSctq i2jivdb3ZSpw5PDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Peter Zijlstra , Mathias Nyman , linux-usb@vger.kernel.org Subject: [PATCH printk v3 31/40] usb: early: xhci-dbc: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:29 +0106 Message-Id: <20221107141638.3790965-32-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?1748847414668750556?= X-GMAIL-MSGID: =?utf-8?q?1748847414668750556?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/usb/early/xhci-dbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index bfb7e2b85299..797047154820 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -927,7 +927,7 @@ void __init early_xdbc_register_console(void) static void xdbc_unregister_console(void) { - if (early_xdbc_console.flags & CON_ENABLED) + if (console_is_registered(&early_xdbc_console)) unregister_console(&early_xdbc_console); } From patchwork Mon Nov 7 14:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078589wru; Mon, 7 Nov 2022 06:20:48 -0800 (PST) X-Google-Smtp-Source: AMsMyM7VvCTalhhGbv+88amafQ+63Ye7/bW8pvihyQrtsjFRgHoSsx0Su1ylTr/KkapjHgaS9q/1 X-Received: by 2002:aa7:d858:0:b0:463:12ed:3f86 with SMTP id f24-20020aa7d858000000b0046312ed3f86mr47021548eds.281.1667830848023; Mon, 07 Nov 2022 06:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830848; cv=none; d=google.com; s=arc-20160816; b=aRnm0RRDTlm1pl+bn74p17fuHNkZLubGDll2gFB5UceG4SO+rPXT58EP322O3NTV1Z LsKynEWiP5eOnigO1DVm1AZ2UYw3Hm1cypZXNt08VbaMPeTdqsZq/Xx9Guu39IVkDLmg JkdBeuOL0ldaJ6EjTdqDFGnN6ooosGAy8bVCxIfDWI8qgv7mU78zZ/HJd/Wywfsd0vr5 7hDeviFG0W0Tn/RJQFmr+wYdMp3PI2/HcoWQ5hQfLoNphlz8UaKRIDDEe7aaXR8ckSUb iGTZDGO83m2X9ASSxWV5hLUET+PNueNQznlhPEdqK7V64+MzgdVQSbTDuuZ6wP2gTK9j d4xA== 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=YTUlGbaC4IbICTFrgEP8a7yLfyPtpor03FP0It9Xna7JDvnKJ85Iv/pdSFDtMddIv9 O+2fPyB4oDNuAOSB1MkSUO4tyRscd6zT3hrh1tDVYgV54Seke/lww1/8sL9CXdP5H+mH BIFamsQl7IdPsFV+T2z1pGj1CSm7HKzZgGJ+uG2jy6/IG0e7krJApRWSEuTR/E9pSVjW FKfNnrKJG+6vLGa/AmMfXPOjWfp9cDFTT68YYPdsRz+ezsiYD10nCmwUv5BchYRQjo/E BQCW1LG4JXXo1VChv5sl7Y9OuJj4GkuVOvgVN7jgNuIiNUAMJP/MRwbAkmFgpi9hgT84 lMjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=b4ql8y1C; 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 j8-20020aa7c0c8000000b00458e689f41fsi7958423edp.415.2022.11.07.06.20.19; Mon, 07 Nov 2022 06:20:48 -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=b4ql8y1C; 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 S232103AbiKGOTF (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbiKGORR (ORCPT ); Mon, 7 Nov 2022 09:17:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FD7E1D31A; Mon, 7 Nov 2022 06:16:56 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830615; 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=b4ql8y1CqshqWcXCG3fY/oCmxHiTCLqFp/vC5T7L6qJ5ftrsfJggc2LiYk23/G8uF2RCo0 sQwE/M5aYJgbrztjWgKxbzTaokKE/ML8eKgCOoi7fZ6th7Q6pJlmDrboSmojAXWzxG356u 7EMylIHc0pr+wXYfxZnGu4sgYKQjAL5nNKNuNvsc+jwAC/UqM05yo6/phGUgUXGOA+FWJ+ /9BhuARU1Zk7JU3Tmkq/Qgr0KvpxrbmyGDFMZ7kTywgU+fFz1SD8KFVXYp6F4mSxtC4BLZ AU01jBfG7+/FAho/BFUkNEEwhkzUPDHfiPPbLzhTGSyAHbAH0YoxbOKx+scuNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830615; 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=NB2DL2wjGq46VY5TZjuKeyQr4jtN3KHh2TuJaQu0Gc6dPBeDZEg/LqMW4yrdBOi8ko43Bk Rtc49uN3OHpgz/BA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH printk v3 32/40] netconsole: avoid CON_ENABLED misuse to track registration Date: Mon, 7 Nov 2022 15:22:30 +0106 Message-Id: <20221107141638.3790965-33-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?1748847399396975342?= X-GMAIL-MSGID: =?utf-8?q?1748847399396975342?= The CON_ENABLED flag is being misused to track whether or not the extended console should be or has been registered. Instead use a local variable to decide if the extended console should be registered and console_is_registered() to determine if it has been registered. Also add a check in cleanup_netconsole() to only unregister the extended console if it has been registered. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/net/netconsole.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bdff9ac5056d..4f4f79532c6c 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item, } if (enabled) { /* true */ - if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { - netconsole_ext.flags |= CON_ENABLED; + if (nt->extended && !console_is_registered(&netconsole_ext)) register_console(&netconsole_ext); - } /* * Skip netpoll_parse_options() -- all the attributes are @@ -869,7 +867,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) static struct console netconsole_ext = { .name = "netcon_ext", - .flags = CON_EXTENDED, /* starts disabled, registered on first use */ + .flags = CON_ENABLED | CON_EXTENDED, .write = write_ext_msg, }; @@ -883,6 +881,7 @@ static int __init init_netconsole(void) { int err; struct netconsole_target *nt, *tmp; + bool extended = false; unsigned long flags; char *target_config; char *input = config; @@ -895,11 +894,12 @@ static int __init init_netconsole(void) goto fail; } /* Dump existing printks when we register */ - if (nt->extended) - netconsole_ext.flags |= CON_PRINTBUFFER | - CON_ENABLED; - else + if (nt->extended) { + extended = true; + netconsole_ext.flags |= CON_PRINTBUFFER; + } else { netconsole.flags |= CON_PRINTBUFFER; + } spin_lock_irqsave(&target_list_lock, flags); list_add(&nt->list, &target_list); @@ -915,7 +915,7 @@ static int __init init_netconsole(void) if (err) goto undonotifier; - if (netconsole_ext.flags & CON_ENABLED) + if (extended) register_console(&netconsole_ext); register_console(&netconsole); pr_info("network logging started\n"); @@ -945,7 +945,8 @@ static void __exit cleanup_netconsole(void) { struct netconsole_target *nt, *tmp; - unregister_console(&netconsole_ext); + if (console_is_registered(&netconsole_ext)) + unregister_console(&netconsole_ext); unregister_console(&netconsole); dynamic_netconsole_exit(); unregister_netdevice_notifier(&netconsole_netdev_notifier); From patchwork Mon Nov 7 14:16: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: 16450 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078771wru; Mon, 7 Nov 2022 06:21:08 -0800 (PST) X-Google-Smtp-Source: AMsMyM7a6wIuatLFfc+Fpft+Oo2xYoSdhOGsfs918QKAbr4coq2G+axTXxNMTz/yiNgmT4AFILsr X-Received: by 2002:a63:5a0b:0:b0:434:4748:4e7a with SMTP id o11-20020a635a0b000000b0043447484e7amr43023901pgb.561.1667830868233; Mon, 07 Nov 2022 06:21:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830868; cv=none; d=google.com; s=arc-20160816; b=a+x/ayLLbhlkbpFs96MqR2QFXjv5FZvH0FHo+6ggzjtcNvIHkc8r9WlYfegM3Fhzda vE5UFBjTyWNJIfJVwAWIerSsNwTVXaEhVilEpqBAM8+rlMrEXCTsVwKVXzANUog8PPgJ w/m5X16IA/QvVe39Yv7GU/n3oE0Vru7bRmMTFz/GGFDkTyrsoyokrCsgqHf4I2mi6LQk LvmajdykScjgO4CBsYiM9cVIP+mKurVzPAizR2Kpt3YZ4K7bw7wY9oelnsNnWyd6dwLX j7NjHYC43lV48hyxZY+f8cQIqwx7jCXQk0Opt/5fa4wslwd899dhQcBSJbwh5Q76XJIV YCzQ== 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=gS+TlnBfnvuNwOKZQIZcdjPH9bhpfrs5K1fOz4tyq8E=; b=ENXuQBR1baOgXQFC/0QpphktIZlrDHjWkMhztteFinFkiTi4jn0aS/HqiZJDX+K+VN WrCd3ByIfZhTakduBaif/YQ6GDa9sVjLUe1AQfqvm85ue50YXG066FNiMF1VKk8L5bb0 bsFFkbqNHxytcgjPsT9McB4h50nozngc1LphrHMrAaOQqrh1yF3HCq57bI4oN1Axm4TX W5qQUfBVDOHgo6B5SLfd0n26YH8fqcjl4fFmH6mzSqIwD7f/uYWEUmS8zR+MkLd4ridT ZgeMOdVRJ0awAlKU3duG3ACcTA67/DkqJQIhDVxcLZskUluBPRv2X5DJSw6B5wu6oyoA zQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=djqqVbIJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 x14-20020a63170e000000b00464a9874658si10755078pgl.6.2022.11.07.06.20.54; Mon, 07 Nov 2022 06:21:08 -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=djqqVbIJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232431AbiKGOTM (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbiKGOR1 (ORCPT ); Mon, 7 Nov 2022 09:17:27 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2101A1D31F; Mon, 7 Nov 2022 06:16:57 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830615; 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=gS+TlnBfnvuNwOKZQIZcdjPH9bhpfrs5K1fOz4tyq8E=; b=djqqVbIJuMlxRG/KUYbjTE3WlJPb8/4BRjZqiVgvYMTr7/Sg0autRsyaU2JWaZq3VN3Mfw OwXHjvPPuCWuVO7A4iO0R7oz5UwNRLhdk02uk4jpCy9Gt7MNNPJoFi4PLw9QL+wwMeqZgG x8w4JTnSU8McnTmTMP+zEv1TCPiXlXiHUYwTYDDfpGnYPpWIDb6LZ00TZMmkMkukcDDlD8 pGbuhmV/Z89XLkI7qVEP/xlfkQntbD1FliCvEtwapvNn1D8KcDpxh7Pcm+BFSRCbglYTQK WSb0+BfzqLoXNbMVTMuI8qVDma66XMtIjHtCHVcUsZm6wYyw6AxM9KLuzMDR0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830615; 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=gS+TlnBfnvuNwOKZQIZcdjPH9bhpfrs5K1fOz4tyq8E=; b=M60ZeenQNKgOoEahohQx+InKZNToZ2PTl+S+h/Y9/Dwe3ZAZMQrMX+0/9pXQL0rFd4ySGx /D2ZyiONrI29IoCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Greg Kroah-Hartman , Javier Martinez Canillas , Thomas Zimmermann , Juergen Gross , Boris Ostrovsky , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH printk v3 33/40] printk, xen: fbfront: create/use safe function for forcing preferred Date: Mon, 7 Nov 2022 15:22:31 +0106 Message-Id: <20221107141638.3790965-34-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?1748847420221812624?= X-GMAIL-MSGID: =?utf-8?q?1748847420221812624?= With commit 9e124fe16ff2("xen: Enable console tty by default in domU if it's not a dummy") a hack was implemented to make sure that the tty console remains the console behind the /dev/console device. The main problem with the hack is that, after getting the console pointer to the tty console, it is assumed the pointer is still valid after releasing the console_sem. This assumption is incorrect and unsafe. Make the hack safe by introducing a new function console_force_preferred_locked() and perform the full operation under the console_list_lock. Signed-off-by: John Ogness --- drivers/video/fbdev/xen-fbfront.c | 12 +++------ include/linux/console.h | 1 + kernel/printk/printk.c | 44 ++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c index 4d2694d904aa..8752d389e382 100644 --- a/drivers/video/fbdev/xen-fbfront.c +++ b/drivers/video/fbdev/xen-fbfront.c @@ -504,18 +504,14 @@ static void xenfb_make_preferred_console(void) if (console_set_on_cmdline) return; - console_lock(); + console_list_lock(); for_each_console(c) { if (!strcmp(c->name, "tty") && c->index == 0) break; } - console_unlock(); - if (c) { - unregister_console(c); - c->flags |= CON_CONSDEV; - c->flags &= ~CON_PRINTBUFFER; /* don't print again */ - register_console(c); - } + if (c) + console_force_preferred_locked(c); + console_list_unlock(); } static int xenfb_resume(struct xenbus_device *dev) diff --git a/include/linux/console.h b/include/linux/console.h index cdae70e27377..b6b5d796d15c 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -273,6 +273,7 @@ enum con_flush_mode { }; extern int add_preferred_console(char *name, int idx, char *options); +extern void console_force_preferred_locked(struct console *con); extern void register_console(struct console *); extern int unregister_console(struct console *); extern void console_lock(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index be40a9688403..d74e6e609f7d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -247,9 +247,10 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void console_list_lock(void) { /* - * In unregister_console(), synchronize_srcu() is called with the - * console_list_lock held. Therefore it is not allowed that the - * console_list_lock is taken with the srcu_lock held. + * In unregister_console() and console_force_preferred_locked(), + * synchronize_srcu() is called with the console_list_lock held. + * Therefore it is not allowed that the console_list_lock is taken + * with the srcu_lock held. * * Whether or not this context is in the read-side critical section * can only be detected if the appropriate debug options are enabled. @@ -3457,6 +3458,43 @@ int unregister_console(struct console *console) } EXPORT_SYMBOL(unregister_console); +/** + * console_force_preferred_locked - force a registered console preferred + * @con: The registered console to force preferred. + * + * Must be called under console_list_lock(). + */ +void console_force_preferred_locked(struct console *con) +{ + struct console *cur_pref_con; + + if (!console_is_registered_locked(con)) + return; + + cur_pref_con = console_first(); + + /* Already preferred? */ + if (cur_pref_con == con) + return; + + hlist_del_init_rcu(&con->node); + + /* + * Ensure that all SRCU list walks have completed so that the console + * can be added to the beginning of the console list and its forward + * list pointer can be re-initialized. + */ + synchronize_srcu(&console_srcu); + + con->flags |= CON_CONSDEV; + WARN_ON(!con->device); + + /* Only the new head can have CON_CONSDEV set. */ + WRITE_ONCE(cur_pref_con->flags, cur_pref_con->flags & ~CON_CONSDEV); + hlist_add_behind_rcu(&con->node, console_list.first); +} +EXPORT_SYMBOL(console_force_preferred_locked); + /* * Initialize the console device. This is called *early*, so * we can't necessarily depend on lots of kernel help here. From patchwork Mon Nov 7 14:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16453 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078902wru; Mon, 7 Nov 2022 06:21:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6tn0McZUvREqqK3qCQYHNhWpurmE5q+b+wLYWMlav2T56s7XNrBmHtQ3jwSgXK9qi2bC69 X-Received: by 2002:a17:902:ce07:b0:188:7cd7:1ff0 with SMTP id k7-20020a170902ce0700b001887cd71ff0mr7436953plg.174.1667830884518; Mon, 07 Nov 2022 06:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830884; cv=none; d=google.com; s=arc-20160816; b=jnypUDnZWJLPsAmLHAzHhMlYR8CMw+jOfj/lO80WqjbBg2XqDEklXuvIxaXb+1WooJ hhWLKoq3qRW6czTUmyU0Dygd3ccxn8xRy/XdwUMFp+pCMP6XXqRHBNYBD9MvNDwcIgMB pn6A1QDBAc8ZmC9IkUsYxqiokjT3emVAoIfqvqlwVWRRbpDmDVFIVX/rxstSFGmMbtw0 /W7xx4qN0iqnCZpAhMQ98Du7lj9EGH0hlX0FUNrP3IfXXpph6qTqo+vLZWO9ZSDOg3vt GQWpOIsx/VJBCmRXLZD5g1r0dNfEbwC6XztWYB3XmLRIu1CMZNvp9vTm33LO7XSpedbJ rpGQ== 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=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=k8pD76/1wBg+XVX+vnqxGItelDmd32ucFqkoGMX/dIUYhN3Ox7vhXAH87U9wG+bl1M 378lM6Cj9eD6EGDWVvuZH7J/r+9L609OsBLYD9d2ExHe0G1l9v/sWbGi0f+ScUALvazG P8E9UhPpajMHf5ZD1xRXaicnqx0ax/cQWiIdsibr+No3Py1xSREAajObl04ih3FjcZ6D RhAVfGJsFd67RWcPSo3ZJPzvhyenGqs553iA00R9gCR95d+0Gx5Uaz8r2EPgjDJy8LS3 cVYJmS3k7g1iwKWD3NOI7XdkZTN0angMAkTgkrelV5k+uHcdBMrWJ/O52kz5qwOtMemt Dkbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ad8er1f7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zK+1fRr2; 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 131-20020a621689000000b00562b0b92756si8748471pfw.297.2022.11.07.06.21.10; Mon, 07 Nov 2022 06:21:24 -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=Ad8er1f7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zK+1fRr2; 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 S232443AbiKGOTQ (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232254AbiKGOR2 (ORCPT ); Mon, 7 Nov 2022 09:17:28 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6125F1D331 for ; Mon, 7 Nov 2022 06:16:57 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830616; 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=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=Ad8er1f7f8T+qnj0Gixt4/Eb+4c4OBJuex8lcfrI6Qt9I87cz3Yhpp3wFd3F8c5QAakGi7 n0yYpOb0XzwK6fAjOBesCSJAdkcc9KpXBouFayqOhvycH3D3yadGi/NrkdtoGLbncezA5X YjxkitS3+oQNxU51jX06dua+f/JTR0XVGlDIr8XnD/7XQCOkEkGQV7za9feSO1p2qDYB97 UumWZEnga12d8kYgQTwG2oUlZ8itzYhywnpRTKu8Ks8TF1Bk4XdZtBxWxmXB+X1cV+LfUg IEtga3BtJP43iP9Aa+RQ9n71Ed9jlHvrLDju9BL47ap7+sIADoEpSefIdM/kVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830616; 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=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=zK+1fRr2slLJAgCrOQ92XALV5x6DkTtyLpaf7GZ9DoHDzskWr2XYcAOYzCFmWcOd1UDl2W 031PveM/i8gqIXAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v3 34/40] tty: tty_io: use console_list_lock for list synchronization Date: Mon, 7 Nov 2022 15:22:32 +0106 Message-Id: <20221107141638.3790965-35-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?1748847437815722296?= X-GMAIL-MSGID: =?utf-8?q?1748847437815722296?= show_cons_active() uses the console_lock to gather information on registered consoles. It requires that no consoles are unregistered until it is finished. The console_list_lock should be used because list synchronization responsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/tty_io.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index ee4da2fec328..cafdff575716 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3527,16 +3527,13 @@ static ssize_t show_cons_active(struct device *dev, ssize_t count = 0; /* - * Hold the console_lock to guarantee that no consoles are + * Hold the console_list_lock to guarantee that no consoles are * unregistered until all console processing is complete. * This also allows safe traversal of the console list and * race-free reading of @flags. - * - * Take console_lock to serialize device() callback with - * other console operations. For example, fg_console is - * modified under console_lock when switching vt. */ - console_lock(); + console_list_lock(); + for_each_console(c) { if (!c->device) continue; @@ -3548,6 +3545,13 @@ static ssize_t show_cons_active(struct device *dev, if (i >= ARRAY_SIZE(cs)) break; } + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ + console_lock(); while (i--) { int index = cs[i]->index; struct tty_driver *drv = cs[i]->device(cs[i], &index); @@ -3563,6 +3567,8 @@ static ssize_t show_cons_active(struct device *dev, } console_unlock(); + console_list_unlock(); + return count; } static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL); From patchwork Mon Nov 7 14:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16456 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079393wru; Mon, 7 Nov 2022 06:22:14 -0800 (PST) X-Google-Smtp-Source: AMsMyM6c0gkSqr1gisuuscQobbdJQNFsckoA/nvx+/YiUyNN4ItNN6dJXb5px5RSZG9g2nZ+SNX8 X-Received: by 2002:a17:902:e843:b0:186:b180:3c3a with SMTP id t3-20020a170902e84300b00186b1803c3amr51463717plg.66.1667830934263; Mon, 07 Nov 2022 06:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830934; cv=none; d=google.com; s=arc-20160816; b=dvr8EpLyzMd1E9vvrWOS9NAGqfTQFdZ6L6BP7pJyLb7kXjZ96+lt9fp1F+AiD3dJ99 bo2srdMjddhYaaecZH722WPKiAfh6Gh11udCaZx3zk8MrLMAXzkE3Z/HLRNU/tAxeZOx iGGo4LrGiPYKoKPSsEk8UTpLR1Es6cc6acM6Tm5JyakS5WC4rOHhRst7u9NynkPIANC+ mDvWziiJqOYJZmM6Rz52vtDp7kQY09GnT2FqDl0GqVHFVr4oKMoPXmih6gF5dA1ufsg6 S+Q9o0DHpJU+VnRQPUDs1o8DhFU7hRkDqMLJNixtx5S69cbyqYQmAybPCHC32l0BKfqb GknA== 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=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=dmbOjqxJkTI8Raj5g1TuyMJDcjM2cNkyvqjY8+fWVv/Wm5L0836x2Wb4sEkq+BWo+F foe3+AeaALbqewV1vftZe955fEYWHeOVhesRgoF7+WM99UVa5xinICzlw7WRUO5bGD6v EMgAqwgKsGSeCeU6/mEn19tUYWhfzSq4IvHHbAfq3LY/W/BkmAr/v2a0bDhLTQknol+x Ln184WU/8T1w8MPj0fLKOtMueoFDsDfYkdV62v6uP0aY7JBFvEBCF+FGm3CxW6u5euZy mSIM0/iKHQBOIPzDon5XEKvMqDrVgTvz2K9SM1OMLKjQwvtorYKalHf4VQAyWb2rJs/q OTsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=biEAGa+R; 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 nl7-20020a17090b384700b0020bbfb294a1si19343894pjb.174.2022.11.07.06.22.00; Mon, 07 Nov 2022 06:22:14 -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=biEAGa+R; 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 S232453AbiKGOTY (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232100AbiKGORk (ORCPT ); Mon, 7 Nov 2022 09:17:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C10171D315; Mon, 7 Nov 2022 06:16:57 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830616; 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=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=biEAGa+Rugsj2SX4G+BNsq8EPIYMc1nSHftM4sNymF14x7nqnHnqTM5bbTrZC4Ao72JdFD eTy9sSnuQ/YAdPEZmjeT39aFM4mepO2NY5cv7tgSQN2ng7Gm+FW5FWq4V0zEJ+Rp0Qhjvp D5EmBmxObSSi6Z/MBmXKgXU7wzspNfdcTkPvjiNC6PGqowBwn21MikFz/RTx0ZSe6a3WvK GCyQUMHYmlc9dRQ0lruWDtK9A2vkliI2cC+r41Jo8RkhUyycUsPBPPzKGGCgUWnwbGWcTV 4/XDTbEtoaG7rBuDjtnF+UqOmm2kRbKMvRA3cXZa7n008/WBKIM/yFusvkZFfw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830616; 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=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=SH/lU/D4g49aRYA0T5dcgahfw8R97npuTuD4r52dmy41thUx2GTJ6aduLe1DBo7JG4JFCb zYNyNAOKDVecz9AA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org Subject: [PATCH printk v3 35/40] proc: consoles: use console_list_lock for list iteration Date: Mon, 7 Nov 2022 15:22:33 +0106 Message-Id: <20221107141638.3790965-36-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?1748847489855286825?= X-GMAIL-MSGID: =?utf-8?q?1748847489855286825?= The console_lock is used in part to guarantee safe list iteration. The console_list_lock should be used because list synchronization responsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index 46b305fa04ed..e0758fe7936d 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -33,7 +33,16 @@ static int show_console_dev(struct seq_file *m, void *v) if (con->device) { const struct tty_driver *driver; int index; + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ + console_lock(); driver = con->device(con, &index); + console_unlock(); + if (driver) { dev = MKDEV(driver->major, driver->minor_start); dev += index; @@ -64,15 +73,11 @@ static void *c_start(struct seq_file *m, loff_t *pos) loff_t off = 0; /* - * Take console_lock to serialize device() callback with - * other console operations. For example, fg_console is - * modified under console_lock when switching vt. - * - * Hold the console_lock to guarantee safe traversal of the + * Hold the console_list_lock to guarantee safe traversal of the * console list. SRCU cannot be used because there is no * place to store the SRCU cookie. */ - console_lock(); + console_list_lock(); for_each_console(con) if (off++ == *pos) break; @@ -90,7 +95,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *pos) static void c_stop(struct seq_file *m, void *v) { - console_unlock(); + console_list_unlock(); } static const struct seq_operations consoles_op = { From patchwork Mon Nov 7 14:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079355wru; Mon, 7 Nov 2022 06:22:09 -0800 (PST) X-Google-Smtp-Source: AMsMyM5BJ1Q5ODBLoc4SrWxZZXx/XUZZ5h1QpBN+q3lKGseL1FjQyR4CxQMioEtpjdV+MG/Wqqia X-Received: by 2002:a17:906:e44:b0:7ae:62b:3088 with SMTP id q4-20020a1709060e4400b007ae062b3088mr28592465eji.28.1667830929723; Mon, 07 Nov 2022 06:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830929; cv=none; d=google.com; s=arc-20160816; b=qLHNjmAOybPp6bol1IFRoIbsGQvBSpAZElasWN/+W6flANrjSyIQka0FPBD8e2M+hs Qn8OUle4yK1VGQGQfS7JyMha08sqiepV+eSLpEX6/oBQ/CULWw6X5fVzHx5jqNxGPQiW TLeSYrb78z0Nj/y+UgOB1meeHuAyCPxEFLMXAowFWA7WYPKtAZAYfDkyvsNpNkuSKpMy UFju4ru3TmsZjCmrqix5M4tJGj5QVRV3j/POyBEmewR1/9nwXE11qz0lLCl5GQRy+Udn UmZpbxZXqJXQ036s/rLoSeYw+LcByBTVXv3wbx3B7ZdbVm6sYRfzXeRTamrBAwPNaX+j JSDg== 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=MzQ18CbWCTXFhWm04SkwyZ25tmQRyL0RsW4C4LxROfa8i1Flz4FQwbWss+ocApwhUr tyY0+6+9h0bU3/hCo4xOChMA3K67aY3SKEq5HOBeKis0/80I7/P5yCrJj0uMn3hwTwnh xHug286JeqJMUA14dgTPTgvy3cPiDlmeSuTffkzqY/SkgRvIDpmGwqCrN1iZyJ045lvL W2NpAQ49LMtycCprUUUWZLwEVsMsA7w0MmXm9csrgXFrnEQ5bZG+wpRNJsxlOVxmZN8I pNngQUUKVVSa4Nx6vyYj2/kuDVqFjqn9H00i4fDuwj8WQexUeGrBFdzumGeNIDQ3r0vy KN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gqAyq8wc; 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 ca2-20020a170906a3c200b0078d3b940ec5si7395695ejb.373.2022.11.07.06.21.44; Mon, 07 Nov 2022 06:22:09 -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=gqAyq8wc; 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 S232446AbiKGOTT (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbiKGORk (ORCPT ); Mon, 7 Nov 2022 09:17:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA621D33E; Mon, 7 Nov 2022 06:16:58 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830617; 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=gqAyq8wc/xmtR7iqeOG6HKRPQNaHenvleIBzDQ/LW3mKRO51oeZo94GS/qRNuT8ieSU0xm 67Ezdbpop5bIKLaW4vynak6kv+RutOCMz7GJmsmWvJ7ztSxvOPnfZsII/sczgr4+zwlbH0 bvBpYYScUM3+IVnwUhj0PRvYRquDb0k9dX6d4FiyUu64Q/sTrT/pd/vzPWoMAYhgg2rfNa 2MwuVE4oyZ5XOUiJrMrXKb8HCarltDgby4NEQN13ZduKMvpyiMLdZaTIIaHReLQ4CPsOXo WmDQpN1gWbLYKOD9QXS7ZKEJtYAVyIu5cwJ/0yLtFFfv2+ZH5482Fb2f8IS7XA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830617; 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=Z547tJz8CL/7ne/rUO0T2mCvQYl5X73Ya4ph+/4nhh6mLeSrOtoKGcN6H+lDnm6AvUFYKH ymi7EfX8Rj0GaIBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v3 36/40] tty: serial: kgdboc: use console_list_lock for list traversal Date: Mon, 7 Nov 2022 15:22:34 +0106 Message-Id: <20221107141638.3790965-37-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?1748847484636173613?= X-GMAIL-MSGID: =?utf-8?q?1748847484636173613?= configure_kgdboc() uses the console_lock for console list iteration. Use the console_list_lock instead because list synchronization responsibility will be removed from the console_lock in a later change. The SRCU iterator could have been used here, but a later change will relocate the locking of the console_list_lock to also provide synchronization against register_console(). Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness --- drivers/tty/serial/kgdboc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 5be381003e58..82b4b4d67823 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -193,7 +193,16 @@ static int configure_kgdboc(void) if (!p) goto noconfig; + /* For safe traversal of the console list. */ + console_list_lock(); + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); + for_each_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) == p && @@ -202,8 +211,11 @@ static int configure_kgdboc(void) break; } } + console_unlock(); + console_list_unlock(); + kgdb_tty_driver = p; kgdb_tty_line = tty_line; @@ -451,6 +463,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) { struct console *con; static bool already_warned; + int cookie; if (already_warned) return; @@ -463,9 +476,14 @@ static void kgdboc_earlycon_pre_exp_handler(void) * serial drivers might be OK with this, print a warning once per * boot if we detect this case. */ - for_each_console(con) + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { if (con == kgdboc_earlycon_io_ops.cons) - return; + break; + } + console_srcu_read_unlock(cookie); + if (con) + return; already_warned = true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); From patchwork Mon Nov 7 14:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079477wru; Mon, 7 Nov 2022 06:22:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM4p4/kNxUWvdzWkB6/wvCK8p+uNXiQwo8away1CfT9FoQ78PvGOHQrIaO91Ko66y5rQS4nw X-Received: by 2002:a63:ec51:0:b0:46f:ed8d:7089 with SMTP id r17-20020a63ec51000000b0046fed8d7089mr28226421pgj.469.1667830944813; Mon, 07 Nov 2022 06:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830944; cv=none; d=google.com; s=arc-20160816; b=pCee4U7kopeTIOrHu2+1/N7+MBQD262Jekt5aINu2aXh+Q4cxDQr/r8+Hq/GqoEQbF y1qI6T+gU7DcmMPQ3PVlXWIfyHm7kLlUNlsCc17H9gyh94rRQVhGaI8QrB4mecUaSCUD 4LnZY8UusAL5EMNlTHfgD4lsKbSPfJ16U9PZaZt+oBPj81Lg/TTOatwul8A2t2y34Sk4 jgSDt+8CtqgtMuKsDnE0jUN6Ews6XydC6V8+C/XW1ZVnSfh8byKGGpS5MWRpruWixyL/ 1hjHIx9+/BlMTZJbxUkErvsrwskmm3c9sCkj6J92cY7AJb1666AGchW6w2qtcrkyZlQJ TcVQ== 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=cUai3pdIKdcuUClSwSR4vMEb5FhU5IcIc606U2/UXdH46CT/6cWE+QdIrNp3B5ZDBt PFl6LwGQAvC6lNr006GmdQavqd4BQQmr7IATTmO2WT1RULoHQxg9tbsDgloN+cInDhb4 OlRLtOC/FzoKfEuJhiUe+RUxYeu2InijP72IFILm/dFfnmuUGzskoI/7zn02kmkYqWO6 1fzB2ylxplHVOEyxPDWUUj0Df1B0T0cLXldLucgtWrT8m5R5hc9AcH0qWdkForiE2WbA Zt0kQyogX3RNOlemD5ZCyCE0LDm51klMZxPoEA3/IAWkActoaNMN5g8fUANQIDNuAOzK CDKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=quYSkn0H; 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 l1-20020a170902ec0100b00179f9521d08si9489765pld.149.2022.11.07.06.22.11; Mon, 07 Nov 2022 06:22:24 -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=quYSkn0H; 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 S232142AbiKGOT3 (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbiKGORk (ORCPT ); Mon, 7 Nov 2022 09:17:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF5231D641; Mon, 7 Nov 2022 06:16:58 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830617; 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=quYSkn0H6WS4/l0RYtMy3BDn/rK/rRzby8k7+wPwnxKordiq2TgHz8VGVPX95WuRGgwskm EtBX73KPFW0k9NtYTpUCTtC+tWMJhMww3Zvq9V2lgXuA2ShF3fqmI4g0ScS/P1sTLwetNh ExpToebi/v9WRQUmTKE5E/WcN/uuirbBRldIeX/WLOaS06fohXQ/OGszmxg1g6WSergB31 MbaozUQ59Y9Fv+G+GH08ICMAjHlm76Pco9BS188p4z7JPQKzTEx426fF2f8aER4+H6sylG CSiyN8MEZvyACLULxolUeG76LhEFYwnZoc0EQUAsjHeEZdS3ykqCDiKbXDiAqw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830617; 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=0EsqVlG5GcPGEcsVNMZ4uy7CR5J6JcEVjcsCxd7fPEIZJDWclxknPbTwQCDjbw6tArZeef 7aUFWCYb4TEtlXBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v3 37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() Date: Mon, 7 Nov 2022 15:22:35 +0106 Message-Id: <20221107141638.3790965-38-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?1748847500823828086?= X-GMAIL-MSGID: =?utf-8?q?1748847500823828086?= Calling tty_find_polling_driver() can lead to uart_set_options() being called (via the poll_init() callback of tty_operations) to configure the uart. But uart_set_options() can also be called by register_console() (via the setup() callback of console). Take the console_list_lock to synchronize against register_console() and also use it for console list traversal. This also ensures the console list cannot change until the polling console has been chosen. Signed-off-by: John Ogness Reviewed-by: Daniel Thompson Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 82b4b4d67823..8c2b7ccdfebf 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -189,12 +189,20 @@ static int configure_kgdboc(void) if (kgdboc_register_kbd(&cptr)) goto do_register; + /* + * tty_find_polling_driver() can call uart_set_options() + * (via poll_init) to configure the uart. Take the console_list_lock + * in order to synchronize against register_console(), which can also + * configure the uart via uart_set_options(). This also allows safe + * traversal of the console list. + */ + console_list_lock(); + p = tty_find_polling_driver(cptr, &tty_line); - if (!p) + if (!p) { + console_list_unlock(); goto noconfig; - - /* For safe traversal of the console list. */ - console_list_lock(); + } /* * Take console_lock to serialize device() callback with From patchwork Mon Nov 7 14:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079619wru; Mon, 7 Nov 2022 06:22:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM5LF9X9ipuLo0Rm/2YuteAUr83p42aOwy+iUrKsvmDbATRQfVEFC5etNXzosfuoPtzcnp2H X-Received: by 2002:a05:6402:204d:b0:463:153d:6790 with SMTP id bc13-20020a056402204d00b00463153d6790mr48240119edb.293.1667830959157; Mon, 07 Nov 2022 06:22:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830959; cv=none; d=google.com; s=arc-20160816; b=cYBd2QdWFrcR2o+vFDPd5YK36aOwkt5fLyxkCKlBUPqLcF5i75Sn0JKQCbxTuGyslF l4aaaeZKd+XyAOaEhDKytP7LsTwpekFXq0LXaRWvlKIyEPSODu7JCRcRI30+E6rOnrEe Pl7OMk4SbKKzFZZcngZu7X2M7ixMnhvrmrwYmBgz5Wf3xp8FUaimtU9h2GkkuNouodcE moGnZgpAvz8ZU2mysKRAOv/BIWsRv/WN2MEW45SQkTbFlow/UJAeEdqepRuAZVTn692f PacVkoStwwE5tJeUvUjXHsIjNluKKcz0wTYqWeWb3gCeaVflZQcT5W4FIQYjdwH9d8RU KZTg== 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=wUO1Wdk5xzj9Vs+pxrA7dhcSw4wLvHPzDi2xSOEA1ME=; b=erabvHrW217HISI01kMlQHzacvAC8pY3C9b5/dQq5YdjHQmxBtvnu6rHsHNXbgkgQj A0U8DioyOCu8nQQ02/Bx5/PqIunvHJBIlTbAtghWPaUINUpzxbhD3NBR0FnRGGynitTT 5wGOHeL+FaBsSko2pcyvpZ+Rsu3fz3y/ohEzY2lZP709dSKetmbywFswoHN87b+9BQZX 25YN2/kaasXlfLuNGbl5lLjqV1HAta7K/qYX5Njb4DBrAaUAM5NOEsAqXoPVYwZYI0G6 fBhh2tJJLte9BznIQVu0Z2esFiqvIZsG8jrhx+MtC9cNbTE4m2PYsWJNx5ueXWazo5yd UzBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MUs03b3d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="y/4D56T+"; 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 nc18-20020a1709071c1200b00797e151e571si10907306ejc.36.2022.11.07.06.22.15; Mon, 07 Nov 2022 06:22:39 -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=MUs03b3d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="y/4D56T+"; 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 S232462AbiKGOTb (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232271AbiKGORk (ORCPT ); Mon, 7 Nov 2022 09:17:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50A241D31D; 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=wUO1Wdk5xzj9Vs+pxrA7dhcSw4wLvHPzDi2xSOEA1ME=; b=MUs03b3dJuWNfo7QVI5dMRKPmYfQe1AaNJ2UCFqmSPdHCpaerJkXb3JFXDpY8yzudMgvnP 61U2iJhwFpPiu02FexbWU0B8hzVeF59HrupwiQEC7KereqcT3hG2P1BwQAp1BnEjetn9Os VLR5NODmKIEmjVQZXGsbpSHYyLjvtewiY1to6bauh8e82VcN2YloCflvNTuVwlXypZ5AvZ tZvQA8n2lcbO4jAm0y2Iw584HkKm6Vkg/w3L2cfPtUw+CBVoFVvHQEVfVo0mPUpKxPR9JJ I4LIPcFhdvv006X3sdjQF2kzFT6wD4jjecuBt4WILIomm2h6+JrS8JvaVx9KhQ== 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=wUO1Wdk5xzj9Vs+pxrA7dhcSw4wLvHPzDi2xSOEA1ME=; b=y/4D56T+eDpvRE8oe5A4x+AW38ZOTavCt3hqTDnko5X0Qde4DudGdqovNKjwfPfw9L1jQR KXKUXgdgHjl6TwCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v3 38/40] tty: serial: kgdboc: use console_list_lock to trap exit Date: Mon, 7 Nov 2022 15:22:36 +0106 Message-Id: <20221107141638.3790965-39-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?1748847516199256158?= X-GMAIL-MSGID: =?utf-8?q?1748847516199256158?= kgdboc_earlycon_init() uses the console_lock to ensure that no consoles are unregistered until the kgdboc_earlycon is setup. The console_list_lock should be used instead because list synchronization responsibility will be removed from the console_lock in a later change. Signed-off-by: John Ogness Reviewed-by: Daniel Thompson Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 8c2b7ccdfebf..a3ed9b34e2ab 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -558,13 +558,13 @@ static int __init kgdboc_earlycon_init(char *opt) */ /* - * Hold the console_lock to guarantee that no consoles are + * Hold the console_list_lock to guarantee that no consoles are * unregistered until the kgdboc_earlycon setup is complete. * Trapping the exit() callback relies on exit() not being * called until the trap is setup. This also allows safe * traversal of the console list and race-free reading of @flags. */ - console_lock(); + console_list_lock(); for_each_console(con) { if (con->write && con->read && (con->flags & (CON_BOOT | CON_ENABLED)) && @@ -606,7 +606,7 @@ static int __init kgdboc_earlycon_init(char *opt) } unlock: - console_unlock(); + console_list_unlock(); /* Non-zero means malformed option so we always return zero */ return 0; 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 From patchwork Mon Nov 7 14:16:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079594wru; Mon, 7 Nov 2022 06:22:37 -0800 (PST) X-Google-Smtp-Source: AMsMyM67rVT+bLEA1Pac2t3941Qb/Pi/txhIPfABbSMpAxvlfowu6BAEzcMzjWs/LzWYcW2+5GJo X-Received: by 2002:a17:90a:6f83:b0:213:9e97:d5e1 with SMTP id e3-20020a17090a6f8300b002139e97d5e1mr53202476pjk.149.1667830956823; Mon, 07 Nov 2022 06:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830956; cv=none; d=google.com; s=arc-20160816; b=rYsThg7JIhVa+Fkvq5cZM/r18TgvYYdVx/Z3CdDzSIfBiCzZl49739Ttnf936FW1q4 DGOIht4QvBA4XKlrp3JJZV+DXwbxUqamaw5czpNmoyb3b3L57aoe50Ro5abVbbirFSgn /nCozQCa8E4H/clmkUpchtdVZk8hANqfFK10UCCsqYR01YjRJ3q6LPV3YUkJd3YKuFrO biqXqVuXslx1cSRilG5OvhuYFKsJerzNFS2WK5fk1vC9sgu9OLxo7xAIALCyV89Qb17S jHcOQHxQFco/IFkdJBmSjqH3FBUcGjeMyldOIEjk7TxmDbMG05NpZLq395o+ZKtrgzt1 drJQ== 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=wOWHeHInm2fmU2wKM0mWh276PVpVVzC8ULssrB/joiM=; b=bcMDtYUPenZYWWIStUv/0NQzkx7xNSkxMrb8+7+lJ2osql3wsKldc+T3pdObEH3vTV CkI+zg10CMhtAEyJ2iJ+4jChvsm54o6YY0IDb+buPdBxev14thLYTyibBbWYcTtGJo5M jLtxLmerS4lNL/8ZUMBk4A39wVcGTKd8PlTFdEuuDAi2ucGxqwoLVF22AmCF4rziAL9Q greXWKcmgKS/rGP73nkc3NITlUCz6jLVwyCJ/frAVYwGAi7yWtYZ91KVp3SiV4Fx9wJC dWj84NCu/Su2W7YXmNv/0eRIj4B9EpN4ngRAmAeEOqnmoXZ9mHD1MKy8Zp58aLWpxN3K s5bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="swwcC/ey"; dkim=neutral (no key) header.i=@linutronix.de header.b=XMu8M3iT; 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 e6-20020a17090301c600b0018699a9ea71si11270111plh.18.2022.11.07.06.22.23; Mon, 07 Nov 2022 06:22:36 -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="swwcC/ey"; dkim=neutral (no key) header.i=@linutronix.de header.b=XMu8M3iT; 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 S232469AbiKGOTg (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbiKGOSB (ORCPT ); Mon, 7 Nov 2022 09:18:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10CD41D33D; Mon, 7 Nov 2022 06:17:00 -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=wOWHeHInm2fmU2wKM0mWh276PVpVVzC8ULssrB/joiM=; b=swwcC/eytgcMbEKzOsEncCun4WY7vCLbcSffYIRaqcjIVCgoqyAiB72Hq237ceNlyL5/yg IaBRPSjRNC+INjKqpcmmT7hw6GRutYGeymQnr6Ol54Fij7be5Jfsm1DMqRlgS5UuQl9Rvq kdDA0dnHuT7VyfDq9u5tURAAc7KWeGndsalFDzyw85DF2YnZXb09JJH4a9xoJEpkWVwyS8 9jeLeuqUOLHzlmT4uTJIGlq4oWnVJQX+g1TczTiRuFCoB5GfciO6IKmx3iBPLaJbghiv/i PLkKtR22cC0RUj+pZZuRVN6VNvOn/czOzbB7QmzT3PZHj15nJHjX9f2zg0usMA== 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=wOWHeHInm2fmU2wKM0mWh276PVpVVzC8ULssrB/joiM=; b=XMu8M3iTA3yEquZZqVsUkXpN+6MK0GssBgVj2Cl5IKI6K2iL8N2eyBMcwztJY/whxe4NYQ BGYy6M/luah7T/Cg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v3 40/40] tty: serial: sh-sci: use setup() callback for early console Date: Mon, 7 Nov 2022 15:22:38 +0106 Message-Id: <20221107141638.3790965-41-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?1748847513435395923?= X-GMAIL-MSGID: =?utf-8?q?1748847513435395923?= When setting up the early console, the setup() callback of the regular console is used. It is called manually before registering the early console instead of providing a setup() callback for the early console. This is probably because the early setup needs a different @options during the early stage. The issue here is that the setup() callback is called without the console_list_lock held and functions such as uart_set_options() expect that. Rather than manually calling the setup() function before registering, provide an early console setup() callback that will use the different early options. This ensures that the error checking, ordering, and locking context when setting up the early console are correct. Note that technically the current implementation works because it is only used in early boot. And since the early console setup is performed before registering, it cannot race with anything and thus does not need any locking. However, longterm maintenance is easier when drivers rely on the subsystem API rather than manually implementing steps that could cause breakage in the future. Signed-off-by: John Ogness Reviewed-by: Geert Uytterhoeven --- drivers/tty/serial/sh-sci.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 62f773286d44..f3a1cfec757a 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3054,15 +3054,26 @@ static struct console serial_console = { }; #ifdef CONFIG_SUPERH +static char early_serial_buf[32]; + +static int early_serial_console_setup(struct console *co, char *options) +{ + WARN_ON(options); + /* + * Use @early_serial_buf because @options will always be + * NULL at this early stage. + */ + return serial_console_setup(co, early_serial_buf); +} + static struct console early_serial_console = { .name = "early_ttySC", .write = serial_console_write, + .setup = early_serial_console_setup, .flags = CON_PRINTBUFFER, .index = -1, }; -static char early_serial_buf[32]; - static int sci_probe_earlyprintk(struct platform_device *pdev) { const struct plat_sci_port *cfg = dev_get_platdata(&pdev->dev); @@ -3074,8 +3085,6 @@ static int sci_probe_earlyprintk(struct platform_device *pdev) sci_init_single(pdev, &sci_ports[pdev->id], pdev->id, cfg, true); - serial_console_setup(&early_serial_console, early_serial_buf); - if (!strstr(early_serial_buf, "keep")) early_serial_console.flags |= CON_BOOT;