Skip to content

Commit 234b8ab

Browse files
willdeaconPeter Zijlstra
authored andcommitted
sched: Introduce dl_task_check_affinity() to check proposed affinity
In preparation for restricting the affinity of a task during execve() on arm64, introduce a new dl_task_check_affinity() helper function to give an indication as to whether the restricted mask is admissible for a deadline task. Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Daniel Bristot de Oliveira <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 07ec77a commit 234b8ab

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

include/linux/sched.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new
17091709
extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask);
17101710
extern int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src, int node);
17111711
extern void release_user_cpus_ptr(struct task_struct *p);
1712+
extern int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask);
17121713
extern void force_compatible_cpus_allowed_ptr(struct task_struct *p);
17131714
extern void relax_compatible_cpus_allowed_ptr(struct task_struct *p);
17141715
#else
@@ -1731,6 +1732,11 @@ static inline void release_user_cpus_ptr(struct task_struct *p)
17311732
{
17321733
WARN_ON(p->user_cpus_ptr);
17331734
}
1735+
1736+
static inline int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
1737+
{
1738+
return 0;
1739+
}
17341740
#endif
17351741

17361742
extern int yield_to(struct task_struct *p, bool preempt);

kernel/sched/core.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7756,6 +7756,32 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
77567756
return retval;
77577757
}
77587758

7759+
#ifdef CONFIG_SMP
7760+
int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
7761+
{
7762+
int ret = 0;
7763+
7764+
/*
7765+
* If the task isn't a deadline task or admission control is
7766+
* disabled then we don't care about affinity changes.
7767+
*/
7768+
if (!task_has_dl_policy(p) || !dl_bandwidth_enabled())
7769+
return 0;
7770+
7771+
/*
7772+
* Since bandwidth control happens on root_domain basis,
7773+
* if admission test is enabled, we only admit -deadline
7774+
* tasks allowed to run on all the CPUs in the task's
7775+
* root_domain.
7776+
*/
7777+
rcu_read_lock();
7778+
if (!cpumask_subset(task_rq(p)->rd->span, mask))
7779+
ret = -EBUSY;
7780+
rcu_read_unlock();
7781+
return ret;
7782+
}
7783+
#endif
7784+
77597785
static int
77607786
__sched_setaffinity(struct task_struct *p, const struct cpumask *mask)
77617787
{
@@ -7773,23 +7799,9 @@ __sched_setaffinity(struct task_struct *p, const struct cpumask *mask)
77737799
cpuset_cpus_allowed(p, cpus_allowed);
77747800
cpumask_and(new_mask, mask, cpus_allowed);
77757801

7776-
/*
7777-
* Since bandwidth control happens on root_domain basis,
7778-
* if admission test is enabled, we only admit -deadline
7779-
* tasks allowed to run on all the CPUs in the task's
7780-
* root_domain.
7781-
*/
7782-
#ifdef CONFIG_SMP
7783-
if (task_has_dl_policy(p) && dl_bandwidth_enabled()) {
7784-
rcu_read_lock();
7785-
if (!cpumask_subset(task_rq(p)->rd->span, new_mask)) {
7786-
retval = -EBUSY;
7787-
rcu_read_unlock();
7788-
goto out_free_new_mask;
7789-
}
7790-
rcu_read_unlock();
7791-
}
7792-
#endif
7802+
retval = dl_task_check_affinity(p, new_mask);
7803+
if (retval)
7804+
goto out_free_new_mask;
77937805
again:
77947806
retval = __set_cpus_allowed_ptr(p, new_mask, SCA_CHECK | SCA_USER);
77957807
if (retval)

0 commit comments

Comments
 (0)