From patchwork Thu Sep 21 12:40:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 113252 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp1846122edb; Thu, 21 Sep 2017 05:43:03 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBM/N5jISPy1QideYsAmb5XkRdQBVSLEmteHjcmWNsdnARwsMwFuiR3y+3Q4z9m8nQF30Vm X-Received: by 10.36.110.3 with SMTP id w3mr1275276itc.113.1505997783595; Thu, 21 Sep 2017 05:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505997783; cv=none; d=google.com; s=arc-20160816; b=ZTsZHISsUp13HFT52D/+JsCeJubatPhODgbfJEkKAAb0Qpto2KIyO4itz0hIofhigM xtXTf7OgKVj3AoyvQtzygQHhEZd0uU+GRl4OF/cP45KCwE3TAlT1ncqaai8G1omEuA9K cQpBQYLMz0pztZlDRwDx/Cfr5g71hYP65xNE4HtAgP8ojUVcLPUxoEVjeMVyxwuRl0n/ 3FqCorjWiKx3G32Aoc9mgcL8SVDy7AGcU1bvq3tvc9TFHFsbVHfsC29o17oXovN2UH2d 95AMerMgKnnLAXYzDROEy6OSd3QAlrhYaPBBq0/W2bjPBQsp7ZAukv86n7LpvQLoZtEH M0hw== 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=9du4enZMyIeFfVkSvUDfGEWDZ63xZdy0Tta6OonNFe8=; b=W0Uyb2EMueehPmolBtyKEHIbEPWTrAnrshMfjBGn1hILyqrIwK73J12LqmuAdGOZwW uK68s64XuoLihqxWh+px94tQq04jYNt8ThNWzstoou36OuHU+ugE+6aqcDOk3ou9dWm/ 0VQA8tpyyeo8kb5f6hQyoDUa9oG2ggE428pAi052M2qWi+lVHI2PHqN4fUQagwupd0xe p4qjNRw+fyoSoOnRXg7pxO7CBnDb7iRI4cI8ENQRNCwpWX26MZ8Vdk3SJjz8Y4ovstXS O0iL9inrb2fYnNbu7FUgwAxFXZ4iOTmGedVzSRgU7WLfSpFFvVsMp6Lbp7eUgNcaHjZL SplA== 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 q134si1084212iod.339.2017.09.21.05.43.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 05:43:03 -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 1dv0ml-0001Ht-FR; Thu, 21 Sep 2017 12:40:55 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0mk-0001GP-HN for xen-devel@lists.xen.org; Thu, 21 Sep 2017 12:40:54 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id B1/98-02044-553B3C95; Thu, 21 Sep 2017 12:40:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCLMWRWlGSWpSXmKPExsVysyfVTTd08+F Ig3nzWCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oy2c1dYCk5YVky+0M7UwDhXu4uRi0NIYDOj xIO+vUwQzmlGiee9b9m7GDk52AQ0Je58/sQEYosISEtc+3yZEaSIWWAxo8Tn/b3MIAlhgRiJ1 2/6WUBsFgFViXcPDoDZvAIWEje3fwFrlhCQl9jVdpEVxOYUsJRoO/wNzBYCqvk14QTrBEbuBY wMqxg1ilOLylKLdA1N9ZKKMtMzSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAn3MAAQ7GNd s9zzEKMnBpCTK+27d4UghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErwBm4BygkWp6akVaZk5wGCD SUtw8CiJ8DaBpHmLCxJzizPTIVKnGHU5Om7e/cMkxJKXn5cqJc5rDlIkAFKUUZoHNwIW+JcYZ aWEeRmBjhLiKUgtys0sQZV/xSjOwagkzBsLMoUnM68EbtMroCOYgI7I3nAA5IiSRISUVAOjiW CCR12LwFKdM2r8KyddnOrvtV/nzr6E0tzCeYzBgTLmSvPqU7YuUJIOf3Pcv/l8yaaSE/1fOyy us3FnOs79/chGS5j/AYvkQ5vqCxsk/JcE3Jzkt2qH03VN4UMd39YLC8x++aH9mkiTm13b1IrO gz90I1z1r+ec26X+3e8Pe0Hc1RW2UqJKLMUZiYZazEXFiQD/mvTqdwIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1505997652!99078146!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 28846 invoked from network); 21 Sep 2017 12:40:52 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-12.tower-31.messagelabs.com with SMTP; 21 Sep 2017 12:40:52 -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 291C4165D; Thu, 21 Sep 2017 05:40:52 -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 19DB83F58C; Thu, 21 Sep 2017 05:40:50 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 13:40:26 +0100 Message-Id: <20170921124035.2410-8-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 07/16] xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_decrease_reservation 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" Signed-off-by: Julien Grall Acked-by: Andrew Cooper Reviewed-by: Wei Liu Acked-by: George Dunlap --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Changes in v2: - Add Andrew's acked-by --- xen/arch/arm/p2m.c | 3 +-- xen/arch/x86/mm/p2m-pod.c | 20 +++++++++----------- xen/common/memory.c | 3 ++- xen/include/asm-arm/p2m.h | 13 ------------- xen/include/asm-x86/p2m.h | 7 ------- xen/include/xen/p2m-common.h | 13 +++++++++++++ 6 files changed, 25 insertions(+), 34 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 192a1c329d..0410b1e86b 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -393,8 +393,7 @@ int guest_physmap_mark_populate_on_demand(struct domain *d, return -ENOSYS; } -int p2m_pod_decrease_reservation(struct domain *d, - xen_pfn_t gpfn, +int p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order) { return -ENOSYS; diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 34f5239b6d..eb74e5c01f 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -511,9 +511,7 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn); * allow decrease_reservation() to handle everything else. */ int -p2m_pod_decrease_reservation(struct domain *d, - xen_pfn_t gpfn, - unsigned int order) +p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order) { int ret = 0; unsigned long i, n; @@ -521,7 +519,7 @@ p2m_pod_decrease_reservation(struct domain *d, bool_t steal_for_cache; long pod, nonpod, ram; - gfn_lock(p2m, gpfn, order); + gfn_lock(p2m, gfn, order); pod_lock(p2m); /* @@ -545,7 +543,7 @@ p2m_pod_decrease_reservation(struct domain *d, p2m_type_t t; unsigned int cur_order; - p2m->get_entry(p2m, gpfn + i, &t, &a, 0, &cur_order, NULL); + p2m->get_entry(p2m, gfn_x(gfn) + i, &t, &a, 0, &cur_order, NULL); n = 1UL << min(order, cur_order); if ( t == p2m_populate_on_demand ) pod += n; @@ -567,7 +565,7 @@ p2m_pod_decrease_reservation(struct domain *d, * All PoD: Mark the whole region invalid and tell caller * we're done. */ - p2m_set_entry(p2m, gpfn, INVALID_MFN, order, p2m_invalid, + p2m_set_entry(p2m, gfn_x(gfn), INVALID_MFN, order, p2m_invalid, p2m->default_access); p2m->pod.entry_count -= 1UL << order; BUG_ON(p2m->pod.entry_count < 0); @@ -584,7 +582,7 @@ p2m_pod_decrease_reservation(struct domain *d, * - 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, gpfn & ~(SUPERPAGE_PAGES - 1)) ) + p2m_pod_zero_check_superpage(p2m, gfn_x(gfn) & ~(SUPERPAGE_PAGES - 1)) ) { pod = 1UL << order; ram = nonpod = 0; @@ -605,13 +603,13 @@ p2m_pod_decrease_reservation(struct domain *d, p2m_access_t a; unsigned int cur_order; - mfn = p2m->get_entry(p2m, gpfn + i, &t, &a, 0, &cur_order, NULL); + mfn = p2m->get_entry(p2m, gfn_x(gfn) + i, &t, &a, 0, &cur_order, NULL); if ( order < cur_order ) cur_order = order; n = 1UL << cur_order; if ( t == p2m_populate_on_demand ) { - p2m_set_entry(p2m, gpfn + i, INVALID_MFN, cur_order, + p2m_set_entry(p2m, gfn_x(gfn) + i, INVALID_MFN, cur_order, p2m_invalid, p2m->default_access); p2m->pod.entry_count -= n; BUG_ON(p2m->pod.entry_count < 0); @@ -633,7 +631,7 @@ p2m_pod_decrease_reservation(struct domain *d, page = mfn_to_page(mfn); - p2m_set_entry(p2m, gpfn + i, INVALID_MFN, cur_order, + p2m_set_entry(p2m, gfn_x(gfn) + i, INVALID_MFN, cur_order, p2m_invalid, p2m->default_access); p2m_tlb_flush_sync(p2m); for ( j = 0; j < n; ++j ) @@ -663,7 +661,7 @@ out_entry_check: out_unlock: pod_unlock(p2m); - gfn_unlock(p2m, gpfn, order); + gfn_unlock(p2m, gfn, order); return ret; } diff --git a/xen/common/memory.c b/xen/common/memory.c index a2abf554e3..ad987e0f29 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -417,7 +417,8 @@ static void decrease_reservation(struct memop_args *a) /* See if populate-on-demand wants to handle this */ if ( is_hvm_domain(a->domain) - && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) ) + && p2m_pod_decrease_reservation(a->domain, _gfn(gmfn), + a->extent_order) ) continue; for ( j = 0; j < (1 << a->extent_order); j++ ) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index bc5bbf0db7..faadcfe8fe 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -266,19 +266,6 @@ static inline int guest_physmap_add_page(struct domain *d, mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn); -/* - * Populate-on-demand - */ - -/* - * Call when decreasing memory reservation to handle PoD entries properly. - * Will return '1' if all entries were handled and nothing more need be done. - */ -int -p2m_pod_decrease_reservation(struct domain *d, - xen_pfn_t gpfn, - unsigned int order); - /* Look up a GFN and take a reference count on the backing page. */ typedef unsigned int p2m_query_t; #define P2M_ALLOC (1u<<0) /* Populate PoD and paged-out entries */ diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 10cdfc09a9..8f3409b400 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -643,13 +643,6 @@ int p2m_pod_empty_cache(struct domain *d); * domain matches target */ int p2m_pod_set_mem_target(struct domain *d, unsigned long target); -/* Call when decreasing memory reservation to handle PoD entries properly. - * Will return '1' if all entries were handled and nothing more need be done.*/ -int -p2m_pod_decrease_reservation(struct domain *d, - xen_pfn_t gpfn, - unsigned int order); - /* Scan pod cache when offline/broken page triggered */ int p2m_pod_offline_or_broken_hit(struct page_info *p); diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index 2b5696cf33..27f89208f5 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -20,4 +20,17 @@ int unmap_mmio_regions(struct domain *d, unsigned long nr, mfn_t mfn); +/* + * Populate-on-Demand + */ + +/* + * Call when decreasing memory reservation to handle PoD entries properly. + * Will return '1' if all entries were handled and nothing more need be done. + */ +int +p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, + unsigned int order); + + #endif /* _XEN_P2M_COMMON_H */