From patchwork Thu Sep 21 12:40:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 113255 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp1846168edb; Thu, 21 Sep 2017 05:43:06 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC4vrkR4dXorGrbFrUYjHC5I8Ym9iMjxmq9iQ3ZLs4Ay978FQmvQvAgbCpMjFr3OXAWsc0Z X-Received: by 10.36.41.78 with SMTP id p75mr1286845itp.21.1505997786527; Thu, 21 Sep 2017 05:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505997786; cv=none; d=google.com; s=arc-20160816; b=kfWqA2lhviGCVA0KgkcOrcftNQN2EZLPcWUeZnPRSPtjFm29ai7hWY1P9Hocuw6iod Rb1M8NHDDFq6BGwmyDoQMnJqiK8tBQATu9s+A2I1/BvyBDJ3XAEKC10GRkXAlyi9g/HX bFRl5iOUiVvj7ywWkiC/GrGDMQ8dBZHi3wg96qXyParx6EBCY4+phMswVKcwvvSh9rUl cEyzdHsSyNTNuXzkSXAEtrizX6DUDOBwZtE08K8WIfLUcLB7khPWyyqUcqX9oe+XX/aQ ZAgN2pQ7AJDwmc0mkwJ2MeoIYjm0GypZPVDx/mYKDKfCEKopGUqQNoHmmg0UPzr7x6lL XTzA== 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=bNU6RtYl9ZugCLjf7zPiN2cQLozn+aGyLTTnZgRMENU=; b=m0wlj8jdvTMObkppcXYGja+95qhFI19bKqnZj75a9E/+4N88jxqFGhoKaT+kLNEUo1 VxFMfy7kEk/SoD9uBJbulsPhAAf87oTWEPtjyaziCQhxplTT3kS0hFRtFjYG6IUdaDNZ TYSVEYR9po0o9bPcLKTUw6F/wu2f0Rz7hMjE0wPi2kwXNZ0qORGmOZGa/wWWcByGULL1 YR0IfE5GkHeRnqYfydJvhE16TJ3s3moEkWSLhG4bFKwe4Rt3TfkFWeDgeCP7LfG3HgxY zuslTNtJO75oBw0mQ/KExTjRW4qrWQ9ho3r+RHtFx9DejrdUPyutw+SJbKTqmyPtc6DD gseQ== 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 i2si535678iob.252.2017.09.21.05.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 05:43:06 -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 1dv0mo-0001Kq-NK; Thu, 21 Sep 2017 12:40:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0mn-0001JG-7e for xen-devel@lists.xen.org; Thu, 21 Sep 2017 12:40:57 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 1A/2D-02226-853B3C95; Thu, 21 Sep 2017 12:40:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGLMWRWlGSWpSXmKPExsVysyfVTTd88+F Ig8kN4hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aPG0dYCi5tZ6z4sGQNSwPjjGbGLkYuDiGB zYwS77dsY4NwTjNKND+ZA+RwcrAJaErc+fyJCcQWEZCWuPb5MlgHs8BRJok9LTtYQRLCAmkSs 9/MYwexWQRUJTo3T2UEsXkFLCTWzr4P1iwhIC+xq+0iWD2ngKVE2+FvYLYQUM2vCSdYJzByL2 BkWMWoUZxaVJZapGtorpdUlJmeUZKbmJmja2hgrJebWlycmJ6ak5hUrJecn7uJEehnBiDYwfj ytOchRkkOJiVR3nfrDkcK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuDl3ASUEyxKTU+tSMvMAQYc TFqCg0dJhNcVJM1bXJCYW5yZDpE6xajL0XHz7h8mIZa8/LxUKXFec5AiAZCijNI8uBGw4L/EK CslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYV5lkCk8mXklcJteAR3BBHRE9oYDIEeUJCKkpBoYXX oKjky78Lx1n6JS5rTvNf+TnA9wKulH/vjzpDuqw01jx6bXE39+PXD3u7KR4KVX9r9y+2232Ux 0634Zm/Djye4QuUv8f54c7WKvYJ7GuN4yp1xhy/MlXuEWFenCSsfSMmWZ49LEl5le4qqwzDex kmc2vpKlVnvgrX5monnJrSq9XxFbrs1UYinOSDTUYi4qTgQAF3pJ4nkCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1505997654!99078159!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 29174 invoked from network); 21 Sep 2017 12:40:54 -0000 Received: from usa-sjc-mx-foss1.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:54 -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 356251529; Thu, 21 Sep 2017 05:40:54 -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 689093F58C; Thu, 21 Sep 2017 05:40:52 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 13:40:27 +0100 Message-Id: <20170921124035.2410-9-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: Kevin Tian , Tamas K Lengyel , Jun Nakajima , Razvan Cojocaru , George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 08/16] xen/x86: p2m: Use typesafe gfn for the P2M callbacks get_entry and set_entry 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: Kevin Tian Reviewed-by: Wei Liu --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Razvan Cojocaru Cc: Tamas K Lengyel Cc: George Dunlap Cc: Jun Nakajima Cc: Kevin Tian Changes in v2: - Add Andre's acked - Add Kevin's reviewed (EPT part) --- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/mm/mem_access.c | 19 +++++------ xen/arch/x86/mm/mem_sharing.c | 4 +-- xen/arch/x86/mm/p2m-ept.c | 6 ++-- xen/arch/x86/mm/p2m-pod.c | 15 +++++---- xen/arch/x86/mm/p2m-pt.c | 6 ++-- xen/arch/x86/mm/p2m.c | 77 +++++++++++++++++++++++-------------------- xen/include/asm-x86/p2m.h | 4 +-- 8 files changed, 73 insertions(+), 60 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 93394c1fb6..2a32102a41 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1787,7 +1787,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, { bool_t sve; - p2m->get_entry(p2m, gfn, &p2mt, &p2ma, 0, NULL, &sve); + p2m->get_entry(p2m, _gfn(gfn), &p2mt, &p2ma, 0, NULL, &sve); if ( !sve && altp2m_vcpu_emulate_ve(curr) ) { diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 9211fc0abe..948e377e69 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -66,7 +66,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, } gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn_x(gfn), &t, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL, NULL); gfn_unlock(p2m, gfn, 0); if ( mfn_eq(mfn, INVALID_MFN) ) @@ -142,7 +142,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, vm_event_request_t **req_ptr) { struct vcpu *v = current; - unsigned long gfn = gpa >> PAGE_SHIFT; + gfn_t gfn = gaddr_to_gfn(gpa); struct domain *d = v->domain; struct p2m_domain *p2m = NULL; mfn_t mfn; @@ -215,7 +215,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla, *req_ptr = req; req->reason = VM_EVENT_REASON_MEM_ACCESS; - req->u.mem_access.gfn = gfn; + req->u.mem_access.gfn = gfn_x(gfn); req->u.mem_access.offset = gpa & ((1 << PAGE_SHIFT) - 1); if ( npfec.gla_valid ) { @@ -247,7 +247,7 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, unsigned long gfn_l = gfn_x(gfn); int rc; - mfn = ap2m->get_entry(ap2m, gfn_l, &t, &old_a, 0, NULL, NULL); + mfn = ap2m->get_entry(ap2m, gfn, &t, &old_a, 0, NULL, NULL); /* Check host p2m if no valid entry in alternate */ if ( !mfn_valid(mfn) ) @@ -264,16 +264,16 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, if ( page_order != PAGE_ORDER_4K ) { unsigned long mask = ~((1UL << page_order) - 1); - unsigned long gfn2_l = gfn_l & mask; + gfn_t gfn2 = _gfn(gfn_l & mask); mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); - rc = ap2m->set_entry(ap2m, gfn2_l, mfn2, page_order, t, old_a, 1); + rc = ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, old_a, 1); if ( rc ) return rc; } } - return ap2m->set_entry(ap2m, gfn_l, mfn, PAGE_ORDER_4K, t, a, + return ap2m->set_entry(ap2m, gfn, mfn, PAGE_ORDER_4K, t, a, (current->domain != d)); } @@ -295,10 +295,9 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m, mfn_t mfn; p2m_access_t _a; p2m_type_t t; - unsigned long gfn_l = gfn_x(gfn); - mfn = p2m->get_entry(p2m, gfn_l, &t, &_a, 0, NULL, NULL); - rc = p2m->set_entry(p2m, gfn_l, mfn, PAGE_ORDER_4K, t, a, -1); + mfn = p2m->get_entry(p2m, gfn, &t, &_a, 0, NULL, NULL); + rc = p2m->set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, t, a, -1); } return rc; diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 3ab119cef2..62a3899089 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1234,7 +1234,7 @@ int relinquish_shared_pages(struct domain *d) if ( atomic_read(&d->shr_pages) == 0 ) break; - mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &t, &a, 0, NULL, NULL); if ( mfn_valid(mfn) && (t == p2m_ram_shared) ) { /* Does not fail with ENOMEM given the DESTROY flag */ @@ -1243,7 +1243,7 @@ int relinquish_shared_pages(struct domain *d) /* Clear out the p2m entry so no one else may try to * unshare. Must succeed: we just read the old entry and * we hold the p2m lock. */ - set_rc = p2m->set_entry(p2m, gfn, _mfn(0), PAGE_ORDER_4K, + set_rc = p2m->set_entry(p2m, _gfn(gfn), _mfn(0), PAGE_ORDER_4K, p2m_invalid, p2m_access_rwx, -1); ASSERT(set_rc == 0); count += 0x10; diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 23c0518733..f14d1686b7 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -674,11 +674,12 @@ bool_t ept_handle_misconfig(uint64_t gpa) * Returns: 0 for success, -errno for failure */ static int -ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, +ept_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn, unsigned int order, p2m_type_t p2mt, p2m_access_t p2ma, int sve) { ept_entry_t *table, *ept_entry = NULL; + unsigned long gfn = gfn_x(gfn_); unsigned long gfn_remainder = gfn; unsigned int i, target = order / EPT_TABLE_ORDER; unsigned long fn_mask = !mfn_eq(mfn, INVALID_MFN) ? (gfn | mfn_x(mfn)) : gfn; @@ -910,11 +911,12 @@ out: /* Read ept p2m entries */ static mfn_t ept_get_entry(struct p2m_domain *p2m, - unsigned long gfn, p2m_type_t *t, p2m_access_t* a, + gfn_t gfn_, p2m_type_t *t, p2m_access_t* a, p2m_query_t q, unsigned int *page_order, bool_t *sve) { ept_entry_t *table = map_domain_page(_mfn(pagetable_get_pfn(p2m_get_pagetable(p2m)))); + unsigned long gfn = gfn_x(gfn_); unsigned long gfn_remainder = gfn; ept_entry_t *ept_entry; u32 index; diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index eb74e5c01f..c8c8cff014 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -543,7 +543,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order) p2m_type_t t; unsigned int cur_order; - p2m->get_entry(p2m, gfn_x(gfn) + i, &t, &a, 0, &cur_order, NULL); + p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, &cur_order, NULL); n = 1UL << min(order, cur_order); if ( t == p2m_populate_on_demand ) pod += n; @@ -603,7 +603,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order) p2m_access_t a; unsigned int cur_order; - mfn = p2m->get_entry(p2m, gfn_x(gfn) + i, &t, &a, 0, &cur_order, NULL); + mfn = p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, &cur_order, NULL); if ( order < cur_order ) cur_order = order; n = 1UL << cur_order; @@ -717,7 +717,8 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn) unsigned long k; const struct page_info *page; - mfn = p2m->get_entry(p2m, gfn + i, &type, &a, 0, &cur_order, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn + i), &type, &a, 0, + &cur_order, NULL); /* * Conditions that must be met for superpage-superpage: @@ -859,7 +860,9 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) for ( i = 0; i < count; i++ ) { p2m_access_t a; - mfns[i] = p2m->get_entry(p2m, gfns[i], types + i, &a, 0, NULL, NULL); + + mfns[i] = p2m->get_entry(p2m, _gfn(gfns[i]), types + i, &a, + 0, NULL, NULL); /* * If this is ram, and not a pagetable or from the xen heap, and * probably not mapped elsewhere, map it; otherwise, skip. @@ -988,7 +991,7 @@ p2m_pod_emergency_sweep(struct p2m_domain *p2m) for ( i = p2m->pod.reclaim_single; i > 0 ; i-- ) { p2m_access_t a; - (void)p2m->get_entry(p2m, i, &t, &a, 0, NULL, NULL); + (void)p2m->get_entry(p2m, _gfn(i), &t, &a, 0, NULL, NULL); if ( p2m_is_ram(t) ) { gfns[j] = i; @@ -1237,7 +1240,7 @@ guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, p2m_access_t a; unsigned int cur_order; - p2m->get_entry(p2m, gfn + i, &ot, &a, 0, &cur_order, NULL); + p2m->get_entry(p2m, _gfn(gfn + i), &ot, &a, 0, &cur_order, NULL); n = 1UL << min(order, cur_order); if ( p2m_is_ram(ot) ) { diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 0e63d6ed11..4bfec4f5f0 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -479,12 +479,13 @@ int p2m_pt_handle_deferred_changes(uint64_t gpa) /* Returns: 0 for success, -errno for failure */ static int -p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, +p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn, unsigned int page_order, p2m_type_t p2mt, p2m_access_t p2ma, int sve) { /* XXX -- this might be able to be faster iff current->domain == d */ void *table; + unsigned long gfn = gfn_x(gfn_); unsigned long i, gfn_remainder = gfn; l1_pgentry_t *p2m_entry, entry_content; /* Intermediate table to free if we're replacing it with a superpage. */ @@ -731,11 +732,12 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, } static mfn_t -p2m_pt_get_entry(struct p2m_domain *p2m, unsigned long gfn, +p2m_pt_get_entry(struct p2m_domain *p2m, gfn_t gfn_, p2m_type_t *t, p2m_access_t *a, p2m_query_t q, unsigned int *page_order, bool_t *sve) { mfn_t mfn; + unsigned long gfn = gfn_x(gfn_); paddr_t addr = ((paddr_t)gfn) << PAGE_SHIFT; l2_pgentry_t *l2e; l1_pgentry_t *l1e; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 0b479105b9..35d4a15391 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -415,11 +415,12 @@ void p2m_unlock_and_tlb_flush(struct p2m_domain *p2m) mm_write_unlock(&p2m->lock); } -mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn, +mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn_l, p2m_type_t *t, p2m_access_t *a, p2m_query_t q, unsigned int *page_order, bool_t locked) { mfn_t mfn; + gfn_t gfn = _gfn(gfn_l); /* Unshare makes no sense withuot populate. */ if ( q & P2M_UNSHARE ) @@ -430,7 +431,7 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn, /* Not necessarily true, but for non-translated guests, we claim * it's the most generic kind of memory */ *t = p2m_ram_rw; - return _mfn(gfn); + return _mfn(gfn_l); } if ( locked ) @@ -444,8 +445,8 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn, ASSERT(p2m_is_hostp2m(p2m)); /* Try to unshare. If we fail, communicate ENOMEM without * sleeping. */ - if ( mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0 ) - (void)mem_sharing_notify_enomem(p2m->domain, gfn, 0); + if ( mem_sharing_unshare_page(p2m->domain, gfn_l, 0) < 0 ) + (void)mem_sharing_notify_enomem(p2m->domain, gfn_l, 0); mfn = p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); } @@ -556,7 +557,7 @@ int p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, else order = 0; - set_rc = p2m->set_entry(p2m, gfn, mfn, order, p2mt, p2ma, -1); + set_rc = p2m->set_entry(p2m, _gfn(gfn), mfn, order, p2mt, p2ma, -1); if ( set_rc ) rc = set_rc; @@ -735,7 +736,8 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, { for ( i = 0; i < (1UL << page_order); i++ ) { - mfn_return = p2m->get_entry(p2m, gfn + i, &t, &a, 0, NULL, NULL); + mfn_return = p2m->get_entry(p2m, _gfn(gfn + i), &t, &a, 0, + NULL, NULL); if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) ) set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY); ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) ); @@ -762,7 +764,8 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned int page_order, p2m_type_t t) { struct p2m_domain *p2m = p2m_get_hostp2m(d); - unsigned long i, ogfn; + unsigned long i; + gfn_t ogfn; p2m_type_t ot; p2m_access_t a; mfn_t omfn; @@ -803,7 +806,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, /* First, remove m->p mappings for existing p->m mappings */ for ( i = 0; i < (1UL << page_order); i++ ) { - omfn = p2m->get_entry(p2m, gfn_x(gfn_add(gfn, i)), &ot, + omfn = p2m->get_entry(p2m, gfn_add(gfn, i), &ot, &a, 0, NULL, NULL); if ( p2m_is_shared(ot) ) { @@ -831,7 +834,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, 0); return rc; } - omfn = p2m->get_entry(p2m, gfn_x(gfn_add(gfn, i)), + omfn = p2m->get_entry(p2m, gfn_add(gfn, i), &ot, &a, 0, NULL, NULL); ASSERT(!p2m_is_shared(ot)); } @@ -873,21 +876,24 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, } if ( page_get_owner(mfn_to_page(mfn_add(mfn, i))) != d ) continue; - ogfn = mfn_to_gfn(d, mfn_add(mfn, i)); - if ( (ogfn != INVALID_M2P_ENTRY) && (ogfn != gfn_x(gfn_add(gfn, i))) ) + ogfn = _gfn(mfn_to_gfn(d, mfn_add(mfn, i))); + if ( !gfn_eq(ogfn, _gfn(INVALID_M2P_ENTRY)) && + !gfn_eq(ogfn, gfn_add(gfn, i)) ) { /* This machine frame is already mapped at another physical * address */ P2M_DEBUG("aliased! mfn=%#lx, old gfn=%#lx, new gfn=%#lx\n", - mfn_x(mfn_add(mfn, i)), ogfn, gfn_x(gfn_add(gfn, i))); + mfn_x(mfn_add(mfn, i)), gfn_x(ogfn), + gfn_x(gfn_add(gfn, i))); omfn = p2m->get_entry(p2m, ogfn, &ot, &a, 0, NULL, NULL); if ( p2m_is_ram(ot) && !p2m_is_paged(ot) ) { ASSERT(mfn_valid(omfn)); P2M_DEBUG("old gfn=%#lx -> mfn %#lx\n", - ogfn , mfn_x(omfn)); + gfn_x(ogfn) , mfn_x(omfn)); if ( mfn_eq(omfn, mfn_add(mfn, i)) ) - p2m_remove_page(p2m, ogfn, mfn_x(mfn_add(mfn, i)), 0); + p2m_remove_page(p2m, gfn_x(ogfn), mfn_x(mfn_add(mfn, i)), + 0); } } } @@ -948,7 +954,7 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn, gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &pt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &pt, &a, 0, NULL, NULL); rc = likely(pt == ot) ? p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, nt, p2m->default_access) @@ -1065,14 +1071,15 @@ int p2m_finish_type_change(struct domain *d, * 1 + new order for caller to retry with smaller order (guaranteed * to be smaller than order passed in) */ -static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, - unsigned int order, p2m_type_t gfn_p2mt, - p2m_access_t access) +static int set_typed_p2m_entry(struct domain *d, unsigned long gfn_l, + mfn_t mfn, unsigned int order, + p2m_type_t gfn_p2mt, p2m_access_t access) { int rc = 0; p2m_access_t a; p2m_type_t ot; mfn_t omfn; + gfn_t gfn = _gfn(gfn_l); unsigned int cur_order = 0; struct p2m_domain *p2m = p2m_get_hostp2m(d); @@ -1103,11 +1110,11 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, } } - P2M_DEBUG("set %d %lx %lx\n", gfn_p2mt, gfn, mfn_x(mfn)); - rc = p2m_set_entry(p2m, gfn, mfn, order, gfn_p2mt, access); + P2M_DEBUG("set %d %lx %lx\n", gfn_p2mt, gfn_l, mfn_x(mfn)); + rc = p2m_set_entry(p2m, gfn_l, mfn, order, gfn_p2mt, access); if ( rc ) gdprintk(XENLOG_ERR, "p2m_set_entry: %#lx:%u -> %d (0x%"PRI_mfn")\n", - gfn, order, rc, mfn_x(mfn)); + gfn_l, order, rc, mfn_x(mfn)); else if ( p2m_is_pod(ot) ) { pod_lock(p2m); @@ -1157,7 +1164,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn, gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); if ( p2mt == p2m_invalid || p2mt == p2m_mmio_dm ) ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K, @@ -1201,7 +1208,7 @@ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, return -EIO; gfn_lock(p2m, gfn, order); - actual_mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, &cur_order, NULL); + actual_mfn = p2m->get_entry(p2m, _gfn(gfn), &t, &a, 0, &cur_order, NULL); if ( cur_order < order ) { rc = cur_order + 1; @@ -1245,7 +1252,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn) gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); if ( p2mt == p2m_mmio_direct && mfn_x(mfn) == gfn ) { ret = p2m_set_entry(p2m, gfn, INVALID_MFN, PAGE_ORDER_4K, @@ -1278,7 +1285,7 @@ int set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) return -EIO; gfn_lock(p2m, gfn, 0); - omfn = p2m->get_entry(p2m, gfn, &ot, &a, 0, NULL, NULL); + omfn = p2m->get_entry(p2m, _gfn(gfn), &ot, &a, 0, NULL, NULL); /* At the moment we only allow p2m change if gfn has already been made * sharable first */ ASSERT(p2m_is_shared(ot)); @@ -1330,7 +1337,7 @@ int p2m_mem_paging_nominate(struct domain *d, unsigned long gfn) gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); /* Check if mfn is valid */ if ( !mfn_valid(mfn) ) @@ -1392,7 +1399,7 @@ int p2m_mem_paging_evict(struct domain *d, unsigned long gfn) gfn_lock(p2m, gfn, 0); /* Get mfn */ - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); if ( unlikely(!mfn_valid(mfn)) ) goto out; @@ -1524,7 +1531,7 @@ void p2m_mem_paging_populate(struct domain *d, unsigned long gfn) /* Fix p2m mapping */ gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); /* Allow only nominated or evicted pages to enter page-in path */ if ( p2mt == p2m_ram_paging_out || p2mt == p2m_ram_paged ) { @@ -1586,7 +1593,7 @@ int p2m_mem_paging_prep(struct domain *d, unsigned long gfn, uint64_t buffer) gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); ret = -ENOENT; /* Allow missing pages */ @@ -1674,7 +1681,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp) unsigned long gfn = rsp->u.mem_access.gfn; gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL, NULL); + mfn = p2m->get_entry(p2m, _gfn(gfn), &p2mt, &a, 0, NULL, NULL); /* * Allow only pages which were prepared properly, or pages which * were nominated but not evicted. @@ -2263,7 +2270,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, p2m_lock(hp2m); p2m_lock(ap2m); - mfn = ap2m->get_entry(ap2m, gfn_x(old_gfn), &t, &a, 0, NULL, NULL); + mfn = ap2m->get_entry(ap2m, old_gfn, &t, &a, 0, NULL, NULL); if ( gfn_eq(new_gfn, INVALID_GFN) ) { @@ -2292,21 +2299,21 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, gfn = _gfn(gfn_x(old_gfn) & mask); mfn = _mfn(mfn_x(mfn) & mask); - if ( ap2m->set_entry(ap2m, gfn_x(gfn), mfn, page_order, t, a, 1) ) + if ( ap2m->set_entry(ap2m, gfn, mfn, page_order, t, a, 1) ) goto out; } } - mfn = ap2m->get_entry(ap2m, gfn_x(new_gfn), &t, &a, 0, NULL, NULL); + mfn = ap2m->get_entry(ap2m, new_gfn, &t, &a, 0, NULL, NULL); if ( !mfn_valid(mfn) ) - mfn = hp2m->get_entry(hp2m, gfn_x(new_gfn), &t, &a, 0, NULL, NULL); + mfn = hp2m->get_entry(hp2m, new_gfn, &t, &a, 0, NULL, NULL); /* Note: currently it is not safe to remap to a shared entry */ if ( !mfn_valid(mfn) || (t != p2m_ram_rw) ) goto out; - if ( !ap2m->set_entry(ap2m, gfn_x(old_gfn), mfn, PAGE_ORDER_4K, t, a, + if ( !ap2m->set_entry(ap2m, old_gfn, mfn, PAGE_ORDER_4K, t, a, (current->domain != d)) ) { rc = 0; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 8f3409b400..1c9a51e9ad 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -234,13 +234,13 @@ struct p2m_domain { struct page_list_head pages; int (*set_entry)(struct p2m_domain *p2m, - unsigned long gfn, + gfn_t gfn, mfn_t mfn, unsigned int page_order, p2m_type_t p2mt, p2m_access_t p2ma, int sve); mfn_t (*get_entry)(struct p2m_domain *p2m, - unsigned long gfn, + gfn_t gfn, p2m_type_t *p2mt, p2m_access_t *p2ma, p2m_query_t q,