From nobody Thu Mar 19 03:45:11 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0D2130EF67 for ; Mon, 16 Feb 2026 13:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771249394; cv=none; b=SVdtedl0TJchZfgzccCx8wBM77gf+JfZBIZ2Ob53CQiBPJPgFLLaxnl8Lds89Uu2qOfGUtQ/mklFrLemFUL4kwGw6EJBZ4MtEepHEo3FRYvCVZhhQZcFFDRY7CoUYoOnSpm8pomxoYwh8N7NrZwFrSg+AL5mW38Tcx3YizL1k6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771249394; c=relaxed/simple; bh=33NvmzifiaBRigoFifMef35hi/yQkfKUWjLhPBQHZC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ajxsP19euzxwmojjubg8vH2HaMtlJ3N5hdJuSBvA8y8OjhoGROgGkAdW8fe7fR+pcEmTFJmkD4a4gJlIseQRQMs2hmwSWKwqzRAx+jXjUxruN34jqJgey7p8mr24in4YZ5OLlyWbDZSMLqlj+OEtfgLU2VIa5eAvBf7HctsbGsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RKWcAa77; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RKWcAa77" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-435a11957f6so2730231f8f.0 for ; Mon, 16 Feb 2026 05:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1771249391; x=1771854191; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BHlgJV/WzhgeNXBdeNtIIZu+ZwNnn+yQBr5wKMb7lyM=; b=RKWcAa77lpb10O5MnDtr5VaK7M6v25kfM9ifJhCHx/7fBjPQO87Qc6xrXFuxjSO3f+ wsCWew92zoMGSxMlvjxps5ZbkHswZneiITzk0N8grriSOf6L3okS3Qd72aDW6vXpOtUo iWJXi+QfuyFoZM1G7i375PNfZElfGmDHJJqbeZIojB1xaVhry7vRJijG8c81UINhTkLE nDRvarjv6a56Rrv4ol1UZ9s+mPdTjJC1mCoI+3kTbu3cyk72Cjm1DQ5jkAfhM6iu1YNC aE4riU+Lsv3rPDvX4eIAL3mdnINALPasf5oNO6uxYiCMGIcBilCsd3xzSsZeqMC0SXLd sqcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771249391; x=1771854191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BHlgJV/WzhgeNXBdeNtIIZu+ZwNnn+yQBr5wKMb7lyM=; b=JT0z7HqUeCs+p7HLhujg3Dz03mudn6Dj43i3TWQzoxtZRi7D63EZKxo8aoWaz1rYk4 VQik2jtQoX0qu/HGi1N9Dmq8tfa7wcE52PM2ayvwp3NH0ysJu9gKnt7agPZeg0JLMgbM TiVn1W6tjM9k1mlCzJ589mkmunb4bwzv0ePmGaSdfHdLvSftXD0JPBI/TlFogPwalcfU msmTl8xxfRYe3LVd/2bP7WCAWmq9qcY8Oqgg1u+YkPIUa+hWAY+4hhGPKxAbkr2k/kJt VOtz8uL3xZpyrZreSLA4U1FkDH8ZnHSHDVopMeqpdE4ZqqrtiRn7TZe9viOa8EzQk6EK ExSg== X-Forwarded-Encrypted: i=1; AJvYcCVH4UN0bG/OVHsSPTKJ4dD1+C8fBpjL3FjXnyooUBEN0VQ0VMD5jaGp7XY4GGJDkjVGVyz/7obsY8gbuFQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3gsadJRTjaoypeXIXaDZ7jBspCDYhcKH+f7MBJHt9T+eUlc8x C7bR/uGn9ROVzT2j0cl8njrL6oJUTIoCtHsw2Z7Gz6p56wMIdtfGD/ve6SJ+b2KSE4o= X-Gm-Gg: AZuq6aJ90AWrxCbURQKZ05FE6G8nocJ7jzurl6/kfJvXKICVGIZLbYWNcZ7PVhGGe/g XWRZdx6NF8LeZLE7Wk5O7OGHLaY5SPujx9skOlseOEK0+v2jC27zCQMahw1jF1xmOgp0KYq4vrs Z14tcwvEWCS1luT6E26oUS5LXxeS3F1ZzYirJ4A0T19ng7nB7bcOFUxPXCs2fhMdKKwbowrR6pU RwFTs45T3u5HlFLP+wXasJt65Utotv4Ck20Sfq1S89pZZEis7soQNDeER+XDL2GCk8aGX290YPI 28m/RZLAPUpRz0zHpfXIkWSO3Gf6oawulhZ9cIFv5pZHaeYg7gfYN/GcnMXXt7IeDuKtXdbeBXN 4VcZ6wOuLTjJ+jByAw37AVUlKaArZLPYvyHudcU1chtUobRke68iIkedWgdYAjUvZlZL+TFSyJ1 uwWXx9MJaJCZG6ZTdoR6Z9nzI2yZupAGt5hxpWZH+bTR2dSDatDPM= X-Received: by 2002:a05:6000:2481:b0:436:8058:45a with SMTP id ffacd0b85a97d-43797913eaamr17300323f8f.39.1771249391215; Mon, 16 Feb 2026 05:43:11 -0800 (PST) Received: from zovi.suse.cz (nat2.prg.suse.com. [195.250.132.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43796a6ba57sm22103738f8f.15.2026.02.16.05.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 05:43:10 -0800 (PST) From: Petr Pavlu To: Steven Rostedt , Masami Hiramatsu Cc: Mathieu Desnoyers , Tom Zanussi , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Petr Pavlu Subject: [PATCH v2 3/4] tracing: Clean up access to trace_event_file from a file pointer Date: Mon, 16 Feb 2026 14:41:59 +0100 Message-ID: <20260216134247.1311631-4-petr.pavlu@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260216134247.1311631-1-petr.pavlu@suse.com> References: <20260216134247.1311631-1-petr.pavlu@suse.com> 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" 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. Signed-off-by: Petr Pavlu --- 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 8428c437cb9d..27fb3fe6a7e0 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1739,11 +1739,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 @@ -1764,12 +1759,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 2ca76b048638..d23e7a9d07e6 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2090,12 +2090,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.52.0