]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
xen/guest: fetch vCPU ID from Xen
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 27 Dec 2017 09:23:01 +0000 (09:23 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 16 Jan 2018 18:34:04 +0000 (18:34 +0000)
If available.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
[ wei: fix non-shim build ]
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/guest/xen.c
xen/arch/x86/smpboot.c
xen/include/asm-x86/guest/xen.h

index f62f93af16f9e462ec62f383c8f6aeba9c1e6458..de8cfc6e367bfef9de70861450d6d71980a81962 100644 (file)
@@ -37,6 +37,8 @@ static __read_mostly uint32_t xen_cpuid_base;
 extern char hypercall_page[];
 static struct rangeset *mem;
 
+DEFINE_PER_CPU(unsigned int, vcpu_id);
+
 static void __init find_xen_leaves(void)
 {
     uint32_t eax, ebx, ecx, edx, base;
@@ -102,6 +104,20 @@ static void map_shared_info(void)
         write_atomic(&XEN_shared_info->evtchn_mask[i], ~0ul);
 }
 
+static void set_vcpu_id(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    ASSERT(xen_cpuid_base);
+
+    /* Fetch vcpu id from cpuid. */
+    cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx);
+    if ( eax & XEN_HVM_CPUID_VCPU_ID_PRESENT )
+        this_cpu(vcpu_id) = ebx;
+    else
+        this_cpu(vcpu_id) = smp_processor_id();
+}
+
 static void __init init_memmap(void)
 {
     unsigned int i;
@@ -136,6 +152,13 @@ void __init hypervisor_setup(void)
     init_memmap();
 
     map_shared_info();
+
+    set_vcpu_id();
+}
+
+void hypervisor_ap_setup(void)
+{
+    set_vcpu_id();
 }
 
 int hypervisor_alloc_unused_page(mfn_t *mfn)
index acce2f65bd2bc934f238c27548777ebb075bdb2b..63ca053b353711018fb4ea8fb5efe902b2bc0d7d 100644 (file)
@@ -38,6 +38,7 @@
 #include <asm/desc.h>
 #include <asm/div64.h>
 #include <asm/flushtlb.h>
+#include <asm/guest.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
 #include <asm/time.h>
@@ -375,6 +376,9 @@ void start_secondary(void *unused)
     cpumask_set_cpu(cpu, &cpu_online_map);
     unlock_vector_lock();
 
+    if ( xen_guest )
+        hypervisor_ap_setup();
+
     /* We can take interrupts now: we're officially "up". */
     local_irq_enable();
     mtrr_ap_init();
index f25ad4241b57e39ca510c066a36deb0f7f1aa283..db35a9e6282ee800c91fcf86050edf6d4fb6e319 100644 (file)
@@ -32,9 +32,12 @@ extern bool xen_guest;
 
 void probe_hypervisor(void);
 void hypervisor_setup(void);
+void hypervisor_ap_setup(void);
 int hypervisor_alloc_unused_page(mfn_t *mfn);
 int hypervisor_free_unused_page(mfn_t mfn);
 
+DECLARE_PER_CPU(unsigned int, vcpu_id);
+
 #else
 
 #define xen_guest 0
@@ -44,6 +47,10 @@ static inline void hypervisor_setup(void)
 {
     ASSERT_UNREACHABLE();
 }
+static inline void hypervisor_ap_setup(void)
+{
+    ASSERT_UNREACHABLE();
+}
 
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */