Because the code logic in InitPaging() in Patch 14/15 requires that the two 
arrays have been sorted.
Yes, the code logic in FindSmramInfo() to deals with un-sorted 
mSmmCpuSmramRanges array can removed. Will add more changes to do this.

Thanks,
Dun

-----Original Message-----
From: Ni, Ray <ray...@intel.com> 
Sent: Friday, June 2, 2023 11:36 AM
To: Tan, Dun <dun....@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.d...@intel.com>; Kumar, Rahul R <rahul.r.ku...@intel.com>; 
Gerd Hoffmann <kra...@redhat.com>
Subject: RE: [Patch V4 13/15] UefiCpuPkg: Sort mProtectionMemRange when 
ReadyToLock

Why do you add the sort logic?
I thought you might have further changes to remove some unnecessary logic that 
deals with un-sorted array.

> -----Original Message-----
> From: Ni, Ray
> Sent: Friday, June 2, 2023 11:34 AM
> To: Tan, Dun <dun....@intel.com>; devel@edk2.groups.io
> Cc: Dong, Eric <eric.d...@intel.com>; Kumar, Rahul R 
> <rahul.r.ku...@intel.com>; Gerd Hoffmann <kra...@redhat.com>
> Subject: RE: [Patch V4 13/15] UefiCpuPkg: Sort mProtectionMemRange 
> when ReadyToLock
> 
> Similar comments as patch #12.
> You could avoid pool allocation.
> 
> > -----Original Message-----
> > From: Tan, Dun <dun....@intel.com>
> > Sent: Tuesday, May 16, 2023 6:00 PM
> > To: devel@edk2.groups.io
> > Cc: Dong, Eric <eric.d...@intel.com>; Ni, Ray <ray...@intel.com>; 
> > Kumar,
> Rahul
> > R <rahul.r.ku...@intel.com>; Gerd Hoffmann <kra...@redhat.com>
> > Subject: [Patch V4 13/15] UefiCpuPkg: Sort mProtectionMemRange when 
> > ReadyToLock
> >
> > Sort mProtectionMemRange in InitProtectedMemRange() when 
> > ReadyToLock.
> >
> > Signed-off-by: Dun Tan <dun....@intel.com>
> > Cc: Eric Dong <eric.d...@intel.com>
> > Cc: Ray Ni <ray...@intel.com>
> > Cc: Rahul Kumar <rahul1.ku...@intel.com>
> > Cc: Gerd Hoffmann <kra...@redhat.com>
> > ---
> >  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 35
> > +++++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> >
> > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> > index 5625ba0cac..b298e2fb99 100644
> > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> > @@ -375,6 +375,32 @@ IsAddressSplit (
> >    return FALSE;
> >  }
> >
> > +/**
> > +  Function to compare 2 MEMORY_PROTECTION_RANGE based on range base.
> > +
> > +  @param[in] Buffer1            pointer to Device Path poiner to compare
> > +  @param[in] Buffer2            pointer to second DevicePath pointer to 
> > compare
> > +
> > +  @retval 0                     Buffer1 equal to Buffer2
> > +  @retval <0                    Buffer1 is less than Buffer2
> > +  @retval >0                    Buffer1 is greater than Buffer2
> > +**/
> > +INTN
> > +EFIAPI
> > +ProtectionRangeCompare (
> > +  IN  CONST VOID  *Buffer1,
> > +  IN  CONST VOID  *Buffer2
> > +  )
> > +{
> > +  if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base >
> > ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) {
> > +    return 1;
> > +  } else if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base <
> > ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) {
> > +    return -1;
> > +  }
> > +
> > +  return 0;
> > +}
> > +
> >  /**
> >    Initialize the protected memory ranges and the 4KB-page mapped 
> > memory ranges.
> >
> > @@ -397,6 +423,7 @@ InitProtectedMemRange (
> >    EFI_PHYSICAL_ADDRESS             Base2MBAlignedAddress;
> >    UINT64                           High4KBPageSize;
> >    UINT64                           Low4KBPageSize;
> > +  VOID                             *Buffer;
> >
> >    NumberOfDescriptors      = 0;
> >    NumberOfAddedDescriptors = mSmmCpuSmramRangeCount; @@ -533,6 
> > +560,14 @@ InitProtectedMemRange (
> >
> >    mSplitMemRangeCount = NumberOfSpliteRange;
> >
> > +  //
> > +  // Sort the mProtectionMemRange
> > +  //
> > +  Buffer = AllocateZeroPool (sizeof (MEMORY_PROTECTION_RANGE));  
> > + ASSERT (Buffer != NULL);  QuickSort (mProtectionMemRange, 
> > + mProtectionMemRangeCount, sizeof
> > (MEMORY_PROTECTION_RANGE),
> > (BASE_SORT_COMPARE)ProtectionRangeCompare, Buffer);
> > +  FreePool (Buffer);
> > +
> >    DEBUG ((DEBUG_INFO, "SMM Profile Memory Ranges:\n"));
> >    for (Index = 0; Index < mProtectionMemRangeCount; Index++) {
> >      DEBUG ((DEBUG_INFO, "mProtectionMemRange[%d].Base = %lx\n", 
> > Index, mProtectionMemRange[Index].Range.Base));
> > --
> > 2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105634): https://edk2.groups.io/g/devel/message/105634
Mute This Topic: https://groups.io/mt/98922941/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to