* [edk2-devel] [PATCH v3 1/4] OvmfPkg/PlatformPei: log a warning when memory is tight
2024-02-14 10:45 [edk2-devel] [PATCH v3 0/4] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
@ 2024-02-14 10:45 ` Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 2/4] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Gerd Hoffmann
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2024-02-14 10:45 UTC (permalink / raw)
To: devel
Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao, Laszlo Ersek,
Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
OvmfPkg/PlatformPei/MemDetect.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 493cb1fbeb01..e0ecca10b6e0 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -319,6 +319,14 @@ PublishPeiMemory (
if (MemorySize > PeiMemoryCap) {
MemoryBase = LowerMemorySize - PeiMemoryCap;
MemorySize = PeiMemoryCap;
+ } else {
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: Not enough memory for PEI (have %lu KB, estimated need %u KB)\n",
+ __func__,
+ RShiftU64 (MemorySize, 10),
+ PeiMemoryCap >> 10
+ ));
}
}
--
2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115437): https://edk2.groups.io/g/devel/message/115437
Mute This Topic: https://groups.io/mt/104350490/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [edk2-devel] [PATCH v3 2/4] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap
2024-02-14 10:45 [edk2-devel] [PATCH v3 0/4] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 1/4] OvmfPkg/PlatformPei: log a warning when memory is tight Gerd Hoffmann
@ 2024-02-14 10:45 ` Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 3/4] OvmfPkg/PlatformPei: rewrite page table calculation Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
3 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2024-02-14 10:45 UTC (permalink / raw)
To: devel
Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao, Laszlo Ersek,
Gerd Hoffmann
Needed to avoid running out of memory when booting
with a large (~2048) number of vcpus.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
OvmfPkg/PlatformPei/MemDetect.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index e0ecca10b6e0..d6c46ffc89dd 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;
}
/**
--
2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115440): https://edk2.groups.io/g/devel/message/115440
Mute This Topic: https://groups.io/mt/104350493/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [edk2-devel] [PATCH v3 3/4] OvmfPkg/PlatformPei: rewrite page table calculation
2024-02-14 10:45 [edk2-devel] [PATCH v3 0/4] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 1/4] OvmfPkg/PlatformPei: log a warning when memory is tight Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 2/4] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Gerd Hoffmann
@ 2024-02-14 10:45 ` Gerd Hoffmann
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
3 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2024-02-14 10:45 UTC (permalink / raw)
To: devel
Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao, Laszlo Ersek,
Gerd Hoffmann
Consider 5-level paging. Simplify calculation to make it easier
to understand. Add some comments, improve ASSERTs.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
OvmfPkg/PlatformPei/MemDetect.c | 58 ++++++++++++++++++++-------------
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index d6c46ffc89dd..81c29c626bb3 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -184,9 +184,12 @@ GetPeiMemoryCap (
BOOLEAN Page1GSupport;
UINT32 RegEax;
UINT32 RegEdx;
- UINT32 Pml4Entries;
- UINT32 PdpEntries;
- UINTN TotalPages;
+ UINT64 MaxAddr;
+ UINT32 Level5Pages;
+ UINT32 Level4Pages;
+ UINT32 Level3Pages;
+ UINT32 Level2Pages;
+ UINT32 TotalPages;
UINT64 ApStacks;
UINT64 MemoryCap;
@@ -203,8 +206,7 @@ GetPeiMemoryCap (
//
// Dependent on physical address width, PEI memory allocations can be
// dominated by the page tables built for 64-bit DXE. So we key the cap off
- // of those. The code below is based on CreateIdentityMappingPageTables() in
- // "MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c".
+ // of those.
//
Page1GSupport = FALSE;
if (PcdGetBool (PcdUse1GPageTable)) {
@@ -217,25 +219,37 @@ GetPeiMemoryCap (
}
}
- if (PlatformInfoHob->PhysMemAddressWidth <= 39) {
- Pml4Entries = 1;
- PdpEntries = 1 << (PlatformInfoHob->PhysMemAddressWidth - 30);
- ASSERT (PdpEntries <= 0x200);
+ //
+ // - A 4KB page accommodates the least significant 12 bits of the
+ // virtual address.
+ // - A page table entry at any level consumes 8 bytes, so a 4KB page
+ // table page (at any level) contains 512 entries, and
+ // accommodates 9 bits of the virtual address.
+ // - we minimally cover the phys address space with 2MB pages, so
+ // level 1 never exists.
+ // - If 1G paging is available, then level 2 doesn't exist either.
+ // - Start with level 2, where a page table page accommodates
+ // 9 + 9 + 12 = 30 bits of the virtual address (and covers 1GB of
+ // physical address space).
+ //
+
+ MaxAddr = LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth);
+ Level2Pages = (UINT32)RShiftU64 (MaxAddr, 30);
+ Level3Pages = MAX (Level2Pages >> 9, 1u);
+ Level4Pages = MAX (Level3Pages >> 9, 1u);
+ Level5Pages = 1;
+
+ if (Page1GSupport) {
+ Level2Pages = 0;
+ TotalPages = Level5Pages + Level4Pages + Level3Pages;
+ ASSERT (TotalPages <= 0x40201);
} else {
- if (PlatformInfoHob->PhysMemAddressWidth > 48) {
- Pml4Entries = 0x200;
- } else {
- Pml4Entries = 1 << (PlatformInfoHob->PhysMemAddressWidth - 39);
- }
-
- ASSERT (Pml4Entries <= 0x200);
- PdpEntries = 512;
+ TotalPages = Level5Pages + Level4Pages + Level3Pages + Level2Pages;
+ // PlatformAddressWidthFromCpuid() caps at 40 phys bits without 1G pages.
+ ASSERT (PlatformInfoHob->PhysMemAddressWidth <= 40);
+ ASSERT (TotalPages <= 0x404);
}
- TotalPages = Page1GSupport ? Pml4Entries + 1 :
- (PdpEntries + 1) * Pml4Entries + 1;
- ASSERT (TotalPages <= 0x40201);
-
//
// With 32k stacks and 4096 vcpus this lands at 128 MB (far away
// from MAX_UINT32).
@@ -247,7 +261,7 @@ GetPeiMemoryCap (
// PhysMemAddressWidth values close to 36 and a small number of
// CPUs, the cap will actually be dominated by this increment.
//
- MemoryCap = EFI_PAGES_TO_SIZE (TotalPages) + ApStacks + SIZE_64MB;
+ MemoryCap = EFI_PAGES_TO_SIZE ((UINTN)TotalPages) + ApStacks + SIZE_64MB;
ASSERT (MemoryCap <= MAX_UINT32);
return (UINT32)MemoryCap;
--
2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115438): https://edk2.groups.io/g/devel/message/115438
Mute This Topic: https://groups.io/mt/104350491/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details
2024-02-14 10:45 [edk2-devel] [PATCH v3 0/4] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
` (2 preceding siblings ...)
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 3/4] OvmfPkg/PlatformPei: rewrite page table calculation Gerd Hoffmann
@ 2024-02-14 10:45 ` Gerd Hoffmann
2024-02-15 8:24 ` Laszlo Ersek
3 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2024-02-14 10:45 UTC (permalink / raw)
To: devel
Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao, Laszlo Ersek,
Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/PlatformPei/MemDetect.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 81c29c626bb3..04409b28bacf 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -263,6 +263,30 @@ GetPeiMemoryCap (
//
MemoryCap = EFI_PAGES_TO_SIZE ((UINTN)TotalPages) + ApStacks + SIZE_64MB;
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: page tables: %6lu KB (%u/%u/%u/%u pages for levels 5/4/3/2)\n",
+ __func__,
+ RShiftU64 (EFI_PAGES_TO_SIZE ((UINTN)TotalPages), 10),
+ Level5Pages,
+ Level4Pages,
+ Level3Pages,
+ Level2Pages
+ ));
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: ap stacks: %6lu KB (%u cpus)\n",
+ __func__,
+ RShiftU64 (ApStacks, 10),
+ PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber
+ ));
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: memory cap: %6lu KB\n",
+ __func__,
+ RShiftU64 (MemoryCap, 10)
+ ));
+
ASSERT (MemoryCap <= MAX_UINT32);
return (UINT32)MemoryCap;
}
--
2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115441): https://edk2.groups.io/g/devel/message/115441
Mute This Topic: https://groups.io/mt/104350494/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details
2024-02-14 10:45 ` [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
@ 2024-02-15 8:24 ` Laszlo Ersek
2024-02-27 8:44 ` Gerd Hoffmann
0 siblings, 1 reply; 8+ messages in thread
From: Laszlo Ersek @ 2024-02-15 8:24 UTC (permalink / raw)
To: devel, kraxel; +Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao
On 2/14/24 11:45, Gerd Hoffmann wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> OvmfPkg/PlatformPei/MemDetect.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
> index 81c29c626bb3..04409b28bacf 100644
> --- a/OvmfPkg/PlatformPei/MemDetect.c
> +++ b/OvmfPkg/PlatformPei/MemDetect.c
> @@ -263,6 +263,30 @@ GetPeiMemoryCap (
> //
> MemoryCap = EFI_PAGES_TO_SIZE ((UINTN)TotalPages) + ApStacks + SIZE_64MB;
>
> + DEBUG ((
> + DEBUG_INFO,
> + "%a: page tables: %6lu KB (%u/%u/%u/%u pages for levels 5/4/3/2)\n",
> + __func__,
> + RShiftU64 (EFI_PAGES_TO_SIZE ((UINTN)TotalPages), 10),
> + Level5Pages,
> + Level4Pages,
> + Level3Pages,
> + Level2Pages
> + ));
> + DEBUG ((
> + DEBUG_INFO,
> + "%a: ap stacks: %6lu KB (%u cpus)\n",
> + __func__,
> + RShiftU64 (ApStacks, 10),
> + PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber
> + ));
> + DEBUG ((
> + DEBUG_INFO,
> + "%a: memory cap: %6lu KB\n",
> + __func__,
> + RShiftU64 (MemoryCap, 10)
> + ));
> +
> ASSERT (MemoryCap <= MAX_UINT32);
> return (UINT32)MemoryCap;
> }
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This series is now ready for merging, as far as I'm concerned (thanks
for the updates in the other patches too, I've re-checked them). Please
send a reminder after the stable tag.
Thanks!
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115492): https://edk2.groups.io/g/devel/message/115492
Mute This Topic: https://groups.io/mt/104350494/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details
2024-02-15 8:24 ` Laszlo Ersek
@ 2024-02-27 8:44 ` Gerd Hoffmann
2024-02-27 13:33 ` Laszlo Ersek
0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2024-02-27 8:44 UTC (permalink / raw)
To: Laszlo Ersek; +Cc: devel, Oliver Steffen, Ard Biesheuvel, Jiewen Yao
On Thu, Feb 15, 2024 at 09:24:41AM +0100, Laszlo Ersek wrote:
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> This series is now ready for merging, as far as I'm concerned (thanks
> for the updates in the other patches too, I've re-checked them). Please
> send a reminder after the stable tag.
Friendly post-freeze ping ;)
thanks & take care,
Gerd
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116011): https://edk2.groups.io/g/devel/message/116011
Mute This Topic: https://groups.io/mt/104350494/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH v3 4/4] OvmfPkg/PlatformPei: log pei memory cap details
2024-02-27 8:44 ` Gerd Hoffmann
@ 2024-02-27 13:33 ` Laszlo Ersek
0 siblings, 0 replies; 8+ messages in thread
From: Laszlo Ersek @ 2024-02-27 13:33 UTC (permalink / raw)
To: devel, kraxel; +Cc: Oliver Steffen, Ard Biesheuvel, Jiewen Yao
On 2/27/24 09:44, Gerd Hoffmann wrote:
> On Thu, Feb 15, 2024 at 09:24:41AM +0100, Laszlo Ersek wrote:
>>
>> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> This series is now ready for merging, as far as I'm concerned (thanks
>> for the updates in the other patches too, I've re-checked them). Please
>> send a reminder after the stable tag.
>
> Friendly post-freeze ping ;)
Thanks!
Merged as commit range ba9c3ceaf83d..aceb3490a2a3, via
<https://github.com/tianocore/edk2/pull/5418>.
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116043): https://edk2.groups.io/g/devel/message/116043
Mute This Topic: https://groups.io/mt/104350494/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 8+ messages in thread