public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "Zeng, Star" <star.zeng@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "Dong, Eric" <eric.dong@intel.com>, "Ni, Ray" <ray.ni@intel.com>,
	"Laszlo Ersek" <lersek@redhat.com>,
	"Kumar, Rahul1" <rahul1.kumar@intel.com>
Subject: Re: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition
Date: Mon, 25 Jan 2021 05:15:43 +0000	[thread overview]
Message-ID: <CO1PR11MB4929FA1102A18D240939381CD2BD9@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <DM6PR11MB4058795F6CDA4FF57C4A92BEE3BD9@DM6PR11MB4058.namprd11.prod.outlook.com>

Hi Star,

That line is only active when (CpuMpData->SevEsIsEnabled) is TRUE.

The race condition addressed by this BZ is for systems with SecEsIsEnabled FALSE.

From comments in this file the SecEsIsEnabled cases have already been handled.

Mike

> -----Original Message-----
> From: Zeng, Star <star.zeng@intel.com>
> Sent: Sunday, January 24, 2021 7:15 PM
> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1
> <rahul1.kumar@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: RE: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition
> 
> Does https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpInitLib/MpLib.c#L909 (also decrements
> NumApsExecuting) also need be handled?
> 
> Thanks,
> Star
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael
> > D Kinney
> > Sent: Saturday, January 23, 2021 1:10 AM
> > To: devel@edk2.groups.io
> > Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Laszlo
> > Ersek <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
> > Subject: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP
> > VolatileRegisters race condition
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3182
> >
> > Fix the order of operations in ApWakeupFunction() when
> > PcdCpuApLoopMode
> > is set to HLT mode that uses INIT-SIPI-SIPI to wake APs.  In this mode,
> > volatile state is restored and saved each time a INIT-SIPI-SIPI is sent
> > to an AP to request a function to be executed on the AP.  When the
> > function is completed the volatile state of the AP is saved.  However,
> > the counters NumApsExecuting and FinishedCount are updated before
> > the volatile state is saved.  This allows for a race condition window
> > for the BSP that is waiting on these counters to request a new
> > INIT-SIPI-SIPI before all the APs have completely saved their volatile
> > state.  The fix is to save the AP volatile state before updating the
> > NumApsExecuting and FinishedCount counters.
> >
> > Cc: Eric Dong <eric.dong@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Laszlo Ersek <lersek@redhat.com>
> > Cc: Rahul Kumar <rahul1.kumar@intel.com>
> > Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
> > ---
> >  UefiCpuPkg/Library/MpInitLib/MpLib.c | 31 ++++++++++++++++------------
> >  1 file changed, 18 insertions(+), 13 deletions(-)
> >
> > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> > b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> > index 681fa79b4cff..8b1f7f84bad6 100644
> > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> > @@ -769,15 +769,6 @@ ApWakeupFunction (
> >        RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters,
> > FALSE);
> >        InitializeApData (CpuMpData, ProcessorNumber, BistData,
> > ApTopOfStack);
> >        ApStartupSignalBuffer = CpuMpData-
> > >CpuData[ProcessorNumber].StartupApSignal;
> > -
> > -      //
> > -      // Delay decrementing the APs executing count when SEV-ES is enabled
> > -      // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly
> > -      // performs another INIT-SIPI-SIPI sequence.
> > -      //
> > -      if (!CpuMpData->SevEsIsEnabled) {
> > -        InterlockedDecrement ((UINT32 *) &CpuMpData-
> > >MpCpuExchangeInfo->NumApsExecuting);
> > -      }
> >      } else {
> >        //
> >        // Execute AP function if AP is ready
> > @@ -866,19 +857,33 @@ ApWakeupFunction (
> >        }
> >      }
> >
> > +    if (CpuMpData->ApLoopMode == ApInHltLoop) {
> > +      //
> > +      // Save AP volatile registers
> > +      //
> > +      SaveVolatileRegisters (&CpuMpData-
> > >CpuData[ProcessorNumber].VolatileRegisters);
> > +    }
> > +
> >      //
> >      // AP finished executing C code
> >      //
> >      InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount);
> >
> > +    if (CpuMpData->InitFlag == ApInitConfig) {
> > +      //
> > +      // Delay decrementing the APs executing count when SEV-ES is enabled
> > +      // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly
> > +      // performs another INIT-SIPI-SIPI sequence.
> > +      //
> > +      if (!CpuMpData->SevEsIsEnabled) {
> > +        InterlockedDecrement ((UINT32 *) &CpuMpData-
> > >MpCpuExchangeInfo->NumApsExecuting);
> > +      }
> > +    }
> > +
> >      //
> >      // Place AP is specified loop mode
> >      //
> >      if (CpuMpData->ApLoopMode == ApInHltLoop) {
> > -      //
> > -      // Save AP volatile registers
> > -      //
> > -      SaveVolatileRegisters (&CpuMpData-
> > >CpuData[ProcessorNumber].VolatileRegisters);
> >        //
> >        // Place AP in HLT-loop
> >        //
> > --
> > 2.29.2.windows.2
> >
> >
> >
> > 
> >


  reply	other threads:[~2021-01-25  5:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 17:10 [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition Michael D Kinney
2021-01-23  2:02 ` [edk2-devel] " Laszlo Ersek
2021-01-26  6:47   ` Philippe Mathieu-Daudé
2021-01-23  5:10 ` Dong, Eric
2021-01-25  3:14 ` [edk2-devel] " Zeng, Star
2021-01-25  5:15   ` Michael D Kinney [this message]
2021-01-25  8:43     ` Zeng, Star
2021-01-25  8:53       ` Ni, Ray
2021-01-25 11:04         ` Zeng, Star
2021-01-25 21:17           ` Laszlo Ersek
2021-01-26  1:18             ` Zeng, Star
2021-01-26  2:26             ` Ni, Ray
2021-01-26  3:34               ` Zeng, Star

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=CO1PR11MB4929FA1102A18D240939381CD2BD9@CO1PR11MB4929.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