From patchwork Sun Mar 22 16:14:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 11451875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9CED17D4 for ; Sun, 22 Mar 2020 16:16:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9437B20724 for ; Sun, 22 Mar 2020 16:16:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9437B20724 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3FB-0004Wo-45; Sun, 22 Mar 2020 16:14:33 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3FA-0004W0-7N for xen-devel@lists.xenproject.org; Sun, 22 Mar 2020 16:14:32 +0000 X-Inumbo-ID: 35b3b146-6c58-11ea-8134-12813bfff9fa Received: from mail-ed1-f66.google.com (unknown [209.85.208.66]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 35b3b146-6c58-11ea-8134-12813bfff9fa; Sun, 22 Mar 2020 16:14:30 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id n25so12545265eds.10 for ; Sun, 22 Mar 2020 09:14:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h83qCfUbAW/2NAbwW1ERuK1KGMn6B8eXif9Ulq27FvE=; b=Plzv16lAi+7hz6qwQSg2f0VNYQ4dNP5eq7h4pi/71FuUosH8RN7rCT0H72OPwSA7Ah IrDr83WPGh9s8OqEZG2edmcQakPrCSjY+wbOiT/TrE+u8tR6oZ8EZ2xOF3P1fvZE2F8w tCzPikQa9QcbgWQAKi1lohEH8tV1ThJ1qeOs+ogICgAwUI2B/kqenUH18qAtFxGNgnCj RcjvYlweQMwyr7GNzJfHKHvK/21KHSHKIHhv7kCuVz0uisUD3LToI7lusWfsJHJAC6Yw vRdi9c1PaXRgQBHVYc338Z3tKp4zMkEyKIDzZTfj/uMQxD3JHT0vdVIOyLSvYxRkcQxn 7mVw== X-Gm-Message-State: ANhLgQ0WfG8pxCbQJ+d5GNFm7+Pgg8WnSX4KnpZe3EpInzqZRrfgZWao 9NXEjcWbbZ+aXYd/khltUsoZrIhDhkuEFw== X-Google-Smtp-Source: ADFU+vsSf5w5HhH8Xe2gqsgBouk/xZQTxqN1/mvxgjQ0srN2RxUQWRAl7Xu368gThWCl/SH69aBRGw== X-Received: by 2002:a05:6402:110a:: with SMTP id u10mr11436967edv.159.1584893668808; Sun, 22 Mar 2020 09:14:28 -0700 (PDT) Received: from ufe34d9ed68d054.ant.amazon.com (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id v13sm106693edj.62.2020.03.22.09.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 09:14:28 -0700 (PDT) From: julien@xen.org To: xen-devel@lists.xenproject.org Date: Sun, 22 Mar 2020 16:14:06 +0000 Message-Id: <20200322161418.31606-6-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200322161418.31606-1-julien@xen.org> References: <20200322161418.31606-1-julien@xen.org> Subject: [Xen-devel] [PATCH 05/17] xen/x86: Remove the non-typesafe version of pagetable_* helpers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , julien@xen.org, Jun Nakajima , Wei Liu , Andrew Cooper , Julien Grall , Tim Deegan , George Dunlap , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Most of the users of the pagetable_* helpers can use the typesafe version. Therefore, it is time to convert the callers still using non-typesafe version to use the typesafe one. Some part of the code assume that a pagetable is NULL when the MFN 0. When possible this is replaced with the helper pagetable_is_null(). There are still someplace which test against MFN 0 and it is not clear if other unconverted part of the code rely on the value. So, for now, the NULL value is not changed to INVALID_MFN. No functional changes intented. Signed-off-by: Julien Grall --- xen/arch/x86/domain.c | 18 ++++++++------- xen/arch/x86/domctl.c | 6 ++--- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 2 +- xen/arch/x86/mm.c | 40 +++++++++++++++++----------------- xen/arch/x86/mm/hap/hap.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/arch/x86/mm/p2m-pt.c | 4 ++-- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/multi.c | 24 ++++++++++---------- xen/arch/x86/pv/dom0_build.c | 10 ++++----- xen/arch/x86/traps.c | 6 ++--- xen/include/asm-x86/page.h | 19 ++++++++-------- 14 files changed, 70 insertions(+), 69 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 15750ce210..18d8fda9bd 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -952,25 +952,27 @@ int arch_set_info_guest( } else { - unsigned long pfn = pagetable_get_pfn(v->arch.guest_table); + mfn_t mfn = pagetable_get_mfn(v->arch.guest_table); bool fail; if ( !compat ) { - fail = xen_pfn_to_cr3(pfn) != c.nat->ctrlreg[3]; + fail = mfn_to_cr3(mfn) != c.nat->ctrlreg[3]; if ( pagetable_is_null(v->arch.guest_table_user) ) fail |= c.nat->ctrlreg[1] || !(flags & VGCF_in_kernel); else { - pfn = pagetable_get_pfn(v->arch.guest_table_user); - fail |= xen_pfn_to_cr3(pfn) != c.nat->ctrlreg[1]; + mfn = pagetable_get_mfn(v->arch.guest_table_user); + fail |= mfn_to_cr3(mfn) != c.nat->ctrlreg[1]; } - } else { - l4_pgentry_t *l4tab = map_domain_page(_mfn(pfn)); + } + else + { + l4_pgentry_t *l4tab = map_domain_page(mfn); - pfn = l4e_get_pfn(*l4tab); + mfn = l4e_get_mfn(*l4tab); unmap_domain_page(l4tab); - fail = compat_pfn_to_cr3(pfn) != c.cmp->ctrlreg[3]; + fail = compat_pfn_to_cr3(mfn_x(mfn)) != c.cmp->ctrlreg[3]; } for ( i = 0; i < ARRAY_SIZE(v->arch.pv.gdt_frames); ++i ) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index ed86762fa6..02596c3810 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1611,11 +1611,11 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) if ( !compat ) { - c.nat->ctrlreg[3] = xen_pfn_to_cr3( - pagetable_get_pfn(v->arch.guest_table)); + c.nat->ctrlreg[3] = mfn_to_cr3( + pagetable_get_mfn(v->arch.guest_table)); c.nat->ctrlreg[1] = pagetable_is_null(v->arch.guest_table_user) ? 0 - : xen_pfn_to_cr3(pagetable_get_pfn(v->arch.guest_table_user)); + : mfn_to_cr3(pagetable_get_mfn(v->arch.guest_table_user)); } else { diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 4c23645454..1f39367253 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1290,7 +1290,7 @@ static int construct_vmcs(struct vcpu *v) struct p2m_domain *p2m = p2m_get_hostp2m(d); struct ept_data *ept = &p2m->ept; - ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); + ept->mfn = mfn_x(pagetable_get_mfn(p2m_get_pagetable(p2m))); __vmwrite(EPT_POINTER, ept->eptp); __vmwrite(HOST_PAT, XEN_MSR_PAT); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index d265ed46ad..a1e3a19c0a 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2110,7 +2110,7 @@ static void vmx_vcpu_update_eptp(struct vcpu *v) p2m = p2m_get_hostp2m(d); ept = &p2m->ept; - ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); + ept->mfn = mfn_x(pagetable_get_mfn(p2m_get_pagetable(p2m))); vmx_vmcs_enter(v); diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index f049920196..84b47ef277 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1149,7 +1149,7 @@ static uint64_t get_shadow_eptp(struct vcpu *v) struct p2m_domain *p2m = p2m_get_nestedp2m(v); struct ept_data *ept = &p2m->ept; - ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); + ept->mfn = mfn_x(pagetable_get_mfn(p2m_get_pagetable(p2m))); return ept->eptp; } diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7c0f81759a..aa0bf3d0ee 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3085,7 +3085,7 @@ int put_old_guest_table(struct vcpu *v) int vcpu_destroy_pagetables(struct vcpu *v) { - unsigned long mfn = pagetable_get_pfn(v->arch.guest_table); + mfn_t mfn = pagetable_get_mfn(v->arch.guest_table); struct page_info *page = NULL; int rc = put_old_guest_table(v); bool put_guest_table_user = false; @@ -3102,9 +3102,9 @@ int vcpu_destroy_pagetables(struct vcpu *v) */ if ( is_pv_32bit_vcpu(v) ) { - l4_pgentry_t *l4tab = map_domain_page(_mfn(mfn)); + l4_pgentry_t *l4tab = map_domain_page(mfn); - mfn = l4e_get_pfn(*l4tab); + mfn = l4e_get_mfn(*l4tab); l4e_write(l4tab, l4e_empty()); unmap_domain_page(l4tab); } @@ -3116,24 +3116,24 @@ int vcpu_destroy_pagetables(struct vcpu *v) /* Free that page if non-zero */ do { - if ( mfn ) + if ( !mfn_eq(mfn, _mfn(0)) ) { - page = mfn_to_page(_mfn(mfn)); + page = mfn_to_page(mfn); if ( paging_mode_refcounts(v->domain) ) put_page(page); else rc = put_page_and_type_preemptible(page); - mfn = 0; + mfn = _mfn(0); } if ( !rc && put_guest_table_user ) { /* Drop ref to guest_table_user (from MMUEXT_NEW_USER_BASEPTR) */ - mfn = pagetable_get_pfn(v->arch.guest_table_user); + mfn = pagetable_get_mfn(v->arch.guest_table_user); v->arch.guest_table_user = pagetable_null(); put_guest_table_user = false; } - } while ( mfn ); + } while ( !mfn_eq(mfn, _mfn(0)) ); /* * If a "put" operation was interrupted, finish things off in @@ -3551,7 +3551,8 @@ long do_mmuext_op( break; case MMUEXT_NEW_USER_BASEPTR: { - unsigned long old_mfn; + mfn_t old_mfn; + mfn_t new_mfn = _mfn(op.arg1.mfn); if ( unlikely(currd != pg_owner) ) rc = -EPERM; @@ -3560,19 +3561,18 @@ long do_mmuext_op( if ( unlikely(rc) ) break; - old_mfn = pagetable_get_pfn(curr->arch.guest_table_user); + old_mfn = pagetable_get_mfn(curr->arch.guest_table_user); /* * This is particularly important when getting restarted after the * previous attempt got preempted in the put-old-MFN phase. */ - if ( old_mfn == op.arg1.mfn ) + if ( mfn_eq(old_mfn, new_mfn) ) break; - if ( op.arg1.mfn != 0 ) + if ( !mfn_eq(new_mfn, _mfn(0)) ) { - rc = get_page_and_type_from_mfn( - _mfn(op.arg1.mfn), PGT_root_page_table, currd, PTF_preemptible); - + rc = get_page_and_type_from_mfn(new_mfn, PGT_root_page_table, + currd, PTF_preemptible); if ( unlikely(rc) ) { if ( rc == -EINTR ) @@ -3580,19 +3580,19 @@ long do_mmuext_op( else if ( rc != -ERESTART ) gdprintk(XENLOG_WARNING, "Error %d installing new mfn %" PRI_mfn "\n", - rc, op.arg1.mfn); + rc, mfn_x(new_mfn)); break; } if ( VM_ASSIST(currd, m2p_strict) ) - zap_ro_mpt(_mfn(op.arg1.mfn)); + zap_ro_mpt(new_mfn); } - curr->arch.guest_table_user = pagetable_from_pfn(op.arg1.mfn); + curr->arch.guest_table_user = pagetable_from_mfn(new_mfn); - if ( old_mfn != 0 ) + if ( !mfn_eq(old_mfn, _mfn(0)) ) { - page = mfn_to_page(_mfn(old_mfn)); + page = mfn_to_page(old_mfn); switch ( rc = put_page_and_type_preemptible(page) ) { diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index a6d5e39b02..051e92169a 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -394,7 +394,7 @@ static mfn_t hap_make_monitor_table(struct vcpu *v) l4_pgentry_t *l4e; mfn_t m4mfn; - ASSERT(pagetable_get_pfn(v->arch.monitor_table) == 0); + ASSERT(pagetable_is_null(v->arch.monitor_table)); if ( (pg = hap_alloc(d)) == NULL ) goto oom; diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index eb0f0edfef..346696e469 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1366,7 +1366,7 @@ void p2m_init_altp2m_ept(struct domain *d, unsigned int i) p2m->ept.ad = hostp2m->ept.ad; ept = &p2m->ept; - ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); + ept->mfn = mfn_x(pagetable_get_mfn(p2m_get_pagetable(p2m))); d->arch.altp2m_eptp[array_index_nospec(i, MAX_EPTP)] = ept->eptp; } diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index eb66077496..cccb06c26e 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -867,7 +867,7 @@ static void p2m_pt_change_entry_type_global(struct p2m_domain *p2m, unsigned long gfn = 0; unsigned int i, changed; - if ( pagetable_get_pfn(p2m_get_pagetable(p2m)) == 0 ) + if ( pagetable_is_null(p2m_get_pagetable(p2m)) ) return; ASSERT(hap_enabled(p2m->domain)); @@ -950,7 +950,7 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) ASSERT(pod_locked_by_me(p2m)); /* Audit part one: walk the domain's p2m table, checking the entries. */ - if ( pagetable_get_pfn(p2m_get_pagetable(p2m)) != 0 ) + if ( !pagetable_is_null(p2m_get_pagetable(p2m)) ) { 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 9f51370327..45b4b784d3 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -702,7 +702,7 @@ int p2m_alloc_table(struct p2m_domain *p2m) return -EINVAL; } - if ( pagetable_get_pfn(p2m_get_pagetable(p2m)) != 0 ) + if ( !pagetable_is_null(p2m_get_pagetable(p2m)) ) { P2M_ERROR("p2m already allocated for this domain\n"); p2m_unlock(p2m); diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index b6afc0fba4..5751dae344 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1520,7 +1520,7 @@ sh_make_monitor_table(struct vcpu *v) { struct domain *d = v->domain; - ASSERT(pagetable_get_pfn(v->arch.monitor_table) == 0); + ASSERT(pagetable_is_null(v->arch.monitor_table)); /* Guarantee we can get the memory we need */ shadow_prealloc(d, SH_type_monitor_table, CONFIG_PAGING_LEVELS); @@ -2351,11 +2351,11 @@ int sh_safe_not_to_sync(struct vcpu *v, mfn_t gl1mfn) ASSERT(mfn_valid(smfn)); #endif - if ( pagetable_get_pfn(v->arch.shadow_table[0]) == mfn_x(smfn) + if ( mfn_eq(pagetable_get_mfn(v->arch.shadow_table[0]), smfn) #if (SHADOW_PAGING_LEVELS == 3) - || pagetable_get_pfn(v->arch.shadow_table[1]) == mfn_x(smfn) - || pagetable_get_pfn(v->arch.shadow_table[2]) == mfn_x(smfn) - || pagetable_get_pfn(v->arch.shadow_table[3]) == mfn_x(smfn) + || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[1]), smfn) + || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[2]), smfn) + || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[3]), smfn) #endif ) return 0; @@ -3707,7 +3707,7 @@ sh_update_linear_entries(struct vcpu *v) /* Don't try to update the monitor table if it doesn't exist */ if ( shadow_mode_external(d) - && pagetable_get_pfn(v->arch.monitor_table) == 0 ) + && pagetable_is_null(v->arch.monitor_table) ) return; #if SHADOW_PAGING_LEVELS == 4 @@ -3722,7 +3722,7 @@ sh_update_linear_entries(struct vcpu *v) if ( v == current ) { __linear_l4_table[l4_linear_offset(SH_LINEAR_PT_VIRT_START)] = - l4e_from_pfn(pagetable_get_pfn(v->arch.shadow_table[0]), + l4e_from_mfn(pagetable_get_mfn(v->arch.shadow_table[0]), __PAGE_HYPERVISOR_RW); } else @@ -3730,7 +3730,7 @@ sh_update_linear_entries(struct vcpu *v) l4_pgentry_t *ml4e; ml4e = map_domain_page(pagetable_get_mfn(v->arch.monitor_table)); ml4e[l4_table_offset(SH_LINEAR_PT_VIRT_START)] = - l4e_from_pfn(pagetable_get_pfn(v->arch.shadow_table[0]), + l4e_from_mfn(pagetable_get_mfn(v->arch.shadow_table[0]), __PAGE_HYPERVISOR_RW); unmap_domain_page(ml4e); } @@ -3964,15 +3964,15 @@ sh_update_cr3(struct vcpu *v, int do_locking, bool noflush) { ASSERT(shadow_mode_external(d)); if ( hvm_paging_enabled(v) ) - ASSERT(pagetable_get_pfn(v->arch.guest_table)); + ASSERT(!pagetable_is_null(v->arch.guest_table)); else - ASSERT(v->arch.guest_table.pfn - == d->arch.paging.shadow.unpaged_pagetable.pfn); + ASSERT(mfn_eq(pagetable_get_mfn(v->arch.guest_table), + pagetable_get_mfn(d->arch.paging.shadow.unpaged_pagetable))); } #endif SHADOW_PRINTK("%pv guest_table=%"PRI_mfn"\n", - v, (unsigned long)pagetable_get_pfn(v->arch.guest_table)); + v, mfn_x(pagetable_get_mfn(v->arch.guest_table))); #if GUEST_PAGING_LEVELS == 4 if ( !(v->arch.flags & TF_kernel_mode) ) diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 30846b5f97..8abd5d255c 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -93,14 +93,14 @@ static __init void mark_pv_pt_pages_rdonly(struct domain *d, } } -static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn, +static __init void setup_pv_physmap(struct domain *d, mfn_t pgtbl_mfn, unsigned long v_start, unsigned long v_end, unsigned long vphysmap_start, unsigned long vphysmap_end, unsigned long nr_pages) { struct page_info *page = NULL; - l4_pgentry_t *pl4e, *l4start = map_domain_page(_mfn(pgtbl_pfn)); + l4_pgentry_t *pl4e, *l4start = map_domain_page(pgtbl_mfn); l3_pgentry_t *pl3e = NULL; l2_pgentry_t *pl2e = NULL; l1_pgentry_t *pl1e = NULL; @@ -760,11 +760,9 @@ int __init dom0_construct_pv(struct domain *d, /* Set up the phys->machine table if not part of the initial mapping. */ if ( parms.p2m_base != UNSET_ADDR ) - { - pfn = pagetable_get_pfn(v->arch.guest_table); - setup_pv_physmap(d, pfn, v_start, v_end, vphysmap_start, vphysmap_end, + setup_pv_physmap(d, pagetable_get_mfn(v->arch.guest_table), + v_start, v_end, vphysmap_start, vphysmap_end, nr_pages); - } /* Write the phys->machine and machine->phys table entries. */ for ( pfn = 0; pfn < count; pfn++ ) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 4aa7c35be4..04a3ebc0a2 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -247,12 +247,12 @@ static void compat_show_guest_stack(struct vcpu *v, if ( v != current ) { struct vcpu *vcpu; - unsigned long mfn; + mfn_t mfn; ASSERT(guest_kernel_mode(v, regs)); - mfn = read_cr3() >> PAGE_SHIFT; + mfn = cr3_to_mfn(read_cr3()); for_each_vcpu( v->domain, vcpu ) - if ( pagetable_get_pfn(vcpu->arch.guest_table) == mfn ) + if ( mfn_eq(pagetable_get_mfn(vcpu->arch.guest_table), mfn) ) break; if ( !vcpu ) { diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 624dbbb949..377ba14f6e 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -18,6 +18,7 @@ #ifndef __ASSEMBLY__ # include # include +# include #endif #include @@ -213,17 +214,17 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) #ifndef __ASSEMBLY__ /* Page-table type. */ -typedef struct { u64 pfn; } pagetable_t; -#define pagetable_get_paddr(x) ((paddr_t)(x).pfn << PAGE_SHIFT) +typedef struct { mfn_t mfn; } pagetable_t; +#define PAGETABLE_NULL_MFN _mfn(0) + +#define pagetable_get_paddr(x) mfn_to_maddr((x).mfn) #define pagetable_get_page(x) mfn_to_page(pagetable_get_mfn(x)) -#define pagetable_get_pfn(x) ((x).pfn) -#define pagetable_get_mfn(x) _mfn(((x).pfn)) -#define pagetable_is_null(x) ((x).pfn == 0) -#define pagetable_from_pfn(pfn) ((pagetable_t) { (pfn) }) -#define pagetable_from_mfn(mfn) ((pagetable_t) { mfn_x(mfn) }) +#define pagetable_get_mfn(x) ((x).mfn) +#define pagetable_is_null(x) mfn_eq((x).mfn, PAGETABLE_NULL_MFN) +#define pagetable_from_mfn(mfn) ((pagetable_t) { mfn }) #define pagetable_from_page(pg) pagetable_from_mfn(page_to_mfn(pg)) -#define pagetable_from_paddr(p) pagetable_from_pfn((p)>>PAGE_SHIFT) -#define pagetable_null() pagetable_from_pfn(0) +#define pagetable_from_paddr(p) pagetable_from_mfn(maddr_to_mfn(p)) +#define pagetable_null() pagetable_from_mfn(PAGETABLE_NULL_MFN) void clear_page_sse2(void *); void copy_page_sse2(void *, const void *);