From patchwork Fri Feb 2 02:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165489dyc; Thu, 1 Feb 2024 18:32:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUaR68ssMXdxwx/KdOnWS4hwYiQxB1EtNemPkFdlxLIa8soGywSKCheEqFlgsfwJF53ulo X-Received: by 2002:a05:620a:4629:b0:783:7a44:3787 with SMTP id br41-20020a05620a462900b007837a443787mr1429182qkb.15.1706841164273; Thu, 01 Feb 2024 18:32:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841164; cv=pass; d=google.com; s=arc-20160816; b=ie5G0DNfgzX3jghzjitADzdby1kgN6P2annBGIdDYLj9bROs/58P0/Gqd66u5mq3RX +5C6jTS12m01jl3MuU6FBHWJZr5xJFes0VGBlUtnbbiJFSnZDDCj4/2pISx+FMnYuIfJ kI88+nv+wEdOROZw2y1QmyRuMQR6pzjvD06FuleUeqWryWU82BghjkhzFaf/4Lpd2QZx 8DAX/7iLLyZSrkk0nHaNRkaLdbTmeH1TBBc2ss/wGrBPJ/SECL/VgupUU2pXSUB/IqLo 9zmRO4CGz1hYHmz8gyQz0tmZXUJnyVBKvGntvAnBHbV3e00T8fJPlMBmbYPVJsJoZPgR lNOw== 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=1StJzQdcbFCUjy6KdEzslNkyz9IsDAJM/7sSK4pi1Uo=; fh=eqZCkaObjF44xMz8fOKl9vYFj3+ypL/RQhNc+mUV8P8=; b=YJTaUiz+7Mwf1xul+nmH+NDoncTN26wehv5BYVMK3IFnY4jKDxnliU6dzVKy1ItSXk KwfZlQxleu+fYfNfLUPPYV4boaftE8R59DlUoYFNA6ShnOnLj2mcI1EmUc4ezVz64878 iuFK7ieIVM9Eanv68lQrvRm980noa5psY5uHwwM8tEY0S5tpfHoCbBKgx49DwIc8dphF 5sSyW0O99FQVUcavpFIwtlN888IxUckjQ3EQrP4Oldqy93HIuV36wF5pEq/opR9QFbMc Hv3EEBgullyC4d3N32np33EaXJqND62zKR8SLR4BjhBh4sHMFgU5P2HUdWry2quiUXCQ u95g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVn7su4LP4JV+daQMChVDrHxJ8xhDA9Es4tRILCc/qnnULtSqcUBdMLBdrMYKohVl175DkEmqYUR5K2v4LSt4ocSg2/TQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b8-20020a05620a04e800b007840449a485si1005749qkh.234.2024.02.01.18.32.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49098-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 139861C2327E for ; Fri, 2 Feb 2024 02:32:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ED1017BA8; Fri, 2 Feb 2024 02:30:09 +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 3EB82D30E; Fri, 2 Feb 2024 02:30:05 +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=1706841005; cv=none; b=fmc76MBLtwFS24uDs7Jh34kOzj3hLnoX3GFZWNDGGWHB/L1jSx8KNDO3ltdlxG3G9Aq06SqwrDn2C/goRFD2Yf3Y4EcFF2AKa8XKI3Pwmw5nmXCp9rsrNmRY3BymtaOleinbIyt4Kbwc/klB0gY+NR/tss7a0ohudyk2GbfjcZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=VbPnmr5i8jO9pUVUWfcJV065CxA6MC9e4dU/HikVKBs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=uId2wm7LgiRAmli/Uc5UAJCbX9f0cqaK5jyy2dfOJ1lLAwoiFl706itrtR4GOpvd6RBBGoQ36MoOe1NwuKQLW4gKAbLLegtQkuxTh3rm9v3Kwcyrgis6Bsee6HsWfbK+8Pxl4hQeaVY4PDbmJbFByG5FNNOETUbJYECENo2O0RI= 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 27C26C41612; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005k94-0huT; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.027918668@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:06 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , Linus Torvalds Subject: [for-linus][PATCH 07/13] eventfs: Clean up dentry ops and add revalidate function References: <20240202022959.515961549@goodmis.org> 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: 1789752680583017344 X-GMAIL-MSGID: 1789752680583017344 From: Linus Torvalds In order for the dentries to stay up-to-date with the eventfs changes, just add a 'd_revalidate' function that checks the 'is_freed' bit. Also, clean up the dentry release to actually use d_release() rather than the slightly odd d_iput() function. We don't care about the inode, all we want to do is to get rid of the refcount to the eventfs data added by dentry->d_fsdata. It would probably be cleaner to make eventfs its own filesystem, or at least set its own dentry ops when looking up eventfs files. But as it is, only eventfs dentries use d_fsdata, so we don't really need to split these things up by use. Another thing that might be worth doing is to make all eventfs lookups mark their dentries as not worth caching. We could do that with d_delete(), but the DCACHE_DONTCACHE flag would likely be even better. As it is, the dentries are all freeable, but they only tend to get freed at memory pressure rather than more proactively. But that's a separate issue. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.124644253@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 5 ++--- fs/tracefs/inode.c | 27 ++++++++++++++++++--------- fs/tracefs/internal.h | 3 ++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 16ca8d9759b1..b2285d5f3fed 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei) } /** - * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode - * @ti: the tracefs_inode of the dentry + * eventfs_d_release - dentry is going away * @dentry: dentry which has the reference to remove. * * Remove the association between a dentry from an eventfs_inode. */ -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) +void eventfs_d_release(struct dentry *dentry) { struct eventfs_inode *ei; int i; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 5c84460feeeb..d65ffad4c327 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = { .show_options = tracefs_show_options, }; -static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) +/* + * It would be cleaner if eventfs had its own dentry ops. + * + * Note that d_revalidate is called potentially under RCU, + * so it can't take the eventfs mutex etc. It's fine - if + * we open a file just as it's marked dead, things will + * still work just fine, and just see the old stale case. + */ +static void tracefs_d_release(struct dentry *dentry) { - struct tracefs_inode *ti; + if (dentry->d_fsdata) + eventfs_d_release(dentry); +} - if (!dentry || !inode) - return; +static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct eventfs_inode *ei = dentry->d_fsdata; - ti = get_tracefs(inode); - if (ti && ti->flags & TRACEFS_EVENT_INODE) - eventfs_set_ei_status_free(ti, dentry); - iput(inode); + return !(ei && ei->is_freed); } static const struct dentry_operations tracefs_dentry_operations = { - .d_iput = tracefs_dentry_iput, + .d_revalidate = tracefs_d_revalidate, + .d_release = tracefs_d_release, }; static int trace_fill_super(struct super_block *sb, void *data, int silent) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 932733a2696a..4b50a0668055 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry); struct inode *tracefs_get_inode(struct super_block *sb); -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); + +void eventfs_d_release(struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */