drm/scheduler: Remove entity->rq NULL check
Subsystems (3)
Christian König
reviewerPATCH 1/1 drm/scheduler: Remove entity->rq NULL check
That is superflous now.
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -5
@@ -590,11 +590,6 @@ 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 (entity->rq->sched);
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerPing. Any objections to that?
Christian.
Am 03.08.2018 um 13:08 schrieb Christian König:
Quoted 13 lines
That is superflous now.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- 1 file changed, 5 deletions(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -590,11 +590,6 @@ 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 595
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5/* 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 (entity->rq->sched);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh < [email protected]>
Nayan
Quoted 12 lines · Christian König
Ping. Any objections to that?
Christian.
Am 03.08.2018 um 13:08 schrieb Christian König:
Quoted 7 lines
That is superflous now.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- 1 file changed, 5 deletions(-)
Quoted 20 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/scheduler/gpu_scheduler.cdrivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct drm_sched_job
Quoted 4 lines
index
85908c7f913e..65078dd3c82c100644drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -590,11 +590,6 @@ void drm_sched_entity_push_job(struct drm_sched_job
*sched_job,Quoted 11 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5if (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 (entity->rq->sched);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Andrey Grodzovsky
Reviewed-byBut I still have questions about entity->last_user (didn't notice this before) -
Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing drm_sched_entity_flush->cmpxchg(...)
now process B working on same entity (forked) is inside drm_sched_entity_push_job, he writes his PID to entity->last_user and also
executes drm_sched_rq_add_entity. Now process A runs again and execute drm_sched_rq_remove_entity inadvertently causing process B removal
from it's scheduler rq.
Looks to me like instead we should lock together entity->last_user accesses and adds/removals of entity to the rq.
Andrey
Quoted 32 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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) {
Quoted 9 lines
> - 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(entity->rq->sched);_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerCrap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.
Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 12 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removal
Quoted 50 lines
from it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
I can take care of this.
Andrey
Quoted 69 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 62 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalfrom it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Attached.
If the general idea in the patch is OK I can think of a test (and maybe add to libdrm amdgpu tests) to actually simulate this scenario with 2 forked
concurrent processes working on same entity's job queue when one is dying while the other keeps pushing to the same queue. For now I only tested it
with normal boot and ruining multiple glxgears concurrently - which doesn't really test this code path since i think each of them works on it's own FD.
Andrey
Quoted 70 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 12 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalQuoted 50 lines
from it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);
Quoted 1 line
From
c581a410e1b3f82de2bb14746d8484db2162f82cMon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Mon, 13 Aug 2018 12:33:29 -0400
Subject: drm/scheduler: Fix possible race condition.
Problem:
The possbile race scenario is as follwing -
Process A was preempted after doing drm_sched_entity_flush->cmpxchg(...) now process B working on same entity (forked) is inside drm_sched_entity_push_job, he writes his PID to entity->last_user and also executes drm_sched_rq_add_entity. Now process A runs again and execute drm_sched_rq_remove_entity inadvertently causing process B removal from it's scheduler rq.
Fix:
Lock together entity->last_user accesses and adds/removals of entity to the rq.
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +15 -7
@@ -311,10 +311,12 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For killed process disable any more IBs enqueue right now */ +spin_lock (&entity->rq_lock); last_user =cmpxchg (&entity->last_user, current->group_leader,NULL );if ((!last_user || last_user == current->group_leader) && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL ))drm_sched_rq_remove_entity (entity->rq, entity); +spin_unlock (&entity->rq_lock);return ret; }
@@ -596,17 +598,23 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,trace_drm_sched_job (sched_job, entity);atomic_inc (&entity->rq->sched->num_jobs); -WRITE_ONCE (entity->last_user, current->group_leader); first =spsc_queue_push (&entity->job_queue, &sched_job->queue_node); -/* first job wakes up scheduler */ -if (first) { -/* Add the entity to the run queue */ -spin_lock (&entity->rq_lock); +/* +* entity might not be attached to rq because it's the first time we use it +* or because another process removed the entity from the rq during +* it's termination in drm_sched_entity_flush. We then need to add +* back the entity to rq +*/ +spin_lock (&entity->rq_lock); + entity->last_user = current->group_leader; +if (list_empty (&entity->list))drm_sched_rq_add_entity (entity->rq, entity); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->rq_lock); + +/* first job wakes up scheduler */ +if (first)drm_sched_wakeup (entity->rq->sched); - } }EXPORT_SYMBOL (drm_sched_entity_push_job);
Signature · 1 line
2.7.4
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerI would rather like to avoid taking the lock in the hot path.
How about this:
/* For killed process disable any more IBs enqueue right now */ last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) { grab_lock();
drm_sched_rq_remove_entity(entity->rq, entity);
if (READ_ONCE(&entity->last_user) != NULL) drm_sched_rq_add_entity(entity->rq, entity); drop_lock();
}
Christian.
Am 13.08.2018 um 18:43 schrieb Andrey Grodzovsky:
Quoted 85 lines
Attached.
If the general idea in the patch is OK I can think of a test (and maybe add to libdrm amdgpu tests) to actually simulate this scenario with 2 forked
concurrent processes working on same entity's job queue when one is dying while the other keeps pushing to the same queue. For now I only tested it
with normal boot and ruining multiple glxgears concurrently - which doesn't really test this code path since i think each of them works on it's own FD.
Andrey
Quoted 69 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 62 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalfrom it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
I assume that this is the only code change and no locks are taken in drm_sched_entity_push_job -
What happens if process A runs drm_sched_entity_push_job after this code was executed from the (dying) process B and there
are still jobs in the queue (the wait_event terminated prematurely), the entity already removed from rq , but bool 'first' in drm_sched_entity_push_job
will return false and so the entity will not be reinserted back into rq entity list and no wake up trigger will happen for process A pushing a new job.
Another issue bellow -
Andrey
Quoted 11 lines · Christian König
I would rather like to avoid taking the lock in the hot path.
How about this:
/* For killed process disable any more IBs enqueue right now */
last_user=cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user ||last_user==current->group_leader) && (current->flags&PF_EXITING) && (current->exit_code== SIGKILL)) {grab_lock();
drm_sched_rq_remove_entity(entity->rq, entity);
if (READ_ONCE(&entity->last_user)!= NULL)
This condition is true because just exactly now process A did drm_sched_entity_push_job->WRITE_ONCE(entity->last_user, current->group_leader); and so the line bellow executed and entity reinserted into rq. Let's say also that the entity job queue is empty now. For process A bool 'first' will be true and hence also drm_sched_entity_push_job->drm_sched_rq_add_entity(entity->rq, entity) will take place causing double insertion of the entity queue into rq list.
Andrey
Quoted 4 lines
drm_sched_rq_add_entity(entity->rq, entity);
drop_lock();
}
Quoted 93 lines
Christian.
Am 13.08.2018 um 18:43 schrieb Andrey Grodzovsky:
Quoted 89 lines
Attached.
If the general idea in the patch is OK I can think of a test (and maybe add to libdrm amdgpu tests) to actually simulate this scenario with 2 forked
concurrent processes working on same entity's job queue when one is dying while the other keeps pushing to the same queue. For now I only tested it
with normal boot and ruining multiple glxgears concurrently - which doesn't really test this code path since i think each of them works on it's own FD.
Andrey
Quoted 69 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 62 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalfrom it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 14.08.2018 um 17:17 schrieb Andrey Grodzovsky:
Quoted 3 lines
I assume that this is the only code change and no locks are taken in
drm_sched_entity_push_job-
What are you talking about? You surely now take looks in drm_sched_entity_push_job():
Quoted 10 lines
+ spin_lock(&entity->rq_lock);
+ entity->last_user =current->group_leader;
+ if (list_empty(&entity->list))What happens if process A runs
drm_sched_entity_push_jobafter this code was executed from the (dying) process B and thereare still jobs in the queue (the
wait_eventterminated prematurely), the entity already removed from rq , but bool 'first' indrm_sched_entity_push_jobwill return false and so the entity will not be reinserted back into rq entity list and no wake up trigger will happen for process A pushing a new job.
Thought about this as well, but in this case I would say: Shit happens!
The dying process did some command submission and because of this the entity was killed as well when the process died and that is legitimate.
Quoted 19 lines
Another issue bellow -
Andrey
Quoted 11 lines · Christian König
I would rather like to avoid taking the lock in the hot path.
How about this:
/* For killed process disable any more IBs enqueue right now */
last_user=cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user ||last_user==current->group_leader) && (current->flags&PF_EXITING) && (current->exit_code== SIGKILL)) {grab_lock();
drm_sched_rq_remove_entity(entity->rq, entity);
if (READ_ONCE(&entity->last_user)!= NULL)
Quoted 3 lines
This condition is true because just exactly now process A did
drm_sched_entity_push_job->WRITE_ONCE(entity->last_user, current->group_leader); and so the line bellow executed and entity reinserted into rq. Let's say also that the entity job queue is empty now. For process A bool 'first' will be true and hence alsodrm_sched_entity_push_job->drm_sched_rq_add_entity(entity->rq, entity)will take place causing double insertion of the entity queue into rq list.
Calling drm_sched_rq_add_entity() is harmless, it is protected against double insertion.
But thinking more about it your idea of adding a killed or finished flag becomes more and more appealing to have a consistent handling here.
Christian.
Quoted 101 lines
Andrey
Quoted 97 lines
drm_sched_rq_add_entity(entity->rq, entity);
drop_lock();
}Christian.
Am 13.08.2018 um 18:43 schrieb Andrey Grodzovsky:
Quoted 89 lines
Attached.
If the general idea in the patch is OK I can think of a test (and maybe add to libdrm amdgpu tests) to actually simulate this scenario with 2 forked
concurrent processes working on same entity's job queue when one is dying while the other keeps pushing to the same queue. For now I only tested it
with normal boot and ruining multiple glxgears concurrently - which doesn't really test this code path since i think each of them works on it's own FD.
Andrey
Quoted 69 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 62 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalfrom it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 9 lines · Christian König
Am 14.08.2018 um 17:17 schrieb Andrey Grodzovsky:
Quoted 3 lines
I assume that this is the only code change and no locks are taken in
drm_sched_entity_push_job-What are you talking about? You surely now take looks in
drm_sched_entity_push_job():Quoted 3 lines
+ spin_lock(&entity->rq_lock);
+ entity->last_user =current->group_leader;
+ if (list_empty(&entity->list))
Oh, so your code in drm_sched_entity_flush still relies on my code in drm_sched_entity_push_job, OK.
Quoted 31 lines
Quoted 7 lines
What happens if process A runs
drm_sched_entity_push_jobafter this code was executed from the (dying) process B and thereare still jobs in the queue (the
wait_eventterminated prematurely), the entity already removed from rq , but bool 'first' indrm_sched_entity_push_jobwill return false and so the entity will not be reinserted back into rq entity list and no wake up trigger will happen for process A pushing a new job.
Thought about this as well, but in this case I would say: Shit happens!
The dying process did some command submission and because of this the entity was killed as well when the process died and that is legitimate.
Quoted 19 lines
Another issue bellow -
Andrey
Quoted 11 lines · Christian König
I would rather like to avoid taking the lock in the hot path.
How about this:
/* For killed process disable any more IBs enqueue right now */
last_user=cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user ||last_user==current->group_leader) && (current->flags&PF_EXITING) && (current->exit_code== SIGKILL)) {grab_lock();
drm_sched_rq_remove_entity(entity->rq, entity);
if (READ_ONCE(&entity->last_user)!= NULL)
Quoted 5 lines
Quoted 3 lines
This condition is true because just exactly now process A did
drm_sched_entity_push_job->WRITE_ONCE(entity->last_user, current->group_leader); and so the line bellow executed and entity reinserted into rq. Let's say also that the entity job queue is empty now. For process A bool 'first' will be true and hence alsodrm_sched_entity_push_job->drm_sched_rq_add_entity(entity->rq, entity)will take place causing double insertion of the entity queue into rq list.Calling
drm_sched_rq_add_entity()is harmless, it is protected against double insertion.
Missed that one, right...
Quoted 4 lines
But thinking more about it your idea of adding a killed or finished flag becomes more and more appealing to have a consistent handling here.
Christian.
So to be clear - you would like something like
Removing entity->last_user and adding a 'stopped' flag to drm_sched_entity to be set in drm_sched_entity_flush and in
drm_sched_entity_push_job check for 'if (entity->stopped)' and when true just return some error back to user instead of pushing the job ?
Andrey
Quoted 96 lines
Quoted 96 lines
Andrey
Quoted 92 lines
drm_sched_rq_add_entity(entity->rq, entity);
drop_lock();
}Christian.
Am 13.08.2018 um 18:43 schrieb Andrey Grodzovsky:
Quoted 85 lines
Attached.
If the general idea in the patch is OK I can think of a test (and maybe add to libdrm amdgpu tests) to actually simulate this scenario with 2 forked
concurrent processes working on same entity's job queue when one is dying while the other keeps pushing to the same queue. For now I only tested it
with normal boot and ruining multiple glxgears concurrently - which doesn't really test this code path since i think each of them works on it's own FD.
Andrey
Quoted 69 lines · Christian König
Crap, yeah indeed that needs to be protected by some lock.
Going to prepare a patch for that,
Christian.Am 09.08.2018 um 21:49 schrieb Andrey Grodzovsky:
Quoted 62 lines
Reviewed-by Andrey Grodzovsky <[email protected]>But I still have questions about
entity->last_user(didn't notice this before) -Looks to me there is a race condition with it's current usage, let's say process A was preempted after doing
drm_sched_entity_flush->cmpxchg(...)now process B working on same entity (forked) is inside
drm_sched_entity_push_job, he writes his PID toentity->last_userand alsoexecutes
drm_sched_rq_add_entity. Now process A runs again and executedrm_sched_rq_remove_entityinadvertently causing process B removalfrom it's scheduler rq.
Looks to me like instead we should lock together
entity->last_useraccesses and adds/removals of entity to the rq.Andrey
Quoted 41 lines · Nayan Deshmukh
I forgot about this since we started discussing possible scenarios of processes and threads.
In any case, this check is redundant. Acked-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
Nayan
On Mon, Aug 6, 2018 at 7:43 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Ping. Any objections to that? Christian. Am 03.08.2018 um 13:08 schrieb Christian König: > That is superflous now. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 5 ----- > 1 file changed, 5 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index 85908c7f913e..65078dd3c82c 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -590,11 +590,6 @@ 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(entity->rq->sched);
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel