xref: /openbmc/linux/arch/x86/xen/smp_hvm.c (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
20cd39f46SPeter Zijlstra #include <linux/thread_info.h>
3a52482d9SVitaly Kuznetsov #include <asm/smp.h>
4a52482d9SVitaly Kuznetsov 
584d582d2SBoris Ostrovsky #include <xen/events.h>
684d582d2SBoris Ostrovsky 
7a52482d9SVitaly Kuznetsov #include "xen-ops.h"
8a52482d9SVitaly Kuznetsov #include "smp.h"
9a52482d9SVitaly Kuznetsov 
10a52482d9SVitaly Kuznetsov 
xen_hvm_smp_prepare_boot_cpu(void)11a52482d9SVitaly Kuznetsov static void __init xen_hvm_smp_prepare_boot_cpu(void)
12a52482d9SVitaly Kuznetsov {
13a52482d9SVitaly Kuznetsov 	BUG_ON(smp_processor_id() != 0);
14a52482d9SVitaly Kuznetsov 	native_smp_prepare_boot_cpu();
15a52482d9SVitaly Kuznetsov 
16a52482d9SVitaly Kuznetsov 	/*
17ad73fd59SAnkur Arora 	 * Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info
18ad73fd59SAnkur Arora 	 * in xen_cpu_up_prepare_hvm().
19a52482d9SVitaly Kuznetsov 	 */
20a52482d9SVitaly Kuznetsov 	xen_vcpu_setup(0);
21a52482d9SVitaly Kuznetsov 
22a52482d9SVitaly Kuznetsov 	/*
23eed05744SDongli Zhang 	 * Called again in case the kernel boots on vcpu >= MAX_VIRT_CPUS.
24eed05744SDongli Zhang 	 * Refer to comments in xen_hvm_init_time_ops().
25eed05744SDongli Zhang 	 */
26eed05744SDongli Zhang 	xen_hvm_init_time_ops();
27eed05744SDongli Zhang 
28eed05744SDongli Zhang 	/*
29a52482d9SVitaly Kuznetsov 	 * The alternative logic (which patches the unlock/lock) runs before
30a52482d9SVitaly Kuznetsov 	 * the smp bootup up code is activated. Hence we need to set this up
31a52482d9SVitaly Kuznetsov 	 * the core kernel is being patched. Otherwise we will have only
32a52482d9SVitaly Kuznetsov 	 * modules patched but not core code.
33a52482d9SVitaly Kuznetsov 	 */
34a52482d9SVitaly Kuznetsov 	xen_init_spinlocks();
35a52482d9SVitaly Kuznetsov }
36a52482d9SVitaly Kuznetsov 
xen_hvm_smp_prepare_cpus(unsigned int max_cpus)37a52482d9SVitaly Kuznetsov static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
38a52482d9SVitaly Kuznetsov {
390b64ffb8SAnkur Arora 	int cpu;
400b64ffb8SAnkur Arora 
41a52482d9SVitaly Kuznetsov 	native_smp_prepare_cpus(max_cpus);
42a52482d9SVitaly Kuznetsov 
433d7746beSDavid Woodhouse 	if (xen_have_vector_callback) {
443d7746beSDavid Woodhouse 		WARN_ON(xen_smp_intr_init(0));
45a52482d9SVitaly Kuznetsov 		xen_init_lock_cpu(0);
463d7746beSDavid Woodhouse 	}
470b64ffb8SAnkur Arora 
480b64ffb8SAnkur Arora 	for_each_possible_cpu(cpu) {
490b64ffb8SAnkur Arora 		if (cpu == 0)
500b64ffb8SAnkur Arora 			continue;
510b64ffb8SAnkur Arora 
520b64ffb8SAnkur Arora 		/* Set default vcpu_id to make sure that we don't use cpu-0's */
530b64ffb8SAnkur Arora 		per_cpu(xen_vcpu_id, cpu) = XEN_VCPU_ID_INVALID;
540b64ffb8SAnkur Arora 	}
55a52482d9SVitaly Kuznetsov }
56a52482d9SVitaly Kuznetsov 
57a52482d9SVitaly Kuznetsov #ifdef CONFIG_HOTPLUG_CPU
xen_hvm_cleanup_dead_cpu(unsigned int cpu)58*2711b8e2SThomas Gleixner static void xen_hvm_cleanup_dead_cpu(unsigned int cpu)
59a52482d9SVitaly Kuznetsov {
603d7746beSDavid Woodhouse 	if (xen_have_vector_callback) {
61a52482d9SVitaly Kuznetsov 		xen_smp_intr_free(cpu);
62a52482d9SVitaly Kuznetsov 		xen_uninit_lock_cpu(cpu);
63a52482d9SVitaly Kuznetsov 		xen_teardown_timer(cpu);
64a52482d9SVitaly Kuznetsov 	}
65a52482d9SVitaly Kuznetsov }
66a52482d9SVitaly Kuznetsov #else
xen_hvm_cleanup_dead_cpu(unsigned int cpu)67*2711b8e2SThomas Gleixner static void xen_hvm_cleanup_dead_cpu(unsigned int cpu)
68a52482d9SVitaly Kuznetsov {
69a52482d9SVitaly Kuznetsov 	BUG();
70a52482d9SVitaly Kuznetsov }
71a52482d9SVitaly Kuznetsov #endif
72a52482d9SVitaly Kuznetsov 
xen_hvm_smp_init(void)73a52482d9SVitaly Kuznetsov void __init xen_hvm_smp_init(void)
74a52482d9SVitaly Kuznetsov {
753d7746beSDavid Woodhouse 	smp_ops.smp_prepare_boot_cpu = xen_hvm_smp_prepare_boot_cpu;
76a52482d9SVitaly Kuznetsov 	smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
773d7746beSDavid Woodhouse 	smp_ops.smp_cpus_done = xen_smp_cpus_done;
78*2711b8e2SThomas Gleixner 	smp_ops.cleanup_dead_cpu = xen_hvm_cleanup_dead_cpu;
793d7746beSDavid Woodhouse 
803d7746beSDavid Woodhouse 	if (!xen_have_vector_callback) {
81bd9dcef6SRandy Dunlap #ifdef CONFIG_PARAVIRT_SPINLOCKS
823d7746beSDavid Woodhouse 		nopvspin = true;
83bd9dcef6SRandy Dunlap #endif
843d7746beSDavid Woodhouse 		return;
853d7746beSDavid Woodhouse 	}
863d7746beSDavid Woodhouse 
873d7746beSDavid Woodhouse 	smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
88a52482d9SVitaly Kuznetsov 	smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
89a52482d9SVitaly Kuznetsov 	smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
90a52482d9SVitaly Kuznetsov }
91