From patchwork Tue Feb 6 11:32:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482369dyb; Tue, 6 Feb 2024 03:52:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA/pY7s/txrkob7QNvOJYey7KotFB33Te9WnbLF51hYqm6zv7J3S1rEZGEZROCcSiNBufA X-Received: by 2002:a17:902:e5c4:b0:1d9:a5ec:30d2 with SMTP id u4-20020a170902e5c400b001d9a5ec30d2mr1505046plf.12.1707220378627; Tue, 06 Feb 2024 03:52:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220378; cv=pass; d=google.com; s=arc-20160816; b=JfO8lB7EIgJoc0DVa5fRY7J5yhnYUxysU7Gc4qHWDpe1JRsM/pCRqY729Og8LL8cX7 yfD3+eChqXuou0Gr45r5ZHEArxQUBVxZ7TRWn+MEvsFp5ViVM0vCORxEqulipCOg24CG J9MThVBm972KcUtwXHOxYHE4R3FD6fSQneQWby70qr0EU2JqwpLin6FJzDaVFlXi0UmH 4vmMy+PCnGsm/pJi9ZHp1DXkuRidYVgo6tU8qlX8ZM9qSpG+BOzCOZD0Eb1HBYWbV++j qJo+eFR1ZicPbBJ6eWyQBnMeGv86LNBVrOfZ0mL3014HKFRVLHxzHMUJvaiOVV9IaUtv twAw== 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=IQawZvBLYF5JFZI+rFb8AokumLl5RtI5O3pDK2MGN+c=; b=Rak8PtN+cdF30ZgqBr0iuZTiM/Am7aYaOVGZL08quAkkfQx9q3udUlwTBIbd/ZE8oo 3ym9H3CCHlCIQWgbX7X3GFfj1gPFy0eELfTv/b89xeWWKZIbtE07K9to6j4tRYAko7F7 EJ8E//Wci75JgS5rsxGvTw6JgHSW4YnS15IOqoig95tOC9N4XFAV60HLt8dKTv3jLnWz hHYxnUrY032YzRLm/o70pfHIOTuk/9zh5XWn+VExNxZh6y8HePO3P/AIp+7iHb7Kl2W0 oZF35spILvAZ/VsPL9eIahTDvS4e/aeJjTMn3D25vBSO9qGiD7UIv6TTi/u87dbM5N+W vrsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWBRvQvSJK2Kxf/B0TTxRB5T73KXFTUplQTCpFtJPV4DM0EC6pMouoW6FSxdmAnDOJwgqdX0TfDrizxHgj6j0i+PoV+Gg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ju1-20020a170903428100b001d9871e4da8si1515816plb.33.2024.02.06.03.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54802-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-54802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54802-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 E8C26B239E8 for ; Tue, 6 Feb 2024 11:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95EDF1386C2; Tue, 6 Feb 2024 11:33:38 +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 A2E69134759; 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=DvTdwPh6wkEOjVT3j5LoRf7IQG1sDPZJP5NCg2prG6Q9Aybjwt2+V7aR4pFPWQirMftTTFaK33kkqiXVUFaLEvOLPrWC3AHuEwiZSdPrzz++ec1GkdQD9Btb29mHOYTHVKL+lNUTkP1U5xDqvoGaRyuYaQlX69fmLHmd/bN9J98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=QRzNsPzlJd46xARPV8LoVgr8hMSulcnSOm9LygT2RX0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OUjuScDnonfNQvBUhWKjsf755H0P4o5VQRAoBmlfJYOsThlIwgOc53RvhKdLN5LXfrASCWgYVlWXXnp4cNafaJpPpOKvS8jkRBotji1Ln93GKZL4Rgi41xR6q9JY7aZvove39Zj/fNu+FsMS+I9609f8Foy3Jmd6oZjRAUCL8kA= 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 5BF7DC433C7; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aNp-2mUJ; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.525587454@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:13 -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 15/23] tracefs: Avoid using the ei->dentry pointer unnecessarily 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: 1790150315383295399 X-GMAIL-MSGID: 1790150315383295399 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; }