Commit ad5475f9 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by David Vrabel

x86/xen: use xen_vcpu_id mapping for HYPERVISOR_vcpu_op

HYPERVISOR_vcpu_op() passes Linux's idea of vCPU id as a parameter
while Xen's idea is expected. In some cases these ideas diverge so we
need to do remapping.

Convert all callers of HYPERVISOR_vcpu_op() to use xen_vcpu_nr().

Leave xen_fill_possible_map() and xen_filter_cpu_maps() intact as
they're only being called by PV guests before perpu areas are
initialized. While the issue could be solved by switching to
early_percpu for xen_vcpu_id I think it's not worth it: PV guests will
probably never get to the point where their idea of vCPU id diverges
from Xen's.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
parent 88e957d6
...@@ -177,7 +177,8 @@ static void xen_percpu_init(void) ...@@ -177,7 +177,8 @@ static void xen_percpu_init(void)
info.mfn = virt_to_gfn(vcpup); info.mfn = virt_to_gfn(vcpup);
info.offset = xen_offset_in_page(vcpup); info.offset = xen_offset_in_page(vcpup);
err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, cpu, &info); err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, xen_vcpu_nr(cpu),
&info);
BUG_ON(err); BUG_ON(err);
per_cpu(xen_vcpu, cpu) = vcpup; per_cpu(xen_vcpu, cpu) = vcpup;
......
...@@ -228,7 +228,8 @@ static void xen_vcpu_setup(int cpu) ...@@ -228,7 +228,8 @@ static void xen_vcpu_setup(int cpu)
hypervisor has no unregister variant and this hypercall does not hypervisor has no unregister variant and this hypercall does not
allow to over-write info.mfn and info.offset. allow to over-write info.mfn and info.offset.
*/ */
err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, cpu, &info); err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, xen_vcpu_nr(cpu),
&info);
if (err) { if (err) {
printk(KERN_DEBUG "register_vcpu_info failed: err=%d\n", err); printk(KERN_DEBUG "register_vcpu_info failed: err=%d\n", err);
...@@ -252,10 +253,11 @@ void xen_vcpu_restore(void) ...@@ -252,10 +253,11 @@ void xen_vcpu_restore(void)
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
bool other_cpu = (cpu != smp_processor_id()); bool other_cpu = (cpu != smp_processor_id());
bool is_up = HYPERVISOR_vcpu_op(VCPUOP_is_up, cpu, NULL); bool is_up = HYPERVISOR_vcpu_op(VCPUOP_is_up, xen_vcpu_nr(cpu),
NULL);
if (other_cpu && is_up && if (other_cpu && is_up &&
HYPERVISOR_vcpu_op(VCPUOP_down, cpu, NULL)) HYPERVISOR_vcpu_op(VCPUOP_down, xen_vcpu_nr(cpu), NULL))
BUG(); BUG();
xen_setup_runstate_info(cpu); xen_setup_runstate_info(cpu);
...@@ -264,7 +266,7 @@ void xen_vcpu_restore(void) ...@@ -264,7 +266,7 @@ void xen_vcpu_restore(void)
xen_vcpu_setup(cpu); xen_vcpu_setup(cpu);
if (other_cpu && is_up && if (other_cpu && is_up &&
HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL)) HYPERVISOR_vcpu_op(VCPUOP_up, xen_vcpu_nr(cpu), NULL))
BUG(); BUG();
} }
} }
......
...@@ -109,7 +109,8 @@ static void xen_safe_halt(void) ...@@ -109,7 +109,8 @@ static void xen_safe_halt(void)
static void xen_halt(void) static void xen_halt(void)
{ {
if (irqs_disabled()) if (irqs_disabled())
HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL); HYPERVISOR_vcpu_op(VCPUOP_down,
xen_vcpu_nr(smp_processor_id()), NULL);
else else
xen_safe_halt(); xen_safe_halt();
} }
......
...@@ -454,7 +454,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle) ...@@ -454,7 +454,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
#endif #endif
ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs); ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir)); ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt)) if (HYPERVISOR_vcpu_op(VCPUOP_initialise, xen_vcpu_nr(cpu), ctxt))
BUG(); BUG();
kfree(ctxt); kfree(ctxt);
...@@ -492,7 +492,7 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle) ...@@ -492,7 +492,7 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
if (rc) if (rc)
return rc; return rc;
rc = HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL); rc = HYPERVISOR_vcpu_op(VCPUOP_up, xen_vcpu_nr(cpu), NULL);
BUG_ON(rc); BUG_ON(rc);
while (cpu_report_state(cpu) != CPU_ONLINE) while (cpu_report_state(cpu) != CPU_ONLINE)
...@@ -520,7 +520,8 @@ static int xen_cpu_disable(void) ...@@ -520,7 +520,8 @@ static int xen_cpu_disable(void)
static void xen_cpu_die(unsigned int cpu) static void xen_cpu_die(unsigned int cpu)
{ {
while (xen_pv_domain() && HYPERVISOR_vcpu_op(VCPUOP_is_up, cpu, NULL)) { while (xen_pv_domain() && HYPERVISOR_vcpu_op(VCPUOP_is_up,
xen_vcpu_nr(cpu), NULL)) {
__set_current_state(TASK_UNINTERRUPTIBLE); __set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(HZ/10); schedule_timeout(HZ/10);
} }
...@@ -536,7 +537,7 @@ static void xen_cpu_die(unsigned int cpu) ...@@ -536,7 +537,7 @@ static void xen_cpu_die(unsigned int cpu)
static void xen_play_dead(void) /* used only with HOTPLUG_CPU */ static void xen_play_dead(void) /* used only with HOTPLUG_CPU */
{ {
play_dead_common(); play_dead_common();
HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL); HYPERVISOR_vcpu_op(VCPUOP_down, xen_vcpu_nr(smp_processor_id()), NULL);
cpu_bringup(); cpu_bringup();
/* /*
* commit 4b0c0f294 (tick: Cleanup NOHZ per cpu data on cpu down) * commit 4b0c0f294 (tick: Cleanup NOHZ per cpu data on cpu down)
...@@ -576,7 +577,7 @@ static void stop_self(void *v) ...@@ -576,7 +577,7 @@ static void stop_self(void *v)
set_cpu_online(cpu, false); set_cpu_online(cpu, false);
HYPERVISOR_vcpu_op(VCPUOP_down, cpu, NULL); HYPERVISOR_vcpu_op(VCPUOP_down, xen_vcpu_nr(cpu), NULL);
BUG(); BUG();
} }
......
...@@ -223,8 +223,10 @@ static int xen_vcpuop_shutdown(struct clock_event_device *evt) ...@@ -223,8 +223,10 @@ static int xen_vcpuop_shutdown(struct clock_event_device *evt)
{ {
int cpu = smp_processor_id(); int cpu = smp_processor_id();
if (HYPERVISOR_vcpu_op(VCPUOP_stop_singleshot_timer, cpu, NULL) || if (HYPERVISOR_vcpu_op(VCPUOP_stop_singleshot_timer, xen_vcpu_nr(cpu),
HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL)) NULL) ||
HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, xen_vcpu_nr(cpu),
NULL))
BUG(); BUG();
return 0; return 0;
...@@ -234,7 +236,8 @@ static int xen_vcpuop_set_oneshot(struct clock_event_device *evt) ...@@ -234,7 +236,8 @@ static int xen_vcpuop_set_oneshot(struct clock_event_device *evt)
{ {
int cpu = smp_processor_id(); int cpu = smp_processor_id();
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL)) if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, xen_vcpu_nr(cpu),
NULL))
BUG(); BUG();
return 0; return 0;
...@@ -253,7 +256,8 @@ static int xen_vcpuop_set_next_event(unsigned long delta, ...@@ -253,7 +256,8 @@ static int xen_vcpuop_set_next_event(unsigned long delta,
/* Get an event anyway, even if the timeout is already expired */ /* Get an event anyway, even if the timeout is already expired */
single.flags = 0; single.flags = 0;
ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single); ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, xen_vcpu_nr(cpu),
&single);
BUG_ON(ret != 0); BUG_ON(ret != 0);
return ret; return ret;
...@@ -352,7 +356,8 @@ void xen_timer_resume(void) ...@@ -352,7 +356,8 @@ void xen_timer_resume(void)
return; return;
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL)) if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer,
xen_vcpu_nr(cpu), NULL))
BUG(); BUG();
} }
} }
...@@ -372,7 +377,8 @@ static void __init xen_time_init(void) ...@@ -372,7 +377,8 @@ static void __init xen_time_init(void)
clocksource_register_hz(&xen_clocksource, NSEC_PER_SEC); clocksource_register_hz(&xen_clocksource, NSEC_PER_SEC);
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL) == 0) { if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, xen_vcpu_nr(cpu),
NULL) == 0) {
/* Successfully turned off 100Hz tick, so we have the /* Successfully turned off 100Hz tick, so we have the
vcpuop-based timer interface */ vcpuop-based timer interface */
printk(KERN_DEBUG "Xen: using vcpuop timer interface\n"); printk(KERN_DEBUG "Xen: using vcpuop timer interface\n");
......
...@@ -1211,7 +1211,8 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector) ...@@ -1211,7 +1211,8 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
#ifdef CONFIG_X86 #ifdef CONFIG_X86
if (unlikely(vector == XEN_NMI_VECTOR)) { if (unlikely(vector == XEN_NMI_VECTOR)) {
int rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi, cpu, NULL); int rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi, xen_vcpu_nr(cpu),
NULL);
if (rc < 0) if (rc < 0)
printk(KERN_WARNING "Sending nmi to CPU%d failed (rc:%d)\n", cpu, rc); printk(KERN_WARNING "Sending nmi to CPU%d failed (rc:%d)\n", cpu, rc);
return; return;
......
...@@ -95,7 +95,7 @@ void xen_setup_runstate_info(int cpu) ...@@ -95,7 +95,7 @@ void xen_setup_runstate_info(int cpu)
area.addr.v = &per_cpu(xen_runstate, cpu); area.addr.v = &per_cpu(xen_runstate, cpu);
if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area, if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area,
cpu, &area)) xen_vcpu_nr(cpu), &area))
BUG(); BUG();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment