From nobody Tue May 21 13:43:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98493+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98493+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673629366; cv=none; d=zohomail.com; s=zohoarc; b=HETVF23qlsd0B2xKopPf6Ps5wHKoIKvCuMIPwhTmRVkLEszIXsX6D3DXq11B2xWrGN29R5HUwnuZXsGHwuvR6EMWNKszMTPKAFOUoSePAREoyn5XBpFuV5r/nd4xL4coehIDkwdyreV7XZRgsb4/1uA09m8aBEgB6vNnPRXyT4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673629366; h=Content-Type:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=jhj5mIDAKtpj7PGFFCrbXz/6ZeNaou9Rmr/mFd9tYsE=; b=Rth5jXO50VIpc3n/k/kBfB/VHy9+cUT12db+3PzkZY3SFW+hEDOtD1Xx1b2ky7ngHRm8BwkPrTo28ERp0L2Ku/5dNAE+/YR5YBg25p7B8Bq+XsDxKsaR8z7QzAm2VmHNNtdcW828Cd1pwMtHIUfugkiXYp1iXb4Sf0xKkEPiU7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98493+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673629366090271.0184430769509; Fri, 13 Jan 2023 09:02:46 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uzs9YY1788612xreSEdd6cXp; Fri, 13 Jan 2023 09:02:45 -0800 X-Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by mx.groups.io with SMTP id smtpd.web10.74390.1673571429489721484 for ; Thu, 12 Jan 2023 16:57:09 -0800 X-Received: by mail-pj1-f74.google.com with SMTP id me17-20020a17090b17d100b0022901e51ab3so2125599pjb.2 for ; Thu, 12 Jan 2023 16:57:09 -0800 (PST) X-Gm-Message-State: M45hCymr6Srw6po5h1SgVW6Tx1787277AA= X-Google-Smtp-Source: AMrXdXtVocylIZSVRIvNHNrrxelXdsocfkP9gt/un6p23ZW/3cYSGDgyFbx2smD1rGlPchSr7txbSuXzpA== X-Received: from lisik.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:6647]) (user=lisik job=sendgmr) by 2002:aa7:8d52:0:b0:578:8850:fe65 with SMTP id s18-20020aa78d52000000b005788850fe65mr6345958pfe.65.1673571428763; Thu, 12 Jan 2023 16:57:08 -0800 (PST) Date: Fri, 13 Jan 2023 00:57:05 +0000 Mime-Version: 1.0 Message-ID: <5e1916c6669ee2a918a2c22b7698e96f7dbf5488.1673568149.git.lisik@google.com> Subject: [edk2-devel] [PATCH] OvmfPkg: Create additional PML4 entries for large SEV-SNP VMs From: "Mikolaj Lisik via groups.io" To: devel@edk2.groups.io Cc: Mikolaj Lisik Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lisik@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673629365; bh=8gegL33lTAm76GquhyWByAD63hv/apOZnMZDjdNOraE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=iYXiIUaBwTix9u5O6CPxWIRmlgnLVfoGY7FzqxYVhACgSRUzQbgSLRatsShOcenhwXR leUl2jBOCJT3ZhW8eamEv7GptyJL4ItxSeBiQQ3oODpL0eze3RBcDmqbTVt+jXxtjkHqc +1RiV+vcYftoj7bY92hVDAB9G4u6ehzPzzo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673629367662100019 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Edk2 was failing, rather than creating more PML4 entries, when they weren't present in the initial memory acceptance flow. Because of that VMs with more than 512G memory were crashing. This code fixes that. This change affects only SEV-SNP VMs. The code was tested by successfully booting a 512G SEV-SNP VM. Signed-off-by: Mikolaj Lisik --- .../X64/PeiDxeVirtualMemory.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index b9c0a5b25a..3dbff51ac2 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -548,6 +548,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; UINT64 PgTableMask; + UINT64 *NewPageTable; UINT64 AddressEncMask; BOOLEAN IsWpEnabled; RETURN_STATUS Status; @@ -602,15 +603,13 @@ InternalMemEncryptSevCreateIdentityMap1G ( PageMapLevel4Entry =3D (VOID *)(Cr3BaseAddress & ~PgTableMask); PageMapLevel4Entry +=3D PML4_OFFSET (PhysicalAddress); if (!PageMapLevel4Entry->Bits.Present) { - DEBUG (( - DEBUG_ERROR, - "%a:%a: bad PML4 for Physical=3D0x%Lx\n", - gEfiCallerBaseName, - __FUNCTION__, - PhysicalAddress - )); - Status =3D RETURN_NO_MAPPING; - goto Done; + NewPageTable =3D AllocatePageTableMemory(1); + ASSERT(NewPageTable !=3D NULL); + SetMem (NewPageTable, EFI_PAGE_SIZE, 0); + PageMapLevel4Entry->Uint64 =3D (UINT64)(UINTN)NewPageTable | Address= EncMask; + PageMapLevel4Entry->Bits.Present =3D 1; + PageMapLevel4Entry->Bits.MustBeZero =3D 0; + PageMapLevel4Entry->Bits.ReadWrite =3D 1; } =20 PageDirectory1GEntry =3D (VOID *)( @@ -640,7 +639,6 @@ InternalMemEncryptSevCreateIdentityMap1G ( // CpuFlushTlb (); =20 -Done: // // Restore page table write protection, if any. // --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98493): https://edk2.groups.io/g/devel/message/98493 Mute This Topic: https://groups.io/mt/96250316/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-