From patchwork Mon Nov 20 23:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 167430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp294181vqb; Mon, 20 Nov 2023 15:54:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4BjrUTbt1e4u1pXx/TGrd+ZYDIZRATtJGaslu78X9BQukbY5/+k9oL8iJYwtNIGlfCppU X-Received: by 2002:a17:90b:2347:b0:285:117a:deb2 with SMTP id ms7-20020a17090b234700b00285117adeb2mr1395585pjb.23.1700524489694; Mon, 20 Nov 2023 15:54:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700524489; cv=none; d=google.com; s=arc-20160816; b=jxG51ciqZi96he8ICxYiU6np1ZF+1H+NhzqDbUfJcFZQUGmeMueCvSzzwnIMn6WWIJ lUJUmIXI7mrj4qgAupB96T+Z6vBoyFre/cOHpcRmkEJ4YyOgD1kNTbSxx/Dr2sMMA749 zVn4OKwlo1+D4rib/D+mXP0g3hqMczlqxetE2YkCbQX71cE4lL/dbAQWU49P4SNGwmr/ dcAgxTEahuxv9rfi6wK643q2Xk7xnwJKZduBTXTPdIAdYjH0mFMFYM+bsaEDKLIoJUoH LY/5Wgk6Hj2BvCmtWTJ4LuLkS5Q6E73naYQrf4woJvoS/hAHsBGf0YBPdQhsqGzNFkxA DKEA== 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=YYLYUNl9fi7Qz/ewHIchNEmCcZiQFtZ0DRgTn9EckYA=; b=hpfuEA5TVEagQqK3QdrD4eSIf34KXZAmhCA9QwyZILM7F4LLDFP214zlU0xDjgq8/9 7t8IyDCeKF/jW43a9kHcCQdRFv+4meAGwDtW7Fp3mYH0HYZ5hI9bx0eJXqs4Xhvqlob0 Obf+DK/GaO5Snd76B9FX1So8WD3Nb5Pr+GcCBp2VLCxfpyqJAYCXx+8cTCcXfF3cI/sK G4UDo4U+ZbuFjnmWE4dflJz/C9Spn+Dlue8lsfcKTgU0rzijYdmljXBpuyXZG19LWXk7 48GZMJai0zEM6vvCyJczAuzaPmR+UITqtvD9FFKLJRad2YWvbae4xHKED1zU0PKLmSV+ zAZA== 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:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id sr8-20020a17090b4e8800b002809a033855si9293791pjb.157.2023.11.20.15.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 15:54:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7693D80909C8; Mon, 20 Nov 2023 15:52:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232678AbjKTXvt (ORCPT + 27 others); Mon, 20 Nov 2023 18:51:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbjKTXvm (ORCPT ); Mon, 20 Nov 2023 18:51:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B277C3 for ; Mon, 20 Nov 2023 15:51:39 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BB41C433CA; Mon, 20 Nov 2023 23:51:39 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97-RC3) (envelope-from ) id 1r5E3W-00000002PnN-1h4t; Mon, 20 Nov 2023 18:51:54 -0500 Message-ID: <20231120235154.265826243@goodmis.org> User-Agent: quilt/0.67 Date: Mon, 20 Nov 2023 18:51:06 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton Subject: [PATCH 1/2] eventfs: Remove expectation that ei->is_freed means ei->dentry == NULL References: <20231120235105.834774147@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 15:52:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783129167038247897 X-GMAIL-MSGID: 1783129167038247897 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)