From patchwork Fri Aug 12 23:36:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9278133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF444600CB for ; Fri, 12 Aug 2016 23:36:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F57828B23 for ; Fri, 12 Aug 2016 23:36:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9413828B2A; Fri, 12 Aug 2016 23:36:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B245A28B23 for ; Fri, 12 Aug 2016 23:36:57 +0000 (UTC) Received: from localhost ([::1]:55271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYM0W-00062r-S1 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 12 Aug 2016 19:36:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYM00-0005yn-Qt for qemu-devel@nongnu.org; Fri, 12 Aug 2016 19:36:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bYLzt-0000HY-Kj for qemu-devel@nongnu.org; Fri, 12 Aug 2016 19:36:23 -0400 Received: from mail.kernel.org ([198.145.29.136]:41360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYLzt-0000HR-7B for qemu-devel@nongnu.org; Fri, 12 Aug 2016 19:36:17 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88103200F3; Fri, 12 Aug 2016 23:36:15 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (unknown [96.82.76.110]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D4712013A; Fri, 12 Aug 2016 23:36:14 +0000 (UTC) From: Stefano Stabellini To: peter.maydell@linaro.org Date: Fri, 12 Aug 2016 16:36:10 -0700 Message-Id: <1471044970-9229-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471044970-9229-1-git-send-email-sstabellini@kernel.org> References: <1471044970-9229-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 198.145.29.136 Subject: [Qemu-devel] [PULL 2/2] xen: handle inbound migration of VMs without ioreq server pages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Durrant VMs created on older versions on Xen will not have been provisioned with pages to support creation of non-default ioreq servers. In this case the ioreq server API is not supported and QEMU's only option is to fall back to using the default ioreq server pages as it did prior to commit 3996e85c ("Xen: Use the ioreq-server API when available"). This patch therefore changes the code in xen_common.h to stop considering a failure of xc_hvm_create_ioreq_server() as a hard failure but simply as an indication that the guest is too old to support the ioreq server API. Instead a boolean is set to cause reversion to old behaviour such that the default ioreq server is then used. Signed-off-by: Paul Durrant Signed-off-by: Stefano Stabellini Acked-by: Anthony PERARD Acked-by: Stefano Stabellini --- include/hw/xen/xen_common.h | 125 +++++++++++++++++++++++++++++++------------- trace-events | 1 + xen-hvm.c | 6 +-- 3 files changed, 92 insertions(+), 40 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 640c31e..bd39287 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -107,6 +107,44 @@ static inline int xen_get_vmport_regs_pfn(xc_interface *xc, domid_t dom, #endif +static inline int xen_get_default_ioreq_server_info(xc_interface *xc, + domid_t dom, + xen_pfn_t *ioreq_pfn, + xen_pfn_t *bufioreq_pfn, + evtchn_port_t + *bufioreq_evtchn) +{ + unsigned long param; + int rc; + + rc = xc_get_hvm_param(xc, dom, HVM_PARAM_IOREQ_PFN, ¶m); + if (rc < 0) { + fprintf(stderr, "failed to get HVM_PARAM_IOREQ_PFN\n"); + return -1; + } + + *ioreq_pfn = param; + + rc = xc_get_hvm_param(xc, dom, HVM_PARAM_BUFIOREQ_PFN, ¶m); + if (rc < 0) { + fprintf(stderr, "failed to get HVM_PARAM_BUFIOREQ_PFN\n"); + return -1; + } + + *bufioreq_pfn = param; + + rc = xc_get_hvm_param(xc, dom, HVM_PARAM_BUFIOREQ_EVTCHN, + ¶m); + if (rc < 0) { + fprintf(stderr, "failed to get HVM_PARAM_BUFIOREQ_EVTCHN\n"); + return -1; + } + + *bufioreq_evtchn = param; + + return 0; +} + /* Xen before 4.5 */ #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 450 @@ -154,10 +192,9 @@ static inline void xen_unmap_pcidev(xc_interface *xc, domid_t dom, { } -static inline int xen_create_ioreq_server(xc_interface *xc, domid_t dom, - ioservid_t *ioservid) +static inline void xen_create_ioreq_server(xc_interface *xc, domid_t dom, + ioservid_t *ioservid) { - return 0; } static inline void xen_destroy_ioreq_server(xc_interface *xc, domid_t dom, @@ -171,35 +208,8 @@ static inline int xen_get_ioreq_server_info(xc_interface *xc, domid_t dom, xen_pfn_t *bufioreq_pfn, evtchn_port_t *bufioreq_evtchn) { - unsigned long param; - int rc; - - rc = xc_get_hvm_param(xc, dom, HVM_PARAM_IOREQ_PFN, ¶m); - if (rc < 0) { - fprintf(stderr, "failed to get HVM_PARAM_IOREQ_PFN\n"); - return -1; - } - - *ioreq_pfn = param; - - rc = xc_get_hvm_param(xc, dom, HVM_PARAM_BUFIOREQ_PFN, ¶m); - if (rc < 0) { - fprintf(stderr, "failed to get HVM_PARAM_BUFIOREQ_PFN\n"); - return -1; - } - - *bufioreq_pfn = param; - - rc = xc_get_hvm_param(xc, dom, HVM_PARAM_BUFIOREQ_EVTCHN, - ¶m); - if (rc < 0) { - fprintf(stderr, "failed to get HVM_PARAM_BUFIOREQ_EVTCHN\n"); - return -1; - } - - *bufioreq_evtchn = param; - - return 0; + return xen_get_default_ioreq_server_info(xc, dom, ioreq_pfn, bufioreq_pfn, + bufioreq_evtchn); } static inline int xen_set_ioreq_server_state(xc_interface *xc, domid_t dom, @@ -212,6 +222,8 @@ static inline int xen_set_ioreq_server_state(xc_interface *xc, domid_t dom, /* Xen 4.5 */ #else +static bool use_default_ioreq_server; + static inline void xen_map_memory_section(xc_interface *xc, domid_t dom, ioservid_t ioservid, MemoryRegionSection *section) @@ -220,6 +232,10 @@ static inline void xen_map_memory_section(xc_interface *xc, domid_t dom, ram_addr_t size = int128_get64(section->size); hwaddr end_addr = start_addr + size - 1; + if (use_default_ioreq_server) { + return; + } + trace_xen_map_mmio_range(ioservid, start_addr, end_addr); xc_hvm_map_io_range_to_ioreq_server(xc, dom, ioservid, 1, start_addr, end_addr); @@ -233,6 +249,11 @@ static inline void xen_unmap_memory_section(xc_interface *xc, domid_t dom, ram_addr_t size = int128_get64(section->size); hwaddr end_addr = start_addr + size - 1; + if (use_default_ioreq_server) { + return; + } + + trace_xen_unmap_mmio_range(ioservid, start_addr, end_addr); xc_hvm_unmap_io_range_from_ioreq_server(xc, dom, ioservid, 1, start_addr, end_addr); @@ -246,6 +267,11 @@ static inline void xen_map_io_section(xc_interface *xc, domid_t dom, ram_addr_t size = int128_get64(section->size); hwaddr end_addr = start_addr + size - 1; + if (use_default_ioreq_server) { + return; + } + + trace_xen_map_portio_range(ioservid, start_addr, end_addr); xc_hvm_map_io_range_to_ioreq_server(xc, dom, ioservid, 0, start_addr, end_addr); @@ -259,6 +285,10 @@ static inline void xen_unmap_io_section(xc_interface *xc, domid_t dom, ram_addr_t size = int128_get64(section->size); hwaddr end_addr = start_addr + size - 1; + if (use_default_ioreq_server) { + return; + } + trace_xen_unmap_portio_range(ioservid, start_addr, end_addr); xc_hvm_unmap_io_range_from_ioreq_server(xc, dom, ioservid, 0, start_addr, end_addr); @@ -268,6 +298,10 @@ static inline void xen_map_pcidev(xc_interface *xc, domid_t dom, ioservid_t ioservid, PCIDevice *pci_dev) { + if (use_default_ioreq_server) { + return; + } + trace_xen_map_pcidev(ioservid, pci_bus_num(pci_dev->bus), PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn)); xc_hvm_map_pcidev_to_ioreq_server(xc, dom, ioservid, @@ -280,6 +314,10 @@ static inline void xen_unmap_pcidev(xc_interface *xc, domid_t dom, ioservid_t ioservid, PCIDevice *pci_dev) { + if (use_default_ioreq_server) { + return; + } + trace_xen_unmap_pcidev(ioservid, pci_bus_num(pci_dev->bus), PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn)); xc_hvm_unmap_pcidev_from_ioreq_server(xc, dom, ioservid, @@ -288,22 +326,29 @@ static inline void xen_unmap_pcidev(xc_interface *xc, domid_t dom, PCI_FUNC(pci_dev->devfn)); } -static inline int xen_create_ioreq_server(xc_interface *xc, domid_t dom, - ioservid_t *ioservid) +static inline void xen_create_ioreq_server(xc_interface *xc, domid_t dom, + ioservid_t *ioservid) { int rc = xc_hvm_create_ioreq_server(xc, dom, HVM_IOREQSRV_BUFIOREQ_ATOMIC, ioservid); if (rc == 0) { trace_xen_ioreq_server_create(*ioservid); + return; } - return rc; + *ioservid = 0; + use_default_ioreq_server = true; + trace_xen_default_ioreq_server(); } static inline void xen_destroy_ioreq_server(xc_interface *xc, domid_t dom, ioservid_t ioservid) { + if (use_default_ioreq_server) { + return; + } + trace_xen_ioreq_server_destroy(ioservid); xc_hvm_destroy_ioreq_server(xc, dom, ioservid); } @@ -314,6 +359,12 @@ static inline int xen_get_ioreq_server_info(xc_interface *xc, domid_t dom, xen_pfn_t *bufioreq_pfn, evtchn_port_t *bufioreq_evtchn) { + if (use_default_ioreq_server) { + return xen_get_default_ioreq_server_info(xc, dom, ioreq_pfn, + bufioreq_pfn, + bufioreq_evtchn); + } + return xc_hvm_get_ioreq_server_info(xc, dom, ioservid, ioreq_pfn, bufioreq_pfn, bufioreq_evtchn); @@ -323,6 +374,10 @@ static inline int xen_set_ioreq_server_state(xc_interface *xc, domid_t dom, ioservid_t ioservid, bool enable) { + if (use_default_ioreq_server) { + return 0; + } + trace_xen_ioreq_server_state(ioservid, enable); return xc_hvm_set_ioreq_server_state(xc, dom, ioservid, enable); } diff --git a/trace-events b/trace-events index 52c6a6c..616cc52 100644 --- a/trace-events +++ b/trace-events @@ -60,6 +60,7 @@ spice_vmc_event(int event) "spice vmc event %d" # xen-hvm.c xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx" xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_dirty) "%#"PRIx64" size %#lx, log_dirty %i" +xen_default_ioreq_server(void) "" xen_ioreq_server_create(uint32_t id) "id: %u" xen_ioreq_server_destroy(uint32_t id) "id: %u" xen_ioreq_server_state(uint32_t id, bool enable) "id: %u: enable: %i" diff --git a/xen-hvm.c b/xen-hvm.c index 3b0343a..2f348ed 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -1203,11 +1203,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) goto err; } - rc = xen_create_ioreq_server(xen_xc, xen_domid, &state->ioservid); - if (rc < 0) { - perror("xen: ioreq server create"); - goto err; - } + xen_create_ioreq_server(xen_xc, xen_domid, &state->ioservid); state->exit.notify = xen_exit_notifier; qemu_add_exit_notifier(&state->exit);