WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2 of 4] x86: make the pv-only e820 array be dynamic

To: xen-devel@xxxxxxxxxxxxxxxxxxx, keir.fraser@xxxxxxxxxxxxx, Ian.Campbell@xxxxxxxxxx, Ian.Jackson@xxxxxxxxxxxxx, Tim.Deegan@xxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 4] x86: make the pv-only e820 array be dynamic
From: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Date: Mon, 11 Apr 2011 17:35:32 -0400
Cc: konrad.wilk@xxxxxxxxxx
Delivery-date: Mon, 11 Apr 2011 14:48:39 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1302557730@xxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1302557730@xxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.8.1
# HG changeset patch
# User Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
# Date 1302295108 14400
# Node ID e7057fec103ba69776d157d470d630ce99dbc540
# Parent  0f279f43f41ffa8549e076f2a30f499bd8d6cc1d
x86: make the pv-only e820 array be dynamic.

During creation of the PV domain we allocate the E820 structure to
have the amount of E820 entries on the machine, plus the number three.

This will allow the tool stack to fill the E820 with more
than three entries. Specifically the use cases is , where the toolstack
retrieves the E820, sanitizes it, and then sets it for the PV guest
(for PCI passthrough), this dynamic number of E820 is just
right.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>

diff -r 0f279f43f41f -r e7057fec103b xen/arch/x86/domain.c
--- a/xen/arch/x86/domain.c     Fri Apr 08 16:35:49 2011 -0400
+++ b/xen/arch/x86/domain.c     Fri Apr 08 16:38:28 2011 -0400
@@ -634,14 +634,23 @@ int arch_domain_create(struct domain *d,
                 d->arch.pirq_emuirq[i] = IRQ_UNBOUND;
             for (i = 0; i < nr_irqs; i++)
                 d->arch.emuirq_pirq[i] = IRQ_UNBOUND;
+        } else
+        {
+          d->arch.pv_domain.e820 = xmalloc_array(struct e820entry, E820NR);
+
+          if ( !d->arch.pv_domain.e820 )
+            goto fail;
+
+          memset(d->arch.pv_domain.e820, 0,
+                 E820NR * sizeof(*d->arch.pv_domain.e820));
         }
 
-
         if ( (rc = iommu_domain_init(d)) != 0 )
             goto fail;
 
         /* For Guest vMCE MSRs virtualization */
         vmce_init_msr(d);
+
     }
 
     if ( is_hvm_domain(d) )
@@ -668,6 +677,10 @@ int arch_domain_create(struct domain *d,
  fail:
     d->is_dying = DOMDYING_dead;
     vmce_destroy_msr(d);
+    if ( !is_hvm_domain(d) )
+    {
+      xfree(d->arch.pv_domain.e820);
+    }
     xfree(d->arch.pirq_irq);
     xfree(d->arch.irq_pirq);
     xfree(d->arch.pirq_emuirq);
@@ -696,6 +709,8 @@ void arch_domain_destroy(struct domain *
 
     if ( is_hvm_domain(d) )
         hvm_domain_destroy(d);
+    else
+      xfree(d->arch.pv_domain.e820);
 
     vmce_destroy_msr(d);
     pci_release_devices(d);
diff -r 0f279f43f41f -r e7057fec103b xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Fri Apr 08 16:35:49 2011 -0400
+++ b/xen/arch/x86/mm.c Fri Apr 08 16:38:28 2011 -0400
@@ -4710,7 +4710,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
         if ( copy_from_guest(&fmap, arg, 1) )
             return -EFAULT;
 
-        if ( fmap.map.nr_entries > ARRAY_SIZE(d->arch.pv_domain.e820) )
+        if ( fmap.map.nr_entries > E820NR )
             return -EINVAL;
 
         rc = rcu_lock_target_domain_by_id(fmap.domid, &d);
@@ -4730,9 +4730,16 @@ long arch_memory_op(int op, XEN_GUEST_HA
             return -EPERM;
         }
 
+        if ( d->arch.pv_domain.e820 == NULL )
+        {
+            rcu_unlock_domain(d);
+            return -EINVAL;
+        }
         rc = copy_from_guest(d->arch.pv_domain.e820, fmap.map.buffer,
                              fmap.map.nr_entries) ? -EFAULT : 0;
-        d->arch.pv_domain.nr_e820 = fmap.map.nr_entries;
+
+        if ( rc == 0 )
+          d->arch.pv_domain.nr_e820 = fmap.map.nr_entries;
 
         rcu_unlock_domain(d);
         return rc;
@@ -4747,6 +4754,9 @@ long arch_memory_op(int op, XEN_GUEST_HA
         if ( d->arch.pv_domain.nr_e820 == 0 )
             return -ENOSYS;
 
+        if ( d->arch.pv_domain.e820 == NULL )
+            return -ENOSYS;
+
         if ( copy_from_guest(&map, arg, 1) )
             return -EFAULT;
 
diff -r 0f279f43f41f -r e7057fec103b xen/include/asm-x86/domain.h
--- a/xen/include/asm-x86/domain.h      Fri Apr 08 16:35:49 2011 -0400
+++ b/xen/include/asm-x86/domain.h      Fri Apr 08 16:38:28 2011 -0400
@@ -238,7 +238,7 @@ struct pv_domain
     unsigned long pirq_eoi_map_mfn;
 
     /* Pseudophysical e820 map (XENMEM_memory_map).  */
-    struct e820entry e820[3];
+    struct e820entry *e820;
     unsigned int nr_e820;
 };
 
diff -r 0f279f43f41f -r e7057fec103b xen/include/asm-x86/e820.h
--- a/xen/include/asm-x86/e820.h        Fri Apr 08 16:35:49 2011 -0400
+++ b/xen/include/asm-x86/e820.h        Fri Apr 08 16:38:28 2011 -0400
@@ -39,4 +39,6 @@ extern unsigned int lowmem_kb, highmem_k
 #define e820_raw bootsym(e820map)
 #define e820_raw_nr bootsym(e820nr)
 
+/* The +3 is for guest RAM entries */
+#define E820NR (e820.nr_map + 3)
 #endif /*__E820_HEADER*/



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel