From nobody Fri Apr 19 01:35:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526403024984702.8103582006411; Tue, 15 May 2018 09:50:24 -0700 (PDT) Received: from localhost ([::1]:47721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId9c-0005EK-3G for importer@patchew.org; Tue, 15 May 2018 12:50:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId0X-0005s8-Mx for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fId0U-0007Qr-9t for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:01 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:23739) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fId0T-0007Pf-VF for qemu-devel@nongnu.org; Tue, 15 May 2018 12:40:58 -0400 X-IronPort-AV: E=Sophos;i="5.49,403,1520899200"; d="scan'208";a="54708351" From: Paul Durrant To: , Date: Tue, 15 May 2018 17:40:51 +0100 Message-ID: <20180515164053.14604-2-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180515164053.14604-1-paul.durrant@citrix.com> References: <20180515164053.14604-1-paul.durrant@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v3 1/3] xen-hvm: create separate function for ioreq server initialization 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: Paul Durrant , Stefano Stabellini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The code is sufficiently substantial that it improves code readability to put it in a new function called by xen_hvm_init() rather than having it inline. Signed-off-by: Paul Durrant Reviewed-by: Anthony Perard --- Cc: Stefano Stabellini --- hw/i386/xen/xen-hvm.c | 76 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index caa563be3d..6ffa3c22cc 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -95,7 +95,8 @@ typedef struct XenIOState { CPUState **cpu_by_vcpu_id; /* the evtchn port for polling the notification, */ evtchn_port_t *ioreq_local_port; - /* evtchn local port for buffered io */ + /* evtchn remote and local ports for buffered io */ + evtchn_port_t bufioreq_remote_port; evtchn_port_t bufioreq_local_port; /* the evtchn fd for polling */ xenevtchn_handle *xce_handle; @@ -1236,12 +1237,52 @@ static void xen_wakeup_notifier(Notifier *notifier,= void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } =20 -void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) +static int xen_map_ioreq_server(XenIOState *state) { - int i, rc; xen_pfn_t ioreq_pfn; xen_pfn_t bufioreq_pfn; evtchn_port_t bufioreq_evtchn; + int rc; + + rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, + &ioreq_pfn, &bufioreq_pfn, + &bufioreq_evtchn); + if (rc < 0) { + error_report("failed to get ioreq server info: error %d handle=3D%= p", + errno, xen_xc); + return rc; + } + + DPRINTF("shared page at pfn %lx\n", ioreq_pfn); + DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); + DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); + + state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &ioreq_pfn, NULL); + if (state->shared_page =3D=3D NULL) { + error_report("map shared IO page returned error %d handle=3D%p", + errno, xen_xc); + return -1; + } + + state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &bufioreq_pfn, NULL); + if (state->buffered_io_page =3D=3D NULL) { + error_report("map buffered IO page returned error %d", errno); + return -1; + } + + state->bufioreq_remote_port =3D bufioreq_evtchn; + + return 0; +} + +void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) +{ + int i, rc; + xen_pfn_t ioreq_pfn; XenIOState *state; =20 state =3D g_malloc0(sizeof (XenIOState)); @@ -1269,25 +1310,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) state->wakeup.notify =3D xen_wakeup_notifier; qemu_register_wakeup_notifier(&state->wakeup); =20 - rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, - &ioreq_pfn, &bufioreq_pfn, - &bufioreq_evtchn); + rc =3D xen_map_ioreq_server(state); if (rc < 0) { - error_report("failed to get ioreq server info: error %d handle=3D%= p", - errno, xen_xc); - goto err; - } - - DPRINTF("shared page at pfn %lx\n", ioreq_pfn); - DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); - DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); - - state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ|PROT_WRITE, - 1, &ioreq_pfn, NULL); - if (state->shared_page =3D=3D NULL) { - error_report("map shared IO page returned error %d handle=3D%p", - errno, xen_xc); goto err; } =20 @@ -1308,14 +1332,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) goto err; } =20 - state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ|PROT_WRITE, - 1, &bufioreq_pfn, NULL); - if (state->buffered_io_page =3D=3D NULL) { - error_report("map buffered IO page returned error %d", errno); - goto err; - } - /* Note: cpus is empty at this point in init */ state->cpu_by_vcpu_id =3D g_malloc0(max_cpus * sizeof(CPUState *)); =20 @@ -1340,7 +1356,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion = **ram_memory) } =20 rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, - bufioreq_evtchn); + state->bufioreq_remote_port); if (rc =3D=3D -1) { error_report("buffered evtchn bind error %d", errno); goto err; --=20 2.11.0 From nobody Fri Apr 19 01:35:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152640259951724.213804139106742; Tue, 15 May 2018 09:43:19 -0700 (PDT) Received: from localhost ([::1]:46897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId2k-0007Pv-Jc for importer@patchew.org; Tue, 15 May 2018 12:43:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId0X-0005s6-Mi for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fId0T-0007QU-OD for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:01 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:23739) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fId0T-0007Pf-FL for qemu-devel@nongnu.org; Tue, 15 May 2018 12:40:57 -0400 X-IronPort-AV: E=Sophos;i="5.49,403,1520899200"; d="scan'208";a="54708348" From: Paul Durrant To: , Date: Tue, 15 May 2018 17:40:52 +0100 Message-ID: <20180515164053.14604-3-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180515164053.14604-1-paul.durrant@citrix.com> References: <20180515164053.14604-1-paul.durrant@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v3 2/3] checkpatch: generalize xen handle matching in the list of types 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: Paolo Bonzini , Paul Durrant Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All the xen stable APIs define handle types of the form: xen_handle and some define additional handle types of the form: xen__handle Examples of these are xenforeignmemory_handle and xenforeignmemory_resource_handle. Both of these types will be misparsed by checkpatch if they appear as the first token in a line since, as types defined by an external library, they do not conform to the QEMU CODING_STYLE, which suggests CamelCase. A previous patch (5ac067a24a8) added xendevicemodel_handle to the list of types. This patch changes that to xen\w+_handle such that it will match all Xen stable API handles of the forms detailed above. Signed-off-by: Paul Durrant Reviewed-by: Eric Blake --- Cc: Paolo Bonzini Cc: Daniel P. Berrange v3: - Adjusted commit comment slightly as suggested by Eric v2: - New in this version --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index cb1b652388..e3d8c2cdfc 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -271,7 +271,7 @@ our @typeList =3D ( qr{hwaddr}, # external libraries qr{xml${Ident}}, - qr{xendevicemodel_handle}, + qr{xen\w+_handle}, # Glib definitions qr{gchar}, qr{gshort}, --=20 2.11.0 From nobody Fri Apr 19 01:35:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526402652646358.6884173531781; Tue, 15 May 2018 09:44:12 -0700 (PDT) Received: from localhost ([::1]:46966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId3b-0008CC-KQ for importer@patchew.org; Tue, 15 May 2018 12:44:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fId0X-0005s7-My for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fId0V-0007Rf-6H for qemu-devel@nongnu.org; Tue, 15 May 2018 12:41:01 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:23743) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fId0U-0007Qe-QU for qemu-devel@nongnu.org; Tue, 15 May 2018 12:40:59 -0400 X-IronPort-AV: E=Sophos;i="5.49,403,1520899200"; d="scan'208";a="54708354" From: Paul Durrant To: , Date: Tue, 15 May 2018 17:40:53 +0100 Message-ID: <20180515164053.14604-4-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180515164053.14604-1-paul.durrant@citrix.com> References: <20180515164053.14604-1-paul.durrant@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v3 3/3] xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq 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: Anthony Perard , Paul Durrant , Stefano Stabellini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Xen 4.11 has a new API to directly map guest resources. Among the resources that can be mapped using this API are ioreq pages. This patch modifies QEMU to attempt to use the new API should it exist, falling back to the previous mechanism if it is unavailable. Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Anthony Perard v3: - Addressed comments from Anthony - Verified build against Xen 4.10 --- configure | 5 ++++ hw/i386/xen/trace-events | 1 + hw/i386/xen/xen-hvm.c | 66 ++++++++++++++++++++++++++++++++++-------= ---- include/hw/xen/xen_common.h | 16 +++++++++++ 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 59f91ab3f9..d03094f905 100755 --- a/configure +++ b/configure @@ -2231,12 +2231,17 @@ EOF #undef XC_WANT_COMPAT_DEVICEMODEL_API #define __XEN_TOOLS__ #include +#include int main(void) { xendevicemodel_handle *xd; + xenforeignmemory_handle *xfmem; =20 xd =3D xendevicemodel_open(0, 0); xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); =20 + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0); + return 0; } EOF diff --git a/hw/i386/xen/trace-events b/hw/i386/xen/trace-events index 8dab7bcfe0..38616b698f 100644 --- a/hw/i386/xen/trace-events +++ b/hw/i386/xen/trace-events @@ -15,6 +15,7 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint3= 2_t data_is_ptr, uint64 cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t s= ize) "I/O=3D%p pio read reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D%d" cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t = size) "I/O=3D%p pio write reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D= %d" cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr,= uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p cop= y dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" count=3D%= d size=3D%d" +xen_map_resource_ioreq(uint32_t id, void *addr) "id: %u addr: %p" =20 # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64 diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 6ffa3c22cc..ff2a99cbb3 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1239,13 +1239,39 @@ static void xen_wakeup_notifier(Notifier *notifier,= void *data) =20 static int xen_map_ioreq_server(XenIOState *state) { + void *addr =3D NULL; + xenforeignmemory_resource_handle *fres; xen_pfn_t ioreq_pfn; xen_pfn_t bufioreq_pfn; evtchn_port_t bufioreq_evtchn; int rc; =20 + /* + * Attempt to map using the resource API and fall back to normal + * foreign mapping if this is not supported. + */ + QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_bufioreq !=3D 0); + QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_ioreq(0) !=3D 1); + fres =3D xenforeignmemory_map_resource(xen_fmem, xen_domid, + XENMEM_resource_ioreq_server, + state->ioservid, 0, 2, + &addr, + PROT_READ | PROT_WRITE, 0); + if (fres !=3D NULL) { + trace_xen_map_resource_ioreq(state->ioservid, addr); + state->buffered_io_page =3D addr; + state->shared_page =3D addr + TARGET_PAGE_SIZE; + } else if (errno !=3D EOPNOTSUPP) { + error_report("failed to map ioreq server resources: error %d handl= e=3D%p", + errno, xen_xc); + return -1; + } + rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, - &ioreq_pfn, &bufioreq_pfn, + (state->shared_page =3D=3D NULL) ? + &ioreq_pfn : NULL, + (state->buffered_io_page =3D=3D NULL) ? + &bufioreq_pfn : NULL, &bufioreq_evtchn); if (rc < 0) { error_report("failed to get ioreq server info: error %d handle=3D%= p", @@ -1253,27 +1279,37 @@ static int xen_map_ioreq_server(XenIOState *state) return rc; } =20 - DPRINTF("shared page at pfn %lx\n", ioreq_pfn); - DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); - DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); - - state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ | PROT_WRITE, - 1, &ioreq_pfn, NULL); if (state->shared_page =3D=3D NULL) { - error_report("map shared IO page returned error %d handle=3D%p", - errno, xen_xc); - return -1; + DPRINTF("shared page at pfn %lx\n", ioreq_pfn); + + state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &ioreq_pfn, NULL); + if (state->shared_page =3D=3D NULL) { + error_report("map shared IO page returned error %d handle=3D%p= ", + errno, xen_xc); + } } =20 - state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ | PROT_WRITE, - 1, &bufioreq_pfn, NULL); if (state->buffered_io_page =3D=3D NULL) { - error_report("map buffered IO page returned error %d", errno); + DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); + + state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_dom= id, + PROT_READ | PROT_WR= ITE, + 1, &bufioreq_pfn, + NULL); + if (state->buffered_io_page =3D=3D NULL) { + error_report("map buffered IO page returned error %d", errno); + return -1; + } + } + + if (state->shared_page =3D=3D NULL || state->buffered_io_page =3D=3D N= ULL) { return -1; } =20 + DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); + state->bufioreq_remote_port =3D bufioreq_evtchn; =20 return 0; diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 5f1402b494..2e47b98834 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -119,6 +119,22 @@ static inline int xendevicemodel_pin_memory_cacheattr( return xc_domain_pin_memory_cacheattr(xen_xc, domid, start, end, type); } =20 +typedef void xenforeignmemory_resource_handle; + +#define XENMEM_resource_ioreq_server 0 + +#define XENMEM_resource_ioreq_server_frame_bufioreq 0 +#define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n)) + +static inline xenforeignmemory_resource_handle *xenforeignmemory_map_resou= rce( + xenforeignmemory_handle *fmem, domid_t domid, unsigned int type, + unsigned int id, unsigned long frame, unsigned long nr_frames, + void **paddr, int prot, int flags) +{ + errno =3D EOPNOTSUPP; + return NULL; +} + #endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 */ =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 --=20 2.11.0