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: 113245 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp1845967edb; Thu, 21 Sep 2017 05:42:53 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCMLN+C9aOJ33uAQXKnPPcjrhNyHp8NWvgEy3eMzCmh8rSsWrH8nTXL+d+qNC0wk4eRpMmw X-Received: by 10.36.66.138 with SMTP id i132mr1084425itb.93.1505997773768; Thu, 21 Sep 2017 05:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505997773; cv=none; d=google.com; s=arc-20160816; b=EQor0IFiNv8/erwT5loZEktWECDWoKm7cw3Ltpu/okQphg12HhZx8ZAZGaRelFUVVt uX6iGJwsWAAyfz+GEx4vCsGSGAMHi8h78FFcybccDrV+72ISwvZrpsWPC+NWheiNgCWr RWbgbkw2mKPRRXIQaN3uCLiCwqk3sHuNPZ4SDH9q93aaU0LCRN9Of5hClDx2NGkHkORe RbgPjKk98u2RICfqpGK4haCglQj2mUyfX2Dpd9inGCi3MFbDQIauBg1upiN++JtmTaeJ lN5YET0mjn0tec5tuZhxdVygHfNxVGiVD6ctzM76Cwrxh/IO3LC+7aU7eHkwPLcCuiTs zG1Q== 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=C04GWqgk7d2t7qi2pcanm9ZPbT+pAZCpdAaqQDxk4YA=; b=wuy2Q1jRnOzjGU7lcygBTaYJYQnJy8AhSnZjCV6EdT4jqsMKLi+x+6oSr4ItDbqQHz tuOm4sfVEFWbT+7/ZQgKnD4nAYlQ1JMZxVDr7o3VxKSB9a13zXBT6WwkP5LTVhYBWwjb FFcTRt4WypeaMoxEDQH40+Rwa0YSOV4OX5Yc9+di8f8xkiV+pmYd9ICqrz8VUXgxC/Vs 9mF+mNUV4uTYjMZLIk1HUkLKHk/A1tlRZJ1ZMMDvMS2PzJ+opn15DvZE9VAWQPGTu+yh GdTsHWmhFB720v0kSbzj4nIqAn6ykGtfrz9RfvEMHmXT5t+WT9zUp/t4vWlRrXVNlz01 f1cA== 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 b7si1558698itj.17.2017.09.21.05.42.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 05:42:53 -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 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" 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); } }