From 99605175c93a24be4aa39543cd02551ea205e614 Mon Sep 17 00:00:00 2001 From: Liang Li Date: Tue, 13 Jan 2015 10:40:53 +0800 Subject: [PATCH 1/2] xen-pt: Fix PCI devices re-attach failed Use the 'xl pci-attach $DomU $BDF' command to attach more than one PCI devices to the guest, then detach the devices with 'xl pci-detach $DomU $BDF', after that, re-attach these PCI devices again, an error message will be reported like following: libxl: error: libxl_qmp.c:287:qmp_handle_error_response: receive an error message from QMP server: Duplicate ID 'pci-pt-03_10.1' for device. If using the 'address_space_memory' as the parameter of 'memory_listener_register', 'xen_pt_region_del' will not be called if the memory region's name is not 'xen-pci-pt-*' when the devices is detached. This will cause the device's related QemuOpts object not be released properly. Using the device's address space can avoid such issue, because the calling count of 'xen_pt_region_add' when attaching and the calling count of 'xen_pt_region_del' when detaching is the same, so all the memory region ref and unref by the 'xen_pt_region_add' and 'xen_pt_region_del' can be released properly. Signed-off-by: Liang Li Reviewed-by: Paolo Bonzini Reported-by: Longtao Pang --- hw/xen/xen_pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index c1bf357154..f2893b28aa 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -736,7 +736,7 @@ static int xen_pt_initfn(PCIDevice *d) } out: - memory_listener_register(&s->memory_listener, &address_space_memory); + memory_listener_register(&s->memory_listener, &s->dev.bus_master_as); memory_listener_register(&s->io_listener, &address_space_io); XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered successfully!\n", From c1d322e6048796296555dd36fdd102d7fa2f50bf Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Wed, 3 Dec 2014 08:15:19 -0500 Subject: [PATCH 2/2] xen-hvm: increase maxmem before calling xc_domain_populate_physmap Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time. This patch fixes an abort() when assigning more than 4 NICs to a VM. Signed-off-by: Stefano Stabellini Signed-off-by: Don Slutz --- xen-hvm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xen-hvm.c b/xen-hvm.c index 754879481e..e2e575b099 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -90,6 +90,12 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) #endif #define BUFFER_IO_MAX_DELAY 100 +/* Leave some slack so that hvmloader does not complain about lack of + * memory at boot time ("Could not allocate order=0 extent"). + * Once hvmloader is modified to cope with that situation without + * printing warning messages, QEMU_SPARE_PAGES can be removed. + */ +#define QEMU_SPARE_PAGES 16 typedef struct XenPhysmap { hwaddr start_addr; @@ -244,6 +250,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) unsigned long nr_pfn; xen_pfn_t *pfn_list; int i; + xc_domaininfo_t info; + unsigned long free_pages; if (runstate_check(RUN_STATE_INMIGRATE)) { /* RAM already populated in Xen */ @@ -266,6 +274,22 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i; } + if ((xc_domain_getinfolist(xen_xc, xen_domid, 1, &info) != 1) || + (info.domain != xen_domid)) { + hw_error("xc_domain_getinfolist failed"); + } + free_pages = info.max_pages - info.tot_pages; + if (free_pages > QEMU_SPARE_PAGES) { + free_pages -= QEMU_SPARE_PAGES; + } else { + free_pages = 0; + } + if ((free_pages < nr_pfn) && + (xc_domain_setmaxmem(xen_xc, xen_domid, + ((info.max_pages + nr_pfn - free_pages) + << (XC_PAGE_SHIFT - 10))) < 0)) { + hw_error("xc_domain_setmaxmem failed"); + } if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) { hw_error("xen: failed to populate ram at " RAM_ADDR_FMT, ram_addr); }