From patchwork Fri Feb 2 02:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165002dyc; Thu, 1 Feb 2024 18:31:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGZuV5gKjuqZtK7BsqKzn5yGg4TBrhn/BiVttb0cG7Z5x3PpCmb0sxZDI5xqNDqv/8b52v X-Received: by 2002:a92:b70b:0:b0:363:a8fc:9a8d with SMTP id k11-20020a92b70b000000b00363a8fc9a8dmr2415729ili.30.1706841089843; Thu, 01 Feb 2024 18:31:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841089; cv=pass; d=google.com; s=arc-20160816; b=ejIxCagfdwjwil5dr5hpIJoZQOMSb39bBjIh6JKBEwAakmR/Rnjh0g1TNIZIQamtdB 4f+j8OuyLM8JncNKVfAn1qb7JPVGdYg3VevHZ8LXyQXr69bR7mIHIk53PUcd4uPUNL+e dHQT7gNbsdQsdWbvo3h/WSr+nD+55Q8xGDMG+Kh4JGrkZaU/xUSnLzrHn1Oi+BSyzNmS ayDh02nGbVSLbHMwpamK5VXfRibw1o55VKvhO0S71u/uXNcBQVHuTwMT24ShrKAzDBJG hdGZrUptuAzJEJsrKnEMT9C7G0VKmP1FZBLcM+JKmWepsA3AVoa1dyV/D0/8zCDoegIY z07g== 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=wKE/WufTyap63SfcxU9dPL8mhs39rgxfXyZYuQOvuDU=; fh=ZShNmrTTRFnD228HR7YcHUJ6VJrJ3dwDecnB2ebtYXg=; b=X+iv4fMI4FxqH72AyCwrIi9RAR9+3a7A+sR8v/4n0nozJOVPmhwFAyujJPRjyyGCfU iI2grgd4VKHvyVQ/4ztzINba57puSrg4aMkW7iz4wg/9fJvlPzvlF/Pt/H32lAgtktgZ dd678qUsJjqJUS5WY6schBH+kv/sJfef/CfUQPSmJYnEHYm7oKuv6h93RX96lQguUJ5n ZrsEcD0DZCC9OsqfALJPPZTsS/2LNnwlDiwpM1BvqyF8iBRZBn/slOP+ova5BLQrlk0T fcNKG3p1sHaHj+nbCxF5mD8fSj1yad6IsMy89vj0874iMC9sBsNLwD9NdhKmfcV525u6 QCXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49097-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49097-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWWzxrSKrc/Pf/k2+5h1u/E6hwNLK61Y+HClAS4onG++JPEO0HGxFEhyfZkgJPlgOElaO40O/LxkL+0zrsC7mFkZG5uew== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 19-20020a631953000000b005d79125d04dsi742947pgz.726.2024.02.01.18.31.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:31:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49097-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-49097-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49097-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 8E0FA28A683 for ; Fri, 2 Feb 2024 02:31:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B5E8168AF; Fri, 2 Feb 2024 02:30:07 +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 1A6B3C8DB; Fri, 2 Feb 2024 02:30:04 +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=m1hjlENu/2p0GcEDCV72iKhx5hx9FbKQPCUFei+dRFflc/BGq4vZxXx/HqxY+TVVnjoUvtEtJi2GmUmDMgn17/W82AKvjQMj1YJ5W29LM7DV6JNmwb1/K93CWOH1fg4J0s/D612kEo/z4gXb1ilxfEQZ4jhPktuzlstbMNTxvWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=NR3h4mErQ47RHUi+GxBhB9CL/lVTmIE+3l5kJKozkPk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rswfJaxezvlxFotSZLfo05E7DWzMaC0Ci4feCCiMQXc9VbfIVVgpIgAdEYKB6IIjyIqJ32izABQGDcjHgsWfPanSM1JFn/Y7cUAKYzvnLFhipUNIIsRZSLYb5uNCE3lS7OH327FxQQFZZQZmB9KaCoWvy8OlzpQRh6djk8IWO94= 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 A9488C43390; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJu-00000005k7c-2tuQ; Thu, 01 Feb 2024 21:30:22 -0500 Message-ID: <20240202023022.554271330@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:03 -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 04/13] tracefs: Avoid using the ei->dentry pointer unnecessarily 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: 1789752602451483642 X-GMAIL-MSGID: 1789752602451483642 From: Linus Torvalds The eventfs_find_events() code tries to walk up the tree to find the event directory that a dentry belongs to, in order to then find the eventfs inode that is associated with that event directory. However, it uses an odd combination of walking the dentry parent, looking up the eventfs inode associated with that, and then looking up the dentry from there. Repeat. But the code shouldn't have back-pointers to dentries in the first place, and it should just walk the dentry parenthood chain directly. Similarly, 'set_top_events_ownership()' looks up the dentry from the eventfs inode, but the only reason it wants a dentry is to look up the superblock in order to look up the root dentry. But it already has the real filesystem inode, which has that same superblock pointer. So just pass in the superblock pointer using the information that's already there, instead of looking up extraneous data that is irrelevant. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.638645365@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 | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 824b1811e342..e9819d719d2a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -156,33 +156,30 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, return ret; } -static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry) +static void update_top_events_attr(struct eventfs_inode *ei, struct super_block *sb) { - struct inode *inode; + struct inode *root; /* Only update if the "events" was on the top level */ if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; /* Get the tracefs root inode. */ - inode = d_inode(dentry->d_sb->s_root); - ei->attr.uid = inode->i_uid; - ei->attr.gid = inode->i_gid; + root = d_inode(sb->s_root); + ei->attr.uid = root->i_uid; + ei->attr.gid = root->i_gid; } static void set_top_events_ownership(struct inode *inode) { struct tracefs_inode *ti = get_tracefs(inode); struct eventfs_inode *ei = ti->private; - struct dentry *dentry; /* The top events directory doesn't get automatically updated */ if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; - dentry = ei->dentry; - - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, inode->i_sb); if (!(ei->attr.mode & EVENTFS_SAVE_UID)) inode->i_uid = ei->attr.uid; @@ -235,8 +232,10 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) mutex_lock(&eventfs_mutex); do { - /* The parent always has an ei, except for events itself */ - ei = dentry->d_parent->d_fsdata; + // The parent is stable because we do not do renames + dentry = dentry->d_parent; + // ... and directories always have d_fsdata + ei = dentry->d_fsdata; /* * If the ei is being freed, the ownership of the children @@ -246,12 +245,11 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) ei = NULL; break; } - - dentry = ei->dentry; + // Walk upwards until you find the events inode } while (!ei->is_events); mutex_unlock(&eventfs_mutex); - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, dentry->d_sb); return ei; }