From patchwork Mon Oct 2 12:59:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 114596 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp653293qgn; Mon, 2 Oct 2017 06:01:49 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBkKScAt73Zu33KvsG8j+yIPQknHzIqSII8ZHu5+N08+Pxiip+/yIphhjpqC5tVp9NxKSPI X-Received: by 10.107.133.92 with SMTP id h89mr22386853iod.208.1506949308920; Mon, 02 Oct 2017 06:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506949308; cv=none; d=google.com; s=arc-20160816; b=VMZ4jf2IsCm8EvqNoMtfHSAGX6hmAVHFBudwYbEB1Dh873gQQkLA4YBSbbtMjr07GR QE/oEjAW6SdIzAQx8Qg+wpZB07ik46Z0DdR9RjfTE/zxHql1Sib7t6fZvHaD3rh3uf1s gKOX3tVaZD35RtZ1R3xoc+yJidlX9tH7sD3WVWZx4KUYfgZWpZqyJRBgXArJpr5b5XdE mLDfil/9CYdofpfmmY99sMU1DXaQ6AbPM6ocAFsDWN1Jkjg/wlIlce7YXUQpUH+li7x7 gNWjxGYEGpr6t0vgNWWb5S0dZWbeGWNX8MNiJPiR5krQBSlAxp/gFwxOGRqg3cX4aP5B a4xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=aHqYx53WIOVM+H5d1/6NrRPssX9kFk0VDuOriJQS32c=; b=UVZKUt/5EcYe7WpIvfX4v8otPgDpNgr7o895XrY43HKs40HKCEszB/LEvtmctnWPX3 O+BGNlUKSDv/18pou77Aw4uFDD0+XbDiHDNe6G3ROqEnCn9tmFI3XLsx+WIBBR3MXHB6 Fqkd4lFofZAzkU0UsfX8nEQthxmoHgl6oYN+Z7cs5VXTVsklDsMzqmqWgryHJcPxXA9f czmHvVimQmjqoXbF7xW+SMxw1JApapuDm+tdyJE0aTuq4wxWkj/xDg6iIRj0wWFg9bkH En++Z5/9HRZb5nv6v+ajSeIfbi0DzdZ6NgLzHzZ2mNDF4F5X1iw5aW66oBwwYSt8E7NJ 1Dgg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q185si8856504itc.206.2017.10.02.06.01.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 06:01:48 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dz0KS-0004JC-GF; Mon, 02 Oct 2017 13:00:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dz0KR-0004Fl-4q for xen-devel@lists.xen.org; Mon, 02 Oct 2017 13:00:11 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 52/BF-03422-A5832D95; Mon, 02 Oct 2017 13:00:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRWlGSWpSXmKPExsVysyfVTTfM4lK kwddpphZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8afnotsBWcMKmacesDawPhFqYuRi0NIYDOj xL6pUxghnNOMEhOnbGXrYuTkYBPQlLjz+RMTiC0iIC1x7fNlsCJmgcWMEp/39zKDJIQFgiRat /cB2RwcLAKqEq1zTEHCvAJWEmdbH4DNkRCQl9jVdpEVxOYEir8//hHMFhKwlDjePYlpAiP3Ak aGVYzqxalFZalFupZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiB/mUAgh2Mdzc FHGKU5GBSEuVlNrwUKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCV8McKCdYlJqeWpGWmQMMNJi0 BAePkgivKUiat7ggMbc4Mx0idYrRmOPHpCt/mDg6bt79wyTEkpeflyolzlsBUioAUppRmgc3C BYBlxhlpYR5GYFOE+IpSC3KzSxBlX/FKM7BqCTM6wIyhSczrwRu3yugU5iATpnTdQHklJJEhJ RUAyM7s3bjobf+dyWfL2Nev/lFNKt/3N97dXHLH095rB5clnbh3T2n6yvXXdwUWfl1evW5yI+ f0zq0ta46t8qtePY0p9zy+HSn+McZPg1fl/jdmb6w69jWgKIZLb0pGx7Nj9q80HFyWcAOpRum 63dEHZ1409Og90Jc9NpgAY2G7aemPoiZWJbGveCNEktxRqKhFnNRcSIAW82IoXsCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1506949206!118733092!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 37781 invoked from network); 2 Oct 2017 13:00:06 -0000 Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-27.messagelabs.com with SMTP; 2 Oct 2017 13:00:06 -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 0BE61165D; Mon, 2 Oct 2017 06:00:06 -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 F10163F53D; Mon, 2 Oct 2017 06:00:04 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 2 Oct 2017 13:59:38 +0100 Message-Id: <20171002125941.11274-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171002125941.11274-1-julien.grall@arm.com> References: <20171002125941.11274-1-julien.grall@arm.com> Cc: George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v3 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" 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 Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Changes in v3: - Add Wei's reviewed-by 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 6581f8d82f..668c484a75 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); } }