# 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
|