From patchwork Tue Feb 6 12:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1507106dyb; Tue, 6 Feb 2024 04:38:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0QuRl76L/esx2QrPt8eHz/H0I8Q2l4ioHYCOGSKoRbz2gqH40yqETXeBZm5HCEPAYFkBI X-Received: by 2002:a05:6a20:d90e:b0:19e:9c72:90ab with SMTP id jd14-20020a056a20d90e00b0019e9c7290abmr529864pzb.18.1707223080330; Tue, 06 Feb 2024 04:38:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223080; cv=pass; d=google.com; s=arc-20160816; b=E5K/LCSvnQ/QD0h6/JTfTXNNz0MYu3/EOtQu1whoUFtI34Te8RTlnQ+wZSdP1HgUhL 4U+vzL9HZDEfoEQKZ/OhkyRMnjLz5yHTIjmVFxoqUDYWIk1o/YW1v04Xi9tgDmpOONwL 9KoDyp/zAfxB3qRnldtppfPGYmbL7YdwTeq9Mp9Zgl+x3nPhMP/5X9eFsqMeDWMC6g6b f6DsriCDmBEDrGOVKeXlONGuZXnMJA1G+W8Uxmjx2yCJoPYpnnzIdQwEKuBWRpG3IVfL rnS+RTUuJ+4MNHPj2xOeeQTRN+xxxPqTGNKWJSuvDUIHppYiwtIYevgqfi0sTtG0LPig Qfhw== 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=rgrAzZUZwjdhZAOBcK/XLdzP90uCuuyLOx0Pcytg8bE=; fh=Ba5oIKrQzZZK0aFMZZddYCisM6cWIkoVxLpeZL8+0TA=; b=Zw8J30pZHbyENXGf3AJHM9dqBI2YZeFKcprtmS5VQwxAreHl6B4EGwB5esoltOy2QF pqkQ5LeWk04K/q61Z3CzeDQBPSiLHsPksDCkwFtFdV/CU0zsrquAN0WoNPUym2omlMuH MQAV3m9OMlUP9fx86SNchPhlYQZd9fol+k1pxuWWggTT543LwP1CehHtZHM2qBeQimOz ht834SR1lrRTubKA7M0aURiAfuKykfUNQZUhBL1ONXV5n1RZVfS3aXaN4mJh2Vx1DNQg ucrLa+e1N9ozJubaDihYImwsfg2/TSVkxjl0LY9Lne3pQ8h1L10O2GfQcPgkVc8f7Lop TgBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWt6uyh5x2VHpo2ZxICREnFjQvWzLkbJ4RrENJFgoE+icxor637DsdK7vj6RATYQjVTMXfLdDTHyq8j3fIvZ26P53qhhA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e24-20020a631e18000000b005d6a99217dasi1632423pge.403.2024.02.06.04.37.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54926-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 32D40B285BB for ; Tue, 6 Feb 2024 12:28:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81A83152BF5; Tue, 6 Feb 2024 12:09:42 +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 ADA1D13B792; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=mV/YHiObGIDJE4TOeNC2u3VOiXbtyw4C3hS7AeoakWDBaKcM+v+VUN+oOG33bfNt4FpeDBfm/BAYS4ZTFqCv4dsou3OZPbYR6ZCjqpiXMDWpF9t24fbrIZ3oP411uaIxQ+Uk5w2sItLUPt6Yn/DKIK+gLEp3fThi1zB9FP0m8C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=WKYWs+tozJFf0aESTI4h+kx5amCCXJ1ckyoJFMyYUfI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sqAJrHS6eBQAiMJnx6P9Dp4qGtmZ60Gp+MFSxqnG3jRwptMEpi10asqFbZVSiIweBungC7KjYM/0u7d1JtB2AOoM7hCVL0TzX5ncsJlStBifF3b4w1AYML0x+8LtlzqXhq+gCeH/Fe5v1FG+R9JvCFlrNrzV9WYrLGR2o7Q+fA4= 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 83C43C43609; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bRL-487S; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.845943821@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:57 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 52/57] eventfs: Clean up dentry ops and add revalidate function 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: 1790153148488604574 X-GMAIL-MSGID: 1790153148488604574 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) (cherry picked from commit 8dce06e98c70a7fcbb4bca7d90faf40522e65c58) --- 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 a24dfa7fcf23..99caf1c3d0c4 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 */