GNU Linux-libre 4.19.263-gnu1
[releases.git] / arch / x86 / xen / smp_hvm.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <asm/smp.h>
3
4 #include <xen/events.h>
5
6 #include "xen-ops.h"
7 #include "smp.h"
8
9
10 static void __init xen_hvm_smp_prepare_boot_cpu(void)
11 {
12         BUG_ON(smp_processor_id() != 0);
13         native_smp_prepare_boot_cpu();
14
15         /*
16          * Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info
17          * in xen_cpu_up_prepare_hvm().
18          */
19         xen_vcpu_setup(0);
20
21         /*
22          * Called again in case the kernel boots on vcpu >= MAX_VIRT_CPUS.
23          * Refer to comments in xen_hvm_init_time_ops().
24          */
25         xen_hvm_init_time_ops();
26
27         /*
28          * The alternative logic (which patches the unlock/lock) runs before
29          * the smp bootup up code is activated. Hence we need to set this up
30          * the core kernel is being patched. Otherwise we will have only
31          * modules patched but not core code.
32          */
33         xen_init_spinlocks();
34 }
35
36 static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
37 {
38         int cpu;
39
40         native_smp_prepare_cpus(max_cpus);
41         WARN_ON(xen_smp_intr_init(0));
42
43         xen_init_lock_cpu(0);
44
45         for_each_possible_cpu(cpu) {
46                 if (cpu == 0)
47                         continue;
48
49                 /* Set default vcpu_id to make sure that we don't use cpu-0's */
50                 per_cpu(xen_vcpu_id, cpu) = XEN_VCPU_ID_INVALID;
51         }
52 }
53
54 #ifdef CONFIG_HOTPLUG_CPU
55 static void xen_hvm_cpu_die(unsigned int cpu)
56 {
57         if (common_cpu_die(cpu) == 0) {
58                 xen_smp_intr_free(cpu);
59                 xen_uninit_lock_cpu(cpu);
60                 xen_teardown_timer(cpu);
61         }
62 }
63 #else
64 static void xen_hvm_cpu_die(unsigned int cpu)
65 {
66         BUG();
67 }
68 #endif
69
70 void __init xen_hvm_smp_init(void)
71 {
72         if (!xen_have_vector_callback)
73                 return;
74
75         smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
76         smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
77         smp_ops.cpu_die = xen_hvm_cpu_die;
78         smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
79         smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
80         smp_ops.smp_prepare_boot_cpu = xen_hvm_smp_prepare_boot_cpu;
81         smp_ops.smp_cpus_done = xen_smp_cpus_done;
82 }