Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/thread_info.h>
0003 #include <asm/smp.h>
0004 
0005 #include <xen/events.h>
0006 
0007 #include "xen-ops.h"
0008 #include "smp.h"
0009 
0010 
0011 static void __init xen_hvm_smp_prepare_boot_cpu(void)
0012 {
0013     BUG_ON(smp_processor_id() != 0);
0014     native_smp_prepare_boot_cpu();
0015 
0016     /*
0017      * Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info
0018      * in xen_cpu_up_prepare_hvm().
0019      */
0020     xen_vcpu_setup(0);
0021 
0022     /*
0023      * Called again in case the kernel boots on vcpu >= MAX_VIRT_CPUS.
0024      * Refer to comments in xen_hvm_init_time_ops().
0025      */
0026     xen_hvm_init_time_ops();
0027 
0028     /*
0029      * The alternative logic (which patches the unlock/lock) runs before
0030      * the smp bootup up code is activated. Hence we need to set this up
0031      * the core kernel is being patched. Otherwise we will have only
0032      * modules patched but not core code.
0033      */
0034     xen_init_spinlocks();
0035 }
0036 
0037 static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
0038 {
0039     int cpu;
0040 
0041     native_smp_prepare_cpus(max_cpus);
0042 
0043     if (xen_have_vector_callback) {
0044         WARN_ON(xen_smp_intr_init(0));
0045         xen_init_lock_cpu(0);
0046     }
0047 
0048     for_each_possible_cpu(cpu) {
0049         if (cpu == 0)
0050             continue;
0051 
0052         /* Set default vcpu_id to make sure that we don't use cpu-0's */
0053         per_cpu(xen_vcpu_id, cpu) = XEN_VCPU_ID_INVALID;
0054     }
0055 }
0056 
0057 #ifdef CONFIG_HOTPLUG_CPU
0058 static void xen_hvm_cpu_die(unsigned int cpu)
0059 {
0060     if (common_cpu_die(cpu) == 0) {
0061         if (xen_have_vector_callback) {
0062             xen_smp_intr_free(cpu);
0063             xen_uninit_lock_cpu(cpu);
0064             xen_teardown_timer(cpu);
0065         }
0066     }
0067 }
0068 #else
0069 static void xen_hvm_cpu_die(unsigned int cpu)
0070 {
0071     BUG();
0072 }
0073 #endif
0074 
0075 void __init xen_hvm_smp_init(void)
0076 {
0077     smp_ops.smp_prepare_boot_cpu = xen_hvm_smp_prepare_boot_cpu;
0078     smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
0079     smp_ops.smp_cpus_done = xen_smp_cpus_done;
0080     smp_ops.cpu_die = xen_hvm_cpu_die;
0081 
0082     if (!xen_have_vector_callback) {
0083 #ifdef CONFIG_PARAVIRT_SPINLOCKS
0084         nopvspin = true;
0085 #endif
0086         return;
0087     }
0088 
0089     smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
0090     smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
0091     smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
0092 }