2007-07-17 18:37:06 -07:00
|
|
|
#include <linux/smp.h>
|
2017-06-02 17:06:02 -07:00
|
|
|
#include <linux/cpu.h>
|
2017-03-14 10:35:46 -07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/percpu.h>
|
2007-07-17 18:37:06 -07:00
|
|
|
|
|
|
|
#include <xen/events.h>
|
|
|
|
|
2011-09-01 06:48:27 -07:00
|
|
|
#include <xen/hvc-console.h>
|
2007-07-17 18:37:06 -07:00
|
|
|
#include "xen-ops.h"
|
2014-09-10 16:36:06 -07:00
|
|
|
#include "smp.h"
|
2007-07-17 18:37:06 -07:00
|
|
|
|
2013-06-04 13:42:29 -07:00
|
|
|
static DEFINE_PER_CPU(struct xen_common_irq, xen_resched_irq) = { .irq = -1 };
|
|
|
|
static DEFINE_PER_CPU(struct xen_common_irq, xen_callfunc_irq) = { .irq = -1 };
|
|
|
|
static DEFINE_PER_CPU(struct xen_common_irq, xen_callfuncsingle_irq) = { .irq = -1 };
|
2013-06-04 13:37:44 -07:00
|
|
|
static DEFINE_PER_CPU(struct xen_common_irq, xen_debug_irq) = { .irq = -1 };
|
2007-07-17 18:37:06 -07:00
|
|
|
|
|
|
|
static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id);
|
2008-06-26 02:21:54 -07:00
|
|
|
static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id);
|
2007-07-17 18:37:06 -07:00
|
|
|
|
|
|
|
/*
|
2011-04-05 08:23:39 -07:00
|
|
|
* Reschedule call back.
|
2007-07-17 18:37:06 -07:00
|
|
|
*/
|
|
|
|
static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
2009-01-18 08:38:57 -07:00
|
|
|
inc_irq_stat(irq_resched_count);
|
2011-04-05 08:23:39 -07:00
|
|
|
scheduler_ipi();
|
2008-05-26 15:31:16 -07:00
|
|
|
|
2007-07-17 18:37:06 -07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2016-08-03 10:22:27 -07:00
|
|
|
void xen_smp_intr_free(unsigned int cpu)
|
2013-06-04 13:31:34 -07:00
|
|
|
{
|
2013-06-04 13:42:29 -07:00
|
|
|
if (per_cpu(xen_resched_irq, cpu).irq >= 0) {
|
2013-06-04 13:37:44 -07:00
|
|
|
unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu).irq, NULL);
|
2013-06-04 13:42:29 -07:00
|
|
|
per_cpu(xen_resched_irq, cpu).irq = -1;
|
2013-06-04 13:47:17 -07:00
|
|
|
kfree(per_cpu(xen_resched_irq, cpu).name);
|
|
|
|
per_cpu(xen_resched_irq, cpu).name = NULL;
|
2013-06-04 13:42:29 -07:00
|
|
|
}
|
|
|
|
if (per_cpu(xen_callfunc_irq, cpu).irq >= 0) {
|
2013-06-04 13:37:44 -07:00
|
|
|
unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu).irq, NULL);
|
2013-06-04 13:42:29 -07:00
|
|
|
per_cpu(xen_callfunc_irq, cpu).irq = -1;
|
2013-06-04 13:47:17 -07:00
|
|
|
kfree(per_cpu(xen_callfunc_irq, cpu).name);
|
|
|
|
per_cpu(xen_callfunc_irq, cpu).name = NULL;
|
2013-06-04 13:42:29 -07:00
|
|
|
}
|
|
|
|
if (per_cpu(xen_debug_irq, cpu).irq >= 0) {
|
2013-06-04 13:37:44 -07:00
|
|
|
unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu).irq, NULL);
|
2013-06-04 13:42:29 -07:00
|
|
|
per_cpu(xen_debug_irq, cpu).irq = -1;
|
2013-06-04 13:47:17 -07:00
|
|
|
kfree(per_cpu(xen_debug_irq, cpu).name);
|
|
|
|
per_cpu(xen_debug_irq, cpu).name = NULL;
|
2013-06-04 13:42:29 -07:00
|
|
|
}
|
|
|
|
if (per_cpu(xen_callfuncsingle_irq, cpu).irq >= 0) {
|
2013-06-04 13:37:44 -07:00
|
|
|
unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu).irq,
|
2013-06-04 13:31:34 -07:00
|
|
|
NULL);
|
2013-06-04 13:42:29 -07:00
|
|
|
per_cpu(xen_callfuncsingle_irq, cpu).irq = -1;
|
2013-06-04 13:47:17 -07:00
|
|
|
kfree(per_cpu(xen_callfuncsingle_irq, cpu).name);
|
|
|
|
per_cpu(xen_callfuncsingle_irq, cpu).name = NULL;
|
2013-06-04 13:42:29 -07:00
|
|
|
}
|
2017-03-14 10:35:42 -07:00
|
|
|
}
|
2013-06-04 13:31:34 -07:00
|
|
|
|
2016-08-03 10:22:27 -07:00
|
|
|
int xen_smp_intr_init(unsigned int cpu)
|
2007-07-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
int rc;
|
2017-03-14 10:35:42 -07:00
|
|
|
char *resched_name, *callfunc_name, *debug_name;
|
2007-07-17 18:37:06 -07:00
|
|
|
|
|
|
|
resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
|
|
|
|
rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
|
|
|
|
cpu,
|
|
|
|
xen_reschedule_interrupt,
|
2013-09-06 23:46:49 -07:00
|
|
|
IRQF_PERCPU|IRQF_NOBALANCING,
|
2007-07-17 18:37:06 -07:00
|
|
|
resched_name,
|
|
|
|
NULL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2013-06-04 13:37:44 -07:00
|
|
|
per_cpu(xen_resched_irq, cpu).irq = rc;
|
2013-06-04 13:47:17 -07:00
|
|
|
per_cpu(xen_resched_irq, cpu).name = resched_name;
|
2007-07-17 18:37:06 -07:00
|
|
|
|
|
|
|
callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
|
|
|
|
rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
|
|
|
|
cpu,
|
|
|
|
xen_call_function_interrupt,
|
2013-09-06 23:46:49 -07:00
|
|
|
IRQF_PERCPU|IRQF_NOBALANCING,
|
2007-07-17 18:37:06 -07:00
|
|
|
callfunc_name,
|
|
|
|
NULL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2013-06-04 13:37:44 -07:00
|
|
|
per_cpu(xen_callfunc_irq, cpu).irq = rc;
|
2013-06-04 13:47:17 -07:00
|
|
|
per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
|
2007-07-17 18:37:06 -07:00
|
|
|
|
2008-03-17 16:37:18 -07:00
|
|
|
debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
|
|
|
|
rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt,
|
2013-09-06 23:46:49 -07:00
|
|
|
IRQF_PERCPU | IRQF_NOBALANCING,
|
2008-03-17 16:37:18 -07:00
|
|
|
debug_name, NULL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2013-06-04 13:37:44 -07:00
|
|
|
per_cpu(xen_debug_irq, cpu).irq = rc;
|
2013-06-04 13:47:17 -07:00
|
|
|
per_cpu(xen_debug_irq, cpu).name = debug_name;
|
2008-03-17 16:37:18 -07:00
|
|
|
|
2008-06-26 02:21:54 -07:00
|
|
|
callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
|
|
|
|
rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
|
|
|
|
cpu,
|
|
|
|
xen_call_function_single_interrupt,
|
2013-09-06 23:46:49 -07:00
|
|
|
IRQF_PERCPU|IRQF_NOBALANCING,
|
2008-06-26 02:21:54 -07:00
|
|
|
callfunc_name,
|
|
|
|
NULL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2013-06-04 13:37:44 -07:00
|
|
|
per_cpu(xen_callfuncsingle_irq, cpu).irq = rc;
|
2013-06-04 13:47:17 -07:00
|
|
|
per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
|
2008-06-26 02:21:54 -07:00
|
|
|
|
2017-03-14 10:35:42 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
xen_smp_intr_free(cpu);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-06-02 17:06:02 -07:00
|
|
|
void __init xen_smp_cpus_done(unsigned int max_cpus)
|
|
|
|
{
|
|
|
|
int cpu, rc, count = 0;
|
|
|
|
|
|
|
|
if (xen_hvm_domain())
|
|
|
|
native_smp_cpus_done(max_cpus);
|
|
|
|
|
|
|
|
if (xen_have_vcpu_info_placement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
if (xen_vcpu_nr(cpu) < MAX_VIRT_CPUS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = cpu_down(cpu);
|
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
/*
|
|
|
|
* Reset vcpu_info so this cpu cannot be onlined again.
|
|
|
|
*/
|
|
|
|
xen_vcpu_info_reset(cpu);
|
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
pr_warn("%s: failed to bring CPU %d down, error %d\n",
|
|
|
|
__func__, cpu, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WARN(count, "%s: brought %d CPUs offline\n", __func__, count);
|
|
|
|
}
|
|
|
|
|
2017-03-14 10:35:45 -07:00
|
|
|
void xen_smp_send_reschedule(int cpu)
|
2007-07-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
xen_send_IPI_one(cpu, XEN_RESCHEDULE_VECTOR);
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:11:04 -07:00
|
|
|
static void __xen_send_IPI_mask(const struct cpumask *mask,
|
|
|
|
int vector)
|
2007-07-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
unsigned cpu;
|
|
|
|
|
2008-12-16 18:33:59 -07:00
|
|
|
for_each_cpu_and(cpu, mask, cpu_online_mask)
|
2007-07-17 18:37:06 -07:00
|
|
|
xen_send_IPI_one(cpu, vector);
|
|
|
|
}
|
|
|
|
|
2017-03-14 10:35:45 -07:00
|
|
|
void xen_smp_send_call_function_ipi(const struct cpumask *mask)
|
2008-06-26 02:21:54 -07:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2012-04-20 09:11:04 -07:00
|
|
|
__xen_send_IPI_mask(mask, XEN_CALL_FUNCTION_VECTOR);
|
2008-06-26 02:21:54 -07:00
|
|
|
|
|
|
|
/* Make sure other vcpus get a chance to run if they need to. */
|
2008-12-16 18:33:59 -07:00
|
|
|
for_each_cpu(cpu, mask) {
|
2008-06-26 02:21:54 -07:00
|
|
|
if (xen_vcpu_stolen(cpu)) {
|
2009-03-05 12:13:57 -07:00
|
|
|
HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
|
2008-06-26 02:21:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 10:35:45 -07:00
|
|
|
void xen_smp_send_call_function_single_ipi(int cpu)
|
2008-06-26 02:21:54 -07:00
|
|
|
{
|
2012-04-20 09:11:04 -07:00
|
|
|
__xen_send_IPI_mask(cpumask_of(cpu),
|
2008-12-16 18:33:52 -07:00
|
|
|
XEN_CALL_FUNCTION_SINGLE_VECTOR);
|
2008-06-26 02:21:54 -07:00
|
|
|
}
|
|
|
|
|
2012-04-20 09:11:04 -07:00
|
|
|
static inline int xen_map_vector(int vector)
|
|
|
|
{
|
|
|
|
int xen_vector;
|
|
|
|
|
|
|
|
switch (vector) {
|
|
|
|
case RESCHEDULE_VECTOR:
|
|
|
|
xen_vector = XEN_RESCHEDULE_VECTOR;
|
|
|
|
break;
|
|
|
|
case CALL_FUNCTION_VECTOR:
|
|
|
|
xen_vector = XEN_CALL_FUNCTION_VECTOR;
|
|
|
|
break;
|
|
|
|
case CALL_FUNCTION_SINGLE_VECTOR:
|
|
|
|
xen_vector = XEN_CALL_FUNCTION_SINGLE_VECTOR;
|
|
|
|
break;
|
2012-04-20 09:11:05 -07:00
|
|
|
case IRQ_WORK_VECTOR:
|
|
|
|
xen_vector = XEN_IRQ_WORK_VECTOR;
|
|
|
|
break;
|
2013-07-19 08:51:31 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
case NMI_VECTOR:
|
|
|
|
case APIC_DM_NMI: /* Some use that instead of NMI_VECTOR */
|
|
|
|
xen_vector = XEN_NMI_VECTOR;
|
|
|
|
break;
|
|
|
|
#endif
|
2012-04-20 09:11:04 -07:00
|
|
|
default:
|
|
|
|
xen_vector = -1;
|
|
|
|
printk(KERN_ERR "xen: vector 0x%x is not implemented\n",
|
|
|
|
vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
return xen_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_send_IPI_mask(const struct cpumask *mask,
|
|
|
|
int vector)
|
|
|
|
{
|
|
|
|
int xen_vector = xen_map_vector(vector);
|
|
|
|
|
|
|
|
if (xen_vector >= 0)
|
|
|
|
__xen_send_IPI_mask(mask, xen_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_send_IPI_all(int vector)
|
|
|
|
{
|
|
|
|
int xen_vector = xen_map_vector(vector);
|
|
|
|
|
|
|
|
if (xen_vector >= 0)
|
|
|
|
__xen_send_IPI_mask(cpu_online_mask, xen_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_send_IPI_self(int vector)
|
|
|
|
{
|
|
|
|
int xen_vector = xen_map_vector(vector);
|
|
|
|
|
|
|
|
if (xen_vector >= 0)
|
|
|
|
xen_send_IPI_one(smp_processor_id(), xen_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
|
|
|
|
int vector)
|
|
|
|
{
|
|
|
|
unsigned cpu;
|
|
|
|
unsigned int this_cpu = smp_processor_id();
|
2013-05-08 07:37:35 -07:00
|
|
|
int xen_vector = xen_map_vector(vector);
|
2012-04-20 09:11:04 -07:00
|
|
|
|
2013-05-08 07:37:35 -07:00
|
|
|
if (!(num_online_cpus() > 1) || (xen_vector < 0))
|
2012-04-20 09:11:04 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_cpu_and(cpu, mask, cpu_online_mask) {
|
|
|
|
if (this_cpu == cpu)
|
|
|
|
continue;
|
|
|
|
|
2013-05-08 07:37:35 -07:00
|
|
|
xen_send_IPI_one(cpu, xen_vector);
|
2012-04-20 09:11:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_send_IPI_allbutself(int vector)
|
|
|
|
{
|
2013-05-08 07:37:35 -07:00
|
|
|
xen_send_IPI_mask_allbutself(cpu_online_mask, vector);
|
2012-04-20 09:11:04 -07:00
|
|
|
}
|
|
|
|
|
2007-07-17 18:37:06 -07:00
|
|
|
static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
irq_enter();
|
2008-06-26 02:21:54 -07:00
|
|
|
generic_smp_call_function_interrupt();
|
2009-01-18 08:38:57 -07:00
|
|
|
inc_irq_stat(irq_call_count);
|
2007-07-17 18:37:06 -07:00
|
|
|
irq_exit();
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-06-26 02:21:54 -07:00
|
|
|
static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id)
|
2007-07-17 18:37:06 -07:00
|
|
|
{
|
2008-06-26 02:21:54 -07:00
|
|
|
irq_enter();
|
|
|
|
generic_smp_call_function_single_interrupt();
|
2009-01-18 08:38:57 -07:00
|
|
|
inc_irq_stat(irq_call_count);
|
2008-06-26 02:21:54 -07:00
|
|
|
irq_exit();
|
2007-07-17 18:37:06 -07:00
|
|
|
|
2008-06-26 02:21:54 -07:00
|
|
|
return IRQ_HANDLED;
|
2007-07-17 18:37:06 -07:00
|
|
|
}
|