Skip to contentSkip to conversation

drm/sched: Don't crash kernel on wrong params

PATCH Superseded Philipp Stanner 4 participants 5 messages Nov 7, 2025 – Nov 10, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Philipp Stanner

author maintainer
#0 lore raw

PATCH 1/1 drm/sched: Don't crash kernel on wrong params

drm_sched_job_arm() just panics the kernel with BUG_ON() in case of an entity being NULL. While drm_sched_job_arm() crashing or not effectively arming jobs is certainly a huge issue that needs to be noticed, completely shooting down the kernel reduces the probability of reaching and debugging a system to 0.

Moreover, the checkpatch script by now strongly discourages all new uses of BUG_ON() for this reason.

Replace the BUG_ON() in drm_sched_job_arm() with a WARN_ON().

---
 drivers/gpu/drm/scheduler/sched_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 1d4f1b822e7b..3bf4ae0ca4bc 100644
@@ -857,7 +857,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
 	struct drm_gpu_scheduler *sched;
 	struct drm_sched_entity *entity = job->entity;
 
-	BUG_ON(!entity);
+	WARN_ON(!entity);
 	drm_sched_entity_select_rq(entity);
 	sched = entity->rq->sched;
 
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Philipp Stanner

drm_sched_job_arm() just panics the kernel with BUG_ON() in case of an entity being NULL. While drm_sched_job_arm() crashing or not effectively arming jobs is certainly a huge issue that needs to be noticed, completely shooting down the kernel reduces the probability of reaching and debugging a system to 0.

Quoted 6 lines

Moreover, the checkpatch script by now strongly discourages all new uses of BUG_ON() for this reason.

Replace the BUG_ON() in drm_sched_job_arm() with a WARN_ON().

Quoted 20 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -2
index 1d4f1b822e7b..3bf4ae0ca4bc 100644
@@ -857,7 +857,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
        struct drm_gpu_scheduler *sched;
        struct drm_sched_entity *entity = job->entity;
 
-       BUG_ON(!entity);
+       WARN_ON(!entity);
        drm_sched_entity_select_rq(entity);
        sched = entity->rq->sched;
 
--

2.49.0

#2 lore raw
In reply to Philipp Stanner
Quoted 21 lines · Philipp Stanner

drm_sched_job_arm() just panics the kernel with BUG_ON() in case of an entity being NULL. While drm_sched_job_arm() crashing or not effectively arming jobs is certainly a huge issue that needs to be noticed, completely shooting down the kernel reduces the probability of reaching and debugging a system to 0.

Moreover, the checkpatch script by now strongly discourages all new uses of BUG_ON() for this reason.

Replace the BUG_ON() in drm_sched_job_arm() with a WARN_ON().

---
  drivers/gpu/drm/scheduler/sched_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 1d4f1b822e7b..3bf4ae0ca4bc 100644

drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_arm(struct drm_sched_job *job) · line 861

Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -857,7 +857,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
  	struct drm_gpu_scheduler *sched;
  	struct drm_sched_entity *entity = job->entity;
 
-	BUG_ON(!entity);
+	WARN_ON(!entity);
  	drm_sched_entity_select_rq(entity);

void drm_sched_entity_select_rq(struct drm_sched_entity *entity)

{
	struct dma_fence *fence;
	struct drm_gpu_scheduler *sched;
	struct drm_sched_rq *rq;

	/* single possible engine and already selected */
	if (!entity->sched_list)

Still the same end result.

I believe best practice is to simply not have BUG_ON's followed by null pointer dereferences since they add no value. Ie. it should just be removed and not replaced.

Regards,

Tvrtko

Regards,

Tvrtko

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
  	sched = entity->rq->sched;
 
#3 lore raw
Quoted 35 lines · Tvrtko Ursulin
Quoted 21 lines · Philipp Stanner

drm_sched_job_arm() just panics the kernel with BUG_ON() in case of an entity being NULL. While drm_sched_job_arm() crashing or not effectively arming jobs is certainly a huge issue that needs to be noticed, completely shooting down the kernel reduces the probability of reaching and debugging a system to 0.

Moreover, the checkpatch script by now strongly discourages all new uses of BUG_ON() for this reason.

Replace the BUG_ON() in drm_sched_job_arm() with a WARN_ON().

---
  drivers/gpu/drm/scheduler/sched_main.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 1d4f1b822e7b..3bf4ae0ca4bc 100644

drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_arm(struct drm_sched_job *job) · line 860

Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -857,7 +857,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
       struct drm_gpu_scheduler *sched;
       struct drm_sched_entity *entity = job->entity;
-    BUG_ON(!entity);
+    WARN_ON(!entity);
       drm_sched_entity_select_rq(entity);

void drm_sched_entity_select_rq(struct drm_sched_entity *entity) {
    struct dma_fence *fence;
    struct drm_gpu_scheduler *sched;
    struct drm_sched_rq *rq;

Quoted 6 lines

    /* single possible engine and already selected */ if (!entity->sched_list)

Still the same end result.

I believe best practice is to simply not have BUG_ON's followed by null

Sorry I meant WARN_ONs. If we think there is scope for bad things to happen after letting the execution proceed then I would add an early return to the WARN_ON (_ONCE?). That probably means to push job as well.

Regards,

Tvrtko

Quoted 12 lines

pointer dereferences since they add no value. Ie. it should just be removed and not replaced.

Regards,

Tvrtko

Regards,

Tvrtko

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0 -0
       sched = entity->rq->sched;
#4 lore raw
In reply to Tvrtko Ursulin
Quoted 39 lines · Tvrtko Ursulin
Quoted 26 lines · Philipp Stanner

drm_sched_job_arm() just panics the kernel with BUG_ON() in case of an entity being NULL. While drm_sched_job_arm() crashing or not effectively arming jobs is certainly a huge issue that needs to be noticed, completely shooting down the kernel reduces the probability of reaching and debugging a system to 0.

Moreover, the checkpatch script by now strongly discourages all new uses of BUG_ON() for this reason.

Replace the BUG_ON() in drm_sched_job_arm() with a WARN_ON().

---
  drivers/gpu/drm/scheduler/sched_main.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 1d4f1b822e7b..3bf4ae0ca4bc 100644
@@ -857,7 +857,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
   	struct drm_gpu_scheduler *sched;
   	struct drm_sched_entity *entity = job->entity;

drivers/gpu/drm/scheduler/sched_main.c +1 -1
-	BUG_ON(!entity);
+	WARN_ON(!entity);
Quoted 1 line

   drm_sched_entity_select_rq(entity);

void drm_sched_entity_select_rq(struct drm_sched_entity *entity)

{
	struct dma_fence *fence;
	struct drm_gpu_scheduler *sched;
	struct drm_sched_rq *rq;

	/* single possible engine and already selected */
	if (!entity->sched_list)
Quoted 5 lines

Still the same end result.

I believe best practice is to simply not have BUG_ON's followed by null pointer dereferences since they add no value. Ie. it should just be removed and not replaced.

Hm, right. I agree. Both jobs and entities are initialized to 0 anyways. Existing users work, and new users would notice a null ptr crash.

Let's remove it altogether.

P.