[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 29/62] xen/guest: fetch vCPU ID from Xen



From: Roger Pau Monne <roger.pau@xxxxxxxxxx>

If available.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
[ wei: fix non-shim build ]
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/guest/xen.c        | 23 +++++++++++++++++++++++
 xen/arch/x86/smpboot.c          |  4 ++++
 xen/include/asm-x86/guest/xen.h |  7 +++++++
 3 files changed, 34 insertions(+)

diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index f62f93af16..de8cfc6e36 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -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)
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index 7b97ff86cb..945b6d594c 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -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>
@@ -372,6 +373,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();
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index f25ad4241b..db35a9e628 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -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__ */
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.