Merge tag 'hyperv-next-signed-20240320' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / arch / x86 / hyperv / hv_vtl.c
index edd2f35b2a5e100ce9662ceead612bc04c213f29..5c7de79423b8a5e13feea450abea601cae9720d0 100644 (file)
@@ -12,6 +12,7 @@
 #include <asm/i8259.h>
 #include <asm/mshyperv.h>
 #include <asm/realmode.h>
+#include <../kernel/smpboot.h>
 
 extern struct boot_params boot_params;
 static struct real_mode_header hv_vtl_real_mode_header;
@@ -65,7 +66,7 @@ static void hv_vtl_ap_entry(void)
        ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
 }
 
-static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored)
+static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored)
 {
        u64 status;
        int ret = 0;
@@ -79,7 +80,9 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored)
        struct ldttss_desc *ldt;
        struct desc_struct *gdt;
 
-       u64 rsp = current->thread.sp;
+       struct task_struct *idle = idle_thread_get(cpu);
+       u64 rsp = (unsigned long)idle->thread.sp;
+
        u64 rip = (u64)&hv_vtl_ap_entry;
 
        native_store_gdt(&gdt_ptr);
@@ -206,7 +209,15 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)
 
 static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
 {
-       int vp_id;
+       int vp_id, cpu;
+
+       /* Find the logical CPU for the APIC ID */
+       for_each_present_cpu(cpu) {
+               if (arch_match_cpu_phys_id(cpu, apicid))
+                       break;
+       }
+       if (cpu >= nr_cpu_ids)
+               return -EINVAL;
 
        pr_debug("Bringing up CPU with APIC ID %d in VTL2...\n", apicid);
        vp_id = hv_vtl_apicid_to_vp_id(apicid);
@@ -220,7 +231,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
                return -EINVAL;
        }
 
-       return hv_vtl_bringup_vcpu(vp_id, start_eip);
+       return hv_vtl_bringup_vcpu(vp_id, cpu, start_eip);
 }
 
 int __init hv_vtl_early_init(void)