From patchwork Wed Jan 31 18:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 194912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2107436dyb; Wed, 31 Jan 2024 11:16:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiprRu3J0wSFN8UOpssSQe+4ryDQl4cP+H0uv127eNx43UvMy6MNfziPJADVFzAiVYoQDg X-Received: by 2002:a05:6870:5309:b0:214:2dd0:6c78 with SMTP id j9-20020a056870530900b002142dd06c78mr3065349oan.25.1706728566953; Wed, 31 Jan 2024 11:16:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706728566; cv=pass; d=google.com; s=arc-20160816; b=u3ipBGyDYuZRYdwRa/L/UK2hUlrXTgYSQbY5OJmGOfhdcj6W+92+WdMLNqRACd3pCN 4IY5iwyACOc2ifiXyr72zZplesFtI72FYm1GsKTb/sW/psJR/BryO2dUdRmhKRGWNVog 4hMspDjFS3yf3XLxqANCd3nQiDMsDo8og7CmNGmETokryFOWF0R21i3NE4cBHTPim/p2 hA0yFV5yqy12/PL8h50JSSWbLpQg7arbWGy5vXAWzHVIRmFhvpKeI3TVf/n+wOXndeFx sMhWalcOdiC+SVQD2LyR8UwrDVEZkKZitxDtb+/zobe3S0ZBN6Gc+2vf23YPFkVoS7D6 bFNQ== 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=lQxtUAB98YvH689MmRbXqsDi5zOdnFTKnh+wJRPHUk8=; fh=5x+SgJ1py+lN3ONkpLcGOZCqg3EhQuvgDRP1YwNBNT8=; b=GFwB76u0R2Ebg+PM2quGrdtnTz+RYkBghcoy9IUhA4CZLODBD9rAd4Agx2bKHv0Ajd o2eYCqSz+Zu5hmkpN1/CUn5w3lizPsXxUy3ATrmzi5OuMUPTvGi6HWEIybQx58JSFjbF a3b2AG4riUTNG7e1AbtcbGvt9th0NTmEYYCj2eWrGTlnpneT/XdI10JcyyfET7LrdGg3 huuNsuGVOlkC/mZEYoJKfG010Elo62lgLN/p98o64ZMPYBryl9X7sfwxRyLXoecoJV29 fj1zvYLncCgBKahygR6Z3wrOQtL36SLW+JwGli65wVJ6dy1pkC/oIkQT4ry1PlbrI/JK xFvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-46989-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46989-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUmM3PRCpsnkQv26kq80z0tUc2Z9ZwSZ+qRmCV8xI8jfvbRgBPb+2dbz6mF8D7PRyOBBW66+yM0PWPPJqMnwQAQCSmwFA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s67-20020a635e46000000b005b942de1e92si10008398pgb.443.2024.01.31.11.16.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:16:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46989-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-46989-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46989-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 40DADB28145 for ; Wed, 31 Jan 2024 18:56:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AE49135A5C; Wed, 31 Jan 2024 18:55:00 +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 125DB3A1C8; Wed, 31 Jan 2024 18:54:57 +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=1706727298; cv=none; b=Yn8JZn0Iwabe8Ua9fcT4G+5b163vjldSYfz9J6h7+6l+S97SoTRco+xh0hLR4jmiO7+4SUu9ZvZI/FF+0DBx0eypI/waU6z2l1BApJzCJcAlUSu8jelHj2GJTvOIVdb+SuIl21sdEuxR9TwTncE90ehDUCro8FYMn28hunHd8B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706727298; c=relaxed/simple; bh=GDc+aLW5Fd1txUftp1mWm1xo+fkkQ873V74up1OwR9E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TqUKGMLpJifjlVUUvG6T6Ycl2hxA5mCAb8CTKYgTEKluOaEPpwp8likqt3fCbPQ/ilqjl3FljVBDk5SkOn1+F4QqdefV1n/DlZ9DlxAmRYxdpOtJday0gWbKD6z28xAEmZ7Po3JDkvExewGyMeAiXht3B2YWfJ4hwOqcwoIBTnM= 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 AC093C433B2; Wed, 31 Jan 2024 18:54:57 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVFjs-000000055Qq-3Goq; Wed, 31 Jan 2024 13:55:12 -0500 Message-ID: <20240131185512.638645365@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 31 Jan 2024 13:49:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , stable@vger.kernel.org Subject: [PATCH v2 3/7] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240131184918.945345370@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: 1789634614046123260 X-GMAIL-MSGID: 1789634614046123260 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/ Cc: stable@vger.kernel.org Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) --- Original patch: https://lore.kernel.org/linux-trace-kernel/20240130190355.11486-1-torvalds@linux-foundation.org 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; }