[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 14/22] xen: allow HVM guests to use XENMEM_memory_map
Enable this hypercall for HVM guests in order to fetch the e820 memory map in the absence of an emulated BIOS. The memory map is populated and notified to Xen in arch_setup_meminit_hvm. Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- tools/libxc/xc_dom_x86.c | 29 ++++++++++++++++++++++++++++- xen/arch/x86/hvm/hvm.c | 2 -- xen/arch/x86/mm.c | 6 ------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c index 336eab4..45b1f03 100644 --- a/tools/libxc/xc_dom_x86.c +++ b/tools/libxc/xc_dom_x86.c @@ -1113,6 +1113,7 @@ static int check_mmio_hole(uint64_t start, uint64_t memsize, return 1; } +#define MAX_E820_ENTRIES 128 static int meminit_hvm(struct xc_dom_image *dom) { unsigned long i, vmemid, nr_pages = dom->total_pages; @@ -1133,6 +1134,8 @@ static int meminit_hvm(struct xc_dom_image *dom) unsigned int nr_vmemranges, nr_vnodes; xc_interface *xch = dom->xch; uint32_t domid = dom->guest_domid; + struct e820entry entries[MAX_E820_ENTRIES]; + int e820_index = 0; if ( nr_pages > target_pages ) memflags |= XENMEMF_populate_on_demand; @@ -1183,6 +1186,13 @@ static int meminit_hvm(struct xc_dom_image *dom) vnode_to_pnode = dom->vnode_to_pnode; } + /* Add one additional memory range to account for the VGA hole */ + if ( (nr_vmemranges + (dom->emulation ? 1 : 0)) > MAX_E820_ENTRIES ) + { + DOMPRINTF("Too many memory ranges"); + goto error_out; + } + total_pages = 0; p2m_size = 0; for ( i = 0; i < nr_vmemranges; i++ ) @@ -1271,9 +1281,13 @@ static int meminit_hvm(struct xc_dom_image *dom) * Under 2MB mode, we allocate pages in batches of no more than 8MB to * ensure that we can be preempted and hence dom0 remains responsive. */ - if ( dom->emulation ) + if ( dom->emulation ) { rc = xc_domain_populate_physmap_exact( xch, domid, 0xa0, 0, memflags, &dom->p2m_host[0x00]); + entries[e820_index].addr = 0; + entries[e820_index].size = 0xa0 << PAGE_SHIFT; + entries[e820_index++].type = E820_RAM; + } stat_normal_pages = 0; for ( vmemid = 0; vmemid < nr_vmemranges; vmemid++ ) @@ -1300,6 +1314,12 @@ static int meminit_hvm(struct xc_dom_image *dom) else cur_pages = vmemranges[vmemid].start >> PAGE_SHIFT; + /* Build an e820 map. */ + entries[e820_index].addr = cur_pages << PAGE_SHIFT; + entries[e820_index].size = vmemranges[vmemid].end - + entries[e820_index].addr; + entries[e820_index++].type = E820_RAM; + while ( (rc == 0) && (end_pages > cur_pages) ) { /* Clip count to maximum 1GB extent. */ @@ -1417,6 +1437,13 @@ static int meminit_hvm(struct xc_dom_image *dom) DPRINTF(" 2MB PAGES: 0x%016lx\n", stat_2mb_pages); DPRINTF(" 1GB PAGES: 0x%016lx\n", stat_1gb_pages); + rc = xc_domain_set_memory_map(xch, domid, entries, e820_index); + if ( rc != 0 ) + { + DOMPRINTF("unable to set memory map."); + goto error_out; + } + rc = 0; goto out; error_out: diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 66f95b2..8a9c9df 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4748,7 +4748,6 @@ static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) switch ( cmd & MEMOP_CMD_MASK ) { - case XENMEM_memory_map: case XENMEM_machine_memory_map: case XENMEM_machphys_mapping: return -ENOSYS; @@ -4824,7 +4823,6 @@ static long hvm_memory_op_compat32(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) switch ( cmd & MEMOP_CMD_MASK ) { - case XENMEM_memory_map: case XENMEM_machine_memory_map: case XENMEM_machphys_mapping: return -ENOSYS; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index fd151c6..92eccd0 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4717,12 +4717,6 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return rc; } - if ( is_hvm_domain(d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - e820 = xmalloc_array(e820entry_t, fmap.map.nr_entries); if ( e820 == NULL ) { -- 1.9.5 (Apple Git-50.3) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |