drm/sched: avoid killing parent entity on child SIGKILL v2
Subsystems (3)
Christian König
reviewerPATCH 1/1 drm/sched: avoid killing parent entity on child SIGKILL v2
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so when an process accidentially leaked its file descriptor to a child and that child got killed we killed the parents entities.
Avoid that and instead initialize the entities last user on entity creation.
--- drivers/gpu/drm/scheduler/sched_entity.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -1
@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader;/* * It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it
@@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For a killed process disallow further enqueueing of jobs. */ last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); -if ((!last_user || last_user == current->group_leader) && +if (last_user == current->group_leader && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL ))drm_sched_entity_kill (entity);
Signature · 1 line
2.43.0
Quoted 7 lines · Christian König
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so
initially
Quoted 1 line
when an process accidentially leaked its file descriptor to a child and
accidently
Quoted 1 line
that child got killed we killed the parents entities.
that child got killed, we killed the parent's entities.
Quoted 7 lines
Avoid that and instead initialize the entities last user on entity creation.
Signed-off-by David Rosca <[email protected]>Signed-off-by Christian König <[email protected]>
With the above fixes,
Quoted 28 lines
--- drivers/gpu/drm/scheduler/sched_entity.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader;/* * It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it @@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For a killed process disallow further enqueueing of jobs. */ last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); -if ((!last_user || last_user == current->group_leader) && +if (last_user == current->group_leader && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL ))drm_sched_entity_kill (entity); --2.43.0
Quoted 6 lines · Christian König
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so
s/tracked/track
Quoted 1 line
when an process accidentially leaked its file descriptor to a child and
s/an/a
Quoted 1 line
that child got killed we killed the parents entities.
s/parents/parent's
Quoted 27 lines
Avoid that and instead initialize the entities last user on entity creation.
Signed-off-by David Rosca <[email protected]>Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-0@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader; /** It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it @@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
/* For a killed process disallow further enqueueing of jobs. */last_user=cmpxchg(&entity->last_user, current->group_leader, NULL);
drivers/gpu/drm/scheduler/sched_entity.c long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) · line 306
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +1
-1- if ((!last_user || last_user == current->group_leader) && + if (last_user == current->group_leader &&
It's not super clear from the commit message why the NULL check is being removed. Previously entities could have been killed if there was no last user. That's not desired anymore. Why?
P.
Quoted 3 lines
(
current->flags&PF_EXITING) && (current->exit_code== SIGKILL))drm_sched_entity_kill(entity);
Quoted 43 lines · Philipp Stanner
Quoted 6 lines · Christian König
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so
s/tracked/track
Quoted 1 line
when an process accidentially leaked its file descriptor to a child and
s/an/a
Quoted 1 line
that child got killed we killed the parents entities.
s/parents/parent's
Quoted 25 lines
Avoid that and instead initialize the entities last user on entity creation.
Signed-off-by David Rosca <[email protected]>Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-0@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader; /** It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it @@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_entity.c long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) · line 306
Quoted 4 lines
/* For a killed process disallow further enqueueing of jobs. */
last_user=cmpxchg(&entity->last_user, current->group_leader, NULL);drivers/gpu/drm/scheduler/sched_entity.c +1
-1- if ((!last_user || last_user == current->group_leader) && + if (last_user == current->group_leader &&It's not super clear from the commit message why the NULL check is being removed. Previously entities could have been killed if there was no last user. That's not desired anymore. Why?
The reason that we don't need the NULL check any more is because we now don't encounter the NULL pointer any more.
In other words the pointer is now always initialized, even when the entity was never used.
I've added another sentence to the commit message, but I'm not sure how to better describe that. Is that sufficient? If not suggestions welcome.
Thanks,
Christian.
Quoted 8 lines
P.
Quoted 3 lines
(
current->flags&PF_EXITING) && (current->exit_code== SIGKILL))drm_sched_entity_kill(entity);
Quoted 55 lines · Christian König
Quoted 43 lines · Philipp Stanner
Quoted 6 lines · Christian König
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so
s/tracked/track
Quoted 1 line
when an process accidentially leaked its file descriptor to a child and
s/an/a
Quoted 1 line
that child got killed we killed the parents entities.
s/parents/parent's
Quoted 25 lines
Avoid that and instead initialize the entities last user on entity creation.
Signed-off-by David Rosca <[email protected]>Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-0@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader; /** It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it @@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)Quoted 8 lines
drivers/gpu/drm/scheduler/sched_entity.c long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) · line 306
Quoted 4 lines
/* For a killed process disallow further enqueueing of jobs. */
last_user=cmpxchg(&entity->last_user, current->group_leader, NULL);drivers/gpu/drm/scheduler/sched_entity.c +1
-1- if ((!last_user || last_user == current->group_leader) && + if (last_user == current->group_leader &&It's not super clear from the commit message why the NULL check is being removed. Previously entities could have been killed if there was no last user. That's not desired anymore. Why?
Quoted 5 lines
The reason that we don't need the NULL check any more is because we now don't encounter the NULL pointer any more.
In other words the pointer is now always initialized, even when the entity was never used.
I've added another sentence to the commit message, but I'm not sure how to better describe that. Is that sufficient? If not suggestions welcome.
Sounds good enough, thank you.
P.
Quoted 14 lines
Thanks,
Christian.Quoted 8 lines
P.
Quoted 3 lines
(
current->flags&PF_EXITING) && (current->exit_code== SIGKILL))drm_sched_entity_kill(entity);
Quoted 9 lines · Christian König
From: David Rosca <[email protected]>
The DRM scheduler tracks who last uses an entity and when that process is killed blocks all further submissions to that entity.
The problem is that we didn't tracked who initialy created an entity, so when an process accidentially leaked its file descriptor to a child and that child got killed we killed the parents entities.
Quoted 6 lines
Avoid that and instead initialize the entities last user on entity creation.
Signed-off-by David Rosca <[email protected]>Signed-off-by Christian König <[email protected]>
Up to back there perhaps?
Quoted 17 lines
--- drivers/gpu/drm/scheduler/sched_entity.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-0@@ -70,6 +70,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->last_user = current->group_leader;/* * It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it
drivers/gpu/drm/scheduler/sched_entity.c long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) · line 309
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -302,7 +303,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For a killed process disallow further enqueueing of jobs. */ last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); -if ((!last_user || last_user == current->group_leader) && +if (last_user == current->group_leader && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL ))drm_sched_entity_kill (entity);
Hm, but is it not just a band aid for a specific usage pattern?
Ie. the exiting process can still kill the shared entity, just needs to be the last one using it. So for an use case where two threads might be legitimately sharing it will be random chance whether one exiting thread kills the shared entity or not.
Not saying I know of such patterns, but I am also not sure at the scheduler level it should be precluded. Neither that defining sensible and compatible semantics is easy at this point.
So if what I write is correct perhaps just explain it in the commit message. Or even a code comment.
Regards,
Tvrtko