* Mon Apr 08 2024 Miroslav Rezanina <mrezanin@redhat.com> - 20240214-2
- edk2-OvmfPkg-PlatformPei-log-a-warning-when-memory-is-tig.patch [RHEL-22202] - edk2-OvmfPkg-PlatformPei-consider-AP-stacks-for-pei-memor.patch [RHEL-22202] - edk2-OvmfPkg-PlatformPei-rewrite-page-table-calculation.patch [RHEL-22202] - edk2-OvmfPkg-PlatformPei-log-pei-memory-cap-details.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p2.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p3.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p4.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p5.patch [RHEL-22202] - edk2-UefiCpuPkg-MpInitLib-return-early-in-GetBspNumber.patch [RHEL-22202] - Resolves: RHEL-22202 ([EDK2] Support booting with 4096 vcpus)
This commit is contained in:
		
							parent
							
								
									9c8fc7cb9a
								
							
						
					
					
						commit
						ee6707224d
					
				| @ -0,0 +1,64 @@ | ||||
| From 9ecb56fbd704c4471b3485c08c1cbabeef5ee137 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Wed, 14 Feb 2024 11:45:02 +0100 | ||||
| Subject: [PATCH 02/10] OvmfPkg/PlatformPei: consider AP stacks for pei memory | ||||
|  cap | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [2/10] e2c5325678de49e455de33581735d0275fb6b3b7 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| 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> | ||||
| Message-Id: <20240214104504.2931339-3-kraxel@redhat.com> | ||||
| (cherry picked from commit 8757e648d11357b663331f6ed1cdb2ab017df178) | ||||
| ---
 | ||||
|  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 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;
 | ||||
|  } | ||||
|   | ||||
|  /** | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
| @ -0,0 +1,41 @@ | ||||
| From 6bafe5fb1b432b88396913c7feda272970e67002 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Wed, 14 Feb 2024 11:45:01 +0100 | ||||
| Subject: [PATCH 01/10] OvmfPkg/PlatformPei: log a warning when memory is tight | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [1/10] 2ade669e2b69eaed11d054f181808d6c3158f8f3 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| Message-Id: <20240214104504.2931339-2-kraxel@redhat.com> | ||||
| (cherry picked from commit 9d32a02a724c79215a00bb2d2563c7fd026b0726) | ||||
| ---
 | ||||
|  OvmfPkg/PlatformPei/MemDetect.c | 8 ++++++++ | ||||
|  1 file changed, 8 insertions(+) | ||||
| 
 | ||||
| diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
 | ||||
| index 493cb1fbeb..e0ecca10b6 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.39.3 | ||||
| 
 | ||||
							
								
								
									
										57
									
								
								edk2-OvmfPkg-PlatformPei-log-pei-memory-cap-details.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								edk2-OvmfPkg-PlatformPei-log-pei-memory-cap-details.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,57 @@ | ||||
| From d80ea2ea86698de8e38629352a765c60c391a5d3 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Wed, 14 Feb 2024 11:45:04 +0100 | ||||
| Subject: [PATCH 04/10] OvmfPkg/PlatformPei: log pei memory cap details | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [4/10] 640b85027aaf2df96c892bef5d15d87b09a7554a (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Message-Id: <20240214104504.2931339-5-kraxel@redhat.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| (cherry picked from commit aceb3490a2a350b128156fd4e36e53fc19739e4e) | ||||
| ---
 | ||||
|  OvmfPkg/PlatformPei/MemDetect.c | 24 ++++++++++++++++++++++++ | ||||
|  1 file changed, 24 insertions(+) | ||||
| 
 | ||||
| diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
 | ||||
| index 81c29c626b..04409b28ba 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.39.3 | ||||
| 
 | ||||
							
								
								
									
										117
									
								
								edk2-OvmfPkg-PlatformPei-rewrite-page-table-calculation.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								edk2-OvmfPkg-PlatformPei-rewrite-page-table-calculation.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,117 @@ | ||||
| From 4f7561085f7333777392543915b6da801c624aab Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Wed, 14 Feb 2024 11:45:03 +0100 | ||||
| Subject: [PATCH 03/10] OvmfPkg/PlatformPei: rewrite page table calculation | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [3/10] faaac541239856514781c0e9eec38edc25a6c1f8 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| 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> | ||||
| Message-Id: <20240214104504.2931339-4-kraxel@redhat.com> | ||||
| (cherry picked from commit 3ad1d7eb7bcb12d7b4967a27c6dec80395517797) | ||||
| ---
 | ||||
|  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 d6c46ffc89..81c29c626b 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,24 +219,36 @@ GetPeiMemoryCap (
 | ||||
|      } | ||||
|    } | ||||
|   | ||||
| -  if (PlatformInfoHob->PhysMemAddressWidth <= 39) {
 | ||||
| -    Pml4Entries = 1;
 | ||||
| -    PdpEntries  = 1 << (PlatformInfoHob->PhysMemAddressWidth - 30);
 | ||||
| -    ASSERT (PdpEntries <= 0x200);
 | ||||
| -  } else {
 | ||||
| -    if (PlatformInfoHob->PhysMemAddressWidth > 48) {
 | ||||
| -      Pml4Entries = 0x200;
 | ||||
| -    } else {
 | ||||
| -      Pml4Entries = 1 << (PlatformInfoHob->PhysMemAddressWidth - 39);
 | ||||
| -    }
 | ||||
| +  //
 | ||||
| +  // - 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).
 | ||||
| +  //
 | ||||
|   | ||||
| -    ASSERT (Pml4Entries <= 0x200);
 | ||||
| -    PdpEntries = 512;
 | ||||
| -  }
 | ||||
| +  MaxAddr     = LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth);
 | ||||
| +  Level2Pages = (UINT32)RShiftU64 (MaxAddr, 30);
 | ||||
| +  Level3Pages = MAX (Level2Pages >> 9, 1u);
 | ||||
| +  Level4Pages = MAX (Level3Pages >> 9, 1u);
 | ||||
| +  Level5Pages = 1;
 | ||||
|   | ||||
| -  TotalPages = Page1GSupport ? Pml4Entries + 1 :
 | ||||
| -               (PdpEntries + 1) * Pml4Entries + 1;
 | ||||
| -  ASSERT (TotalPages <= 0x40201);
 | ||||
| +  if (Page1GSupport) {
 | ||||
| +    Level2Pages = 0;
 | ||||
| +    TotalPages  = Level5Pages + Level4Pages + Level3Pages;
 | ||||
| +    ASSERT (TotalPages <= 0x40201);
 | ||||
| +  } else {
 | ||||
| +    TotalPages = Level5Pages + Level4Pages + Level3Pages + Level2Pages;
 | ||||
| +    // PlatformAddressWidthFromCpuid() caps at 40 phys bits without 1G pages.
 | ||||
| +    ASSERT (PlatformInfoHob->PhysMemAddressWidth <= 40);
 | ||||
| +    ASSERT (TotalPages <= 0x404);
 | ||||
| +  }
 | ||||
|   | ||||
|    // | ||||
|    // With 32k stacks and 4096 vcpus this lands at 128 MB (far away | ||||
| @@ -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.39.3 | ||||
| 
 | ||||
| @ -0,0 +1,73 @@ | ||||
| From 4c9151fa8f06c42f04459f79ae45bf9c01bba08a Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:02 +0100 | ||||
| Subject: [PATCH 06/10] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to | ||||
|  GetBspNumber() | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [6/10] 41754f3533416e10c3057b3b31ac2829002d115c (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Rename the MpHandOff parameter to FirstMpHandOff.  Add a loop so the | ||||
| function inspects all HOBs present in the system. | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| Message-Id: <20240222160106.686484-3-kraxel@redhat.com> | ||||
| (cherry picked from commit b48523046283e8ef670b5d2b9f53de6855f7d3bf) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 +++++++++++++++-------- | ||||
|  1 file changed, 15 insertions(+), 8 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| index 00b36b0e18..770874b09d 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| @@ -1900,26 +1900,33 @@ CheckAllAPs (
 | ||||
|  /** | ||||
|    This function Get BspNumber. | ||||
|   | ||||
| -  @param[in] MpHandOff        Pointer to MpHandOff
 | ||||
| +  @param[in] FirstMpHandOff   Pointer to first MpHandOff HOB body.
 | ||||
|    @return                     BspNumber | ||||
|  **/ | ||||
|  UINT32 | ||||
|  GetBspNumber ( | ||||
| -  IN CONST MP_HAND_OFF  *MpHandOff
 | ||||
| +  IN CONST MP_HAND_OFF  *FirstMpHandOff
 | ||||
|    ) | ||||
|  { | ||||
| -  UINT32  ApicId;
 | ||||
| -  UINT32  BspNumber;
 | ||||
| -  UINT32  Index;
 | ||||
| +  UINT32             ApicId;
 | ||||
| +  UINT32             BspNumber;
 | ||||
| +  UINT32             Index;
 | ||||
| +  CONST MP_HAND_OFF  *MpHandOff;
 | ||||
|   | ||||
|    // | ||||
|    // Get the processor number for the BSP | ||||
|    // | ||||
|    BspNumber = MAX_UINT32; | ||||
|    ApicId    = GetInitialApicId (); | ||||
| -  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| -    if (MpHandOff->Info[Index].ApicId == ApicId) {
 | ||||
| -      BspNumber = Index;
 | ||||
| +
 | ||||
| +  for (MpHandOff = FirstMpHandOff;
 | ||||
| +       MpHandOff != NULL;
 | ||||
| +       MpHandOff = GetNextMpHandOffHob (MpHandOff))
 | ||||
| +  {
 | ||||
| +    for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| +      if (MpHandOff->Info[Index].ApicId == ApicId) {
 | ||||
| +        BspNumber = MpHandOff->ProcessorIndex + Index;
 | ||||
| +      }
 | ||||
|      } | ||||
|    } | ||||
|   | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
| @ -0,0 +1,100 @@ | ||||
| From 9b609dba20e4ff82b83e73b9a61a36710a8014b8 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:03 +0100 | ||||
| Subject: [PATCH 07/10] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to | ||||
|  SwitchApContext() | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [7/10] faa8253e80a08b71e0adc0fed6a5d17fada30402 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Rename the MpHandOff parameter to FirstMpHandOff.  Add loops so the | ||||
| function inspects all HOBs present in the system. | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| Message-Id: <20240222160106.686484-4-kraxel@redhat.com> | ||||
| (cherry picked from commit e2c9d8eba49754b644ed4599331395d777afc379) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++++++++++++++++++---------- | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.h |  2 +- | ||||
|  2 files changed, 24 insertions(+), 13 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| index 770874b09d..1494355f49 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| @@ -1944,31 +1944,42 @@ GetBspNumber (
 | ||||
|    This procedure allows the AP to switch to another section of | ||||
|    memory and continue its loop there. | ||||
|   | ||||
| -  @param[in] MpHandOff  Pointer to MP hand-off data structure.
 | ||||
| +  @param[in] FirstMpHandOff  Pointer to first MP hand-off HOB body.
 | ||||
|  **/ | ||||
|  VOID | ||||
|  SwitchApContext ( | ||||
| -  IN MP_HAND_OFF  *MpHandOff
 | ||||
| +  IN CONST MP_HAND_OFF  *FirstMpHandOff
 | ||||
|    ) | ||||
|  { | ||||
| -  UINTN   Index;
 | ||||
| -  UINT32  BspNumber;
 | ||||
| +  UINTN              Index;
 | ||||
| +  UINT32             BspNumber;
 | ||||
| +  CONST MP_HAND_OFF  *MpHandOff;
 | ||||
|   | ||||
| -  BspNumber = GetBspNumber (MpHandOff);
 | ||||
| +  BspNumber = GetBspNumber (FirstMpHandOff);
 | ||||
|   | ||||
| -  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| -    if (Index != BspNumber) {
 | ||||
| -      *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = (UINTN)SwitchContextPerAp;
 | ||||
| -      *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress   = MpHandOff->StartupSignalValue;
 | ||||
| +  for (MpHandOff = FirstMpHandOff;
 | ||||
| +       MpHandOff != NULL;
 | ||||
| +       MpHandOff = GetNextMpHandOffHob (MpHandOff))
 | ||||
| +  {
 | ||||
| +    for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| +      if (MpHandOff->ProcessorIndex + Index != BspNumber) {
 | ||||
| +        *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = (UINTN)SwitchContextPerAp;
 | ||||
| +        *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress   = MpHandOff->StartupSignalValue;
 | ||||
| +      }
 | ||||
|      } | ||||
|    } | ||||
|   | ||||
|    // | ||||
|    // Wait all APs waken up if this is not the 1st broadcast of SIPI | ||||
|    // | ||||
| -  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| -    if (Index != BspNumber) {
 | ||||
| -      WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSignalAddress));
 | ||||
| +  for (MpHandOff = FirstMpHandOff;
 | ||||
| +       MpHandOff != NULL;
 | ||||
| +       MpHandOff = GetNextMpHandOffHob (MpHandOff))
 | ||||
| +  {
 | ||||
| +    for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| +      if (MpHandOff->ProcessorIndex + Index != BspNumber) {
 | ||||
| +        WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSignalAddress));
 | ||||
| +      }
 | ||||
|      } | ||||
|    } | ||||
|  } | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| index fab2b2d493..3a7b9896cf 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| @@ -482,7 +482,7 @@ GetWakeupBuffer (
 | ||||
|  **/ | ||||
|  VOID | ||||
|  SwitchApContext ( | ||||
| -  IN MP_HAND_OFF  *MpHandOff
 | ||||
| +  IN CONST MP_HAND_OFF  *FirstMpHandOff
 | ||||
|    ); | ||||
|   | ||||
|  /** | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
| @ -0,0 +1,162 @@ | ||||
| From 3ec2efae40a9a7c552c60e6c60b05b74ce5a6fbb Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:04 +0100 | ||||
| Subject: [PATCH 08/10] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to | ||||
|  MpInitLibInitialize | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [8/10] 9ae7e900f38bfa95694841b68520560e02b0f927 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Loop over all MP_HAND_OFF HOBs instead of expecting a single HOB | ||||
| covering all CPUs in the system. | ||||
| 
 | ||||
| Add a new FirstMpHandOff variable, which caches the first HOB body for | ||||
| faster lookups.  It is also used to check whenever MP_HAND_OFF HOBs are | ||||
| present.  Using the MpHandOff pointer for that does not work any more | ||||
| because the variable will be NULL at the end of HOB loops. | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Message-Id: <20240222160106.686484-5-kraxel@redhat.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| (cherry picked from commit c8e77454b5ffccfc39f48d5a792bc0aac311b634) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.c | 68 +++++++++++++++++++--------- | ||||
|  1 file changed, 47 insertions(+), 21 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| index 1494355f49..a50981c9d1 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| @@ -2031,6 +2031,7 @@ MpInitLibInitialize (
 | ||||
|    VOID | ||||
|    ) | ||||
|  { | ||||
| +  MP_HAND_OFF              *FirstMpHandOff;
 | ||||
|    MP_HAND_OFF              *MpHandOff; | ||||
|    CPU_INFO_IN_HOB          *CpuInfoInHob; | ||||
|    UINT32                   MaxLogicalProcessorNumber; | ||||
| @@ -2044,17 +2045,31 @@ MpInitLibInitialize (
 | ||||
|    CPU_MP_DATA              *CpuMpData; | ||||
|    UINT8                    ApLoopMode; | ||||
|    UINT8                    *MonitorBuffer; | ||||
| -  UINTN                    Index;
 | ||||
| +  UINT32                   Index, HobIndex;
 | ||||
|    UINTN                    ApResetVectorSizeBelow1Mb; | ||||
|    UINTN                    ApResetVectorSizeAbove1Mb; | ||||
|    UINTN                    BackupBufferAddr; | ||||
|    UINTN                    ApIdtBase; | ||||
|   | ||||
| -  MpHandOff = GetNextMpHandOffHob (NULL);
 | ||||
| -  if (MpHandOff == NULL) {
 | ||||
| -    MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
 | ||||
| +  FirstMpHandOff = GetNextMpHandOffHob (NULL);
 | ||||
| +  if (FirstMpHandOff != NULL) {
 | ||||
| +    MaxLogicalProcessorNumber = 0;
 | ||||
| +    for (MpHandOff = FirstMpHandOff;
 | ||||
| +         MpHandOff != NULL;
 | ||||
| +         MpHandOff = GetNextMpHandOffHob (MpHandOff))
 | ||||
| +    {
 | ||||
| +      DEBUG ((
 | ||||
| +        DEBUG_INFO,
 | ||||
| +        "%a: ProcessorIndex=%u CpuCount=%u\n",
 | ||||
| +        __func__,
 | ||||
| +        MpHandOff->ProcessorIndex,
 | ||||
| +        MpHandOff->CpuCount
 | ||||
| +        ));
 | ||||
| +      ASSERT (MaxLogicalProcessorNumber == MpHandOff->ProcessorIndex);
 | ||||
| +      MaxLogicalProcessorNumber += MpHandOff->CpuCount;
 | ||||
| +    }
 | ||||
|    } else { | ||||
| -    MaxLogicalProcessorNumber = MpHandOff->CpuCount;
 | ||||
| +    MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
 | ||||
|    } | ||||
|   | ||||
|    ASSERT (MaxLogicalProcessorNumber != 0); | ||||
| @@ -2198,7 +2213,7 @@ MpInitLibInitialize (
 | ||||
|    // | ||||
|    ProgramVirtualWireMode (); | ||||
|   | ||||
| -  if (MpHandOff == NULL) {
 | ||||
| +  if (FirstMpHandOff == NULL) {
 | ||||
|      if (MaxLogicalProcessorNumber > 1) { | ||||
|        // | ||||
|        // Wakeup all APs and calculate the processor count in system | ||||
| @@ -2214,21 +2229,32 @@ MpInitLibInitialize (
 | ||||
|        AmdSevUpdateCpuMpData (CpuMpData); | ||||
|      } | ||||
|   | ||||
| -    CpuMpData->CpuCount  = MpHandOff->CpuCount;
 | ||||
| -    CpuMpData->BspNumber = GetBspNumber (MpHandOff);
 | ||||
| +    CpuMpData->CpuCount  = MaxLogicalProcessorNumber;
 | ||||
| +    CpuMpData->BspNumber = GetBspNumber (FirstMpHandOff);
 | ||||
|      CpuInfoInHob         = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; | ||||
| -    for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
 | ||||
| -      InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock);
 | ||||
| -      CpuMpData->CpuData[Index].CpuHealthy = (MpHandOff->Info[Index].Health == 0) ? TRUE : FALSE;
 | ||||
| -      CpuMpData->CpuData[Index].ApFunction = 0;
 | ||||
| -      CpuInfoInHob[Index].InitialApicId    = MpHandOff->Info[Index].ApicId;
 | ||||
| -      CpuInfoInHob[Index].ApTopOfStack     = CpuMpData->Buffer + (Index + 1) * CpuMpData->CpuApStackSize;
 | ||||
| -      CpuInfoInHob[Index].ApicId           = MpHandOff->Info[Index].ApicId;
 | ||||
| -      CpuInfoInHob[Index].Health           = MpHandOff->Info[Index].Health;
 | ||||
| +    for (MpHandOff = FirstMpHandOff;
 | ||||
| +         MpHandOff != NULL;
 | ||||
| +         MpHandOff = GetNextMpHandOffHob (MpHandOff))
 | ||||
| +    {
 | ||||
| +      for (HobIndex = 0; HobIndex < MpHandOff->CpuCount; HobIndex++) {
 | ||||
| +        Index = MpHandOff->ProcessorIndex + HobIndex;
 | ||||
| +        InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock);
 | ||||
| +        CpuMpData->CpuData[Index].CpuHealthy = (MpHandOff->Info[HobIndex].Health == 0) ? TRUE : FALSE;
 | ||||
| +        CpuMpData->CpuData[Index].ApFunction = 0;
 | ||||
| +        CpuInfoInHob[Index].InitialApicId    = MpHandOff->Info[HobIndex].ApicId;
 | ||||
| +        CpuInfoInHob[Index].ApTopOfStack     = CpuMpData->Buffer + (Index + 1) * CpuMpData->CpuApStackSize;
 | ||||
| +        CpuInfoInHob[Index].ApicId           = MpHandOff->Info[HobIndex].ApicId;
 | ||||
| +        CpuInfoInHob[Index].Health           = MpHandOff->Info[HobIndex].Health;
 | ||||
| +      }
 | ||||
|      } | ||||
|   | ||||
| -    DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof (VOID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *)));
 | ||||
| -    if (MpHandOff->WaitLoopExecutionMode == sizeof (VOID *)) {
 | ||||
| +    DEBUG ((
 | ||||
| +      DEBUG_INFO,
 | ||||
| +      "FirstMpHandOff->WaitLoopExecutionMode: %04d, sizeof (VOID *): %04d\n",
 | ||||
| +      FirstMpHandOff->WaitLoopExecutionMode,
 | ||||
| +      sizeof (VOID *)
 | ||||
| +      ));
 | ||||
| +    if (FirstMpHandOff->WaitLoopExecutionMode == sizeof (VOID *)) {
 | ||||
|        ASSERT (CpuMpData->ApLoopMode != ApInHltLoop); | ||||
|   | ||||
|        CpuMpData->FinishedCount                        = 0; | ||||
| @@ -2244,7 +2270,7 @@ MpInitLibInitialize (
 | ||||
|        // enables the APs to switch to a different memory section and continue their | ||||
|        // looping process there. | ||||
|        // | ||||
| -      SwitchApContext (MpHandOff);
 | ||||
| +      SwitchApContext (FirstMpHandOff);
 | ||||
|        // | ||||
|        // Wait for all APs finished initialization | ||||
|        // | ||||
| @@ -2293,7 +2319,7 @@ MpInitLibInitialize (
 | ||||
|    // Wakeup APs to do some AP initialize sync (Microcode & MTRR) | ||||
|    // | ||||
|    if (CpuMpData->CpuCount > 1) { | ||||
| -    if (MpHandOff != NULL) {
 | ||||
| +    if (FirstMpHandOff != NULL) {
 | ||||
|        // | ||||
|        // Only needs to use this flag for DXE phase to update the wake up | ||||
|        // buffer. Wakeup buffer allocated in PEI phase is no longer valid | ||||
| @@ -2310,7 +2336,7 @@ MpInitLibInitialize (
 | ||||
|        CpuPause (); | ||||
|      } | ||||
|   | ||||
| -    if (MpHandOff != NULL) {
 | ||||
| +    if (FirstMpHandOff != NULL) {
 | ||||
|        CpuMpData->InitFlag = ApInitDone; | ||||
|      } | ||||
|   | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
| @ -0,0 +1,98 @@ | ||||
| From 529cf9e805df50d45cd56dfb96b373057f9b0557 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:05 +0100 | ||||
| Subject: [PATCH 09/10] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to | ||||
|  SaveCpuMpData() | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [9/10] 764ed13aaaa7e01c056773e9fe82555eb9476a16 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Add support for splitting Hand-Off data into multiple HOBs. | ||||
| This is required for VMs with thousands of CPUs. | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Message-Id: <20240222160106.686484-6-kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| [lersek@redhat.com: define one local variable per line [Ray]] | ||||
| (cherry picked from commit 5e09b5d6d7eda2c88d12ee27db18b3c75ed24dd3) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 48 +++++++++++++++---------- | ||||
|  1 file changed, 30 insertions(+), 18 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
 | ||||
| index f80e00edcf..ec1aa66692 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
 | ||||
| @@ -126,35 +126,47 @@ SaveCpuMpData (
 | ||||
|    IN CPU_MP_DATA  *CpuMpData | ||||
|    ) | ||||
|  { | ||||
| +  UINT32           MaxCpusPerHob;
 | ||||
| +  UINT32           CpusInHob;
 | ||||
|    UINT64           Data64; | ||||
| -  UINTN            Index;
 | ||||
| +  UINT32           Index;
 | ||||
| +  UINT32           HobBase;
 | ||||
|    CPU_INFO_IN_HOB  *CpuInfoInHob; | ||||
|    MP_HAND_OFF      *MpHandOff; | ||||
|    UINTN            MpHandOffSize; | ||||
|   | ||||
| +  MaxCpusPerHob = (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF);
 | ||||
| +
 | ||||
|    // | ||||
|    // When APs are in a state that can be waken up by a store operation to a memory address, | ||||
|    // report the MP_HAND_OFF data for DXE to use. | ||||
|    // | ||||
| -  CpuInfoInHob  = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
 | ||||
| -  MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * CpuMpData->CpuCount;
 | ||||
| -  MpHandOff     = (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, MpHandOffSize);
 | ||||
| -  ASSERT (MpHandOff != NULL);
 | ||||
| -  ZeroMem (MpHandOff, MpHandOffSize);
 | ||||
| -  MpHandOff->ProcessorIndex = 0;
 | ||||
| -
 | ||||
| -  MpHandOff->CpuCount = CpuMpData->CpuCount;
 | ||||
| -  if (CpuMpData->ApLoopMode != ApInHltLoop) {
 | ||||
| -    MpHandOff->StartupSignalValue    = MP_HAND_OFF_SIGNAL;
 | ||||
| -    MpHandOff->WaitLoopExecutionMode = sizeof (VOID *);
 | ||||
| -  }
 | ||||
| +  CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
 | ||||
| +
 | ||||
| +  for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
 | ||||
| +    if (Index % MaxCpusPerHob == 0) {
 | ||||
| +      HobBase   = Index;
 | ||||
| +      CpusInHob = MIN (CpuMpData->CpuCount - HobBase, MaxCpusPerHob);
 | ||||
| +
 | ||||
| +      MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * CpusInHob;
 | ||||
| +      MpHandOff     = (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, MpHandOffSize);
 | ||||
| +      ASSERT (MpHandOff != NULL);
 | ||||
| +      ZeroMem (MpHandOff, MpHandOffSize);
 | ||||
| +
 | ||||
| +      MpHandOff->ProcessorIndex = HobBase;
 | ||||
| +      MpHandOff->CpuCount       = CpusInHob;
 | ||||
| +
 | ||||
| +      if (CpuMpData->ApLoopMode != ApInHltLoop) {
 | ||||
| +        MpHandOff->StartupSignalValue    = MP_HAND_OFF_SIGNAL;
 | ||||
| +        MpHandOff->WaitLoopExecutionMode = sizeof (VOID *);
 | ||||
| +      }
 | ||||
| +    }
 | ||||
|   | ||||
| -  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
 | ||||
| -    MpHandOff->Info[Index].ApicId = CpuInfoInHob[Index].ApicId;
 | ||||
| -    MpHandOff->Info[Index].Health = CpuInfoInHob[Index].Health;
 | ||||
| +    MpHandOff->Info[Index-HobBase].ApicId = CpuInfoInHob[Index].ApicId;
 | ||||
| +    MpHandOff->Info[Index-HobBase].Health = CpuInfoInHob[Index].Health;
 | ||||
|      if (CpuMpData->ApLoopMode != ApInHltLoop) { | ||||
| -      MpHandOff->Info[Index].StartupSignalAddress    = (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal;
 | ||||
| -      MpHandOff->Info[Index].StartupProcedureAddress = (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction;
 | ||||
| +      MpHandOff->Info[Index-HobBase].StartupSignalAddress    = (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal;
 | ||||
| +      MpHandOff->Info[Index-HobBase].StartupProcedureAddress = (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction;
 | ||||
|      } | ||||
|    } | ||||
|   | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
							
								
								
									
										108
									
								
								edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,108 @@ | ||||
| From 78881a773805298141feaeaf5670ebce616a8338 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:01 +0100 | ||||
| Subject: [PATCH 05/10] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to | ||||
|  GetMpHandOffHob | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [5/10] d738dc794cf7f5b8440bb9c23f21a11eb220add3 (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| Rename the function to GetNextMpHandOffHob(), add MP_HAND_OFF parameter. | ||||
| When called with NULL pointer return the body of the first HOB, otherwise | ||||
| return the next in the chain. | ||||
| 
 | ||||
| Also add the function prototype to the MpLib.h header file. | ||||
| 
 | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Message-Id: <20240222160106.686484-2-kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| (cherry picked from commit a3ee1eea96752cf2d4e0f70310facc109b7c4352) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.c | 26 ++++++++++++++++---------- | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.h | 12 ++++++++++++ | ||||
|  2 files changed, 28 insertions(+), 10 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| index 7bc93dfa13..00b36b0e18 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| @@ -1967,25 +1967,31 @@ SwitchApContext (
 | ||||
|  } | ||||
|   | ||||
|  /** | ||||
| -  Get pointer to MP_HAND_OFF GUIDed HOB.
 | ||||
| +  Get pointer to next MP_HAND_OFF GUIDed HOB body.
 | ||||
| +
 | ||||
| +  @param[in] MpHandOff  Previous HOB body.  Pass NULL to get the first HOB.
 | ||||
|   | ||||
|    @return  The pointer to MP_HAND_OFF structure. | ||||
|  **/ | ||||
|  MP_HAND_OFF * | ||||
| -GetMpHandOffHob (
 | ||||
| -  VOID
 | ||||
| +GetNextMpHandOffHob (
 | ||||
| +  IN CONST MP_HAND_OFF  *MpHandOff
 | ||||
|    ) | ||||
|  { | ||||
|    EFI_HOB_GUID_TYPE  *GuidHob; | ||||
| -  MP_HAND_OFF        *MpHandOff;
 | ||||
|   | ||||
| -  MpHandOff = NULL;
 | ||||
| -  GuidHob   = GetFirstGuidHob (&mMpHandOffGuid);
 | ||||
| -  if (GuidHob != NULL) {
 | ||||
| -    MpHandOff = (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob);
 | ||||
| +  if (MpHandOff == NULL) {
 | ||||
| +    GuidHob = GetFirstGuidHob (&mMpHandOffGuid);
 | ||||
| +  } else {
 | ||||
| +    GuidHob = (VOID *)(((UINT8 *)MpHandOff) - sizeof (EFI_HOB_GUID_TYPE));
 | ||||
| +    GuidHob = GetNextGuidHob (&mMpHandOffGuid, GET_NEXT_HOB (GuidHob));
 | ||||
| +  }
 | ||||
| +
 | ||||
| +  if (GuidHob == NULL) {
 | ||||
| +    return NULL;
 | ||||
|    } | ||||
|   | ||||
| -  return MpHandOff;
 | ||||
| +  return (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob);
 | ||||
|  } | ||||
|   | ||||
|  /** | ||||
| @@ -2026,7 +2032,7 @@ MpInitLibInitialize (
 | ||||
|    UINTN                    BackupBufferAddr; | ||||
|    UINTN                    ApIdtBase; | ||||
|   | ||||
| -  MpHandOff = GetMpHandOffHob ();
 | ||||
| +  MpHandOff = GetNextMpHandOffHob (NULL);
 | ||||
|    if (MpHandOff == NULL) { | ||||
|      MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); | ||||
|    } else { | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| index a96a6389c1..fab2b2d493 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
 | ||||
| @@ -485,6 +485,18 @@ SwitchApContext (
 | ||||
|    IN MP_HAND_OFF  *MpHandOff | ||||
|    ); | ||||
|   | ||||
| +/**
 | ||||
| +  Get pointer to next MP_HAND_OFF GUIDed HOB body.
 | ||||
| +
 | ||||
| +  @param[in] MpHandOff  Previous HOB body.  Pass NULL to get the first HOB.
 | ||||
| +
 | ||||
| +  @return  The pointer to MP_HAND_OFF structure.
 | ||||
| +**/
 | ||||
| +MP_HAND_OFF *
 | ||||
| +GetNextMpHandOffHob (
 | ||||
| +  IN CONST MP_HAND_OFF  *MpHandOff
 | ||||
| +  );
 | ||||
| +
 | ||||
|  /** | ||||
|    Get available EfiBootServicesCode memory below 4GB by specified size. | ||||
|   | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
							
								
								
									
										67
									
								
								edk2-UefiCpuPkg-MpInitLib-return-early-in-GetBspNumber.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								edk2-UefiCpuPkg-MpInitLib-return-early-in-GetBspNumber.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,67 @@ | ||||
| From 364b11a2cc6c37ce66af2bbeb70591f98d8b14d2 Mon Sep 17 00:00:00 2001 | ||||
| From: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Date: Thu, 22 Feb 2024 17:01:06 +0100 | ||||
| Subject: [PATCH 10/10] UefiCpuPkg/MpInitLib: return early in GetBspNumber() | ||||
| 
 | ||||
| RH-Author: Gerd Hoffmann <None> | ||||
| RH-MergeRequest: 59: backport 4096 vcpu patches for c9s | ||||
| RH-Jira: RHEL-22202 | ||||
| RH-Acked-by: Oliver Steffen <osteffen@redhat.com> | ||||
| RH-Commit: [10/10] 0695e52ad712025a0cfb097926dcf14a498664ae (kraxel.rh/centos-src-edk2) | ||||
| 
 | ||||
| After finding the BSP Number return the result instead of | ||||
| continuing to loop over the remaining processors. | ||||
| 
 | ||||
| Suggested-by: Laszlo Ersek <lersek@redhat.com> | ||||
| Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> | ||||
| Message-Id: <20240222160106.686484-7-kraxel@redhat.com> | ||||
| Reviewed-by: Ray Ni <ray.ni@intel.com> | ||||
| Reviewed-by: Laszlo Ersek <lersek@redhat.com> | ||||
| [lersek@redhat.com: s/ASSERT (FALSE)/ASSERT_EFI_ERROR (EFI_NOT_FOUND)/ [Ray]] | ||||
| (cherry picked from commit d25421d0d8cd2493b30215ef80d2424ecb19c870) | ||||
| ---
 | ||||
|  UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 ++++------- | ||||
|  1 file changed, 4 insertions(+), 7 deletions(-) | ||||
| 
 | ||||
| diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| index a50981c9d1..b408585fcc 100644
 | ||||
| --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
 | ||||
| @@ -1909,15 +1909,13 @@ GetBspNumber (
 | ||||
|    ) | ||||
|  { | ||||
|    UINT32             ApicId; | ||||
| -  UINT32             BspNumber;
 | ||||
|    UINT32             Index; | ||||
|    CONST MP_HAND_OFF  *MpHandOff; | ||||
|   | ||||
|    // | ||||
|    // Get the processor number for the BSP | ||||
|    // | ||||
| -  BspNumber = MAX_UINT32;
 | ||||
| -  ApicId    = GetInitialApicId ();
 | ||||
| +  ApicId = GetInitialApicId ();
 | ||||
|   | ||||
|    for (MpHandOff = FirstMpHandOff; | ||||
|         MpHandOff != NULL; | ||||
| @@ -1925,14 +1923,13 @@ GetBspNumber (
 | ||||
|    { | ||||
|      for (Index = 0; Index < MpHandOff->CpuCount; Index++) { | ||||
|        if (MpHandOff->Info[Index].ApicId == ApicId) { | ||||
| -        BspNumber = MpHandOff->ProcessorIndex + Index;
 | ||||
| +        return MpHandOff->ProcessorIndex + Index;
 | ||||
|        } | ||||
|      } | ||||
|    } | ||||
|   | ||||
| -  ASSERT (BspNumber != MAX_UINT32);
 | ||||
| -
 | ||||
| -  return BspNumber;
 | ||||
| +  ASSERT_EFI_ERROR (EFI_NOT_FOUND);
 | ||||
| +  return 0;
 | ||||
|  } | ||||
|   | ||||
|  /** | ||||
| -- 
 | ||||
| 2.39.3 | ||||
| 
 | ||||
							
								
								
									
										36
									
								
								edk2.spec
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								edk2.spec
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ ExclusiveArch: x86_64 aarch64 | ||||
| 
 | ||||
| Name:       edk2 | ||||
| Version:    %{GITDATE} | ||||
| Release:    1%{?dist} | ||||
| Release:    2%{?dist} | ||||
| Summary:    UEFI firmware for 64-bit virtual machines | ||||
| License:    BSD-2-Clause-Patent and Apache-2.0 and MIT | ||||
| URL:        http://www.tianocore.org | ||||
| @ -82,6 +82,26 @@ Patch28: 0030-OvmfPkg-Sec-Setup-MTRR-early-in-the-boot-process.patch | ||||
| Patch29: 0031-MdePkg-ArchitecturalMsr.h-add-defines-for-MTRR-cache.patch | ||||
| Patch30: 0032-UefiCpuPkg-MtrrLib.h-use-cache-type-defines-from-Arc.patch | ||||
| Patch31: 0033-OvmfPkg-Sec-use-cache-type-defines-from-Architectura.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch32: edk2-OvmfPkg-PlatformPei-log-a-warning-when-memory-is-tig.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch33: edk2-OvmfPkg-PlatformPei-consider-AP-stacks-for-pei-memor.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch34: edk2-OvmfPkg-PlatformPei-rewrite-page-table-calculation.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch35: edk2-OvmfPkg-PlatformPei-log-pei-memory-cap-details.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch36: edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch37: edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p2.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch38: edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p3.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch39: edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p4.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch40: edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p5.patch | ||||
| # For RHEL-22202 - [EDK2] Support booting with 4096 vcpus | ||||
| Patch41: edk2-UefiCpuPkg-MpInitLib-return-early-in-GetBspNumber.patch | ||||
| 
 | ||||
| # python3-devel and libuuid-devel are required for building tools. | ||||
| # python3-devel is also needed for varstore template generation and | ||||
| @ -415,6 +435,20 @@ install -m 0644 \ | ||||
| 
 | ||||
| 
 | ||||
| %changelog | ||||
| * Mon Apr 08 2024 Miroslav Rezanina <mrezanin@redhat.com> - 20240214-2 | ||||
| - edk2-OvmfPkg-PlatformPei-log-a-warning-when-memory-is-tig.patch [RHEL-22202] | ||||
| - edk2-OvmfPkg-PlatformPei-consider-AP-stacks-for-pei-memor.patch [RHEL-22202] | ||||
| - edk2-OvmfPkg-PlatformPei-rewrite-page-table-calculation.patch [RHEL-22202] | ||||
| - edk2-OvmfPkg-PlatformPei-log-pei-memory-cap-details.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p2.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p3.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p4.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-Add-support-for-multiple-HOBs-t.p5.patch [RHEL-22202] | ||||
| - edk2-UefiCpuPkg-MpInitLib-return-early-in-GetBspNumber.patch [RHEL-22202] | ||||
| - Resolves: RHEL-22202 | ||||
|   ([EDK2] Support booting with 4096 vcpus) | ||||
| 
 | ||||
| * Tue Feb 27 2024 Gerd Hoffmann <kraxel@redhat.com> - 20240214-1 | ||||
| - Rebase to edk2-stable202302 | ||||
| - Resolves: RHEL-26879 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user