From nobody Thu Apr 25 20:12:28 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=1557242213; cv=none; d=zoho.com; s=zohoarc; b=Dxh1vD0s9jWQ/m80gmQD1L9yLCeQjcerBCFQzs+IuPkVKzy8CVecJ2HMFcYWSAcptjdMHg043bHl9pdpSTSuIWl7Mu1f8pwvTfCZPGeUL7AJ82OfpaQ8twDcGr0vVZqWiM8Bmg0ziXp0CGDTzW40tkhlxz5p5uMqlGxM4K0e3yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557242213; 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=Y9ETzyo+1KP0BmnYQ+Kx9113zhEhvc6xvzoEGYZoItM=; b=beQAaZ8FImF2PFc5cPV4EaxgUcqaR/9Cp+X/Iw1zsKOiEgSOOTRGQE2xng2cXOaHhu3MP56agFKruJi7YueXQ/wTmRku5/W2DbWgvSk3wU/gQIsvmCUDNXZxvq9nNV1YrfccjfE3wuVHSJKJKMMVMBneFCLQDqVKYVzSn/UXTUY= 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 1557242213312874.5276766014608; Tue, 7 May 2019 08:16:53 -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 1hO1oe-0007Z3-7R; Tue, 07 May 2019 15:15:36 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hO1oc-0007WE-VI for xen-devel@lists.xenproject.org; Tue, 07 May 2019 15:15:35 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id f50b4400-70da-11e9-843c-bc764e045a96; Tue, 07 May 2019 15:15:32 +0000 (UTC) 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 A77F91682; Tue, 7 May 2019 08:15:32 -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 741453F5AF; Tue, 7 May 2019 08:15:31 -0700 (PDT) X-Inumbo-ID: f50b4400-70da-11e9-843c-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 7 May 2019 16:14:56 +0100 Message-Id: <20190507151458.29350-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190507151458.29350-1-julien.grall@arm.com> References: <20190507151458.29350-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 12/14] xen/x86: pv: Convert update_intpte() to use typesafe MFN 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: Andrew Cooper , Julien Grall , Wei Liu , Jan Beulich , =?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" The third parameter of update_intpte() is a MFN, so it can be switched to use the typesafe. At the same time, the typesafe is propagated as far as possible without major modifications. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- Changes in v2: - Patch added --- xen/arch/x86/mm.c | 84 ++++++++++++++++++++-----------------= ---- xen/arch/x86/pv/grant_table.c | 6 +-- xen/arch/x86/pv/mm.h | 6 +-- xen/arch/x86/pv/ro-page-fault.c | 2 +- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 570e1e0deb..7d887f2699 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2080,7 +2080,7 @@ void page_unlock(struct page_info *page) =20 /* Update the L1 entry at pl1e to new value nl1e. */ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, - unsigned long gl1mfn, unsigned int cmd, + mfn_t gl1mfn, unsigned int cmd, struct vcpu *pt_vcpu, struct domain *pg_dom) { bool preserve_ad =3D (cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD); @@ -2177,8 +2177,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentr= y_t nl1e, } else if ( pv_l1tf_check_l1e(pt_dom, nl1e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, - preserve_ad)) ) + else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, + pt_vcpu, preserve_ad)) ) { return -EBUSY; } @@ -2188,16 +2188,16 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgen= try_t nl1e, } =20 =20 -/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame pfn= . */ +/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame mfn= . */ static int mod_l2_entry(l2_pgentry_t *pl2e, l2_pgentry_t nl2e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { l2_pgentry_t ol2e; struct domain *d =3D vcpu->domain; - struct page_info *l2pg =3D mfn_to_page(_mfn(pfn)); + struct page_info *l2pg =3D mfn_to_page(mfn); unsigned long type =3D l2pg->u.inuse.type_info; int rc =3D 0; =20 @@ -2224,16 +2224,16 @@ static int mod_l2_entry(l2_pgentry_t *pl2e, if ( !l2e_has_changed(ol2e, nl2e, ~FASTPATH_FLAG_WHITELIST) ) { nl2e =3D adjust_guest_l2e(nl2e, d); - if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad= ) ) + if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad= ) ) return 0; return -EBUSY; } =20 - if ( unlikely((rc =3D get_page_from_l2e(nl2e, pfn, d, 0)) < 0) ) + if ( unlikely((rc =3D get_page_from_l2e(nl2e, mfn_x(mfn), d, 0)) <= 0) ) return rc; =20 nl2e =3D adjust_guest_l2e(nl2e, d); - if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad)) ) { ol2e =3D nl2e; @@ -2242,21 +2242,21 @@ static int mod_l2_entry(l2_pgentry_t *pl2e, } else if ( pv_l1tf_check_l2e(d, nl2e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad)) ) { return -EBUSY; } =20 - put_page_from_l2e(ol2e, pfn, 0, true); + put_page_from_l2e(ol2e, mfn_x(mfn), 0, true); =20 return rc; } =20 -/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame pfn= . */ +/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame mfn= . */ static int mod_l3_entry(l3_pgentry_t *pl3e, l3_pgentry_t nl3e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { @@ -2287,17 +2287,17 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, if ( !l3e_has_changed(ol3e, nl3e, ~FASTPATH_FLAG_WHITELIST) ) { nl3e =3D adjust_guest_l3e(nl3e, d); - rc =3D UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, preserve_= ad); + rc =3D UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_= ad); return rc ? 0 : -EFAULT; } =20 - rc =3D get_page_from_l3e(nl3e, pfn, d, 0); + rc =3D get_page_from_l3e(nl3e, mfn_x(mfn), d, 0); if ( unlikely(rc < 0) ) return rc; rc =3D 0; =20 nl3e =3D adjust_guest_l3e(nl3e, d); - if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_ad)) ) { ol3e =3D nl3e; @@ -2306,7 +2306,7 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, } else if ( pv_l1tf_check_l3e(d, nl3e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_ad)) ) { return -EFAULT; @@ -2316,14 +2316,14 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, if ( !create_pae_xen_mappings(d, pl3e) ) BUG(); =20 - put_page_from_l3e(ol3e, pfn, 0, 1); + put_page_from_l3e(ol3e, mfn_x(mfn), 0, 1); return rc; } =20 -/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame pfn= . */ +/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame mfn= . */ static int mod_l4_entry(l4_pgentry_t *pl4e, l4_pgentry_t nl4e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { @@ -2354,17 +2354,17 @@ static int mod_l4_entry(l4_pgentry_t *pl4e, if ( !l4e_has_changed(ol4e, nl4e, ~FASTPATH_FLAG_WHITELIST) ) { nl4e =3D adjust_guest_l4e(nl4e, d); - rc =3D UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, preserve_= ad); + rc =3D UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_= ad); return rc ? 0 : -EFAULT; } =20 - rc =3D get_page_from_l4e(nl4e, pfn, d, 0); + rc =3D get_page_from_l4e(nl4e, mfn_x(mfn), d, 0); if ( unlikely(rc < 0) ) return rc; rc =3D 0; =20 nl4e =3D adjust_guest_l4e(nl4e, d); - if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_ad)) ) { ol4e =3D nl4e; @@ -2373,13 +2373,13 @@ static int mod_l4_entry(l4_pgentry_t *pl4e, } else if ( pv_l1tf_check_l4e(d, nl4e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_ad)) ) { return -EFAULT; } =20 - put_page_from_l4e(ol4e, pfn, 0, 1); + put_page_from_l4e(ol4e, mfn_x(mfn), 0, 1); return rc; } #endif /* CONFIG_PV */ @@ -3083,7 +3083,7 @@ int new_guest_cr3(mfn_t mfn) l4e_from_mfn(mfn, (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)), - mfn_x(gt_mfn), 0, curr); + gt_mfn, 0, curr); unmap_domain_page(pl4e); switch ( rc ) { @@ -3752,12 +3752,12 @@ long do_mmu_update( { struct mmu_update req; void *va =3D NULL; - unsigned long gpfn, gmfn, mfn; + unsigned long gpfn, gmfn; struct page_info *page; unsigned int cmd, i =3D 0, done =3D 0, pt_dom; struct vcpu *curr =3D current, *v =3D curr; struct domain *d =3D v->domain, *pt_owner =3D d, *pg_owner; - mfn_t map_mfn =3D INVALID_MFN; + mfn_t map_mfn =3D INVALID_MFN, mfn; bool sync_guest =3D false; uint32_t xsm_needed =3D 0; uint32_t xsm_checked =3D 0; @@ -3883,14 +3883,14 @@ long do_mmu_update( break; } =20 - mfn =3D mfn_x(page_to_mfn(page)); + mfn =3D page_to_mfn(page); =20 - if ( !mfn_eq(_mfn(mfn), map_mfn) ) + if ( !mfn_eq(mfn, map_mfn) ) { if ( va ) unmap_domain_page(va); - va =3D map_domain_page(_mfn(mfn)); - map_mfn =3D _mfn(mfn); + va =3D map_domain_page(mfn); + map_mfn =3D mfn; } va =3D _p(((unsigned long)va & PAGE_MASK) + (req.ptr & ~PAGE_M= ASK)); =20 @@ -3926,7 +3926,8 @@ long do_mmu_update( { bool local_in_use =3D false; =20 - if ( pagetable_get_pfn(curr->arch.guest_table) =3D= =3D mfn ) + if ( mfn_eq(pagetable_get_mfn(curr->arch.guest_tab= le), + mfn) ) { local_in_use =3D true; get_cpu_info()->root_pgt_changed =3D true; @@ -3939,15 +3940,15 @@ long do_mmu_update( */ if ( (page->u.inuse.type_info & PGT_count_mask) > (1 + !!(page->u.inuse.type_info & PGT_pinned)= + - (pagetable_get_pfn(curr->arch.guest_table_us= er) =3D=3D - mfn) + local_in_use) ) + (mfn_eq(pagetable_get_mfn(curr->arch.guest_t= able_user), + mfn)) + local_in_use) ) sync_guest =3D true; } break; =20 case PGT_writable_page: perfc_incr(writable_mmu_updates); - if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn= )) ) + if ( paging_write_guest_entry(v, va, req.val, mfn) ) rc =3D 0; break; } @@ -3958,7 +3959,7 @@ long do_mmu_update( else if ( get_page_type(page, PGT_writable_page) ) { perfc_incr(writable_mmu_updates); - if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) ) + if ( paging_write_guest_entry(v, va, req.val, mfn) ) rc =3D 0; put_page_type(page); } @@ -3980,7 +3981,7 @@ long do_mmu_update( break; } =20 - mfn =3D req.ptr >> PAGE_SHIFT; + mfn =3D maddr_to_mfn(req.ptr); gpfn =3D req.val; =20 xsm_needed |=3D XSM_MMU_MACHPHYS_UPDATE; @@ -3992,7 +3993,7 @@ long do_mmu_update( xsm_checked =3D xsm_needed; } =20 - page =3D get_page_from_mfn(_mfn(mfn), pg_owner); + page =3D get_page_from_mfn(mfn, pg_owner); if ( unlikely(!page) ) { gdprintk(XENLOG_WARNING, @@ -4001,7 +4002,7 @@ long do_mmu_update( break; } =20 - set_gpfn_from_mfn(mfn, gpfn); + set_gpfn_from_mfn(mfn_x(mfn), gpfn); paging_mark_pfn_dirty(pg_owner, _pfn(gpfn)); =20 put_page(page); @@ -4257,8 +4258,7 @@ static int __do_update_va_mapping( goto out; } =20 - rc =3D mod_l1_entry(pl1e, val, mfn_x(gl1mfn), MMU_NORMAL_PT_UPDATE, v, - pg_owner); + rc =3D mod_l1_entry(pl1e, val, gl1mfn, MMU_NORMAL_PT_UPDATE, v, pg_own= er); =20 page_unlock(gl1pg); put_page(gl1pg); diff --git a/xen/arch/x86/pv/grant_table.c b/xen/arch/x86/pv/grant_table.c index 5180334f42..0325618c98 100644 --- a/xen/arch/x86/pv/grant_table.c +++ b/xen/arch/x86/pv/grant_table.c @@ -108,7 +108,7 @@ int create_grant_pv_mapping(uint64_t addr, mfn_t frame, goto out_unlock; =20 ol1e =3D *pl1e; - if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) ) + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) ) rc =3D GNTST_okay; =20 out_unlock: @@ -165,7 +165,7 @@ static bool steal_linear_address(unsigned long linear, = l1_pgentry_t *out) goto out_unlock; =20 ol1e =3D *pl1e; - okay =3D UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), mfn_x(gl1mfn), curr= , 0); + okay =3D UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), gl1mfn, curr, 0); =20 if ( okay ) *out =3D ol1e; @@ -293,7 +293,7 @@ int replace_grant_pv_mapping(uint64_t addr, mfn_t frame, "PTE flags %x for %"PRIx64" don't match grant (%x)\n", l1e_get_flags(ol1e), addr, grant_pte_flags); =20 - if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) ) + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) ) rc =3D GNTST_okay; =20 out_unlock: diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h index 976209ba4c..ef84dbb41c 100644 --- a/xen/arch/x86/pv/mm.h +++ b/xen/arch/x86/pv/mm.h @@ -37,7 +37,7 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned lon= g linear) * Returns false for failure (pointer not valid), true for success. */ static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new, - unsigned long mfn, struct vcpu *v, + mfn_t mfn, struct vcpu *v, bool preserve_ad) { bool rv =3D true; @@ -45,7 +45,7 @@ static inline bool update_intpte(intpte_t *p, intpte_t ol= d, intpte_t new, #ifndef PTE_UPDATE_WITH_CMPXCHG if ( !preserve_ad ) { - rv =3D paging_write_guest_entry(v, p, new, _mfn(mfn)); + rv =3D paging_write_guest_entry(v, p, new, mfn); } else #endif @@ -59,7 +59,7 @@ static inline bool update_intpte(intpte_t *p, intpte_t ol= d, intpte_t new, if ( preserve_ad ) _new |=3D old & (_PAGE_ACCESSED | _PAGE_DIRTY); =20 - rv =3D paging_cmpxchg_guest_entry(v, p, &t, _new, _mfn(mfn)); + rv =3D paging_cmpxchg_guest_entry(v, p, &t, _new, mfn); if ( unlikely(rv =3D=3D 0) ) { gdprintk(XENLOG_WARNING, diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-faul= t.c index e7a7179dda..92911076ef 100644 --- a/xen/arch/x86/pv/ro-page-fault.c +++ b/xen/arch/x86/pv/ro-page-fault.c @@ -197,7 +197,7 @@ static int ptwr_emulated_update(unsigned long addr, int= pte_t *p_old, else { ol1e =3D *pl1e; - if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(mfn), v, 0) ) + if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn, v, 0) ) BUG(); } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel