Skip to content

Commit

Permalink
cpu_opv: handle CPU hotplug
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Paul Turner <pjt@google.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Andrew Hunter <ahh@google.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Andi Kleen <andi@firstfloor.org>
CC: Dave Watson <davejwatson@fb.com>
CC: Chris Lameter <cl@linux.com>
CC: Ingo Molnar <mingo@redhat.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Ben Maurer <bmaurer@fb.com>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Josh Triplett <josh@joshtriplett.org>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Russell King <linux@arm.linux.org.uk>
CC: Catalin Marinas <catalin.marinas@arm.com>
CC: Will Deacon <will.deacon@arm.com>
CC: Michael Kerrisk <mtk.manpages@gmail.com>
CC: Boqun Feng <boqun.feng@gmail.com>
CC: linux-api@vger.kernel.org
  • Loading branch information
compudj committed Oct 13, 2017
1 parent af41c6d commit b602821
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion kernel/cpu_opv.c
Expand Up @@ -26,6 +26,7 @@
#include <linux/syscalls.h>
#include <linux/cpu_opv.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <asm/ptrace.h>
#include <asm/byteorder.h>

Expand All @@ -34,6 +35,8 @@
#define TMP_BUFLEN 64
#define NR_PINNED_PAGES_ON_STACK 8

static DEFINE_MUTEX(cpu_opv_offline_lock);

/*
* The cpu_opv system call executes a vector of operations on behalf of
* user-space on a specific CPU with preemption disabled. It is inspired
Expand Down Expand Up @@ -947,7 +950,7 @@ static int do_cpu_opv(struct cpu_op *cpuop, int cpuopcnt, int cpu)
if (cpu != raw_smp_processor_id()) {
ret = push_task_to_cpu(current, cpu);
if (ret)
return ret;
goto check_online;
}
preempt_disable();
if (cpu != smp_processor_id()) {
Expand All @@ -958,6 +961,27 @@ static int do_cpu_opv(struct cpu_op *cpuop, int cpuopcnt, int cpu)
end:
preempt_enable();
return ret;

check_online:
if (!cpu_possible(cpu))
return -EINVAL;
get_online_cpus();
if (cpu_online(cpu)) {
ret = -EAGAIN;
goto put_online_cpus;
}
/*
* CPU is offline. Perform operation from the current CPU with
* cpu_online read lock held, preventing that CPU from coming online,
* and with mutex held, providing mutual exclusion against other
* CPUs also finding out about an offline CPU.
*/
mutex_lock(&cpu_opv_offline_lock);
ret = __do_cpu_opv(cpuop, cpuopcnt);
mutex_unlock(&cpu_opv_offline_lock);
put_online_cpus:
put_online_cpus();
return ret;
}

/*
Expand Down

0 comments on commit b602821

Please sign in to comment.