From nobody Wed Oct 29 09:08:36 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524758518958585.7175618060052; Thu, 26 Apr 2018 09:01:58 -0700 (PDT) Received: from localhost ([::1]:43069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBjLE-0004tR-53 for importer@patchew.org; Thu, 26 Apr 2018 12:01:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBjGL-0000y8-Us for qemu-devel@nongnu.org; Thu, 26 Apr 2018 11:56:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBjGI-0003dq-SY for qemu-devel@nongnu.org; Thu, 26 Apr 2018 11:56:50 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:29380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBjGI-0003dF-Ii for qemu-devel@nongnu.org; Thu, 26 Apr 2018 11:56:46 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52857200" From: Ian Jackson To: Date: Thu, 26 Apr 2018 16:56:22 +0100 Message-ID: <1524758187-9351-12-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524758187-9351-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524758187-9351-1-git-send-email-ian.jackson@eu.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] [PULL 11/16] xen: Use newly added dmops for mapping VGA memory 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: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org 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" From: Ross Lagerwall Xen unstable (to be in 4.11) has two new dmops, relocate_memory and pin_memory_cacheattr. Use these to set up the VGA memory, replacing the previous calls to libxc. This allows the VGA console to work properly when QEMU is running restricted (-xen-domid-restrict). Wrapper functions are provided to allow QEMU to work with older versions of Xen. Tweak the error handling while making this change: * Report pin_memory_cacheattr errors. * Report errors even when DEBUG_HVM is not set. This is useful for trying to understand why VGA is not working, since otherwise it just fails silently. * Fix the return values when an error occurs. The functions now consistently return -1 and set errno. CC: Ian Jackson Signed-off-by: Ross Lagerwall Reviewed-by: Ian Jackson Signed-off-by: Ian Jackson Acked-by: Anthony PERARD --- configure | 19 +++++++++++++++++ hw/i386/xen/xen-hvm.c | 50 ++++++++++++++++++++++++-----------------= ---- include/hw/xen/xen_common.h | 32 +++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 5cf9dde..aa35aef 100755 --- a/configure +++ b/configure @@ -2221,6 +2221,25 @@ EOF # Xen unstable elif cat > $TMPC < +int main(void) { + xendevicemodel_handle *xd; + + xd =3D xendevicemodel_open(0, 0); + xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); + + return 0; +} +EOF + compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxen= toolcore" + then + xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs -lxentoolcore" + xen_ctrl_version=3D41100 + xen=3Dyes + elif + cat > $TMPC < #include diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index fb727bc..caa563b 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -347,7 +347,7 @@ static int xen_add_to_physmap(XenIOState *state, MemoryRegion *mr, hwaddr offset_within_region) { - unsigned long i =3D 0; + unsigned long nr_pages; int rc =3D 0; XenPhysmap *physmap =3D NULL; hwaddr pfn, start_gpfn; @@ -396,22 +396,26 @@ go_physmap: =20 pfn =3D phys_offset >> TARGET_PAGE_BITS; start_gpfn =3D start_addr >> TARGET_PAGE_BITS; - for (i =3D 0; i < size >> TARGET_PAGE_BITS; i++) { - unsigned long idx =3D pfn + i; - xen_pfn_t gpfn =3D start_gpfn + i; - - rc =3D xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE= _gmfn, idx, gpfn); - if (rc) { - DPRINTF("add_to_physmap MFN %"PRI_xen_pfn" to PFN %" - PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc,= errno); - return -rc; - } + nr_pages =3D size >> TARGET_PAGE_BITS; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, + start_gpfn); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + nr_pages, pfn, start_gpfn, strerror(saved_errno)); + errno =3D saved_errno; + return -1; } =20 - xc_domain_pin_memory_cacheattr(xen_xc, xen_domid, + rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, start_addr >> TARGET_PAGE_BITS, (start_addr + size - 1) >> TARGET_PAGE_= BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); + if (rc) { + error_report("pin_memory_cacheattr failed: %s", strerror(errno)); + } return xen_save_physmap(state, physmap); } =20 @@ -419,7 +423,6 @@ static int xen_remove_from_physmap(XenIOState *state, hwaddr start_addr, ram_addr_t size) { - unsigned long i =3D 0; int rc =3D 0; XenPhysmap *physmap =3D NULL; hwaddr phys_offset =3D 0; @@ -438,16 +441,17 @@ static int xen_remove_from_physmap(XenIOState *state, size >>=3D TARGET_PAGE_BITS; start_addr >>=3D TARGET_PAGE_BITS; phys_offset >>=3D TARGET_PAGE_BITS; - for (i =3D 0; i < size; i++) { - xen_pfn_t idx =3D start_addr + i; - xen_pfn_t gpfn =3D phys_offset + i; - - rc =3D xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE= _gmfn, idx, gpfn); - if (rc) { - fprintf(stderr, "add_to_physmap MFN %"PRI_xen_pfn" to PFN %" - PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc,= errno); - return -rc; - } + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, + phys_offset); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory "RAM_ADDR_FMT" pages" + " from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + size, start_addr, phys_offset, strerror(saved_errno)); + errno =3D saved_errno; + return -1; } =20 QLIST_REMOVE(physmap, list); diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 4bd30a3..2eed6fc 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -89,6 +89,38 @@ typedef xc_interface xendevicemodel_handle; =20 #endif =20 +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 + +static inline int xendevicemodel_relocate_memory( + xendevicemodel_handle *dmod, domid_t domid, uint32_t size, uint64_t sr= c_gfn, + uint64_t dst_gfn) +{ + uint32_t i; + int rc; + + for (i =3D 0; i < size; i++) { + unsigned long idx =3D src_gfn + i; + xen_pfn_t gpfn =3D dst_gfn + i; + + rc =3D xc_domain_add_to_physmap(xen_xc, domid, XENMAPSPACE_gmfn, i= dx, + gpfn); + if (rc) { + return rc; + } + } + + return 0; +} + +static inline int xendevicemodel_pin_memory_cacheattr( + xendevicemodel_handle *dmod, domid_t domid, uint64_t start, uint64_t e= nd, + uint32_t type) +{ + return xc_domain_pin_memory_cacheattr(xen_xc, domid, start, end, type); +} + +#endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 */ + #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 =20 #define XEN_COMPAT_PHYSMAP --=20 2.1.4