From patchwork Wed Oct 19 14:55:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 5651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379635wrs; Wed, 19 Oct 2022 08:11:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lrOG850aHSEvQHtVnk++k/boeyvY3GexBOAVtpmfFQzGxVeeIt30AubIgE7+4RiKvD7eT X-Received: by 2002:a17:907:a46:b0:782:1c1c:8141 with SMTP id be6-20020a1709070a4600b007821c1c8141mr7058606ejc.549.1666192278109; Wed, 19 Oct 2022 08:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192278; cv=none; d=google.com; s=arc-20160816; b=UdulkzV9Ir0ykJau31GHaQlfs/A2buHLTet1d50RIiWe/lw/WF++fy8I0D4dK9VZA4 DN6r2/PCzU77O8fWeF6zKk1YTUmizZYO/POd/WTetJw6TwDuUkoO4CEvKuchAl77qvlf XKfcFNhpXgsuUUzsnRFJmNAapVLhz2FLAUaIgSc/Gu485TsUN2bD3UNDPP6yUOV5jigp QBCD90sopF6GAH4Po5wURrJp+Q/4wguxX/254vTXOdoBbFQCv+81zlXLlKvGEneDPX1b qigrBXnBiDWRUdGKx8PHUrXeyE+2S0CXRfsghrfQA0jln56K7lY4Hssg+UEpF/UdGkd7 aItQ== 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=M9ps/+3zFTTMX/Xw+H343+FOn0pASHbTafsRYfPyD80=; b=iO1ncKxYdZsxO4V1UPJSvPq4KD3ccEpZ81gbj7j8RAyRAismWXcMyqlZScpjLPFp8A z0xnAjqh7YCwn8V/AQ1Sg6QJCDqkOt3m0REI08r3x4HIJW+Sj9B+3TfwBVUvDUt9SlJK E+Zg0OUXZu848En8Xsst/4bb1EItKept9IIjUL32cwZ0n8YrgXTP11k75FDWviEq/iUS UKDLovxJq7gs2HktIKxa1o2UJb8YAkYmNyjH27PWa/FXOnjIlHw55RjC2l0MLujQ/xbR rmE/HOFNo+cmxlchTh9VecBDP5sK1JuN12QsmvFmzYQSStdacL1LJXskdmNgYYIQBpVa cw7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xryRBIth; 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 d11-20020a50ea8b000000b0045cca8f9a1fsi6232452edo.558.2022.10.19.08.10.51; Wed, 19 Oct 2022 08:11:18 -0700 (PDT) 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=xryRBIth; 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 S232140AbiJSPII (ORCPT + 99 others); Wed, 19 Oct 2022 11:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiJSPGi (ORCPT ); Wed, 19 Oct 2022 11:06:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C213F36798; Wed, 19 Oct 2022 07:59:31 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191381; 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=M9ps/+3zFTTMX/Xw+H343+FOn0pASHbTafsRYfPyD80=; b=xryRBIthFWhP4UrwlfzbLHB1wneSnBcBBrCWGbfzhFtyZZ62blHFAAWadbR3RfJ0xiS3D8 E8G/EiTVA2QAo78BFXu4HLdwD+wAF6JL8ZZPT3fT3XiPQ0U3QnQkiqFxYtRNWpb8fxr2Cx A/Cmed+jZKcC1QRl0fM0J5BhpF3Ep4COPsunR9DMwyMVrS6nOyn1FZdHgAvIlS9jd3c3/u DNATXphbwlgI1vTSZ6DZy++PAOL/yQeAkH6xkw/VIyWpUi46a/OKZkof+PQOokG1dN51E3 ScxR1SESvRXx3+MDvobD2S55zRzzj6vOpkbNnDYcWKvXBeaZ6jqGRdPZWw68+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191381; 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=M9ps/+3zFTTMX/Xw+H343+FOn0pASHbTafsRYfPyD80=; b=nK0TpZ0gm/hS4UwI6UaYUoHDooyjpXsBf4rDrK5NbkFeKSjWQqGLTzLJJFbqmldTgUwgZh deKrFqZ6DM/L2uDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration Date: Wed, 19 Oct 2022 17:01:58 +0206 Message-Id: <20221019145600.1282823-37-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-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?1747129234153487808?= X-GMAIL-MSGID: =?utf-8?q?1747129234153487808?= The console_lock is used in part to guarantee safe list iteration. The console_list_lock should be used because list synchronization repsponsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to stop console printing. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index 32512b477605..77409b176569 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -33,7 +33,15 @@ static int show_console_dev(struct seq_file *m, void *v) if (con->device) { const struct tty_driver *driver; int index; + + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ + console_lock(); driver = con->device(con, &index); + console_unlock(); + if (driver) { dev = MKDEV(driver->major, driver->minor_start); dev += index; @@ -64,14 +72,11 @@ static void *c_start(struct seq_file *m, loff_t *pos) loff_t off = 0; /* - * Stop console printing because the device() callback may - * assume the console is not within its write() callback. - * - * 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; @@ -89,7 +94,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 = {