sched_ext: Call ops.sub_attach() only while the cgroup is online
Subsystems (2)
Tejun Heo
reviewerPATCH 1/1 sched_ext: Call ops.sub_attach() only while the cgroup is online
The parent's ops.sub_attach() runs before the enable work checks that the cgroup is still online, so the parent can get an attach for a cgroup whose rmdir already returned. That complicates parents where cgroup cleanup and sub-scheduler attach race.
Check CSS_ONLINE and call ops.sub_attach() under cgroup_lock(), so that the parent sees an attach only for a cgroup that is online.
--- kernel/sched/ext/internal.h | 4 ++++ kernel/sched/ext/sub.c | 13 +++++++++++++ 2 files changed, 17 insertions(+)
kernel/sched/ext/internal.h +4 -0
@@ -869,6 +869,10 @@ struct sched_ext_ops {* @sub_attach: Attach a sub-scheduler * @args: argument container, see the struct definition * +* The sub-scheduler's cgroup is online for the whole call. If it goes +* offline after the sub-scheduler is accepted, ops.sub_detach() +* follows. +* * Return 0 to accept the sub-scheduler. -errno to reject. */ s32 (*sub_attach)(struct scx_sub_attach_args *args);
kernel/sched/ext/sub.c +13 -0
@@ -2340,8 +2340,21 @@ void scx_sub_enable_workfn(struct kthread_work *work) .cgroup_path = sch->cgrp_path, }; +/* +* The cgroup stays online across ops.sub_attach(), so the parent never +* sees an attach for a cgroup that rmdir already removed. +*/ +cgroup_lock (); +if (!(cgrp->self.flags &CSS_ONLINE )) { +cgroup_unlock (); +scx_error (sch,"cgroup is not online" ); + ret = -ENODEV ; + goto err_disable; + } ret =SCX_CALL_OP_RET (parent, sub_attach,NULL , &sub_attach_args); +cgroup_unlock (); +if (ret) { ret =scx_ops_sanitize_err (sch,"sub_attach" , ret);scx_error (sch,"parent rejected (%d)" , ret);
Signature · 1 line
2.56.0
Quoted 10 lines · Tejun Heo
The parent's
ops.sub_attach()runs before the enable work checks that the cgroup is still online, so the parent can get an attach for a cgroup whose rmdir already returned. That complicates parents where cgroup cleanup and sub-scheduler attach race.Check
CSS_ONLINEand callops.sub_attach()undercgroup_lock(), so that the parent sees an attach only for a cgroup that is online.Fixes ebeca1f930ea ("sched_ext: Introduce cgroup sub-sched support")Signed-off-by Tejun Heo <[email protected]>
Thanks,
-Andrea
Quoted 49 lines
--- kernel/sched/ext/internal.h | 4 ++++ kernel/sched/ext/sub.c | 13 +++++++++++++ 2 files changed, 17 insertions(+)kernel/sched/ext/internal.h +4
-0@@ -869,6 +869,10 @@ struct sched_ext_ops {* @sub_attach: Attach a sub-scheduler * @args: argument container, see the struct definition * +* The sub-scheduler's cgroup is online for the whole call. If it goes +* offline after the sub-scheduler is accepted, ops.sub_detach() +* follows. +* * Return 0 to accept the sub-scheduler. -errno to reject. */ s32 (*sub_attach)(struct scx_sub_attach_args *args);kernel/sched/ext/sub.c +13
-0@@ -2340,8 +2340,21 @@ void scx_sub_enable_workfn(struct kthread_work *work) .cgroup_path = sch->cgrp_path, }; +/* +* The cgroup stays online across ops.sub_attach(), so the parent never +* sees an attach for a cgroup that rmdir already removed. +*/ +cgroup_lock (); +if (!(cgrp->self.flags &CSS_ONLINE )) { +cgroup_unlock (); +scx_error (sch,"cgroup is not online" ); + ret = -ENODEV ; + goto err_disable; + } ret =SCX_CALL_OP_RET (parent, sub_attach,NULL , &sub_attach_args); +cgroup_unlock (); +if (ret) { ret =scx_ops_sanitize_err (sch,"sub_attach" , ret);scx_error (sch,"parent rejected (%d)" , ret);Signature · 1 line
2.56.0
Applied to sched_ext/for-7.4-fixes with the following tags added:
Thanks.
--
tejun