From nobody Thu Apr 2 22:05:13 2026 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 E6AFF3FB04F for ; Thu, 26 Mar 2026 14:26:29 +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=1774535190; cv=none; b=OPB1zo3luzzQuwBZUsiEhm7uUVhsNF6TH/mcffV6t1THhl22XEOHysYVErvef5iTgtuI7Zt7YZ6WvmcaR0YHKjnk3k6EVpxFwkjuKy8VnfYp8jZNKhJtihJVuSm5vtMS712/3dSDbJxUT63V00XD9dFbOOMr+6u8SGHSQYFNNss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774535190; c=relaxed/simple; bh=zcAw5f43I5Vmc+VHblcCKwXlEacEGDMa1mFfbQf9cpk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VdBk/Q0Uq3SLW5qbBEiAm4aD1yemb/Asi7EkKqjmN0fIa1owhxqMmHpgCpVKABMqfUFoOfR90L59odk1neKUrmYmFFJNpDA/En8fxuLiMBek0hIHeEsHWJmh1uWLL/rSl404BqIQipnSknt9zYfzQgKuW+zmp5+Rj7gtosQ8fCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FffrcZPd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FffrcZPd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5832C2BCB5; Thu, 26 Mar 2026 14:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774535189; bh=zcAw5f43I5Vmc+VHblcCKwXlEacEGDMa1mFfbQf9cpk=; h=Date:From:To:Cc:Subject:References:From; b=FffrcZPdK2jcl6+B1jL6Hv1kAiTlBpl3QvsaRRRqsrHSg3orPyyjPnb/oeinEh4Ye xBd62IryazFBOv24qiDdTtq4P5VYpTHiAXiDWCqEc/kfZT9IjyCRrwXU9nXF6XqC69 FL7MwjzurPRiEdTYoUWttsBZHMhnAs/txmqXZvDZh77adqzYvV/71F7MPjKowX4Nx6 KRiYV9NwJ5a7R5I4j0bo5/Bwz1Ikh3LPb8GxgLA7i0brqVHOHDfXGf2Wi+arL6IH9W oiaRxva0clknaa+saGN8cRIEdj1EvNQoVVml3wYtmfUfUrM4ODRiEqXPNog4i6ydNs YPZbBCDDI+Nqg== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1w5lg4-0000000DuAy-2d9O; Thu, 26 Mar 2026 10:27:16 -0400 Message-ID: <20260326142716.479635119@kernel.org> User-Agent: quilt/0.69 Date: Thu, 26 Mar 2026 10:26:59 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi , Petr Pavlu Subject: [for-next][PATCH 03/13] tracing: Clean up access to trace_event_file from a file pointer References: <20260326142656.794462952@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Petr Pavlu The tracing code provides two functions event_file_file() and event_file_data() to obtain a trace_event_file pointer from a file struct. The primary method to use is event_file_file(), as it checks for the EVENT_FILE_FL_FREED flag to determine whether the event is being removed. The second function event_file_data() is an optimization for retrieving the same data when the event_mutex is still held. In the past, when removing an event directory in remove_event_file_dir(), the code set i_private to NULL for all event files and readers were expected to check for this state to recognize that the event is being removed. In the case of event_id_read(), the value was read using event_file_data() without acquiring the event_mutex. This required event_file_data() to use READ_ONCE() when retrieving the i_private data. With the introduction of eventfs, i_private is assigned when an eventfs inode is allocated and remains set throughout its lifetime. Remove the now unnecessary READ_ONCE() access to i_private in both event_file_file() and event_file_data(). Inline the access to i_private in remove_event_file_dir(), which allows event_file_data() to handle i_private solely as a trace_event_file pointer. Add a check in event_file_data() to ensure that the event_mutex is held and that file->flags doesn't have the EVENT_FILE_FL_FREED flag set. Finally, move event_file_data() immediately after event_file_code() since the latter provides a comment explaining how both functions should be used together. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Tom Zanussi Link: https://patch.msgid.link/20260219162737.314231-5-petr.pavlu@suse.com Signed-off-by: Petr Pavlu Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 17 +++++++++++------ kernel/trace/trace_events.c | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index b8f3804586a0..7db78a62f786 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1802,11 +1802,6 @@ extern struct trace_event_file *find_event_file(stru= ct trace_array *tr, const char *system, const char *event); =20 -static inline void *event_file_data(struct file *filp) -{ - return READ_ONCE(file_inode(filp)->i_private); -} - extern struct mutex event_mutex; extern struct list_head ftrace_events; =20 @@ -1827,12 +1822,22 @@ static inline struct trace_event_file *event_file_f= ile(struct file *filp) struct trace_event_file *file; =20 lockdep_assert_held(&event_mutex); - file =3D READ_ONCE(file_inode(filp)->i_private); + file =3D file_inode(filp)->i_private; if (!file || file->flags & EVENT_FILE_FL_FREED) return NULL; return file; } =20 +static inline void *event_file_data(struct file *filp) +{ + struct trace_event_file *file; + + lockdep_assert_held(&event_mutex); + file =3D file_inode(filp)->i_private; + WARN_ON(!file || file->flags & EVENT_FILE_FL_FREED); + return file; +} + extern const struct file_operations event_trigger_fops; extern const struct file_operations event_hist_fops; extern const struct file_operations event_hist_debug_fops; diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 26d1e95a55d1..6523c873689a 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2184,12 +2184,12 @@ static int trace_format_open(struct inode *inode, s= truct file *file) static ssize_t event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *pp= os) { - int id =3D (long)event_file_data(filp); + /* id is directly in i_private and available for inode's lifetime. */ + int id =3D (long)file_inode(filp)->i_private; char buf[32]; int len; =20 - if (unlikely(!id)) - return -ENODEV; + WARN_ON(!id); =20 len =3D sprintf(buf, "%d\n", id); =20 --=20 2.51.0