From patchwork Tue Feb 6 12:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498951dyb; Tue, 6 Feb 2024 04:22:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQceOOyFJIEqxE//Awzp0E6I8Ww3LkYqZKNYOYGQLGIu/7efhwVpBxD84Db6vuFxIEnd83 X-Received: by 2002:a17:903:32c6:b0:1d9:c187:3f8c with SMTP id i6-20020a17090332c600b001d9c1873f8cmr1742382plr.58.1707222169663; Tue, 06 Feb 2024 04:22:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222169; cv=pass; d=google.com; s=arc-20160816; b=cY6E8A+3Q6mh7XpNAzw/Hql9WMIdJfr+kInxI2v4RSSDIVhM1sC0FGVdCA760A2FUv FEQFr6YCysqpsDP/xkyVH9TFU263KOFiePslyYWhbfEeOZNVjTwFpY9HAgriFx2uClMX Lmm+sVUMSGxRzUYeycysDQ4YBzlVZtyP/t79I3gyswQX9C/gYhpnV5oDIvY2PwTkdOdN E/eb8BmVyzYvqGAvNLMoGWLU7PH3PaddGL89OrLvvFgF0dKmzVQNC0b1kxoICJIi9pgz CxtjToeiKn7zMNNvA7rtqsU6TPNowshV+uCRsVw3cKL2k3ivHdV0A2Ef2Xr7XiTR4nW1 f7kA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=wtToWHzsErUZSHrTYi952TGMfcmqd4tKVXVRALKDnPg=; fh=4qWsFWbG7U5WR2H5lhO/3zzOEgyyBKjBXFl+4fYyxfA=; b=jKGTm78pzY/Q9CQ1kwFvhbG+GOr9+/lZoILQZPPVFJOm2mwgAcpw1W8Usr7lKFfrOP 1AtJRC16+vXjPx1ic/0CpcaCU5Lar05clArScYcJBC6THHtaG3rhIFgXFesfoKqBPvEe Hxfn3kvyI6wCb1dK+/dcW6m5O1Jx5RRmvdEwQxh75m2/0+w/AdS+ig//b3/kpwlFXlDT qBbSckkFEMoauseEPMw1tr/CuEFVRTFnCxLf+O0LoaRWGB/rAnzRO8r+9NIH7OZRHmHv yxAUYZRJAxQDWARsd+6ZaE93D9PPQJuJrXNUzW4VdasGk/Vtek8MRGCUeljU2czQUzD6 FMbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXp4q2rppRe6a7oWl5B92XC22ctgYL6sjZsfMs/k5CA83lh4AKBOWcdIf1WryTNNjk4jdZNN5nd6Hzm5qoA47gsptzBmw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i18-20020a17090acf9200b002953a1e7e33si1040784pju.164.2024.02.06.04.22.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6FCEA282A75 for ; Tue, 6 Feb 2024 12:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 960D4146903; Tue, 6 Feb 2024 12:09:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4446B137C37; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; cv=none; b=TWE1YE9Agu/20iI1ayjN7/64yN0EagVrPbMHQA9AqVnB4EOCv6y2SLjpsaUAk1tFg360tQ+OBnC8clYYG28B7mbNG2dyUMTW0WakE+kU7j6wch3GwMavk9le4nsyxY2rtDWTclR3O4NLBlMH0QMCgV0J7ayOJk396iOsWCUVqOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=PbQrblDeR9F0JgOw4gGsVCF/2xvBxqNknZ0wT0MnC+M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dnLdyaz2fELQKPO8Sl9lPqwra8UqiB7WvSLTX2tWBS6zhSKwY3Mv9rNDcSY6kOS/PT7RklMXsX7efPiv991nza+n/sACDjswwbrmH+2hxbBzhVvzrspw6UJk4kpU4FEbq2frtHX37P1t+7i2Nj9gvHILYzd9V7P0a54zNxC4I9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1A80C433F1; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bDL-1mZY; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.284520771@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:29 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [v6.6][PATCH 24/57] eventfs: Remove expectation that ei->is_freed means ei->dentry == NULL References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152194190601102 X-GMAIL-MSGID: 1790152194190601102 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. Link: https://lkml.kernel.org/r/20231120235154.265826243@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Fixes: 020010fbfa20 ("eventfs: Delete eventfs_inode when the last dentry is freed") Reported-by: Mark Rutland Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 88903daecacf03b1e5636e1b5f18bda5b07030fc) --- 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)