From patchwork Tue Feb 6 12:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1506837dyb; Tue, 6 Feb 2024 04:37:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUY7jL20lNUWJEGhDgHk5RPN2FHido2UoKydVMUyED6ZBzyNFBKmEW4MENsNkbJe/MRSPy X-Received: by 2002:a17:90a:43c5:b0:296:e3e:fc0 with SMTP id r63-20020a17090a43c500b002960e3e0fc0mr12291327pjg.1.1707223044123; Tue, 06 Feb 2024 04:37:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223044; cv=pass; d=google.com; s=arc-20160816; b=U42I4Kn4RDsxWpybCxprc5RFQ4AXnbhiR3oHApkDy2PQVgCGOjTJjRMD6exDzZ+13q XgwR0mLg+CeehJPcRs1se7NUS7TTgfwJtcrr8nwbKLjXpCnEw/bLWmX4hNEYj4abauwu fUZ62/Eg9jh22x3nYrOnX7XYUel3NigI3uDq5wDIn3IztLy7fFIMXXYm8Gf7NdNl1RwQ VKkT7gacvsQDK6xrfxmn+gyMFnyw/IoCIahcJZdZDwEdC2yXlbRoW/X9v0X4h4aEnvQS fXSMjBRyYUTuR2NmMepa8RqA3/dhX306YYuJzB+SY29ezIgAT/ncKPiElObL8M4cFxet BXvQ== 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=qLO9528/AFQeQ08mVECH/y3JPQcyc9jWqtGZe8Oheaw=; fh=53SKGGjhNTe5zUJRwdlIIzqN1iOz/oev+lX+dC+oJd0=; b=K/mUXgH998ssroZ3VrvbxkNe1gv4Hz6NgovU8A4o3fPt4CkLmQv64LLd/P3jYVLNGM C7/Hqnln1gVlz5qzRe+HNPwkqScRwjxPju7DAUulQeriDMUBSqT62J6eyKEOjhcpW4tX XcQizeons6/NDdLCO2ccIf+5Uqhiwn+DXfoGE71dpeP5wuV5yCFEi0gX6LvCD1UxnO3M bzM/kc554uGvNFYLyPNpSmm0/7JHKCZQQihxbspvV5ZPUB61Wq0JubRs5ZblWm1VIHBe y2+D1Y5J8aCvN2z343ak4lFBjPPHHQ+6BnNjy1Y0H8wDwxzuw1d/AHf5NWDy40A5OE8s 2awA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXSmdUm1kqi+cHwMOfUrKOIv4nItcA1zEw3ZE6h7GyJD3PLg2EXfflzaCq4dQHPvv5d14LvmnF/kxOBBKo5aFMzz7sS3g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id pg17-20020a17090b1e1100b002960ecfb434si1086507pjb.160.2024.02.06.04.37.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:37:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54924-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 B2AABB2823E for ; Tue, 6 Feb 2024 12:27:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5B72151CDA; Tue, 6 Feb 2024 12:09:41 +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 2655E133422; 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=WD1noir4Et1UHXNsH63D9doQn3EXM2I4AwLN0jrTcYgrXEAjuQ0TgM4m/aPnkpDnIVM2d95hO19mgeJJnZq1vq0XX2AvMSUt8a3mdCZ4ZDhTW0r61vWdk1mG6OzVFOMdpUncjlSuNKf7onTutczuNrHplBflBc7nIMpM44d36Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=QRzNsPzlJd46xARPV8LoVgr8hMSulcnSOm9LygT2RX0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=AZMWv8mc3ayqjcdr0zl3XJeSe4qIg4aLn+1bbMtmzGNYvjJEeqBB77vxjy/xunW1Xkbs/xBIc1ES87JsOH6qF+xHHa5+wVWPaCjLG7RXESvTMv/2+GpZPoeCusiY8eGxhE23+nc/pKwI1/81guYbusu2h1RJqVjp7l9IRUdGMnA= 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 107E4C43394; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bPq-24wh; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.362950692@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:54 -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 49/57] tracefs: Avoid using the ei->dentry pointer unnecessarily 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: 1790153110935021690 X-GMAIL-MSGID: 1790153110935021690 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) (cherry picked from commit 99c001cb617df409dac275a059d6c3f187a2da7a) --- 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; }