public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: Laszlo Ersek <lersek@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Wu, Jiaxin" <jiaxin.wu@intel.com>
Cc: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Dong, Eric" <eric.dong@intel.com>,
	"Zeng, Star" <star.zeng@intel.com>,
	"Kumar, Rahul R" <rahul.r.kumar@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Zimmer, Vincent" <vincent.zimmer@intel.com>
Subject: Re: [PATCH v3 1/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base HOB Data
Date: Thu, 2 Feb 2023 03:52:31 +0000	[thread overview]
Message-ID: <DM4PR11MB8226D867B9C5B29C8C34CA458CD69@DM4PR11MB8226.namprd11.prod.outlook.com> (raw)
In-Reply-To: <8142cc40-ca21-2748-a3de-d0432ccbdc07@redhat.com>



> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com>
> Sent: Friday, January 20, 2023 4:21 PM
> To: Ni, Ray <ray.ni@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Wu,
> Jiaxin <jiaxin.wu@intel.com>
> Cc: devel@edk2.groups.io; Dong, Eric <eric.dong@intel.com>; Zeng, Star
> <star.zeng@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>; Zimmer, Vincent
> <vincent.zimmer@intel.com>
> Subject: Re: [PATCH v3 1/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base
> HOB Data
> 
> On 1/18/23 16:06, Ni, Ray wrote:
> 
> > #pragma pack(1)
> > typedef struct {
> >   UINT32    CpuIndex;
> >   UINT32    NumberOfCpus;  // align to
> EFI_SEC_PLATFORM_INFORMATION_RECORD2.NumberOfCpus
> >   UINT64    SmBase[];
> > } SMM_BASE_HOB_DATA;
> > #pragma pack()
> >
> > For system with less than 8K CPUs, one HOB is produced. CpuIndex is set to
> 0 indicating
> > the HOB describes the CPU from 0 to NumberOfCpus-1.
> >
> > The HOB list may contains multiple such HOB instances each describing the
> information for
> > CPU from CpuIndex to CpuIndex + NumberOfCpus - 1.
> > The instance order in the HOB list is random so consumer cannot assume
> the CpuIndex
> > of first instance is 0.
> 
> When using discontiguous blocks that are limited to ~64KB each:
> 
> - The consumer won't be able to access elements of the "conceptual" big
> array in a truly random (= random-access) fashion. There won't be a
> single contiguous domain of valid subscripts. It's "bank switching", and
> switching banks should be avoided IMO. It effectively replaces the
> vector data structure with a linked list. The consequence is that the
> consumer will have to either (a) build a new (temporary, or permanent)
> index table of sorts, for implementing the "conceptual" big array as a
> factual contiguous array, or (b) traverse the HOB list multiple times.

I agree. My recommendation is the consumer queries the total cpu count and
allocate a big-enough temp buffer, then it traverse the HOB and copies
each instance of the SMM information HOB to the proper location in the buffer.
After the SMM rebase is done, the temp buffer can be freed to reduce
SMM memory consumption.

Multi-traverse of the HOB can avoid the temp buffer allocation. But the code
logic will be a bit more complicated. I don't prefer.


> 
> - If the element size of the array increases (which is otherwise
> possible to do compatibly, e.g. by placing a GUID and/or revision# in
> the HOB), the number of elements that fit in a single HOB decreases. I
> think that's an artifact that needlessly complicates debugging, and
> maybe performance too (it might increase the number of full-list
> traversals).

TRUE that multi-instance of the HOBs make the debugging harder.
That's why I propose to have "CpuIndex" field to tell which range CPU the
specific HOB describes.

> 
> - With relatively many elements fitting into a single HOB, on most
> platforms, just one HOB is going to be used. While that may be good for
> performance, it is not good for code coverage (testing). The quirky
> indexing method will not be exercised by most platforms.

TRUE so I propose that the first version of the code change only expects
the HOB.NumberOfCpus equals to the NumberOfCpus returned from MP
service, meaning the code logic only supports single instance of the HOB.
When a platform that contains >8000 cpu threads resulting in multiple HOBs
produced, the expectation will break and remind us that the CpuSmm driver
needs to update to handle multiple HOBs.

> 
> What's wrong with:
> 
> - restricting the creation of all such HOBs after
> "gEfiPeiMemoryDiscoveredPpiGuid"
> 
> - using a page allocation, for representing the array contiguously
> 
> - in the HOB, only storing the address of the page allocation.
> 
> Page allocations performed after gEfiPeiMemoryDiscoveredPpiGuid will not
> be moved, so the address in the HOB would be stable.

It can work. I agree.
However, please think about future standalone MM case. The StandaloneMmIpl
builds HOB list and pass to StandaloneMmCore. The HOB list shall contain the
SMM base information HOB. If we only store a pointer in the HOB, the pointer will
points to a SMRAM carved out from SMRAM by StandaloneMmIpl. Memory service
in StandaloneMmCore cannot be used because StandaloneMmCore hasn't been loaded.
I don't prefer to introduce extra memory management logic in StandaloneMmIpl though
the logic is very simple to carve out some pages from SMRAM.

Thanks,
Ray

  parent reply	other threads:[~2023-02-02  3:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18  9:56 [PATCH v3 0/5] Simplify SMM Relocation Process Wu, Jiaxin
2023-01-18  9:56 ` [PATCH v3 1/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base HOB Data Wu, Jiaxin
2023-01-18 11:19   ` Gerd Hoffmann
2023-01-18 15:06     ` Ni, Ray
2023-01-19  7:13       ` Gerd Hoffmann
2023-01-29  5:08         ` Wu, Jiaxin
2023-02-01 13:02           ` Gerd Hoffmann
2023-01-20  8:21       ` Laszlo Ersek
2023-01-29  5:24         ` Wu, Jiaxin
2023-02-01 13:14           ` Gerd Hoffmann
2023-02-02  0:44             ` Wu, Jiaxin
2023-02-02  3:54             ` [edk2-devel] " Ni, Ray
2023-02-02  3:52         ` Ni, Ray [this message]
2023-02-02 12:51           ` Gerd Hoffmann
2023-02-02 22:29             ` [edk2-devel] " Brian J. Johnson
2023-02-03  3:14               ` Ni, Ray
2023-02-03  7:54                 ` Gerd Hoffmann
2023-02-03 13:22                   ` Wu, Jiaxin
2023-02-03 13:31                     ` Ni, Ray
2023-02-03 15:00                     ` Gerd Hoffmann
2023-01-18  9:56 ` [PATCH v3 2/5] UefiCpuPkg/PiSmmCpuDxeSmm: Fix invalid InitializeMpSyncData call Wu, Jiaxin
2023-01-18  9:56 ` [PATCH v3 3/5] UefiCpuPkg/PiSmmCpuDxeSmm: Consume SMM Base Hob for SmBase info Wu, Jiaxin
2023-01-18 12:02   ` Gerd Hoffmann
2023-01-29  6:14     ` [edk2-devel] " Wu, Jiaxin
2023-01-18  9:56 ` [PATCH v3 4/5] UefiCpuPkg/SmmCpuFeaturesLib: Skip SMBASE configuration Wu, Jiaxin
2023-01-18  9:56 ` [PATCH v3 5/5] OvmfPkg/SmmCpuFeaturesLib: " Wu, Jiaxin
2023-01-18 12:19   ` Gerd Hoffmann
2023-01-18 14:37     ` Ni, Ray
2023-01-19  7:53       ` Gerd Hoffmann
2023-01-29  5:47         ` Wu, Jiaxin
2023-02-01 13:40           ` Gerd Hoffmann
2023-02-02  1:41             ` Wu, Jiaxin
2023-02-02  9:00               ` Gerd Hoffmann
2023-02-02 11:47                 ` Laszlo Ersek
2023-02-02 12:24                   ` Gerd Hoffmann
2023-02-03  3:05                     ` Wu, Jiaxin
2023-02-03  2:47                   ` Wu, Jiaxin
2023-02-03  3:45                   ` Ni, Ray
2023-02-03  7:31                     ` Gerd Hoffmann
2023-02-03  7:43                       ` Ni, Ray
2023-02-03  8:49                         ` Gerd Hoffmann
2023-02-03 11:18                         ` Wu, Jiaxin
     [not found] ` <173B5EAF72B992BD.14781@groups.io>
2023-02-03  8:59   ` [edk2-devel] " Wu, Jiaxin
2023-02-03  9:04     ` Gerd Hoffmann
2023-02-03 11:15       ` Wu, Jiaxin

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=DM4PR11MB8226D867B9C5B29C8C34CA458CD69@DM4PR11MB8226.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