From patchwork Sun Feb 4 01:16:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148356dyb; Sat, 3 Feb 2024 17:23:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlAliBKpCh25Jx/XkaHm/Cq8vDNqYudJRy9E/sarLWVynyVdqJARiYOoES6eQWXnoQy8fZ X-Received: by 2002:ac8:5450:0:b0:42b:fcde:1a87 with SMTP id d16-20020ac85450000000b0042bfcde1a87mr2350657qtq.14.1707009811284; Sat, 03 Feb 2024 17:23:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009811; cv=pass; d=google.com; s=arc-20160816; b=h1DlryJeZy5mGPo3kKEP+NWQabt0+p330fVRG4N3Jnay+Qxmi9zu8aCN69Qhs+Olnq LBnBzmRfb3+XsuUtTzzw+n+74yNq8UBQ7a/Nl+rIz0axMJuFLS2+rwFN6Eow6X/vAvt/ s9Z8bh9aNInwK7IKuNZed3UG8ZbeG5rfo/aOBfFZennT661ZRrakU/qDzoCmbEV5Yxny eQwtZ8Be23obCdr10e4Vrcd4ndi1v93IGVKUtnpxDuExo3pmJLJrtqVxVbqC6A4eLYCy mZtudyHTw1bjhWYfZyyqYJ28ukTAQflFtiFHgDTFWNckZfIREd7/OAo+/fOiBrEOMdha EymA== 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=MTFDAV2NFOkkAC8aVmF/VtoXV0IT3q49c7Fm7n9koQo=; b=V8Pln5kp706lnnxWeQWGEKDTc7wE3DCP1xtAcWzaVV3mMd7rGgDU2zGYVte4vNnFsG +HMd5U+Kv6/VRWeOhFXzhlYBj6IHWqPUmgSkRs8hB1qM/K+3RRzYxgjLiUr4xzjfXPbc uNAj+BtObphIA2DIcBiBbQltZ8x6iLFdXeivXqsVa2BhEvlDyCHV5ru8/CYDdaqGNnOf cLmGD1yxxYnl9J7NNakr7R/a3MprQ2lcawYfCdaIhXdxHg1Pv4g3xr9c7MLirIS3OY3i TkRbgMVx3t5jGmQ3HHlEARPP6iJW3uNio/7FiF7Cc78zVQP5Ib1s0LQLckKFHNjhqdQU xdNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX9aqr8tfisxbaazH0FNDz8gzEjYsDvkD7BJny7FAcVLxI8sIheCvwkfN3qIwcFrIiOCKXtODqzlLYoIYLy3vJO18eJWA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f3-20020ac859c3000000b0042bf703cfb6si5391217qtf.612.2024.02.03.17.23.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51351-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-51351-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51351-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 071981C22C0B for ; Sun, 4 Feb 2024 01:23:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0084818AEE; Sun, 4 Feb 2024 01:18:13 +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 6B4E7EDE; Sun, 4 Feb 2024 01:18:07 +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=1707009487; cv=none; b=Hmo3uCYGpsJoTdV0SPnhHjbnZuJkEGsaoJFRsWQeR47Gm/i4xtLWrOl+B5gn8oRJGBRAQ58MGchp0ohnQVbAnIMiGIYyB2bbg9LV5uOIkr8OFVfHlyyWjWqCcGm8Nt+20hd+PvQ8UUGtVRWcXIJHql1vD4yW/iwAcJYkYHlyRbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=NR3h4mErQ47RHUi+GxBhB9CL/lVTmIE+3l5kJKozkPk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=e6oJYQaQ9xmtD4vudplaefhW2xVtL1cKdNkExEA8Lxd+QPK3Lt93JjLNkeDECGrrSriUYZz1CtWK9MYJos8EHFDF2pmacxe+Lg3nAoQSlVRhbbc7uYfoRasIOU2T6V5DukepcawK3t0AeSsjxXpKQMbYaYEf0RObxNG0YeQSJ1U= 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 CB49CC4AF7E; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006Ors-1zJh; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.331283280@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:30 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 15/23] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240204011615.703023949@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: 1789929519613263996 X-GMAIL-MSGID: 1789929519613263996 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; }