From patchwork Mon Nov 14 16:29: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: 19908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239465wru; Mon, 14 Nov 2022 08:33:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6flsA83FMaY4cnLCQabfyl7WgyupGGN7B7+D0aZTJrlb9EL95w8CVIiFFwmFS3upR3o+Sg X-Received: by 2002:a17:906:3551:b0:7ae:43f5:a2a3 with SMTP id s17-20020a170906355100b007ae43f5a2a3mr10425488eja.595.1668443621324; Mon, 14 Nov 2022 08:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443621; cv=none; d=google.com; s=arc-20160816; b=Eug2fRFMAolhUR1dMEUe8mpU/XcMVxrIptYFreLcNsUcKucAw3fS1IWnGrPhH9e4gL NCtOz4+MdNTSaINWlzKZKJ5ze5Otc3/WwPAen3tQsaedMDHih1Mbtgdp9qjZmZP+PWAF rvO0yqaaHb+lVeegVBYGAhuTXvq1phWs98G7jTCz4VCn8GwBwC22X5r8z1Z2HpzUbdWD rlHRpF48zCkXP9J9zroqhZHlOUvrsfPyE8qI8kUTqNNU9dawXWoEgjFGP537tg/f+cUf ZU3e9YhGoJGaNxT2SpIoXQ/SUGxVQ71WWUp4q7Ajt1ejViJyXithONG7GEDFQVpHHneg lOlw== 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=S2ean/TesJg8Mgf4DSaewBL9JZCmCttlh2q55l1NnYMjqyc+eOk5DniPtsTH9E59yg xR341mGO1a9YZlhgCIMCs68CMu8SXe3qfFHNrv/XUu2J5jjbKXQukTVSvXj28eGM6KE0 bm187jd4jNXMF+i46Ac/oo2WPgiVMaV4Wdewxc8YOCJGZTx7kx2l2Mde+ZUMJRI6IAex gzKGzRWMolkQoeyQac69wTFk5iRr944OvZe17S8td4M8ye5SOgwxooY7FTBP1iYwphP6 xuKasOvHbsyH1x2VjZqrGXx7ct7giBslPLsEKfaSviMBPEcz4DbFCteZ6lAD+Kxl+uBZ Dcig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mfXS5Cw3; 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 d13-20020a50cd4d000000b0045f802c0b98si8382231edj.443.2022.11.14.08.32.28; Mon, 14 Nov 2022 08:33:41 -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=mfXS5Cw3; 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 S237717AbiKNQbf (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237694AbiKNQau (ORCPT ); Mon, 14 Nov 2022 11:30:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A80E2F01D; Mon, 14 Nov 2022 08:29:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443388; 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=mfXS5Cw3dKtbQJm9mn+jcg8yDvbnLClYULmacns+jvjhLW6rZek5GuH88Ux2VGAzSEiGM+ 22pWQ8qF/fPePKGvvi1k6uu4aDqJWXFK1WWBjtv0tmYOVBDYEAs/ROS4JLOyUa1YgTJSBS FFFAIJonz5AKb777jVgTUWJqIPr38s89l4QvRMZ07iCVdI/jvx0YXISW0ty7Kco/C2TABd qo4nWg+wlTKPATLOpOb3qPPDigJsPiZzdmOHVzXM+cn7TZM8nhVmW2F9ayfwK/EOgNftaP j5HxMDyy54fs41BQhQzBQDCOEqhxBVcysteCb/v9FgrJKxSVFyAApdCPeSkvZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443388; 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=YF4kcTgIBdDPE43HzqRI7H6KMWjfmgcTt3tzko7kkdkywT7MIrIQCbxb+24VrZ/T8f2Pt3 dfouT9kVORt4Q/Dg== 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 v4 33/39] proc: consoles: use console_list_lock for list iteration Date: Mon, 14 Nov 2022 17:35:26 +0106 Message-Id: <20221114162932.141883-34-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489938447453235?= X-GMAIL-MSGID: =?utf-8?q?1749489938447453235?= 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 = {