public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: "Feng, Ning" <ning.feng@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib
Date: Thu, 23 May 2024 14:39:47 +0000	[thread overview]
Message-ID: <MN6PR11MB82440080CA97B3593C36D9958CF42@MN6PR11MB8244.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20240523180235.3841139-1-ning.feng@intel.com>

[-- Attachment #1: Type: text/plain, Size: 6210 bytes --]

Ning,
The patch looks good to me.
But it seems you did not change the patch title to a more specific message.

[Ray.1] The subject should be more specific. E.g.: UefiCpuPkg/MpInitLib: Do not assume BSP is #0.




Thanks,
Ray
________________________________
From: Feng, Ning <ning.feng@intel.com>
Sent: Friday, May 24, 2024 2:02
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Feng, Ning <ning.feng@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH] Pkg-Module:UefiCpuPkg/MpLib

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4778
MPInitlib have wrong expectation that BSP index should always be 0 in
MpInitLibInitialize(), SwitchBsp(),ApWakeupFunction().
That will cause the data mismatch, if the initial BSP is not 0.
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Ning Feng <ning.feng@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 ++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d724456502..ae279c6ceb 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -114,6 +114,10 @@ FutureBSPProc (
   SaveVolatileRegisters (&DataInHob->APInfo.VolatileRegisters);

   AsmExchangeRole (&DataInHob->APInfo, &DataInHob->BSPInfo);

   RestoreVolatileRegisters (&DataInHob->APInfo.VolatileRegisters, FALSE);

+  //

+  // Restore VolatileReg saved in CpuMpData->CpuData

+  //

+  CopyMem (&DataInHob->CpuData[DataInHob->BspNumber].VolatileRegisters, &DataInHob->APInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));

 }



 /**

@@ -761,11 +765,11 @@ ApWakeupFunction (
       BistData     = (UINT32)ApStackData->Bist;



       //

-      // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP environment,

+      // CpuMpData->CpuData[BspNumber].VolatileRegisters is initialized based on BSP environment,

       //   to initialize AP in InitConfig path.

-      // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters points to a different IDT shared by all APs.

+      // NOTE: IDTR.BASE stored in CpuMpData->CpuData[BspNumber].VolatileRegisters points to a different IDT shared by all APs.

       //

-      RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);

+      RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

       InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);

       ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;

     } else {

@@ -798,10 +802,10 @@ ApWakeupFunction (
         // 1. AP is re-enabled after it's disabled, in either PEI or DXE phase.

         // 2. AP is initialized in DXE phase.

         // In either case, use the volatile registers value derived from BSP.

-        // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters points to a

+        // NOTE: IDTR.BASE stored in CpuMpData->CpuData[BspNumber].VolatileRegisters points to a

         //   different IDT shared by all APs.

         //

-        RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);

+        RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

       } else {

         if (CpuMpData->ApLoopMode == ApInHltLoop) {

           //

@@ -927,7 +931,7 @@ DxeApEntryPoint (
     AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64);

   }



-  RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);

+  RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount);

   PlaceAPInMwaitLoopOrRunLoop (

     CpuMpData->ApLoopMode,

@@ -2151,7 +2155,12 @@ MpInitLibInitialize (
   CpuMpData->BackupBufferSize = ApResetVectorSizeBelow1Mb;

   CpuMpData->WakeupBuffer     = (UINTN)-1;

   CpuMpData->CpuCount         = 1;

-  CpuMpData->BspNumber        = 0;

+  if (MpHandOff == NULL) {

+    CpuMpData->BspNumber = 0;

+  } else {

+    CpuMpData->BspNumber = GetBspNumber (MpHandOff);

+  }

+

   CpuMpData->WaitEvent        = NULL;

   CpuMpData->SwitchBspFlag    = FALSE;

   CpuMpData->CpuData          = (CPU_AP_DATA *)(CpuMpData + 1);

@@ -2186,11 +2195,11 @@ MpInitLibInitialize (
   // Don't pass BSP's TR to APs to avoid AP init failure.

   //

   VolatileRegisters.Tr = 0;

-  CopyMem (&CpuMpData->CpuData[0].VolatileRegisters, &VolatileRegisters, sizeof (VolatileRegisters));

+  CopyMem (&CpuMpData->CpuData[CpuMpData->BspNumber].VolatileRegisters, &VolatileRegisters, sizeof (VolatileRegisters));

   //

   // Set BSP basic information

   //

-  InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);

+  InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer + ApStackSize * (CpuMpData->BspNumber + 1));

   //

   // Save assembly code information

   //

@@ -2615,7 +2624,12 @@ SwitchBSPWorker (
   SaveVolatileRegisters (&CpuMpData->BSPInfo.VolatileRegisters);

   AsmExchangeRole (&CpuMpData->BSPInfo, &CpuMpData->APInfo);

   RestoreVolatileRegisters (&CpuMpData->BSPInfo.VolatileRegisters, FALSE);

-

+  //

+  // Restore VolatileRegs saved in CpuMpData->CpuData

+  // Don't pass BSP's TR to APs to avoid AP init failure.

+  //

+  CopyMem (&CpuMpData->CpuData[CpuMpData->NewBspNumber].VolatileRegisters, &CpuMpData->BSPInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));

+  CpuMpData->CpuData[CpuMpData->NewBspNumber].VolatileRegisters.Tr = 0;

   //

   // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP

   //

--
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119160): https://edk2.groups.io/g/devel/message/119160
Mute This Topic: https://groups.io/mt/106256300/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 11645 bytes --]

  parent reply	other threads:[~2024-05-23 14:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 18:02 [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib Ning Feng
2024-05-23  9:55 ` Ning Feng
2024-05-23 14:39 ` Ni, Ray [this message]
2024-05-24  1:26   ` Ning Feng
  -- strict thread matches above, loose matches on Subject: below --
2024-05-23 17:51 Ning Feng
2024-05-23 17:44 Ning Feng
2024-05-23 11:13 Ning Feng
2024-05-23  7:31 ` Ni, Ray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN6PR11MB82440080CA97B3593C36D9958CF42@MN6PR11MB8244.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox