improve x86's alloc_vcpu_guest_context()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 22 Sep 2015 10:42:21 +0000 (12:42 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2015 10:42:21 +0000 (12:42 +0200)
This essentially reverts c/s 2037f2adb "x86: introduce
alloc_vcpu_guest_context()", including the newer arm bits, but achieves
the same end goal by using the newer vmalloc() infrastructure.

For both x86 and ARM, {alloc,free}_vcpu_guest_context() become arch-local
static inlines (which avoids a call into a separate translation),
and removes an x86 scalability limit when compiling with a large NR_CPUS.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Julien Grall <julien.grall@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen/arch/arm/domain.c
xen/arch/x86/domain.c
xen/include/asm-arm/domain.h
xen/include/asm-x86/domain.h
xen/include/asm-x86/fixmap.h
xen/include/xen/domain.h

index 5bdc2e964ff655d4f7c554eba6c5c7f07ff0c255..575745cf4cd44402a5fa42740876eb1f4329d2e3 100644 (file)
@@ -466,17 +466,6 @@ void free_vcpu_struct(struct vcpu *v)
     free_xenheap_page(v);
 }
 
-struct vcpu_guest_context *alloc_vcpu_guest_context(void)
-{
-    return xmalloc(struct vcpu_guest_context);
-
-}
-
-void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
-{
-    xfree(vgc);
-}
-
 int vcpu_initialise(struct vcpu *v)
 {
     int rc = 0;
index 5ff09e75eb08fd6a283031f2075c8b320c68b190..0b97912994d0186bb57c0b9a3c9b4ccd275a6e9f 100644 (file)
@@ -48,7 +48,6 @@
 #include <asm/cpuidle.h>
 #include <asm/mpspec.h>
 #include <asm/ldt.h>
-#include <asm/fixmap.h>
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/viridian.h>
@@ -272,51 +271,6 @@ void free_vcpu_struct(struct vcpu *v)
     free_xenheap_page(v);
 }
 
-static DEFINE_PER_CPU(struct page_info *[
-    PFN_UP(sizeof(struct vcpu_guest_context))], vgc_pages);
-
-struct vcpu_guest_context *alloc_vcpu_guest_context(void)
-{
-    unsigned int i, cpu = smp_processor_id();
-    enum fixed_addresses idx = FIX_VGC_BEGIN -
-        cpu * PFN_UP(sizeof(struct vcpu_guest_context));
-
-    BUG_ON(per_cpu(vgc_pages[0], cpu) != NULL);
-
-    for ( i = 0; i < PFN_UP(sizeof(struct vcpu_guest_context)); ++i )
-    {
-        struct page_info *pg = alloc_domheap_page(current->domain,
-                                                  MEMF_no_owner);
-
-        if ( unlikely(pg == NULL) )
-        {
-            free_vcpu_guest_context(NULL);
-            return NULL;
-        }
-        __set_fixmap(idx - i, page_to_mfn(pg), __PAGE_HYPERVISOR_RW);
-        per_cpu(vgc_pages[i], cpu) = pg;
-    }
-    return (void *)fix_to_virt(idx);
-}
-
-void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
-{
-    unsigned int i, cpu = smp_processor_id();
-    enum fixed_addresses idx = FIX_VGC_BEGIN -
-        cpu * PFN_UP(sizeof(struct vcpu_guest_context));
-
-    BUG_ON(vgc && vgc != (void *)fix_to_virt(idx));
-
-    for ( i = 0; i < PFN_UP(sizeof(struct vcpu_guest_context)); ++i )
-    {
-        if ( !per_cpu(vgc_pages[i], cpu) )
-            continue;
-        clear_fixmap(idx - i);
-        free_domheap_page(per_cpu(vgc_pages[i], cpu));
-        per_cpu(vgc_pages[i], cpu) = NULL;
-    }
-}
-
 static int setup_compat_l4(struct vcpu *v)
 {
     struct page_info *pg;
index 7ddaeaa07425531905ac21eba42df6ea26bf8b8b..c3f5a959410716926e267dd2196efe0bb29040cf 100644 (file)
@@ -300,6 +300,16 @@ static inline register_t vcpuid_to_vaffinity(unsigned int vcpuid)
     return vaff;
 }
 
+static inline struct vcpu_guest_context *alloc_vcpu_guest_context(void)
+{
+    return xmalloc(struct vcpu_guest_context);
+}
+
+static inline void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
+{
+    xfree(vgc);
+}
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
index 59cf8265a9ca8ec1fd2f3b075ee2c488af9150c2..f0aeade198c1f24a11d505aa5d4e203dcad92f96 100644 (file)
@@ -576,6 +576,16 @@ void domain_cpuid(struct domain *d,
 
 #define domain_max_vcpus(d) (is_hvm_domain(d) ? HVM_MAX_VCPUS : MAX_VIRT_CPUS)
 
+static inline struct vcpu_guest_context *alloc_vcpu_guest_context(void)
+{
+    return vmalloc(sizeof(struct vcpu_guest_context));
+}
+
+static inline void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
+{
+    vfree(vgc);
+}
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
index 70eadffba95ba278e719c491bf4ed855776e8129..1e24b1170169dd1142b4ff0760865580518f8312 100644 (file)
@@ -47,9 +47,6 @@ enum fixed_addresses {
     FIX_COM_END,
     FIX_EHCI_DBGP,
     /* Everything else should go further down. */
-    FIX_VGC_END,
-    FIX_VGC_BEGIN = FIX_VGC_END
-      + PFN_UP(sizeof(struct vcpu_guest_context)) * NR_CPUS - 1,
     FIX_APIC_BASE,
     FIX_IO_APIC_BASE_0,
     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
index a469fe0017da7701f189df8b6e9f682099b9060e..3dca3f69082e6d9d6d2247e6c167cfc3a1aaff3b 100644 (file)
@@ -31,12 +31,6 @@ void free_domain_struct(struct domain *d);
 struct vcpu *alloc_vcpu_struct(void);
 void free_vcpu_struct(struct vcpu *v);
 
-/* Allocate/free a vcpu_guest_context structure. */
-#ifndef alloc_vcpu_guest_context
-struct vcpu_guest_context *alloc_vcpu_guest_context(void);
-void free_vcpu_guest_context(struct vcpu_guest_context *);
-#endif
-
 /* Allocate/free a PIRQ structure. */
 #ifndef alloc_pirq_struct
 struct pirq *alloc_pirq_struct(struct domain *);