smp_hvm.c 2.0 KB

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