REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4337
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 relocate
and program the new SMBASE (in TSEG range) for each CPU thread. When
the SMBASE relocation happens in a PEI module, the PEI module shall
produce the SMM_BASE_HOB in HOB database which tells the
PiSmmCpuDxeSmm driver (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 relocate and
program the new SMBASE itself.
This patch adds the SMM Base HOB for any PEI module to do
the SmBase relocation ahead of PiSmmCpuDxeSmm driver and
store the relocated SmBase address in array for reach
Processors.
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
UefiCpuPkg/Include/Guid/SmmBaseHob.h | 64 ++++++++++++++++++++++++++++++++++++
UefiCpuPkg/UefiCpuPkg.dec | 3 ++
2 files changed, 67 insertions(+)
create mode 100644 UefiCpuPkg/Include/Guid/SmmBaseHob.h
diff --git a/UefiCpuPkg/Include/Guid/SmmBaseHob.h b/UefiCpuPkg/Include/Guid/SmmBaseHob.h
new file mode 100644
index 0000000000..d22b3b942c
--- /dev/null
+++ b/UefiCpuPkg/Include/Guid/SmmBaseHob.h
@@ -0,0 +1,64 @@
+/** @file
+ The Smm Base HOB is used to store the information of:
+ * The relocated SmBase address in array for each Processors.
+
+ 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 relocate and program
+ the new SMBASE (in TSEG range) for each CPU thread. When the SMBASE relocation
+ 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 relocate and program
+ the new SMBASE itself.
+
+ Note:
+ SMBASE relocation process needs to program the vender specific hardware
+ interface to set SMBASE, it should be in the thread scope. It's doable to
+ program the hardware interface using DXE MP service protocol in PiSmmCpuDxeSmm
+ entry point. But, considering the standalone MM environment where the CpuMm
+ driver runs in a isolated environment and it cannot invoke any DXE or PEI MP
+ service, we recommend to put the hardware interface programming in a separate
+ PEI module instead of in the PiSmmCpuDxeSmm driver.
+
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef SMM_BASE_HOB_H_
+#define SMM_BASE_HOB_H_
+
+#define SMM_BASE_HOB_DATA_GUID \
+ { \
+ 0xc2217ba7, 0x03bb, 0x4f63, {0xa6, 0x47, 0x7c, 0x25, 0xc5, 0xfc, 0x9d, 0x73} \
+ }
+
+#pragma pack(1)
+typedef struct {
+ ///
+ /// CpuIndex tells which CPU range this specific HOB instance described.
+ /// If CpuIndex is set to 0, it indicats the HOB describes the CPU from 0 to
+ /// NumberOfCpus - 1. The HOB list may contains multiple this HOB instances.
+ /// Each HOB instances describe the information for CPU from CpuIndex to
+ /// CpuIndex + NumberOfCpus - 1. The instance order in the HOB list is random
+ /// so consumer can not assume the CpuIndex of first instance is 0.
+ ///
+ UINT32 CpuIndex;
+ ///
+ /// Describes the Number of all max supported processors.
+ ///
+ UINT32 NumberOfProcessors;
+ ///
+ /// Pointer to SmBase address for each Processors.
+ ///
+ UINT64 SmBase[1];
+} SMM_BASE_HOB_DATA;
+#pragma pack()
+
+extern EFI_GUID gSmmBaseHobGuid;
+
+#endif
diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index cff239d528..2afd08cdd2 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -76,10 +76,13 @@
gEdkiiCpuFeaturesInitDoneGuid = { 0xc77c3a41, 0x61ab, 0x4143, { 0x98, 0x3e, 0x33, 0x39, 0x28, 0x6, 0x28, 0xe5 }}
## Include/Guid/MicrocodePatchHob.h
gEdkiiMicrocodePatchHobGuid = { 0xd178f11d, 0x8716, 0x418e, { 0xa1, 0x31, 0x96, 0x7d, 0x2a, 0xc4, 0x28, 0x43 }}
+ ## Include/Guid/SmmBaseHob.h
+ gSmmBaseHobGuid = { 0xc2217ba7, 0x03bb, 0x4f63, {0xa6, 0x47, 0x7c, 0x25, 0xc5, 0xfc, 0x9d, 0x73 }}
+
[Protocols]
## Include/Protocol/SmmCpuService.h
gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }}
gEdkiiSmmCpuRendezvousProtocolGuid = { 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }}
--
2.16.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99957): https://edk2.groups.io/g/devel/message/99957
Mute This Topic: https://groups.io/mt/96871372/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi,
> +#pragma pack(1)
> +typedef struct {
> + ///
> + /// CpuIndex tells which CPU range this specific HOB instance described.
> + /// If CpuIndex is set to 0, it indicats the HOB describes the CPU from 0 to
> + /// NumberOfCpus - 1. The HOB list may contains multiple this HOB instances.
> + /// Each HOB instances describe the information for CPU from CpuIndex to
> + /// CpuIndex + NumberOfCpus - 1. The instance order in the HOB list is random
> + /// so consumer can not assume the CpuIndex of first instance is 0.
> + ///
> + UINT32 CpuIndex;
> + ///
> + /// Describes the Number of all max supported processors.
> + ///
> + UINT32 NumberOfProcessors;
> + ///
> + /// Pointer to SmBase address for each Processors.
> + ///
> + UINT64 SmBase[1];
> +} SMM_BASE_HOB_DATA;
> +#pragma pack()
No generic chunked hobs as suggested/discussed on v3 of this series?
Why not?
take care,
Gerd
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99975): https://edk2.groups.io/g/devel/message/99975
Mute This Topic: https://groups.io/mt/96871372/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Gerd,
That requires changing PI spec and all HOB consuming logic.
But if you have a simple idea, please advise.
Thanks,
Ray
> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Friday, February 10, 2023 7:24 PM
> To: Wu, Jiaxin <jiaxin.wu@intel.com>
> Cc: devel@edk2.groups.io; Dong, Eric <eric.dong@intel.com>; Ni, Ray
> <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Laszlo Ersek
> <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>
> Subject: Re: [PATCH v4 2/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base HOB
> Data
>
> Hi,
>
> > +#pragma pack(1)
> > +typedef struct {
> > + ///
> > + /// CpuIndex tells which CPU range this specific HOB instance described.
> > + /// If CpuIndex is set to 0, it indicats the HOB describes the CPU from 0 to
> > + /// NumberOfCpus - 1. The HOB list may contains multiple this HOB
> instances.
> > + /// Each HOB instances describe the information for CPU from CpuIndex to
> > + /// CpuIndex + NumberOfCpus - 1. The instance order in the HOB list is
> random
> > + /// so consumer can not assume the CpuIndex of first instance is 0.
> > + ///
> > + UINT32 CpuIndex;
> > + ///
> > + /// Describes the Number of all max supported processors.
> > + ///
> > + UINT32 NumberOfProcessors;
> > + ///
> > + /// Pointer to SmBase address for each Processors.
> > + ///
> > + UINT64 SmBase[1];
> > +} SMM_BASE_HOB_DATA;
> > +#pragma pack()
>
> No generic chunked hobs as suggested/discussed on v3 of this series?
> Why not?
>
> take care,
> Gerd
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99980): https://edk2.groups.io/g/devel/message/99980
Mute This Topic: https://groups.io/mt/96871372/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On Fri, Feb 10, 2023 at 11:56:01AM +0000, Ni, Ray wrote: > Gerd, > That requires changing PI spec Yes, but we have https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Code-First-Process > and all HOB consuming logic. There is no need to change the existing logic. Code to handle chunked HOBs can go to new helper functions in HobLib. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100001): https://edk2.groups.io/g/devel/message/100001 Mute This Topic: https://groups.io/mt/96871372/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Gerd, Firstly, chunk idea allows to split the >64K hob to multiple one without using domain knowledge, that means the split can happen in byte level. It will hurt debuggability a lot: When I exam the HOB list during debugging, it's hard to combine/group the chunk hobs with the same GUID into >64K big hobs. Secondly, Code-First process requires the code be created in edk2-staging repo. It means the code cannot be merged in edk2 trunk. I would like to collect more use cases for >64K hobs and if more such hobs are needed from different domains (not just CPU), I will consider to use the chunk idea. Thanks, Ray > -----Original Message----- > From: Gerd Hoffmann <kraxel@redhat.com> > Sent: Friday, February 10, 2023 8:32 PM > To: Ni, Ray <ray.ni@intel.com> > Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; devel@edk2.groups.io; Dong, Eric > <eric.dong@intel.com>; Zeng, Star <star.zeng@intel.com>; Laszlo Ersek > <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com> > Subject: Re: [PATCH v4 2/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base HOB > Data > > On Fri, Feb 10, 2023 at 11:56:01AM +0000, Ni, Ray wrote: > > Gerd, > > That requires changing PI spec > > Yes, but we have > https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Code-First- > Process > > > and all HOB consuming logic. > > There is no need to change the existing logic. Code to handle > chunked HOBs can go to new helper functions in HobLib. > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100014): https://edk2.groups.io/g/devel/message/100014 Mute This Topic: https://groups.io/mt/96871372/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Combine the situation, I prefer the case by case handling to simplify the patch series purpose for the smbase pre-relocation support. Thanks, Jiaxin > -----Original Message----- > From: Ni, Ray <ray.ni@intel.com> > Sent: Friday, February 10, 2023 9:13 PM > To: Gerd Hoffmann <kraxel@redhat.com> > Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; devel@edk2.groups.io; Dong, Eric > <eric.dong@intel.com>; Zeng, Star <star.zeng@intel.com>; Laszlo Ersek > <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Zimmer, > Vincent <vincent.zimmer@intel.com> > Subject: RE: [PATCH v4 2/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base > HOB Data > > Gerd, > Firstly, chunk idea allows to split the >64K hob to multiple one without using > domain knowledge, that means the split can happen in byte level. It will hurt > debuggability a lot: When I exam the HOB list during debugging, it's hard to > combine/group the chunk hobs with the same GUID into >64K big hobs. > > Secondly, Code-First process requires the code be created in edk2-staging > repo. > It means the code cannot be merged in edk2 trunk. > > I would like to collect more use cases for >64K hobs and > if more such hobs are needed from different domains (not just CPU), I will > consider to use the chunk idea. > > Thanks, > Ray > > > -----Original Message----- > > From: Gerd Hoffmann <kraxel@redhat.com> > > Sent: Friday, February 10, 2023 8:32 PM > > To: Ni, Ray <ray.ni@intel.com> > > Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; devel@edk2.groups.io; Dong, Eric > > <eric.dong@intel.com>; Zeng, Star <star.zeng@intel.com>; Laszlo Ersek > > <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com> > > Subject: Re: [PATCH v4 2/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base > HOB > > Data > > > > On Fri, Feb 10, 2023 at 11:56:01AM +0000, Ni, Ray wrote: > > > Gerd, > > > That requires changing PI spec > > > > Yes, but we have > > https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Code-First- > > Process > > > > > and all HOB consuming logic. > > > > There is no need to change the existing logic. Code to handle > > chunked HOBs can go to new helper functions in HobLib. > > > > take care, > > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100050): https://edk2.groups.io/g/devel/message/100050 Mute This Topic: https://groups.io/mt/96871372/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Jiaxin, > + /// > + /// Pointer to SmBase address for each Processors. > + /// > + UINT64 SmBase[1]; Why SmBase[1] instead of SmBase[0]? I think using SmBase[0] can better help C code to calculate the HOB size. Simply sizeof (SMM_BASE_HOB_DATA) * sizeof (UINT64) * CpuCount, instead of sizeof (SMM_BASE_HOB_DATA) * sizeof (UINT64) * (CpuCount - 1). -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99963): https://edk2.groups.io/g/devel/message/99963 Mute This Topic: https://groups.io/mt/96871372/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Hi Ray, Both is fine to me, one thought is that we must have one CPU, so change to 1 and I also checked some existing usage cases like the EFI_SMRAM_HOB_DESCRIPTOR_BLOCK.Descriptor, WIN_CERTIFICATE_UEFI_GUID. CertData, it also the same way. Thanks, Jiaxin > -----Original Message----- > From: Ni, Ray <ray.ni@intel.com> > Sent: Friday, February 10, 2023 3:15 PM > To: Wu, Jiaxin <jiaxin.wu@intel.com>; devel@edk2.groups.io > Cc: Dong, Eric <eric.dong@intel.com>; Zeng, Star <star.zeng@intel.com>; > Laszlo Ersek <lersek@redhat.com>; Gerd Hoffmann <kraxel@redhat.com>; > Kumar, Rahul R <rahul.r.kumar@intel.com> > Subject: RE: [PATCH v4 2/5] UefiCpuPkg/SmmBaseHob.h: Add SMM Base > HOB Data > > Jiaxin, > > + /// > > + /// Pointer to SmBase address for each Processors. > > + /// > > + UINT64 SmBase[1]; > > Why SmBase[1] instead of SmBase[0]? > I think using SmBase[0] can better help C code to calculate the HOB size. > Simply sizeof (SMM_BASE_HOB_DATA) * sizeof (UINT64) * CpuCount, > instead of sizeof (SMM_BASE_HOB_DATA) * sizeof (UINT64) * (CpuCount - > 1). > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99964): https://edk2.groups.io/g/devel/message/99964 Mute This Topic: https://groups.io/mt/96871372/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.