[PATCH 0/2] drm/imagination: fix teardown use-after-free after removal

From: Lewis Lakerink

Date: Wed Nov 25 2026 - 03:26:50 EST


Hi all,

These two patches fix use-after-free crashes when DRM files, syncobj
fences, or in-flight jobs outlive the PowerVR platform device:

1. drm/imagination: guard fence release against device removal (13+/1-)
2. drm/imagination: quiesce queues before device teardown (135+/6-)

pvr_remove() currently calls pvr_device_fini() and
pvr_queue_device_fini() before drm_dev_unplug(), and leaves scheduler
workers and timers running. Unbinding the device while a client holds
an open DRM file or syncobj crashes on fd close in __queue_work() on
the destroyed sched_wq (from both drm_syncobj_release() and
pvr_queue_kill()) and in pvr_meta_vm_unmap() on the freed
kernel_vm_ctx.

Patch 1 guards pvr_queue_fence_release() with drm_dev_enter(). Patch 2
depends on patch 1 for <drm/drm_drv.h> in pvr_queue.c (the series
applies cleanly with plain git am), stops the watchdog and calls
drm_dev_unplug() first when !READ_ONCE(pvr_dev->lost), quiesces active
and idle queues via drm_sched_entity_fini() + drm_sched_fini(), guards
postclose/destroy_context/timedout_job, and flushes sched_wq before
device teardown. Device objects on files or fences that outlive
removal are deliberately leaked (reported by the existing WARN_ON()
checks) rather than reworked around drmm_/refcounted device lifetime
here so the fixes remain backportable.

Overlap with pending work:
Ryan Brue's unmerged system-suspend series ("[PATCH v3 0/4]
drm/imagination: fix system suspend, and the callback design underneath
it") also moves pvr_watchdog_fini() and drm_dev_unplug() (guarded by
!pvr_dev->lost) earlier in pvr_remove() (patches 2/4 and 3/4). This
series leaves pvr_power.c untouched so it applies cleanly on
drm-misc-next independently of the system-sleep rework; happy to rebase
onto v4 of that series if maintainers prefer to land it first.

Tested on MediaTek MT8173 (PowerVR Rogue GX6250, arm64) on v7.3.6 with
a Vulkan client and sysfs unbind across close-only, idle unbind, 6
in-flight unbind/rebind cycles (3 runs across explicit close and
SIGKILL), and module unload (rmmod): 0 oopses/faults, with the expected
leaked-object WARN_ONs. (An earlier revision without the !lost guard
also passed a 75 s post-unbind hold past SCHED_TIMEOUT_PERIOD.)

Known limits:
- Compiled (arm64 defconfig, powervr.ko) on drm-misc-next (a2853fd);
runtime-tested on v7.3.6 (arm64, MT8173) only.
- Runtime PM on remove is left untouched (see patch 2): a
runtime-active GPU remains powered after removal.
- Foreign fences outliving both removal and the last drm_file close, and
unpopped entity jobs blocked on external fences (deferred to system_wq
by drm_sched_entity_kill()), still require a full device-lifetime
rework.

Stable notes:
- Patch 1 (Cc: stable # 6.14+) also affects 6.12.y, which carries
df1a1ed5e1bd by backport.
- Patch 2 (Cc: stable # 6.8+) tracks bug provenance; pre-7.x branches
need backport adjustments in pvr_queue_timedout_job() and pre-6.12
postclose.

Disclosure: analysis and patches were drafted with an LLM coding
assistant (Assisted-by: LLM on both patches; no sparse, smatch, or
coccinelle pass was run). I reviewed the changes and ran the hardware
builds and tests.

Signed-off-by: Lewis Lakerink <lewis@xxxxxxxxxx>

Lewis Lakerink (2):
drm/imagination: guard fence release against device removal
drm/imagination: quiesce queues before device teardown

drivers/gpu/drm/imagination/pvr_drv.c | 73 ++++++++++++++++++++--
drivers/gpu/drm/imagination/pvr_queue.c | 80 ++++++++++++++++++++++++-
drivers/gpu/drm/imagination/pvr_queue.h | 2 +
3 files changed, 148 insertions(+), 7 deletions(-)

--
2.43.0