From nobody Sun May 19 14:32:55 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+99097+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+99097+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1674764847; cv=none; d=zohomail.com; s=zohoarc; b=XOv9AYnQOLYHfjiNtrQwlkj4OSMFQRfqE/5hF+eL+vehUDDGbSf9fT9x1EdnlYI3D93XLjTeCePH7QqWzz9vm2ahulxoXsvHA3+iBeGBXELdlAwxsfKNXRfUqO7whFAukruYvPdu9ixOS8NU3Q1LBsRnw/BiWnCaiR8VO6G6L0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674764847; h=Content-Type:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Cy9BG/lNtEP4WlfSFAS8O+msPxfbcF0ZAlUCZZGgBmM=; b=ZubPc+3oq/L+88L4xHRb3M/a1ncr9p0ToIDnwZJzz766G8O6JCrHNP6Yq/ZKWIFPIQhMlDn9gYZNITDPWGYRE+598/ry+yDmDFgG/7t7FUMXPsQjVKnLTQq311bsUpBPRnXLIumW0f8mo03/96eKvk1mK1joNI4TnP0TuiIPzmU= 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+99097+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674764847093927.0162350115413; Thu, 26 Jan 2023 12:27:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id WVV8YY1788612xpH0DryMvjS; Thu, 26 Jan 2023 12:27:26 -0800 X-Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by mx.groups.io with SMTP id smtpd.web10.85298.1674764846236540136 for ; Thu, 26 Jan 2023 12:27:26 -0800 X-Received: by mail-pj1-f73.google.com with SMTP id a20-20020a17090ad81400b0022c3185ebbeso855038pjv.3 for ; Thu, 26 Jan 2023 12:27:26 -0800 (PST) X-Gm-Message-State: OPNJiPKdABsL4Gn8PjOUYFPqx1787277AA= X-Google-Smtp-Source: AK7set+xkZ4PmXWQsnn0XohcGAKtb/ZRr7v6v/6VM1foq43Phwi6mNxcUMwJmHpFr2A+MmduC62e6jnAHw== X-Received: from lisik.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:6647]) (user=lisik job=sendgmr) by 2002:a17:903:41cd:b0:196:237f:164d with SMTP id u13-20020a17090341cd00b00196237f164dmr1117820ple.14.1674764845282; Thu, 26 Jan 2023 12:27:25 -0800 (PST) Date: Thu, 26 Jan 2023 20:26:40 +0000 Mime-Version: 1.0 Message-ID: Subject: [edk2-devel] [PATCH v2] OvmfPkg: Create additional PML1 entries for large SEV-SNP VMs From: "Mikolaj Lisik via groups.io" To: devel@edk2.groups.io Cc: pedro.falcato@gmail.com, erdemaktas@google.com, jejb@linux.ibm.com, jiewen.yao@intel.com, min.m.xu@intel.com, thomas.lendacky@amd.com, michael.roth@amd.com, 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=1674764846; bh=Wf+ZDrW+/G/D/EAW+r+lMA2cX+Xdn5rq7kPS86uk6V0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=a5hWHFqrTqSz8JGN5w6w7ZxUK1IfDl+g0OrQRcN7tqfK9tWqa7CN5aYGGPiuvgTEnwz HZpLXv72g3rWnFFaSWCzdwn3oCntUvWb1J+K7oIoCRf0ZCl4POAhx62xDwLPIKF4LAtAb KP/aMONomudGUwMQIaE75LlWJV1ls0ZoKOg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674764847423100001 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 Acked-by: Gerd Hoffmann Acked-by: Tom Lendacky --- .../X64/PeiDxeVirtualMemory.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index b9c0a5b25a..75c2c36bb4 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,22 @@ 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); + if (NewPageTable =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "%a:%a: failed to allocate a new PML4 entry\n", + gEfiCallerBaseName, + __FUNCTION__ + )); + Status =3D RETURN_NO_MAPPING; + goto Done; + } + SetMem (NewPageTable, EFI_PAGE_SIZE, 0); + PageMapLevel4Entry->Uint64 =3D (UINT64)(UINTN)NewPageTable = | AddressEncMask; + PageMapLevel4Entry->Bits.MustBeZero =3D 0; + PageMapLevel4Entry->Bits.ReadWrite =3D 1; + PageMapLevel4Entry->Bits.Present =3D 1; } =20 PageDirectory1GEntry =3D (VOID *)( --=20 2.39.1.456.gfc5497dd1b-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 (#99097): https://edk2.groups.io/g/devel/message/99097 Mute This Topic: https://groups.io/mt/96551964/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-