Skip to contentSkip to conversation

drm/amdgpu: guard VCE/UVD sched entity teardown on failed probe

PATCH In review Olivier Kaloudoff 2 participants 3 messages Oct 14 – Oct 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: guard VCE/UVD sched entity teardown on failed probe

Since commit 037b98a2312e ("drm/amdgpu: move UVD and VCE sched entity init after sched init"), drm_sched_entity_init() for the VCE and UVD kernel entities runs in the scheduler-init phase, well after the IP-block sw_init phase has allocated the vcpu_bos.

If probe fails between the two phases, amdgpu_device_fini_sw() still runs the per-IP sw_fini callbacks for blocks that did complete sw_init. Both amdgpu_vce_sw_fini() and amdgpu_uvd_sw_fini() then call drm_sched_entity_destroy() on an entity that was never initialized:
entity->rq is NULL and drm_sched_entity_flush() dereferences it, oopsing in whatever context drove the failed probe.

Observed on real hardware: MI50 (Vega20, VCE 4.0 / UVD 7.2) behind a Thunderbolt link — a pciehp presence/link-change event re-probes the device; when the re-probe fails (-EINVAL here), the cleanup path NULL-derefs inside drm_sched_entity_flush() in the pciehp IRQ thread and takes the whole machine down (panic_on_oops, EFI pstore capture). Reproduced twice on 7.3-rc5, 2026-10-06 and 2026-10-09, identical signature:

  BUG: kernel NULL pointer dereference
  RIP: drm_sched_entity_flush+0x34/0x2d0 [gpu_sched]
  drm_sched_entity_destroy
  amdgpu_vce_sw_fini
  vce_v4_0_sw_fini
  amdgpu_device_fini_sw
  ...
  pciehp_configure_device
  pciehp_handle_presence_or_link_change

Guard the entity teardown on entity->rq, which is set only by drm_sched_entity_init(). amdgpu_ring_fini() already self-guards via the rings[] registration, and the vcpu_bo/firmware cleanup still runs as before.

Fixes 037b98a2312e ("drm/amdgpu: move UVD and VCE sched entity init after sched init")
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +2 -1
index ecd7caa95..cd35ff7ca 100644
@@ -377,7 +377,8 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
 	void *addr = amdgpu_bo_kptr(adev->uvd.ib_bo);
 	int i, j;
 
-	drm_sched_entity_destroy(&adev->uvd.entity);
+	if (adev->uvd.entity.rq)
+		drm_sched_entity_destroy(&adev->uvd.entity);
 
 	for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
 		if (adev->uvd.harvest_config & (1 << j))
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -1
index 1f7a98cdc..3952af9ae 100644
@@ -253,7 +253,8 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)
 	if (adev->vce.vcpu_bo == NULL)
 		return 0;
 
-	drm_sched_entity_destroy(&adev->vce.entity);
+	if (adev->vce.entity.rq)
+		drm_sched_entity_destroy(&adev->vce.entity);
 
 	for (i = 0; i < adev->vce.num_rings; i++)
 		amdgpu_ring_fini(&adev->vce.ring[i]);
Signature · 1 line
2.39.5
#1 lore raw
Quoted 21 lines · Olivier Kaloudoff

Since commit 037b98a2312e ("drm/amdgpu: move UVD and VCE sched entity init after sched init"), drm_sched_entity_init() for the VCE and UVD kernel entities runs in the scheduler-init phase, well after the IP-block sw_init phase has allocated the vcpu_bos.

If probe fails between the two phases, amdgpu_device_fini_sw() still runs the per-IP sw_fini callbacks for blocks that did complete sw_init. Both amdgpu_vce_sw_fini() and amdgpu_uvd_sw_fini() then call drm_sched_entity_destroy() on an entity that was never initialized:
entity->rq is NULL and drm_sched_entity_flush() dereferences it, oopsing in whatever context drove the failed probe.

Observed on real hardware: MI50 (Vega20, VCE 4.0 / UVD 7.2) behind a Thunderbolt link — a pciehp presence/link-change event re-probes the device; when the re-probe fails (-EINVAL here), the cleanup path NULL-derefs inside drm_sched_entity_flush() in the pciehp IRQ thread and takes the whole machine down (panic_on_oops, EFI pstore capture). Reproduced twice on 7.3-rc5, 2026-10-06 and 2026-10-09, identical signature:

Quoted 6 lines
  BUG: kernel NULL pointer dereference
  RIP: drm_sched_entity_flush+0x34/0x2d0 [gpu_sched]
  drm_sched_entity_destroy
  amdgpu_vce_sw_fini
  vce_v4_0_sw_fini
  amdgpu_device_fini_sw

Shouldn't this already be handled by commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.")? That commit adds a entity->rq NULL check in drm_sched_entity_flush() and other places as well.

Alex

Quoted 48 lines

...
pciehp_configure_device
pciehp_handle_presence_or_link_change

Guard the entity teardown on entity->rq, which is set only by drm_sched_entity_init(). amdgpu_ring_fini() already self-guards via the rings[] registration, and the vcpu_bo/firmware cleanup still runs as before.

Fixes 037b98a2312e ("drm/amdgpu: move UVD and VCE sched entity init after sched init")
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +2 -1
index ecd7caa95..cd35ff7ca 100644
@@ -377,7 +377,8 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
        void *addr = amdgpu_bo_kptr(adev->uvd.ib_bo);
        int i, j;
 
-       drm_sched_entity_destroy(&adev->uvd.entity);
+       if (adev->uvd.entity.rq)
+               drm_sched_entity_destroy(&adev->uvd.entity);
 
        for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
                if (adev->uvd.harvest_config & (1 << j))
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -2
index 1f7a98cdc..3952af9ae 100644
@@ -253,7 +253,8 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)
        if (adev->vce.vcpu_bo == NULL)
                return 0;
 
-       drm_sched_entity_destroy(&adev->vce.entity);
+       if (adev->vce.entity.rq)
+               drm_sched_entity_destroy(&adev->vce.entity);
 
        for (i = 0; i < adev->vce.num_rings; i++)
                amdgpu_ring_fini(&adev->vce.ring[i]);
--

2.39.5

#2 lore raw

Hi Alex,

Quoted 3 lines

Shouldn't this already be handled by commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.")? That commit adds a entity->rq NULL check in drm_sched_entity_flush() and other places as well.

It was — until June. Commit 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks") removed exactly that check from drm_sched_entity_flush() (and the matching ones in drm_sched_entity_kill() and drm_sched_job_init()), on the grounds that "entity->rq can now never be NULL". That holds only for entities that completed drm_sched_entity_init() — the failed-probe path here calls drm_sched_entity_destroy() on a never-initialized entity, because amdgpu_device is zeroed and VCE/UVD entity init only runs in the scheduler-init phase, after the sw_init phase that failed.

Verified on the crashing build (7.3.0-rc5, gpu-sched.ko): there is no rq test emitted; flush+0x34 is mov (%rax),%r15 with rax = entity->rq == NULL — the sched = entity->rq->sched deref:

    +0x19:  mov 0x18(%rdi),%rax    ; rax = entity->rq
    +0x34:  mov (%rax),%r15        ; fault: *rq

So this is a regression introduced by 2df5efb45425 in the 7.3 window — the same failed-probe teardown was silently safe before it. v2 of the patch retargets Fixes: accordingly and Cc's Tvrtko and Philipp.

Regards,
Olivier