Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp865606rwb; Wed, 16 Nov 2022 08:38:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf57oH8D2xv9KHIvBCkkTTw29KkgWNJVDvM5xc82afmSmBdo0Gfe1Uq9BRLcoac7FgY1YY1Y X-Received: by 2002:a17:906:2856:b0:7a9:a59c:4be with SMTP id s22-20020a170906285600b007a9a59c04bemr18245974ejc.556.1668616717606; Wed, 16 Nov 2022 08:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616717; cv=none; d=google.com; s=arc-20160816; b=wGvNLXHfasJQT/Oo2hMaw8HsZPXVDQQVS4pMDd813s+jOmJS5UBGJDx31PidLD4FSr y8DdogLIaTTf/5ZNSFkt5BeauB8EszNf02rORzLfe/pJzC3UAG57N8mVVCbazsa8Yhm/ a/dWSXnLf2G5YgUDPjHZbfB7CQynaVoHWXG794/GBvZ5fg+a1FWUHw/Nb6rT8XBeAU61 uNgaSoP93aZ5cp4E7A9IUK+/7i94+Wr/EhvsY9It8g0Ut9qNFLy5FnS7xCD8hkwGzK3R kOjMVvow6FHkwpkRhxYmYLOsA+p3I6RCyWFPLdIjDM6EqIuy3kP1EX2jzwDTYWafqcPY dirQ== 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=o9AWlZFiF/LYeBX2tQmYKVcJmpgnGTovUHHC17vN+6qrU9wCiVQ4/tDA6Ubj79q0Vs kvLbTPoGmOK+GDFsv7WX316JgDWbuGMWzkwgfTp7n/9fMIn5pz+vlLQHAu9rQhGMptCX KVtRxh7togrmFEIKD5UPHlLDRZ/KpEH/5+v+epRq79z6ONtCfJ4ZFN3YHy2D59Yg+dEG 3GFcjxJ4AC0llqa97Rzs1xjG+JG3HUNBuk1P9eYNXWuvIlCbwMdN5ihrO1GkQUY3wwva ufHQR/7oyxWXxw1O36HEeqDRU2sWxBxoaiErcB6oWsEvLA0YopPdp9DUaSCwiE8vKF0J Ih+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qybUVOHQ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt18-20020a1709072d9200b00797e151e571si16679857ejc.36.2022.11.16.08.38.15; Wed, 16 Nov 2022 08:38:37 -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=qybUVOHQ; 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 S238973AbiKPQZt (ORCPT + 92 others); Wed, 16 Nov 2022 11:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238019AbiKPQXD (ORCPT ); Wed, 16 Nov 2022 11:23:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6617658BE1; Wed, 16 Nov 2022 08:22:15 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615733; 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=qybUVOHQ3lcpPJORwUZxfRKNSDT/E1lW8xR9jQFAUnk+CmGFCk6egkthMCR3TQeua2DtWM VyojWSc5t+MeGT9e4X2IlZEDixaROC4FQDK+95FFmvVk3mBvNNZZurhDgYXAjTiINlLEpF qg4PxKKgKoK5ZTSTBHifiUwP480lYx3KbdCcXDHRTbRcqsdmOZnVSY0fGJZ8UV9PZv5U3V o2INZ38YMktP/5lqXKutOY83w6LM0Iv/JvaPFKxh05++GiySPm5y//mPl3U1g2AGNuTkCg CJFulvLQk226W5njRJXauh3efYaiUiH+LlheE8AI7XiIf0Zi9/Vf7eqCzK8qTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615733; 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=HsEGN6tMo3uc7PUkebWaEn1oYTUp5bx/ZwX+WR68pMluY1e7aak5EW/DR9K2+PrfNPUAQ1 iiHhLYBATOPUnIDg== 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 v5 34/40] proc: consoles: use console_list_lock for list iteration Date: Wed, 16 Nov 2022 17:27:46 +0106 Message-Id: <20221116162152.193147-35-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = { -- 2.30.2