xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xensource.com, keir.fraser@eu.citrix.com,
	Ian.Campbell@citrix.com, Ian.Jackson@eu.citrix.com,
	Tim.Deegan@citrix.com
Cc: konrad.wilk@oracle.com
Subject: [PATCH 2 of 4] x86: make the pv-only e820 array be dynamic
Date: Mon, 11 Apr 2011 17:35:32 -0400	[thread overview]
Message-ID: <e7057fec103ba69776d1.1302557732@localhost6.localdomain6> (raw)
In-Reply-To: <patchbomb.1302557730@localhost6.localdomain6>

# HG changeset patch
# User Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
# 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@oracle.com>

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*/

  parent reply	other threads:[~2011-04-11 21:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 21:35 [PATCH 0 of 4] Patches for PCI passthrough with modified E820 (v2) Konrad Rzeszutek Wilk
2011-04-11 21:35 ` [PATCH 1 of 4] tools: Add xc_domain_set_memory_map and xc_get_machine_memory_map calls (x86, amd64 only) Konrad Rzeszutek Wilk
2011-04-11 21:35 ` Konrad Rzeszutek Wilk [this message]
2011-04-12 12:32   ` [PATCH 2 of 4] x86: make the pv-only e820 array be dynamic Keir Fraser
2011-04-12 12:53     ` Konrad Rzeszutek Wilk
2011-04-12 13:06       ` Keir Fraser
2011-04-12 17:21         ` Konrad Rzeszutek Wilk
2011-04-13  7:34           ` Jan Beulich
2011-04-13 13:31             ` Konrad Rzeszutek Wilk
2011-04-13  8:46           ` Keir Fraser
2011-04-13 13:32             ` Konrad Rzeszutek Wilk
2011-04-11 21:35 ` [PATCH 3 of 4] libxl: Add support for passing in the machine's E820 for PCI passthrough in libxl_device_pci_parse_bdf Konrad Rzeszutek Wilk
2011-04-12 12:19   ` Ian Campbell
2011-04-12 17:53     ` Konrad Rzeszutek Wilk
2011-04-12 18:44       ` Ian Campbell
2011-04-12 19:00         ` Konrad Rzeszutek Wilk
2011-04-12 19:29           ` Ian Campbell
2011-04-11 21:35 ` [PATCH 4 of 4] libxl: Convert E820_UNUSABLE and E820_RAM to E820_UNUSABLE as appropriate Konrad Rzeszutek Wilk
  -- strict thread matches above, loose matches on Subject: below --
2011-04-12 20:31 [PATCH 0 of 4] Patches for PCI passthrough with modified E820 (v3) Konrad Rzeszutek Wilk
2011-04-12 20:31 ` [PATCH 2 of 4] x86: make the pv-only e820 array be dynamic Konrad Rzeszutek Wilk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7057fec103ba69776d1.1302557732@localhost6.localdomain6 \
    --to=konrad.wilk@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=Tim.Deegan@citrix.com \
    --cc=keir.fraser@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).