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

[Xen-devel] [PATCH v2 30/62] x86/guest: map per-cpu vcpu_info area.



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

Mapping the per-vcpu vcpu_info area is required in order to use more
than XEN_LEGACY_MAX_VCPUS.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Changes since v1:
 - Make vcpu_info_mapped static.
 - Add a BUG_ON in case VCPUOP_register_vcpu_info fails.
 - Remove one indentation level in hypervisor_setup.
 - Make xen_hypercall_vcpu_op return int.
---
 xen/arch/x86/guest/xen.c              | 57 +++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/guest/hypercall.h |  8 +++++
 xen/include/asm-x86/guest/xen.h       |  1 +
 3 files changed, 66 insertions(+)

diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index de8cfc6e36..60626ec21c 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -39,6 +39,10 @@ static struct rangeset *mem;
 
 DEFINE_PER_CPU(unsigned int, vcpu_id);
 
+static struct vcpu_info *vcpu_info;
+static unsigned long vcpu_info_mapped[BITS_TO_LONGS(NR_CPUS)];
+DEFINE_PER_CPU(struct vcpu_info *, vcpu_info);
+
 static void __init find_xen_leaves(void)
 {
     uint32_t eax, ebx, ecx, edx, base;
@@ -104,6 +108,41 @@ static void map_shared_info(void)
         write_atomic(&XEN_shared_info->evtchn_mask[i], ~0ul);
 }
 
+static int map_vcpuinfo(void)
+{
+    unsigned int vcpu = this_cpu(vcpu_id);
+    struct vcpu_register_vcpu_info info;
+    int rc;
+
+    if ( !vcpu_info )
+    {
+        this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu];
+        return 0;
+    }
+
+    if ( test_bit(vcpu, vcpu_info_mapped) )
+    {
+        this_cpu(vcpu_info) = &vcpu_info[vcpu];
+        return 0;
+    }
+
+    info.mfn = virt_to_mfn(&vcpu_info[vcpu]);
+    info.offset = (unsigned long)&vcpu_info[vcpu] & ~PAGE_MASK;
+    rc = xen_hypercall_vcpu_op(VCPUOP_register_vcpu_info, vcpu, &info);
+    if ( rc )
+    {
+        BUG_ON(vcpu >= XEN_LEGACY_MAX_VCPUS);
+        this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu];
+    }
+    else
+    {
+        this_cpu(vcpu_info) = &vcpu_info[vcpu];
+        set_bit(vcpu, vcpu_info_mapped);
+    }
+
+    return rc;
+}
+
 static void set_vcpu_id(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -154,11 +193,29 @@ void __init hypervisor_setup(void)
     map_shared_info();
 
     set_vcpu_id();
+    vcpu_info = xzalloc_array(struct vcpu_info, nr_cpu_ids);
+    if ( map_vcpuinfo() )
+    {
+        xfree(vcpu_info);
+        vcpu_info = NULL;
+    }
+    if ( !vcpu_info && nr_cpu_ids > XEN_LEGACY_MAX_VCPUS )
+    {
+        unsigned int i;
+
+        for ( i = XEN_LEGACY_MAX_VCPUS; i < nr_cpu_ids; i++ )
+            __cpumask_clear_cpu(i, &cpu_present_map);
+        nr_cpu_ids = XEN_LEGACY_MAX_VCPUS;
+        printk(XENLOG_WARNING
+               "unable to map vCPU info, limiting vCPUs to: %u\n",
+               XEN_LEGACY_MAX_VCPUS);
+    }
 }
 
 void hypervisor_ap_setup(void)
 {
     set_vcpu_id();
+    map_vcpuinfo();
 }
 
 int hypervisor_alloc_unused_page(mfn_t *mfn)
diff --git a/xen/include/asm-x86/guest/hypercall.h 
b/xen/include/asm-x86/guest/hypercall.h
index 9cd95d2b92..dbc57a566e 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -26,6 +26,8 @@
 #include <public/xen.h>
 #include <public/sched.h>
 
+#include <public/vcpu.h>
+
 /*
  * Hypercall primatives for 64bit
  *
@@ -96,6 +98,12 @@ static inline long xen_hypercall_memory_op(unsigned int cmd, 
void *arg)
     return _hypercall64_2(long, __HYPERVISOR_memory_op, cmd, arg);
 }
 
+static inline int xen_hypercall_vcpu_op(unsigned int cmd, unsigned int vcpu,
+                                        void *arg)
+{
+    return _hypercall64_3(long, __HYPERVISOR_vcpu_op, cmd, vcpu, arg);
+}
+
 /*
  * Higher level hypercall helpers
  */
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index db35a9e628..b3e684f756 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -37,6 +37,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn);
 int hypervisor_free_unused_page(mfn_t mfn);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
+DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 
 #else
 
-- 
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®.