From patchwork Wed Sep 13 17:59:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9951803 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 317696038F for ; Wed, 13 Sep 2017 18:02:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23B5728C1C for ; Wed, 13 Sep 2017 18:02:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 181D328C32; Wed, 13 Sep 2017 18:02:37 +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 977D628C1C for ; Wed, 13 Sep 2017 18:02:36 +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 1dsBxV-00082C-32; Wed, 13 Sep 2017 18:00:21 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsBxT-0007y5-KD for xen-devel@lists.xen.org; Wed, 13 Sep 2017 18:00:19 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 98/46-03414-33279B95; Wed, 13 Sep 2017 18:00:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRWlGSWpSXmKPExsVysyfVTdeoaGe kwa25YhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8b1g2vYC1r1K/oW72JsYLyr2MXIxSEksJlR 4lzLelYI5zSjxMHJX5i6GDk52AQ0Je58/gRmiwhIS1z7fJkRpIhZYDGjxOf9vcwgCWEBf4mNK 5axg9gsAqoSSw+vZwGxeQWsJG5/uAsWlxCQl9jVdpEVxOYEis/8ugBoKAfQNkuJ0z1RExi5Fz AyrGJUL04tKkst0jXTSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87P3cQI9C8DEOxgnHf C/xCjJAeTkijvXt2dkUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeCUKgXKCRanpqRVpmTnAQINJ S3DwKInwaoOkeYsLEnOLM9MhUqcYjTl+TLryh4mj4+bdP0xCLHn5ealS4rzrC4BKBUBKM0rz4 AbBIuASo6yUMC8j0GlCPAWpRbmZJajyrxjFORiVhHn1QBbyZOaVwO17BXQKE9ApZ07vADmlJB EhJdXAyFL9+8Anw2lnrSf+X3GX2V461z1+rerpnde74/cXCa6Umba87sXN9Q+uXNnXtJtljcB xEcejKVo+WXvOSc0MW7m9rmTDpAP/96fWts/80vrpc3bDd7n0t6qbdbWSd210nb1PkUHoo8DM 7wkrpwbsasjh33g056nu98ffSo+pPswJPMEQvipn5l4lluKMREMt5qLiRAA5ES6QewIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1505325617!82745263!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 35541 invoked from network); 13 Sep 2017 18:00:18 -0000 Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-21.messagelabs.com with SMTP; 13 Sep 2017 18:00:18 -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 8184516A0; Wed, 13 Sep 2017 11:00:17 -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 6FEF03F483; Wed, 13 Sep 2017 11:00:16 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 13 Sep 2017 18:59:50 +0100 Message-Id: <20170913175953.16942-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170913175953.16942-1-julien.grall@arm.com> References: <20170913175953.16942-1-julien.grall@arm.com> Cc: George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH 12/15] 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 --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper --- 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); } }