From patchwork Tue Mar 7 10:55:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9608615 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 CC55660414 for ; Tue, 7 Mar 2017 10:58:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7858284E8 for ; Tue, 7 Mar 2017 10:58:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC2F2284F2; Tue, 7 Mar 2017 10:58:02 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E8D5A284E8 for ; Tue, 7 Mar 2017 10:58:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clCmQ-0003cS-Ta; Tue, 07 Mar 2017 10:55:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clCmP-0003bW-E4 for xen-devel@lists.xenproject.org; Tue, 07 Mar 2017 10:55:45 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 22/DE-26304-0B19EB85; Tue, 07 Mar 2017 10:55:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeJIrShJLcpLzFFi42JxWrohUnfdxH0 RBj0r+Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxjS/wLDhdXLG9IbWDcE9zFyMkhIeAvMfdk AxuIzSagIzH16SVWEFtEwFZi9t+pzCA2s0CExN4bi4BqODiEBRwl9m0wBgmzCKhI3Fg4ix3E5 hVwl9j8ewsLxEg5ifPHf4K1cgp4SKxY0AMWFwKqOT53CTuErSKxfuosNoheQYmTM5+wQKySkD j44gXzBEbeWUhSs5CkFjAyrWLUKE4tKkst0jU00ksqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUw q1kvOz93ECAwbBiDYwdg3y/kQoyQHk5IoLxf/7gghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErw3 JIFygkWp6akVaZk5wACGSUtw8CiJ8P6WAErzFhck5hZnpkOkTjEqSonz3gPpEwBJZJTmwbXBo uYSo6yUMC8j0CFCPAWpRbmZJajyrxjFORiVhHn3gUzhycwrgZv+CmgxE9BiP5mdIItLEhFSUg 2M4glJVSv8vMo+93Hz+Wne/DFZed6MsM6EzunxkZUZZ3JCP13fXnlP8cU0s1PfVA8u4bLY7K0 pzz5NYEJdluCjJZdZflmnZW7vtt6jOCXNeWOtwyNO/c22sw5/tbq/UnDBJsUTVzkjjyunFgkE q+75K+z3NMNKhyNOL6X6dfefWqbm8w4nP+1QYinOSDTUYi4qTgQAtNrFj5UCAAA= X-Env-Sender: prvs=232365128=Paul.Durrant@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1488884138!85332921!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7225 invoked from network); 7 Mar 2017 10:55:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 7 Mar 2017 10:55:41 -0000 X-IronPort-AV: E=Sophos;i="5.35,258,1484006400"; d="scan'208";a="412022154" From: Paul Durrant To: , Date: Tue, 7 Mar 2017 10:55:34 +0000 Message-ID: <1488884134-29190-6-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1488884134-29190-1-git-send-email-paul.durrant@citrix.com> References: <1488884134-29190-1-git-send-email-paul.durrant@citrix.com> MIME-Version: 1.0 Cc: Paul Durrant , Stefano Stabellini Subject: [Xen-devel] [PATCH v4 5/5] xen: use libxendevicemodel when available X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch modifies the wrapper functions in xen_common.h to use the new xendevicemodel interface if it is available along with compatibility code to use the old libxenctrl interface if it is not. Signed-off-by: Paul Durrant Reviewed-by: Anthony Perard Reviewed-by: Stefano Stabellini --- Cc: Stefano Stabellini v4: - Fix typo causing build failures on < 490 - Fix building on < 450 - Build-tested against 4.2.5 and 4.8.0 v3: - Switch from macros to static inlines. v2: - Add a compat define for xenforeignmemory_close() since this is now used. --- include/hw/xen/xen_common.h | 203 +++++++++++++++++++++++++++++++++++++------- xen-common.c | 8 ++ 2 files changed, 178 insertions(+), 33 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 31cf25f..274accc 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -9,6 +9,7 @@ #undef XC_WANT_COMPAT_EVTCHN_API #undef XC_WANT_COMPAT_GNTTAB_API #undef XC_WANT_COMPAT_MAP_FOREIGN_API +#undef XC_WANT_COMPAT_DEVICEMODEL_API #include #include @@ -26,48 +27,183 @@ extern xc_interface *xen_xc; * We don't support Xen prior to 4.2.0. */ +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 490 + +typedef xc_interface xendevicemodel_handle; + +static inline xendevicemodel_handle *xendevicemodel_open( + struct xentoollog_logger *logger, unsigned int open_flags) +{ + return xen_xc; +} + +#if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 450 + +static inline int xendevicemodel_create_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, int handle_bufioreq, + ioservid_t *id) +{ + return xc_hvm_create_ioreq_server(dmod, domid, handle_bufioreq, + id); +} + +static inline int xendevicemodel_get_ioreq_server_info( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, + xen_pfn_t *ioreq_pfn, xen_pfn_t *bufioreq_pfn, + evtchn_port_t *bufioreq_port) +{ + return xc_hvm_get_ioreq_server_info(dmod, domid, id, ioreq_pfn, + bufioreq_pfn, bufioreq_port); +} + +static inline int xendevicemodel_map_io_range_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, int is_mmio, + uint64_t start, uint64_t end) +{ + return xc_hvm_map_io_range_to_ioreq_server(dmod, domid, id, is_mmio, + start, end); +} + +static inline int xendevicemodel_unmap_io_range_from_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, int is_mmio, + uint64_t start, uint64_t end) +{ + return xc_hvm_unmap_io_range_from_ioreq_server(dmod, domid, id, is_mmio, + start, end); +} + +static inline int xendevicemodel_map_pcidev_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, + uint16_t segment, uint8_t bus, uint8_t device, uint8_t function) +{ + return xc_hvm_map_pcidev_to_ioreq_server(dmod, domid, id, segment, + bus, device, function); +} + +static inline int xendevicemodel_unmap_pcidev_from_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, + uint16_t segment, uint8_t bus, uint8_t device, uint8_t function) +{ + return xc_hvm_unmap_pcidev_from_ioreq_server(dmod, domid, id, segment, + bus, device, function); +} + +static inline int xendevicemodel_destroy_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id) +{ + return xc_hvm_destroy_ioreq_server(dmod, domid, id); +} + +static inline int xendevicemodel_set_ioreq_server_state( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, int enabled) +{ + return xc_hvm_set_ioreq_server_state(dmod, domid, id, enabled); +} + +#endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 450 */ + +static inline int xendevicemodel_set_pci_intx_level( + xendevicemodel_handle *dmod, domid_t domid, uint16_t segment, + uint8_t bus, uint8_t device, uint8_t intx, unsigned int level) +{ + return xc_hvm_set_pci_intx_level(dmod, domid, segment, bus, device, + intx, level); +} + +static inline int xendevicemodel_set_isa_irq_level( + xendevicemodel_handle *dmod, domid_t domid, uint8_t irq, + unsigned int level) +{ + return xc_hvm_set_isa_irq_level(dmod, domid, irq, level); +} + +static inline int xendevicemodel_set_pci_link_route( + xendevicemodel_handle *dmod, domid_t domid, uint8_t link, uint8_t irq) +{ + return xc_hvm_set_pci_link_route(dmod, domid, link, irq); +} + +static inline int xendevicemodel_inject_msi( + xendevicemodel_handle *dmod, domid_t domid, uint64_t msi_addr, + uint32_t msi_data) +{ + return xc_hvm_inject_msi(dmod, domid, msi_addr, msi_data); +} + +static inline int xendevicemodel_track_dirty_vram( + xendevicemodel_handle *dmod, domid_t domid, uint64_t first_pfn, + uint32_t nr, unsigned long *dirty_bitmap) +{ + return xc_hvm_track_dirty_vram(dmod, domid, first_pfn, nr, + dirty_bitmap); +} + +static inline int xendevicemodel_modified_memory( + xendevicemodel_handle *dmod, domid_t domid, uint64_t first_pfn, + uint32_t nr) +{ + return xc_hvm_modified_memory(dmod, domid, first_pfn, nr); +} + +static inline int xendevicemodel_set_mem_type( + xendevicemodel_handle *dmod, domid_t domid, hvmmem_type_t mem_type, + uint64_t first_pfn, uint32_t nr) +{ + return xc_hvm_set_mem_type(dmod, domid, mem_type, first_pfn, nr); +} + +#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 490 */ + +#include + +#endif + +extern xendevicemodel_handle *xen_dmod; + static inline int xen_set_mem_type(domid_t domid, hvmmem_type_t type, uint64_t first_pfn, uint32_t nr) { - return xc_hvm_set_mem_type(xen_xc, domid, type, first_pfn, nr); + return xendevicemodel_set_mem_type(xen_dmod, domid, type, first_pfn, + nr); } static inline int xen_set_pci_intx_level(domid_t domid, uint16_t segment, uint8_t bus, uint8_t device, uint8_t intx, unsigned int level) { - return xc_hvm_set_pci_intx_level(xen_xc, domid, segment, bus, device, - intx, level); + return xendevicemodel_set_pci_intx_level(xen_dmod, domid, segment, bus, + device, intx, level); } static inline int xen_set_pci_link_route(domid_t domid, uint8_t link, uint8_t irq) { - return xc_hvm_set_pci_link_route(xen_xc, domid, link, irq); + return xendevicemodel_set_pci_link_route(xen_dmod, domid, link, irq); } static inline int xen_inject_msi(domid_t domid, uint64_t msi_addr, uint32_t msi_data) { - return xc_hvm_inject_msi(xen_xc, domid, msi_addr, msi_data); + return xendevicemodel_inject_msi(xen_dmod, domid, msi_addr, msi_data); } static inline int xen_set_isa_irq_level(domid_t domid, uint8_t irq, unsigned int level) { - return xc_hvm_set_isa_irq_level(xen_xc, domid, irq, level); + return xendevicemodel_set_isa_irq_level(xen_dmod, domid, irq, level); } static inline int xen_track_dirty_vram(domid_t domid, uint64_t first_pfn, uint32_t nr, unsigned long *bitmap) { - return xc_hvm_track_dirty_vram(xen_xc, domid, first_pfn, nr, bitmap); + return xendevicemodel_track_dirty_vram(xen_dmod, domid, first_pfn, nr, + bitmap); } static inline int xen_modified_memory(domid_t domid, uint64_t first_pfn, uint32_t nr) { - return xc_hvm_modified_memory(xen_xc, domid, first_pfn, nr); + return xendevicemodel_modified_memory(xen_dmod, domid, first_pfn, nr); } /* Xen 4.2 through 4.6 */ @@ -97,6 +233,7 @@ typedef xc_gnttab xengnttab_handle; xc_gnttab_map_domain_grant_refs(h, c, d, r, p) #define xenforeignmemory_open(l, f) xen_xc +#define xenforeignmemory_close(h) static inline void *xenforeignmemory_map(xc_interface *h, uint32_t dom, int prot, size_t pages, @@ -285,8 +422,8 @@ static inline void xen_map_memory_section(domid_t dom, } trace_xen_map_mmio_range(ioservid, start_addr, end_addr); - xc_hvm_map_io_range_to_ioreq_server(xen_xc, dom, ioservid, 1, - start_addr, end_addr); + xendevicemodel_map_io_range_to_ioreq_server(xen_dmod, dom, ioservid, 1, + start_addr, end_addr); } static inline void xen_unmap_memory_section(domid_t dom, @@ -302,8 +439,8 @@ static inline void xen_unmap_memory_section(domid_t dom, } trace_xen_unmap_mmio_range(ioservid, start_addr, end_addr); - xc_hvm_unmap_io_range_from_ioreq_server(xen_xc, dom, ioservid, - 1, start_addr, end_addr); + xendevicemodel_unmap_io_range_from_ioreq_server(xen_dmod, dom, ioservid, + 1, start_addr, end_addr); } static inline void xen_map_io_section(domid_t dom, @@ -319,8 +456,8 @@ static inline void xen_map_io_section(domid_t dom, } trace_xen_map_portio_range(ioservid, start_addr, end_addr); - xc_hvm_map_io_range_to_ioreq_server(xen_xc, dom, ioservid, 0, - start_addr, end_addr); + xendevicemodel_map_io_range_to_ioreq_server(xen_dmod, dom, ioservid, 0, + start_addr, end_addr); } static inline void xen_unmap_io_section(domid_t dom, @@ -336,8 +473,8 @@ static inline void xen_unmap_io_section(domid_t dom, } trace_xen_unmap_portio_range(ioservid, start_addr, end_addr); - xc_hvm_unmap_io_range_from_ioreq_server(xen_xc, dom, ioservid, - 0, start_addr, end_addr); + xendevicemodel_unmap_io_range_from_ioreq_server(xen_dmod, dom, ioservid, + 0, start_addr, end_addr); } static inline void xen_map_pcidev(domid_t dom, @@ -350,10 +487,10 @@ static inline void xen_map_pcidev(domid_t dom, 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(xen_xc, dom, ioservid, 0, - pci_bus_num(pci_dev->bus), - PCI_SLOT(pci_dev->devfn), - PCI_FUNC(pci_dev->devfn)); + xendevicemodel_map_pcidev_to_ioreq_server(xen_dmod, dom, ioservid, 0, + pci_bus_num(pci_dev->bus), + PCI_SLOT(pci_dev->devfn), + PCI_FUNC(pci_dev->devfn)); } static inline void xen_unmap_pcidev(domid_t dom, @@ -366,18 +503,18 @@ static inline void xen_unmap_pcidev(domid_t dom, 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(xen_xc, dom, ioservid, 0, - pci_bus_num(pci_dev->bus), - PCI_SLOT(pci_dev->devfn), - PCI_FUNC(pci_dev->devfn)); + xendevicemodel_unmap_pcidev_from_ioreq_server(xen_dmod, dom, ioservid, 0, + pci_bus_num(pci_dev->bus), + PCI_SLOT(pci_dev->devfn), + PCI_FUNC(pci_dev->devfn)); } static inline void xen_create_ioreq_server(domid_t dom, ioservid_t *ioservid) { - int rc = xc_hvm_create_ioreq_server(xen_xc, dom, - HVM_IOREQSRV_BUFIOREQ_ATOMIC, - ioservid); + int rc = xendevicemodel_create_ioreq_server(xen_dmod, dom, + HVM_IOREQSRV_BUFIOREQ_ATOMIC, + ioservid); if (rc == 0) { trace_xen_ioreq_server_create(*ioservid); @@ -397,7 +534,7 @@ static inline void xen_destroy_ioreq_server(domid_t dom, } trace_xen_ioreq_server_destroy(ioservid); - xc_hvm_destroy_ioreq_server(xen_xc, dom, ioservid); + xendevicemodel_destroy_ioreq_server(xen_dmod, dom, ioservid); } static inline int xen_get_ioreq_server_info(domid_t dom, @@ -412,9 +549,9 @@ static inline int xen_get_ioreq_server_info(domid_t dom, bufioreq_evtchn); } - return xc_hvm_get_ioreq_server_info(xen_xc, dom, ioservid, - ioreq_pfn, bufioreq_pfn, - bufioreq_evtchn); + return xendevicemodel_get_ioreq_server_info(xen_dmod, dom, ioservid, + ioreq_pfn, bufioreq_pfn, + bufioreq_evtchn); } static inline int xen_set_ioreq_server_state(domid_t dom, @@ -426,8 +563,8 @@ static inline int xen_set_ioreq_server_state(domid_t dom, } trace_xen_ioreq_server_state(ioservid, enable); - return xc_hvm_set_ioreq_server_state(xen_xc, dom, ioservid, - enable); + return xendevicemodel_set_ioreq_server_state(xen_dmod, dom, ioservid, + enable); } #endif diff --git a/xen-common.c b/xen-common.c index 703e7a5..ae76150 100644 --- a/xen-common.c +++ b/xen-common.c @@ -27,6 +27,7 @@ xc_interface *xen_xc; xenforeignmemory_handle *xen_fmem; +xendevicemodel_handle *xen_dmod; static int store_dev_info(int domid, Chardev *cs, const char *string) { @@ -128,6 +129,13 @@ static int xen_init(MachineState *ms) xc_interface_close(xen_xc); return -1; } + xen_dmod = xendevicemodel_open(0, 0); + if (xen_dmod == NULL) { + xen_pv_printf(NULL, 0, "can't open xen devicemodel interface\n"); + xenforeignmemory_close(xen_fmem); + xc_interface_close(xen_xc); + return -1; + } qemu_add_vm_change_state_handler(xen_change_state_handler, NULL); global_state_set_optional();