From: sashiko-bot@kernel.org
To: "Umesh Nerlige Ramappa" <umesh.nerlige.ramappa@intel.com>,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v6 7/7] drm/xe/oa: Quiesce OA streams on driver unbind and PCI reset
Date: Mon, 16 Nov 2026 23:10:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-217851@kernel.org> (raw)
In-Reply-To: <20261116222752.3677159-16-umesh.nerlige.ramappa@intel.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] drm/xe/oa: xe_oa_ioctl() returns -ECANCELED instead of
-ENODEV on dead stream
- [Medium] drm/xe/oa: race between xe_oa_release() and
xe_bo_pinned_fini() on OA buffer
- [Medium] drm/xe/oa: xe_oa_emit_oa_config() returns 0 on wedged or
unplugged device
- [Low] drm/xe/oa: inaccurate xe_oa_quiesce() comment and commit message
after v5
--
commit a7a247bac1e078594e18d5ec17411108f9fc195e
Author: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
drm/xe/oa: Quiesce OA streams on driver unbind and PCI reset
This commit quiesces active OA streams on driver unbind and PCI reset,
rejecting further operations on dead stream fds and deferring final
stream struct and OA buffer cleanup until the fd is released.
> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index 1a37312de099c..551f5a0631630 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
[ ... ]
> @@ -1134,9 +1155,15 @@ static int xe_oa_emit_oa_config(struct xe_oa_stream *stream, struct xe_oa_config
> if (err == -ENOENT)
> xe_oa_config_cb(fence, &ofence->cb);
>
> - /* If nothing needs to be signaled we wait synchronously */
> + /*
> + * If nothing needs to be signaled we wait synchronously unless the device
> + * is unplugged/wedged.
> + */
> if (!num_signal) {
> - dma_fence_wait(&ofence->base, false);
> + while (!dma_fence_wait_timeout(&ofence->base, false, HZ / 10))
> + if (drm_dev_is_unplugged(>_to_xe(stream->gt)->drm) ||
> + xe_wedged(gt_to_xe(stream->gt)))
> + break;
> dma_fence_put(&ofence->base);
> }
[Severity: Medium]
Should xe_oa_emit_oa_config() return an error when it breaks out of the
wait loop because the device is unplugged or wedged?
Right now it still falls through and returns 0. On the stream open path
(xe_oa_stream_open_ioctl_locked() -> xe_oa_stream_init() ->
xe_oa_enable_metric_set()), a 0 return lets open proceed to enable the OA
hardware, start poll_check_timer and install a live stream fd even though
the config batch never completed and the device is wedged or unplugged.
[ ... ]
> @@ -1710,6 +1737,9 @@ static long xe_oa_ioctl_locked(struct xe_oa_stream *stream,
> unsigned int cmd,
> unsigned long arg)
> {
> + if (stream->dead)
> + return -ENODEV;
> +
> switch (cmd) {
> case DRM_XE_OBSERVATION_IOCTL_ENABLE:
> return xe_oa_enable_locked(stream);
> @@ -1731,17 +1761,34 @@ static long xe_oa_ioctl(struct file *file,
> unsigned long arg)
> {
> struct xe_oa_stream *stream = file->private_data;
> + struct xe_device *xe = gt_to_xe(stream->gt);
> long ret;
> + int idx;
> +
> + if (xe_wedged(xe))
> + return -ECANCELED;
> +
> + if (!drm_dev_enter(&xe->drm, &idx))
> + return -ENODEV;
>
> mutex_lock(&stream->stream_lock);
> ret = xe_oa_ioctl_locked(stream, cmd, arg);
> mutex_unlock(&stream->stream_lock);
>
> + drm_dev_exit(idx);
> +
> return ret;
> }
[Severity: Medium]
Does checking xe_wedged(xe) before drm_dev_enter() and stream->dead cause
xe_oa_ioctl() to return -ECANCELED instead of -ENODEV on a dead stream?
During a PCI slot reset, prepare_device_for_reset() sets xe->wedged.flag
on the old xe_device before slot reset removes and reprobes the device:
drivers/gpu/drm/xe/xe_pci_error.c:prepare_device_for_reset() {
...
if (!atomic_xchg(&xe->wedged.flag, 1))
xe_pm_runtime_get_noresume(xe);
...
}
Because xe_wedged(xe) stays true on the old xe_device (and when unbinding
an already wedged device), xe_oa_ioctl() returns -ECANCELED before
reaching drm_dev_enter() or the stream->dead check in
xe_oa_ioctl_locked().
> static void xe_oa_destroy_locked(struct xe_oa_stream *stream)
> {
> + if (stream->dead) {
> + xe_oa_free_oa_buffer(stream);
> + mutex_destroy(&stream->stream_lock);
> + kfree(stream);
> + return;
> + }
> +
> xe_pm_runtime_get(gt_to_xe(stream->gt));
>
> /* A wedged device may be unresponsive, skip HW access */
> @@ -1758,17 +1805,37 @@ static void xe_oa_destroy_locked(struct xe_oa_stream *stream)
> kfree(stream);
> }
>
> +static void xe_oa_quiesce_oa_unit(struct xe_oa_unit *u, bool hw_accessible);
> +
> static int xe_oa_release(struct inode *inode, struct file *file)
> {
> struct xe_oa_stream *stream = file->private_data;
> struct xe_gt *gt = stream->gt;
> + struct xe_device *xe = gt_to_xe(gt);
> + int idx;
>
> mutex_lock(>->oa.gt_lock);
> - xe_oa_destroy_locked(stream);
> + if (drm_dev_enter(&xe->drm, &idx)) {
> + xe_oa_destroy_locked(stream);
> + drm_dev_exit(idx);
> + } else {
> + if (!stream->dead)
> + xe_oa_quiesce_oa_unit(stream->oa_unit, !xe_wedged(xe));
> +
> + xe_oa_destroy_locked(stream);
> + }
> mutex_unlock(>->oa.gt_lock);
>
> + /*
> + * Freeing the OA buffer may defer the BO destroy to the TTM workqueue. Once the device
> + * is unplugged, this may be the last reference on the drm device, so let the destroy
> + * finish before drm_dev_put() releases the GGTT.
> + */
> + if (drm_dev_is_unplugged(&xe->drm))
> + flush_workqueue(xe->ttm.wq);
> +
> /* Release the reference the OA stream kept on the driver */
> - drm_dev_put(>_to_xe(gt)->drm);
> + drm_dev_put(&xe->drm);
>
> return 0;
> }
[Severity: Medium]
Can xe_oa_release() race with xe_bo_pinned_fini() on stream->oa_buffer.bo
if userspace closes the stream fd during device teardown?
During remove, devres runs xe_oa_fini() -> xe_oa_quiesce() (which leaves
stream->oa_buffer.bo pinned and wakes poll_wq) and then runs
xe_bo_pinned_fini() -> xe_bo_apply_to_pinned() without holding
gt->oa.gt_lock:
CPU0 (devres remove) CPU1 (close fd)
xe_oa_fini()
xe_oa_quiesce()
wake_up_all(&stream->poll_wq)
xe_bo_pinned_fini()
xe_bo_apply_to_pinned()
xe_bo_get(bo)
xe_oa_release()
xe_oa_destroy_locked()
xe_oa_free_oa_buffer()
xe_bo_unpin_map_no_vm(bo)
xe_bo_unpin(bo)
xe_bo_put(bo) (refcnt 2 -> 1)
flush_workqueue(xe->ttm.wq)
drm_dev_put(&xe->drm)
xe_bo_dma_unmap_pinned(bo)
xe_bo_put(bo) (refcnt 1 -> 0)
queue_work(xe->ttm.wq, ...)
...
drm_dev_put() (frees GGTT)
ttm_bo_Delayed_delete()
xe_ggtt_remove_bo() <-- use-after-free
Because CPU0 holds a transient BO reference in xe_bo_apply_to_pinned(),
xe_oa_free_oa_buffer() does not drop the final reference on the BO, so
flush_workqueue(xe->ttm.wq) in xe_oa_release() runs before the BO is
queued for delayed deletion. In addition, xe_bo_unpin(bo) exposes the BO
to the shrinker while xe_bo_dma_unmap_pinned(bo) accesses xe_tt->sg
without holding the BO lock.
[ ... ]
> +/**
> + * xe_oa_quiesce - Disable all active OA streams on driver unbind or PCI slot reset
> + * @xe: @xe_device
> + *
> + * Disables the OA unit and stops the poll timer of every active stream, marks it dead
> + * and releases all device-bound resources (OA buffer, exec queues, configs, references).
> + * Unless the device is wedged, the HW state (whitelist, metric set, forcewake, preemption)
> + * is restored first. Any further read, poll, mmap or ioctl on the stream fd is rejected
> + * (-ENODEV). Only the stream struct stays allocated until userspace closes the fd, at
> + * which point xe_oa_release() just frees it.
> + */
[Severity: Low]
This isn't a bug, but the comment above xe_oa_quiesce() and the commit
message still say that xe_oa_quiesce() releases the OA buffer, restores
preemption and leaves only the stream struct allocated until
xe_oa_release(). In the code, the OA buffer stays pinned and allocated
until xe_oa_destroy_locked() calls xe_oa_free_oa_buffer() on release, and
xe_oa_disable_locked() skips xe_oa_enable_preempt_timeslice() because
stream->dead is set before calling it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116222752.3677159-9-umesh.nerlige.ramappa@intel.com?part=7
next prev parent reply other threads:[~2026-11-16 23:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 22:27 [PATCH v6 0/7] Cleanup OA stream on PCI unbind/remove Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 1/7] drm/xe/oa: Use the drm device address_space for the OA stream fd Umesh Nerlige Ramappa
2026-11-16 22:46 ` sashiko-bot
2026-11-16 22:27 ` [PATCH v6 2/7] drm/xe/oa: Split OA stream destroy into HW teardown and resource release Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 3/7] drm/xe/oa: Take the runtime PM reference in xe_oa_destroy_locked() Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 4/7] drm/xe/oa: Skip OA HW teardown on a wedged device Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 5/7] drm/xe/oa: Wait for in-flight OA batches before stream HW teardown Umesh Nerlige Ramappa
2026-11-16 23:00 ` sashiko-bot
2026-11-16 22:27 ` [PATCH v6 6/7] drm/xe: Reject vm_ops->access on BO mappings of an unplugged device Umesh Nerlige Ramappa
2026-11-16 22:54 ` sashiko-bot
2026-11-16 22:28 ` [PATCH v6 7/7] drm/xe/oa: Quiesce OA streams on driver unbind and PCI reset Umesh Nerlige Ramappa
2026-11-16 23:10 ` sashiko-bot [this message]
2026-11-16 22:39 ` ✓ CI.KUnit: success for Cleanup OA stream on PCI unbind/remove (rev6) Patchwork
2026-11-16 23:11 ` ✓ Xe.CI.BAT: " 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=sashiko-outbox-217851@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=umesh.nerlige.ramappa@intel.com \
/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