From patchwork Tue Feb 6 11:32:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482614dyb; Tue, 6 Feb 2024 03:53:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5PjcgcuVr0VQWu0lyK3CncLSJcX3VTHFz2LLfJaXy3ltI7FsEylfl8JBtNmL+tcbx6keZ X-Received: by 2002:a05:620a:110b:b0:783:d369:6e5a with SMTP id o11-20020a05620a110b00b00783d3696e5amr2115831qkk.76.1707220418117; Tue, 06 Feb 2024 03:53:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220418; cv=pass; d=google.com; s=arc-20160816; b=hF6X0qMYw6YVxcoqY/lmUMdleC9sc7ZwRKAvG/t8dqvKY1sHFxQXtkjCiAXluyGxHw mhVFvVOlrOTgCFtkMz1+ClS34ork+qlyGGbd2LIW/HaUzQSCCEXtga9zutM/GWliMTTk 7vU+ocgO5yTKqnJ1+LQk2xlxJd/OQT10uBui30XaZtI7KwPMfnuecY+EK4aVUeQgoKa1 TNpVLcASWCJRXjX1IQTPG9CVwDjNlKsDplnE57LtHRzorGOdwvMztvSfyicc7MEW5IuE +L9jrobGxNUC3aiZv0oITaJVcltmGXgR6lXeKtzI13Qy+CU/X6BfS5jP2veNFd9CRync u3lw== 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=ATYjBrgrQgHux704Rexi0i1KZf3q/HOV5z1Ibp2pi6Y=; fh=GrnETzDgXL+QIWrSyG2PtEzPcrjYYdKBv9r7ah9uAig=; b=zqhhJWfhl1Q/XjNrcQ9yda3ZSqACSTtOYgpS7Guu8a/m5d+xj0hs/jXBfT16EvRhfV TVA6BxUKdDO5hN/88EQm3oBMyE8sJUEEB+GryoRAdR/XmgpEI2QZESV8Jrm+7rSFQXit Vd0e/4eCVDSYvUorWBVGp9RoUkrj57RlJfE81vUzxQ0Dg3mzwiKdhPk5Ja3286QSSE/n Iu24JpVP3MP68z8h9UX/X22UcrfQqZ3cuVjnKnMZIYDqfiBFSvMCDsa18jIqsWeZV8y+ JYdb1g51vwV+ThMom6LvaXgN3gINfW/u/hrAYEpKSEL8wOR1MwUFz1ARCT8mmeQJJPPm sovw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVT4SDWyrk9OBttsTKos2n+eXVLxhQ7p34rA/Jr5EXsfSOkaMUUytfzSjr0OafpKVPAI/mX5XLBIkXFYUMJkr4hZEp7VQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c4-20020a05620a164400b0078532a9689dsi2055060qko.623.2024.02.06.03.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54805-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 E485A1C226B2 for ; Tue, 6 Feb 2024 11:53:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8284B13A267; Tue, 6 Feb 2024 11:33:39 +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 D4ED9134CD1; Tue, 6 Feb 2024 11:33:32 +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=1707219212; cv=none; b=m7Oddcg0ezdJG+SEHewvOHMGPBNjP0NSfRbLp7xM/t+P+MQgiU1CvwNlmHvUPUWVKsmI2d8Gef++rYbNzx8sd+PRRvFvvlSNHlZ+ZSnCPaK0aVspghUw+eCM4Bh0L1mHusrIt8JMVtpd+j6qwJjrctcJc7H4kNPIC3WoE5ArTOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=d4lAO/Lp5Wz8u/KkIxfXJiOAORWOFSfTFPDiSHjfGI4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RxfiupDuDgqM8LN5NQjKrGapYUbec+kO8Qsgs/2QrqIaE0rzhs9ExNY+QCRTr+8W6wvOgFfg9SoqsyIClmOQXoQ7eszXPxs3fuK3EMM/ZOKeNNk+zYQiaaz7fFRJA2KOh9V1rkde4kxTzoqo7rUnULoY9tTov9biz+CyPLCHeu4= 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 B58A3C43399; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aPK-0cXc; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.010494265@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:16 -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.7][PATCH v2 18/23] eventfs: Clean up dentry ops and add revalidate function References: <20240206113158.822006147@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: 1790150357534781604 X-GMAIL-MSGID: 1790150357534781604 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 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 */