From nobody Mon Apr 29 18:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900127; cv=none; d=zoho.com; s=zohoarc; b=fdjziCnqVHgJgr6JYLI+Qgrqro/aS3YFj5mrRrUp75B8DNDIc/o1ZVSPM3CVF0bzjnVkgViqTqE75a3EPgdDTSvDSVaNkoOyzwvaqMXlpv+5K9QRQPRcJyu+h77+G7Aua72illrZ0E8Kc9Z9rqN0iG3kCxe+uv1qsd2taPFUIRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900127; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KuwsomYPZdCM407ty3OUREjEyl9fT1JNOltYzbd+lBU=; b=NPK9YLeMwPS4G7ofJq2t2zkGpRsFSfS0Na6xlcl4ihLNQa1197L7hdAD6yUWN6ehidnUV2CM2ZYBOpb/pTbE8YEac5CmwuH/e/tP4nBOKQhAybSYcssNHGkLBgN3gWo4V8JYnvn7rtM3kVfF9uTViCugMQ2flpyRnWFv/9fn/BQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900127614208.82968163002874; Tue, 18 Jun 2019 16:22:07 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004sC-J9; Tue, 18 Jun 2019 23:20:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOr-0004rZ-Lt for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:25 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a652754a-921f-11e9-add7-5fd5842afd59; Tue, 18 Jun 2019 23:20:24 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D935F20873; Tue, 18 Jun 2019 23:20:23 +0000 (UTC) X-Inumbo-ID: a652754a-921f-11e9-add7-5fd5842afd59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900024; bh=yVZQzkQok0gYAhrEXWpnxZitVqiKzT0k9xmVq1U4JHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZL6DeuNm+TuEG2Kkc5hgUWQcrYUc8CdNWKe5ErvmFgDF9eGWonMvQCGLdIG2G9jX/ 5nzGN6cg03O3NDf464QmA7eJM9MYXCwxdaWSP/z2tkoxq7nhIrN2d9+oqOhJluXLuN 7rTIcPDgJJF3lFpXsm4lykJEo2W0nvLYAKaGPgck= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:15 -0700 Message-Id: <20190618232019.26425-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 1/5] xen: add a p2mt parameter to map_mmio_regions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, JBeulich@suse.com, andrew.cooper3@citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add a p2mt parameter to map_mmio_regions, pass p2m_mmio_direct_dev on ARM and p2m_mmio_direct on x86 -- no changes in behavior. On x86, introduce a macro to strip away the last parameter and rename the existing implementation of map_mmio_regions to __map_mmio_regions. Use __map_mmio_regions in vpci as it is x86-only today. On ARM, given the similarity between map_mmio_regions after the change and map_regions_p2mt, remove un/map_regions_p2mt. Also add an ASSERT to check that only p2m_mmio_* types are passed to it. Also fix the style of the comment on top of map_mmio_regions since we are at it. Signed-off-by: Stefano Stabellini CC: JBeulich@suse.com CC: andrew.cooper3@citrix.com --- Changes in v3: - code style - introduce __map_mmio_regions on x86 - fix comment style on top of map_mmio_regions - add an assert on allowed p2mt types in map_mmio_regions Changes in v2: - new patch --- xen/arch/arm/acpi/domain_build.c | 4 ++-- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v2.c | 3 ++- xen/arch/arm/p2m.c | 21 ++++----------------- xen/arch/arm/platforms/exynos5.c | 6 ++++-- xen/arch/arm/platforms/omap5.c | 12 ++++++++---- xen/arch/arm/traps.c | 2 +- xen/arch/arm/vgic-v2.c | 2 +- xen/arch/arm/vgic/vgic-v2.c | 2 +- xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/mm/p2m.c | 8 ++++---- xen/common/domctl.c | 7 ++++++- xen/drivers/vpci/header.c | 2 +- xen/include/asm-arm/p2m.h | 15 --------------- xen/include/asm-x86/p2m.h | 8 ++++++++ xen/include/xen/p2m-common.h | 11 +++++++---- 16 files changed, 51 insertions(+), 56 deletions(-) diff --git a/xen/arch/arm/acpi/domain_build.c b/xen/arch/arm/acpi/domain_bu= ild.c index 5aae32ac20..f4ac91cdac 100644 --- a/xen/arch/arm/acpi/domain_build.c +++ b/xen/arch/arm/acpi/domain_build.c @@ -193,7 +193,7 @@ static void __init acpi_map_other_tables(struct domain = *d) { addr =3D acpi_gbl_root_table_list.tables[i].address; size =3D acpi_gbl_root_table_list.tables[i].length; - res =3D map_regions_p2mt(d, + res =3D map_mmio_regions(d, gaddr_to_gfn(addr), PFN_UP(size), maddr_to_mfn(addr), @@ -547,7 +547,7 @@ int __init prepare_acpi(struct domain *d, struct kernel= _info *kinfo) acpi_create_efi_mmap_table(d, &kinfo->mem, tbl_add); =20 /* Map the EFI and ACPI tables to Dom0 */ - rc =3D map_regions_p2mt(d, + rc =3D map_mmio_regions(d, gaddr_to_gfn(d->arch.efi_acpi_gpa), PFN_UP(d->arch.efi_acpi_len), virt_to_mfn(d->arch.efi_acpi_table), diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d9836779d1..1f808b2ff1 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1171,7 +1171,7 @@ static int __init map_range_to_domain(const struct dt= _device_node *dev, =20 if ( need_mapping ) { - res =3D map_regions_p2mt(d, + res =3D map_mmio_regions(d, gaddr_to_gfn(addr), PFN_UP(len), maddr_to_mfn(addr), diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 256988c665..d2ef361fc7 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -701,7 +701,8 @@ static int gicv2_map_hwdown_extra_mappings(struct domai= n *d) =20 ret =3D map_mmio_regions(d, gaddr_to_gfn(v2m_data->addr), PFN_UP(v2m_data->size), - maddr_to_mfn(v2m_data->addr)); + maddr_to_mfn(v2m_data->addr), + p2m_mmio_direct_dev); if ( ret ) { printk(XENLOG_ERR "GICv2: Map v2m frame to d%d failed.\n", diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index e28ea1c85a..d88df11e09 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1310,31 +1310,18 @@ static inline int p2m_remove_mapping(struct domain = *d, return rc; } =20 -int map_regions_p2mt(struct domain *d, +int map_mmio_regions(struct domain *d, gfn_t gfn, unsigned long nr, mfn_t mfn, p2m_type_t p2mt) { + ASSERT( p2mt =3D=3D p2m_mmio_direct_dev || + p2mt =3D=3D p2m_mmio_direct_nc || + p2mt =3D=3D p2m_mmio_direct_c ); return p2m_insert_mapping(d, gfn, nr, mfn, p2mt); } =20 -int unmap_regions_p2mt(struct domain *d, - gfn_t gfn, - unsigned long nr, - mfn_t mfn) -{ - return p2m_remove_mapping(d, gfn, nr, mfn); -} - -int map_mmio_regions(struct domain *d, - gfn_t start_gfn, - unsigned long nr, - mfn_t mfn) -{ - return p2m_insert_mapping(d, start_gfn, nr, mfn, p2m_mmio_direct_dev); -} - int unmap_mmio_regions(struct domain *d, gfn_t start_gfn, unsigned long nr, diff --git a/xen/arch/arm/platforms/exynos5.c b/xen/arch/arm/platforms/exyn= os5.c index 6560507092..97cd080759 100644 --- a/xen/arch/arm/platforms/exynos5.c +++ b/xen/arch/arm/platforms/exynos5.c @@ -83,11 +83,13 @@ static int exynos5250_specific_mapping(struct domain *d) { /* Map the chip ID */ map_mmio_regions(d, gaddr_to_gfn(EXYNOS5_PA_CHIPID), 1, - maddr_to_mfn(EXYNOS5_PA_CHIPID)); + maddr_to_mfn(EXYNOS5_PA_CHIPID), + p2m_mmio_direct_dev); =20 /* Map the PWM region */ map_mmio_regions(d, gaddr_to_gfn(EXYNOS5_PA_TIMER), 2, - maddr_to_mfn(EXYNOS5_PA_TIMER)); + maddr_to_mfn(EXYNOS5_PA_TIMER), + p2m_mmio_direct_dev); =20 return 0; } diff --git a/xen/arch/arm/platforms/omap5.c b/xen/arch/arm/platforms/omap5.c index aee24e4d28..c5701dfd6c 100644 --- a/xen/arch/arm/platforms/omap5.c +++ b/xen/arch/arm/platforms/omap5.c @@ -99,19 +99,23 @@ static int omap5_specific_mapping(struct domain *d) { /* Map the PRM module */ map_mmio_regions(d, gaddr_to_gfn(OMAP5_PRM_BASE), 2, - maddr_to_mfn(OMAP5_PRM_BASE)); + maddr_to_mfn(OMAP5_PRM_BASE), + p2m_mmio_direct_dev); =20 /* Map the PRM_MPU */ map_mmio_regions(d, gaddr_to_gfn(OMAP5_PRCM_MPU_BASE), 1, - maddr_to_mfn(OMAP5_PRCM_MPU_BASE)); + maddr_to_mfn(OMAP5_PRCM_MPU_BASE), + p2m_mmio_direct_dev); =20 /* Map the Wakeup Gen */ map_mmio_regions(d, gaddr_to_gfn(OMAP5_WKUPGEN_BASE), 1, - maddr_to_mfn(OMAP5_WKUPGEN_BASE)); + maddr_to_mfn(OMAP5_WKUPGEN_BASE), + p2m_mmio_direct_dev); =20 /* Map the on-chip SRAM */ map_mmio_regions(d, gaddr_to_gfn(OMAP5_SRAM_PA), 32, - maddr_to_mfn(OMAP5_SRAM_PA)); + maddr_to_mfn(OMAP5_SRAM_PA), + p2m_mmio_direct_dev); =20 return 0; } diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 3103620323..ec125cfd4f 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1884,7 +1884,7 @@ static bool try_map_mmio(gfn_t gfn) if ( !iomem_access_permitted(d, mfn_x(mfn), mfn_x(mfn) + 1) ) return false; =20 - return !map_regions_p2mt(d, gfn, 1, mfn, p2m_mmio_direct_c); + return !map_mmio_regions(d, gfn, 1, mfn, p2m_mmio_direct_c); } =20 static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c index 64b141fea5..1543625ea4 100644 --- a/xen/arch/arm/vgic-v2.c +++ b/xen/arch/arm/vgic-v2.c @@ -691,7 +691,7 @@ static int vgic_v2_domain_init(struct domain *d) * region of the guest. */ ret =3D map_mmio_regions(d, gaddr_to_gfn(cbase), csize / PAGE_SIZE, - maddr_to_mfn(vbase)); + maddr_to_mfn(vbase), p2m_mmio_direct_dev); if ( ret ) return ret; =20 diff --git a/xen/arch/arm/vgic/vgic-v2.c b/xen/arch/arm/vgic/vgic-v2.c index b5ba4ace87..04f34ddab5 100644 --- a/xen/arch/arm/vgic/vgic-v2.c +++ b/xen/arch/arm/vgic/vgic-v2.c @@ -309,7 +309,7 @@ int vgic_v2_map_resources(struct domain *d) * region of the guest. */ ret =3D map_mmio_regions(d, gaddr_to_gfn(cbase), csize / PAGE_SIZE, - maddr_to_mfn(vbase)); + maddr_to_mfn(vbase), p2m_mmio_direct_dev); if ( ret ) { gdprintk(XENLOG_ERR, "Unable to remap VGIC CPU to VCPU\n"); diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 8845399ae9..3a43234f69 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -79,7 +79,7 @@ static int __init modify_identity_mmio(struct domain *d, = unsigned long pfn, =20 for ( ; ; ) { - rc =3D map ? map_mmio_regions(d, _gfn(pfn), nr_pages, _mfn(pfn)) + rc =3D map ? __map_mmio_regions(d, _gfn(pfn), nr_pages, _mfn(pfn= )) : unmap_mmio_regions(d, _gfn(pfn), nr_pages, _mfn(pfn)); if ( rc =3D=3D 0 ) break; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 4c9954867c..e007eee42f 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2276,10 +2276,10 @@ static unsigned int mmio_order(const struct domain = *d, =20 #define MAP_MMIO_MAX_ITER 64 /* pretty arbitrary */ =20 -int map_mmio_regions(struct domain *d, - gfn_t start_gfn, - unsigned long nr, - mfn_t mfn) +int __map_mmio_regions(struct domain *d, + gfn_t start_gfn, + unsigned long nr, + mfn_t mfn) { int ret =3D 0; unsigned long i; diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 72a44953d0..c6fd88d285 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -927,6 +927,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) unsigned long nr_mfns =3D op->u.memory_mapping.nr_mfns; unsigned long mfn_end =3D mfn + nr_mfns - 1; int add =3D op->u.memory_mapping.add_mapping; + p2m_type_t p2mt; =20 ret =3D -EINVAL; if ( mfn_end < mfn || /* wrap? */ @@ -939,6 +940,10 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) /* Must break hypercall up as this could take a while. */ if ( nr_mfns > 64 ) break; + + p2mt =3D p2m_mmio_direct_dev; +#else + p2mt =3D p2m_mmio_direct; #endif =20 ret =3D -EPERM; @@ -956,7 +961,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) "memory_map:add: dom%d gfn=3D%lx mfn=3D%lx nr=3D%lx\n", d->domain_id, gfn, mfn, nr_mfns); =20 - ret =3D map_mmio_regions(d, _gfn(gfn), nr_mfns, _mfn(mfn)); + ret =3D map_mmio_regions(d, _gfn(gfn), nr_mfns, _mfn(mfn), p2m= t); if ( ret < 0 ) printk(XENLOG_G_WARNING "memory_map:fail: dom%d gfn=3D%lx mfn=3D%lx nr=3D%l= x ret:%ld\n", diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 258b91deed..ade6d19b45 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -52,7 +52,7 @@ static int map_range(unsigned long s, unsigned long e, vo= id *data, * - {un}map_mmio_regions doesn't support preemption. */ =20 - rc =3D map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(s)) + rc =3D map->map ? __map_mmio_regions(map->d, _gfn(s), size, _mfn(s= )) : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(s)); if ( rc =3D=3D 0 ) { diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 2f89bb00c3..76aadc215d 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -252,21 +252,6 @@ void p2m_toggle_cache(struct vcpu *v, bool was_enabled= ); =20 void p2m_flush_vm(struct vcpu *v); =20 -/* - * Map a region in the guest p2m with a specific p2m type. - * The memory attributes will be derived from the p2m type. - */ -int map_regions_p2mt(struct domain *d, - gfn_t gfn, - unsigned long nr, - mfn_t mfn, - p2m_type_t p2mt); - -int unmap_regions_p2mt(struct domain *d, - gfn_t gfn, - unsigned long nr, - mfn_t mfn); - int map_dev_mmio_region(struct domain *d, gfn_t gfn, unsigned long nr, diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 09ef7e02fd..8321dc1f2a 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -1000,6 +1000,14 @@ static inline int p2m_entry_modify(struct p2m_domain= *p2m, p2m_type_t nt, return 0; } =20 +/* x86 doesn't use the p2mt parameter, just strip it away */ +#define map_mmio_regions(d, start_gfn, nr, mfn, p2mt) \ + __map_mmio_regions(d, start_gfn, nr, mfn) +int __map_mmio_regions(struct domain *d, + gfn_t start_gfn, + unsigned long nr, + mfn_t mfn); + #endif /* _XEN_ASM_X86_P2M_H */ =20 /* diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index 58031a6ea8..e20b4974b0 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -8,13 +8,16 @@ int __must_check guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned int page_order); =20 -/* Map MMIO regions in the p2m: start_gfn and nr describe the range in - * * the guest physical address space to map, starting from the machine - * * frame number mfn. */ +/* + * Map MMIO regions in the p2m: start_gfn and nr describe the range in + * the guest physical address space to map, starting from the machine + * frame number mfn. + */ int map_mmio_regions(struct domain *d, gfn_t start_gfn, unsigned long nr, - mfn_t mfn); + mfn_t mfn, + p2m_type_t p2mt); int unmap_mmio_regions(struct domain *d, gfn_t start_gfn, unsigned long nr, --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 18:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900123; cv=none; d=zoho.com; s=zohoarc; b=BoKbAmYv8/jRZE3BKU7Ah1wV2BaEVmg4fJ9+lZDZqAJz+PujIqQ7ocgXfywnEkClzMq3laewQN3oU16y6bxvuUQuO4AB0HZOUyWNVbZPP5nqg/jUND5K6rVKWqVAUfDWGGPRRklzGMfbUth6O+S0dcKoFlG6PbGJrOtojveO5Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900123; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QGVm8mMUWWp291y6XixrFL9Jt/M2LZC6tonEYn1LYK8=; b=Q0RjD8XZIMNe/CJHHnNeZs0c9mDnjbg1a9L7qft9WzUoD9fN4tZteOJejUd9XXqs/sxtZXAiEOM7XpbaXG2x6V8/KqIYGuSyQR4EpJnDQ6grlpBQWiFyIcje/ucPRs1kuEEZmjQnK4miU+LnqRe78IB/Yq1g3ns6wHP4Ex+Hzuk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900123325235.7340180031224; Tue, 18 Jun 2019 16:22:03 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004sL-Sv; Tue, 18 Jun 2019 23:20:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOr-0004rb-PF for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:25 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a6a40978-921f-11e9-a5e4-f7cb9184a011; Tue, 18 Jun 2019 23:20:25 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A4B721479; Tue, 18 Jun 2019 23:20:24 +0000 (UTC) X-Inumbo-ID: a6a40978-921f-11e9-a5e4-f7cb9184a011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900024; bh=2DrpelDctcvXkXSvHa1gX5/UiYIw+GVWWZ3Km79MV/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ESGcy4hAbHSqng2VDwVDoszRU8vDRorkt/bESRqeqVzbXB7Htm3JLvFlRQ3snD6Gl kAsCkwQN+kJ2PmHkFt9CRpoRKXV88Jd4jIo4EjflVqU+oIoDPAlQKTQJzjYKVV5dzK +gElHPY/nhJhw78Dw8XfevJbVXxsjUgI0luNleQQ= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:16 -0700 Message-Id: <20190618232019.26425-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 2/5] xen: extend XEN_DOMCTL_memory_mapping to handle memory policy X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, JBeulich@suse.com, andrew.cooper3@citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Reuse the existing padding field to pass memory policy information. On Arm, the caller can specify whether the memory should be mapped as Device-nGnRE (Device Memory on Armv7) at stage-2, which is the default and the only possibility today, or cacheable memory write-back. The resulting memory attributes will be a combination of stage-2 and stage-1 memory attributes: it will actually be the strongest between the 2 stages attributes. On x86, the only option is uncachable. The current behavior becomes the default (numerically '0'). Also explicitely set the memory_policy field to 0 in libxc. On ARM, map Device-nGnRE as p2m_mmio_direct_dev (as it is already done today) and WB cacheable memory as p2m_mmio_direct_c. On x86, return error if the memory policy requested is not MEMORY_POLICY_X86_UC_MINUS. Signed-off-by: Stefano Stabellini CC: JBeulich@suse.com CC: andrew.cooper3@citrix.com --- Andrew suggested to remove MEMORY_POLICY_X86_UC_MINUS completely. If that's the consensus I am happy to respin the series removing code. Changes in v3: - error handling in default label of the switch - set memory_policy to 0 in libxc - improve commit message - improve comments - s/Device-nGRE/Device-nGnRE/g - add in-code comment - s/MEMORY_POLICY_X86_UC/MEMORY_POLICY_X86_UC_MINUS/g - #ifdef hypercall defines according to arch Changes in v2: - rebase - use p2m_mmio_direct_c - use EOPNOTSUPP - rename cache_policy to memory policy - rename MEMORY_POLICY_DEVMEM to MEMORY_POLICY_ARM_DEV_nGRE - rename MEMORY_POLICY_MEMORY to MEMORY_POLICY_ARM_MEM_WB - add MEMORY_POLICY_X86_UC - add MEMORY_POLICY_DEFAULT and use it --- tools/libxc/xc_domain.c | 1 + xen/common/domctl.c | 24 ++++++++++++++++++++++-- xen/include/public/domctl.h | 23 ++++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 05d771f2ce..8531298563 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -2070,6 +2070,7 @@ int xc_domain_memory_mapping( domctl.cmd =3D XEN_DOMCTL_memory_mapping; domctl.domain =3D domid; domctl.u.memory_mapping.add_mapping =3D add_mapping; + domctl.u.memory_mapping.memory_policy =3D 0; max_batch_sz =3D nr_mfns; do { diff --git a/xen/common/domctl.c b/xen/common/domctl.c index c6fd88d285..f21f6957b0 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -928,6 +928,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) unsigned long mfn_end =3D mfn + nr_mfns - 1; int add =3D op->u.memory_mapping.add_mapping; p2m_type_t p2mt; + uint32_t memory_policy =3D op->u.memory_mapping.memory_policy; =20 ret =3D -EINVAL; if ( mfn_end < mfn || /* wrap? */ @@ -958,9 +959,28 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) if ( add ) { printk(XENLOG_G_DEBUG - "memory_map:add: dom%d gfn=3D%lx mfn=3D%lx nr=3D%lx\n", - d->domain_id, gfn, mfn, nr_mfns); + "memory_map:add: dom%d gfn=3D%lx mfn=3D%lx nr=3D%lx cac= he=3D%u\n", + d->domain_id, gfn, mfn, nr_mfns, memory_policy); =20 + switch ( memory_policy ) + { +#ifdef CONFIG_ARM + case MEMORY_POLICY_ARM_MEM_WB: + p2mt =3D p2m_mmio_direct_c; + break; + case MEMORY_POLICY_ARM_DEV_nGnRE: + p2mt =3D p2m_mmio_direct_dev; + break; +#endif +#ifdef CONFIG_X86 + case MEMORY_POLICY_X86_UC_MINUS: + p2mt =3D p2m_mmio_direct; + break; +#endif + default: + domctl_lock_release(); + goto domctl_out_unlock_domonly; + } ret =3D map_mmio_regions(d, _gfn(gfn), nr_mfns, _mfn(mfn), p2m= t); if ( ret < 0 ) printk(XENLOG_G_WARNING diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 19486d5e32..e51caada35 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -571,12 +571,33 @@ struct xen_domctl_bind_pt_irq { */ #define DPCI_ADD_MAPPING 1 #define DPCI_REMOVE_MAPPING 0 +/* + * Default memory policy. Corresponds to: + * Arm: MEMORY_POLICY_ARM_DEV_nGnRE + * x86: MEMORY_POLICY_X86_UC_MINUS + */ +#define MEMORY_POLICY_DEFAULT 0 +#if defined(__i386__) || defined(__x86_64__) +/* x86 only. Memory type UNCACHABLE */ +# define MEMORY_POLICY_X86_UC_MINUS 0 +#elif defined(__arm__) || defined (__aarch64__) +/* Arm only. Outer Shareable, Device-nGnRE memory (Device Memory on Armv7)= */ +# define MEMORY_POLICY_ARM_DEV_nGnRE 0 +/* Arm only. Outer Shareable, Outer/Inner Write-Back Cacheable memory */ +# define MEMORY_POLICY_ARM_MEM_WB 1 +/* + * On ARM, MEMORY_POLICY selects the stage-2 memory attributes, but note + * that the resulting memory attributes will be a combination of stage-2 + * and stage-1 memory attributes: it will be the strongest between the 2 + * stages attributes. + */ +#endif struct xen_domctl_memory_mapping { uint64_aligned_t first_gfn; /* first page (hvm guest phys page) in ran= ge */ uint64_aligned_t first_mfn; /* first page (machine page) in range */ uint64_aligned_t nr_mfns; /* number of pages in range (>0) */ uint32_t add_mapping; /* add or remove mapping */ - uint32_t padding; /* padding for 64-bit aligned structure */ + uint32_t memory_policy; /* cacheability of the memory mapping */ }; =20 =20 --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 18:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900119; cv=none; d=zoho.com; s=zohoarc; b=btnZF25BRD2h8B/apChM+Lo2/IPZDuvVgX1190Uta1ho1pkKctruWECqd9lPgslvzv27asG0T8GKCe22UUzEB/pvDXhn0FMJl+QkKd7G5EIHpwi1aqt4UJduRWBIZyMdZe8ZK0KV60lwNmNv7saYG1IHl7/GKueUp4VyeF36arM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FmYAABU28uqH2JAS7X5QrYbzIMeUQRdkdcuNzQzyG6M=; b=VHNriID1+KbMe7jlbeUCe1bzzzOE0FAkge8K1AvWGVrHGfIUlnXFaS31CglWZAXZGqiZQEKA+Q/asAgnL5BUao9xJRaGtUOeJ0iMl3YE9mCB715lrwdjINEVjMEpjYugf0xhJvJ5zoUXptlT+KYss4tfQsdw1gECLJnfH7r7WSU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900119622239.54270979552336; Tue, 18 Jun 2019 16:21:59 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOu-0004sY-6T; Tue, 18 Jun 2019 23:20:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004s2-1r for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:27 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a6e3a7e0-921f-11e9-a682-a783eb3d4bbc; Tue, 18 Jun 2019 23:20:25 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB7532147A; Tue, 18 Jun 2019 23:20:24 +0000 (UTC) X-Inumbo-ID: a6e3a7e0-921f-11e9-a682-a783eb3d4bbc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900025; bh=JvsnVwnBptlh0LsR20oI9PWGsuWgVEn+TIWcVJRmph4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EGBGiU6ZXRlULicQmIXDrpPUSpNwCPueDrtY+Al691hUW20h15JaNoARdq2jZBcdW H30tO8Rkr+jh9O777qXVHGBjmEKXS5cNz6Xq0uB3NWmO4DGR4uDP8GQH+8C7ermfqq 5v2YKbX9jsPgbYtrlFJ2vTgUX4vKlZz4xdSEuNxM= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:17 -0700 Message-Id: <20190618232019.26425-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 3/5] libxc: introduce xc_domain_mem_map_policy X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, ian.jackson@eu.citrix.com, wei.liu2@citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Introduce a new libxc function that makes use of the new memory_policy parameter added to the XEN_DOMCTL_memory_mapping hypercall. The parameter values are the same for the XEN_DOMCTL_memory_mapping hypercall (0 is MEMORY_POLICY_DEFAULT). Pass MEMORY_POLICY_DEFAULT by default -- no changes in behavior. We could extend xc_domain_memory_mapping, but QEMU makes use of it, so it is easier and less disruptive to introduce a new libxc function and change the implementation of xc_domain_memory_mapping to call into it. Signed-off-by: Stefano Stabellini CC: ian.jackson@eu.citrix.com CC: wei.liu2@citrix.com --- Changes in v2: - rename cache_policy to memory policy - rename MEMORY_POLICY_DEVMEM to MEMORY_POLICY_ARM_DEV_nGRE - rename MEMORY_POLICY_MEMORY to MEMORY_POLICY_ARM_MEM_WB - introduce xc_domain_mem_map_policy --- tools/libxc/include/xenctrl.h | 8 ++++++++ tools/libxc/xc_domain.c | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 538007a6dc..64bd98d5fe 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1713,6 +1713,14 @@ int xc_deassign_dt_device(xc_interface *xch, uint32_t domid, char *path); =20 +int xc_domain_mem_map_policy(xc_interface *xch, + uint32_t domid, + unsigned long first_gfn, + unsigned long first_mfn, + unsigned long nr_mfns, + uint32_t add_mapping, + uint32_t memory_policy); + int xc_domain_memory_mapping(xc_interface *xch, uint32_t domid, unsigned long first_gfn, diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 8531298563..02f5778212 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -2042,13 +2042,14 @@ failed: return -1; } =20 -int xc_domain_memory_mapping( +int xc_domain_mem_map_policy( xc_interface *xch, uint32_t domid, unsigned long first_gfn, unsigned long first_mfn, unsigned long nr_mfns, - uint32_t add_mapping) + uint32_t add_mapping, + uint32_t memory_policy) { DECLARE_DOMCTL; xc_dominfo_t info; @@ -2070,7 +2071,7 @@ int xc_domain_memory_mapping( domctl.cmd =3D XEN_DOMCTL_memory_mapping; domctl.domain =3D domid; domctl.u.memory_mapping.add_mapping =3D add_mapping; - domctl.u.memory_mapping.memory_policy =3D 0; + domctl.u.memory_mapping.memory_policy =3D memory_policy; max_batch_sz =3D nr_mfns; do { @@ -2106,8 +2107,9 @@ int xc_domain_memory_mapping( * Errors here are ignored. */ if ( ret && add_mapping !=3D DPCI_REMOVE_MAPPING ) - xc_domain_memory_mapping(xch, domid, first_gfn, first_mfn, nr_mfns, - DPCI_REMOVE_MAPPING); + xc_domain_mem_map_policy(xch, domid, first_gfn, first_mfn, nr_mfns, + DPCI_REMOVE_MAPPING, + MEMORY_POLICY_DEFAULT); =20 /* We might get E2BIG so many times that we never advance. */ if ( !done && !ret ) @@ -2116,6 +2118,19 @@ int xc_domain_memory_mapping( return ret; } =20 +int xc_domain_memory_mapping( + xc_interface *xch, + uint32_t domid, + unsigned long first_gfn, + unsigned long first_mfn, + unsigned long nr_mfns, + uint32_t add_mapping) +{ + return xc_domain_mem_map_policy(xch, domid, first_gfn, first_mfn, + nr_mfns, add_mapping, + MEMORY_POLICY_DEFAULT); +} + int xc_domain_ioport_mapping( xc_interface *xch, uint32_t domid, --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 18:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900124; cv=none; d=zoho.com; s=zohoarc; b=cz6NPNbQHh1w6LMM20LiITgA/re6B9FPBtSZA6ZrAmrYKL5cpYtSRWJPs9QUeqh6hVqu6o5i9WQce4bRmIsMocgq2cCkFFZusH57edyG6WHLcI5cHshXSyBKBXeVReo8d6QIyZVv9Rfb3oZnn32H/ixkFDKlpi+tp8lTgJSHqOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900124; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5/IT2qyynt9WTDaekYEv+S5Blpu7NwabU+P8zLEmfsE=; b=CXsKFcBuTbci3DEG0Df2iveNNuW2xQSdUvW6ylj0uxkX4Sfy/T2HVvOpjTr511jE/9wc+PGZkOBkaNumvsUW9plevp/qLx2UAOwtgIqcg5U6yvMTm22NXkQpib/jUTFnkNlZoawWy1pDO9St4EGJt4TxYRrwhjj6B4wsnouZswY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900124209942.6891150808989; Tue, 18 Jun 2019 16:22:04 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOu-0004sh-HA; Tue, 18 Jun 2019 23:20:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004s1-1r for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:27 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a723a48a-921f-11e9-8118-f3a670875dcd; Tue, 18 Jun 2019 23:20:26 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F9C1214AF; Tue, 18 Jun 2019 23:20:25 +0000 (UTC) X-Inumbo-ID: a723a48a-921f-11e9-8118-f3a670875dcd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900025; bh=HkXCY7hv5J3WXPS9KxQulFJeApct47ijpI8oixCxGVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hxqafs8npeMOI045aBD8L80jhBhH2Hn/JV2Pe4h1hGXsiBQIWk8eqeq5gax5V1LKR KjaMsHkxO+0nK8N48S3eZ11LDTyt2cB43u+BuOujczy3UHJApWw+MdR9Fg5Z1UvYw1 76X7cStgtHRPYyvQV8wTzJLuFjDDCQvKoVYR1ljU= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:18 -0700 Message-Id: <20190618232019.26425-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 4/5] libxl/xl: add memory policy option to iomem X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, ian.jackson@eu.citrix.com, wei.liu2@citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add a new memory policy option for the iomem parameter. Possible values are: - arm_dev_nGnRE, Device-nGnRE, the default on ARM - arm_mem_WB, WB cachable memory - x86_UC_minus: uncachable memory, the default on x86 Store the parameter in a new field in libxl_iomem_range. Pass the memory policy option to xc_domain_mem_map_policy. Do the libxl to libxc value conversion in per-arch functions so that we can return error for x86 parameters on Arm architectures and vice versa. Signed-off-by: Stefano Stabellini CC: ian.jackson@eu.citrix.com CC: wei.liu2@citrix.com --- Andrew suggested to remove MEMORY_POLICY_X86_UC_MINUS and x86_UC_minus completely. If that's the consensus I am happy to respin the series removing code. Changes in v3: - s/nGRE/nGnRE/g - s/LIBXL_MEMORY_POLICY_ARM_DEV_NGRE/LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE/g - s/arm_devmem/arm_dev_nGnRE/g - s/arm_memory/arm_mem_WB/g - improve commit message - improve man page - s/MEMORY_POLICY_X86_UC/MEMORY_POLICY_X86_UC_MINUS/g - s/x86_uc/x86_UC_minus/g - move security support clarification to a separate patch Changes in v2: - add #define LIBXL_HAVE_MEMORY_POLICY - ability to part the memory policy parameter even if gfn is not passed - rename cache_policy to memory policy - rename MEMORY_POLICY_DEVMEM to MEMORY_POLICY_ARM_DEV_nGRE - rename MEMORY_POLICY_MEMORY to MEMORY_POLICY_ARM_MEM_WB - rename memory to arm_memory and devmem to arm_devmem - expand the non-security support status to non device passthrough iomem configurations - rename iomem options - add x86 specific iomem option --- docs/man/xl.cfg.5.pod.in | 10 +++++++++- tools/libxl/libxl.h | 5 +++++ tools/libxl/libxl_arch.h | 3 +++ tools/libxl/libxl_arm.c | 14 ++++++++++++++ tools/libxl/libxl_create.c | 12 ++++++++++-- tools/libxl/libxl_types.idl | 9 +++++++++ tools/libxl/libxl_x86.c | 12 ++++++++++++ tools/xl/xl_parse.c | 22 +++++++++++++++++++++- 8 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index c99d40307e..fbb9e43e9e 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1222,7 +1222,7 @@ is given in hexadecimal format and may either be a ra= nge, e.g. C<2f8-2ff> It is recommended to only use this option for trusted VMs under administrator's control. =20 -=3Ditem B +=3Ditem B =20 Allow auto-translated domains to access specific hardware I/O memory pages. =20 @@ -1233,6 +1233,14 @@ B is not specified, the mapping will be perform= ed using B as a start in the guest's address space, therefore performing a 1:1 mapping by default. All of these values must be given in hexadecimal format. +B for ARM platforms: + - "arm_dev_nGnRE" for Device-nGnRE (Device Memory on Armv7), the default= on ARM + - "arm_mem_WB" for Outer Shareable Write-Back Cacheable Memory +They select the stage-2 memory attributes, but note that the resulting +memory attributes will be a combination of stage-2 and stage-1 memory +attributes: it will be the strongest between the 2 stages attributes. +B can be for x86 platforms: + - "x86_UC_minus" for Uncachable Memory, the default on x86 =20 Note that the IOMMU won't be updated with the mappings specified with this option. This option therefore should not be used to pass through any diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 9bacfb97f0..cf12f1d3bd 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -378,6 +378,11 @@ #define LIBXL_HAVE_BUILDINFO_BOOTLOADER 1 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER_ARGS 1 =20 +/* + * Support specifying memory policy information for memory mappings. + */ +#define LIBXL_HAVE_MEMORY_POLICY 1 + /* * LIBXL_HAVE_EXTENDED_VKB indicates that libxl_device_vkb has extended fi= elds: * - unique_id; diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h index d624159e53..9c858b06ce 100644 --- a/tools/libxl/libxl_arch.h +++ b/tools/libxl/libxl_arch.h @@ -77,6 +77,9 @@ int libxl__arch_extra_memory(libxl__gc *gc, const libxl_domain_build_info *info, uint64_t *out); =20 +_hidden +int libxl__memory_policy_to_xc(libxl_memory_policy c); + #if defined(__i386__) || defined(__x86_64__) =20 #define LAPIC_BASE_ADDRESS 0xfee00000 diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 141e159043..6354b852dc 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -1149,6 +1149,20 @@ void libxl__arch_domain_build_info_setdefault(libxl_= _gc *gc, libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PVH); } =20 +int libxl__memory_policy_to_xc(libxl_memory_policy c) +{ + switch (c) { + case LIBXL_MEMORY_POLICY_ARM_MEM_WB: + return MEMORY_POLICY_ARM_MEM_WB; + case LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE: + return MEMORY_POLICY_ARM_DEV_nGnRE; + case LIBXL_MEMORY_POLICY_DEFAULT: + return MEMORY_POLICY_DEFAULT; + default: + return ERROR_INVAL; + } +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 03ce166f4f..84da6406d0 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1357,6 +1357,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libx= l__multidev *multidev, =20 for (i =3D 0; i < d_config->b_info.num_iomem; i++) { libxl_iomem_range *io =3D &d_config->b_info.iomem[i]; + int memory_policy; =20 LOGD(DEBUG, domid, "iomem %"PRIx64"-%"PRIx64, io->start, io->start + io->number - 1); @@ -1370,9 +1371,16 @@ static void domcreate_launch_dm(libxl__egc *egc, lib= xl__multidev *multidev, ret =3D ERROR_FAIL; goto error_out; } - ret =3D xc_domain_memory_mapping(CTX->xch, domid, + memory_policy =3D libxl__memory_policy_to_xc(io->memory_policy); + if (memory_policy < 0) { + LOGED(ERROR, domid, + "invalid memory policy %u", io->memory_policy); + ret =3D ERROR_FAIL; + goto error_out; + } + ret =3D xc_domain_mem_map_policy(CTX->xch, domid, io->gfn, io->start, - io->number, 1); + io->number, 1, memory_policy); if (ret < 0) { LOGED(ERROR, domid, "failed to map to domain iomem range %"PRIx64"-%"PRIx64 diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index b61399ce36..bd791d338d 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -272,6 +272,13 @@ libxl_ioport_range =3D Struct("ioport_range", [ ("number", uint32), ]) =20 +libxl_memory_policy =3D Enumeration("memory_policy", [ + (0, "default"), + (1, "ARM_Dev_nGnRE"), + (2, "ARM_Mem_WB"), + (3, "x86_UC_MINUS"), + ], init_val =3D "LIBXL_MEMORY_POLICY_DEFAULT") + libxl_iomem_range =3D Struct("iomem_range", [ # start host frame number to be mapped to the guest ("start", uint64), @@ -279,6 +286,8 @@ libxl_iomem_range =3D Struct("iomem_range", [ ("number", uint64), # guest frame number used as a start for the mapping ("gfn", uint64, {'init_val': "LIBXL_INVALID_GFN"}), + # memory_policy of the memory region + ("memory_policy", libxl_memory_policy), ]) =20 libxl_vga_interface_info =3D Struct("vga_interface_info", [ diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index c0f88a7eaa..c7c0ad9218 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -631,6 +631,18 @@ void libxl__arch_domain_build_info_setdefault(libxl__g= c *gc, libxl_defbool_setdefault(&b_info->acpi, true); } =20 +int libxl__memory_policy_to_xc(libxl_memory_policy c) +{ + switch (c) { + case LIBXL_MEMORY_POLICY_X86_UC_MINUS: + return MEMORY_POLICY_X86_UC_MINUS; + case LIBXL_MEMORY_POLICY_DEFAULT: + return MEMORY_POLICY_DEFAULT; + default: + return ERROR_INVAL; + } +} + /* * Local variables: * mode: C diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index e105bda2bb..46525f40f5 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1883,6 +1883,7 @@ void parse_config_data(const char *config_source, } for (i =3D 0; i < num_iomem; i++) { int used; + const char *mempolicy; =20 buf =3D xlu_cfg_get_listitem (iomem, i); if (!buf) { @@ -1895,11 +1896,30 @@ void parse_config_data(const char *config_source, &b_info->iomem[i].start, &b_info->iomem[i].number, &used, &b_info->iomem[i].gfn, &used); - if (ret < 2 || buf[used] !=3D '\0') { + if (ret < 2) { fprintf(stderr, "xl: Invalid argument parsing iomem: %s\n", buf); exit(1); } + mempolicy =3D &buf[used]; + if (strlen(mempolicy) > 1) { + mempolicy++; + if (!strcmp(mempolicy, "arm_dev_nGnRE")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE; + else if (!strcmp(mempolicy, "x86_UC_minus")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_X86_UC_MINUS; + else if (!strcmp(mempolicy, "arm_mem_WB")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_ARM_MEM_WB; + else { + fprintf(stderr, + "xl: Invalid iomem memory policy parameter: %s= \n", + mempolicy); + exit(1); + } + } } } =20 --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 18:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900123; cv=none; d=zoho.com; s=zohoarc; b=SD2Phlvt5nELxt2f5oEGDpmfKh2G7tj7G1I901/odJIGqLHcyIisnxAqNTlk+LNg9uEcdE7rfNqb3kHiozctpb+5t82DHBJwfexbkNfK8dVZxIO+lpJG1fV9QRcIFY69LH/FMppcR1ZOLA6WSOzhPNZ7JFLAcwmyNueMbZZ5eoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900123; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wq0b6L9XxGDeS5HZIGeMbLnB9Uy3l2phH6OwdKnDlIM=; b=J4XAFGHhwPCoGgmI3Wka/hhLY2AIrNgNFwUYm7X9QQHh+wNrO69/ts5AF+hMwedZViFnX6VtjUDO0ewkeFfb6jSdoEm7AgeSw1vEsa2qtk2FNYbcaWYu2uVudxNabdZitZ5flHpIYhC5WUISh9lB6kRPUWmL4t9wTi1tFvMadVY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900123178873.8799111580028; Tue, 18 Jun 2019 16:22:03 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOw-0004tt-3Y; Tue, 18 Jun 2019 23:20:30 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004sM-VW for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:28 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id a76e26e1-921f-11e9-8980-bc764e045a96; Tue, 18 Jun 2019 23:20:26 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A91C621530; Tue, 18 Jun 2019 23:20:25 +0000 (UTC) X-Inumbo-ID: a76e26e1-921f-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900026; bh=GwEyAjT+Br4GmpstYguJ2DQHzeu78DBIV+5LF7N2vbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSevXbgbMVp2mTcYMW61MlU2kdFMQc1sR18u44u3cWrwkX9Esyfd8I/AyBwqADcEB l4krxPv9Q/Q2e8wVw74ZM8CVUf+c6CyRBnWeJ4Q83YL4bX85QI4X13WuLEKX5Rv2Ed 0d7/G6mGgl+CVyDLGmWkcvfJ3rWqc3lvF/TrDn5I= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:19 -0700 Message-Id: <20190618232019.26425-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 5/5] xen/arm: clarify the support status of iomem configurations X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, wei.liu2@citrix.com, konrad.wilk@oracle.com, andrew.cooper3@citrix.com, tim@xen.org, julien.grall@arm.com, JBeulich@suse.com, ian.jackson@eu.citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) iomem settings fall under the broader category of "Non-PCI device passthrough": they are not security supported. Make it clearer. Signed-off-by: Stefano Stabellini CC: tim@xen.org CC: konrad.wilk@oracle.com CC: Julien Grall CC: JBeulich@suse.com CC: andrew.cooper3@citrix.com CC: ian.jackson@eu.citrix.com CC: wei.liu2@citrix.com --- SUPPORT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SUPPORT.md b/SUPPORT.md index 375473a456..bc6fb58e04 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -639,7 +639,7 @@ to be used in addition to QEMU. =20 Status: Experimental =20 -### ARM/Non-PCI device passthrough +### ARM/Non-PCI device passthrough and other iomem configurations =20 Status: Supported, not security supported =20 --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel