From patchwork Tue Jun 14 12:07:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9175693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 849EE60772 for ; Tue, 14 Jun 2016 12:09:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7521124151 for ; Tue, 14 Jun 2016 12:09:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69F5627E78; Tue, 14 Jun 2016 12:09:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AABDD24151 for ; Tue, 14 Jun 2016 12:09:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCn7w-0004wr-N8; Tue, 14 Jun 2016 12:07:28 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCn7v-0004vY-Gq for xen-devel@lists.xen.org; Tue, 14 Jun 2016 12:07:27 +0000 Received: from [193.109.254.147] by server-2.bemta-14.messagelabs.com id 93/C5-26430-E73FF575; Tue, 14 Jun 2016 12:07:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsVysyfVTbfuc3y 4we3ZLBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8av/Z3MBetjKn4dPszUwNhq38XIxSEksIlR YtWE7YwQzmlGia6GZUxdjJwcbAKaEnc+fwKzRQSkJa59vgxWxCzwgkliwpHbLCAJYQFficcrf jOD2CwCqhLHDk1mA7F5BVwklh4+A9YsISAncfLYZNYuRg4OTgFXibtThEHCQkAlM1tmMU5g5F 7AyLCKUb04tagstUjXRC+pKDM9oyQ3MTNH19DQRC83tbg4MT01JzGpWC85P3cTI9C/DECwg3H FQudDjJIcTEqivLcnxocL8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuBd8gkoJ1iUmp5akZaZAww0 mLQEB4+SCO8jkDRvcUFibnFmOkTqFKMux6oFN9YyCbHk5eelSonzbgQpEgApyijNgxsBC/pLj LJSwryMQEcJ8RSkFuVmlqDKv2IU52BUEuZ9DjKFJzOvBG7TK6AjmICOsJkOdkRJIkJKqoGx4u PTI2ril17pbO8JZ3ikKLxP8ceVdXtSeBLtLq7Qc7eOOGV+9G7q6TclXc6NYfZGuzaZe1nPidk 4Y37p9Qn/7XLn1XDZ+q7IlZZeXr51VVXNqYm/st/5ZnMViL4/teaWannn3S62IyZNP0Nls2c2 GQssiPSLKSs8I3r5v5X+FLEHTHMPH56sxFKckWioxVxUnAgAhYu8THUCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1465906045!43940171!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47727 invoked from network); 14 Jun 2016 12:07:25 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-8.tower-27.messagelabs.com with SMTP; 14 Jun 2016 12:07:25 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0680A2A2; Tue, 14 Jun 2016 05:08:05 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.215.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 140BE3F246; Tue, 14 Jun 2016 05:07:22 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 14 Jun 2016 13:07:04 +0100 Message-Id: <1465906027-16614-6-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465906027-16614-1-git-send-email-julien.grall@arm.com> References: <1465906027-16614-1-git-send-email-julien.grall@arm.com> Cc: sstabellini@kernel.org, Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , wei.chen@linaro.org Subject: [Xen-devel] [PATCH 5/8] xen: Use the typesafe mfn and gfn in map_mmio_regions... X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP to avoid mixing machine frame with guest frame. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Cc: Stefano Stabellini Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu --- xen/arch/arm/domain_build.c | 4 ++-- xen/arch/arm/gic-v2.c | 4 ++-- xen/arch/arm/p2m.c | 22 +++++++++++----------- xen/arch/arm/platforms/exynos5.c | 8 ++++---- xen/arch/arm/platforms/omap5.c | 16 ++++++++-------- xen/arch/arm/vgic-v2.c | 4 ++-- xen/arch/x86/mm/p2m.c | 18 ++++++++++-------- xen/common/domctl.c | 4 ++-- xen/include/xen/p2m-common.h | 8 ++++---- 9 files changed, 45 insertions(+), 43 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 02b4539..865539a 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1042,9 +1042,9 @@ static int map_range_to_domain(const struct dt_device_node *dev, if ( need_mapping ) { res = map_mmio_regions(d, - paddr_to_pfn(addr), + _gfn(paddr_to_pfn(addr)), DIV_ROUND_UP(len, PAGE_SIZE), - paddr_to_pfn(addr)); + _mfn(paddr_to_pfn(addr))); if ( res < 0 ) { printk(XENLOG_ERR "Unable to map 0x%"PRIx64 diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 2c1c0ba..58917c8 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -601,9 +601,9 @@ static int gicv2_map_hwdown_extra_mappings(struct domain *d) d->domain_id, v2m_data->addr, v2m_data->size, v2m_data->spi_start, v2m_data->nr_spis); - ret = map_mmio_regions(d, paddr_to_pfn(v2m_data->addr), + ret = map_mmio_regions(d, _gfn(paddr_to_pfn(v2m_data->addr)), DIV_ROUND_UP(v2m_data->size, PAGE_SIZE), - paddr_to_pfn(v2m_data->addr)); + _mfn(paddr_to_pfn(v2m_data->addr))); 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 decec0d..4831cf1 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1243,27 +1243,27 @@ int unmap_regions_rw_cache(struct domain *d, } int map_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn) + mfn_t mfn) { return apply_p2m_changes(d, INSERT, - pfn_to_paddr(start_gfn), - pfn_to_paddr(start_gfn + nr), - pfn_to_paddr(mfn), + pfn_to_paddr(gfn_x(start_gfn)), + pfn_to_paddr(gfn_x(start_gfn) + nr), + pfn_to_paddr(mfn_x(mfn)), MATTR_DEV, 0, p2m_mmio_direct, d->arch.p2m.default_access); } int unmap_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn) + mfn_t mfn) { return apply_p2m_changes(d, REMOVE, - pfn_to_paddr(start_gfn), - pfn_to_paddr(start_gfn + nr), - pfn_to_paddr(mfn), + pfn_to_paddr(gfn_x(start_gfn)), + pfn_to_paddr(gfn_x(start_gfn) + nr), + pfn_to_paddr(mfn_x(mfn)), MATTR_DEV, 0, p2m_invalid, d->arch.p2m.default_access); } @@ -1278,7 +1278,7 @@ int map_dev_mmio_region(struct domain *d, if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) ) return 0; - res = map_mmio_regions(d, start_gfn, nr, mfn); + res = map_mmio_regions(d, _gfn(start_gfn), nr, _mfn(mfn)); if ( res < 0 ) { printk(XENLOG_G_ERR "Unable to map [%#lx - %#lx] in Dom%d\n", diff --git a/xen/arch/arm/platforms/exynos5.c b/xen/arch/arm/platforms/exynos5.c index bf4964d..c43934f 100644 --- a/xen/arch/arm/platforms/exynos5.c +++ b/xen/arch/arm/platforms/exynos5.c @@ -83,12 +83,12 @@ static int exynos5_init_time(void) static int exynos5250_specific_mapping(struct domain *d) { /* Map the chip ID */ - map_mmio_regions(d, paddr_to_pfn(EXYNOS5_PA_CHIPID), 1, - paddr_to_pfn(EXYNOS5_PA_CHIPID)); + map_mmio_regions(d, _gfn(paddr_to_pfn(EXYNOS5_PA_CHIPID)), 1, + _mfn(paddr_to_pfn(EXYNOS5_PA_CHIPID))); /* Map the PWM region */ - map_mmio_regions(d, paddr_to_pfn(EXYNOS5_PA_TIMER), 2, - paddr_to_pfn(EXYNOS5_PA_TIMER)); + map_mmio_regions(d, _gfn(paddr_to_pfn(EXYNOS5_PA_TIMER)), 2, + _mfn(paddr_to_pfn(EXYNOS5_PA_TIMER))); return 0; } diff --git a/xen/arch/arm/platforms/omap5.c b/xen/arch/arm/platforms/omap5.c index a49ba62..539588e 100644 --- a/xen/arch/arm/platforms/omap5.c +++ b/xen/arch/arm/platforms/omap5.c @@ -102,20 +102,20 @@ static int omap5_init_time(void) static int omap5_specific_mapping(struct domain *d) { /* Map the PRM module */ - map_mmio_regions(d, paddr_to_pfn(OMAP5_PRM_BASE), 2, - paddr_to_pfn(OMAP5_PRM_BASE)); + map_mmio_regions(d, _gfn(paddr_to_pfn(OMAP5_PRM_BASE)), 2, + _mfn(paddr_to_pfn(OMAP5_PRM_BASE))); /* Map the PRM_MPU */ - map_mmio_regions(d, paddr_to_pfn(OMAP5_PRCM_MPU_BASE), 1, - paddr_to_pfn(OMAP5_PRCM_MPU_BASE)); + map_mmio_regions(d, _gfn(paddr_to_pfn(OMAP5_PRCM_MPU_BASE)), 1, + _mfn(paddr_to_pfn(OMAP5_PRCM_MPU_BASE))); /* Map the Wakeup Gen */ - map_mmio_regions(d, paddr_to_pfn(OMAP5_WKUPGEN_BASE), 1, - paddr_to_pfn(OMAP5_WKUPGEN_BASE)); + map_mmio_regions(d, _gfn(paddr_to_pfn(OMAP5_WKUPGEN_BASE)), 1, + _mfn(paddr_to_pfn(OMAP5_WKUPGEN_BASE))); /* Map the on-chip SRAM */ - map_mmio_regions(d, paddr_to_pfn(OMAP5_SRAM_PA), 32, - paddr_to_pfn(OMAP5_SRAM_PA)); + map_mmio_regions(d, _gfn(paddr_to_pfn(OMAP5_SRAM_PA)), 32, + _mfn(paddr_to_pfn(OMAP5_SRAM_PA))); return 0; } diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c index 9adb4a9..cbe61cf 100644 --- a/xen/arch/arm/vgic-v2.c +++ b/xen/arch/arm/vgic-v2.c @@ -688,8 +688,8 @@ static int vgic_v2_domain_init(struct domain *d) * Map the gic virtual cpu interface in the gic cpu interface * region of the guest. */ - ret = map_mmio_regions(d, paddr_to_pfn(cbase), csize / PAGE_SIZE, - paddr_to_pfn(vbase)); + ret = map_mmio_regions(d, _gfn(paddr_to_pfn(cbase)), csize / PAGE_SIZE, + _mfn(paddr_to_pfn(vbase))); if ( ret ) return ret; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index faf6e13..070efd4 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2202,9 +2202,9 @@ static unsigned int mmio_order(const struct domain *d, #define MAP_MMIO_MAX_ITER 64 /* pretty arbitrary */ int map_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn) + mfn_t mfn) { int ret = 0; unsigned long i; @@ -2217,10 +2217,11 @@ int map_mmio_regions(struct domain *d, i += 1UL << order, ++iter ) { /* OR'ing gfn and mfn values will return an order suitable to both. */ - for ( order = mmio_order(d, (start_gfn + i) | (mfn + i), nr - i); ; + for ( order = mmio_order(d, (gfn_x(start_gfn) + i) | (mfn_x(mfn) + i), nr - i); ; order = ret - 1 ) { - ret = set_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i), order, + ret = set_mmio_p2m_entry(d, gfn_x(start_gfn) + i, + _mfn(mfn_x(mfn) + i), order, p2m_get_hostp2m(d)->default_access); if ( ret <= 0 ) break; @@ -2234,9 +2235,9 @@ int map_mmio_regions(struct domain *d, } int unmap_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn) + mfn_t mfn) { int ret = 0; unsigned long i; @@ -2249,10 +2250,11 @@ int unmap_mmio_regions(struct domain *d, i += 1UL << order, ++iter ) { /* OR'ing gfn and mfn values will return an order suitable to both. */ - for ( order = mmio_order(d, (start_gfn + i) | (mfn + i), nr - i); ; + for ( order = mmio_order(d, (gfn_x(start_gfn) + i) | (mfn_x(mfn) + i), nr - i); ; order = ret - 1 ) { - ret = clear_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i), order); + ret = clear_mmio_p2m_entry(d, gfn_x(start_gfn) + i, + _mfn(mfn_x(mfn) + i), order); if ( ret <= 0 ) break; ASSERT(ret <= order); diff --git a/xen/common/domctl.c b/xen/common/domctl.c index e43904e..b784e6c 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -1074,7 +1074,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n", d->domain_id, gfn, mfn, nr_mfns); - ret = map_mmio_regions(d, gfn, nr_mfns, mfn); + ret = map_mmio_regions(d, _gfn(gfn), nr_mfns, _mfn(mfn)); if ( ret < 0 ) printk(XENLOG_G_WARNING "memory_map:fail: dom%d gfn=%lx mfn=%lx nr=%lx ret:%ld\n", @@ -1086,7 +1086,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n", d->domain_id, gfn, mfn, nr_mfns); - ret = unmap_mmio_regions(d, gfn, nr_mfns, mfn); + ret = unmap_mmio_regions(d, _gfn(gfn), nr_mfns, _mfn(mfn)); if ( ret < 0 && is_hardware_domain(current->domain) ) printk(XENLOG_ERR "memory_map: error %ld removing dom%d access to [%lx,%lx]\n", diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index 6374a5b..b4f9077 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -37,13 +37,13 @@ typedef enum { * * the guest physical address space to map, starting from the machine * * frame number mfn. */ int map_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn); + mfn_t mfn); int unmap_mmio_regions(struct domain *d, - unsigned long start_gfn, + gfn_t start_gfn, unsigned long nr, - unsigned long mfn); + mfn_t mfn); /* * Set access type for a region of gfns.