Skip to content

Commit

Permalink
kernel/hotplug: restore original cpu mask oncpu/down
Browse files Browse the repository at this point in the history
If a task which is allowed to run only on CPU X puts CPU Y down then it
will be allowed on all CPUs but the on CPU Y after it comes back from
kernel. This patch ensures that we don't lose the initial setting unless
the CPU the task is running is going down.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  • Loading branch information
Sebastian Andrzej Siewior authored and jnettlet committed Sep 4, 2018
1 parent ba05997 commit 6aa07da
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
bool hasdied = false;
int mycpu;
cpumask_var_t cpumask;
cpumask_var_t cpumask_org;

if (num_online_cpus() == 1)
return -EBUSY;
Expand All @@ -1291,6 +1292,12 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
/* Move the downtaker off the unplug cpu */
if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
return -ENOMEM;
if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL)) {
free_cpumask_var(cpumask);
return -ENOMEM;
}

cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
set_cpus_allowed_ptr(current, cpumask);
free_cpumask_var(cpumask);
Expand All @@ -1299,7 +1306,8 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
if (mycpu == cpu) {
printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
migrate_enable();
return -EBUSY;
ret = -EBUSY;
goto restore_cpus;
}

cpu_hotplug_begin();
Expand Down Expand Up @@ -1353,6 +1361,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
/* This post dead nonsense must die */
if (!ret && hasdied)
cpu_notify_nofail(CPU_POST_DEAD, cpu);
restore_cpus:
set_cpus_allowed_ptr(current, cpumask_org);
free_cpumask_var(cpumask_org);
return ret;
}

Expand Down

0 comments on commit 6aa07da

Please sign in to comment.