Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp233607rdb; Mon, 22 Jan 2024 19:13:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2cLTJj/PzIQKkQG91hg5AMyvKGDKgnzJqSZxWZc3lZ9Oy3veGvPINGqoQruwd6BZakd43 X-Received: by 2002:a05:620a:1006:b0:783:9279:817b with SMTP id z6-20020a05620a100600b007839279817bmr5880085qkj.82.1705979626508; Mon, 22 Jan 2024 19:13:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705979626; cv=pass; d=google.com; s=arc-20160816; b=JDU/X2QyjRM63Ork5hDWA/HpqcwkevQ2SLyiAS6h5I6MW4x5w3qZNV9aeS9LNtO+99 4hGQm0bnxTVyEx9HX4t4vxWBec55OMWLY58nM2422jd7087g0ChA29gFOe7a243IbL72 HKVTDqjLHlBJB5Nya//omOY5/eMtLInXhYmM/oWYP2prBPP/tSeqJLe7jkfIImRoWj3/ bByXs3j6i+Ycj02uVJcS4tHdvdjkDeTE+uaTenhBOYpErK1YVZWE/pwNe5JK0hIyfSi3 My6roOGvw1Vz+wtjizMhXP4PwiIJvceOFTu3d3i1h33JkrEPODSVcFDUnLJXdQHRIATB H30g== 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=Umdkro5x5kuRTrwSRoNTZIjStDCr9LRVL99QFK3uAYE=; fh=3ExuGtZUYaqUYQ6NOg7W3CZ6fshj5PAp4L7OK0kjqpg=; b=HojMbYzMd8i1cSGNu19tAIPeR8UHgdtvVVQ/hOUXcoD82qT0tTmcfkUuHBSSrrgQHj ikyEGNX6yRo8giFT+qaUO+UByIhLuPewgKhYFmY2U93NssSfRCWMzfz0DTTxChgKJVE2 m+xD3WK2gyLgEj9cJdDZEks+XLZQa6udaParolEkyjFEXMj12W+lvXm0+mrfSyAtWTW2 581ekdlgNtcNmgJM8c4wnMxrAAPJwN0ITC8KenQmGKtpVJ2UnXGHqvXVK2sc9bN4Yxgy kTx1dZnsUxoz5pzCmYfZCj3OGQr7bFc/bExznqjhmvEfqeVMAX+m/OBXHTgOcVrME9Is jwiQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-34672-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34672-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s12-20020a05622a178c00b0042578643aacsi6838469qtk.577.2024.01.22.19.13.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:13:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34672-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-34672-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34672-linux.lists.archive=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 455441C282A3 for ; Tue, 23 Jan 2024 03:13:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E04631C02; Tue, 23 Jan 2024 03:13:23 +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 60DC11102 for ; Tue, 23 Jan 2024 03:13:23 +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=1705979603; cv=none; b=E55Vk+c63bvc4NS3qODQiyiARbfOrhRUmMa0jt0NpsJ+NR44sx0oonxcE4rtnY0t12Y7x57KK3x5bv3Wh33IpUH3u8uOZ+5DECYmKZXEN1c0+YhjGM/jh2wmXWRwWz8bEiOlwA6otsngegYo564Wq3v2SgbDQC4VGLjcTRHBFug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705979603; c=relaxed/simple; bh=g1vOPJnY9t3y2bVhIPnU2h6iLtYDdE5uoCvaW6dG+O4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=lvsVILXeXkQR7AKknv6/VcPlG/eYSrFWTU5WLfbA1IR9G2dt4w2YbayW5R9g3N0d3PICil5T6bZWFWrLyDMwHVDDRwVxHt4RYCbj+ML1B8D+ESi7Tw7cqQaC6qOQZEHBBiNZjQ/nNivqd0I8BunsvKSBvOW+J5vF2dmZx/r4Ijw= 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 E0CF5C43394; Tue, 23 Jan 2024 03:13:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rS7FU-00000002i9Q-45QQ; Mon, 22 Jan 2024 22:14:52 -0500 Message-ID: <20240123031452.830697973@goodmis.org> User-Agent: quilt/0.67 Date: Mon, 22 Jan 2024 22:08:28 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Geert Uytterhoeven , Kees Cook Subject: [for-linus][PATCH 2/2] eventfs: Save directory inodes in the eventfs_inode structure References: <20240123030826.619242906@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: "Steven Rostedt (Google)" The eventfs inodes and directories are allocated when referenced. But this leaves the issue of keeping consistent inode numbers and the number is only saved in the inode structure itself. When the inode is no longer referenced, it can be freed. When the file that the inode was representing is referenced again, the inode is once again created, but the inode number needs to be the same as it was before. Just making the inode numbers the same for all files is fine, but that does not work with directories. The find command will check for loops via the inode number and having the same inode number for directories triggers: # find /sys/kernel/tracing find: File system loop detected; '/sys/kernel/debug/tracing/events/initcall/initcall_finish' is part of the same file system loop as '/sys/kernel/debug/tracing/events/initcall'. [..] Linus pointed out that the eventfs_inode structure ends with a single 32bit int, and on 64 bit machines, there's likely a 4 byte hole due to alignment. We can use this hole to store the inode number for the eventfs_inode. All directories in eventfs are represented by an eventfs_inode and that data structure can hold its inode number. That last int was also purposely placed at the end of the structure to prevent holes from within. Now that there's a 4 byte number to hold the inode, both the inode number and the last integer can be moved up in the structure for better cache locality, where the llist and rcu fields can be moved to the end as they are only used when the eventfs_inode is being deleted. Link: https://lore.kernel.org/all/CAMuHMdXKiorg-jiuKoZpfZyDJ3Ynrfb8=X+c7x0Eewxn-YRdCA@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240122152748.46897388@gandalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Reported-by: Geert Uytterhoeven Fixes: 53c41052ba31 ("eventfs: Have the inodes all for files and directories all be the same") Signed-off-by: Steven Rostedt (Google) Reviewed-by: Kees Cook --- fs/tracefs/event_inode.c | 14 +++++++++++--- fs/tracefs/internal.h | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6795fda2af19..6b211522a13e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -34,7 +34,15 @@ static DEFINE_MUTEX(eventfs_mutex); /* Choose something "unique" ;-) */ #define EVENTFS_FILE_INODE_INO 0x12c4e37 -#define EVENTFS_DIR_INODE_INO 0x134b2f5 + +/* Just try to make something consistent and unique */ +static int eventfs_dir_ino(struct eventfs_inode *ei) +{ + if (!ei->ino) + ei->ino = get_next_ino(); + + return ei->ino; +} /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from @@ -396,7 +404,7 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_fop = &eventfs_file_operations; /* All directories will have the same inode number */ - inode->i_ino = EVENTFS_DIR_INODE_INO; + inode->i_ino = eventfs_dir_ino(ei); ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; @@ -802,7 +810,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = ei_child->name; - ino = EVENTFS_DIR_INODE_INO; + ino = eventfs_dir_ino(ei_child); if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 12b7d0150ae9..45397df9bb65 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -55,6 +55,10 @@ struct eventfs_inode { struct eventfs_attr *entry_attrs; struct eventfs_attr attr; void *data; + unsigned int is_freed:1; + unsigned int is_events:1; + unsigned int nr_entries:30; + unsigned int ino; /* * Union - used for deletion * @llist: for calling dput() if needed after RCU @@ -64,9 +68,6 @@ struct eventfs_inode { struct llist_node llist; struct rcu_head rcu; }; - unsigned int is_freed:1; - unsigned int is_events:1; - unsigned int nr_entries:30; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) -- 2.43.0