From patchwork Tue Jan 30 19:03:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 194277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1435743dyb; Tue, 30 Jan 2024 11:04:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFI2NGA4cgT/2gpmk66tGC4KSzIyUayKaAcDVJ0isDiAMUQHceVUE3W2m9S/aCLbVpcl3Hk X-Received: by 2002:a17:90a:17a2:b0:28f:f1c0:3d21 with SMTP id q31-20020a17090a17a200b0028ff1c03d21mr5036839pja.41.1706641466724; Tue, 30 Jan 2024 11:04:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706641466; cv=pass; d=google.com; s=arc-20160816; b=sdtoJ9rIXL0pknEociuv+JkwnDwtSQWI+4C8gR4+z4wlAG4l5NPHLCdlB/1xGB/Tyn 0hDcCu3K3tglkA6yTN1CCHmcuaJo9nQyMfSMwxGwZgyRVqvpjeoznOSgIlG4Vx16OgiN oW90P99cL1zNp67VIsst8kLc+i8LdrTY1Uk5odNuY6MQWQ2ywStpw1eysrqsnhLbaQHo Ub/PsvzI3zVVbVXZgfg9Kfgfc8T8CKI591ybnLleEXUTwjuB1qJBBc63AuGv77/yWipR da1ISQuN3lbKbepIe8xYffburH2Dv5TRDKN+P/2KalAgnZ4BED4eobTta4ANzAQW3ENw D+uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=/5/Xj2Srlhp4uYDTTMzT4Qjup+7kuic8fjKtxQpR9Lk=; fh=aD/wDFT3pdBCiZXVST/riRN8xCPBouJr3XfOtoKVvRw=; b=aTaBMl4+xli1PpesyRMePtzB8Hwk68lk/EOa6vqTDmaV4caz97pR+yRrpah2fZ+p7O /8l9buD4NYrSE6nUffR38wvLV0iYHjT1ElrG13vCMgPSgjU6dCljZBHULWNN/LfNu7N7 HmiOoxUdZDlxfjLSE+LMRO6eU91lJSZowBD2MmXM56h21GfjJgtd6mKclwUsMa8F0Kjf ypbiDIxr/vAwaFr7/ZAm+E8kdhEEUV9tbv8F9JT1qw9caiBnDR96mL0B8wja72NIZihQ xFlcaDNyUY4yLblHrp/xsdYxdC4hX+jjaQwDsNFUelsSOo0Jb5IXMqKi2TrWU78E7Qul SABA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=sPvFIbvn; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45154-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45154-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v20-20020a17090a899400b00292e3004eb0si8968318pjn.152.2024.01.30.11.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:04:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45154-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; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=sPvFIbvn; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45154-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45154-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 7FC95289C28 for ; Tue, 30 Jan 2024 19:04:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2491E7995F; Tue, 30 Jan 2024 19:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="sPvFIbvn" 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 083FD79948; Tue, 30 Jan 2024 19:04:11 +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=1706641452; cv=none; b=S50TscRi5ny3JoTnv/gnaSB1I33qw2jO28EwMtTb3Dq+Zs3WfdblTMRXyQFNwbY6ZKKFxQPXfGbq2sipuwr3r3tfbkNaUy4Az/UEk+Fe5ZjJkqZ9g+dXjCNMRjAyjF8nBQZA9CqAnog52J10SROr/13L9GT+ikkW155D7lx36K4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641452; c=relaxed/simple; bh=/VhpS5sd/6Wo9lZmVmUCPhzalbMspHdeI+886w/8Nls=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AjnBtPXejlonvizDos76qup11iEzPBy/yXFcmGOO1aLQH8tFS//ZkGmmqbcjS0jcarxZp3LMT0SOwkR7jlbM5RXvMqiUnilJCf5tdJO8OelF1p19JdKGyThD9Mdo7jbvy40B4Sd7UCP/xx2KlUwbt9zlL3WUv6ELa3JGrOyONjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=sPvFIbvn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48FA5C433C7; Tue, 30 Jan 2024 19:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1706641451; bh=/VhpS5sd/6Wo9lZmVmUCPhzalbMspHdeI+886w/8Nls=; h=From:To:Cc:Subject:Date:From; b=sPvFIbvnEnAfVnGnWpE1wIA6AsVzmHu44QSP4mHgzR0gVpraQ6hb0UWMyr45N6ncO /fVUj47CsgFdoUz4mICcPYg7bl3baxe6qDxRRPpihbNyvnDIKLYXMGkumfcjW6TN2z iDwbrd2zJw+5M5jf/ePV/Uv8EaiQdo1lrUABqMrI= From: Linus Torvalds To: Steven Rostedt Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Linus Torvalds Subject: [PATCH 1/6] tracefs: avoid using the ei->dentry pointer unnecessarily Date: Tue, 30 Jan 2024 11:03:50 -0800 Message-ID: <20240130190355.11486-1-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.43.0.5.g38fb137bdb 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: 1789543282332710531 X-GMAIL-MSGID: 1789543282332710531 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. Signed-off-by: Linus Torvalds --- 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 1c3dd0ad4660..2d128bedd654 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; }