drm/sched: Don't crash kernel on wrong params
Subsystems (3)
Philipp Stanner
maintainerPATCH 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
@@ -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
Quoted 7 lines · Philipp Stanner
drm_sched_job_arm()just panics the kernel withBUG_ON()in case of an entity being NULL. Whiledrm_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()indrm_sched_job_arm()with aWARN_ON().Signed-off-by Philipp Stanner <[email protected]>
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@@ -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
Quoted 21 lines · Philipp Stanner
drm_sched_job_arm()just panics the kernel withBUG_ON()in case of an entity being NULL. Whiledrm_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()indrm_sched_job_arm()with aWARN_ON().Signed-off-by Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0
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
-0sched = entity->rq->sched;
Quoted 35 lines · Tvrtko Ursulin
Quoted 21 lines · Philipp Stanner
drm_sched_job_arm()just panics the kernel withBUG_ON()in case of an entity being NULL. Whiledrm_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()indrm_sched_job_arm()with aWARN_ON().Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0drivers/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){
structdma_fence*fence;
structdrm_gpu_scheduler*sched;
structdrm_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
-0sched = entity->rq->sched;
Quoted 39 lines · Tvrtko Ursulin
Quoted 26 lines · Philipp Stanner
drm_sched_job_arm()just panics the kernel withBUG_ON()in case of an entity being NULL. Whiledrm_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()indrm_sched_job_arm()with aWARN_ON().Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -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.