Skip to contentSkip to conversation

drm/scheduler: add NULL pointer check for run queue (v2)

PATCH In review Junwei Zhang 3 participants 4 messages Jul 16, 2018 – Jul 17, 2018 2 messages not in the archive

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

PATCH 1/1 drm/scheduler: add NULL pointer check for run queue (v2)

To check rq pointer before adding entity into it.
That avoids NULL pointer access in some case.

v2: move the check to caller

---
 drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/scheduler/gpu_scheduler.c +5 -0
index 16bf446..dac71e3 100644
@@ -547,6 +547,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 	if (first) {
 		/* Add the entity to the run queue */
 		spin_lock(&entity->rq_lock);
+		if (!entity->rq) {
+			DRM_ERROR("Trying to push to a killed entity\n");
+			spin_unlock(&entity->rq_lock);
+			return;
+		}
 		drm_sched_rq_add_entity(entity->rq, entity);
 		spin_unlock(&entity->rq_lock);
 		drm_sched_wakeup(sched);
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1531733034-22183-1-git-send-email-Jerry.Zhang-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#2 lore raw

Am 16.07.2018 um 11:23 schrieb Junwei Zhang:

Quoted 7 lines

To check rq pointer before adding entity into it.
That avoids NULL pointer access in some case.

v2: move the check to caller

Quoted 10 lines
---
  drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -0
index 16bf446..dac71e3 100644
@@ -547,6 +547,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
  	if (first) {

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct drm_sched_job *sched_job, · line 557

Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +5 -0
  		/* Add the entity to the run queue */
  		spin_lock(&entity->rq_lock);
+		if (!entity->rq) {
+			DRM_ERROR("Trying to push to a killed entity\n");
+			spin_unlock(&entity->rq_lock);
+			return;
+		}
  		drm_sched_rq_add_entity(entity->rq, entity);
  		spin_unlock(&entity->rq_lock);
  		drm_sched_wakeup(sched);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
In reply to a message not in the archive
Quoted 16 lines · Junwei Zhang

To check rq pointer before adding entity into it.
That avoids NULL pointer access in some case.

v2: move the check to caller

---
 drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -0
index 16bf446..dac71e3 100644

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct drm_sched_job *sched_job, · line 551

Quoted 5 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +2 -0
@@ -547,6 +547,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 	if (first) {
 		/* Add the entity to the run queue */
 		spin_lock(&entity->rq_lock);
+		if (!entity->rq) {
+			DRM_ERROR("Trying to push to a killed entity\n");

This could result in spamming dmesg with this error message. I suggest

		if (WARN_ON_ONCE(!entity->rq)) {

instead, no DRM_ERROR. That will produce a single warning with a backtrace.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): e62a1051-00c9-99b2-dd83-d8f47e9038f4-otUistvHUpPR7s880joybQ@public.gmane.org

#5 lore raw
Quoted 12 lines · Michel Dänzer
Quoted 11 lines · Junwei Zhang

To check rq pointer before adding entity into it.
That avoids NULL pointer access in some case.

v2: move the check to caller

---
  drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 +++++
  1 file changed, 5 insertions(+)
Quoted 12 lines

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct drm_sched_job *sched_job, · line 551

Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +2 -0
index 16bf446..dac71e3 100644
@@ -547,6 +547,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
  	if (first) {
  		/* Add the entity to the run queue */
  		spin_lock(&entity->rq_lock);
+		if (!entity->rq) {
+			DRM_ERROR("Trying to push to a killed entity\n");

This could result in spamming dmesg with this error message. I suggest

Thanks for your comments.
Actually it will cause App or GPU hang, as the job is unexpected to push to a non-existing entity run queue. Now we're trying to predict that before kernel panic or BUG_ON.

Regards,
Jerry

Quoted 6 lines
		if (WARN_ON_ONCE(!entity->rq)) {

instead, no DRM_ERROR. That will produce a single warning with a backtrace.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx