From patchwork Thu Mar 25 15:47:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 12164499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_BASE64_TEXT, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 971DEC433E0 for ; Thu, 25 Mar 2021 15:47:58 +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 5A20661A1D for ; Thu, 25 Mar 2021 15:47:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A20661A1D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.101431.194079 (Exim 4.92) (envelope-from ) id 1lPSCy-0007ut-3d; Thu, 25 Mar 2021 15:47:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 101431.194079; Thu, 25 Mar 2021 15:47:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPSCx-0007uk-W9; Thu, 25 Mar 2021 15:47:39 +0000 Received: by outflank-mailman (input) for mailman id 101431; Thu, 25 Mar 2021 15:47:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPSCw-0007aB-FD for xen-devel@lists.xenproject.org; Thu, 25 Mar 2021 15:47:38 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 90e61a9d-c67b-48fb-ad67-314c0884c5f5; Thu, 25 Mar 2021 15:47:24 +0000 (UTC) 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" X-Inumbo-ID: 90e61a9d-c67b-48fb-ad67-314c0884c5f5 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616687244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HuIUXo43JiGC6QHvcYLXvEgyMc8GCHFyAMB5JBDUT0U=; b=FRuRpojdVj5iOvEoW+dxlyMCODHl+a/a1WUbr1aAAH08GFtesLTcoDLI 9/7rpVxsfRY/woWScGy3TK+SjfeIZbgWNlxC0tqtABY/wE00Q+NQuHn5J BqyAXrjAA7LhdZp06Djq4BKb72sRNVix3icQAKYhQTi6jLwTWjsKJa6hV A=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: d14wjqQx1UXoMjRctiLYpxhGJHIvK94eQ5c4s89qozIWZQl4KaUHiA3YgwQSaIndFMJzBguBbN 9IzeDXGfoziG3zgZkF8T7Z6jXwxSvbHuNZteB7SBz0bD8wp9azfKqst/LXRuXFKCWHazbYvwIG qsNe2/fjTVOhnELAYg5oT5DoD8p+zOILaJwG0Ne31W+M1HtibMhGIOxAVUyFtTx/JHpWDlkIF7 l3KUNFv5kNfZcFlNLtp5ZdLzN0xKEWDtkQohQm5UC9xNsp4tNbvdtuh+M/XOoc+0RzNGiHjBo4 92E= X-SBRS: 5.1 X-MesageID: 40144197 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:z3JXcq0XqT5hO2K8TIRbEQqjBZFyeYIsi2QD101hICF9WsaTm9 my2NES0hHpgDgcMUtQ4uyoEoPoewK+ybde544NMbC+GCzvv2W1JI9vhLGSuQHIMSv46+JbyO NcY7FzYeeAfGRSoOTbxE2DE9gmyMSa66zAv4zj5lpkUA0CUdAG0y5XEQCee3cWeCBnAt4DGI OY9o57oVObCAwqR+ShAH49WfPf4+fnr/vdCyIuIz4CxE2wgSiz6Lj8eiLoris2dz9U278t/S zkvmXCl8Oemsq2wBPdyGPfhq4+8LaMpbV+LfeBhcQPJjLnhhzAXvUZZ5S4sC0ou+bq0V42kb D30mQdFv5u4HDcdHzdm2qO5yDc0S0j43Kn6ViUjWqLm72ceBsGCtFMjY8cTx3B60BIhqAY7I t32Qui16Z/PFflpmDd78KNfwx2nkC0yEBS7NI7vjh6a88iT5N/6aYY51hYFZ8cGjmS0vFaLM B+SMvb4O9fdkPyVQGmgkB/hNq2XnoyGR+aQk8N/syNugIm40xE8w== X-IronPort-AV: E=Sophos;i="5.81,277,1610427600"; d="scan'208";a="40144197" From: Anthony PERARD To: CC: , Jordan Justen , Anthony PERARD , "Ard Biesheuvel" , Laszlo Ersek , Julien Grall Subject: [PATCH v2 5/7] OvmfPkg/XenPlatformPei: Map extra physical address Date: Thu, 25 Mar 2021 15:47:11 +0000 Message-ID: <20210325154713.670104-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210325154713.670104-1-anthony.perard@citrix.com> References: <20210325154713.670104-1-anthony.perard@citrix.com> MIME-Version: 1.0 Some information available in a Xen guest can be mapped anywhere in the physical address space and they don't need to be backed by RAM. For example, the shared info page. While it's easier to put those pages anywhere, it is better to avoid mapping it where the RAM is. It might split a nice 1G guest page table into 4k pages and thus reducing performance of the guest when it access its memory. Also mapping a page like the shared info page and then unmapping it or mapping it somewhere else would live a hole in the RAM that the guest would propably not been able to use anymore. So the patch introduce a new function which can be used to 1:1 mapping of guest physical memory above 4G during the PEI phase so we can map the Xen shared pages outside of memory that can be used by guest, and as high as possible. Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- Notes: v2: - new patch OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Platform.h | 5 ++ OvmfPkg/XenPlatformPei/Xen.c | 71 +++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf index 0ef77db92c03..8790d907d3ec 100644 --- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf +++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf @@ -66,6 +66,7 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/XenPlatformPei/Platform.h b/OvmfPkg/XenPlatformPei/Platform.h index 7661f4a8de0a..e70ca58078eb 100644 --- a/OvmfPkg/XenPlatformPei/Platform.h +++ b/OvmfPkg/XenPlatformPei/Platform.h @@ -127,6 +127,11 @@ XenGetE820Map ( UINT32 *Count ); +EFI_STATUS +PhysicalAddressIdentityMapping ( + IN EFI_PHYSICAL_ADDRESS AddressToMap + ); + extern EFI_BOOT_MODE mBootMode; extern UINT8 mPhysMemAddressWidth; diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c index c41fecdc486e..b2a7d1c21dac 100644 --- a/OvmfPkg/XenPlatformPei/Xen.c +++ b/OvmfPkg/XenPlatformPei/Xen.c @@ -17,6 +17,8 @@ // // The Library classes this module consumes // +#include +#include #include #include #include @@ -25,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -386,3 +389,71 @@ InitializeXen ( return EFI_SUCCESS; } + +EFI_STATUS +PhysicalAddressIdentityMapping ( + IN EFI_PHYSICAL_ADDRESS AddressToMap + ) +{ + INTN Index; + PAGE_MAP_AND_DIRECTORY_POINTER *L4, *L3; + PAGE_TABLE_ENTRY *PageTable; + + DEBUG ((DEBUG_INFO, "Mapping 1:1 of address 0x%lx\n", (UINT64)AddressToMap)); + + // L4 / Top level Page Directory Pointers + + L4 = (VOID*)(UINTN)PcdGet32 (PcdOvmfSecPageTablesBase); + Index = PML4_OFFSET (AddressToMap); + + if (!L4[Index].Bits.Present) { + L3 = AllocatePages (1); + if (L3 == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ZeroMem (L3, EFI_PAGE_SIZE); + + L4[Index].Bits.ReadWrite = 1; + L4[Index].Bits.Accessed = 1; + L4[Index].Bits.PageTableBaseAddress = (EFI_PHYSICAL_ADDRESS)L3 >> 12; + L4[Index].Bits.Present = 1; + } + + // L3 / Next level Page Directory Pointers + + L3 = (VOID*)(EFI_PHYSICAL_ADDRESS)(L4[Index].Bits.PageTableBaseAddress << 12); + Index = PDP_OFFSET (AddressToMap); + + if (!L3[Index].Bits.Present) { + PageTable = AllocatePages (1); + if (PageTable == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ZeroMem (PageTable, EFI_PAGE_SIZE); + + L3[Index].Bits.ReadWrite = 1; + L3[Index].Bits.Accessed = 1; + L3[Index].Bits.PageTableBaseAddress = (EFI_PHYSICAL_ADDRESS)PageTable >> 12; + L3[Index].Bits.Present = 1; + } + + // L2 / Page Table Entries + + PageTable = (VOID*)(EFI_PHYSICAL_ADDRESS)(L3[Index].Bits.PageTableBaseAddress << 12); + Index = PDE_OFFSET (AddressToMap); + + if (!PageTable[Index].Bits.Present) { + PageTable[Index].Bits.ReadWrite = 1; + PageTable[Index].Bits.Accessed = 1; + PageTable[Index].Bits.Dirty = 1; + PageTable[Index].Bits.MustBe1 = 1; + PageTable[Index].Bits.PageTableBaseAddress = AddressToMap >> 21; + PageTable[Index].Bits.Present = 1; + } + + CpuFlushTlb (); + + return EFI_SUCCESS; +}