From: "Wu, Jiaxin" <jiaxin.wu@intel.com>
To: "Ni, Ray" <ray.ni@intel.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Dong, Eric" <eric.dong@intel.com>, "Zeng, Star" <star.zeng@intel.com>
Subject: Re: [PATCH v2] UefiCpuPkg: Support SMM Relocated SmBase handling
Date: Fri, 13 Jan 2023 10:05:31 +0000 [thread overview]
Message-ID: <MN0PR11MB615839FEB5C1DF9F8E95840AFEC29@MN0PR11MB6158.namprd11.prod.outlook.com> (raw)
In-Reply-To: <MN6PR11MB82443776C84CADDBD7B048258CC29@MN6PR11MB8244.namprd11.prod.outlook.com>
Thanks ray, below are really great feedback. I have checked all and response as below:
> The default SMBASE for the x86 processor is 0x30000. When SMI happens,
> CPU runs the
> SMI handler at SMBASE+0x8000. Also, the SMM save state area is within
> SMBASE+0x10000.
>
> One of the SMM initialization from CPU perspective is to program the new
> SMBASE (in TSEG range)
> for each CPU thread. When the SMBASE update happens in a PEI module,
> the PEI module shall
> produce the SMM_BASE_HOB in HOB database which tells the
> PiSmmCpuDxeSmm driver which runs
> at a later phase about the new SMBASE for each CPU thread.
> PiSmmCpuDxeSmm driver installs
> the SMI handler at the SMM_BASE_HOB.SmBase[Index]+0x8000 for CPU
> thread Index.
> When the HOB doesn't exist, PiSmmCpuDxeSmm driver shall program the
> new SMBASE itself.
>
Agree, added!
>
> 2. Can you write the code as "mSmmRelocationDone = (BOOLEAN)
> (GetFirstGuidHob (&gSmmBaseHobGuid) != NULL)"?
> It removes the assumption that the initial value of mSmmRelocationDone is
> FALSE.
> I understand it's TRUE usually. But it depends on the PE loader.
Agree.
>
> > + if (GetFirstGuidHob (&gSmmBaseHobGuid) != NULL) {
> > + mSmmRelocated = TRUE;
> > + } else {
> > + mSmmRelocated = FALSE;
>
> 3. The above code doesn't assume the initial value of global variable. Good.
> Can you align the variable name between SmmCpuFeaturesLib and the
> PiSmmCpuDxeSmm driver?
> If the two names are chosen to fix link error, there are two ways to avoid
> the error:
> a. Add "static" and both component use mSmmRelocated.
> b. One can be renamed as mSmmCpuFeaturesSmmRelocated. No change
> to the one in driver.
>
Agree.
> > + }
> > +
> > + //
> > + // Check whether Smm Relocation is done or not.
> > + // If not, will do the SmmBases Relocation here!!!
> > //
> > - SmmRelocateBases ();
> > + if (!mSmmRelocated) {
> > + //
> > + // Restore SMBASE for BSP and all APs
> > + //
> > + SmmRelocateBases ();
> > + } else {
> > + mSmmInitialized = (BOOLEAN*)AllocateZeroPool (sizeof (BOOLEAN) *
> mMaxNumberOfCpus);
> 4. I guess mSmmInitialized is already allocated in normal boot phase. Here
> what we need is only to set all
> elements to FALSE. Will keep reviewing following changes and confirm my
> guess.
> But we still cannot call Allocate in every S3 boot without freeing. It may
> cause all SMRAM be allocated.
>
Yes, I checked the detailed, we don't need allocate that.
>
> > + ASSERT (mSmmInitialized != NULL);
> > +
> > + mBspApicId = GetApicId ();
> > +
> > + //
> > + // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) for SMM init
> > + //
> > + SendSmiIpi (mBspApicId);
> > + SendSmiIpiAllExcludingSelf ();
> > +
> > + //
> > + // Wait for all processors to finish its 1st SMI
> > + //
> > + for (Index = 0; Index < mNumberOfCpus; Index++) {
> > + while (mSmmInitialized[Index] == FALSE) {
> > + }
> > + }
> 5. I am not sure if the same logic is also needed in normal boot. So, maybe a
> local function can be created to
> reduce the code duplication?
Ok, will define new API to reduce the duplication.
>
>
> > + if (!mSmmRelocated) {
> > + IsMonarch = mIsBsp;
> > + } else if (mBspApicId == ApicId) {
> > + IsMonarch = TRUE;
> > + }
>
> 6. How about removing mIsBsp and always use mBspApicId even when
> mSmmRelocated==FALSE?
> 7. How about renaming IsMonarch to IsBsp?
Agree.
>
> >
> > - if (mIsBsp) {
> > + if (!mSmmRelocated) {
> > + if (mIsBsp) {
> > + //
> > + // BSP rebase is already done above.
> > + // Initialize private data during S3 resume
> > + //
> > + InitializeMpSyncData ();
> 8. Because the same function is already called in driver entrypoint, here the
> call is for s3 path.
> Can you check if we need to call it as well in S3 path when SmmRelocated is
> TRUE?
Yes, we need that in S3, will handle it.
>
> > + if (TileSize > SIZE_8KB) {
> > + DEBUG ((DEBUG_ERROR, "The Range of Smbase in SMRAM is not
> enough -- Required TileSize = 0x%08x, Actual TileSize
> > = 0x%08x\n", TileSize, SIZE_8KB));
> > + ASSERT (TileSize <= SIZE_8KB);
>
> 9. I suggest we add CpuDeadLoop() here to capture the error in release build.
Agree.
prev parent reply other threads:[~2023-01-13 10:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 8:35 [PATCH v2] UefiCpuPkg: Support SMM Relocated SmBase handling Wu, Jiaxin
2023-01-12 12:37 ` [edk2-devel] " Laszlo Ersek
2023-01-12 12:57 ` Laszlo Ersek
2023-01-13 3:05 ` Wu, Jiaxin
2023-01-13 7:28 ` Wu, Jiaxin
2023-01-13 7:52 ` Ni, Ray
2023-01-13 10:05 ` Wu, Jiaxin [this message]
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=MN0PR11MB615839FEB5C1DF9F8E95840AFEC29@MN0PR11MB6158.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