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 = {