Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Subject: [PATCH 1/2] drm/i915/perf: Enable the stream before installing its fd
Date: Tue,  8 Sep 2026 16:15:13 -0700	[thread overview]
Message-ID: <20260908231511.1217426-5-umesh.nerlige.ramappa@intel.com> (raw)
In-Reply-To: <20260908231511.1217426-4-umesh.nerlige.ramappa@intel.com>

Enable the stream before installing the fd. Once the fd is visible
to userspace, file operations can run concurrently with this thread
and they only take stream->lock, which is not held here. In
particular, an I915_PERF_IOCTL_DISABLE racing with the middle of
i915_perf_enable_locked() could clear stream->enabled and cancel a
poll timer that has not been started yet, leaving the stream with
enabled == false and the timer armed. Nothing would then cancel that
timer before the stream is freed on release.

Fixes: 2db609c01495 ("drm/i915/perf: Replace gt->perf.lock with stream->lock for file ops")
Reported-by: Martin Hodo <martin.hodo@intel.com>
Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Assisted-by: Claude:claude-opus-5
---
 drivers/gpu/drm/i915/i915_perf.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 19b82427aa41..96823dcd3fae 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -3900,15 +3900,25 @@ i915_perf_open_ioctl_locked(struct i915_perf *perf,
 	if (param->flags & I915_PERF_FLAG_FD_NONBLOCK)
 		f_flags |= O_NONBLOCK;
 
+	/*
+	 * Enable the stream before installing the fd. Once the fd is visible
+	 * to userspace, file operations can run concurrently with this thread
+	 * and they only take stream->lock, which is not held here. In
+	 * particular, an I915_PERF_IOCTL_DISABLE racing with the middle of
+	 * i915_perf_enable_locked() could clear stream->enabled and cancel a
+	 * poll timer that has not been started yet, leaving the stream with
+	 * enabled == false and the timer armed. Nothing would then cancel that
+	 * timer before the stream is freed on release.
+	 */
+	if (!(param->flags & I915_PERF_FLAG_DISABLED))
+		i915_perf_enable_locked(stream);
+
 	stream_fd = anon_inode_getfd("[i915_perf]", &fops, stream, f_flags);
 	if (stream_fd < 0) {
 		ret = stream_fd;
-		goto err_flags;
+		goto err_enable;
 	}
 
-	if (!(param->flags & I915_PERF_FLAG_DISABLED))
-		i915_perf_enable_locked(stream);
-
 	/* Take a reference on the driver that will be kept with stream_fd
 	 * until its release.
 	 */
@@ -3916,6 +3926,8 @@ i915_perf_open_ioctl_locked(struct i915_perf *perf,
 
 	return stream_fd;
 
+err_enable:
+	i915_perf_disable_locked(stream);
 err_flags:
 	if (stream->ops->destroy)
 		stream->ops->destroy(stream);
-- 
2.53.0


  reply	other threads:[~2026-09-08 23:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 23:15 [PATCH 0/2] Minor fixes to OA in i915 Umesh Nerlige Ramappa
2026-09-08 23:15 ` Umesh Nerlige Ramappa [this message]
2026-09-08 23:29   ` [PATCH 1/2] drm/i915/perf: Enable the stream before installing its fd sashiko-bot
2026-09-08 23:15 ` [PATCH 2/2] drm/i915/perf: Remove sysfs group on OA config idr_alloc() failure Umesh Nerlige Ramappa
2026-09-08 23:26   ` sashiko-bot
2026-09-09  0:19 ` ✓ i915.CI.BAT: success for Minor fixes to OA in i915 Patchwork
2026-09-09 17:10 ` ✓ i915.CI.Full: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260908231511.1217426-5-umesh.nerlige.ramappa@intel.com \
    --to=umesh.nerlige.ramappa@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox