From nobody Mon May 6 14:59:52 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1566224966; cv=none; d=zoho.com; s=zohoarc; b=RIUWyPC49lSU56Cn+FNEW8TVQPZg713F755fUvszRk4bFQ+SZnpnvX03eveHZp9CGZ1wovGkq8Y8vPd5jqk6uOnNAtRKKmHrJyyUWO+K5IvDYOIXVl0glt4h/blE/38e4xKVvQZkwSEAXMiIqCCne3gdjgkvdNXrANxJ1bxjE3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566224966; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vy5eHNgzC/NTRNbrR1zLOYlPRTP6Cd2fBIyp0umG1b0=; b=n6JBesXrrZycg3+sdYjP1ZjXHh4RhM396uiu3jbzCsIDHAF/vsCndDBW0Y+RQL1mARM+BDwxtu4irZ7KyAJQjPlHEPxq3Mcxty4E33f09QYVAuhIqaAvQC5efdirtICdTglVfbIJ80+aSblJBSDkF2mBrh5XRy+hTAVy8NkIEKg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1566224966811126.62693595554606; Mon, 19 Aug 2019 07:29:26 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzicj-0007Hy-0g; Mon, 19 Aug 2019 14:27:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzich-0007Ho-L3 for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 14:27:03 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 689d42cc-c28d-11e9-b90c-bc764e2007e4; Mon, 19 Aug 2019 14:27:01 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E7FDF360; Mon, 19 Aug 2019 07:27:00 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7A0673F718; Mon, 19 Aug 2019 07:26:58 -0700 (PDT) X-Inumbo-ID: 689d42cc-c28d-11e9-b90c-bc764e2007e4 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 15:26:50 +0100 Message-Id: <20190819142651.11058-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190819142651.11058-1-julien.grall@arm.com> References: <20190819142651.11058-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v4 1/2] xen: Switch parameter in get_page_from_gfn to use typesafe gfn 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: Jun Nakajima , Kevin Tian , Stefano Stabellini , Suravee Suthikulpanit , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Brian Woods , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , Boris Ostrovsky , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional change intended. Only reasonable clean-ups are done in this patch. The rest will use _gfn for the time being. The code in get_page_from_gfn is slightly reworked to also handle a bad behavior because it is not safe to use mfn_to_page(...) because mfn_valid(...) succeeds. Signed-off-by: Julien Grall Acked-by: Andrew Cooper Reviewed-by: Paul Durrant --- Changes in v4: - Drop all the reviewed-by/acked-by as the last version was sent nearly 9 months ago. - Rework the change in x86 version get_page_from_gfn - s/%#PRI_/%PRI_/ Changes in v3: - Add Jan's acked-by Changes in v2: - Remove >> PAGE_SHIFT in svm code - Fix typo in the e-mail address - Small NITs --- xen/arch/arm/guestcopy.c | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/domctl.c | 6 +++--- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/domain.c | 6 ++++-- xen/arch/x86/hvm/hvm.c | 9 +++++---- xen/arch/x86/hvm/svm/svm.c | 8 ++++---- xen/arch/x86/hvm/viridian/viridian.c | 16 ++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 4 ++-- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ xen/arch/x86/mm.c | 24 ++++++++++++++---------- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/hvm.c | 6 +++--- xen/arch/x86/physdev.c | 3 ++- xen/arch/x86/pv/descriptor-tables.c | 4 ++-- xen/arch/x86/pv/emul-priv-op.c | 6 +++--- xen/arch/x86/pv/mm.c | 2 +- xen/arch/x86/traps.c | 11 ++++++----- xen/common/domain.c | 2 +- xen/common/event_fifo.c | 12 ++++++------ xen/common/memory.c | 4 ++-- xen/include/asm-arm/p2m.h | 6 +++--- xen/include/asm-x86/p2m.h | 16 ++++++++++++---- 24 files changed, 92 insertions(+), 75 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 7a0f3e9d5f..55892062bb 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -37,7 +37,7 @@ static struct page_info *translate_get_page(copy_info_t i= nfo, uint64_t addr, return get_page_from_gva(info.gva.v, addr, write ? GV2M_WRITE : GV2M_READ); =20 - page =3D get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt, P2M_= ALLOC); + page =3D get_page_from_gfn(info.gpa.d, gaddr_to_gfn(addr), &p2mt, P2M_= ALLOC); =20 if ( !page ) return NULL; diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index e1cdeaaf2f..e9afd53e69 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1405,7 +1405,7 @@ int xenmem_add_to_physmap_one( =20 /* Take reference to the foreign domain page. * Reference will be released in XENMEM_remove_from_physmap */ - page =3D get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC); + page =3D get_page_from_gfn(od, _gfn(idx), &p2mt, P2M_ALLOC); if ( !page ) { put_pg_owner(od); diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c index 375599aca5..c5a4c9a603 100644 --- a/xen/arch/x86/cpu/vpmu.c +++ b/xen/arch/x86/cpu/vpmu.c @@ -590,7 +590,7 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_= t *params) struct vcpu *v; struct vpmu_struct *vpmu; struct page_info *page; - uint64_t gfn =3D params->val; + gfn_t gfn =3D _gfn(params->val); =20 if ( (params->vcpu >=3D d->max_vcpus) || (d->vcpu[params->vcpu] =3D=3D= NULL) ) return -EINVAL; diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 2d45e5b8a8..3ce2dd1463 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -453,7 +453,7 @@ long arch_do_domctl( break; } =20 - page =3D get_page_from_gfn(d, gfn, &t, P2M_ALLOC); + page =3D get_page_from_gfn(d, _gfn(gfn), &t, P2M_ALLOC); =20 if ( unlikely(!page) || unlikely(is_xen_heap_page(page)) ) @@ -503,11 +503,11 @@ long arch_do_domctl( =20 case XEN_DOMCTL_hypercall_init: { - unsigned long gmfn =3D domctl->u.hypercall_init.gmfn; + gfn_t gfn =3D _gfn(domctl->u.hypercall_init.gmfn); struct page_info *page; void *hypercall_page; =20 - page =3D get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); =20 if ( !page || !get_page_type(page, PGT_writable_page) ) { diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index d6d0e8be89..3b3ad27938 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -186,7 +186,7 @@ static int modified_memory(struct domain *d, { struct page_info *page; =20 - page =3D get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE); + page =3D get_page_from_gfn(d, _gfn(pfn), NULL, P2M_UNSHARE); if ( page ) { paging_mark_pfn_dirty(d, _pfn(pfn)); diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c index 5d5a746a25..3c29ff86be 100644 --- a/xen/arch/x86/hvm/domain.c +++ b/xen/arch/x86/hvm/domain.c @@ -296,8 +296,10 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu= _hvm_context_t *ctx) if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) ) { /* Shadow-mode CR3 change. Check PDBR and update refcounts. */ - struct page_info *page =3D get_page_from_gfn(v->domain, - v->arch.hvm.guest_cr[3] >> PAGE_SHIFT, + struct page_info *page; + + page =3D get_page_from_gfn(v->domain, + gaddr_to_gfn(v->arch.hvm.guest_cr[3]), NULL, P2M_ALLOC); if ( !page ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 029eea3b85..236bd6ed38 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2168,7 +2168,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer) { struct vcpu *v =3D current; struct domain *d =3D v->domain; - unsigned long gfn, old_value =3D v->arch.hvm.guest_cr[0]; + unsigned long old_value =3D v->arch.hvm.guest_cr[0]; struct page_info *page; =20 HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value =3D %lx", value); @@ -2223,7 +2223,8 @@ int hvm_set_cr0(unsigned long value, bool may_defer) if ( !paging_mode_hap(d) ) { /* The guest CR3 must be pointing to the guest physical. */ - gfn =3D v->arch.hvm.guest_cr[3] >> PAGE_SHIFT; + gfn_t gfn =3D gaddr_to_gfn(v->arch.hvm.guest_cr[3]); + page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) { @@ -2315,7 +2316,7 @@ int hvm_set_cr3(unsigned long value, bool may_defer) { /* Shadow-mode CR3 change. Check PDBR and update refcounts. */ HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR3 value =3D %lx", value); - page =3D get_page_from_gfn(v->domain, value >> PAGE_SHIFT, + page =3D get_page_from_gfn(v->domain, gaddr_to_gfn(value), NULL, P2M_ALLOC); if ( !page ) goto bad_cr3; @@ -3143,7 +3144,7 @@ enum hvm_translation_result hvm_translate_get_page( && hvm_mmio_internal(gfn_to_gaddr(gfn)) ) return HVMTRANS_bad_gfn_to_mfn; =20 - page =3D get_page_from_gfn(v->domain, gfn_x(gfn), &p2mt, P2M_UNSHARE); + page =3D get_page_from_gfn(v->domain, gfn, &p2mt, P2M_UNSHARE); =20 if ( !page ) return HVMTRANS_bad_gfn_to_mfn; diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index cf83ce9a19..620eb951b6 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_= hw_cpu *c) { if ( c->cr0 & X86_CR0_PG ) { - page =3D get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT, + page =3D get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3), NULL, P2M_ALLOC); if ( !page ) { @@ -2276,9 +2276,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr) return NULL; =20 /* Need to translate L1-GPA to MPA */ - page =3D get_page_from_gfn(v->domain,=20 - nv->nv_vvmcxaddr >> PAGE_SHIFT,=20 - &p2mt, P2M_ALLOC | P2M_UNSHARE); + page =3D get_page_from_gfn(v->domain, + gaddr_to_gfn(nv->nv_vvmcxaddr), + &p2mt, P2M_ALLOC | P2M_UNSHARE); if ( !page ) return NULL; =20 diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridi= an/viridian.c index 4b06b78a27..b393a1457b 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -256,16 +256,16 @@ static void dump_hypercall(const struct domain *d) =20 static void enable_hypercall_page(struct domain *d) { - unsigned long gmfn =3D d->arch.hvm.viridian->hypercall_gpa.pfn; - struct page_info *page =3D get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + gfn_t gfn =3D _gfn(d->arch.hvm.viridian->hypercall_gpa.pfn); + struct page_info *page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); uint8_t *p; =20 if ( !page || !get_page_type(page, PGT_writable_page) ) { if ( page ) put_page(page); - gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n= ", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); + gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN)= ); return; } =20 @@ -733,13 +733,13 @@ void viridian_dump_guest_page(const struct vcpu *v, c= onst char *name, =20 void viridian_map_guest_page(struct domain *d, struct viridian_page *vp) { - unsigned long gmfn =3D vp->msr.pfn; + gfn_t gfn =3D _gfn(vp->msr.pfn); struct page_info *page; =20 if ( vp->ptr ) return; =20 - page =3D get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) goto fail; =20 @@ -760,8 +760,8 @@ void viridian_map_guest_page(struct domain *d, struct v= iridian_page *vp) return; =20 fail: - gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); + gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); } =20 void viridian_unmap_guest_page(struct viridian_page *vp) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 0060310d74..38bdef0862 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -674,7 +674,7 @@ static int vmx_restore_cr0_cr3( { if ( cr0 & X86_CR0_PG ) { - page =3D get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, + page =3D get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), NULL, P2M_ALLOC); if ( !page ) { @@ -1314,7 +1314,7 @@ static void vmx_load_pdptrs(struct vcpu *v) if ( (cr3 & 0x1fUL) && !hvm_pcid_enabled(v) ) goto crash; =20 - page =3D get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt, P2M_UN= SHARE); + page =3D get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), &p2mt, P2M_UN= SHARE); if ( !page ) { /* Ideally you don't want to crash but rather go into a wait=20 diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index fdf449bfd1..c93ae59921 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -646,11 +646,11 @@ static void nvmx_update_apic_access_address(struct vc= pu *v) if ( ctrl & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES ) { p2m_type_t p2mt; - unsigned long apic_gpfn; + gfn_t apic_gfn; struct page_info *apic_pg; =20 - apic_gpfn =3D get_vvmcs(v, APIC_ACCESS_ADDR) >> PAGE_SHIFT; - apic_pg =3D get_page_from_gfn(v->domain, apic_gpfn, &p2mt, P2M_ALL= OC); + apic_gfn =3D gaddr_to_gfn(get_vvmcs(v, APIC_ACCESS_ADDR)); + apic_pg =3D get_page_from_gfn(v->domain, apic_gfn, &p2mt, P2M_ALLO= C); ASSERT(apic_pg && !p2m_is_paging(p2mt)); __vmwrite(APIC_ACCESS_ADDR, page_to_maddr(apic_pg)); put_page(apic_pg); @@ -667,11 +667,11 @@ static void nvmx_update_virtual_apic_address(struct v= cpu *v) if ( ctrl & CPU_BASED_TPR_SHADOW ) { p2m_type_t p2mt; - unsigned long vapic_gpfn; + gfn_t vapic_gfn; struct page_info *vapic_pg; =20 - vapic_gpfn =3D get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR) >> PAGE_SHIFT; - vapic_pg =3D get_page_from_gfn(v->domain, vapic_gpfn, &p2mt, P2M_A= LLOC); + vapic_gfn =3D gaddr_to_gfn(get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR)); + vapic_pg =3D get_page_from_gfn(v->domain, vapic_gfn, &p2mt, P2M_AL= LOC); ASSERT(vapic_pg && !p2m_is_paging(p2mt)); __vmwrite(VIRTUAL_APIC_PAGE_ADDR, page_to_maddr(vapic_pg)); put_page(vapic_pg); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7531406543..f8e2b6f921 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2083,7 +2083,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentr= y_t nl1e, p2m_query_t q =3D l1e_get_flags(nl1e) & _PAGE_RW ? P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC; =20 - page =3D get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &p2mt, q= ); + page =3D get_page_from_gfn(pg_dom, _gfn(l1e_get_pfn(nl1e)), &p= 2mt, q); =20 if ( p2m_is_paged(p2mt) ) { @@ -3307,7 +3307,8 @@ long do_mmuext_op( if ( paging_mode_refcounts(pg_owner) ) break; =20 - page =3D get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_AL= LOC); + page =3D get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL, + P2M_ALLOC); if ( unlikely(!page) ) { rc =3D -EINVAL; @@ -3372,7 +3373,8 @@ long do_mmuext_op( if ( paging_mode_refcounts(pg_owner) ) break; =20 - page =3D get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_AL= LOC); + page =3D get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL, + P2M_ALLOC); if ( unlikely(!page) ) { gdprintk(XENLOG_WARNING, @@ -3588,7 +3590,8 @@ long do_mmuext_op( } =20 case MMUEXT_CLEAR_PAGE: - page =3D get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt, P2M_A= LLOC); + page =3D get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt, + P2M_ALLOC); if ( unlikely(p2mt !=3D p2m_ram_rw) && page ) { put_page(page); @@ -3616,7 +3619,7 @@ long do_mmuext_op( { struct page_info *src_page, *dst_page; =20 - src_page =3D get_page_from_gfn(pg_owner, op.arg2.src_mfn, &p2m= t, + src_page =3D get_page_from_gfn(pg_owner, _gfn(op.arg2.src_mfn)= , &p2mt, P2M_ALLOC); if ( unlikely(p2mt !=3D p2m_ram_rw) && src_page ) { @@ -3632,7 +3635,7 @@ long do_mmuext_op( break; } =20 - dst_page =3D get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt, + dst_page =3D get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p= 2mt, P2M_ALLOC); if ( unlikely(p2mt !=3D p2m_ram_rw) && dst_page ) { @@ -3720,7 +3723,8 @@ long do_mmu_update( { struct mmu_update req; void *va =3D NULL; - unsigned long gpfn, gmfn; + unsigned long gpfn; + gfn_t gfn; struct page_info *page; unsigned int cmd, i =3D 0, done =3D 0, pt_dom; struct vcpu *curr =3D current, *v =3D curr; @@ -3833,8 +3837,8 @@ long do_mmu_update( rc =3D -EINVAL; =20 req.ptr -=3D cmd; - gmfn =3D req.ptr >> PAGE_SHIFT; - page =3D get_page_from_gfn(pt_owner, gmfn, &p2mt, P2M_ALLOC); + gfn =3D gaddr_to_gfn(req.ptr); + page =3D get_page_from_gfn(pt_owner, gfn, &p2mt, P2M_ALLOC); =20 if ( unlikely(!page) || p2mt !=3D p2m_ram_rw ) { @@ -3842,7 +3846,7 @@ long do_mmu_update( put_page(page); if ( p2m_is_paged(p2mt) ) { - p2m_mem_paging_populate(pt_owner, gmfn); + p2m_mem_paging_populate(pt_owner, gfn_x(gfn)); rc =3D -ENOENT; } else diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 4b1e38b131..4ca35b56d6 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2956,7 +2956,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned lon= g fgfn, * Take a refcnt on the mfn. NB: following supported for foreign mappi= ng: * ram_rw | ram_logdirty | ram_ro | paging_out. */ - page =3D get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC); + page =3D get_page_from_gfn(fdom, _gfn(fgfn), &p2mt, P2M_ALLOC); if ( !page || !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) ) { diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c index 0aa560b7f5..1315597878 100644 --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -388,15 +388,15 @@ void shadow_continue_emulation(struct sh_emulate_ctxt= *sh_ctxt, static mfn_t emulate_gva_to_mfn(struct vcpu *v, unsigned long vaddr, struct sh_emulate_ctxt *sh_ctxt) { - unsigned long gfn; + gfn_t gfn; struct page_info *page; mfn_t mfn; p2m_type_t p2mt; uint32_t pfec =3D PFEC_page_present | PFEC_write_access; =20 /* Translate the VA to a GFN. */ - gfn =3D paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec); - if ( gfn =3D=3D gfn_x(INVALID_GFN) ) + gfn =3D _gfn(paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec)= ); + if ( gfn_eq(gfn, INVALID_GFN) ) { x86_emul_pagefault(pfec, vaddr, &sh_ctxt->ctxt); =20 diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 3a3c15890b..4f3f438614 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -229,7 +229,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) break; =20 ret =3D -EINVAL; - page =3D get_page_from_gfn(current->domain, info.gmfn, NULL, P2M_A= LLOC); + page =3D get_page_from_gfn(current->domain, _gfn(info.gmfn), + NULL, P2M_ALLOC); if ( !page ) break; if ( !get_page_type(page, PGT_writable_page) ) diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descript= or-tables.c index 940804b18a..7b3fb2806a 100644 --- a/xen/arch/x86/pv/descriptor-tables.c +++ b/xen/arch/x86/pv/descriptor-tables.c @@ -112,7 +112,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, = unsigned int entries) { struct page_info *page; =20 - page =3D get_page_from_gfn(d, frames[i], NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, _gfn(frames[i]), NULL, P2M_ALLOC); if ( !page ) goto fail; if ( !get_page_type(page, PGT_seg_desc_page) ) @@ -219,7 +219,7 @@ long do_update_descriptor(uint64_t gaddr, seg_desc_t d) if ( !IS_ALIGNED(gaddr, sizeof(d)) || !check_descriptor(currd, &d) ) return -EINVAL; =20 - page =3D get_page_from_gfn(currd, gfn_x(gfn), NULL, P2M_ALLOC); + page =3D get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC); if ( !page ) return -EINVAL; =20 diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index 8a4909bf4c..77ffa7fdcf 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -756,12 +756,12 @@ static int write_cr(unsigned int reg, unsigned long v= al, case 3: /* Write CR3 */ { struct domain *currd =3D curr->domain; - unsigned long gfn; + gfn_t gfn; struct page_info *page; int rc; =20 - gfn =3D !is_pv_32bit_domain(currd) - ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val); + gfn =3D _gfn(!is_pv_32bit_domain(currd) + ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val)); page =3D get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC); if ( !page ) break; diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c index f5ea00ca4e..c9ad1152b4 100644 --- a/xen/arch/x86/pv/mm.c +++ b/xen/arch/x86/pv/mm.c @@ -106,7 +106,7 @@ bool pv_map_ldt_shadow_page(unsigned int offset) if ( unlikely(!(l1e_get_flags(gl1e) & _PAGE_PRESENT)) ) return false; =20 - page =3D get_page_from_gfn(currd, l1e_get_pfn(gl1e), NULL, P2M_ALLOC); + page =3D get_page_from_gfn(currd, _gfn(l1e_get_pfn(gl1e)), NULL, P2M_A= LLOC); if ( unlikely(!page) ) return false; =20 diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 23069e25ec..d8f8070ac9 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -803,7 +803,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint6= 4_t val) case 0: /* Write hypercall page */ { void *hypercall_page; - unsigned long gmfn =3D val >> PAGE_SHIFT; + gfn_t gfn =3D gaddr_to_gfn(val); unsigned int page_index =3D val & (PAGE_SIZE - 1); struct page_info *page; p2m_type_t t; @@ -816,7 +816,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint6= 4_t val) return X86EMUL_EXCEPTION; } =20 - page =3D get_page_from_gfn(d, gmfn, &t, P2M_ALLOC); + page =3D get_page_from_gfn(d, gfn, &t, P2M_ALLOC); =20 if ( !page || !get_page_type(page, PGT_writable_page) ) { @@ -825,13 +825,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uin= t64_t val) =20 if ( p2m_is_paging(t) ) { - p2m_mem_paging_populate(d, gmfn); + p2m_mem_paging_populate(d, gfn_x(gfn)); return X86EMUL_RETRY; } =20 gdprintk(XENLOG_WARNING, - "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN), = base); + "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR %08x\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_= MFN), + base); return X86EMUL_EXCEPTION; } =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 744b572195..e8f6dfbdf1 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1299,7 +1299,7 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, = unsigned offset) if ( (v !=3D current) && !(v->pause_flags & VPF_down) ) return -EINVAL; =20 - page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC); if ( !page ) return -EINVAL; =20 diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c index 230f440f14..073981ab43 100644 --- a/xen/common/event_fifo.c +++ b/xen/common/event_fifo.c @@ -361,7 +361,7 @@ static const struct evtchn_port_ops evtchn_port_ops_fif= o =3D .print_state =3D evtchn_fifo_print_state, }; =20 -static int map_guest_page(struct domain *d, uint64_t gfn, void **virt) +static int map_guest_page(struct domain *d, gfn_t gfn, void **virt) { struct page_info *p; =20 @@ -422,7 +422,7 @@ static int setup_control_block(struct vcpu *v) return 0; } =20 -static int map_control_block(struct vcpu *v, uint64_t gfn, uint32_t offset) +static int map_control_block(struct vcpu *v, gfn_t gfn, uint32_t offset) { void *virt; unsigned int i; @@ -508,7 +508,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control= *init_control) { struct domain *d =3D current->domain; uint32_t vcpu_id; - uint64_t gfn; + gfn_t gfn; uint32_t offset; struct vcpu *v; int rc; @@ -516,7 +516,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control= *init_control) init_control->link_bits =3D EVTCHN_FIFO_LINK_BITS; =20 vcpu_id =3D init_control->vcpu; - gfn =3D init_control->control_gfn; + gfn =3D _gfn(init_control->control_gfn); offset =3D init_control->offset; =20 if ( (v =3D domain_vcpu(d, vcpu_id)) =3D=3D NULL ) @@ -578,7 +578,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control= *init_control) return rc; } =20 -static int add_page_to_event_array(struct domain *d, unsigned long gfn) +static int add_page_to_event_array(struct domain *d, gfn_t gfn) { void *virt; unsigned int slot; @@ -628,7 +628,7 @@ int evtchn_fifo_expand_array(const struct evtchn_expand= _array *expand_array) return -EOPNOTSUPP; =20 spin_lock(&d->event_lock); - rc =3D add_page_to_event_array(d, expand_array->array_gfn); + rc =3D add_page_to_event_array(d, _gfn(expand_array->array_gfn)); spin_unlock(&d->event_lock); =20 return rc; diff --git a/xen/common/memory.c b/xen/common/memory.c index d9b35a608c..2634a8b762 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1393,7 +1393,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE= _PARAM(void) arg) return rc; } =20 - page =3D get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, _gfn(xrfp.gpfn), NULL, P2M_ALLOC); if ( page ) { rc =3D guest_physmap_remove_page(d, _gfn(xrfp.gpfn), @@ -1664,7 +1664,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t g= fn, bool readonly, p2m_type_t p2mt; struct page_info *page; =20 - page =3D get_page_from_gfn(d, gfn_x(gfn), &p2mt, q); + page =3D get_page_from_gfn(d, gfn, &p2mt, q); =20 #ifdef CONFIG_HAS_MEM_PAGING if ( p2m_is_paging(p2mt) ) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 03f2ee75c1..5e50596fcb 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -298,7 +298,7 @@ struct page_info *p2m_get_page_from_gfn(struct domain *= d, gfn_t gfn, p2m_type_t *t); =20 static inline struct page_info *get_page_from_gfn( - struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) + struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q) { mfn_t mfn; p2m_type_t _t; @@ -309,7 +309,7 @@ static inline struct page_info *get_page_from_gfn( * not auto-translated. */ if ( likely(d !=3D dom_xen) ) - return p2m_get_page_from_gfn(d, _gfn(gfn), t); + return p2m_get_page_from_gfn(d, gfn, t); =20 if ( !t ) t =3D &_t; @@ -320,7 +320,7 @@ static inline struct page_info *get_page_from_gfn( * DOMID_XEN sees 1-1 RAM. The p2m_type is based on the type of the * page. */ - mfn =3D _mfn(gfn); + mfn =3D _mfn(gfn_x(gfn)); page =3D mfn_to_page(mfn); =20 if ( !mfn_valid(mfn) || !get_page(page, d) ) diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94285db1b4..ff4528baf9 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -491,18 +491,26 @@ struct page_info *p2m_get_page_from_gfn(struct p2m_do= main *p2m, gfn_t gfn, p2m_query_t q); =20 static inline struct page_info *get_page_from_gfn( - struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) + struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; + mfn_t mfn; =20 if ( paging_mode_translate(d) ) - return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t, NUL= L, q); + return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q); =20 /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ if ( t ) *t =3D likely(d !=3D dom_io) ? p2m_ram_rw : p2m_mmio_direct; - page =3D mfn_to_page(_mfn(gfn)); - return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL; + + mfn =3D _mfn(gfn_x(gfn)); + + if ( !mfn_valid(mfn) ) + return NULL; + + page =3D mfn_to_page(mfn); + + return get_page(page, d) ? page : NULL; } =20 /* General conversion function from mfn to gfn */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon May 6 14:59:52 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1566224963; cv=none; d=zoho.com; s=zohoarc; b=jxG3eUspFDWz5sQZQvVhEitddA8eUSh9U3IW7CBLttyln8bXLSxuiYRANuKNh8aSvr2Tc8XiWjHc3KsPWQX7uHSQWxMOH1khc0/08Bko2URhgvXjhS2eh5rOlIa3smKNkuF3V+19N6/OJC5s5gUtXis82wk1g5wCzDgNXewbfgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566224963; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Cm0cPtxEyRX2EOFBwp4YFmukFT9Ue/LvB0n8E7zK0NU=; b=Xd9TrB6hsNfkheNsZfz8F6fH1lcvqnNFhtxbb1G/hZDJriyrkdSh95/KVKHxnkdvUk36zk7R4kOAy/jawwDIgXtW7pVQ1R8zOIkjRmXEpQWZrs6KE/mlrkdXsPWjdmxaBB1wez0EdJIZlqSfqVjrOq42JwAjg3dGhnSs6hciOVs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1566224963343449.27309036744987; Mon, 19 Aug 2019 07:29:23 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzicj-0007I8-96; Mon, 19 Aug 2019 14:27:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzici-0007Ht-2I for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 14:27:04 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 69736474-c28d-11e9-b90c-bc764e2007e4; Mon, 19 Aug 2019 14:27:02 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D9DC1576; Mon, 19 Aug 2019 07:27:02 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 29E2E3F718; Mon, 19 Aug 2019 07:27:01 -0700 (PDT) X-Inumbo-ID: 69736474-c28d-11e9-b90c-bc764e2007e4 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 15:26:51 +0100 Message-Id: <20190819142651.11058-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190819142651.11058-1-julien.grall@arm.com> References: <20190819142651.11058-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v4 2/2] xen/domain: Use typesafe gfn in map_vcpu_info 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: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the same time, modify the documentation of the hypercall to reflect the real meaning of the field mfn. Signed-off-by: Julien Grall --- Changes in v4: - Patch added --- xen/common/domain.c | 6 +++--- xen/include/public/vcpu.h | 2 +- xen/include/xen/domain.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index e8f6dfbdf1..915ebca190 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1282,7 +1282,7 @@ int vcpu_reset(struct vcpu *v) * of memory, and it sets a pending event to make sure that a pending * event doesn't get missed. */ -int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset) +int map_vcpu_info(struct vcpu *v, gfn_t gfn, unsigned offset) { struct domain *d =3D v->domain; void *mapping; @@ -1299,7 +1299,7 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, = unsigned offset) if ( (v !=3D current) && !(v->pause_flags & VPF_down) ) return -EINVAL; =20 - page =3D get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) return -EINVAL; =20 @@ -1538,7 +1538,7 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUE= ST_HANDLE_PARAM(void) arg) break; =20 domain_lock(d); - rc =3D map_vcpu_info(v, info.mfn, info.offset); + rc =3D map_vcpu_info(v, _gfn(info.mfn), info.offset); domain_unlock(d); =20 break; diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h index 3623af932f..dc4c6a72a0 100644 --- a/xen/include/public/vcpu.h +++ b/xen/include/public/vcpu.h @@ -182,7 +182,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t); */ #define VCPUOP_register_vcpu_info 10 /* arg =3D=3D vcpu_register_vcpu_i= nfo_t */ struct vcpu_register_vcpu_info { - uint64_t mfn; /* mfn of page to place vcpu_info */ + uint64_t mfn; /* gfn of page to place vcpu_info */ uint32_t offset; /* offset within page */ uint32_t rsvd; /* unused */ }; diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 3f09cb66c0..7e754f7cc0 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -58,7 +58,7 @@ void free_pirq_struct(void *); int arch_vcpu_create(struct vcpu *v); void arch_vcpu_destroy(struct vcpu *v); =20 -int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset); +int map_vcpu_info(struct vcpu *v, gfn_t gfn, unsigned offset); void unmap_vcpu_info(struct vcpu *v); =20 int arch_domain_create(struct domain *d, --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel