lkml.org 
[lkml]   [2022]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 1/3] sched: Use user_cpus_ptr for saving user provided cpumask in sched_setaffinity()
On Tue, Aug 16, 2022 at 03:27:32PM -0400, Waiman Long wrote:
> @@ -8079,10 +8056,11 @@ int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
> #endif
>
> static int
> -__sched_setaffinity(struct task_struct *p, const struct cpumask *mask)
> +__sched_setaffinity(struct task_struct *p, const struct cpumask *mask, bool save_mask)
> {
> int retval;
> cpumask_var_t cpus_allowed, new_mask;
> + struct cpumask *user_mask = NULL;
>
> if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL))
> return -ENOMEM;

Please move that retval down so the variable declarations are properly
ordered again.

> @@ -8098,8 +8076,33 @@ __sched_setaffinity(struct task_struct *p, const struct cpumask *mask)
> retval = dl_task_check_affinity(p, new_mask);
> if (retval)
> goto out_free_new_mask;
> +
> + /*
> + * Save the user requested mask into user_cpus_ptr if save_mask set.
> + * pi_lock is used for protecting user_cpus_ptr.
> + */
> + if (save_mask && !p->user_cpus_ptr) {
> + user_mask = kmalloc(cpumask_size(), GFP_KERNEL);
> +
> + if (!user_mask) {
> + retval = -ENOMEM;
> + goto out_free_new_mask;
> + }
> + }
> + if (save_mask) {
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&p->pi_lock, flags);
> + if (!p->user_cpus_ptr) {
> + p->user_cpus_ptr = user_mask;
> + user_mask = NULL;
> + }
> +
> + cpumask_copy(p->user_cpus_ptr, mask);
> + raw_spin_unlock_irqrestore(&p->pi_lock, flags);
> + }

How about:

if (save_mask) {
if (!p->user_cpus_ptr) {
...
}
...
}

?

\
 
 \ /
  Last update: 2022-08-17 10:48    [W:0.090 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site