From nobody Tue Nov 11 13:18:03 2025 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