From nobody Mon Feb 9 12:14:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1617707205; cv=none; d=zohomail.com; s=zohoarc; b=BhZe4jg1O2iHNvlVpO1tBVqos0lHbjxDhGZTeF2OTvSIVicWrVrcnWpj3guuj1GOqCUafGgDJjJKty9YqJiaEPbPvUnrGRrx8Q0qkx7Me0mmaDrZhtO5MsLwpiIg6+U2mlhjCjsAT+vs+oFaTIpH0JhRBuidSczE6fSCjcq2h+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617707205; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Bokmzti3DdezOdGif8N/czvpGiQImoEVzNR/uUs1QN8=; b=jTeFDns0fFLeR/EXoJezEqYJ5cV/Ox1Gpa/MKt+TIVGLV6HQy3OlvHgsL0khDeZV4zg8lvG3tGo6Ax6wI1U2f2/8LNyg6Hzmtr5XVs5lVJmz0IpzYr+ZDXZU2fbAWXSdLCvXq7kBRiI8jQC7JsZUOX7KMT308coWupNoGGmUr2Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 16177072058181005.563920767669; Tue, 6 Apr 2021 04:06:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.105807.202440 (Exim 4.92) (envelope-from ) id 1lTjXT-0004YK-Rj; Tue, 06 Apr 2021 11:06:31 +0000 Received: by outflank-mailman (output) from mailman id 105807.202440; Tue, 06 Apr 2021 11:06:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXT-0004Y6-NM; Tue, 06 Apr 2021 11:06:31 +0000 Received: by outflank-mailman (input) for mailman id 105807; Tue, 06 Apr 2021 11:06:30 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXS-0004WA-Qk for xen-devel@lists.xenproject.org; Tue, 06 Apr 2021 11:06:30 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXS-00053d-Jv; Tue, 06 Apr 2021 11:06:30 +0000 Received: from 54-240-197-238.amazon.com ([54.240.197.238] helo=ua82172827c7b5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTjXS-0002qD-6v; Tue, 06 Apr 2021 11:06:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From; bh=Bokmzti3DdezOdGif8N/czvpGiQImoEVzNR/uUs1QN8=; b=A vngtYDbyG7tFo8wyRVUrNeuWuFv7P8+SOiyYGBDp/Mf3zYscyUoh9KJ+nAXZyA4H9ZNENxy1/uQNE I/vxLqgkNrZxoYTqZkO7f/ziaKzsgKuFnSYJcEHdXurd5MIZVY5UkeUlXzPXlfScLaFbEuIisImIu zI30WG7B2NnaeYoE=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Cc: jgrall@amazon.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v9 08/13] efi: switch to new APIs in EFI code Date: Tue, 6 Apr 2021 12:05:56 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v7: - add blank line after declaration. - rename efi_l4_pgtable into efi_l4t. - pass the mapped efi_l4t to copy_mapping() instead of map it again. - use the alloc_map_clear_xen_pt() API. - unmap pl3e, pl2e, l1t earlier. --- xen/arch/x86/efi/runtime.h | 13 ++++++--- xen/common/efi/boot.c | 55 ++++++++++++++++++++++---------------- xen/common/efi/efi.h | 3 ++- xen/common/efi/runtime.c | 8 +++--- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/efi/runtime.h b/xen/arch/x86/efi/runtime.h index d9eb8f5c270f..77866c5f2178 100644 --- a/xen/arch/x86/efi/runtime.h +++ b/xen/arch/x86/efi/runtime.h @@ -1,12 +1,19 @@ +#include +#include #include #include =20 #ifndef COMPAT -l4_pgentry_t *__read_mostly efi_l4_pgtable; +mfn_t __read_mostly efi_l4_mfn =3D INVALID_MFN_INITIALIZER; =20 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { - if ( efi_l4_pgtable ) - l4e_write(efi_l4_pgtable + l4idx, l4e); + if ( !mfn_eq(efi_l4_mfn, INVALID_MFN) ) + { + l4_pgentry_t *efi_l4t =3D map_domain_page(efi_l4_mfn); + + l4e_write(efi_l4t + l4idx, l4e); + unmap_domain_page(efi_l4t); + } } #endif diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 64b319d0013b..f21ad5030f41 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1437,14 +1437,15 @@ custom_param("efi", parse_efi_param); =20 static __init void copy_mapping(unsigned long mfn, unsigned long end, bool (*is_valid)(unsigned long smfn, - unsigned long emfn)) + unsigned long emfn), + l4_pgentry_t *efi_l4t) { unsigned long next; l3_pgentry_t *l3src =3D NULL, *l3dst =3D NULL; =20 for ( ; mfn < end; mfn =3D next ) { - l4_pgentry_t l4e =3D efi_l4_pgtable[l4_table_offset(mfn << PAGE_SH= IFT)]; + l4_pgentry_t l4e =3D efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)]; unsigned long va =3D (unsigned long)mfn_to_virt(mfn); =20 if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) ) @@ -1463,7 +1464,7 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, =20 l3dst =3D alloc_map_clear_xen_pt(&l3mfn); BUG_ON(!l3dst); - efi_l4_pgtable[l4_table_offset(mfn << PAGE_SHIFT)] =3D + efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)] =3D l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); } else @@ -1496,6 +1497,7 @@ static bool __init rt_range_valid(unsigned long smfn,= unsigned long emfn) void __init efi_init_memory(void) { unsigned int i; + l4_pgentry_t *efi_l4t; struct rt_extra { struct rt_extra *next; unsigned long smfn, emfn; @@ -1610,11 +1612,10 @@ void __init efi_init_memory(void) * Set up 1:1 page tables for runtime calls. See SetVirtualAddressMap(= ) in * efi_exit_boot(). */ - efi_l4_pgtable =3D alloc_xen_pagetable(); - BUG_ON(!efi_l4_pgtable); - clear_page(efi_l4_pgtable); + efi_l4t =3D alloc_map_clear_xen_pt(&efi_l4_mfn); + BUG_ON(!efi_l4t); =20 - copy_mapping(0, max_page, ram_range_valid); + copy_mapping(0, max_page, ram_range_valid, efi_l4t); =20 /* Insert non-RAM runtime mappings inside the direct map. */ for ( i =3D 0; i < efi_memmap_size; i +=3D efi_mdesc_size ) @@ -1630,58 +1631,64 @@ void __init efi_init_memory(void) copy_mapping(PFN_DOWN(desc->PhysicalStart), PFN_UP(desc->PhysicalStart + (desc->NumberOfPages << EFI_PAGE_SHIFT)), - rt_range_valid); + rt_range_valid, efi_l4t); } =20 /* Insert non-RAM runtime mappings outside of the direct map. */ while ( (extra =3D extra_head) !=3D NULL ) { unsigned long addr =3D extra->smfn << PAGE_SHIFT; - l4_pgentry_t l4e =3D efi_l4_pgtable[l4_table_offset(addr)]; + l4_pgentry_t l4e =3D efi_l4t[l4_table_offset(addr)]; l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; l1_pgentry_t *l1t; =20 if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - pl3e =3D alloc_xen_pagetable(); + mfn_t l3mfn; + + pl3e =3D alloc_map_clear_xen_pt(&l3mfn); BUG_ON(!pl3e); - clear_page(pl3e); - efi_l4_pgtable[l4_table_offset(addr)] =3D - l4e_from_paddr(virt_to_maddr(pl3e), __PAGE_HYPERVISOR); + efi_l4t[l4_table_offset(addr)] =3D + l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); } else - pl3e =3D l4e_to_l3e(l4e); + pl3e =3D map_l3t_from_l4e(l4e); pl3e +=3D l3_table_offset(addr); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - pl2e =3D alloc_xen_pagetable(); + mfn_t l2mfn; + + pl2e =3D alloc_map_clear_xen_pt(&l2mfn); BUG_ON(!pl2e); - clear_page(pl2e); - *pl3e =3D l3e_from_paddr(virt_to_maddr(pl2e), __PAGE_HYPERVISO= R); + *pl3e =3D l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR); } else { BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); - pl2e =3D l3e_to_l2e(*pl3e); + pl2e =3D map_l2t_from_l3e(*pl3e); } + UNMAP_DOMAIN_PAGE(pl3e); pl2e +=3D l2_table_offset(addr); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - l1t =3D alloc_xen_pagetable(); + mfn_t l1mfn; + + l1t =3D alloc_map_clear_xen_pt(&l1mfn); BUG_ON(!l1t); - clear_page(l1t); - *pl2e =3D l2e_from_paddr(virt_to_maddr(l1t), __PAGE_HYPERVISOR= ); + *pl2e =3D l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR); } else { BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE); - l1t =3D l2e_to_l1e(*pl2e); + l1t =3D map_l1t_from_l2e(*pl2e); } + UNMAP_DOMAIN_PAGE(pl2e); for ( i =3D l1_table_offset(addr); i < L1_PAGETABLE_ENTRIES && extra->smfn < extra->emfn; ++i, ++extra->smfn ) l1t[i] =3D l1e_from_pfn(extra->smfn, extra->prot); + UNMAP_DOMAIN_PAGE(l1t); =20 if ( extra->smfn =3D=3D extra->emfn ) { @@ -1693,6 +1700,8 @@ void __init efi_init_memory(void) /* Insert Xen mappings. */ for ( i =3D l4_table_offset(HYPERVISOR_VIRT_START); i < l4_table_offset(DIRECTMAP_VIRT_END); ++i ) - efi_l4_pgtable[i] =3D idle_pg_table[i]; + efi_l4t[i] =3D idle_pg_table[i]; + + unmap_domain_page(efi_l4t); } #endif diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 663a8b5000d9..c9aa65d506b1 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include =20 @@ -29,7 +30,7 @@ extern UINTN efi_memmap_size, efi_mdesc_size; extern void *efi_memmap; =20 #ifdef CONFIG_X86 -extern l4_pgentry_t *efi_l4_pgtable; +extern mfn_t efi_l4_mfn; #endif =20 extern const struct efi_pci_rom *efi_pci_roms; diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 95367694b5f3..375b94229e13 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -85,7 +85,7 @@ struct efi_rs_state efi_rs_enter(void) static const u32 mxcsr =3D MXCSR_DEFAULT; struct efi_rs_state state =3D { .cr3 =3D 0 }; =20 - if ( !efi_l4_pgtable ) + if ( mfn_eq(efi_l4_mfn, INVALID_MFN) ) return state; =20 state.cr3 =3D read_cr3(); @@ -111,7 +111,7 @@ struct efi_rs_state efi_rs_enter(void) lgdt(&gdt_desc); } =20 - switch_cr3_cr4(virt_to_maddr(efi_l4_pgtable), read_cr4()); + switch_cr3_cr4(mfn_to_maddr(efi_l4_mfn), read_cr4()); =20 return state; } @@ -140,9 +140,9 @@ void efi_rs_leave(struct efi_rs_state *state) =20 bool efi_rs_using_pgtables(void) { - return efi_l4_pgtable && + return !mfn_eq(efi_l4_mfn, INVALID_MFN) && (smp_processor_id() =3D=3D efi_rs_on_cpu) && - (read_cr3() =3D=3D virt_to_maddr(efi_l4_pgtable)); + (read_cr3() =3D=3D mfn_to_maddr(efi_l4_mfn)); } =20 unsigned long efi_get_time(void) --=20 2.23.3