Skip to contentSkip to conversation

drm/amdgpu: Skip drm_sched_entity realted ops for KIQ ring.

PATCH In review Andrey Grodzovsky 10 participants 19 messages May 15, 2018 – May 16, 2018 12 messages not in the archive

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

PATCH 1/2 drm/amdgpu: Skip drm_sched_entity realted ops for KIQ ring.

Follwoing change 75fbed2 we need to skip KIQ ring when iterating amdgpu_ctx's scheduler entites.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +18 -3
index 6741a62..744519b 100644
@@ -173,9 +173,14 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 
 	ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
-	for (i = 0; i < ctx->adev->num_rings; i++)
+	for (i = 0; i < ctx->adev->num_rings; i++) {
+
+		if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+			continue;
+
 		drm_sched_entity_fini(&ctx->adev->rings[i]->sched,
 			&ctx->rings[i].entity);
+	}
 
 	amdgpu_ctx_fini(ref);
 }
@@ -452,12 +457,17 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
 		if (!ctx->adev)
 			return;
 
-		for (i = 0; i < ctx->adev->num_rings; i++)
+		for (i = 0; i < ctx->adev->num_rings; i++) {
+
+			if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+				continue;
+
 			if (kref_read(&ctx->refcount) == 1)
 				drm_sched_entity_do_release(&ctx->adev->rings[i]->sched,
 						  &ctx->rings[i].entity);
 			else
 				DRM_ERROR("ctx %p is still alive\n", ctx);
+		}
 	}
 }
 
@@ -474,12 +484,17 @@ void amdgpu_ctx_mgr_entity_cleanup(struct amdgpu_ctx_mgr *mgr)
 		if (!ctx->adev)
 			return;
 
-		for (i = 0; i < ctx->adev->num_rings; i++)
+		for (i = 0; i < ctx->adev->num_rings; i++) {
+
+			if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+				continue;
+
 			if (kref_read(&ctx->refcount) == 1)
 				drm_sched_entity_cleanup(&ctx->adev->rings[i]->sched,
 					&ctx->rings[i].entity);
 			else
 				DRM_ERROR("ctx %p is still alive\n", ctx);
+		}
 	}
 }
 
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1526412674-15913-1-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/scheduler: Remove obsolete spinlock.

---
 drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
 include/drm/gpu_scheduler.h               | 1 -
 2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -4
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
 	entity->last_scheduled = NULL;
 
 	spin_lock_init(&entity->rq_lock);
-	spin_lock_init(&entity->queue_lock);
 	spsc_queue_init(&entity->job_queue);
 
 	atomic_set(&entity->fence_seq, 0);
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
 	trace_drm_sched_job(sched_job, entity);
 
-	spin_lock(&entity->queue_lock);
 	first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-	spin_unlock(&entity->queue_lock);
-
 	/* first job wakes up scheduler */
 	if (first) {
 		/* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -1
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
 	spinlock_t			rq_lock;
 	struct drm_gpu_scheduler	*sched;
 
-	spinlock_t			queue_lock;
 	struct spsc_queue		job_queue;
 
 	atomic_t			fence_seq;
Signature · 6 lines
2.7.4

_______________________________________________
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): 1526412674-15913-2-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 1 line · Andrey Grodzovsky

Please provide a better patch description.

Alex

Quoted 44 lines
---
 drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
 include/drm/gpu_scheduler.h               | 1 -
 2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -4
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-       spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 
        atomic_set(&entity->fence_seq, 0);
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
        trace_drm_sched_job(sched_job, entity);
 
-       spin_lock(&entity->queue_lock);
        first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-       spin_unlock(&entity->queue_lock);
-
        /* first job wakes up scheduler */
        if (first) {
                /* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -2
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
-       spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;
--

2.7.4

Quoted 4 lines

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

_______________________________________________
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): CADnq5_Pp=itdSOwq75petxvte1kUcLxmLymp_5zy7LVrgowyVw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Yea, I might need to give another thought to whether this  spinlock can actually be removed.

Andrey

Quoted 47 lines · Alex Deucher
Quoted 1 line · Andrey Grodzovsky

Please provide a better patch description.

Alex

Quoted 40 lines
---
  drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
  include/drm/gpu_scheduler.h               | 1 -
  2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -4
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
         entity->last_scheduled = NULL;
 
         spin_lock_init(&entity->rq_lock);
-       spin_lock_init(&entity->queue_lock);
         spsc_queue_init(&entity->job_queue);
 
         atomic_set(&entity->fence_seq, 0);
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
         trace_drm_sched_job(sched_job, entity);
 
-       spin_lock(&entity->queue_lock);
         first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-       spin_unlock(&entity->queue_lock);
-
         /* first job wakes up scheduler */
         if (first) {
                 /* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -1
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
         spinlock_t                      rq_lock;
         struct drm_gpu_scheduler        *sched;
 
-       spinlock_t                      queue_lock;
         struct spsc_queue               job_queue;
 
Quoted 8 lines
Quoted 8 lines
include/drm/gpu_scheduler.h +0 -1
         atomic_t                        fence_seq;
--

2.7.4

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

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

#7 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

In reply to a message not in the archive
Quoted 19 lines · Andrey Grodzovsky
---
  drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
  include/drm/gpu_scheduler.h               | 1 -
  2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
  	entity->last_scheduled = NULL;
 
  	spin_lock_init(&entity->rq_lock);
-	spin_lock_init(&entity->queue_lock);
  	spsc_queue_init(&entity->job_queue);
 
  	atomic_set(&entity->fence_seq, 0);

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

Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
  	trace_drm_sched_job(sched_job, entity);
 
-	spin_lock(&entity->queue_lock);
  	first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-	spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
  	/* first job wakes up scheduler */
  	if (first) {
  		/* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 7 lines
include/drm/gpu_scheduler.h +0 -1
@@ -56,7 +56,6 @@ struct drm_sched_entity {
  	spinlock_t			rq_lock;
  	struct drm_gpu_scheduler	*sched;
 
-	spinlock_t			queue_lock;
  	struct spsc_queue		job_queue;
 
  	atomic_t			fence_seq;

_______________________________________________
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): dda4fb88-e228-e10b-46a5-27ba9888b78d-5C7GfCeVMHo@public.gmane.org

#9 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 19 lines · Andrey Grodzovsky
---
  drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
  include/drm/gpu_scheduler.h               | 1 -
  2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
      entity->last_scheduled = NULL;
 
      spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
      spsc_queue_init(&entity->job_queue);
 
      atomic_set(&entity->fence_seq, 0);

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

Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
      trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
      first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
      /* first job wakes up scheduler */
      if (first) {
              /* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 7 lines
include/drm/gpu_scheduler.h +0 -1
@@ -56,7 +56,6 @@ struct drm_sched_entity {
      spinlock_t                      rq_lock;
      struct drm_gpu_scheduler        *sched;
 
-     spinlock_t                      queue_lock;
      struct spsc_queue               job_queue;
 
      atomic_t                        fence_seq;

_______________________________________________
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): MWHPR12MB14530840CD7DB545DD286827EA920-Gy0DoCVfaSWZBIDmKHdw+wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#11 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

No, that spinlock is indeed incorrect.

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the queue are reversed in their sequence order and that can cause severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 56 lines

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 19 lines · Andrey Grodzovsky
---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
   include/drm/gpu_scheduler.h               | 1 -
   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,
       entity->last_scheduled = NULL;
 
       spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
       spsc_queue_init(&entity->job_queue);
 
       atomic_set(&entity->fence_seq, 0);

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

Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
 
       trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
       first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
       /* first job wakes up scheduler */
       if (first) {
               /* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
       spinlock_t                      rq_lock;
       struct drm_gpu_scheduler        *sched;
 
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
       struct spsc_queue               job_queue;
 
       atomic_t                        fence_seq;

_______________________________________________
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): 3a54ce0c-6821-9c94-a67f-2b1a3c74959d-5C7GfCeVMHo@public.gmane.org

#13 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 65 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the queue are reversed in their sequence order and that can cause severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 58 lines

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 20 lines · Andrey Grodzovsky

---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ---- include/drm/gpu_scheduler.h               | 1 -

   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct 
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct · line 431

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct 
 drm_sched_job *sched_job,
 
        trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
        first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
        /* first job wakes up scheduler */
        if (first) {

               /* Add the entity to the run queue */

include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
Quoted 5 lines
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;

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

#14 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

drm_sched_fence_create() assigns a sequence number to the fence it creates.

Now drm_sched_fence_create() is called by drm_sched_job_init() to initialize the jobs we want to push on the scheduler queue.

When you now call drm_sched_entity_push_job() without a protecting lock it can happen that you push two (or even more) job with reversed sequence numbers.

Since the sequence numbers are used to determine job completion order reversing them can seriously mess things up.

So the spin lock should be superfluous, if it isn't we have a much larger bug we need to fix.

Christian.

Am 16.05.2018 um 13:15 schrieb Andrey Grodzovsky:

Quoted 74 lines

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 68 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the queue are reversed in their sequence order and that can cause severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 61 lines

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 20 lines · Andrey Grodzovsky

---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ---- include/drm/gpu_scheduler.h               | 1 -

   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct 
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct · line 431

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct 
 drm_sched_job *sched_job,
 
        trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
        first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 15 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
        /* first job wakes up scheduler */
        if (first) {

               /* Add the entity to the run queue */

include/drm/gpu_scheduler.h +0 -1
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
Quoted 7 lines
Quoted 2 lines
Quoted 1 line

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 1 line
include/drm/gpu_scheduler.h +0 -0
        atomic_t                        fence_seq;

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

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

A message that is not in the archive (sent off-list or not yet received): 0d936838-8a88-9bd7-d4ff-053cd73f41cc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#16 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

So are you saying that you expect this to  be already in code for any usage of drm_sched_fence_create and drm_sched_entity_push_job ?

lock()

drm_sched_fence_create()

... (some code)

drm_sched_entity_push_job()

unlock()

Andrey

Quoted 6 lines · Christian König

drm_sched_fence_create() assigns a sequence number to the fence it creates.

Now drm_sched_fence_create() is called by drm_sched_job_init() to initialize the jobs we want to push on the scheduler queue.

When you now call drm_sched_entity_push_job() without a protecting lock it can happen that you push two (or even more) job with reversed sequence numbers.

Quoted 89 lines

Since the sequence numbers are used to determine job completion order reversing them can seriously mess things up.

So the spin lock should be superfluous, if it isn't we have a much larger bug we need to fix.

Christian.

Am 16.05.2018 um 13:15 schrieb Andrey Grodzovsky:

Quoted 81 lines

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 65 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the queue are reversed in their sequence order and that can cause severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 58 lines

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 20 lines · Andrey Grodzovsky

---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ---- include/drm/gpu_scheduler.h               | 1 -

   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct 
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct · line 431

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct 
 drm_sched_job *sched_job,
 
        trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
        first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
        /* first job wakes up scheduler */
        if (first) {

               /* Add the entity to the run queue */

include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
Quoted 5 lines
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;

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

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

maintainer
#17 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Yes, exactly.

For normal user space command submission we should have tons of locks guaranteeing that (e.g. just the VM lock should do).

For kernel moves we have the mutex for the GTT windows which protects it.

The could be problems with the UVD/VCE queues to cleanup the handles when an application crashes.

Christian.

Am 16.05.2018 um 13:47 schrieb Andrey Grodzovsky:

Quoted 8 lines

So are you saying that you expect this to  be already in code for any usage of drm_sched_fence_create and drm_sched_entity_push_job ?

lock()

drm_sched_fence_create()

... (some code)

Quoted 104 lines

drm_sched_entity_push_job()

unlock()

Andrey

Quoted 95 lines · Christian König

drm_sched_fence_create() assigns a sequence number to the fence it creates.

Now drm_sched_fence_create() is called by drm_sched_job_init() to initialize the jobs we want to push on the scheduler queue.

When you now call drm_sched_entity_push_job() without a protecting lock it can happen that you push two (or even more) job with reversed sequence numbers.

Since the sequence numbers are used to determine job completion order reversing them can seriously mess things up.

So the spin lock should be superfluous, if it isn't we have a much larger bug we need to fix.

Christian.

Am 16.05.2018 um 13:15 schrieb Andrey Grodzovsky:

Quoted 81 lines

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 65 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the queue are reversed in their sequence order and that can cause severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 58 lines

Yeah, that what I am not sure about... It's lockless in a sense of single producer single consumer but not for multiple concurrent producers... So now I think this spinlock should stay there... It just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 20 lines · Andrey Grodzovsky

---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ---- include/drm/gpu_scheduler.h               | 1 -

   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct 
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct · line 431

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -2
@@ -424,11 +423,8 @@ void drm_sched_entity_push_job(struct 
 drm_sched_job *sched_job,
 
        trace_drm_sched_job(sched_job, entity);
 
-     spin_lock(&entity->queue_lock);
        first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
        /* first job wakes up scheduler */
        if (first) {

               /* Add the entity to the run queue */

include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
Quoted 5 lines
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;

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

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

A message that is not in the archive (sent off-list or not yet received): 0be3bb9a-004a-7390-469c-3f974ed44055-5C7GfCeVMHo@public.gmane.org

#19 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 11 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

For kernel moves we have the mutex for the GTT windows which protects it.

The could be problems with the UVD/VCE queues to cleanup the handles when an application crashes.

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per entity. So to actually end up with reversed seqnos one context has to preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Regards,
Lucas

Quoted 146 lines

Am 16.05.2018 um 13:47 schrieb Andrey Grodzovsky:

Quoted 10 lines

So are you saying that you expect this to  be already in code for any
usage of drm_sched_fence_create and drm_sched_entity_push_job ?

lock()

drm_sched_fence_create()

... (some code)

Quoted 133 lines

drm_sched_entity_push_job()

unlock()

Andrey

Quoted 125 lines · Christian König

drm_sched_fence_create() assigns a sequence number to the fence it
creates.

Now drm_sched_fence_create() is called by drm_sched_job_init() to
initialize the jobs we want to push on the scheduler queue.

When you now call drm_sched_entity_push_job() without a protecting
lock it can happen that you push two (or even more) job with reversed
sequence numbers.

Since the sequence numbers are used to determine job completion order
reversing them can seriously mess things up.

So the spin lock should be superfluous, if it isn't we have a much
larger bug we need to fix.

Christian.

Am 16.05.2018 um 13:15 schrieb Andrey Grodzovsky:

Quoted 100 lines

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 84 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the
queue are reversed in their sequence order and that can cause
severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 72 lines

Yeah, that what I am not sure about... It's lockless in a sense of
single producer single consumer but not for multiple concurrent
producers... So now I think this spinlock should stay there... It
just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 25 lines · Andrey Grodzovsky

om>
---
   drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ---- include/drm/gpu_scheduler.h               | 1 -

   2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct 
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -0
@@ -424,11 +423,8 @@ void

drm_sched_entity_push_job(struct
drm_sched_job *sched_job,

Quoted 7 lines

       trace_drm_sched_job(sched_job, entity);

-     spin_lock(&entity->queue_lock); first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);

-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 13 lines

-
       /* first job wakes up scheduler */
       if (first) {
               /* Add the entity to the run queue */

include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
Quoted 4 lines
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;

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

Quoted 4 lines

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

_______________________________________________
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): [email protected]

#21 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Am 16.05.2018 um 14:28 schrieb Lucas Stach:

Quoted 10 lines

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 9 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

For kernel moves we have the mutex for the GTT windows which protects it.

Quoted 8 lines
Quoted 2 lines

The could be problems with the UVD/VCE queues to cleanup the handles when an application crashes.

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per entity. So to actually end up with reversed seqnos one context has to preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Yes. The problem is with the right timing this can be used to access freed up memory.

If you then manage to place a page table in that freed up memory taking over the system is just a typing exercise.

Regards,
Christian.

Quoted 146 lines

Regards,
Lucas

Quoted 142 lines

Am 16.05.2018 um 13:47 schrieb Andrey Grodzovsky:

Quoted 141 lines

So are you saying that you expect this to  be already in code for any
usage of drm_sched_fence_create and drm_sched_entity_push_job ?

lock()

drm_sched_fence_create()

... (some code)

drm_sched_entity_push_job()

unlock()

Andrey

Quoted 123 lines · Christian König

drm_sched_fence_create() assigns a sequence number to the fence it
creates.

Now drm_sched_fence_create() is called by drm_sched_job_init() to
initialize the jobs we want to push on the scheduler queue.

When you now call drm_sched_entity_push_job() without a protecting
lock it can happen that you push two (or even more) job with reversed
sequence numbers.

Since the sequence numbers are used to determine job completion order
reversing them can seriously mess things up.

So the spin lock should be superfluous, if it isn't we have a much
larger bug we need to fix.

Christian.

Am 16.05.2018 um 13:15 schrieb Andrey Grodzovsky:

Quoted 98 lines

Can you please elaborate more, maybe give an example - I don't understand yet the problematic scenario.

Andrey

Quoted 83 lines · Christian König

No, that spinlock is indeed incorrect. I

See even when we protect the spsc queue with a spinlock that doesn't make it correct. It can happen that the jobs pushed to the
queue are reversed in their sequence order and that can cause
severe problems in the memory management.

Christian.

Am 16.05.2018 um 05:33 schrieb Grodzovsky, Andrey:

Quoted 71 lines

Yeah, that what I am not sure about... It's lockless in a sense of
single producer single consumer but not for multiple concurrent
producers... So now I think this spinlock should stay there... It
just looked useless to me at first sight...

Andrey

________________________________________
From: Zhou, David(ChunMing)
Sent: 15 May 2018 23:04:44
To: Grodzovsky, Andrey; [email protected]; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 25 lines · Andrey Grodzovsky

om>

---
    drivers/gpu/drm/scheduler/gpu_scheduler.c | 4 ----
    include/drm/gpu_scheduler.h               | 1 -
    2 files changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
index 1f1dd70..2569a63 100644
@@ -140,7 +140,6 @@ int drm_sched_entity_init(struct
 drm_gpu_scheduler *sched,
        entity->last_scheduled = NULL;
 
        spin_lock_init(&entity->rq_lock);
-     spin_lock_init(&entity->queue_lock);
        spsc_queue_init(&entity->job_queue);
 

       atomic_set(&entity->fence_seq, 0);

drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -0
@@ -424,11 +423,8 @@ void

drm_sched_entity_push_job(struct
drm_sched_job *sched_job,

Quoted 7 lines

       trace_drm_sched_job(sched_job, entity);

-     spin_lock(&entity->queue_lock);
       first = spsc_queue_push(&entity->job_queue,
&sched_job->queue_node);

-     spin_unlock(&entity->queue_lock);

Is your spsc safely to be added simultaneously?

Regards,
David Zhou

Quoted 13 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -1
-
        /* first job wakes up scheduler */
        if (first) {
                /* Add the entity to the run queue */
include/drm/gpu_scheduler.h +0 -0
index 350a62c..683eb65 100644
@@ -56,7 +56,6 @@ struct drm_sched_entity {
        spinlock_t                      rq_lock;
        struct drm_gpu_scheduler        *sched;
 
Quoted 4 lines
Quoted 4 lines

include/drm/gpu_scheduler.h struct drm_sched_entity { · line 61

Quoted 4 lines
include/drm/gpu_scheduler.h +0 -1
-     spinlock_t                      queue_lock;
        struct spsc_queue               job_queue;
 
        atomic_t                        fence_seq;

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

Quoted 8 lines
Quoted 4 lines

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

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

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

#22 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Am Mittwoch, den 16.05.2018, 14:32 +0200 schrieb Christian König:

Quoted 25 lines

Am 16.05.2018 um 14:28 schrieb Lucas Stach:

Quoted 15 lines

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 6 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

Quoted 7 lines

For kernel moves we have the mutex for the GTT windows which protects
it.

The could be problems with the UVD/VCE queues to cleanup the handles
when an application crashes.

Quoted 8 lines

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per
entity. So to actually end up with reversed seqnos one context has to
preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Quoted 6 lines

Yes. The problem is with the right timing this can be used to access freed up memory.

If you then manage to place a page table in that freed up memory taking
over the system is just a typing exercise.

Thanks. I believe we don't have this problem in etnaviv, as memory referencing is tied to the job and will only be unreferenced on free_job, but I'll re-check this when I've got some time.

Regards,
Lucas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#24 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Am 16.05.2018 um 15:00 schrieb Lucas Stach:

Quoted 27 lines

Am Mittwoch, den 16.05.2018, 14:32 +0200 schrieb Christian König:

Quoted 26 lines

Am 16.05.2018 um 14:28 schrieb Lucas Stach:

Quoted 14 lines

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 6 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

Quoted 7 lines

For kernel moves we have the mutex for the GTT windows which protects
it.

The could be problems with the UVD/VCE queues to cleanup the handles
when an application crashes.

Quoted 8 lines

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per
entity. So to actually end up with reversed seqnos one context has to
preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Yes. The problem is with the right timing this can be used to access freed up memory.

Quoted 6 lines
Quoted 3 lines

If you then manage to place a page table in that freed up memory taking
over the system is just a typing exercise.

Thanks. I believe we don't have this problem in etnaviv, as memory referencing is tied to the job and will only be unreferenced on free_job, but I'll re-check this when I've got some time.

Well that depends on how you use the sequence numbers.

If you use them for job completion check somewhere then you certainly have a problem if job A gets the 1 and B the 2, but B completes before A.

At bare minimum that's still a bug we need to fix because it confuses functions like dma_fence_is_later() and dma_fence_later().

Christian.

Quoted 3 lines

Regards,
Lucas

_______________________________________________
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): 96b4e712-5e80-0053-301e-3f89940be8f0-5C7GfCeVMHo@public.gmane.org

#26 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Am Mittwoch, den 16.05.2018, 15:10 +0200 schrieb Christian König:

Quoted 34 lines

Am 16.05.2018 um 15:00 schrieb Lucas Stach:

Quoted 33 lines

Am Mittwoch, den 16.05.2018, 14:32 +0200 schrieb Christian König:

Quoted 31 lines

Am 16.05.2018 um 14:28 schrieb Lucas Stach:

Quoted 15 lines

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 6 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

Quoted 7 lines

For kernel moves we have the mutex for the GTT windows which protects
it.

The could be problems with the UVD/VCE queues to cleanup the handles
when an application crashes.

Quoted 8 lines

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per
entity. So to actually end up with reversed seqnos one context has to
preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Yes. The problem is with the right timing this can be used to access freed up memory.

If you then manage to place a page table in that freed up memory taking
over the system is just a typing exercise.

Quoted 8 lines
Quoted 3 lines

Thanks. I believe we don't have this problem in etnaviv, as memory referencing is tied to the job and will only be unreferenced on free_job, but I'll re-check this when I've got some time.

Well that depends on how you use the sequence numbers.

If you use them for job completion check somewhere then you certainly have a problem if job A gets the 1 and B the 2, but B completes before A.

We don't do this anymore. All the etnaviv internals are driven by the fence signal callbacks.

Quoted 2 lines

At bare minimum that's still a bug we need to fix because it confuses functions like dma_fence_is_later() and dma_fence_later().

Agreed. Also amending the documentation to state that drm_sched_job_init() and drm_sched_entity_push_job() need to be called under a common lock seems like a good idea.

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

#27 lore raw

Re: [PATCH 2/2] drm/scheduler: Remove obsolete spinlock.

Quoted 39 lines · Lucas Stach

Am Mittwoch, den 16.05.2018, 15:10 +0200 schrieb Christian König:

Quoted 31 lines

Am 16.05.2018 um 15:00 schrieb Lucas Stach:

Quoted 30 lines

Am Mittwoch, den 16.05.2018, 14:32 +0200 schrieb Christian König:

Quoted 29 lines

Am 16.05.2018 um 14:28 schrieb Lucas Stach:

Quoted 14 lines

Am Mittwoch, den 16.05.2018, 14:08 +0200 schrieb Christian König:

Quoted 6 lines

Yes, exactly.

For normal user space command submission we should have tons of locks
guaranteeing that (e.g. just the VM lock should do).

Quoted 7 lines

For kernel moves we have the mutex for the GTT windows which protects
it.

The could be problems with the UVD/VCE queues to cleanup the handles
when an application crashes.

Quoted 8 lines

FWIW, etnaviv is currently completely unlocked in this path, but I believe that this isn't an issue as the sched fence seq numbers are per
entity. So to actually end up with reversed seqnos one context has to
preempt itself to do another submit, while the current one hasn't returned from kernel space, which I believe is a fairly theoretical issue. Is my understanding correct?

Yes. The problem is with the right timing this can be used to access freed up memory.

If you then manage to place a page table in that freed up memory taking
over the system is just a typing exercise.

Quoted 7 lines
Quoted 3 lines

Thanks. I believe we don't have this problem in etnaviv, as memory referencing is tied to the job and will only be unreferenced on free_job, but I'll re-check this when I've got some time.

Well that depends on how you use the sequence numbers.

If you use them for job completion check somewhere then you certainly have a problem if job A gets the 1 and B the 2, but B completes before A.

Quoted 8 lines

We don't do this anymore. All the etnaviv internals are driven by the fence signal callbacks.

Quoted 2 lines

At bare minimum that's still a bug we need to fix because it confuses functions like dma_fence_is_later() and dma_fence_later().

Agreed. Also amending the documentation to state that drm_sched_job_init() and drm_sched_entity_push_job() need to be called under a common lock seems like a good idea.

I will respin the patch with added documentation.

Andrey

Quoted 2 lines

Regards,
Lucas

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

Reviewed-by
#28 lore raw
In reply to a message not in the archive
Quoted 4 lines · Andrey Grodzovsky

Follwoing change 75fbed2 we need to skip KIQ ring when iterating amdgpu_ctx's scheduler entites.

Typo in the title: realted -> related
Typo in the description: Follwoing -> Following
Also expand on the reasoning a bit in the patch description. E.g., we never initialize or use the GPU scheduler for KIQ.
With those things fixes:

Alex

Quoted 65 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +18 -4
index 6741a62..744519b 100644
@@ -173,9 +173,14 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 
        ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
-       for (i = 0; i < ctx->adev->num_rings; i++)
+       for (i = 0; i < ctx->adev->num_rings; i++) {
+
+               if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                       continue;
+
                drm_sched_entity_fini(&ctx->adev->rings[i]->sched,
                        &ctx->rings[i].entity);
+       }
 
        amdgpu_ctx_fini(ref);
 }
@@ -452,12 +457,17 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
                if (!ctx->adev)
                        return;
 
-               for (i = 0; i < ctx->adev->num_rings; i++)
+               for (i = 0; i < ctx->adev->num_rings; i++) {
+
+                       if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                               continue;
+
                        if (kref_read(&ctx->refcount) == 1)
                                drm_sched_entity_do_release(&ctx->adev->rings[i]->sched,
                                                  &ctx->rings[i].entity);
                        else
                                DRM_ERROR("ctx %p is still alive\n", ctx);
+               }
        }
 }
 
@@ -474,12 +484,17 @@ void amdgpu_ctx_mgr_entity_cleanup(struct amdgpu_ctx_mgr *mgr)
                if (!ctx->adev)
                        return;
 
-               for (i = 0; i < ctx->adev->num_rings; i++)
+               for (i = 0; i < ctx->adev->num_rings; i++) {
+
+                       if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                               continue;
+
                        if (kref_read(&ctx->refcount) == 1)
                                drm_sched_entity_cleanup(&ctx->adev->rings[i]->sched,
                                        &ctx->rings[i].entity);
                        else
                                DRM_ERROR("ctx %p is still alive\n", ctx);
+               }
        }
 }
 
--

2.7.4

Quoted 4 lines

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

_______________________________________________
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): CADnq5_OtJDxZSrTe_peJtFTCm6T8QnBW-iri2UJv1yvOmjraNQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#30 lore raw

Am 15.05.2018 um 21:42 schrieb Alex Deucher:

Quoted 5 lines
Quoted 3 lines · Andrey Grodzovsky

Follwoing change 75fbed2 we need to skip KIQ ring when iterating amdgpu_ctx's scheduler entites.

Quoted 7 lines
Quoted 1 line

Typo in the title: realted -> related
Typo in the description: Follwoing -> Following
Also expand on the reasoning a bit in the patch description. E.g., we never initialize or use the GPU scheduler for KIQ.
With those things fixes:

With the typos fixed Reviewed-by: Christian König <[email protected]>.

Christian.

Quoted 68 lines

Alex

Quoted 65 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 21 ++++++++++++++++++---
  1 file changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +18 -4
index 6741a62..744519b 100644
@@ -173,9 +173,14 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 
         ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
-       for (i = 0; i < ctx->adev->num_rings; i++)
+       for (i = 0; i < ctx->adev->num_rings; i++) {
+
+               if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                       continue;
+
                 drm_sched_entity_fini(&ctx->adev->rings[i]->sched,
                         &ctx->rings[i].entity);
+       }
 
         amdgpu_ctx_fini(ref);
  }
@@ -452,12 +457,17 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
                 if (!ctx->adev)
                         return;
 
-               for (i = 0; i < ctx->adev->num_rings; i++)
+               for (i = 0; i < ctx->adev->num_rings; i++) {
+
+                       if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                               continue;
+
                         if (kref_read(&ctx->refcount) == 1)
                                 drm_sched_entity_do_release(&ctx->adev->rings[i]->sched,
                                                   &ctx->rings[i].entity);
                         else
                                 DRM_ERROR("ctx %p is still alive\n", ctx);
+               }
         }
  }
 
@@ -474,12 +484,17 @@ void amdgpu_ctx_mgr_entity_cleanup(struct amdgpu_ctx_mgr *mgr)
                 if (!ctx->adev)
                         return;
 
-               for (i = 0; i < ctx->adev->num_rings; i++)
+               for (i = 0; i < ctx->adev->num_rings; i++) {
+
+                       if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring)
+                               continue;
+
                         if (kref_read(&ctx->refcount) == 1)
                                 drm_sched_entity_cleanup(&ctx->adev->rings[i]->sched,
                                         &ctx->rings[i].entity);
                         else
                                 DRM_ERROR("ctx %p is still alive\n", ctx);
+               }
         }
  }
 
--

2.7.4

Quoted 8 lines
Quoted 4 lines

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

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

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