Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

scx: cgroup: Fix mismatch between ops.cgroup_prep_move() and ops.cgroup_move() invocations #165

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,17 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)

cgroup_taskset_for_each(p, css, tset) {
struct cgroup *from = tg_cgrp(task_group(p));
struct cgroup *to = tg_cgrp(css_tg(css));

WARN_ON_ONCE(p->scx.cgrp_moving_from);

/*
* sched_move_task() omits identity migrations. Let's match the
* behavior so that ops.cgroup_prep_move() and ops.cgroup_move()
* always match one-to-one.
*/
if (from == to)
continue;

if (SCX_HAS_OP(cgroup_prep_move)) {
ret = SCX_CALL_OP_RET(SCX_KF_SLEEPABLE, cgroup_prep_move,
Expand All @@ -2721,17 +2732,14 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)
goto err;
}

WARN_ON_ONCE(p->scx.cgrp_moving_from);
p->scx.cgrp_moving_from = from;
}

return 0;

err:
cgroup_taskset_for_each(p, css, tset) {
if (!p->scx.cgrp_moving_from)
break;
if (SCX_HAS_OP(cgroup_cancel_move))
if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from)
SCX_CALL_OP(SCX_KF_SLEEPABLE, cgroup_cancel_move, p,
p->scx.cgrp_moving_from, css->cgroup);
p->scx.cgrp_moving_from = NULL;
Expand Down Expand Up @@ -2759,12 +2767,13 @@ void scx_move_task(struct task_struct *p)
if (!scx_enabled())
return;

if (SCX_HAS_OP(cgroup_move)) {
if (WARN_ON_ONCE(!p->scx.cgrp_moving_from))
return;
/*
* @p must have ops.cgroup_prep_move() called on it and thus
* cgrp_moving_from set.
*/
if (SCX_HAS_OP(cgroup_move) && !WARN_ON_ONCE(!p->scx.cgrp_moving_from))
SCX_CALL_OP_TASK(SCX_KF_UNLOCKED, cgroup_move, p,
p->scx.cgrp_moving_from, tg_cgrp(task_group(p)));
}
p->scx.cgrp_moving_from = NULL;
}

Expand All @@ -2782,11 +2791,9 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset)
goto out_unlock;

cgroup_taskset_for_each(p, css, tset) {
if (SCX_HAS_OP(cgroup_cancel_move)) {
WARN_ON_ONCE(!p->scx.cgrp_moving_from);
if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from)
SCX_CALL_OP(SCX_KF_SLEEPABLE, cgroup_cancel_move, p,
p->scx.cgrp_moving_from, css->cgroup);
}
p->scx.cgrp_moving_from = NULL;
}
out_unlock:
Expand Down