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

[Xen-changelog] [xen stable-4.10] xen/guest: fetch vCPU ID from Xen



commit d2df09c92bf988af804b65a1db92d8ea82a60350
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Wed Dec 27 09:23:01 2017 +0000
Commit:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Thu Jan 11 17:51:19 2018 +0000

    xen/guest: fetch vCPU ID from Xen
    
    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 1609b627ae..5c7863035e 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>
@@ -373,6 +374,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__ */
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.10

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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