Message ID | 20240206120953.708915826@rostedt.homelinux.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501200dyb; Tue, 6 Feb 2024 04:27:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPqfwEEfkwFwIb2jq+rgMzOARjqEMxw6E3bsz3v/RcJNi5XVeqvigJMQVTX+82UvM6MSKF X-Received: by 2002:ac8:5b8f:0:b0:42a:7782:c287 with SMTP id a15-20020ac85b8f000000b0042a7782c287mr4978378qta.24.1707222426602; Tue, 06 Feb 2024 04:27:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222426; cv=pass; d=google.com; s=arc-20160816; b=c7r0F7vbyr4q+JZbaNkuJV8zMC+y3u34wLwxB3bQBjbsuaRGnB9lWcWDj2maqBgSe/ Mv+MqOuSuc84kWJznNMusG4mqmg/3uwt0p0szrhZSzqxpeW37K0Gl4oc1AH2F592wHKN yrc7Ol3w74QCWpvOI1jVHjobdT+LSMurap/G6jNhYBvXEdzjlqT1XsHR12eI+5pKJCJi MfXeIhX7fvj2/gW+wzSyvg0ij0t+er/nUk7y24wc3oYXS6Iq0D4Cvntdik/pvMwYLNMr t9gUWPw/vzABojt95k2+WHsaP9+QwSdXAS61sKVfzM2aJgleRBDqmH5di8wBQC1N02ud oG0Q== 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=3RN4NWB+356xYpNgRECCmh0ARfrJ2zZfC34yg1jzV3w=; fh=9U4wSBvu9K2ATSvmhvzvvpNcbABYkqab2PqnKqSSGRg=; b=alLnqWWSGahl1C7t9VAIugYQrEQFml+FZgB2mW7YYUXtNcMrTbh4MoG9+wzp+N1ND2 ymJFCwd79dy3Yiumjufig30pHFGuwHhnpmYCZ2ZturHWegrTml7jQPhaaddY3RPN49cu nqJHKELvOx4mgdaqX2wMJzN1DPpgBk8kvQoZcoYvwlsAsnWva041TN/lTPCMZoJteHbF wOLDhHLfDCopyGTnRSI60Xm4wkbJQ/m2Nqt8D5oHUoCiadJx92K8sJaf5c1zl+db83Bt 2UHT8P01OXEWydV1nRQoLJVcPPM5KWlnoqaxM44sBc/u3l5qE/8/kpoSry6Q4jIVJ1O1 NdLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXt/nVBqgceFIOGsEjtt8+bsR3ovUhugpoF6Z5U8bL3L42EDzPLLCjIrT6knjhU8DWdtm126hLsovhwUvCcOWExArJ1Eg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p12-20020a05622a00cc00b0042bf838e0dbsi2113088qtw.416.2024.02.06.04.27.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:27:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54920-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 662801C24382 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 12:27:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D0121509A2; Tue, 6 Feb 2024 12:09:40 +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 6CCCF1386A1; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=kMZ6Ip4nHYiFKXXWtIBdiTPF24x01KXQ1x/Vwcl5H3juMw0Fs4BfDn8MIIgJN0iWXjbWTuz9G5xnUTNvQjq8ye8sz7L8Rttm2jNHpexE0s88rX0ut6qVhlMj532hqNB278ncmwM3/tP7+H0DNcw97WYxyV6DfH0wX7yqXl52kZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=gW8Qs5dhqv8o0qe0O7sTx8CGnoF40JWC8ay85t0nh1E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=F9i5b5HJe19U/8oYhMQXXPkXw55ZbnWV1/0yVJvE7/MBQkAQqvCN5dgwEKsNfPSRB7t6mIq0Bt2BfhQB40Phlo4K8UZi6PdVsxPd2ET75aDiNev3O/ZHUCnCIPSbTZA9p4dy8gFcUEdr1D8XbLQh3Unbp8Ptc15x3lQEG/jSsoI= 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 5AE18C43399; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from <rostedt@rostedt.homelinux.com>) id 1rXKGv-00000006bNq-3Z0N; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.708915826@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:50 -0500 From: Steven Rostedt <rostedt@goodmis.org> To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds <torvalds@linux-foundation.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sasha Levin <sashal@kernel.org>, Masami Hiramatsu <mhiramat@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Geert Uytterhoeven <geert@linux-m68k.org>, Geert Uytterhoeven <geert+renesas@glider.be>, Kees Cook <keescook@chromium.org> Subject: [v6.6][PATCH 45/57] eventfs: Save directory inodes in the eventfs_inode structure References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152462769177085 X-GMAIL-MSGID: 1790152462769177085 |
Series |
eventfs: Linus's updates for 6.6
|
|
Commit Message
Steven Rostedt
Feb. 6, 2024, 12:09 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org> 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 <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Fixes: 53c41052ba31 ("eventfs: Have the inodes all for files and directories all be the same") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Reviewed-by: Kees Cook <keescook@chromium.org> (cherry picked from commit 834bf76add3e6168038150f162cbccf1fd492a67) --- 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)