From patchwork Thu Sep 21 12:40:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9963839 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 67F886056A for ; Thu, 21 Sep 2017 12:43:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C6CD294C5 for ; Thu, 21 Sep 2017 12:43:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51827294C9; Thu, 21 Sep 2017 12:43:19 +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 D014C294C5 for ; Thu, 21 Sep 2017 12:43:18 +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 1dv0ms-0001Qt-Mw; Thu, 21 Sep 2017 12:41:02 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0mr-0001PW-SS for xen-devel@lists.xen.org; Thu, 21 Sep 2017 12:41:01 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id BD/C6-02224-D53B3C95; Thu, 21 Sep 2017 12:41:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrFLMWRWlGSWpSXmKPExsVysyfVTTdm8+F Ig3XnFCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ox5G26wFrzVr+i+OomxgXGtUhcjF4eQwGZG iUdP7zNCOKcZJRa/agRyODnYBDQl7nz+xARiiwhIS1z7fBmsiFlgMaPE5/29zCAJYYEgicVXZ 7GC2CwCqhLv2teBNfAKWEpsmd0FZksIyEvsarsIVsMJFG87/A3MFhKwkPg14QTrBEbuBYwMqx g1ilOLylKLdI2M9JKKMtMzSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAn1cz8DAuINx6gm /Q4ySHExKorzv1h2OFOJLyk+pzEgszogvKs1JLT7EKMPBoSTBG7AJKCdYlJqeWpGWmQMMNpi0 BAePkgjvhI1Aad7igsTc4sx0iNQpRmOOH5Ou/GHi6Lh59w+TEEtefl6qlDivOcgkAZDSjNI8u EGwKLjEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZj3OchCnsy8Erh9r4BOYQI6JXvDAZBTSh IRUlINjMUHmMsPRRtedZ5WfTkn48TOigmdx47+jDKxiY7j3Rw/YX/A+8r1+W9b/3LGxHasE1O 4aP957UcLpRb5Qvc3r++r1Pe93bRW5mGu8nK1g5Vup88ULTx37enfpLb/l8pNVrUt+7LzjzuL 6gV/obL/zrcuxV6qOn52p967iEXJShUfZ7GtCNEQ7VZiKc5INNRiLipOBABNAojCfQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1505997659!115724330!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26422 invoked from network); 21 Sep 2017 12:41:00 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-31.messagelabs.com with SMTP; 21 Sep 2017 12:41:00 -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 9C8EE1682; Thu, 21 Sep 2017 05:40:59 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D7CF3F58C; Thu, 21 Sep 2017 05:40:58 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 13:40:31 +0100 Message-Id: <20170921124035.2410-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170921124035.2410-1-julien.grall@arm.com> References: <20170921124035.2410-1-julien.grall@arm.com> Cc: George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 12/16] xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_zero_check 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 At the same time make the array gfns const has it is not modified within the function. Signed-off-by: Julien Grall Acked-by: Andrew Cooper Reviewed-by: Wei Liu --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Changes in v2: - Add Andrew's acked-by --- xen/arch/x86/mm/p2m-pod.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 611a087855..0dd0f0a083 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -498,7 +498,7 @@ p2m_pod_offline_or_broken_replace(struct page_info *p) } static int -p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn); +p2m_pod_zero_check_superpage(struct p2m_domain *p2m, gfn_t gfn); /* @@ -582,7 +582,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order) * - not all of the pages were RAM (now knowing order < SUPERPAGE_ORDER) */ if ( steal_for_cache && order < SUPERPAGE_ORDER && ram == (1UL << order) && - p2m_pod_zero_check_superpage(p2m, gfn_x(gfn) & ~(SUPERPAGE_PAGES - 1)) ) + p2m_pod_zero_check_superpage(p2m, _gfn(gfn_x(gfn) & ~(SUPERPAGE_PAGES - 1))) ) { pod = 1UL << order; ram = nonpod = 0; @@ -680,10 +680,9 @@ void p2m_pod_dump_data(struct domain *d) * in the p2m. */ static int -p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn_l) +p2m_pod_zero_check_superpage(struct p2m_domain *p2m, gfn_t gfn) { mfn_t mfn, mfn0 = INVALID_MFN; - gfn_t gfn = _gfn(gfn_l); p2m_type_t type, type0 = 0; unsigned long * map = NULL; int ret=0, reset = 0; @@ -694,7 +693,7 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn_l) ASSERT(pod_locked_by_me(p2m)); - if ( !superpage_aligned(gfn_l) ) + if ( !superpage_aligned(gfn_x(gfn)) ) goto out; /* Allow an extra refcount for one shadow pt mapping in shadowed domains */ @@ -816,7 +815,7 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn_l) int d:16,order:16; } t; - t.gfn = gfn_l; + t.gfn = gfn_x(gfn); t.mfn = mfn_x(mfn); t.d = d->domain_id; t.order = 9; @@ -843,7 +842,7 @@ out: } static void -p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) +p2m_pod_zero_check(struct p2m_domain *p2m, const gfn_t *gfns, int count) { mfn_t mfns[count]; p2m_type_t types[count]; @@ -863,7 +862,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) p2m_access_t a; struct page_info *pg; - mfns[i] = p2m->get_entry(p2m, _gfn(gfns[i]), types + i, &a, + mfns[i] = p2m->get_entry(p2m, gfns[i], types + i, &a, 0, NULL, NULL); pg = mfn_to_page(mfns[i]); @@ -901,7 +900,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) } /* Try to remove the page, restoring old mapping if it fails. */ - p2m_set_entry(p2m, _gfn(gfns[i]), INVALID_MFN, PAGE_ORDER_4K, + p2m_set_entry(p2m, gfns[i], INVALID_MFN, PAGE_ORDER_4K, p2m_populate_on_demand, p2m->default_access); /* @@ -913,7 +912,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) unmap_domain_page(map[i]); map[i] = NULL; - p2m_set_entry(p2m, _gfn(gfns[i]), mfns[i], PAGE_ORDER_4K, + p2m_set_entry(p2m, gfns[i], mfns[i], PAGE_ORDER_4K, types[i], p2m->default_access); continue; @@ -940,7 +939,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) */ if ( j < (PAGE_SIZE / sizeof(*map[i])) ) { - p2m_set_entry(p2m, _gfn(gfns[i]), mfns[i], PAGE_ORDER_4K, + p2m_set_entry(p2m, gfns[i], mfns[i], PAGE_ORDER_4K, types[i], p2m->default_access); } else @@ -952,7 +951,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) int d:16,order:16; } t; - t.gfn = gfns[i]; + t.gfn = gfn_x(gfns[i]); t.mfn = mfn_x(mfns[i]); t.d = d->domain_id; t.order = 0; @@ -973,7 +972,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) static void p2m_pod_emergency_sweep(struct p2m_domain *p2m) { - unsigned long gfns[POD_SWEEP_STRIDE]; + gfn_t gfns[POD_SWEEP_STRIDE]; unsigned long i, j = 0, start, limit; p2m_type_t t; @@ -997,7 +996,7 @@ p2m_pod_emergency_sweep(struct p2m_domain *p2m) (void)p2m->get_entry(p2m, _gfn(i), &t, &a, 0, NULL, NULL); if ( p2m_is_ram(t) ) { - gfns[j] = i; + gfns[j] = _gfn(i); j++; BUG_ON(j > POD_SWEEP_STRIDE); if ( j == POD_SWEEP_STRIDE ) @@ -1039,19 +1038,19 @@ static void pod_eager_reclaim(struct p2m_domain *p2m) do { unsigned int idx = (mrp->idx + i++) % ARRAY_SIZE(mrp->list); - unsigned long gfn = mrp->list[idx]; + gfn_t gfn = _gfn(mrp->list[idx]); - if ( gfn != gfn_x(INVALID_GFN) ) + if ( !gfn_eq(gfn, INVALID_GFN) ) { - if ( gfn & POD_LAST_SUPERPAGE ) + if ( gfn_x(gfn) & POD_LAST_SUPERPAGE ) { - gfn &= ~POD_LAST_SUPERPAGE; + gfn = _gfn(gfn_x(gfn) & ~POD_LAST_SUPERPAGE); if ( p2m_pod_zero_check_superpage(p2m, gfn) == 0 ) { unsigned int x; - for ( x = 0; x < SUPERPAGE_PAGES; ++x, ++gfn ) + for ( x = 0; x < SUPERPAGE_PAGES; ++x, gfn = gfn_add(gfn, 1) ) p2m_pod_zero_check(p2m, &gfn, 1); } }