Skip to contentSkip to conversation

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

PATCH Applied Olivier Kaloudoff 5 participants 7 messages Oct 15 – Oct 20

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

PATCH v2 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.

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

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; the faulting instruction is mov (%rax),%r15 on rax = entity->rq == NULL, i.e. sched = entity->rq->sched:

  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.

v2: retarget Fixes: at commit 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks") — the !entity->rq check from commit 1decbf6bb0b4 ("drm/sched: Fix entities with 0 rqs.") that Alex pointed to was removed by it in the 7.3 window, so this is a regression there, not a pre-existing hole.

Fixes 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks")
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 80 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.

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

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; the faulting instruction is mov (%rax),%r15 on rax = entity->rq == NULL, i.e. sched = entity->rq->sched:

   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.

v2: retarget Fixes: at commit 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks") — the !entity->rq check from commit 1decbf6bb0b4 ("drm/sched: Fix entities with 0 rqs.") that Alex pointed to was removed by it in the 7.3 window, so this is a regression there, not a pre-existing hole.

Fixes 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks")
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
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 +0 -0
index 1f7a98cdc..3952af9ae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_fini(struct amdgpu_device *adev) · line 260

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -1
@@ -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]);

Dang, it looks like currently the ownership of entity initialization is broken between the IP agnostic phase which does the init, and per-IP phase which tears it down.

The fix will get in the way of me re-trying to embed the run-queue into the scheduler but it does look correct.

I will see if I can re-work the init/cleanup phases so this can be removed, or if not, try to add a proper DRM scheduler API to query the status of an entity.

For now lets merge the fixup.

Regards,

Tvrtko

#2 lore raw
Quoted 9 lines · Tvrtko Ursulin
Quoted 7 lines · Olivier Kaloudoff

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

[…]

Quoted 26 lines
Quoted 18 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +2 -1
-	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 +0 -0
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;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -1
-	drm_sched_entity_destroy(&adev->vce.entity);
+	if (adev->vce.entity.rq)
+		drm_sched_entity_destroy(&adev->vce.entity);
Quoted 3 lines


   for (i = 0; i < adev->vce.num_rings; i++) amdgpu_ring_fini(&adev->vce.ring[i]);

Dang, it looks like currently the ownership of entity initialization is broken between the IP agnostic phase which does the init, and per-IP phase which tears it down.

Quoted 2 lines

The fix will get in the way of me re-trying to embed the run-queue into the scheduler but it does look correct.

Couldn't the status be tracked through the vce struct?

if (vce.entity_initialized)

Otherwise you rely on API-internals (again) which is what enabled that bug AFAICS. If it's about amdgpu having called foo_init() or not, then the most robust solution is to track within amdgpu "did I call that function already?" Same applies to all constructors and destructors in the kernel AFAIK.

Quoted 6 lines

I will see if I can re-work the init/cleanup phases so this can be removed, or if not, try to add a proper DRM scheduler API to query the status of an entity.

An API with which you can query whether a data object that you allocated and that you own had the constructor run by yourself? Or am I misunderstanding something?

P.

#3 lore raw
Quoted 44 lines · Philipp Stanner
Quoted 9 lines · Tvrtko Ursulin
Quoted 7 lines · Olivier Kaloudoff

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

[…]

Quoted 26 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +2 -1
-	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 +0 -0
index 1f7a98cdc..3952af9ae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_fini(struct amdgpu_device *adev) · line 260

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -1
@@ -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]);

Dang, it looks like currently the ownership of entity initialization is broken between the IP agnostic phase which does the init, and per-IP phase which tears it down.

Quoted 2 lines

The fix will get in the way of me re-trying to embed the run-queue into the scheduler but it does look correct.

Couldn't the status be tracked through the vce struct?

Quoted 7 lines

if (vce.entity_initialized)

Otherwise you rely on API-internals (again) which is what enabled that bug AFAICS. If it's about amdgpu having called foo_init() or not, then the most robust solution is to track within amdgpu "did I call that function already?" Same applies to all constructors and destructors in the kernel AFAIK.

Yep, it is such a horrible pattern to rely on being able to call destructors on non-initialized objects. I am looking at some flavour of "track in amdgpu" as priority options. Either by re-arranging the probe steps, or by tracking explicitly.

Quoted 10 lines
Quoted 6 lines

I will see if I can re-work the init/cleanup phases so this can be removed, or if not, try to add a proper DRM scheduler API to query the status of an entity.

An API with which you can query whether a data object that you allocated and that you own had the constructor run by yourself? Or am I misunderstanding something?

Yeah it would be bad. I don't think it will come to it since there is at least one better option.

Regards,

Tvrtko

maintainer
#4 lore raw
Quoted 44 lines · Tvrtko Ursulin
Quoted 42 lines · Philipp Stanner
Quoted 9 lines · Tvrtko Ursulin
Quoted 7 lines · Olivier Kaloudoff

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

[…]

Quoted 22 lines
Quoted 10 lines

   -    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 +0 -0
index 1f7a98cdc..3952af9ae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_fini(struct amdgpu_device *adev) · line 259

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
@@ -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]);

Dang, it looks like currently the ownership of entity initialization is broken between the IP agnostic phase which does the init, and per-IP phase which tears it down.

Quoted 2 lines

The fix will get in the way of me re-trying to embed the run-queue into the scheduler but it does look correct.

Couldn't the status be tracked through the vce struct?

if (vce.entity_initialized)

Quoted 7 lines
Quoted 5 lines

Otherwise you rely on API-internals (again) which is what enabled that bug AFAICS. If it's about amdgpu having called foo_init() or not, then the most robust solution is to track within amdgpu "did I call that function already?" Same applies to all constructors and destructors in the kernel AFAIK.

Yep, it is such a horrible pattern to rely on being able to call destructors on non-initialized objects. I am looking at some flavour of "track in amdgpu" as priority options. Either by re-arranging the probe steps, or by tracking explicitly.

Yeah the problem goes deeper than the DRM scheduler here.

Normally the sw_fini callback should only be called when the sw_init callback succeeded. Same for the hw_init/hw_fini.

Somehow amdgpu tries to tear down an IP block which was never full initialized in the first place. The scheduler is just the first component where it becomes obvious that something is going wrong here.

So we need to take a step back and ask why sw_fini is called for something that was never initialized *OR* maybe why the DRM scheduler init is somewhere else than the fini.

Regards,
Christian.

Quoted 18 lines
Quoted 11 lines
Quoted 7 lines

I will see if I can re-work the init/cleanup phases so this can be removed, or if not, try to add a proper DRM scheduler API to query the status of an entity.

An API with which you can query whether a data object that you allocated and that you own had the constructor run by yourself? Or am I misunderstanding something?

Yeah it would be bad. I don't think it will come to it since there is at least one better option.

Regards,

Tvrtko

#5 lore raw
Quoted 53 lines · Christian König
Quoted 44 lines · Tvrtko Ursulin
Quoted 42 lines · Philipp Stanner
Quoted 9 lines · Tvrtko Ursulin
Quoted 7 lines · Olivier Kaloudoff

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

[…]

Quoted 22 lines
Quoted 10 lines

   -    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 +0 -0
index 1f7a98cdc..3952af9ae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_fini(struct amdgpu_device *adev) · line 259

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
@@ -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]);

Dang, it looks like currently the ownership of entity initialization is broken between the IP agnostic phase which does the init, and per-IP phase which tears it down.

Quoted 2 lines

The fix will get in the way of me re-trying to embed the run-queue into the scheduler but it does look correct.

Couldn't the status be tracked through the vce struct?

if (vce.entity_initialized)

Quoted 7 lines
Quoted 5 lines

Otherwise you rely on API-internals (again) which is what enabled that bug AFAICS. If it's about amdgpu having called foo_init() or not, then the most robust solution is to track within amdgpu "did I call that function already?" Same applies to all constructors and destructors in the kernel AFAIK.

Yep, it is such a horrible pattern to rely on being able to call destructors on non-initialized objects. I am looking at some flavour of "track in amdgpu" as priority options. Either by re-arranging the probe steps, or by tracking explicitly.

Quoted 7 lines

Yeah the problem goes deeper than the DRM scheduler here.

Normally the sw_fini callback should only be called when the sw_init callback succeeded. Same for the hw_init/hw_fini.

Somehow amdgpu tries to tear down an IP block which was never full initialized in the first place. The scheduler is just the first component where it becomes obvious that something is going wrong here.

So we need to take a step back and ask why sw_fini is called for something that was never initialized *OR* maybe why the DRM scheduler init is somewhere else than the fini.

Problem is entity is initialized outside of sw_init (after), while destroy is done on sw_fini.

Flow is roughly like this:

amdgpu_device_ip_init
sw_init
... danger zone ...
amdgpu_device_init_schedulers (this initializes the entity)

So any probe failure inside the danger zone calls (correctly) sw_fini and that calls drm_sched_entity_destroy (incorrectly).

I tried moving entity init into the ip block domain, to fix the confused "ownership", but it is all interleaved and not straightforward to untangle. For now I gave up and have a local patch which adds an explicit flag. I'll send it once this one propagates to some visible branch.

At least I have some new trivial cleanup patches as a bonus result, which I will also send soon.

Regards,

Tvrtko

Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
Quoted 5 lines

I will see if I can re-work the init/cleanup phases so this can be removed, or if not, try to add a proper DRM scheduler API to query the status of an entity.

An API with which you can query whether a data object that you allocated and that you own had the constructor run by yourself? Or am I misunderstanding something?

Yeah it would be bad. I don't think it will come to it since there is at least one better option.

Regards,

Tvrtko

Applied
#6 lore raw
In reply to Olivier Kaloudoff

Applied. Thanks!

Alex

Quoted 92 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.

The hole was latent-but-safe until commit 2df5efb45425 ("drm/sched:
Remove redundant entity->rq initialization and checks") removed the if (!entity->rq) early return that commit 1decbf6bb0b4 ("drm/sched:
Fix entities with 0 rqs.") had put in drm_sched_entity_flush(), on the grounds that entity->rq can never be NULL. That holds only for entities that completed drm_sched_entity_init() — not for the never-initialized entity this teardown path reaches.

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; the faulting instruction is mov (%rax),%r15 on rax = entity->rq == NULL, i.e. sched = entity->rq->sched:

  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.

v2: retarget Fixes: at commit 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks") — the !entity->rq check from commit 1decbf6bb0b4 ("drm/sched: Fix entities with 0 rqs.") that Alex pointed to was removed by it in the 7.3 window, so this is a regression there, not a pre-existing hole.

Fixes 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks")
Cc Tvrtko Ursulin <[email protected]>
Cc Philipp Stanner <[email protected]>
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