From 8757e648d11357b663331f6ed1cdb2ab017df178 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 14 Feb 2024 11:45:02 +0100 Subject: OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Needed to avoid running out of memory when booting with a large (~2048) number of vcpus. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Message-Id: <20240214104504.2931339-3-kraxel@redhat.com> --- OvmfPkg/PlatformPei/MemDetect.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'OvmfPkg/PlatformPei') diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index e0ecca10b6..d6c46ffc89 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -187,6 +187,8 @@ GetPeiMemoryCap ( UINT32 Pml4Entries; UINT32 PdpEntries; UINTN TotalPages; + UINT64 ApStacks; + UINT64 MemoryCap; // // If DXE is 32-bit, then just return the traditional 64 MB cap. @@ -234,12 +236,21 @@ GetPeiMemoryCap ( (PdpEntries + 1) * Pml4Entries + 1; ASSERT (TotalPages <= 0x40201); + // + // With 32k stacks and 4096 vcpus this lands at 128 MB (far away + // from MAX_UINT32). + // + ApStacks = PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber * PcdGet32 (PcdCpuApStackSize); + // // Add 64 MB for miscellaneous allocations. Note that for - // PhysMemAddressWidth values close to 36, the cap will actually be - // dominated by this increment. + // PhysMemAddressWidth values close to 36 and a small number of + // CPUs, the cap will actually be dominated by this increment. // - return (UINT32)(EFI_PAGES_TO_SIZE (TotalPages) + SIZE_64MB); + MemoryCap = EFI_PAGES_TO_SIZE (TotalPages) + ApStacks + SIZE_64MB; + + ASSERT (MemoryCap <= MAX_UINT32); + return (UINT32)MemoryCap; } /** -- cgit v1.2.3