From patchwork Mon Nov 20 23:15:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 167424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp278243vqb; Mon, 20 Nov 2023 15:17:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7Sfj+rYw/krlir9k+JEnEkgzf9iBPjdhKjbo3oEHrrLjbTGNwKX0tOHGn7aDUWIVpfwBh X-Received: by 2002:a05:6a20:d41c:b0:13d:8876:4c97 with SMTP id il28-20020a056a20d41c00b0013d88764c97mr6371416pzb.16.1700522238945; Mon, 20 Nov 2023 15:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700522238; cv=none; d=google.com; s=arc-20160816; b=oD8WoG7RHyk3dsApDBAtqnBBY7sl7iBy0Y/IV+H8FEXKD9eDGPHgbKRYX5nbrcwxBB jBKdmoj5qviN8B22H8KA243GHfxCZZv0AjreRG2V/JMKnxMhDXoCvvetWTP2+Zj8tRRL C1DyTxWA8MR2jH4uLqFvsreulZQFXnDXRUr80qLOtdPxCnZz1Q4EEtGEH5EUasaWDGoz PGwXC4wRwnX/1lmHV1XyN+ynHigXTy8wrY5qJE4gmmEh3HotzRnK+a6dcJOVDPMm3ZSb aLA/o+r+Gvgug7JZ2z12lEHQaf/UkmgrlIkax+q5RoXChtOJ0QFI1aIzOnJy/8Gd172b 03Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=iU31SwZx+cmdtIT7tz5DjwnlwY4z/nd3XsVWyQ0TPz8=; fh=cY9HGbp9RiQ9xCYqjybSe1/cIiXVFs0Cn9z6ge1iyyY=; b=yML/GkCS12DOXcN5HVReGCAT07r96p9l9MRit6mVCPuMQsmiPBbeelzcQMa7ibz6yR zd/0W/11+8YE6HLtdw0w6Hp0PitoZdPaQAZTFWbMblxmY/S61T8FCm97V73OFg9tbnpY IpYfNlXWBA+apyKdgbpfZ5XotX61Hb5eNU5LpobEAIg1WXQsvN8QaoTbyh8pBV11De0r xBZucoyzIRqvIp609and48DS0svrrXVcYUeLb0fho364p9bzhoZKs5xn5MUdCOeoUVJ0 ye8v7QdhYWDxXKZLB+lsWtenylR6wXjbbhREON1mqk73L9D/Z4Sk2Ud6vPm8fBAbcHW3 wYCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id fb27-20020a056a002d9b00b006cb901a87c4si3523194pfb.376.2023.11.20.15.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 15:17:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0FF5B8058A0E; Mon, 20 Nov 2023 15:17:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbjKTXQZ (ORCPT + 27 others); Mon, 20 Nov 2023 18:16:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbjKTXQU (ORCPT ); Mon, 20 Nov 2023 18:16:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA1D8C9 for ; Mon, 20 Nov 2023 15:16:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96A77C433C8; Mon, 20 Nov 2023 23:16:15 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97-RC3) (envelope-from ) id 1r5DVG-00000002Obr-37eR; Mon, 20 Nov 2023 18:16:30 -0500 Message-ID: <20231120231630.606101643@goodmis.org> User-Agent: quilt/0.67 Date: Mon, 20 Nov 2023 18:15:54 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton Subject: [for-linus][PATCH 1/2] eventfs: Remove expectation that ei->is_freed means ei->dentry == NULL References: <20231120231553.374392736@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 15:17:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783126807013724543 X-GMAIL-MSGID: 1783126807013724543 From: "Steven Rostedt (Google)" The logic to free the eventfs_inode (ei) use to set is_freed and clear the "dentry" field under the eventfs_mutex. But that changed when a race was found where the ei->dentry needed to be cleared when the last dput() was called on it. But there was still logic that checked if ei->dentry was not NULL and is_freed is set, and would warn if it was. But since that situation was changed and the ei->dentry isn't cleared until the last dput() is called on it while the ei->is_freed is set, do not test for that condition anymore, and change the comments to reflect that. Fixes: 020010fbfa20 ("eventfs: Delete eventfs_inode when the last dentry is freed") Reported-by: Mark Rutland Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f8a594a50ae6..f239b2b507a4 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -27,16 +27,16 @@ /* * eventfs_mutex protects the eventfs_inode (ei) dentry. Any access * to the ei->dentry must be done under this mutex and after checking - * if ei->is_freed is not set. The ei->dentry is released under the - * mutex at the same time ei->is_freed is set. If ei->is_freed is set - * then the ei->dentry is invalid. + * if ei->is_freed is not set. When ei->is_freed is set, the dentry + * is on its way to being freed after the last dput() is made on it. */ static DEFINE_MUTEX(eventfs_mutex); /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from * its parent's list and will have is_freed set (under eventfs_mutex). - * After the SRCU grace period is over, the ei may be freed. + * After the SRCU grace period is over and the last dput() is called + * the ei is freed. */ DEFINE_STATIC_SRCU(eventfs_srcu); @@ -365,12 +365,14 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * created the dentry for this e_dentry. In which case * use that one. * - * Note, with the mutex held, the e_dentry cannot have content - * and the ei->is_freed be true at the same time. + * If ei->is_freed is set, the e_dentry is currently on its + * way to being freed, don't return it. If e_dentry is NULL + * it means it was already freed. */ - dentry = *e_dentry; - if (WARN_ON_ONCE(dentry && ei->is_freed)) + if (ei->is_freed) dentry = NULL; + else + dentry = *e_dentry; /* The lookup does not need to up the dentry refcount */ if (dentry && !lookup) dget(dentry); @@ -473,8 +475,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * created the dentry for this e_dentry. In which case * use that one. * - * Note, with the mutex held, the e_dentry cannot have content - * and the ei->is_freed be true at the same time. + * If ei->is_freed is set, the e_dentry is currently on its + * way to being freed. */ dentry = ei->dentry; if (dentry && !lookup) From patchwork Mon Nov 20 23:15:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 167423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp278112vqb; Mon, 20 Nov 2023 15:17:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvHF4E1YW6in0rkFWfxflAn+dM8AGgU1hyoyj30XwZ5TCcFJcqrBBcaKS50HyKv+vyee2H X-Received: by 2002:a17:902:ea04:b0:1cc:51b8:80f7 with SMTP id s4-20020a170902ea0400b001cc51b880f7mr8337911plg.26.1700522223933; Mon, 20 Nov 2023 15:17:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700522223; cv=none; d=google.com; s=arc-20160816; b=yDR6STbroP5BmXT4U9HBgsD7jwJW+hb2L2xEk8twJRiBG+NlgIo9xFEqAcRnmL2HoG Ipse3RubSb8aO/sxSc/ypKf10kfCdWEAM77Rg5WKYe1n06vp0G7f9R0oyKHSWx+EVGPH 6dN3RfoHIDw8g7wNVUtxl7BNo+PazG7zAobjbImpv+11fRscMxKBQghC3qy6L9lN1vFD SZM9RdgyTHWeZzZ/2sdGEyV2EaP1ca/qNtz6reHT78ZSC1oRApM5rD7yM1rpOyxB76RQ 6yBsiaJ2HGl6Ci2nCarhu1N1KTHCl67yGGWP18k8+vhwufeAAmawu9ZQPY+/Q0+RmO5a Nrhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=jikyGUxFj8iW0/SFDWGy/tR6G/kZxrxCgx+p1SblOLE=; fh=YjQBJM6qZ3nc+ekfu5B3gr3T40+s7gIpg3qawEiJ27s=; b=IKKH9Rqt46l/7rzF0O+b2ljpJz/1ky5J4xP4uJVBzO533fl1CNVHI0+uKuaAZtk2Eb ol7QUy4jYmxFXWleAyaSUj6d5S+Ix7bc4bG/oJfNDCkRufTSOzbsNKA6B5BKd4qnGJje zHFbpYYy37DD2rOF/84PjiZg59buOnHQPq5U0455rbbqFeXrJCfENloH45GMJPWiG8Lw MO1Qgcj2AyE2I5I/4H1/5iMJ/qMHPwVB4zg0nxWnrVqfmmCgcgiGn4GgJrpKwQb6ZT4m TrgPpaSaZ4nMsBc6Po01seVc/hGTbpq2Y2M7esf6bjG8bI9weDDSL4rP8E2X98R6fKGB MAJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t2-20020a170902bc4200b001cf641feed4si2099469plz.446.2023.11.20.15.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 15:17:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 44C4E8058A0E; Mon, 20 Nov 2023 15:17:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230138AbjKTXQX (ORCPT + 27 others); Mon, 20 Nov 2023 18:16:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjKTXQU (ORCPT ); Mon, 20 Nov 2023 18:16:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8EF4A2 for ; Mon, 20 Nov 2023 15:16:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93559C433C7; Mon, 20 Nov 2023 23:16:15 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97-RC3) (envelope-from ) id 1r5DVG-00000002OcL-3mEK; Mon, 20 Nov 2023 18:16:30 -0500 Message-ID: <20231120231630.763281084@goodmis.org> User-Agent: quilt/0.67 Date: Mon, 20 Nov 2023 18:15:55 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Naresh Kamboju , Linux Kernel Functional Testing Subject: [for-linus][PATCH 2/2] eventfs: Do not invalidate dentry in create_file/dir_dentry() References: <20231120231553.374392736@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 15:17:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783126791356062450 X-GMAIL-MSGID: 1783126791356062450 From: "Steven Rostedt (Google)" With the call to simple_recursive_removal() on the entire eventfs sub system when the directory is removed, it performs the d_invalidate on all the dentries when it is removed. There's no need to do clean ups when a dentry is being created while the directory is being deleted. As dentries are cleaned up by the simpler_recursive_removal(), trying to do d_invalidate() in these functions will cause the dentry to be invalidated twice, and crash the kernel. Link: https://lore.kernel.org/all/20231116123016.140576-1-naresh.kamboju@linaro.org/ Fixes: 407c6726ca71 ("eventfs: Use simple_recursive_removal() to clean up dentries") Reported-by: Mark Rutland Reported-by: Naresh Kamboju Reported-by: Linux Kernel Functional Testing Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f239b2b507a4..3eb6c622a74d 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -326,7 +326,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; struct dentry *dentry; - bool invalidate = false; mutex_lock(&eventfs_mutex); if (ei->is_freed) { @@ -389,17 +388,14 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * Otherwise it means two dentries exist with the same name. */ WARN_ON_ONCE(!ei->is_freed); - invalidate = true; + dentry = NULL; } mutex_unlock(&eventfs_mutex); - if (invalidate) - d_invalidate(dentry); - - if (lookup || invalidate) + if (lookup) dput(dentry); - return invalidate ? NULL : dentry; + return dentry; } /** @@ -439,7 +435,6 @@ static struct dentry * create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, struct dentry *parent, bool lookup) { - bool invalidate = false; struct dentry *dentry = NULL; mutex_lock(&eventfs_mutex); @@ -495,16 +490,14 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * Otherwise it means two dentries exist with the same name. */ WARN_ON_ONCE(!ei->is_freed); - invalidate = true; + dentry = NULL; } mutex_unlock(&eventfs_mutex); - if (invalidate) - d_invalidate(dentry); - if (lookup || invalidate) + if (lookup) dput(dentry); - return invalidate ? NULL : dentry; + return dentry; } /**