Re: [edk2-devel] [Patch 1/3] NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg
Reviewed-by: Jiaxin Wu > -Original Message- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Liming Gao > Sent: Wednesday, May 15, 2019 8:02 PM > To: devel@edk2.groups.io > Cc: Fu, Siyuan ; Wu, Jiaxin > Subject: [edk2-devel] [Patch 1/3] NetworkPkg: Move Network library and > drivers from MdeModulePkg to NetworkPkg > > Signed-off-by: Liming Gao > Cc: Siyuan Fu > Cc: Jiaxin Wu > --- > .../Network => NetworkPkg}/ArpDxe/ArpDriver.c | 0 > .../Universal/Network => NetworkPkg}/ArpDxe/ArpImpl.c | 0 > .../Universal/Network => NetworkPkg}/ArpDxe/ArpMain.c | 0 > .../Network => NetworkPkg}/ArpDxe/ComponentName.c | 0 > .../Network => NetworkPkg}/Dhcp4Dxe/ComponentName.c| 0 > .../Network => NetworkPkg}/Dhcp4Dxe/Dhcp4Driver.c | 0 > .../Network => NetworkPkg}/Dhcp4Dxe/Dhcp4Impl.c| 0 > .../Network => NetworkPkg}/Dhcp4Dxe/Dhcp4Io.c | 0 > .../Network => NetworkPkg}/Dhcp4Dxe/Dhcp4Option.c | 0 > .../Universal/Network => NetworkPkg}/DpcDxe/Dpc.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/ComponentName.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Common.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Config2Impl.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Config2Nv.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Driver.c | 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4Icmp.c | 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4If.c| 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4Igmp.c | 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4Impl.c | 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4Input.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Option.c | 0 > .../Network => NetworkPkg}/Ip4Dxe/Ip4Output.c | 0 > .../Universal/Network => NetworkPkg}/Ip4Dxe/Ip4Route.c | 0 > .../Library/DxeDpcLib/DpcLib.c | 0 > .../Library/DxeHttpLib/DxeHttpLib.c| 0 > .../Library/DxeIpIoLib/DxeIpIoLib.c| 0 > .../Library/DxeNetLib/DxeNetLib.c | 0 > .../Library/DxeNetLib/NetBuffer.c | 0 > .../Library/DxeTcpIoLib/DxeTcpIoLib.c | 0 > .../Library/DxeUdpIoLib/DxeUdpIoLib.c | 0 > .../Network => NetworkPkg}/MnpDxe/ComponentName.c | 0 > .../Network => NetworkPkg}/MnpDxe/MnpConfig.c | 0 > .../Network => NetworkPkg}/MnpDxe/MnpDriver.c | 0 > .../Universal/Network => NetworkPkg}/MnpDxe/MnpIo.c| 0 > .../Universal/Network => NetworkPkg}/MnpDxe/MnpMain.c | 0 > .../Universal/Network => NetworkPkg}/MnpDxe/MnpVlan.c | 0 > .../Network => NetworkPkg}/Mtftp4Dxe/ComponentName.c | 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Driver.c| 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Impl.c | 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Option.c| 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Rrq.c | 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Support.c | 0 > .../Network => NetworkPkg}/Mtftp4Dxe/Mtftp4Wrq.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Callback.c | 0 > .../Network => NetworkPkg}/SnpDxe/ComponentName.c | 0 > .../Network => NetworkPkg}/SnpDxe/Get_status.c | 0 > .../Network => NetworkPkg}/SnpDxe/Initialize.c | 0 > .../Network => NetworkPkg}/SnpDxe/Mcast_ip_to_mac.c| 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Nvdata.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Receive.c | 0 > .../Network => NetworkPkg}/SnpDxe/Receive_filters.c| 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Reset.c| 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Shutdown.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Snp.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Start.c| 0 > .../Network => NetworkPkg}/SnpDxe/Station_address.c| 0 > .../Network => NetworkPkg}/SnpDxe/Statistics.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Stop.c | 0 > .../Universal/Network => NetworkPkg}/SnpDxe/Transmit.c | 0 > .../Network => NetworkPkg}/SnpDxe/WaitForPacket.c | 0 > .../Network => NetworkPkg}/Udp4Dxe/ComponentName.c | 0 > .../Network => NetworkPkg}/Udp4Dxe/Udp4Driver.c| 0 > .../Network => NetworkPkg}/Udp4Dxe/Udp4Impl.c | 0 > .../Network => NetworkPkg}/Udp4Dxe/Udp4Main.c | 0 > .../VlanConfigDxe/ComponentName.c | 0 > .../VlanConfigDxe/VlanConfigDriver.c |
Re: [edk2-devel] [Patch 2/3] NetworkPkg: Move Network library header file from MdeModulePkg to NetworkPkg
Reviewed-by: Jiaxin Wu > -Original Message- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Liming Gao > Sent: Wednesday, May 15, 2019 8:02 PM > To: devel@edk2.groups.io > Cc: Fu, Siyuan ; Wu, Jiaxin > Subject: [edk2-devel] [Patch 2/3] NetworkPkg: Move Network library header > file from MdeModulePkg to NetworkPkg > > Signed-off-by: Liming Gao > Cc: Siyuan Fu > Cc: Jiaxin Wu > --- > NetworkPkg/Application/VConfig/VConfig.inf | 1 + > NetworkPkg/ArpDxe/ArpDxe.inf | 1 + > NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf | 1 + > NetworkPkg/DnsDxe/DnsDxe.inf | 1 + > NetworkPkg/DpcDxe/DpcDxe.inf | 1 + > NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf | 1 + > .../Include/Library/DpcLib.h | 0 > .../Include/Library/HttpLib.h | 0 > .../Include/Library/IpIoLib.h | 0 > .../Include/Library/NetLib.h | 0 > .../Include/Library/TcpIoLib.h | 0 > .../Include/Library/UdpIoLib.h | 0 > NetworkPkg/Ip4Dxe/Ip4Dxe.inf | 1 + > NetworkPkg/Library/DxeDpcLib/DxeDpcLib.inf | 1 + > NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf | 1 + > NetworkPkg/Library/DxeIpIoLib/DxeIpIoLib.inf | 1 + > NetworkPkg/Library/DxeNetLib/DxeNetLib.inf | 1 + > NetworkPkg/Library/DxeTcpIoLib/DxeTcpIoLib.inf | 1 + > NetworkPkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf | 1 + > NetworkPkg/MnpDxe/MnpDxe.inf | 1 + > NetworkPkg/Mtftp4Dxe/Mtftp4Dxe.inf | 1 + > NetworkPkg/Mtftp6Dxe/Mtftp6Dxe.inf | 1 + > NetworkPkg/NetworkPkg.dec | 24 > ++ > NetworkPkg/SnpDxe/SnpDxe.inf | 1 + > NetworkPkg/TcpDxe/TcpDxe.inf | 1 + > NetworkPkg/TlsDxe/TlsDxe.inf | 1 + > NetworkPkg/Udp4Dxe/Udp4Dxe.inf | 1 + > NetworkPkg/Udp6Dxe/Udp6Dxe.inf | 1 + > NetworkPkg/VlanConfigDxe/VlanConfigDxe.inf | 1 + > 29 files changed, 46 insertions(+) > rename {MdeModulePkg => NetworkPkg}/Include/Library/DpcLib.h (100%) > rename {MdeModulePkg => NetworkPkg}/Include/Library/HttpLib.h (100%) > rename {MdeModulePkg => NetworkPkg}/Include/Library/IpIoLib.h (100%) > rename {MdeModulePkg => NetworkPkg}/Include/Library/NetLib.h (100%) > rename {MdeModulePkg => NetworkPkg}/Include/Library/TcpIoLib.h (100%) > rename {MdeModulePkg => NetworkPkg}/Include/Library/UdpIoLib.h > (100%) > > diff --git a/NetworkPkg/Application/VConfig/VConfig.inf > b/NetworkPkg/Application/VConfig/VConfig.inf > index 2e6cd1aef3..1d7a81201e 100644 > --- a/NetworkPkg/Application/VConfig/VConfig.inf > +++ b/NetworkPkg/Application/VConfig/VConfig.inf > @@ -35,6 +35,7 @@ [Sources] > [Packages] >MdePkg/MdePkg.dec >MdeModulePkg/MdeModulePkg.dec > + NetworkPkg/NetworkPkg.dec >ShellPkg/ShellPkg.dec > > [LibraryClasses] > diff --git a/NetworkPkg/ArpDxe/ArpDxe.inf > b/NetworkPkg/ArpDxe/ArpDxe.inf > index 78344edf90..2ff74895a6 100644 > --- a/NetworkPkg/ArpDxe/ArpDxe.inf > +++ b/NetworkPkg/ArpDxe/ArpDxe.inf > @@ -42,6 +42,7 @@ [Sources] > [Packages] >MdePkg/MdePkg.dec >MdeModulePkg/MdeModulePkg.dec > + NetworkPkg/NetworkPkg.dec > > > [LibraryClasses] > diff --git a/NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf > b/NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf > index 62883518b2..e34aab0a6b 100644 > --- a/NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf > +++ b/NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf > @@ -44,6 +44,7 @@ [Sources] > [Packages] >MdePkg/MdePkg.dec >MdeModulePkg/MdeModulePkg.dec > + NetworkPkg/NetworkPkg.dec > > > [LibraryClasses] > diff --git a/NetworkPkg/DnsDxe/DnsDxe.inf > b/NetworkPkg/DnsDxe/DnsDxe.inf > index 6298aadc8c..3a66bdd13a 100644 > --- a/NetworkPkg/DnsDxe/DnsDxe.inf > +++ b/NetworkPkg/DnsDxe/DnsDxe.inf > @@ -21,6 +21,7 @@ [Defines] > [Packages] >MdePkg/MdePkg.dec >MdeModulePkg/MdeModulePkg.dec > + NetworkPkg/NetworkPkg.dec > > [Sources] >ComponentName.c > diff --git a/NetworkPkg/DpcDxe/DpcDxe.inf > b/NetworkPkg/DpcDxe/DpcDxe.inf > index 8c241d7f46..1462de28a2 100644 > --- a/NetworkPkg/DpcDxe/DpcDxe.inf > +++ b/NetworkPkg/DpcDxe/DpcDxe.inf > @@ -29,6 +29,7 @@ [Sources] > [Packages] >MdePkg/MdePkg.dec >MdeModulePkg/MdeModulePkg.dec > + NetworkPkg/NetworkPkg.dec > > [LibraryClasses] >UefiDriverEntryPoint > diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf >
Re: [edk2-devel] [PATCH v1 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg
> From C11 "5.1.2.4 Multi-threaded executions and data races": > > - paragraph 4: "Two expression evaluations conflict if one of them > modifies a memory location and the other one reads or modifies the same > memory location." > > - paragraph 25: "The execution of a program contains a data race if it > contains two conflicting actions in different threads, at least one of > which is not atomic, and neither happens before the other. Any such data > race results in undefined behavior." > > In this case, the outer condition (which reads the volatile UINT32 > object "mSmmMpSyncData->BspIndex") is one access. It is a read access, > and it is not atomic. The other access is the > InterlockedCompareExchange32(). It is a read-write access, and it is > atomic. There is no "happens before" relationship enforced between both > accesses. > > Therefore, this is a data race: the pre-check on one CPU conflicts with > the InterlockedCompareExchange32() on another CPU, the pre-check is not > atomic, and there is no happens-before between them. > > A data race means undefined behavior. In particular, if there is a data > race, then there are no guarantees of sequential consistency, so the > observable values in the object could be totally inexplicable. > I think here data race won't cause the undefined behavior: The read operation in one processor might see the 1) old value (MAX_UINT32) or 2) the new value (CpuIndex), but both behaviors are explicable: If case 1, that's ok continue do the lock comxchg since BspIndex hasn't been elected. If case 2, which means another processor has already atomic invalid or write the BspIndex, then existing processor absolutely can skip the lock comxchg. if (mSmmMpSyncData->BspIndex == MAX_UINT32) { InterlockedCompareExchange32 ( (UINT32 *)&mSmmMpSyncData->BspIndex, MAX_UINT32, (UINT32)CpuIndex ); } > If you consider PiSmmCpuDxeSmm's usage of "volatile" to be "atomic", > then that would remove the data race; but volatile is not necessarily > atomic. > I *never* do the assumption: "volatile" is "atomic". BspIndex is volatile, I think it only can ensure the compiler behavior, not processor itself: 1. Compiler will not optimize this variable. All reads and writes to this variable will be done directly to memory, not using cached values in registers. But it doesn't prevent the CPU from caching that variable in its own internal caches. 2. "volatile" can prevent the compiler from optimizing and reordering instructions, it can't prevent the processor from reordering instructions, and can't guarantee the atomicity of operations. For processor reordering, I think Ray explained that reordering won't happen. > Since you linked a wikipedia article, I'll link three articles that > describe a similar (nearly the same) technique called "double-checked > locking". In the general case, that technique is broken. > > http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking. > html > https://en.wikipedia.org/wiki/Double-checked_locking > https://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/ > > It can be made work in bare-bones C, but it requires explicit fences / > memory barriers. Here, the case is different to the above three "Double-checked locking". Cache coherency can make sure the read value for check is only 2 cases as I explained above. The only possible impact is the AP behavior: AP won't pending on lock comxchg, while it will continue do the following code logic after if check: for example performs the APHandler. But it won't has the negative-impact since it has the timeout BSP check in APHandler. And even failure of that, we still has the error handling to sync out the existing AP due to don't know the BSP: SmmCpuSyncCheckOutCpu (mSmmMpSyncData->SyncContext, CpuIndex); return; Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115618): https://edk2.groups.io/g/devel/message/115618 Mute This Topic: https://groups.io/mt/104094808/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
Hi Mike, Could you help approval below 2 patches into the stable tag 202402? The patches have been merged. UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg Thanks, Jiaxin > -Original Message- > From: gaoliming > Sent: Thursday, February 22, 2024 10:48 PM > To: Wu, Jiaxin > Subject: 回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization > > Jiaxin: > I see you merge this patch set in hard freeze. If you want this patch set > to catch this stable tag 202402, you need to reply the mail in mail list and > get the stewards approval. If this patch set is not to catch this stable > tag, I will not include it in this stable tag. > > Thanks > Liming > > -----邮件原件----- > > 发件人: devel@edk2.groups.io 代表 Wu, Jiaxin > > 发送时间: 2024年2月6日 15:58 > > 收件人: devel@edk2.groups.io > > 主题: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization > > > > In V3 patch set, drop the patch to update the CheckFeatureSupported. > > > > The new patch set only focus on the BspIndex refinement. > > > > Jiaxin Wu (2): > > UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting > > UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg > > > > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 22 -- > > 1 file changed, 12 insertions(+), 10 deletions(-) > > > > -- > > 2.16.2.windows.1 > > > > > > > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115862): https://edk2.groups.io/g/devel/message/115862 Mute This Topic: https://groups.io/mt/104194203/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
Talked with Di & Liming, Those 2 patches don't need to catch this stable tag 202402. Please ignore the request here. Thanks, Jiaxin > -Original Message----- > From: Wu, Jiaxin > Sent: Friday, February 23, 2024 8:47 AM > To: gaoliming ; Kinney, Michael D > > Cc: devel@edk2.groups.io > Subject: RE: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization > > Hi Mike, > > Could you help approval below 2 patches into the stable tag 202402? The > patches have been merged. > > UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting > UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg > > > Thanks, > Jiaxin > > > > -Original Message- > > From: gaoliming > > Sent: Thursday, February 22, 2024 10:48 PM > > To: Wu, Jiaxin > > Subject: 回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization > > > > Jiaxin: > > I see you merge this patch set in hard freeze. If you want this patch set > > to catch this stable tag 202402, you need to reply the mail in mail list and > > get the stewards approval. If this patch set is not to catch this stable > > tag, I will not include it in this stable tag. > > > > Thanks > > Liming > > > -邮件原件- > > > 发件人: devel@edk2.groups.io 代表 Wu, Jiaxin > > > 发送时间: 2024年2月6日 15:58 > > > 收件人: devel@edk2.groups.io > > > 主题: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization > > > > > > In V3 patch set, drop the patch to update the CheckFeatureSupported. > > > > > > The new patch set only focus on the BspIndex refinement. > > > > > > Jiaxin Wu (2): > > > UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting > > > UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock > cmpxchg > > > > > > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 22 > -- > > > 1 file changed, 12 insertions(+), 10 deletions(-) > > > > > > -- > > > 2.16.2.windows.1 > > > > > > > > > > > > > > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115867): https://edk2.groups.io/g/devel/message/115867 Mute This Topic: https://groups.io/mt/104194203/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 0/2] SMM MP service performance Improvement
The series patch are to improve the SMM MP service performance. Cc: Ray Ni Cc: Laszlo Ersek Cc: Eric Dong Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Jiaxin Wu (2): UefiCpuPkg/PiSmmCpuDxeSmm: Remove one round of Busy spinlock UefiCpuPkg/PiSmmCpuDxeSmm: Make RunningApCount on exclusive cacheline UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 50 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +- 2 files changed, 23 insertions(+), 29 deletions(-) -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116433): https://edk2.groups.io/g/devel/message/116433 Mute This Topic: https://groups.io/mt/104764103/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 1/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove one round of Busy spinlock
For both non blocking and blocking: Remove unnecessary a pair of AcquireSpinLock and ReleaseSpinLock for each AP. It's target to improve SmmStartupAllAPs performance. No functional impact, see below analysis: During first acquire spinLock, InternalSmmStartupAllAPs will return EFI_NOT_READY if AcquireSpinLockOrFail return false: if (!AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[Index].Busy)) { return EFI_NOT_READY; } which means the AcquireSpinLockOrFail () must return TRUE if InternalSmmStartupAllAPs () can continue the second round of Busy spinlock. since the Busy has already acquired the spinlock, no need to release and acquire again. Cc: Ray Ni Cc: Laszlo Ersek Cc: Eric Dong Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 15 --- 1 file changed, 15 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 081f0c1501..9790b4f888 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1257,12 +1257,10 @@ InternalSmmStartupAllAPs ( } if (!AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[Index].Busy)) { return EFI_NOT_READY; } - - ReleaseSpinLock (mSmmMpSyncData->CpuData[Index].Busy); } } if (CpuCount == 0) { return EFI_NOT_STARTED; @@ -1273,23 +1271,10 @@ InternalSmmStartupAllAPs ( *Token= (MM_COMPLETION)ProcToken->SpinLock; } else { ProcToken = NULL; } - // - // Make sure all BUSY should be acquired. - // - // Because former code already check mSmmMpSyncData->CpuData[***].Busy for each AP. - // Here code always use AcquireSpinLock instead of AcquireSpinLockOrFail for not - // block mode. - // - for (Index = 0; Index < mMaxNumberOfCpus; Index++) { -if (IsPresentAp (Index)) { - AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy); -} - } - for (Index = 0; Index < mMaxNumberOfCpus; Index++) { if (IsPresentAp (Index)) { mSmmMpSyncData->CpuData[Index].Procedure = (EFI_AP_PROCEDURE2)Procedure; mSmmMpSyncData->CpuData[Index].Parameter = ProcedureArguments; if (ProcToken != NULL) { -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116434): https://edk2.groups.io/g/devel/message/116434 Mute This Topic: https://groups.io/mt/104764104/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Make RunningApCount on exclusive cacheline
For non blocking mode during SmmMpBroadcastProcedure, multiple APs might contended access the RunningApCount in the PROCEDURE_TOKEN: Step1: RunningApCount is initialized to the mMaxNumberOfCpus (See GetFreeToken). Step2: Decrease RunningApCount if the AP is not present (See InterlockedDecrement in InternalSmmStartupAllAPs). Step3: multiple APs are contended to decrease RunningApCount in the same token (See ReleaseToken in APHandler). So, Contended lock case happen during Step3. For multiple APs access the shared memory (RunningApCount), we shall use exclusive cache line with WB attribute for SMM Performance Tuning. This patch makes RunningApCount on exclusive cacheline. Cc: Ray Ni Cc: Laszlo Ersek Cc: Eric Dong Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 35 +++--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 9790b4f888..05fa6854fe 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -421,11 +421,11 @@ ReleaseToken ( { PROCEDURE_TOKEN *Token; Token = mSmmMpSyncData->CpuData[CpuIndex].Token; - if (InterlockedDecrement (&Token->RunningApCount) == 0) { + if (InterlockedDecrement (Token->RunningApCount) == 0) { ReleaseSpinLock (Token->SpinLock); } mSmmMpSyncData->CpuData[CpuIndex].Token = NULL; } @@ -970,12 +970,12 @@ AllocateTokenBuffer ( ) { UINTNSpinLockSize; UINT32 TokenCountPerChunk; UINTNIndex; - SPIN_LOCK*SpinLock; - UINT8*SpinLockBuffer; + UINTNBufferAddr; + VOID *Buffer; PROCEDURE_TOKEN *ProcTokens; SpinLockSize = GetSpinLockProperties (); TokenCountPerChunk = FixedPcdGet32 (PcdCpuSmmMpTokenCountPerChunk); @@ -986,25 +986,34 @@ AllocateTokenBuffer ( } DEBUG ((DEBUG_INFO, "CpuSmm: SpinLock Size = 0x%x, PcdCpuSmmMpTokenCountPerChunk = 0x%x\n", SpinLockSize, TokenCountPerChunk)); // - // Separate the Spin_lock and Proc_token because the alignment requires by Spin_Lock. + // Allocate the buffer for SpinLock and RunningApCount to meet the alignment requirement. // - SpinLockBuffer = AllocatePool (SpinLockSize * TokenCountPerChunk); - ASSERT (SpinLockBuffer != NULL); + Buffer = AllocatePages (EFI_SIZE_TO_PAGES (SpinLockSize * TokenCountPerChunk * 2)); + if (Buffer == NULL) { +DEBUG ((DEBUG_ERROR, "AllocateTokenBuffer: Failed to allocate the buffer for SpinLock and RunningApCount!\n")); +CpuDeadLoop (); + } ProcTokens = AllocatePool (sizeof (PROCEDURE_TOKEN) * TokenCountPerChunk); ASSERT (ProcTokens != NULL); + BufferAddr = (UINTN)Buffer; for (Index = 0; Index < TokenCountPerChunk; Index++) { -SpinLock = (SPIN_LOCK *)(SpinLockBuffer + SpinLockSize * Index); -InitializeSpinLock (SpinLock); +ProcTokens[Index].Signature = PROCEDURE_TOKEN_SIGNATURE; + +ProcTokens[Index].SpinLock = (SPIN_LOCK *)BufferAddr; +InitializeSpinLock (ProcTokens[Index].SpinLock); + +BufferAddr += SpinLockSize; + +ProcTokens[Index].RunningApCount = (volatile UINT32 *)BufferAddr; +*ProcTokens[Index].RunningApCount = 0; -ProcTokens[Index].Signature = PROCEDURE_TOKEN_SIGNATURE; -ProcTokens[Index].SpinLock = SpinLock; -ProcTokens[Index].RunningApCount = 0; +BufferAddr += SpinLockSize; InsertTailList (&gSmmCpuPrivate->TokenList, &ProcTokens[Index].Link); } return &ProcTokens[0].Link; @@ -1036,11 +1045,11 @@ GetFreeToken ( } NewToken = PROCEDURE_TOKEN_FROM_LINK (gSmmCpuPrivate->FirstFreeToken); gSmmCpuPrivate->FirstFreeToken = GetNextNode (&gSmmCpuPrivate->TokenList, gSmmCpuPrivate->FirstFreeToken); - NewToken->RunningApCount = RunningApsCount; + *NewToken->RunningApCount = RunningApsCount; AcquireSpinLock (NewToken->SpinLock); return NewToken; } @@ -1298,11 +1307,11 @@ InternalSmmStartupAllAPs ( // // Decrease the count to mark this processor(AP or BSP) as finished. // if (ProcToken != NULL) { -InterlockedDecrement (&ProcToken->RunningApCount); +InterlockedDecrement (ProcToken->RunningApCount); } } } ReleaseAllAPs (); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 7f244ea803..07473208fd 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -213,11 +213,11 @@ typedef struct { typedef struct { UINTN Signature; LIST_ENTRY Link; SPIN_LOCK *SpinLock; - volatile UINT32RunningApCount; + volatile UINT32*RunningApCount; } PROCEDURE_TOKEN; #define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, L
[edk2-devel] OVMF SMM Support
Hi Gerd, With below OVMF build and QEMU command, OVMF hangs after SendSmiIpi (mBspApicId) during SmmRelocateBases(), is there any issues with latest code to support SMM on OVMF or my local command/configuration issue? Build (latest edk2 code): build -p OvmfPkg\OvmfPkgIa32X64.dsc -a IA32 -a X64 -D SECURE_BOOT -D SMM_REQUIRE -D DEBUG_ON_SERIAL_PORT QEMU command (QEMU version: 8.2.0): qemu-system-x86_64 -machine q35,smm=on -m 4G -net none -drive if=pflash,format=raw,unit=0,file=C:\Dev\Code\edk2\Build\Ovmf3264\DEBUG_VS2019\FV\OVMF_CODE.fd,readonly=on -drive if=pflash,format=raw,unit=1,file=C:\Dev\Code\edk2\Build\Ovmf3264\DEBUG_VS2019\FV\OVMF_VARS.fd -hda fat:rw:hda-contents -serial file:log.log Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117493): https://edk2.groups.io/g/devel/message/117493 Mute This Topic: https://groups.io/mt/105397533/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] OVMF SMM Support
Thank you Michael & Gerd, it does the problem of https://gitlab.com/qemu-project/qemu/-/issues/2064. The issue is gone with latest QEMU version. Thanks, Jiaxin > -Original Message- > From: Michael Kubacki > Sent: Tuesday, April 9, 2024 8:55 AM > To: devel@edk2.groups.io; Wu, Jiaxin ; Gerd Hoffmann > > Subject: Re: [edk2-devel] OVMF SMM Support > > Might be related to this issue > https://gitlab.com/qemu-project/qemu/-/issues/2064. > > On 4/8/2024 4:33 AM, Wu, Jiaxin wrote: > > Hi Gerd, > > > > With below OVMF build and QEMU command, OVMF hangs after > SendSmiIpi > > (mBspApicId) during SmmRelocateBases(), is there any issues with latest > > code to support SMM on OVMF or my local command/configuration issue? > > > > *Build (latest edk2 code):* > > > > build -p OvmfPkg\OvmfPkgIa32X64.dsc -a IA32 -a X64 -D SECURE_BOOT -D > > SMM_REQUIRE -D DEBUG_ON_SERIAL_PORT > > > > *QEMU command (QEMU version: 8.2.0):* > > > > qemu-system-x86_64 -machine q35,smm=on -m 4G -net none -drive > > > if=pflash,format=raw,unit=0,file=C:\Dev\Code\edk2\Build\Ovmf3264\DEBUG > _VS2019\FV\OVMF_CODE.fd,readonly=on -drive > if=pflash,format=raw,unit=1,file=C:\Dev\Code\edk2\Build\Ovmf3264\DEBUG > _VS2019\FV\OVMF_VARS.fd -hda fat:rw:hda-contents -serial file:log.log > > > > Thanks, > > > > Jiaxin > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117527): https://edk2.groups.io/g/devel/message/117527 Mute This Topic: https://groups.io/mt/105397533/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 00/13] Add SmmRelocationLib
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ard Biesheuvel Cc: Jiewen Yao Signed-off-by: Jiaxin Wu Jiaxin Wu (13): UefiCpuPkg: Add SmmRelocationLib class UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF UefiCpuPkg/SmmRelocationLib: Add library instance for AMD UefiCpuPkg/UefiCpuPkg.dsc: Include SmmRelocationLib in UefiCpuPkg UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib OvmfPkg: Include SmmRelocationLib in OvmfPkg OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg/SmmAccess: Consume gEfiSmmSmramMemoryGuid OvmfPkg/PlatformInitLib: Create gEfiAcpiVariableGuid OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/Platform.c | 1 + OvmfPkg/PlatformPei/Platform.h | 5 + OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +-- OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- OvmfPkg/SmmAccess/SmramInternal.h | 18 +- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ .../SmmRelocationLib/AmdSmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 109 .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 157 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 141 + .../SmmRelocationLib/OvmfSmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/OvmfSmramSaveStateConfig.c| 107 .../Library/SmmRelocationLib/SmmRelocationLib.c| 659 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/SmramSaveStateConfig.c| 91 +++ .../SmmRelocationLib}/X64/Semaphore.c | 13 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 93 ++- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm| 96 --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 6 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 322 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 98 --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 3 + UefiPayloadPkg/UefiPayloadPkg.dsc | 2 + 42 files changed, 1850 insertions(+), 817 deletions(-) create mode 100644 OvmfPkg/PlatformPei/SmmRelocation.c create mode 100644 UefiCpuPkg/Include/Library/SmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c rename UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/Semaphore.c (72%) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/OvmfSmramSaveStateConfig.c create mode 100644 UefiCpuPkg/Libr
[edk2-devel] [PATCH v1 01/13] UefiCpuPkg: Add SmmRelocationLib class
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) shall: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. This patch just provides the SmmRelocationLib class. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 +++ UefiCpuPkg/UefiCpuPkg.dec | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmRelocationLib.h diff --git a/UefiCpuPkg/Include/Library/SmmRelocationLib.h b/UefiCpuPkg/Include/Library/SmmRelocationLib.h new file mode 100644 index 00..13043641a2 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmRelocationLib.h @@ -0,0 +1,42 @@ +/** @file + Header file for SMM Relocation Library. + + The SmmRelocationLib class provides the SmmRelocationInit() + interface for platform to do the smbase relocation, which + shall provide below 2 functionalities: + 1. Relocate SmBases for each processor. + 2. Create the SmBase HOB (gSmmBaseHobGuid). + + With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) + shall: + 1. Consume the gSmmBaseHobGuid for the relocated smbase for each Processor. + 2. Execute early SMM init. + + Copyright (c) 2023, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_RELOCATION_LIB_H_ +#define SMM_RELOCATION_LIB_H_ + +#include + +/** + CPU SmmBase Relocation Init. + + This function is to relocate CPU SmmBase. + + @param[in] MpServices2Pointer to this instance of the MpServices. + + @retval EFI_SUCCESS CPU SmmBase Relocated successfully. + @retval OthersCPU SmmBase Relocation failed. + +**/ +EFI_STATUS +EFIAPI +SmmRelocationInit ( + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2 + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 571b59b36f..1d7890f19e 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -65,10 +65,13 @@ MmSaveStateLib|Include/Library/MmSaveStateLib.h ## @libraryclass Provides functions for SMM CPU Sync Operation. SmmCpuSyncLib|Include/Library/SmmCpuSyncLib.h + ## @libraryclass Provides functions for SMM Relocation Operation. + SmmRelocationLib|Include/Library/SmmRelocationLib.h + [LibraryClasses.RISCV64] ## @libraryclass Provides functions to manage MMU features on RISCV64 CPUs. ## RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117589): https://edk2.groups.io/g/devel/message/117589 Mute This Topic: https://groups.io/mt/105441988/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF
Due to the definition difference of SMRAM Save State, SmmBase config in SMRAM Save State for OVMF is also different. This patch provides the OvmfSmmRelocationLib library instance to handle the SMRAM Save State difference. Cc: Ray Ni Cc: Zeng Star Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../SmmRelocationLib/OvmfSmmRelocationLib.inf | 61 .../SmmRelocationLib/OvmfSmramSaveStateConfig.c| 107 + 2 files changed, 168 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/OvmfSmramSaveStateConfig.c diff --git a/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf b/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf new file mode 100644 index 00..eba1129ac2 --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf @@ -0,0 +1,61 @@ +## @file +# SMM Relocation Lib for each processor. +# +# This Lib produces the SMM_BASE_HOB in HOB database which tells +# the PiSmmCpuDxeSmm driver (runs at a later phase) about the new +# SMBASE for each processor. PiSmmCpuDxeSmm driver installs the +# SMI handler at the SMM_BASE_HOB.SmBase[Index]+0x8000 for processor +# Index. +# +# Copyright (c) 2024, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION= 0x00010005 + BASE_NAME = SmmRelocationLib + FILE_GUID = 51834F51-CCE0-4743-B553-935D0C8A53FF + MODULE_TYPE= PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = SmmRelocationLib + +[Sources] + InternalSmmRelocationLib.h + OvmfSmramSaveStateConfig.c + SmmRelocationLib.c + +[Sources.Ia32] + Ia32/Semaphore.c + Ia32/SmmInit.nasm + +[Sources.X64] + X64/Semaphore.c + X64/SmmInit.nasm + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + CpuExceptionHandlerLib + DebugLib + HobLib + LocalApicLib + MemoryAllocationLib + PcdLib + PeiServicesLib + +[Guids] + gSmmBaseHobGuid ## HOB ALWAYS_PRODUCED + gEfiSmmSmramMemoryGuid## CONSUMES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize ## CONSUMES + +[FeaturePcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugSupport## CONSUMES diff --git a/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmramSaveStateConfig.c b/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmramSaveStateConfig.c new file mode 100644 index 00..505b1d694a --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/OvmfSmramSaveStateConfig.c @@ -0,0 +1,107 @@ +/** @file + Config SMRAM Save State for SmmBases Relocation. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include "InternalSmmRelocationLib.h" +#include + +/** + This function configures the SmBase on the currently executing CPU. + + @param[in] CpuIndex The index of the CPU. + @param[in,out] CpuState Pointer to SMRAM Save State Map for the + currently executing CPU. On out, SmBase is + updated to the new value. + +**/ +VOID +EFIAPI +ConfigureSmBase ( + IN UINTN CpuIndex, + IN OUT SMRAM_SAVE_STATE_MAP *CpuState + ) +{ + AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState; + + CpuSaveState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState; + + if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { +CpuSaveState->x86.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; + } else { +CpuSaveState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; + } +} + +/** + This function updates the SMRAM save state on the currently executing CPU + to resume execution at a specific address after an RSM instruction. This + function must evaluate the SMRAM save state to determine the execution mode + the RSM instruction resumes and update the resume execution address with + either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart + flag in the SMRAM save state must always be cleared. This function returns + the value of the instruction pointer from the SMRAM save state that was + replaced. If this function returns 0, then the SMRAM save state was not + modified. + + This function is called during the very first SMI on each CPU after + SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode + to signal that the SMBASE of each CPU has been updated before the default + SMBASE address is used for the first SMI to the next CPU. + + @param[in] CpuIndex The processor index for the currently +
[edk2-devel] [PATCH v1 02/13] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance
This patch separates the smbase relocation logic from PiSmmCpuDxeSmm driver, and moves to the SmmRelocationInit interface. Platform shall consume the interface for the smbase relocation if need SMM support. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/Ia32/Semaphore.c | 43 ++ .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 157 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 141 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 659 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/SmramSaveStateConfig.c| 91 +++ .../Library/SmmRelocationLib/X64/Semaphore.c | 70 +++ .../Library/SmmRelocationLib/X64/SmmInit.nasm | 207 +++ 8 files changed, 1429 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/X64/SmmInit.nasm diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c new file mode 100644 index 00..ace3221cfc --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -0,0 +1,43 @@ +/** @file + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalSmmRelocationLib.h" + +UINTN mSmmRelocationOriginalAddress; +volatile BOOLEAN *mRebasedFlag; + +/** + Hook return address of SMM Save State so that semaphore code + can be executed immediately after AP exits SMM to indicate to + the BSP that an AP has exited SMM after SMBASE relocation. + + @param[in] CpuIndex The processor index. + @param[in] RebasedFlag A pointer to a flag that is set to TRUE + immediately after AP exits SMM. + +**/ +VOID +SemaphoreHook ( + IN UINTN CpuIndex, + IN volatile BOOLEAN *RebasedFlag + ) +{ + SMRAM_SAVE_STATE_MAP *CpuState; + + mRebasedFlag = RebasedFlag; + + CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); + + mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( + CpuIndex, + CpuState, + (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, + (UINT64)(UINTN)&SmmRelocationSemaphoreComplete + ); +} diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm new file mode 100644 index 00..cb8b030693 --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -0,0 +1,157 @@ +;-- ; +; Copyright (c) 2024, Intel Corporation. All rights reserved. +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; SmmInit.nasm +; +; Abstract: +; +; Functions for relocating SMBASE's for all processors +; +;--- + +%include "StuffRsbNasm.inc" + +global ASM_PFX(gcSmiIdtr) +global ASM_PFX(gcSmiGdtr) + +extern ASM_PFX(SmmInitHandler) +extern ASM_PFX(mRebasedFlag) +extern ASM_PFX(mSmmRelocationOriginalAddress) + +global ASM_PFX(gPatchSmmCr3) +global ASM_PFX(gPatchSmmCr4) +global ASM_PFX(gPatchSmmCr0) +global ASM_PFX(gPatchSmmInitStack) +global ASM_PFX(gcSmmInitSize) +global ASM_PFX(gcSmmInitTemplate) + +%define PROTECT_MODE_CS 0x8 +%define PROTECT_MODE_DS 0x20 + +SECTION .data + +NullSeg: DQ 0 ; reserved by architecture +CodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeCodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeSsSeg32: +DW -1
[edk2-devel] [PATCH v1 04/13] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD
Due to the definition difference of SMRAM Save State, SmmBase config in SMRAM Save State for AMD is also different. This patch provides the AmdSmmRelocationLib library instance to handle the SMRAM Save State difference. Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../SmmRelocationLib/AmdSmmRelocationLib.inf | 61 .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 109 + 2 files changed, 170 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c diff --git a/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf new file mode 100644 index 00..710cd1948b --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf @@ -0,0 +1,61 @@ +## @file +# SMM Relocation Lib for each processor. +# +# This Lib produces the SMM_BASE_HOB in HOB database which tells +# the PiSmmCpuDxeSmm driver (runs at a later phase) about the new +# SMBASE for each processor. PiSmmCpuDxeSmm driver installs the +# SMI handler at the SMM_BASE_HOB.SmBase[Index]+0x8000 for processor +# Index. +# +# Copyright (c) 2024, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION= 0x00010005 + BASE_NAME = SmmRelocationLib + FILE_GUID = 65C74DCD-0D09-494A-8BFF-A64226EB8054 + MODULE_TYPE= PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = SmmRelocationLib + +[Sources] + InternalSmmRelocationLib.h + AmdSmramSaveStateConfig.c + SmmRelocationLib.c + +[Sources.Ia32] + Ia32/Semaphore.c + Ia32/SmmInit.nasm + +[Sources.X64] + X64/Semaphore.c + X64/SmmInit.nasm + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + CpuExceptionHandlerLib + DebugLib + HobLib + LocalApicLib + MemoryAllocationLib + PcdLib + PeiServicesLib + +[Guids] + gSmmBaseHobGuid ## HOB ALWAYS_PRODUCED + gEfiSmmSmramMemoryGuid## CONSUMES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize ## CONSUMES + +[FeaturePcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugSupport## CONSUMES diff --git a/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c new file mode 100644 index 00..fbcf347f9b --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c @@ -0,0 +1,109 @@ +/** @file + Config SMRAM Save State for SmmBases Relocation. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include "InternalSmmRelocationLib.h" +#include + +/** + This function configures the SmBase on the currently executing CPU. + + @param[in] CpuIndex The index of the CPU. + @param[in,out] CpuState Pointer to SMRAM Save State Map for the + currently executing CPU. On out, SmBase is + updated to the new value. + +**/ +VOID +EFIAPI +ConfigureSmBase ( + IN UINTN CpuIndex, + IN OUT SMRAM_SAVE_STATE_MAP *CpuState + ) +{ + AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState; + + AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState; + + if (mSmmSaveStateRegisterLma == EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT) { +AmdCpuState->x86.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; + } else { +AmdCpuState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; + } +} + +/** + This function updates the SMRAM save state on the currently executing CPU + to resume execution at a specific address after an RSM instruction. This + function must evaluate the SMRAM save state to determine the execution mode + the RSM instruction resumes and update the resume execution address with + either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart + flag in the SMRAM save state must always be cleared. This function returns + the value of the instruction pointer from the SMRAM save state that was + replaced. If this function returns 0, then the SMRAM save state was not + modified. + + This function is called during the very first SMI on each CPU after + SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode + to signal that the SMBASE of each CPU has been updated before the default + SMBASE address is used for the first SMI to the next CPU. + + @param[i
[edk2-devel] [PATCH v1 05/13] UefiCpuPkg/UefiCpuPkg.dsc: Include SmmRelocationLib in UefiCpuPkg
This patch just includes SmmRelocationLib in UefiCpuPkg. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/UefiCpuPkg.dsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 10b33594e5..631a850c78 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -194,10 +194,13 @@ UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf } UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf + UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf + UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf + UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf [Components.X64] UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf [Components.RISCV64] -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117593): https://edk2.groups.io/g/devel/message/117593 Mute This Topic: https://groups.io/mt/105441994/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 06/13] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib
This patch just includes SmmRelocationLib in UefiPayloadPkg. Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ray Ni Signed-off-by: Jiaxin Wu --- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 433fb51a56..328b7fd4fe 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -313,10 +313,12 @@ VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf + [LibraryClasses.common] !if $(BOOTSPLASH_IMAGE) SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf !endif -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117594): https://edk2.groups.io/g/devel/message/117594 Mute This Topic: https://groups.io/mt/105441995/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 07/13] OvmfPkg: Include SmmRelocationLib in OvmfPkg
This patch just includes SmmRelocationLib in OvmfPkg. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 6 files changed, 6 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 60e916b4fd..e171f4e89f 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -146,10 +146,11 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index b522fa1059..5d7ec9bbfa 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -163,10 +163,11 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 2c6bb83beb..a8b12a49a3 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -166,10 +166,11 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 713f08764b..03c35a1a72 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -166,10 +166,11 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/OvmfSmmRelocationLib.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 90b15dc270..90a0c08d6d 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -171,10 +171,11 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCod
[edk2-devel] [PATCH v1 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
SmmRelocationLib instance will reserve the memory from gEfiSmmSmramMemoryGuid for the smbase relocation. So, system must produce the gEfiSmmSmramMemoryGuid. This patch is for the OVMF to produce the gEfiSmmSmramMemoryGuid HOB. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 97 +- .../Library/PlatformInitLib/PlatformInitLib.inf| 5 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 7b6e5102ad..8b98256225 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1,9 +1,9 @@ /**@file Memory Detection for Virtual Machines. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved. + Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: MemDetect.c @@ -41,10 +41,12 @@ Module Name: #include #include #include +#include + #define MEGABYTE_SHIFT 20 VOID EFIAPI PlatformQemuUc32BaseInitialization ( @@ -1027,52 +1029,73 @@ PlatformQemuInitializeRam ( // // Determine total memory size available // PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); - if (PlatformInfoHob->BootMode == BOOT_ON_S3_RESUME) { -// -// Create the following memory HOB as an exception on the S3 boot path. + // + // CpuMpPei saves the original contents of the borrowed area in permanent + // PEI RAM, in a backup buffer allocated with the normal PEI services. + // CpuMpPei restores the original contents ("returns" the borrowed area) at + // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before + // transferring control to the OS's wakeup vector in the FACS. + // + // We expect any other PEIMs that "borrow" memory similarly to CpuMpPei to + // restore the original contents. Furthermore, we expect all such PEIMs + // (CpuMpPei included) to claim the borrowed areas by producing memory + // allocation HOBs, and to honor preexistent memory allocation HOBs when + // looking for an area to borrow. + // + QemuInitializeRamBelow1gb (PlatformInfoHob); + + if (PlatformInfoHob->SmmSmramRequire) { +UINT32 TsegSize; +UINTN BufferSize; +UINT8 SmramRanges; +EFI_PEI_HOB_POINTERSHob; +EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + +TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; +PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); +PlatformAddReservedMemoryBaseSizeHob ( + PlatformInfoHob->LowMemory - TsegSize, + TsegSize, + TRUE + ); + +SmramRanges = 2; +BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); + +Hob.Raw = BuildGuidHob ( +&gEfiSmmSmramMemoryGuid, +BufferSize +); +ASSERT (Hob.Raw); + +SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); +SmramHobDescriptorBlock->NumberOfSmmReservedRegions = SmramRanges; + // -// Normally we'd create memory HOBs only on the normal boot path. However, -// CpuMpPei specifically needs such a low-memory HOB on the S3 path as -// well, for "borrowing" a subset of it temporarily, for the AP startup -// vector. +// Create first SMRAM descriptor, which contains data structures used in S3 resume. +// One page is enough for the data structure // -// CpuMpPei saves the original contents of the borrowed area in permanent -// PEI RAM, in a backup buffer allocated with the normal PEI services. -// CpuMpPei restores the original contents ("returns" the borrowed area) at -// End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before -// transferring control to the OS's wakeup vector in the FACS. +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; +SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; + // -// We expect any other PEIMs that "borrow" memory similarly to CpuMpPei to -// restore the original contents. Furthermore, we expect all such PEIMs -// (CpuMpPei included) to claim the borrowed areas by producing memory -// allocation HOBs, and to honor preexistent memory allocation HOBs when -// looking for an area to borrow. +// Create second SMRAM descriptor, which is free and will be used by SMM foundation. // -QemuInitializeRamBelow1gb (PlatformI
[edk2-devel] [PATCH v1 10/13] OvmfPkg/PlatformInitLib: Create gEfiAcpiVariableGuid
This patch is for OVMF to create the gEfiAcpiVariableGuid since it has been removed from the SmmAccess driver. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 9 + OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf | 1 + 2 files changed, 10 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 8b98256225..f451c9d80c 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -41,10 +41,11 @@ Module Name: #include #include #include +#include #include #define MEGABYTE_SHIFT 20 VOID @@ -1050,10 +1051,11 @@ PlatformQemuInitializeRam ( UINT32 TsegSize; UINTN BufferSize; UINT8 SmramRanges; EFI_PEI_HOB_POINTERSHob; EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; +VOID*GuidHob; TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); PlatformAddReservedMemoryBaseSizeHob ( PlatformInfoHob->LowMemory - TsegSize, @@ -1080,10 +1082,17 @@ PlatformQemuInitializeRam ( SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; +// +// Create gEfiAcpiVariableGuid +// +GuidHob = BuildGuidHob (&gEfiAcpiVariableGuid, sizeof (EFI_SMRAM_DESCRIPTOR)); +ASSERT (GuidHob != NULL); +CopyMem (GuidHob, &SmramHobDescriptorBlock->Descriptor[0], sizeof (EFI_SMRAM_DESCRIPTOR)); + // // Create second SMRAM descriptor, which is free and will be used by SMM foundation. // SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].CpuStart = SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf index 2bb1c0296f..21e6efa5e0 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -56,10 +56,11 @@ [LibraryClasses.X64] TdxLib [Guids] gEfiSmmSmramMemoryGuid + gEfiAcpiVariableGuid [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117598): https://edk2.groups.io/g/devel/message/117598 Mute This Topic: https://groups.io/mt/105442002/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 09/13] OvmfPkg/SmmAccess: Consume gEfiSmmSmramMemoryGuid
This patch refines the SmmAccess implementation: 1. SmramMap will be retrieved from the gEfiSmmSmramMemoryGuid instead of original from the TSEG Memory Base register. 2. Remove the gEfiAcpiVariableGuid creation, thus the DESCRIPTOR_INDEX definition can be also cleaned. The gEfiAcpiVariableGuid HOB will be created in the OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf | 5 +++ OvmfPkg/SmmAccess/SmmAccessPei.c| 88 +++-- OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +-- OvmfPkg/SmmAccess/SmramInternal.c | 73 +++--- OvmfPkg/SmmAccess/SmramInternal.h | 18 +--- 6 files changed, 41 insertions(+), 154 deletions(-) diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c index 4b9e6df37f..3371592de7 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c @@ -4,11 +4,11 @@ Q35 TSEG is expected to have been verified and set up by the SmmAccessPei driver. Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. + Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -113,12 +113,10 @@ SmmAccess2DxeGetCapabilities ( IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR*SmramMap ) { return SmramAccessGetCapabilities ( - This->LockState, - This->OpenState, SmramMapSize, SmramMap ); } diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf index d86381d0fb..d9f01a13c4 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf @@ -3,10 +3,11 @@ # # Q35 TSEG is expected to have been verified and set up by the SmmAccessPei # driver. # # Copyright (C) 2013, 2015, Red Hat, Inc. +# Copyright (c) 2024 Intel Corporation. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,17 +40,21 @@ DebugLib PcdLib PciLib UefiBootServicesTableLib UefiDriverEntryPoint + HobLib [Protocols] gEfiSmmAccess2ProtocolGuid ## PRODUCES [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire +[Guids] + gEfiSmmSmramMemoryGuid # ALWAYS_CONSUMED + [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes [Depex] diff --git a/OvmfPkg/SmmAccess/SmmAccessPei.c b/OvmfPkg/SmmAccess/SmmAccessPei.c index 0e57b7804c..9459bcc989 100644 --- a/OvmfPkg/SmmAccess/SmmAccessPei.c +++ b/OvmfPkg/SmmAccess/SmmAccessPei.c @@ -9,21 +9,19 @@ This PEIM runs from RAM, so we can write to variables with static storage duration. Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2010, Intel Corporation. All rights reserved. + Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include #include #include #include -#include #include #include #include #include #include @@ -62,14 +60,10 @@ SmmAccessPeiOpen ( IN EFI_PEI_SERVICES**PeiServices, IN PEI_SMM_ACCESS_PPI *This, IN UINTN DescriptorIndex ) { - if (DescriptorIndex >= DescIdxCount) { -return EFI_INVALID_PARAMETER; - } - // // According to current practice, DescriptorIndex is not considered at all, // beyond validating it. // return SmramAccessOpen (&This->LockState, &This->OpenState); @@ -100,14 +94,10 @@ SmmAccessPeiClose ( IN EFI_PEI_SERVICES**PeiServices, IN PEI_SMM_ACCESS_PPI *This, IN UINTN DescriptorIndex ) { - if (DescriptorIndex >= DescIdxCount) { -return EFI_INVALID_PARAMETER; - } - // // According to current practice, DescriptorIndex is not considered at all, // beyond validating it. // return SmramAccessClose (&This->LockState, &This->OpenState); @@ -137,14 +127,10 @@ SmmAccessPeiLock ( IN EFI_PEI_SERVICES**PeiServices, IN PEI_SMM_ACCESS_PPI *This, IN UINTN DescriptorIndex ) { - if (DescriptorIndex >= DescIdxCount) { -return EFI_INVALID_PARAMETER; - } - // // According to current practice, DescriptorIndex is not considered at all, // beyond validating it. // return SmramAccessLock (&This->LockState, &This->OpenState); @@ -176,12 +162,10 @@ SmmAccessPeiGetCapabilities ( IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap ) { return SmramAccessGetCapabilities ( - This->LockState, - This->OpenState, SmramMapSize, SmramMap ); } @@ -238,18 +222,14 @@ EFIAPI SmmAccessPeiEntryPoint ( IN EFI_PEI_FILE_HANDLE FileHandle,
[edk2-devel] [PATCH v1 11/13] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not
Based on gSmmBaseHobGuid: If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded in the SmBase array. So, this patch check smbase relocation is done or not in SmmCpuFeaturesInitializeProcessor(). With SmmRelocationLib, gSmmBaseHobGuid will be always created. Here this patch just makes the function/logic correct. The SMM Relocation logic can be totally cleaned from the SmmCpuFeaturesLib. But it will happen in the future patch set, this patch does not target to the cleanup work. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 ++ 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 63822b126e..0a6f33c2b1 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -26,10 +26,16 @@ // // EFER register LMA bit // #define LMA BIT10 +// +// Indicate SmBase for each Processors has been relocated or not. If TRUE, +// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor(). +// +BOOLEAN mSmmCpuFeaturesSmmRelocated; + /** The constructor function @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @@ -44,13 +50,13 @@ SmmCpuFeaturesLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { // // If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded - // in the SmBase array. ASSERT it's not supported in OVMF. + // in the SmBase array. // - ASSERT (GetFirstGuidHob (&gSmmBaseHobGuid) == NULL); + mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL); // // No need to program SMRRs on our virtual platform. // return EFI_SUCCESS; @@ -90,20 +96,25 @@ SmmCpuFeaturesInitializeProcessor ( ) { AMD_SMRAM_SAVE_STATE_MAP *CpuState; // - // Configure SMBASE. + // No need to configure SMBASE if SmBase relocation has been done. // - CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( - SMM_DEFAULT_SMBASE + - SMRAM_SAVE_STATE_MAP_OFFSET - ); - if ((CpuState->x86.SMMRevId & 0x) == 0) { -CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; - } else { -CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + if (!mSmmCpuFeaturesSmmRelocated) { +// +// Configure SMBASE. +// +CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( + SMM_DEFAULT_SMBASE + + SMRAM_SAVE_STATE_MAP_OFFSET + ); +if ((CpuState->x86.SMMRevId & 0x) == 0) { + CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} else { + CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} } // // No need to program SMRRs on our virtual platform. // -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117599): https://edk2.groups.io/g/devel/message/117599 Mute This Topic: https://groups.io/mt/105442004/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1 12/13] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase
This patch is to consume SmmRelocationInit for SmBase Relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/PlatformPei/Platform.c | 1 + OvmfPkg/PlatformPei/Platform.h | 5 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 5 ++- OvmfPkg/PlatformPei/SmmRelocation.c | 80 + 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/PlatformPei/SmmRelocation.c diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8..47ccf9e2b9 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -365,8 +365,9 @@ InitializePlatform ( MiscInitialization (PlatformInfoHob); } IntelTdxInitialize (); InstallFeatureControlCallback (PlatformInfoHob); + InstallSmmRelocationCallback (); return EFI_SUCCESS; } diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 1cf44844a7..e2057623b7 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -76,10 +76,15 @@ InstallFeatureControlCallback ( VOID InstallClearCacheCallback ( VOID ); +VOID +InstallSmmRelocationCallback ( + VOID + ); + VOID AmdSevInitialize ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index ad52be3065..d7a4fd5ffe 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -1,10 +1,10 @@ ## @file # Platform PEI driver # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. +# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -30,10 +30,11 @@ MemDetect.c MemTypeInfo.c Platform.c Platform.h IntelTdx.c + SmmRelocation.c [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -63,10 +64,11 @@ MtrrLib MemEncryptSevLib PcdLib CcExitLib PlatformInitLib + SmmRelocationLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase @@ -137,9 +139,10 @@ [Ppis] gEfiPeiMasterBootModePpiGuid gEfiPeiMpServicesPpiGuid gEfiPeiReadOnlyVariable2PpiGuid + gEdkiiPeiMpServices2PpiGuid [Depex] TRUE diff --git a/OvmfPkg/PlatformPei/SmmRelocation.c b/OvmfPkg/PlatformPei/SmmRelocation.c new file mode 100644 index 00..63db7101b5 --- /dev/null +++ b/OvmfPkg/PlatformPei/SmmRelocation.c @@ -0,0 +1,80 @@ +/**@file + Install a callback to do smm relocation. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include "Platform.h" + +/** + Notification function called when EDKII_PEI_MP_SERVICES2_PPI becomes available. + + @param[in] PeiServices Indirect reference to the PEI Services Table. + @param[in] NotifyDescriptor Address of the notification descriptor data + structure. + @param[in] Ppi Address of the PPI that was installed. + + @return Status of the notification. The status code returned from this + function is ignored. +**/ +STATIC +EFI_STATUS +EFIAPI +OnMpServices2Available ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EDKII_PEI_MP_SERVICES2_PPI *MpServices2; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __func__)); + + MpServices2 = Ppi; + + // + // Smm Relocation Initialize. + // + Status = SmmRelocationInit (MpServices2); + if (EFI_ERROR (Status)) { +DEBUG ((DEBUG_WARN, "OnMpServices2Available: Not able to execute Smm Relocation Init. Status: %r\n", Status)); + } + + return EFI_SUCCESS; +} + +// +// Notification object for registering the callback, for when +// EDKII_PEI_MP_SERVICES2_PPI becomes available. +// +STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServices2Notify = { + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEdkiiPeiMpServices2PpiGuid, // Guid + OnMpServices2Available // Notify +}; + +VOID +InstallSmmRelocationCallback ( + VOID + ) +{ + EFI_STATUS Status; + + Status = PeiServicesNotifyPpi (&mMpServices2Notify); + if (EFI_ERROR (Status)) { +DEBUG (( + DEBUG_ERROR, + "%a: failed to set up MP Services2 callback: %r\n", + __func__, + Status + )); + } +} -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117600): https://edk2.groups.io/g/devel/message/117600
[edk2-devel] [PATCH v1 13/13] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic
This patch is to remove legacy SmBase relocation in PiSmmCpuDxeSmm Driver, and the SmBase relocation behavior will be in the SmmRelocationInit interface: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. Then, PiSmmCpuDxeSmm driver can be simplified to: 1. Consume the gSmmBaseHobGuid for the smbase. 2. ExecuteFirstSmiInit for early SMM Init. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c| 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 42 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 96 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c| 6 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 322 ++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 98 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c| 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm | 146 10 files changed, 30 insertions(+), 843 deletions(-) delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index b14c289a27..d67fb49890 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -639,27 +639,14 @@ InitializeCpuProcedure ( // InitializeCpuBeforeRebase (IsBsp); } if (IsBsp) { -DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated is %d\n", mSmmRelocated)); - // -// Check whether Smm Relocation is done or not. -// If not, will do the SmmBases Relocation here!!! +// Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. // -if (!mSmmRelocated) { - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); -} else { - // - // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. - // - ExecuteFirstSmiInit (); -} +ExecuteFirstSmiInit (); } // // Skip initialization if mAcpiCpuData is not valid // @@ -978,13 +965,13 @@ InitSmmS3ResumeState ( SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); if (SmmS3ResumeState->SmmS3StackBase == 0) { SmmS3ResumeState->SmmS3StackSize = 0; } -SmmS3ResumeState->SmmS3Cr0 = mSmmCr0; +SmmS3ResumeState->SmmS3Cr0 = (UINT32)AsmReadCr0 (); SmmS3ResumeState->SmmS3Cr3 = Cr3; -SmmS3ResumeState->SmmS3Cr4 = mSmmCr4; +SmmS3ResumeState->SmmS3Cr4 = (UINT32)AsmReadCr4 (); if (sizeof (UINTN) == sizeof (UINT64)) { SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64; } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c deleted file mode 100644 index a9fcc89dda..00 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - - mRebasedFlag = RebasedFlag; - - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm deleted file mode 100644 index b5e77a1a5b..00 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm +++ /dev/null @@ -1,96 +0,0 @@ -;---
Re: [edk2-devel] [PATCH v1 00/13] Add SmmRelocationLib
Sure, Jiewen, Yes, I have tested on OVMF: 1) Checked the OVMF can normal boot with SMM enabled. 2) Checked the multiple processor support on OVMF with -smp 4 command. 3) Test the OVMF can response soft SMI, the smbase has been rebased before smm cpu driver dispatch. 4) Pass SMM test on intel QSP platform. Thanks, Jiaxin > -Original Message- > From: Yao, Jiewen > Sent: Wednesday, April 10, 2024 10:02 PM > To: Wu, Jiaxin ; devel@edk2.groups.io > Cc: Ni, Ray ; Zeng, Star ; Gerd > Hoffmann ; Kumar, Rahul R ; > Dong, Guo ; Rhodes, Sean ; > Lu, James ; Guo, Gua ; Ard > Biesheuvel > Subject: RE: [PATCH v1 00/13] Add SmmRelocationLib > > Hello > Would you please describe what test has been done for OvmfPkg? > For example, have you validated OVMF with SMM enabled? > > > > -Original Message- > > From: Wu, Jiaxin > > Sent: Wednesday, April 10, 2024 9:57 PM > > To: devel@edk2.groups.io > > Cc: Ni, Ray ; Zeng, Star ; Gerd > > Hoffmann ; Kumar, Rahul R > ; > > Dong, Guo ; Rhodes, Sean ; > Lu, > > James ; Guo, Gua ; Ard > Biesheuvel > > ; Yao, Jiewen > > Subject: [PATCH v1 00/13] Add SmmRelocationLib > > > > Intel plans to separate the smbase relocation logic from > > PiSmmCpuDxeSmm driver, and the related behavior will be > > moved to the new interface defined by the SmmRelocationLib > > class. > > > > The SmmRelocationLib class provides the SmmRelocationInit() > > interface for platform to do the smbase relocation, which > > shall provide below 2 functionalities: > > 1. Relocate smbases for each processor. > > 2. Create the gSmmBaseHobGuid HOB. > > > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > > a later phase) can be simplfied as below for SMM init: > > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > > for each Processor. > > 2. Execute the early SMM Init. > > > > Cc: Ray Ni > > Cc: Zeng Star > > Cc: Gerd Hoffmann > > Cc: Rahul Kumar > > Cc: Guo Dong > > Cc: Sean Rhodes > > Cc: James Lu > > Cc: Gua Guo > > Cc: Ard Biesheuvel > > Cc: Jiewen Yao > > Signed-off-by: Jiaxin Wu > > > > Jiaxin Wu (13): > > UefiCpuPkg: Add SmmRelocationLib class > > UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance > > UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF > > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD > > UefiCpuPkg/UefiCpuPkg.dsc: Include SmmRelocationLib in UefiCpuPkg > > UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib > > OvmfPkg: Include SmmRelocationLib in OvmfPkg > > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > > OvmfPkg/SmmAccess: Consume gEfiSmmSmramMemoryGuid > > OvmfPkg/PlatformInitLib: Create gEfiAcpiVariableGuid > > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase > > UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic > > > > OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + > > OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + > > OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- > > .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- > > .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- > > OvmfPkg/Microvm/MicrovmX64.dsc | 1 + > > OvmfPkg/OvmfPkgIa32.dsc| 1 + > > OvmfPkg/OvmfPkgIa32X64.dsc | 1 + > > OvmfPkg/OvmfPkgX64.dsc | 1 + > > OvmfPkg/PlatformPei/Platform.c | 1 + > > OvmfPkg/PlatformPei/Platform.h | 5 + > > OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- > > OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ > > OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- > > OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + > > OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +-- > > OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- > > OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- > > OvmfPkg/SmmAccess/SmramInternal.h | 18 +- > > UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ > > .../SmmRelocationLib/AmdSmmRelocationLib.inf | 61 ++ > > .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 109 > > .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > > .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 157 ++
Re: [edk2-devel] [PATCH v1 00/13] Add SmmRelocationLib
Share the PR here: https://github.com/tianocore/edk2/pull/5546 From: Ni, Ray Sent: Thursday, April 11, 2024 11:15 AM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R ; Dong, Guo ; Rhodes, Sean ; Lu, James ; Guo, Gua ; Ard Biesheuvel ; Yao, Jiewen Subject: Re: [PATCH v1 00/13] Add SmmRelocationLib Jiaxin, can you kindly share a PR in GitHub so that it will be easier to review? Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Wednesday, April 10, 2024 21:57 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>> Subject: [PATCH v1 00/13] Add SmmRelocationLib Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni mailto:ray...@intel.com>> Cc: Zeng Star mailto:star.z...@intel.com>> Cc: Gerd Hoffmann mailto:kra...@redhat.com>> Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> Cc: Guo Dong mailto:guo.d...@intel.com>> Cc: Sean Rhodes mailto:sean@starlabs.systems>> Cc: James Lu mailto:james...@intel.com>> Cc: Gua Guo mailto:gua@intel.com>> Cc: Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>> Cc: Jiewen Yao mailto:jiewen@intel.com>> Signed-off-by: Jiaxin Wu mailto:jiaxin...@intel.com>> Jiaxin Wu (13): UefiCpuPkg: Add SmmRelocationLib class UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF UefiCpuPkg/SmmRelocationLib: Add library instance for AMD UefiCpuPkg/UefiCpuPkg.dsc: Include SmmRelocationLib in UefiCpuPkg UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib OvmfPkg: Include SmmRelocationLib in OvmfPkg OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg/SmmAccess: Consume gEfiSmmSmramMemoryGuid OvmfPkg/PlatformInitLib: Create gEfiAcpiVariableGuid OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/Platform.c | 1 + OvmfPkg/PlatformPei/Platform.h | 5 + OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +-- OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- OvmfPkg/SmmAccess/SmramInternal.h | 18 +- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ .../SmmRelocationLib/AmdSmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 109 .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 157 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 141 + .../SmmRelocationLib/OvmfSmmRelocationLib.inf | 61 ++ .../SmmRelocationLib/OvmfSmramSaveStateConfig.c| 107 .../Library/SmmRelocationLib/SmmRelocationLib.c| 659 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 ++ .../SmmRelocation
Re: [edk2-devel] [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF
Hi Gred, Because: 1) The mode of the CPU check is different between the AMD & OVMF. OVMF: CpuSaveState->x86.SMMRevId & 0X AMD: LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA 2) Existing SmBase configuration is different between the AMD & OVMF. OVMF: AmdCpuState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; AMD: if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { CpuSaveState->x86.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; } else { CpuSaveState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; } This series patch won't change the existing implementation code logic, so, we need override one version for OVMF. +AMD feature owner Thanks, Jiaxin > -Original Message- > From: Gerd Hoffmann > Sent: Thursday, April 11, 2024 3:11 PM > To: Wu, Jiaxin > Cc: devel@edk2.groups.io; Ni, Ray ; Zeng, Star > ; Ard Biesheuvel ; Yao, > Jiewen ; Kumar, Rahul R > Subject: Re: [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library > instance for OVMF > > On Wed, Apr 10, 2024 at 09:57:14PM +0800, Jiaxin Wu wrote: > > Due to the definition difference of SMRAM Save State, > > SmmBase config in SMRAM Save State for OVMF is also different. > > > > This patch provides the OvmfSmmRelocationLib library instance > > to handle the SMRAM Save State difference. > > Why ovmf needs its own version? Patch #4 adds an AMD version, and given > that KVM uses the AMD smram layout that library should work for OVMF > too, no? > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117774): https://edk2.groups.io/g/devel/message/117774 Mute This Topic: https://groups.io/mt/105441992/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v2 00/10] Add SmmRelocationLib
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Tom Lendacky Signed-off-by: Jiaxin Wu Jiaxin Wu (10): UefiCpuPkg: Add SmmRelocationLib class UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance UefiCpuPkg/SmmRelocationLib: Add library instance for AMD OvmfPkg/SmmRelocationLib: Add library instance for OVMF OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg: Refine SmmAccess implementation OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic OvmfPkg/AmdSev/AmdSevX64.dsc | 3 + OvmfPkg/CloudHv/CloudHvX64.dsc | 2 + OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm | 148 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 140 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 599 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 107 .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 86 ++- OvmfPkg/Microvm/MicrovmX64.dsc | 3 + OvmfPkg/OvmfPkgIa32.dsc| 2 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/Platform.c | 3 + OvmfPkg/PlatformPei/Platform.h | 5 + OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +-- OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- OvmfPkg/SmmAccess/SmramInternal.h | 18 +- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ .../SmmRelocationLib/AmdSmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 132 + .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 148 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 140 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 599 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 62 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 139 + .../SmmRelocationLib}/X64/Semaphore.c | 13 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 86 ++- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm| 96 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 331 +--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 +--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + UefiPayloadPkg/UefiPayloadPkg.dsc | 2 + 49 files changed, 2833 insertions(+), 856 deletions(-) copy {UefiCpuPkg/PiSmmCpuDxeSmm => OvmfPkg/Library/SmmRelocationLib}/Ia32/Semaphore.c (72%) create mode 100644 OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm create mode 100644 OvmfPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.c create mode 100644 OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf create mode 100
[edk2-devel] [PATCH v2 03/10] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD
Due to the definition difference of SMRAM Save State, SmmBase config in SMRAM Save State for AMD is also different. This patch provides the AmdSmmRelocationLib library instance to handle the SMRAM Save State difference. Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Tom Lendacky Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- ...mmRelocationLib.inf => AmdSmmRelocationLib.inf} | 5 +- ...SaveStateConfig.c => AmdSmramSaveStateConfig.c} | 93 ++ UefiCpuPkg/UefiCpuPkg.dsc | 1 + 3 files changed, 46 insertions(+), 53 deletions(-) copy UefiCpuPkg/Library/SmmRelocationLib/{SmmRelocationLib.inf => AmdSmmRelocationLib.inf} (89%) copy UefiCpuPkg/Library/SmmRelocationLib/{SmramSaveStateConfig.c => AmdSmramSaveStateConfig.c} (50%) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf similarity index 89% copy from UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf index 6581fa2dad..710cd1948b 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf @@ -13,18 +13,18 @@ ## [Defines] INF_VERSION= 0x00010005 BASE_NAME = SmmRelocationLib - FILE_GUID = 853E97B3-790C-4EA3-945C-8F622FC47FE8 + FILE_GUID = 65C74DCD-0D09-494A-8BFF-A64226EB8054 MODULE_TYPE= PEIM VERSION_STRING = 1.0 LIBRARY_CLASS = SmmRelocationLib [Sources] InternalSmmRelocationLib.h - SmramSaveStateConfig.c + AmdSmramSaveStateConfig.c SmmRelocationLib.c [Sources.Ia32] Ia32/Semaphore.c Ia32/SmmInit.nasm @@ -40,11 +40,10 @@ [LibraryClasses] BaseLib BaseMemoryLib CpuExceptionHandlerLib - CpuLib DebugLib HobLib LocalApicLib MemoryAllocationLib PcdLib diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c similarity index 50% copy from UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c index fb69b2b5c5..95a1ce8d46 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c @@ -1,14 +1,17 @@ /** @file Config SMRAM Save State for SmmBases Relocation. + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. Copyright (c) 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalSmmRelocationLib.h" -#include +#include + +#define EFER_ADDRESS 0XC080ul /** Determine the mode of the CPU at the time an SMI occurs @retval EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT 32 bit. @@ -18,44 +21,18 @@ UINT8 CheckMmSaveStateRegisterLma ( VOID ) { - CPUID_VERSION_INFO_EAX RegEax; - CPUID_EXTENDED_CPU_SIG_EDX RegEdx; - UINTN FamilyId; - UINTN ModelId; - UINT32 Eax; - UINT8 SmmSaveStateRegisterLma; - - // - // Determine the mode of the CPU at the time an SMI occurs - // Intel(R) 64 and IA-32 Architectures Software Developer's Manual - // Volume 3C, Section 34.4.1.1 - // - RegEax.Uint32 = GetCpuFamilyModel (); - FamilyId = RegEax.Bits.FamilyId; - ModelId = RegEax.Bits.Model; - if ((FamilyId == 0x06) || (FamilyId == 0x0f)) { -ModelId = ModelId | RegEax.Bits.ExtendedModelId << 4; - } + UINT8 SmmSaveStateRegisterLma; + UINT32 LMAValue; - RegEdx.Uint32 = 0; - AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); - if (Eax >= CPUID_EXTENDED_CPU_SIG) { -AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &(RegEdx.Uint32)); - } - - SmmSaveStateRegisterLma = EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT; - if (RegEdx.Bits.LM) { -SmmSaveStateRegisterLma = EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; - } + SmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT; - if (FamilyId == 0x06) { -if ((ModelId == 0x17) || (ModelId == 0x0f) || (ModelId == 0x1c)) { - SmmSaveStateRegisterLma = EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; -} + LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA; + if (LMAValue) { +SmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT; } return SmmSaveStateRegisterLma; } @@ -73,18 +50,32 @@ EFIAPI ConfigureSmBase ( IN UINTN CpuIndex, IN OUT SMRAM_SAVE_STATE_MAP *CpuState ) { - CpuState->x86.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; + AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState; + + AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState; + + AmdCpuState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuInde
[edk2-devel] [PATCH v2 04/10] OvmfPkg/SmmRelocationLib: Add library instance for OVMF
There are below 2 differences between AMD & OVMF according existing implementation: 1.The mode of the CPU check is different between the AMD & OVMF. OVMF: CpuSaveState->x86.SMMRevId & 0X AMD: LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA 2.Existing SmBase configuration is different between the AMD & OVMF. OVMF: AmdCpuState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; AMD: if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { CpuSaveState->x86.SMBASE = mSmBaseForAllCpus[CpuIndex]; } else { CpuSaveState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; } This patch provides the SmmRelocationLib library instance for OVMF to handle the logic difference, and it won't change the existing implementation code logic. Cc: Ray Ni Cc: Zeng Star Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- OvmfPkg/AmdSev/AmdSevX64.dsc | 3 + OvmfPkg/CloudHv/CloudHvX64.dsc | 2 + .../Library/SmmRelocationLib/Ia32/Semaphore.c | 0 .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 0 .../SmmRelocationLib/InternalSmmRelocationLib.h| 0 .../Library/SmmRelocationLib/SmmRelocationLib.c| 0 .../Library/SmmRelocationLib/SmmRelocationLib.inf | 3 +- .../SmmRelocationLib/SmramSaveStateConfig.c| 65 +++--- .../Library/SmmRelocationLib/X64/Semaphore.c | 0 .../Library/SmmRelocationLib/X64/SmmInit.nasm | 0 OvmfPkg/Microvm/MicrovmX64.dsc | 3 + OvmfPkg/OvmfPkgIa32.dsc| 2 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgX64.dsc | 1 + 14 files changed, 34 insertions(+), 47 deletions(-) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/SmmInit.nasm (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/InternalSmmRelocationLib.h (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.inf (91%) copy UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c => OvmfPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c (64%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/SmmInit.nasm (100%) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 60e916b4fd..f844268cd8 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -170,10 +170,13 @@ BlobVerifierLib|OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf +!if $(SMM_REQUIRE) == TRUE + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf +!endif !if $(SOURCE_DEBUG_ENABLE) == TRUE PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf !else diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index b522fa1059..918c3dff19 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -183,10 +183,12 @@ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf !if $(SMM_REQUIRE) == FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf +!else + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf !endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c copy to OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm copy to OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/OvmfPkg/Library
[edk2-devel] [PATCH v2 01/10] UefiCpuPkg: Add SmmRelocationLib class
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) shall: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. This patch just provides the SmmRelocationLib class. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 +++ UefiCpuPkg/UefiCpuPkg.dec | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmRelocationLib.h diff --git a/UefiCpuPkg/Include/Library/SmmRelocationLib.h b/UefiCpuPkg/Include/Library/SmmRelocationLib.h new file mode 100644 index 00..999a5b46d1 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmRelocationLib.h @@ -0,0 +1,42 @@ +/** @file + Header file for SMM Relocation Library. + + The SmmRelocationLib class provides the SmmRelocationInit() + interface for platform to do the smbase relocation, which + shall provide below 2 functionalities: + 1. Relocate SmBases for each processor. + 2. Create the SmBase HOB (gSmmBaseHobGuid). + + With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) + shall: + 1. Consume the gSmmBaseHobGuid for the relocated smbase for each Processor. + 2. Execute early SMM init. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_RELOCATION_LIB_H_ +#define SMM_RELOCATION_LIB_H_ + +#include + +/** + CPU SmmBase Relocation Init. + + This function is to relocate CPU SmmBase. + + @param[in] MpServices2Pointer to this instance of the MpServices. + + @retval EFI_SUCCESS CPU SmmBase Relocated successfully. + @retval OthersCPU SmmBase Relocation failed. + +**/ +EFI_STATUS +EFIAPI +SmmRelocationInit ( + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2 + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 571b59b36f..1d7890f19e 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -65,10 +65,13 @@ MmSaveStateLib|Include/Library/MmSaveStateLib.h ## @libraryclass Provides functions for SMM CPU Sync Operation. SmmCpuSyncLib|Include/Library/SmmCpuSyncLib.h + ## @libraryclass Provides functions for SMM Relocation Operation. + SmmRelocationLib|Include/Library/SmmRelocationLib.h + [LibraryClasses.RISCV64] ## @libraryclass Provides functions to manage MMU features on RISCV64 CPUs. ## RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117776): https://edk2.groups.io/g/devel/message/117776 Mute This Topic: https://groups.io/mt/105535805/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v2 02/10] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance
This patch separates the smbase relocation logic from PiSmmCpuDxeSmm driver, and moves to the SmmRelocationInit interface. Platform shall consume the interface for the smbase relocation if need SMM support. Note: Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates the SMRAM to be used for SMI handler and Save state area of each processor from Smst->AllocatePages(). With SmmRelocationLib, the SMRAM allocation for SMI handlers and Save state areas is moved to early PEI phase (Smst->AllocatePages() service is not available). So, the allocation is done by splitting the SMRAM out of the SMRAM regions reported from gEfiSmmSMramMemoryGuid. So, Platform must produce the gEfiSmmSMramMemoryGuid HOB for SmmRelocationLib usage. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 148 + .../SmmRelocationLib/InternalSmmRelocationLib.h| 140 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 599 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 62 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 139 + .../SmmRelocationLib}/X64/Semaphore.c | 13 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 86 ++- UefiCpuPkg/UefiCpuPkg.dsc | 1 + 9 files changed, 1173 insertions(+), 28 deletions(-) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/Semaphore.c (72%) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/Semaphore.c (78%) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/SmmInit.nasm (59%) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 72% copy from UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c copy to UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c index a9fcc89dda..ace3221cfc 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -1,15 +1,15 @@ /** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include "PiSmmCpuDxeSmm.h" +#include "InternalSmmRelocationLib.h" UINTN mSmmRelocationOriginalAddress; volatile BOOLEAN *mRebasedFlag; /** @@ -30,11 +30,12 @@ SemaphoreHook ( { SMRAM_SAVE_STATE_MAP *CpuState; mRebasedFlag = RebasedFlag; - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); + CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); + mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( CpuIndex, CpuState, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm new file mode 100644 index 00..931dd17439 --- /dev/null +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -0,0 +1,148 @@ +;-- ; +; Copyright (c) 2024, Intel Corporation. All rights reserved. +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; SmmInit.nasm +; +; Abstract: +; +; Functions for relocating SMBASE's for all processors +; +;--- + +%include "StuffRsbNasm.inc" + +global ASM_PFX(gcSmmInitIdtr) +global ASM_PFX(gcSmmInitGdtr) + +extern ASM_PFX(SmmInitHandler) +extern ASM_PFX(mRebasedFlag) +extern ASM_PFX(mSmmRelocationOriginalAddress) + +global ASM_PFX(gPatchSmmCr3) +global ASM_PFX(gPatchSmmCr4) +global ASM_PFX(gPatchSmmCr0) +global ASM_PFX(gPatchSmmInitStack) +global ASM_PFX(gcSmmInitSize) +global ASM_PFX(gcSmmInitTemplate) + +%define PROTECT_MODE_CS 0x8 +%define PROTECT_MODE_DS 0x20 + +SECTION .data + +NullSeg: DQ 0 ; r
[edk2-devel] [PATCH v2 05/10] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
Background: In the PiSmmCpuDxeSmm driver, SMRAM allocation for SMI handlers and processor Save State areas was traditionally performed using the Smst->AllocatePages() function during the DXE phase. The introduction of SmmRelocationLib changes this process by moving the allocation to the PEI phase, where Smst->AllocatePages() is not accessible. Instead, the allocation is now handled by partitioning the SMRAM based on the information provided by a GUID HOB (identified by gEfiSmmSMramMemoryGuid). This patch is to ensure that OVMF produces the gEfiSmmSMramMemoryGuid HOB, allowing SmmRelocationLib to reserve the necessary memory for SMBASE relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 97 +- .../Library/PlatformInitLib/PlatformInitLib.inf| 5 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 7b6e5102ad..8b98256225 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1,9 +1,9 @@ /**@file Memory Detection for Virtual Machines. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved. + Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: MemDetect.c @@ -41,10 +41,12 @@ Module Name: #include #include #include +#include + #define MEGABYTE_SHIFT 20 VOID EFIAPI PlatformQemuUc32BaseInitialization ( @@ -1027,52 +1029,73 @@ PlatformQemuInitializeRam ( // // Determine total memory size available // PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); - if (PlatformInfoHob->BootMode == BOOT_ON_S3_RESUME) { -// -// Create the following memory HOB as an exception on the S3 boot path. + // + // CpuMpPei saves the original contents of the borrowed area in permanent + // PEI RAM, in a backup buffer allocated with the normal PEI services. + // CpuMpPei restores the original contents ("returns" the borrowed area) at + // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before + // transferring control to the OS's wakeup vector in the FACS. + // + // We expect any other PEIMs that "borrow" memory similarly to CpuMpPei to + // restore the original contents. Furthermore, we expect all such PEIMs + // (CpuMpPei included) to claim the borrowed areas by producing memory + // allocation HOBs, and to honor preexistent memory allocation HOBs when + // looking for an area to borrow. + // + QemuInitializeRamBelow1gb (PlatformInfoHob); + + if (PlatformInfoHob->SmmSmramRequire) { +UINT32 TsegSize; +UINTN BufferSize; +UINT8 SmramRanges; +EFI_PEI_HOB_POINTERSHob; +EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + +TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; +PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); +PlatformAddReservedMemoryBaseSizeHob ( + PlatformInfoHob->LowMemory - TsegSize, + TsegSize, + TRUE + ); + +SmramRanges = 2; +BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); + +Hob.Raw = BuildGuidHob ( +&gEfiSmmSmramMemoryGuid, +BufferSize +); +ASSERT (Hob.Raw); + +SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); +SmramHobDescriptorBlock->NumberOfSmmReservedRegions = SmramRanges; + // -// Normally we'd create memory HOBs only on the normal boot path. However, -// CpuMpPei specifically needs such a low-memory HOB on the S3 path as -// well, for "borrowing" a subset of it temporarily, for the AP startup -// vector. +// Create first SMRAM descriptor, which contains data structures used in S3 resume. +// One page is enough for the data structure // -// CpuMpPei saves the original contents of the borrowed area in permanent -// PEI RAM, in a backup buffer allocated with the normal PEI services. -// CpuMpPei restores the original contents ("returns" the borrowed area) at -// End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before -// transferring control to the OS's wakeup vector in the FACS. +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; +SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; + // -// We expect any other PEIMs that "borrow" memory similarl
[edk2-devel] [PATCH v2 06/10] OvmfPkg: Refine SmmAccess implementation
This patch refines the SmmAccess implementation: 1. SmramMap will be retrieved from the gEfiSmmSmramMemoryGuid instead of original from the TSEG Memory Base register. 2. Remove the gEfiAcpiVariableGuid creation, thus the DESCRIPTOR_INDEX definition can be also cleaned. 3. The gEfiAcpiVariableGuid HOB is moved to the OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 9 +++ .../Library/PlatformInitLib/PlatformInitLib.inf| 1 + OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 ++ OvmfPkg/SmmAccess/SmmAccessPei.c | 88 ++ OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 ++ OvmfPkg/SmmAccess/SmramInternal.h | 18 + 8 files changed, 51 insertions(+), 154 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 8b98256225..f451c9d80c 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -41,10 +41,11 @@ Module Name: #include #include #include +#include #include #define MEGABYTE_SHIFT 20 VOID @@ -1050,10 +1051,11 @@ PlatformQemuInitializeRam ( UINT32 TsegSize; UINTN BufferSize; UINT8 SmramRanges; EFI_PEI_HOB_POINTERSHob; EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; +VOID*GuidHob; TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); PlatformAddReservedMemoryBaseSizeHob ( PlatformInfoHob->LowMemory - TsegSize, @@ -1080,10 +1082,17 @@ PlatformQemuInitializeRam ( SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; +// +// Create gEfiAcpiVariableGuid +// +GuidHob = BuildGuidHob (&gEfiAcpiVariableGuid, sizeof (EFI_SMRAM_DESCRIPTOR)); +ASSERT (GuidHob != NULL); +CopyMem (GuidHob, &SmramHobDescriptorBlock->Descriptor[0], sizeof (EFI_SMRAM_DESCRIPTOR)); + // // Create second SMRAM descriptor, which is free and will be used by SMM foundation. // SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].CpuStart = SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf index 2bb1c0296f..21e6efa5e0 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -56,10 +56,11 @@ [LibraryClasses.X64] TdxLib [Guids] gEfiSmmSmramMemoryGuid + gEfiAcpiVariableGuid [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c index 4b9e6df37f..3371592de7 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c @@ -4,11 +4,11 @@ Q35 TSEG is expected to have been verified and set up by the SmmAccessPei driver. Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. + Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -113,12 +113,10 @@ SmmAccess2DxeGetCapabilities ( IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR*SmramMap ) { return SmramAccessGetCapabilities ( - This->LockState, - This->OpenState, SmramMapSize, SmramMap ); } diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf index d86381d0fb..d9f01a13c4 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf @@ -3,10 +3,11 @@ # # Q35 TSEG is expected to have been verified and set up by the SmmAccessPei # driver. # # Copyright (C) 2013, 2015, Red Hat, Inc. +# Copyright (c) 2024 Intel Corporation. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,17 +40,21 @@ DebugLib PcdLib PciLib UefiBootServicesTableLib UefiDr
[edk2-devel] [PATCH v2 08/10] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase
This patch is to consume SmmRelocationInit for SmBase Relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/PlatformPei/Platform.c | 3 ++ OvmfPkg/PlatformPei/Platform.h | 5 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 5 ++- OvmfPkg/PlatformPei/SmmRelocation.c | 80 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/PlatformPei/SmmRelocation.c diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8..df35726ff6 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -365,8 +365,11 @@ InitializePlatform ( MiscInitialization (PlatformInfoHob); } IntelTdxInitialize (); InstallFeatureControlCallback (PlatformInfoHob); + if (PlatformInfoHob->SmmSmramRequire) { +RelocateSmBase (); + } return EFI_SUCCESS; } diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 1cf44844a7..0a59547cfc 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -76,10 +76,15 @@ InstallFeatureControlCallback ( VOID InstallClearCacheCallback ( VOID ); +VOID +RelocateSmBase ( + VOID + ); + VOID AmdSevInitialize ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index ad52be3065..d7a4fd5ffe 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -1,10 +1,10 @@ ## @file # Platform PEI driver # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. +# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -30,10 +30,11 @@ MemDetect.c MemTypeInfo.c Platform.c Platform.h IntelTdx.c + SmmRelocation.c [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -63,10 +64,11 @@ MtrrLib MemEncryptSevLib PcdLib CcExitLib PlatformInitLib + SmmRelocationLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase @@ -137,9 +139,10 @@ [Ppis] gEfiPeiMasterBootModePpiGuid gEfiPeiMpServicesPpiGuid gEfiPeiReadOnlyVariable2PpiGuid + gEdkiiPeiMpServices2PpiGuid [Depex] TRUE diff --git a/OvmfPkg/PlatformPei/SmmRelocation.c b/OvmfPkg/PlatformPei/SmmRelocation.c new file mode 100644 index 00..1151fc9220 --- /dev/null +++ b/OvmfPkg/PlatformPei/SmmRelocation.c @@ -0,0 +1,80 @@ +/**@file + Install a callback to do smm relocation. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include "Platform.h" + +/** + Notification function called when EDKII_PEI_MP_SERVICES2_PPI becomes available. + + @param[in] PeiServices Indirect reference to the PEI Services Table. + @param[in] NotifyDescriptor Address of the notification descriptor data + structure. + @param[in] Ppi Address of the PPI that was installed. + + @return Status of the notification. The status code returned from this + function is ignored. +**/ +STATIC +EFI_STATUS +EFIAPI +OnMpServices2Available ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EDKII_PEI_MP_SERVICES2_PPI *MpServices2; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __func__)); + + MpServices2 = Ppi; + + // + // Smm Relocation Initialize. + // + Status = SmmRelocationInit (MpServices2); + if (EFI_ERROR (Status)) { +DEBUG ((DEBUG_WARN, "OnMpServices2Available: Not able to execute Smm Relocation Init. Status: %r\n", Status)); + } + + return EFI_SUCCESS; +} + +// +// Notification object for registering the callback, for when +// EDKII_PEI_MP_SERVICES2_PPI becomes available. +// +STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServices2Notify = { + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEdkiiPeiMpServices2PpiGuid, // Guid + OnMpServices2Available // Notify +}; + +VOID +RelocateSmBase ( + VOID + ) +{ + EFI_STATUS Status; + + Status = PeiServicesNotifyPpi (&mMpServices2Notify); + if (EFI_ERROR (Status)) { +DEBUG (( + DEBUG_ERROR, + "%a: failed to set up MP Services2 callback: %r\n", + __func__, + Status + )); + } +} -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117783): https://edk2.groups.io/g/devel/messa
[edk2-devel] [PATCH v2 10/10] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic
This patch is to remove legacy SmBase relocation in PiSmmCpuDxeSmm Driver. The responsibility for SmBase relocation has been transferred to the SmmRelocationInit interface, which now handles the following tasks: 1. Relocates the SmBase for each processor. 2. Generates the gSmmBaseHobGuid HOB. As a result of this change, the PiSmmCpuDxeSmm driver's role in SMM environment setup is simplified to: 1. Utilize the gSmmBaseHobGuid to determine the SmBase. 2. Perform the ExecuteFirstSmiInit() to do early SMM initialization. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c| 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 42 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 96 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c| 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 331 +++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h| 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c| 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm | 146 11 files changed, 39 insertions(+), 854 deletions(-) delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index b14c289a27..d67fb49890 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -639,27 +639,14 @@ InitializeCpuProcedure ( // InitializeCpuBeforeRebase (IsBsp); } if (IsBsp) { -DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated is %d\n", mSmmRelocated)); - // -// Check whether Smm Relocation is done or not. -// If not, will do the SmmBases Relocation here!!! +// Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. // -if (!mSmmRelocated) { - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); -} else { - // - // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. - // - ExecuteFirstSmiInit (); -} +ExecuteFirstSmiInit (); } // // Skip initialization if mAcpiCpuData is not valid // @@ -978,13 +965,13 @@ InitSmmS3ResumeState ( SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); if (SmmS3ResumeState->SmmS3StackBase == 0) { SmmS3ResumeState->SmmS3StackSize = 0; } -SmmS3ResumeState->SmmS3Cr0 = mSmmCr0; +SmmS3ResumeState->SmmS3Cr0 = (UINT32)AsmReadCr0 (); SmmS3ResumeState->SmmS3Cr3 = Cr3; -SmmS3ResumeState->SmmS3Cr4 = mSmmCr4; +SmmS3ResumeState->SmmS3Cr4 = (UINT32)AsmReadCr4 (); if (sizeof (UINTN) == sizeof (UINT64)) { SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64; } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c deleted file mode 100644 index a9fcc89dda..00 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - - mRebasedFlag = RebasedFlag; - - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/
[edk2-devel] [PATCH v2 07/10] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not
Based on gSmmBaseHobGuid: If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded in the SmBase array. So, this patch check smbase relocation is done or not in SmmCpuFeaturesInitializeProcessor(). With SmmRelocationLib, gSmmBaseHobGuid will be always created. Here this patch just makes the function/logic correct. The SMM Relocation logic can be totally cleaned from the SmmCpuFeaturesLib. But it will happen in the future patch set, this patch does not target to the cleanup work. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 ++ 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 63822b126e..0a6f33c2b1 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -26,10 +26,16 @@ // // EFER register LMA bit // #define LMA BIT10 +// +// Indicate SmBase for each Processors has been relocated or not. If TRUE, +// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor(). +// +BOOLEAN mSmmCpuFeaturesSmmRelocated; + /** The constructor function @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @@ -44,13 +50,13 @@ SmmCpuFeaturesLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { // // If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded - // in the SmBase array. ASSERT it's not supported in OVMF. + // in the SmBase array. // - ASSERT (GetFirstGuidHob (&gSmmBaseHobGuid) == NULL); + mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL); // // No need to program SMRRs on our virtual platform. // return EFI_SUCCESS; @@ -90,20 +96,25 @@ SmmCpuFeaturesInitializeProcessor ( ) { AMD_SMRAM_SAVE_STATE_MAP *CpuState; // - // Configure SMBASE. + // No need to configure SMBASE if SmBase relocation has been done. // - CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( - SMM_DEFAULT_SMBASE + - SMRAM_SAVE_STATE_MAP_OFFSET - ); - if ((CpuState->x86.SMMRevId & 0x) == 0) { -CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; - } else { -CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + if (!mSmmCpuFeaturesSmmRelocated) { +// +// Configure SMBASE. +// +CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( + SMM_DEFAULT_SMBASE + + SMRAM_SAVE_STATE_MAP_OFFSET + ); +if ((CpuState->x86.SMMRevId & 0x) == 0) { + CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} else { + CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} } // // No need to program SMRRs on our virtual platform. // -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117782): https://edk2.groups.io/g/devel/message/117782 Mute This Topic: https://groups.io/mt/105535813/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v2 09/10] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib
This patch just includes SmmRelocationLib in UefiPayloadPkg. Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Gua Guo --- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 433fb51a56..328b7fd4fe 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -313,10 +313,12 @@ VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf + [LibraryClasses.common] !if $(BOOTSPLASH_IMAGE) SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf !endif -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117784): https://edk2.groups.io/g/devel/message/117784 Mute This Topic: https://groups.io/mt/105535815/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v2 00/10] Add SmmRelocationLib
Yes, because I moved the SmmRelocationLib within the condition of SMM_REQUIRE == TRUE in the version 2 patch. It should be always included since the PlatformPei need consume it. I will fix it in the next version patch. It won't impact the code review & test with SMM_REQUIRE == TRUE build. Thanks, Jiaxin > -Original Message- > From: Gerd Hoffmann > Sent: Tuesday, April 16, 2024 3:31 PM > To: devel@edk2.groups.io; Wu, Jiaxin > Cc: Ni, Ray ; Zeng, Star ; Kumar, > Rahul R ; Dong, Guo ; > Rhodes, Sean ; Lu, James ; > Guo, Gua ; Ard Biesheuvel > ; Yao, Jiewen ; Abdul > Lateef Attar ; Abner Chang > ; Tom Lendacky > Subject: Re: [edk2-devel] [PATCH v2 00/10] Add SmmRelocationLib > > On Mon, Apr 15, 2024 at 09:30:11PM +0800, Wu, Jiaxin wrote: > > Intel plans to separate the smbase relocation logic from > > PiSmmCpuDxeSmm driver, and the related behavior will be > > moved to the new interface defined by the SmmRelocationLib > > class. > > > > The SmmRelocationLib class provides the SmmRelocationInit() > > interface for platform to do the smbase relocation, which > > shall provide below 2 functionalities: > > 1. Relocate smbases for each processor. > > 2. Create the gSmmBaseHobGuid HOB. > > > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > > a later phase) can be simplfied as below for SMM init: > > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > > for each Processor. > > 2. Execute the early SMM Init. > > How this was tested? > I can't even build this (without -D SMM_REQUIRE=TRUE). > > /home/kraxel/projects/edk2/OvmfPkg/OvmfPkgX64.dsc(...): error 4000: > Instance of library class [SmmRelocationLib] is not found > in > [/home/kraxel/projects/edk2/OvmfPkg/PlatformPei/PlatformPei.inf] [X64] > consumed by module > [/home/kraxel/projects/edk2/OvmfPkg/PlatformPei/PlatformPei.inf] > > I doubt it passes CI. > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117873): https://edk2.groups.io/g/devel/message/117873 Mute This Topic: https://groups.io/mt/105535804/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF
> > On Mon, Apr 15, 2024 at 01:04:58PM +0000, Wu, Jiaxin wrote: > > Hi Gred, > > > > Because: > > 1) The mode of the CPU check is different between the AMD & OVMF. > > OVMF: > > CpuSaveState->x86.SMMRevId & 0X > > > > AMD: > > LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA > > > > 2) Existing SmBase configuration is different between the AMD & OVMF. > > OVMF: > > AmdCpuState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; > > > > AMD: > > if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { > > CpuSaveState->x86.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; > > } else { > > CpuSaveState->x64.SMBASE = (UINT32)mSmBaseForAllCpus[CpuIndex]; > > } > > > > This series patch won't change the existing implementation code logic, so, > > we > need override one version for OVMF. > > The real question is why do these differences exist and are they > actually needed. > > I'd expect the CPU mode check return identical results. I don't the background why AMD and OVMF has such difference. Maybe OVFM doesn't not support the MSR "EFER_ADDRESS". > > The SmBase configuration for OVMF looks suspicious to me. I'm wondering > whenever the OVMF code actually works in Ia32 builds ... > Yes, I will fix it in the next version. Currently, please build it with SMM_REQUIRE == TRUE. In the next version, I will make sure all pass the check. > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117874): https://edk2.groups.io/g/devel/message/117874 Mute This Topic: https://groups.io/mt/105441992/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF
Hi Gerd, > > I don't the background why AMD and OVMF has such difference. Maybe > OVFM doesn't not support the MSR "EFER_ADDRESS". > > It surely does, it's a rather essential MSR for x64 CPUs. > > > > The SmBase configuration for OVMF looks suspicious to me. I'm > wondering > > > whenever the OVMF code actually works in Ia32 builds ... > > Tested OvmfPkg/OvmfPkgIa32.dsc with SMM_REQUIRE == TRUE (master > branch). > Doesn't boot. The difference above (where the OVMF code does not > consider the 32bit case) could very well explain why 32bit support is > broken. Switching to the AMD code might actually fix that. > > Is the SmmRelocationLib approach supposed to work with mixed mode > firmware where PEI is running in ia32 mode and dxe/smm is running > in x64 mode (i.e. OvmfPkg/OvmfPkgIa32X64.dsc)? > Yes, I passed the test on the both OvmfPkgIa32X64 & OvmfPkgX64 for SMM support. It does has the problem on OvmfPkgIa32 for smm support (same as master). I did quick check, it's not only the CpuSaveState->x86 or CpuSaveState->x64 structure issue, but also has some problem to handler the smi hook return. We can handle this problem in another topic. Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117878): https://edk2.groups.io/g/devel/message/117878 Mute This Topic: https://groups.io/mt/105441992/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library instance for OVMF
I'm using the OVMF library, haven't try the AMD library:). > -Original Message- > From: Gerd Hoffmann > Sent: Wednesday, April 17, 2024 3:04 PM > To: Wu, Jiaxin > Cc: thomas.lenda...@amd.com; devel@edk2.groups.io; Ni, Ray > ; Zeng, Star ; Ard Biesheuvel > ; Yao, Jiewen ; Kumar, > Rahul R > Subject: Re: [PATCH v1 03/13] UefiCpuPkg/SmmRelocationLib: Add library > instance for OVMF > > On Tue, Apr 16, 2024 at 11:34:00AM +, Wu, Jiaxin wrote: > > Hi Gerd, > > > > > Is the SmmRelocationLib approach supposed to work with mixed mode > > > firmware where PEI is running in ia32 mode and dxe/smm is running > > > in x64 mode (i.e. OvmfPkg/OvmfPkgIa32X64.dsc)? > > > > Yes, I passed the test on the both OvmfPkgIa32X64 & OvmfPkgX64 for SMM > support. > > The OVMF library I assume? > Did you try the AMD library too? > > > It does has the problem on OvmfPkgIa32 for smm support (same as > > master). I did quick check, it's not only the CpuSaveState->x86 or > > CpuSaveState->x64 structure issue, but also has some problem to > > handler the smi hook return. We can handle this problem in another > > topic. > > Yes, fixing ia32 can be done separately. > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117902): https://edk2.groups.io/g/devel/message/117902 Mute This Topic: https://groups.io/mt/105441992/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
PR: https://github.com/tianocore/edk2/pull/5546 Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Tom Lendacky Signed-off-by: Jiaxin Wu Jiaxin Wu (13): UefiCpuPkg: Add SmmRelocationLib class UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance UefiCpuPkg/SmmRelocationLib: Rename global variables UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable UefiCpuPkg/SmmRelocationLib: Add library instance for AMD OvmfPkg/SmmRelocationLib: Add library instance for OVMF OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg: Refine SmmAccess implementation OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 60 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 100 .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/Platform.c | 3 + OvmfPkg/PlatformPei/Platform.h | 5 + OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +--- OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- OvmfPkg/SmmAccess/SmramInternal.h | 18 +- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ .../SmmRelocationLib/AmdSmmRelocationLib.inf | 60 +++ .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 125 + .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 136 + .../SmmRelocationLib}/X64/Semaphore.c | 13 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 331 ++--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 +--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + UefiPayloadPkg/UefiPayloadPkg.dsc | 2 + 48 files changed, 2514 insertions(+), 794 deletions(-) copy {UefiCpuPkg/PiSmmCpuDxeSmm => OvmfPkg/Library/SmmRelocationLib}/Ia32/Semaphore.c (71%) copy {UefiCpuPkg/PiSmmCpuDxeSmm => OvmfPkg/Library/SmmRelocationLib}/Ia32/SmmInit.nasm (47%) create mode 100644 OvmfPkg/L
[edk2-devel] [PATCH v3 01/13] UefiCpuPkg: Add SmmRelocationLib class
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) shall: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. This patch just provides the SmmRelocationLib class. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 +++ UefiCpuPkg/UefiCpuPkg.dec | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmRelocationLib.h diff --git a/UefiCpuPkg/Include/Library/SmmRelocationLib.h b/UefiCpuPkg/Include/Library/SmmRelocationLib.h new file mode 100644 index 00..999a5b46d1 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmRelocationLib.h @@ -0,0 +1,42 @@ +/** @file + Header file for SMM Relocation Library. + + The SmmRelocationLib class provides the SmmRelocationInit() + interface for platform to do the smbase relocation, which + shall provide below 2 functionalities: + 1. Relocate SmBases for each processor. + 2. Create the SmBase HOB (gSmmBaseHobGuid). + + With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) + shall: + 1. Consume the gSmmBaseHobGuid for the relocated smbase for each Processor. + 2. Execute early SMM init. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_RELOCATION_LIB_H_ +#define SMM_RELOCATION_LIB_H_ + +#include + +/** + CPU SmmBase Relocation Init. + + This function is to relocate CPU SmmBase. + + @param[in] MpServices2Pointer to this instance of the MpServices. + + @retval EFI_SUCCESS CPU SmmBase Relocated successfully. + @retval OthersCPU SmmBase Relocation failed. + +**/ +EFI_STATUS +EFIAPI +SmmRelocationInit ( + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2 + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index f412ac0ce2..f86a6d2bcb 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -69,10 +69,13 @@ MmSaveStateLib|Include/Library/MmSaveStateLib.h ## @libraryclass Provides functions for SMM CPU Sync Operation. SmmCpuSyncLib|Include/Library/SmmCpuSyncLib.h + ## @libraryclass Provides functions for SMM Relocation Operation. + SmmRelocationLib|Include/Library/SmmRelocationLib.h + [LibraryClasses.RISCV64] ## @libraryclass Provides functions to manage MMU features on RISCV64 CPUs. ## RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117946): https://edk2.groups.io/g/devel/message/117946 Mute This Topic: https://groups.io/mt/105593569/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v3 02/13] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance
This patch just separates the smbase relocation logic from PiSmmCpuDxeSmm driver, and moves to the SmmRelocationInit interface. It maintains the original implementation of most functions and leaves the definitions of global variables intact. Further refinements to the code are planned for subsequent patches. Platform shall consume the interface for the smbase relocation if need SMM support. Note: Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates the SMRAM to be used for SMI handler and Save state area of each processor from Smst->AllocatePages(). With SmmRelocationLib, the SMRAM allocation for SMI handlers and Save state areas is moved to early PEI phase (Smst->AllocatePages() service is not available). So, the allocation is done by splitting the SMRAM out of the SMRAM regions reported from gEfiSmmSMramMemoryGuid. So, Platform must produce the gEfiSmmSMramMemoryGuid HOB for SmmRelocationLib usage. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../SmmRelocationLib}/Ia32/Semaphore.c | 10 +- .../SmmRelocationLib}/Ia32/SmmInit.nasm| 67 ++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 132 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 600 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 139 + .../SmmRelocationLib}/X64/Semaphore.c | 10 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 69 ++- UefiCpuPkg/UefiCpuPkg.dsc | 1 + 9 files changed, 1066 insertions(+), 23 deletions(-) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/Semaphore.c (79%) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/SmmInit.nasm (53%) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/Semaphore.c (84%) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/SmmInit.nasm (64%) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 79% copy from UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c copy to UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c index a9fcc89dda..ba329d6ba2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -1,15 +1,15 @@ /** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include "PiSmmCpuDxeSmm.h" +#include "InternalSmmRelocationLib.h" UINTN mSmmRelocationOriginalAddress; volatile BOOLEAN *mRebasedFlag; /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm similarity index 53% copy from UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm copy to UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm index b5e77a1a5b..3d845e9e16 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -1,7 +1,7 @@ ;-- ; -; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. +; Copyright (c) 2024, Intel Corporation. All rights reserved. ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; ; SmmInit.nasm @@ -27,15 +27,70 @@ global ASM_PFX(gcSmmInitSize) global ASM_PFX(gcSmmInitTemplate) %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -SECTION .text +SECTION .data -ASM_PFX(gcSmiInitGdtr): +NullSeg: DQ 0 ; reserved by architecture +CodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeCodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeSsSeg32: +DW -1 ; LimitLow +
[edk2-devel] [PATCH v3 03/13] UefiCpuPkg/SmmRelocationLib: Rename global variables
This patch aims to rename global variables for clearer association with Smm Init, ensuring their names are distinct from those used in the PiSmmCpuDxeSmm Driver. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 18 +++ .../SmmRelocationLib/InternalSmmRelocationLib.h| 8 +++ .../Library/SmmRelocationLib/SmmRelocationLib.c| 26 +++--- .../Library/SmmRelocationLib/X64/SmmInit.nasm | 18 +++ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm index 3d845e9e16..8916cb7d06 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -16,15 +16,15 @@ extern ASM_PFX(SmmInitHandler) extern ASM_PFX(mRebasedFlag) extern ASM_PFX(mSmmRelocationOriginalAddress) -global ASM_PFX(gPatchSmmCr3) -global ASM_PFX(gPatchSmmCr4) -global ASM_PFX(gPatchSmmCr0) +global ASM_PFX(gPatchSmmInitCr3) +global ASM_PFX(gPatchSmmInitCr4) +global ASM_PFX(gPatchSmmInitCr0) global ASM_PFX(gPatchSmmInitStack) -global ASM_PFX(gcSmiInitGdtr) +global ASM_PFX(gcSmmInitGdtr) global ASM_PFX(gcSmmInitSize) global ASM_PFX(gcSmmInitTemplate) %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 @@ -81,11 +81,11 @@ CodeSeg64: DB 0x9b DB 0xaf; LimitHigh DB 0 ; BaseHigh GDT_SIZE equ $ - NullSeg -ASM_PFX(gcSmiInitGdtr): +ASM_PFX(gcSmmInitGdtr): DW GDT_SIZE - 1 DD NullSeg SECTION .text @@ -98,22 +98,22 @@ ASM_PFX(SmmStartup): cpuid mov ebx, edx; rdmsr will change edx. keep it in ebx. and ebx, BIT20 ; extract NX capability bit shr ebx, 9 ; shift bit to IA32_EFER.NXE[BIT11] position mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr3): +ASM_PFX(gPatchSmmInitCr3): mov cr3, eax -o32 lgdt[cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))] +o32 lgdt[cs:ebp + (ASM_PFX(gcSmmInitGdtr) - ASM_PFX(SmmStartup))] mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr4): +ASM_PFX(gPatchSmmInitCr4): mov cr4, eax mov ecx, 0xc080 ; IA32_EFER MSR rdmsr or eax, ebx; set NXE bit if NX is available wrmsr mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr0): +ASM_PFX(gPatchSmmInitCr0): mov di, PROTECT_MODE_DS mov cr0, eax jmp PROTECT_MODE_CS : dword @32bit BITS 32 diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h index a9d3f271a9..ede61b956f 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h +++ b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h @@ -30,17 +30,17 @@ #include #include #include #include -extern IA32_DESCRIPTOR gcSmiInitGdtr; +extern IA32_DESCRIPTOR gcSmmInitGdtr; extern CONST UINT16 gcSmmInitSize; extern CONST UINT8 gcSmmInitTemplate[]; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr0; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr3; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr4; X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack; // // The size 0x20 must be bigger than // the size of template code of SmmInit. Currently, diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 13e62b662d..ca98f06a05 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -22,11 +22,11 @@ UINTN mNumberOfCpus= 1; EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; // // IDT used during SMM Init // -IA32_DESCRIPTOR gcSmiIdtr; +IA32_DESCRIPTOR gcSmmInitIdtr; // // Smbase for all CPUs // UINT64 *mSmBase = NULL; @@ -118,11 +118,11 @@ SmmInitHandler ( UINTN Index; // // Update SMM IDT entries' code segment and load IDT // - AsmWriteIdtr (&gcSmiIdtr); + AsmWriteIdtr (&gcSmmInitIdtr); ApicId = GetApicId (); for (Index = 0; Index < mNumberOfCpus; Index++) { if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { // @@ -167,13 +167,13 @@ SmmRelocateBases ( ASSERT (sizeof (BakBuf) >= gcSmmInitSize); // // Patch ASM code template with current CR0, CR3, and CR4 values // - PatchInstructionX86 (gPatchSmmCr0, AsmReadCr0 (), 4); - PatchInstructionX86 (gPatchSmmCr3, AsmReadCr3 (), 4); - PatchInstru
[edk2-devel] [PATCH v3 04/13] UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation
Since SMM relocation is performed serially for each CPU, there is no need to allocate buffers for all CPUs to store the SmBase address in mSmBase and the Rebased flag in mRebased. A defined global variable is sufficient. This patch focuses on the mSmBase and mRebased global variables to prevent unnecessary memory allocation for these variables. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/SmmRelocationLib.c| 201 + 1 file changed, 90 insertions(+), 111 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index ca98f06a05..3694a07cbb 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -25,31 +25,57 @@ EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; // IDT used during SMM Init // IA32_DESCRIPTOR gcSmmInitIdtr; // -// Smbase for all CPUs +// Smbase for current CPU // -UINT64 *mSmBase = NULL; +UINT64 mSmBase; // -// SmBase Rebased flag for all CPUs +// SmBase Rebased flag for current CPU // -volatile BOOLEAN *mRebased; +volatile BOOLEAN mRebased; + +/** + This function will get the SmBase for CpuIndex. + + @param[in] CpuIndexThe processor index. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. + + @retval The value of SmBase for CpuIndex. + +**/ +UINTN +GetSmBase ( + IN UINTN CpuIndex, + IN EFI_PHYSICAL_ADDRESS SmmRelocationStart, + IN UINTN TileSize + ) +{ + return (UINTN)(SmmRelocationStart) + CpuIndex * TileSize - SMM_HANDLER_OFFSET; +} /** This function will create SmBase for all CPUs. - @param[in] SmBasePointer to SmBase for all CPUs. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. @retval EFI_SUCCESS Create SmBase for all CPUs successfully. @retval OthersFailed to create SmBase for all CPUs. **/ EFI_STATUS CreateSmmBaseHob ( - IN UINT64 *SmBase + IN EFI_PHYSICAL_ADDRESS SmmRelocationStart, + IN UINTN TileSize ) { UINTN Index; SMM_BASE_HOB_DATA *SmmBaseHobData; UINT32 CpuCount; @@ -90,11 +116,11 @@ CreateSmmBaseHob ( DEBUG ((DEBUG_INFO, "CreateSmmBaseHob - SmmBaseHobData[%d]->NumberOfProcessors: %d\n", HobCount, SmmBaseHobData->NumberOfProcessors)); for (Index = 0; Index < SmmBaseHobData->NumberOfProcessors; Index++) { // // Calculate the new SMBASE address // - SmmBaseHobData->SmBase[Index] = SmBase[Index + CpuCount]; + SmmBaseHobData->SmBase[Index] = GetSmBase (Index + CpuCount, SmmRelocationStart, TileSize); DEBUG ((DEBUG_INFO, "CreateSmmBaseHob - SmmBaseHobData[%d]->SmBase[%d]: 0x%08x\n", HobCount, Index, SmmBaseHobData->SmBase[Index])); } CpuCount += NumberOfProcessorsInHob; HobCount++; @@ -126,18 +152,18 @@ SmmInitHandler ( for (Index = 0; Index < mNumberOfCpus; Index++) { if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { // // Configure SmBase. // - ConfigureSmBase (mSmBase[Index]); + ConfigureSmBase (mSmBase); // // Hook return after RSM to set SMM re-based flag // SMM re-based flag can't be set before RSM, because SMM save state context might be override // by next AP flow before it take effect. // - SemaphoreHook (Index, &mRebased[Index]); + SemaphoreHook (Index, &mRebased); return; } } ASSERT (FALSE); @@ -145,14 +171,22 @@ SmmInitHandler ( /** Relocate SmmBases for each processor. Execute on first boot and all S3 resumes + @param[in] MpServices2 Pointer to this instance of the MpServices. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. + **/ VOID SmmRelocateBases ( - VOID + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2, + IN EFI_PHYSICAL_ADDRESSSmmRelocationStart, + IN UINTN TileSize ) { UINT8 BakBuf[BACK_BUF_SIZE]; SMRAM_SAVE_STATE_MAP BakBuf2; SMRAM_SAVE_ST
[edk2-devel] [PATCH v3 05/13] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable
This patch aims on mProcessorInfo global variable, which can be defined as local variable in SmmRelocateBases(). With this patch, no need to allocate the memory for all CPUs to store the Processor Info. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/Ia32/Semaphore.c | 3 - .../SmmRelocationLib/InternalSmmRelocationLib.h| 5 -- .../Library/SmmRelocationLib/SmmRelocationLib.c| 78 +++--- .../SmmRelocationLib/SmramSaveStateConfig.c| 3 - .../Library/SmmRelocationLib/X64/Semaphore.c | 3 - 5 files changed, 24 insertions(+), 68 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c index ba329d6ba2..5d9eea3de9 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -15,28 +15,25 @@ volatile BOOLEAN *mRebasedFlag; /** Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. - @param[in] CpuIndex The processor index. @param[in] RebasedFlag A pointer to a flag that is set to TRUE immediately after AP exits SMM. **/ VOID SemaphoreHook ( - IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag ) { SMRAM_SAVE_STATE_MAP *CpuState; mRebasedFlag = RebasedFlag; CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, CpuState, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete ); } diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h index ede61b956f..d1387f2dfb 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h +++ b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h @@ -81,12 +81,10 @@ SmmRelocationSemaphoreComplete ( Hook the code executed immediately after an RSM instruction on the currently executing CPU. The mode of code executed immediately after RSM must be detected, and the appropriate hook must be selected. Always clear the auto HALT restart flag if it is set. - @param[in] CpuIndex The processor index for the currently - executing CPU. @param[in,out] CpuState Pointer to SMRAM Save State Map for the currently executing CPU. @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to 32-bit mode from 64-bit SMM. @param[in] NewInstructionPointerInstruction pointer to use if resuming to @@ -96,29 +94,26 @@ SmmRelocationSemaphoreComplete ( **/ UINT64 EFIAPI HookReturnFromSmm ( - IN UINTN CpuIndex, IN OUT SMRAM_SAVE_STATE_MAP *CpuState, IN UINT64NewInstructionPointer32, IN UINT64NewInstructionPointer ); /** Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. - @param[in] CpuIndex The processor index. @param[in] RebasedFlag A pointer to a flag that is set to TRUE immediately after AP exits SMM. **/ VOID SemaphoreHook ( - IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag ); /** This function fixes up the address of the global variable or function diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 3694a07cbb..7e65bbf929 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -14,15 +14,10 @@ #include "InternalSmmRelocationLib.h" UINTN mMaxNumberOfCpus = 1; UINTN mNumberOfCpus= 1; -// -// Record all Processors Info -// -EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; - // // IDT used during SMM Init // IA32_DESCRIPTOR gcSmmInitIdtr; @@ -138,37 +133,26 @@ VOID EFIAPI SmmInitHandler ( VOID ) { - UINT32 ApicId; - UINTN Index; - // // Update SMM IDT entries' code segment and load IDT // AsmWriteIdtr (&gcSmmInitIdtr); - ApicId = GetApicId (); - - for (Index = 0; Index < mNumberOfCpus; Index++) { -if (ApicId == (UINT32)mP
[edk2-devel] [PATCH v3 06/13] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD
Due to the definition difference of SMRAM Save State, SmmBase config in SMRAM Save State for AMD is also different. This patch provides the AmdSmmRelocationLib library instance to handle the SMRAM Save State difference. Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Acked-by: Ray Ni --- ...mmRelocationLib.inf => AmdSmmRelocationLib.inf} | 5 +- ...SaveStateConfig.c => AmdSmramSaveStateConfig.c} | 91 ++ UefiCpuPkg/UefiCpuPkg.dsc | 1 + 3 files changed, 43 insertions(+), 54 deletions(-) copy UefiCpuPkg/Library/SmmRelocationLib/{SmmRelocationLib.inf => AmdSmmRelocationLib.inf} (89%) copy UefiCpuPkg/Library/SmmRelocationLib/{SmramSaveStateConfig.c => AmdSmramSaveStateConfig.c} (47%) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf similarity index 89% copy from UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf index 45fdaf35bc..e69079fa02 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf @@ -13,18 +13,18 @@ ## [Defines] INF_VERSION= 0x00010005 BASE_NAME = SmmRelocationLib - FILE_GUID = 853E97B3-790C-4EA3-945C-8F622FC47FE8 + FILE_GUID = 65C74DCD-0D09-494A-8BFF-A64226EB8054 MODULE_TYPE= PEIM VERSION_STRING = 1.0 LIBRARY_CLASS = SmmRelocationLib [Sources] InternalSmmRelocationLib.h - SmramSaveStateConfig.c + AmdSmramSaveStateConfig.c SmmRelocationLib.c [Sources.Ia32] Ia32/Semaphore.c Ia32/SmmInit.nasm @@ -40,11 +40,10 @@ [LibraryClasses] BaseLib BaseMemoryLib CpuExceptionHandlerLib - CpuLib DebugLib HobLib LocalApicLib MemoryAllocationLib PcdLib diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c similarity index 47% copy from UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c index 76d798aba5..068ae60887 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c @@ -1,14 +1,17 @@ /** @file Config SMRAM Save State for SmmBases Relocation. + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. Copyright (c) 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalSmmRelocationLib.h" -#include +#include + +#define EFER_ADDRESS 0XC080ul /** Get the mode of the CPU at the time an SMI occurs @retval EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT 32 bit. @@ -18,44 +21,18 @@ UINT8 GetMmSaveStateRegisterLma ( VOID ) { - CPUID_VERSION_INFO_EAX RegEax; - CPUID_EXTENDED_CPU_SIG_EDX RegEdx; - UINTN FamilyId; - UINTN ModelId; - UINT32 Eax; - UINT8 SmmSaveStateRegisterLma; - - // - // Determine the mode of the CPU at the time an SMI occurs - // Intel(R) 64 and IA-32 Architectures Software Developer's Manual - // Volume 3C, Section 34.4.1.1 - // - RegEax.Uint32 = GetCpuFamilyModel (); - FamilyId = RegEax.Bits.FamilyId; - ModelId = RegEax.Bits.Model; - if ((FamilyId == 0x06) || (FamilyId == 0x0f)) { -ModelId = ModelId | RegEax.Bits.ExtendedModelId << 4; - } - - RegEdx.Uint32 = 0; - AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); - if (Eax >= CPUID_EXTENDED_CPU_SIG) { -AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &(RegEdx.Uint32)); - } + UINT8 SmmSaveStateRegisterLma; + UINT32 LMAValue; SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT; - if (RegEdx.Bits.LM) { -SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; - } - if (FamilyId == 0x06) { -if ((ModelId == 0x17) || (ModelId == 0x0f) || (ModelId == 0x1c)) { - SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; -} + LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA; + if (LMAValue) { +SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; } return SmmSaveStateRegisterLma; } @@ -69,22 +46,32 @@ VOID EFIAPI ConfigureSmBase ( IN UINT64 SmBase ) { - SMRAM_SAVE_STATE_MAP *CpuState; + AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState; - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); + AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - CpuState->x86.SMBASE = (UINT32)SmBase; + Am
[edk2-devel] [PATCH v3 07/13] OvmfPkg/SmmRelocationLib: Add library instance for OVMF
There are below 2 differences between AMD & OVMF according existing implementation: 1.The mode of the CPU check is different between the AMD & OVMF. OVMF: CpuSaveState->x86.SMMRevId & 0X AMD: LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA 2.Existing SmBase configuration is different between the AMD & OVMF. OVMF: if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { CpuSaveState->x86.SMBASE = mSmBaseForAllCpus[CpuIndex]; } else { CpuSaveState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; } AMD: AmdCpuState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; This patch provides the SmmRelocationLib library instance for OVMF to handle the logic difference, and it won't change the existing implementation code logic. Cc: Ray Ni Cc: Zeng Star Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + .../Library/SmmRelocationLib/Ia32/Semaphore.c | 0 .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 0 .../SmmRelocationLib/InternalSmmRelocationLib.h| 0 .../Library/SmmRelocationLib/SmmRelocationLib.c| 0 .../Library/SmmRelocationLib/SmmRelocationLib.inf | 3 +- .../SmmRelocationLib/SmramSaveStateConfig.c| 65 +++--- .../Library/SmmRelocationLib/X64/Semaphore.c | 0 .../Library/SmmRelocationLib/X64/SmmInit.nasm | 0 OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 14 files changed, 27 insertions(+), 47 deletions(-) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/SmmInit.nasm (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/InternalSmmRelocationLib.h (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.inf (90%) copy UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c => OvmfPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c (60%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/SmmInit.nasm (100%) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index a7540bb636..8eb6f4f24f 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -108,10 +108,11 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index b1911d6ab4..4996885301 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -124,10 +124,11 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c copy to OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm copy to OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/OvmfPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h copy to OvmfPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.c similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c copy to OvmfPkg/Li
[edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
Background: In the PiSmmCpuDxeSmm driver, SMRAM allocation for SMI handlers and processor Save State areas was traditionally performed using the Smst->AllocatePages() function during the DXE phase. The introduction of SmmRelocationLib changes this process by moving the allocation to the PEI phase, where Smst->AllocatePages() is not accessible. Instead, the allocation is now handled by partitioning the SMRAM based on the information provided by a GUID HOB (identified by gEfiSmmSMramMemoryGuid). This patch is to ensure that OVMF produces the gEfiSmmSMramMemoryGuid HOB, allowing SmmRelocationLib to reserve the necessary memory for SMBASE relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 97 +- .../Library/PlatformInitLib/PlatformInitLib.inf| 5 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 7b6e5102ad..8b98256225 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1,9 +1,9 @@ /**@file Memory Detection for Virtual Machines. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved. + Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: MemDetect.c @@ -41,10 +41,12 @@ Module Name: #include #include #include +#include + #define MEGABYTE_SHIFT 20 VOID EFIAPI PlatformQemuUc32BaseInitialization ( @@ -1027,52 +1029,73 @@ PlatformQemuInitializeRam ( // // Determine total memory size available // PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); - if (PlatformInfoHob->BootMode == BOOT_ON_S3_RESUME) { -// -// Create the following memory HOB as an exception on the S3 boot path. + // + // CpuMpPei saves the original contents of the borrowed area in permanent + // PEI RAM, in a backup buffer allocated with the normal PEI services. + // CpuMpPei restores the original contents ("returns" the borrowed area) at + // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before + // transferring control to the OS's wakeup vector in the FACS. + // + // We expect any other PEIMs that "borrow" memory similarly to CpuMpPei to + // restore the original contents. Furthermore, we expect all such PEIMs + // (CpuMpPei included) to claim the borrowed areas by producing memory + // allocation HOBs, and to honor preexistent memory allocation HOBs when + // looking for an area to borrow. + // + QemuInitializeRamBelow1gb (PlatformInfoHob); + + if (PlatformInfoHob->SmmSmramRequire) { +UINT32 TsegSize; +UINTN BufferSize; +UINT8 SmramRanges; +EFI_PEI_HOB_POINTERSHob; +EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + +TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; +PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); +PlatformAddReservedMemoryBaseSizeHob ( + PlatformInfoHob->LowMemory - TsegSize, + TsegSize, + TRUE + ); + +SmramRanges = 2; +BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); + +Hob.Raw = BuildGuidHob ( +&gEfiSmmSmramMemoryGuid, +BufferSize +); +ASSERT (Hob.Raw); + +SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); +SmramHobDescriptorBlock->NumberOfSmmReservedRegions = SmramRanges; + // -// Normally we'd create memory HOBs only on the normal boot path. However, -// CpuMpPei specifically needs such a low-memory HOB on the S3 path as -// well, for "borrowing" a subset of it temporarily, for the AP startup -// vector. +// Create first SMRAM descriptor, which contains data structures used in S3 resume. +// One page is enough for the data structure // -// CpuMpPei saves the original contents of the borrowed area in permanent -// PEI RAM, in a backup buffer allocated with the normal PEI services. -// CpuMpPei restores the original contents ("returns" the borrowed area) at -// End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before -// transferring control to the OS's wakeup vector in the FACS. +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; +SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; + // -// We expect any other PEIMs that "borrow" memory similarl
[edk2-devel] [PATCH v3 10/13] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not
Based on gSmmBaseHobGuid: If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded in the SmBase array. So, this patch check smbase relocation is done or not in SmmCpuFeaturesInitializeProcessor(). With SmmRelocationLib, gSmmBaseHobGuid will be always created. Here this patch just makes the function/logic correct. The SMM Relocation logic can be totally cleaned from the SmmCpuFeaturesLib. But it will happen in the future patch set, this patch does not target to the cleanup work. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 ++ 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 63822b126e..0a6f33c2b1 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -26,10 +26,16 @@ // // EFER register LMA bit // #define LMA BIT10 +// +// Indicate SmBase for each Processors has been relocated or not. If TRUE, +// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor(). +// +BOOLEAN mSmmCpuFeaturesSmmRelocated; + /** The constructor function @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @@ -44,13 +50,13 @@ SmmCpuFeaturesLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { // // If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded - // in the SmBase array. ASSERT it's not supported in OVMF. + // in the SmBase array. // - ASSERT (GetFirstGuidHob (&gSmmBaseHobGuid) == NULL); + mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL); // // No need to program SMRRs on our virtual platform. // return EFI_SUCCESS; @@ -90,20 +96,25 @@ SmmCpuFeaturesInitializeProcessor ( ) { AMD_SMRAM_SAVE_STATE_MAP *CpuState; // - // Configure SMBASE. + // No need to configure SMBASE if SmBase relocation has been done. // - CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( - SMM_DEFAULT_SMBASE + - SMRAM_SAVE_STATE_MAP_OFFSET - ); - if ((CpuState->x86.SMMRevId & 0x) == 0) { -CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; - } else { -CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + if (!mSmmCpuFeaturesSmmRelocated) { +// +// Configure SMBASE. +// +CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( + SMM_DEFAULT_SMBASE + + SMRAM_SAVE_STATE_MAP_OFFSET + ); +if ((CpuState->x86.SMMRevId & 0x) == 0) { + CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} else { + CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} } // // No need to program SMRRs on our virtual platform. // -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117956): https://edk2.groups.io/g/devel/message/117956 Mute This Topic: https://groups.io/mt/105593582/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v3 09/13] OvmfPkg: Refine SmmAccess implementation
This patch refines the SmmAccess implementation: 1. SmramMap will be retrieved from the gEfiSmmSmramMemoryGuid instead of original from the TSEG Memory Base register. 2. Remove the gEfiAcpiVariableGuid creation, thus the DESCRIPTOR_INDEX definition can be also cleaned. 3. The gEfiAcpiVariableGuid HOB is moved to the OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 9 +++ .../Library/PlatformInitLib/PlatformInitLib.inf| 1 + OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 ++ OvmfPkg/SmmAccess/SmmAccessPei.c | 88 ++ OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- OvmfPkg/SmmAccess/SmramInternal.c | 73 ++ OvmfPkg/SmmAccess/SmramInternal.h | 18 + 8 files changed, 51 insertions(+), 154 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 8b98256225..f451c9d80c 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -41,10 +41,11 @@ Module Name: #include #include #include +#include #include #define MEGABYTE_SHIFT 20 VOID @@ -1050,10 +1051,11 @@ PlatformQemuInitializeRam ( UINT32 TsegSize; UINTN BufferSize; UINT8 SmramRanges; EFI_PEI_HOB_POINTERSHob; EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; +VOID*GuidHob; TsegSize = PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - TsegSize); PlatformAddReservedMemoryBaseSizeHob ( PlatformInfoHob->LowMemory - TsegSize, @@ -1080,10 +1082,17 @@ PlatformQemuInitializeRam ( SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; +// +// Create gEfiAcpiVariableGuid +// +GuidHob = BuildGuidHob (&gEfiAcpiVariableGuid, sizeof (EFI_SMRAM_DESCRIPTOR)); +ASSERT (GuidHob != NULL); +CopyMem (GuidHob, &SmramHobDescriptorBlock->Descriptor[0], sizeof (EFI_SMRAM_DESCRIPTOR)); + // // Create second SMRAM descriptor, which is free and will be used by SMM foundation. // SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].CpuStart = SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf index 2bb1c0296f..21e6efa5e0 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -56,10 +56,11 @@ [LibraryClasses.X64] TdxLib [Guids] gEfiSmmSmramMemoryGuid + gEfiAcpiVariableGuid [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c index 4b9e6df37f..3371592de7 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c @@ -4,11 +4,11 @@ Q35 TSEG is expected to have been verified and set up by the SmmAccessPei driver. Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. + Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -113,12 +113,10 @@ SmmAccess2DxeGetCapabilities ( IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR*SmramMap ) { return SmramAccessGetCapabilities ( - This->LockState, - This->OpenState, SmramMapSize, SmramMap ); } diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf index d86381d0fb..d9f01a13c4 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf @@ -3,10 +3,11 @@ # # Q35 TSEG is expected to have been verified and set up by the SmmAccessPei # driver. # # Copyright (C) 2013, 2015, Red Hat, Inc. +# Copyright (c) 2024 Intel Corporation. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,17 +40,21 @@ DebugLib PcdLib PciLib UefiBootServicesTableLib UefiDr
[edk2-devel] [PATCH v3 12/13] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib
This patch just includes SmmRelocationLib in UefiPayloadPkg. Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Gua Guo Reviewed-by: Guo Dong --- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index e1b9d5ecf1..2860a659f6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -314,10 +314,12 @@ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf + [LibraryClasses.common] !if $(BOOTSPLASH_IMAGE) SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf !endif -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117957): https://edk2.groups.io/g/devel/message/117957 Mute This Topic: https://groups.io/mt/105593583/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v3 11/13] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase
This patch is to consume SmmRelocationInit for SmBase Relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/PlatformPei/Platform.c | 3 + OvmfPkg/PlatformPei/Platform.h | 5 ++ OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- .../ClearCache.c => PlatformPei/SmmRelocation.c} | 79 ++ 4 files changed, 34 insertions(+), 58 deletions(-) copy OvmfPkg/{Bhyve/PlatformPei/ClearCache.c => PlatformPei/SmmRelocation.c} (32%) diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8..df35726ff6 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -365,8 +365,11 @@ InitializePlatform ( MiscInitialization (PlatformInfoHob); } IntelTdxInitialize (); InstallFeatureControlCallback (PlatformInfoHob); + if (PlatformInfoHob->SmmSmramRequire) { +RelocateSmBase (); + } return EFI_SUCCESS; } diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 1cf44844a7..0a59547cfc 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -76,10 +76,15 @@ InstallFeatureControlCallback ( VOID InstallClearCacheCallback ( VOID ); +VOID +RelocateSmBase ( + VOID + ); + VOID AmdSevInitialize ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 20b1b98292..e036018eab 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -1,10 +1,10 @@ ## @file # Platform PEI driver # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. +# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -30,10 +30,11 @@ MemDetect.c MemTypeInfo.c Platform.c Platform.h IntelTdx.c + SmmRelocation.c [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -64,10 +65,11 @@ MtrrLib MemEncryptSevLib PcdLib CcExitLib PlatformInitLib + SmmRelocationLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase @@ -140,9 +142,10 @@ [Ppis] gEfiPeiMasterBootModePpiGuid gEfiPeiMpServicesPpiGuid gEfiPeiReadOnlyVariable2PpiGuid + gEdkiiPeiMpServices2PpiGuid [Depex] TRUE diff --git a/OvmfPkg/Bhyve/PlatformPei/ClearCache.c b/OvmfPkg/PlatformPei/SmmRelocation.c similarity index 32% copy from OvmfPkg/Bhyve/PlatformPei/ClearCache.c copy to OvmfPkg/PlatformPei/SmmRelocation.c index 9e59f31df7..1151fc9220 100644 --- a/OvmfPkg/Bhyve/PlatformPei/ClearCache.c +++ b/OvmfPkg/PlatformPei/SmmRelocation.c @@ -1,45 +1,21 @@ /**@file - Install a callback to clear cache on all processors. - This is for conformance with the TCG "Platform Reset Attack Mitigation - Specification". Because clearing the CPU caches at boot doesn't impact - performance significantly, do it unconditionally, for simplicity's - sake. + Install a callback to do smm relocation. - Copyright (C) 2018, Red Hat, Inc. + Copyright (c) 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include #include #include -#include - +#include +#include #include "Platform.h" /** - Invalidate data & instruction caches. - All APs execute this function in parallel. The BSP executes the function - separately. - - @param[in,out] WorkSpace Pointer to the input/output argument workspace -shared by all processors. -**/ -STATIC -VOID -EFIAPI -ClearCache ( - IN OUT VOID *WorkSpace - ) -{ - WriteBackInvalidateDataCache (); - InvalidateInstructionCache (); -} - -/** - Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available. + Notification function called when EDKII_PEI_MP_SERVICES2_PPI becomes available. @param[in] PeiServices Indirect reference to the PEI Services Table. @param[in] NotifyDescriptor Address of the notification descriptor data structure. @param[in] Ppi Address of the PPI that was installed. @@ -48,68 +24,57 @@ ClearCache ( function is ignored. **/ STATIC EFI_STATUS EFIAPI -ClearCacheOnMpServicesAvailable ( +OnMpServices2Available ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi ) { - EFI_PEI_MP_SERVICES_PPI *MpServices; - EFI_STATUS Status; + EDKII_PEI_MP_SERVICES2_PPI *MpServices2; + EFI_STATUS Status; DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __func__)); + MpServices2 = Ppi; + // - // Clear
[edk2-devel] [PATCH v3 13/13] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic
This patch is to remove legacy SmBase relocation in PiSmmCpuDxeSmm Driver. The responsibility for SmBase relocation has been transferred to the SmmRelocationInit interface, which now handles the following tasks: 1. Relocates the SmBase for each processor. 2. Generates the gSmmBaseHobGuid HOB. As a result of this change, the PiSmmCpuDxeSmm driver's role in SMM environment setup is simplified to: 1. Utilize the gSmmBaseHobGuid to determine the SmBase. 2. Perform the ExecuteFirstSmiInit() to do early SMM initialization. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c| 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 42 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 96 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c| 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 331 +++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h| 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c| 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm | 146 11 files changed, 39 insertions(+), 854 deletions(-) delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index b14c289a27..d67fb49890 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -639,27 +639,14 @@ InitializeCpuProcedure ( // InitializeCpuBeforeRebase (IsBsp); } if (IsBsp) { -DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated is %d\n", mSmmRelocated)); - // -// Check whether Smm Relocation is done or not. -// If not, will do the SmmBases Relocation here!!! +// Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. // -if (!mSmmRelocated) { - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); -} else { - // - // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. - // - ExecuteFirstSmiInit (); -} +ExecuteFirstSmiInit (); } // // Skip initialization if mAcpiCpuData is not valid // @@ -978,13 +965,13 @@ InitSmmS3ResumeState ( SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); if (SmmS3ResumeState->SmmS3StackBase == 0) { SmmS3ResumeState->SmmS3StackSize = 0; } -SmmS3ResumeState->SmmS3Cr0 = mSmmCr0; +SmmS3ResumeState->SmmS3Cr0 = (UINT32)AsmReadCr0 (); SmmS3ResumeState->SmmS3Cr3 = Cr3; -SmmS3ResumeState->SmmS3Cr4 = mSmmCr4; +SmmS3ResumeState->SmmS3Cr4 = (UINT32)AsmReadCr4 (); if (sizeof (UINTN) == sizeof (UINT64)) { SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64; } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c deleted file mode 100644 index a9fcc89dda..00 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - - mRebasedFlag = RebasedFlag; - - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/
Re: [edk2-devel] [PATCH v3 05/13] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable
Sure, I will you split the removal of CpuIndex parameter in a new patch. Thanks, Jiaxin From: Ni, Ray Sent: Thursday, April 18, 2024 3:48 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R Subject: Re: [PATCH v3 05/13] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable UINT64 EFIAPI HookReturnFromSmm ( - IN UINTN CpuIndex, IN OUT SMRAM_SAVE_STATE_MAP *CpuState, IN UINT64NewInstructionPointer32, IN UINT64NewInstructionPointer ) { diff --git a/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c index 53f3084363..cd6778e3fc 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c @@ -26,18 +26,16 @@ SmmRelocationSemaphoreComplete32 ( /** Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. - @param[in] CpuIndex The processor index. @param[in] RebasedFlag A pointer to a flag that is set to TRUE immediately after AP exits SMM. **/ VOID SemaphoreHook ( - IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag ) { SMRAM_SAVE_STATE_MAP *CpuState; UINTN TempValue; @@ -49,11 +47,10 @@ SemaphoreHook ( 4 ); CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); mSmmRelocationOriginalAddress = HookReturnFromSmm ( -CpuIndex, CpuState, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete32, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete ); [Ray] Can you split the removal of CpuIndex parameter in a new patch? Others look good to me. -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117963): https://edk2.groups.io/g/devel/message/117963 Mute This Topic: https://groups.io/mt/105593573/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
Hi Gerd, Could you help review & check below OVMF related patches? > OvmfPkg/SmmRelocationLib: Add library instance for OVMF > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > OvmfPkg: Refine SmmAccess implementation > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase Thanks, Jiaxin > -Original Message- > From: devel@edk2.groups.io On Behalf Of Wu, > Jiaxin > Sent: Thursday, April 18, 2024 2:56 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Zeng, Star ; Gerd > Hoffmann ; Kumar, Rahul R ; > Dong, Guo ; Rhodes, Sean ; > Lu, James ; Guo, Gua ; Ard > Biesheuvel ; Yao, Jiewen > ; Abdul Lateef Attar ; > Abner Chang ; Tom Lendacky > > Subject: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > PR: https://github.com/tianocore/edk2/pull/5546 > > Intel plans to separate the smbase relocation logic from > PiSmmCpuDxeSmm driver, and the related behavior will be > moved to the new interface defined by the SmmRelocationLib > class. > > The SmmRelocationLib class provides the SmmRelocationInit() > interface for platform to do the smbase relocation, which > shall provide below 2 functionalities: > 1. Relocate smbases for each processor. > 2. Create the gSmmBaseHobGuid HOB. > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > a later phase) can be simplfied as below for SMM init: > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > for each Processor. > 2. Execute the early SMM Init. > > Cc: Ray Ni > Cc: Zeng Star > Cc: Gerd Hoffmann > Cc: Rahul Kumar > Cc: Guo Dong > Cc: Sean Rhodes > Cc: James Lu > Cc: Gua Guo > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Abdul Lateef Attar > Cc: Abner Chang > Cc: Tom Lendacky > Signed-off-by: Jiaxin Wu > > Jiaxin Wu (13): > UefiCpuPkg: Add SmmRelocationLib class > UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance > UefiCpuPkg/SmmRelocationLib: Rename global variables > UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation > UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD > OvmfPkg/SmmRelocationLib: Add library instance for OVMF > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > OvmfPkg: Refine SmmAccess implementation > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase > UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib > UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic > > OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + > OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + > OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- > .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- > .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- > .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- > .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + > .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 > + > .../Library/SmmRelocationLib/SmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/SmramSaveStateConfig.c| 100 > .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- > OvmfPkg/Microvm/MicrovmX64.dsc | 1 + > OvmfPkg/OvmfPkgIa32.dsc| 1 + > OvmfPkg/OvmfPkgIa32X64.dsc | 1 + > OvmfPkg/OvmfPkgX64.dsc | 1 + > OvmfPkg/PlatformPei/Platform.c | 3 + > OvmfPkg/PlatformPei/Platform.h | 5 + > OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- > OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ > OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- > OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + > OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +--- > OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- > OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- > OvmfPkg/SmmAccess/SmramInternal.h | 18 +- > UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ > .../SmmRelocationLib/AmdSmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 125 + > .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- > .../SmmRelocationLib/In
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
Hi Tom & Abner, Could you help check & review AMD related patch? > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD Thanks, Jiaxin > -Original Message- > From: devel@edk2.groups.io On Behalf Of Wu, > Jiaxin > Sent: Thursday, April 18, 2024 2:56 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Zeng, Star ; Gerd > Hoffmann ; Kumar, Rahul R ; > Dong, Guo ; Rhodes, Sean ; > Lu, James ; Guo, Gua ; Ard > Biesheuvel ; Yao, Jiewen > ; Abdul Lateef Attar ; > Abner Chang ; Tom Lendacky > > Subject: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > PR: https://github.com/tianocore/edk2/pull/5546 > > Intel plans to separate the smbase relocation logic from > PiSmmCpuDxeSmm driver, and the related behavior will be > moved to the new interface defined by the SmmRelocationLib > class. > > The SmmRelocationLib class provides the SmmRelocationInit() > interface for platform to do the smbase relocation, which > shall provide below 2 functionalities: > 1. Relocate smbases for each processor. > 2. Create the gSmmBaseHobGuid HOB. > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > a later phase) can be simplfied as below for SMM init: > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > for each Processor. > 2. Execute the early SMM Init. > > Cc: Ray Ni > Cc: Zeng Star > Cc: Gerd Hoffmann > Cc: Rahul Kumar > Cc: Guo Dong > Cc: Sean Rhodes > Cc: James Lu > Cc: Gua Guo > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Abdul Lateef Attar > Cc: Abner Chang > Cc: Tom Lendacky > Signed-off-by: Jiaxin Wu > > Jiaxin Wu (13): > UefiCpuPkg: Add SmmRelocationLib class > UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance > UefiCpuPkg/SmmRelocationLib: Rename global variables > UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation > UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD > OvmfPkg/SmmRelocationLib: Add library instance for OVMF > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > OvmfPkg: Refine SmmAccess implementation > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase > UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib > UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic > > OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + > OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + > OvmfPkg/Library/PlatformInitLib/MemDetect.c| 104 ++-- > .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- > .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- > .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- > .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + > .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 > + > .../Library/SmmRelocationLib/SmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/SmramSaveStateConfig.c| 100 > .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- > OvmfPkg/Microvm/MicrovmX64.dsc | 1 + > OvmfPkg/OvmfPkgIa32.dsc| 1 + > OvmfPkg/OvmfPkgIa32X64.dsc | 1 + > OvmfPkg/OvmfPkgX64.dsc | 1 + > OvmfPkg/PlatformPei/Platform.c | 3 + > OvmfPkg/PlatformPei/Platform.h | 5 + > OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- > OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ > OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- > OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + > OvmfPkg/SmmAccess/SmmAccessPei.c | 88 +--- > OvmfPkg/SmmAccess/SmmAccessPei.inf | 7 +- > OvmfPkg/SmmAccess/SmramInternal.c | 73 +-- > OvmfPkg/SmmAccess/SmramInternal.h | 18 +- > UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ > .../SmmRelocationLib/AmdSmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 125 + > .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- > .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + > .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 > + > .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ > .../SmmRelocationLib/SmramSa
Re: [edk2-devel] [PATCH v3 13/13] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic
Ok, thanks Ray, I will follow the change in next version. From: Ni, Ray Sent: Thursday, April 18, 2024 4:15 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R Subject: Re: [PATCH v3 13/13] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic + // + // Check whether the Required TileSize is enough. + // + 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)); +FreePool (mCpuHotPlugData.SmBase); +FreePool (gSmmCpuPrivate->ProcessorInfo); +CpuDeadLoop (); +return RETURN_BUFFER_TOO_SMALL; } [Ray] Can you move the "TileSize" check just below the original TileSize calculation logic? Others look good to me. -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118002): https://edk2.groups.io/g/devel/message/118002 Mute This Topic: https://groups.io/mt/105593584/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
Oh, sorry, I missed the that email. If so, that's great! Thanks Ray & Abner & Abdul. From: Chang, Abner Sent: Friday, April 19, 2024 11:47 AM To: Ni, Ray ; Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R ; Dong, Guo ; Rhodes, Sean ; Lu, James ; Guo, Gua ; Ard Biesheuvel ; Yao, Jiewen ; Attar, AbdulLateef (Abdul Lateef) ; Lendacky, Thomas Subject: Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib [AMD Official Use Only - General] Right, Abdul's RB is sufficient! Thanks Abner From: Ni, Ray mailto:ray...@intel.com>> Sent: Friday, April 19, 2024 11:35:17 AM To: Wu, Jiaxin mailto:jiaxin...@intel.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>>; Attar, AbdulLateef (Abdul Lateef) mailto:abdullateef.at...@amd.com>>; Chang, Abner mailto:abner.ch...@amd.com>>; Lendacky, Thomas mailto:thomas.lenda...@amd.com>> Subject: Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. Jiaxin, I see Abdul from AMD has given R-B. I assume that's sufficient for merging this patch. Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Thursday, April 18, 2024 16:03 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>>; Wu, Jiaxin mailto:jiaxin...@intel.com>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>>; Abdul Lateef Attar mailto:abdullateef.at...@amd.com>>; Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky mailto:thomas.lenda...@amd.com>> Subject: RE: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib Hi Tom & Abner, Could you help check & review AMD related patch? > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD Thanks, Jiaxin > -Original Message- > From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> > mailto:devel@edk2.groups.io>> On Behalf Of Wu, > Jiaxin > Sent: Thursday, April 18, 2024 2:56 PM > To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> > Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star > mailto:star.z...@intel.com>>; Gerd > Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R > mailto:rahul.r.ku...@intel.com>>; > Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean > mailto:sean@starlabs.systems>>; > Lu, James mailto:james...@intel.com>>; Guo, Gua > mailto:gua@intel.com>>; Ard > Biesheuvel mailto:ardb+tianoc...@kernel.org>>; > Yao, Jiewen > mailto:jiewen@intel.com>>; Abdul Lateef Attar > mailto:abdullateef.at...@amd.com>>; > Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky > mailto:thomas.lenda...@amd.com>> > Subject: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > PR: https://github.com/tianocore/edk2/pull/5546 > > Intel plans to separate the smbase relocation logic from > PiSmmCpuDxeSmm driver, and the related behavior will be > moved to the new interface defined by the SmmRelocationLib > class. > > The SmmRelocationLib class provides the SmmRelocationInit() > interface for platform to do the smbase relocation, which > shall provide below 2 functionalities: > 1. Relocate smbases for each processor. > 2. Create the gSmmBaseHobGuid HOB. > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > a later phase) can be simplfied as below for SMM init: > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > for each Processor. > 2. Execute the early SMM Init. > > Cc: Ray Ni mailto:ray...@intel.com>> > Cc: Zeng Star mailto:star.z...@intel.com>> > Cc: Gerd Hoffmann mailto:kra...@redhat.com>> > Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> > Cc: G
Re: [edk2-devel] [PATCH 1/1] UefiCpuPkg/SmmCpuSyncLib: Add MM_STANDALONE tag.
Reviewed-by: Jiaxin Wu > -Original Message- > From: Xie, Yuanhao > Sent: Tuesday, April 23, 2024 1:57 PM > To: devel@edk2.groups.io > Cc: Xie, Yuanhao ; Dong, Eric > ; Ni, Ray ; Kumar, Rahul R > ; Gerd Hoffmann ; Wu, Jiaxin > > Subject: [PATCH 1/1] UefiCpuPkg/SmmCpuSyncLib: Add MM_STANDALONE > tag. > > Declares in the .inf file that the current component is an MM_STANDALONE > > Signed-off-by: Yuanhao Xie > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > Cc: Jiaxin Wu > --- > UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf > b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf > index 6b0d49c30a..2cfbd27b41 100644 > --- a/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf > +++ b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf > @@ -3,7 +3,7 @@ > # > # This is SMM CPU Synchronization lib used for SMM CPU sync operations. > # > -# Copyright (c) 2023, Intel Corporation. All rights reserved. > +# Copyright (c) 2024, Intel Corporation. All rights reserved. > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > ## > @@ -13,7 +13,7 @@ >BASE_NAME = SmmCpuSyncLib >FILE_GUID = 1ca1bc1a-16a4-46ef-956a-ca500fd3381f >MODULE_TYPE= DXE_SMM_DRIVER > - LIBRARY_CLASS = SmmCpuSyncLib|DXE_SMM_DRIVER > + LIBRARY_CLASS = SmmCpuSyncLib|DXE_SMM_DRIVER > MM_STANDALONE > > [Sources] >SmmCpuSyncLib.c > -- > 2.39.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118126): https://edk2.groups.io/g/devel/message/118126 Mute This Topic: https://groups.io/mt/105685282/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
Thanks Gerd, I will try the S3 on OVMF. And for AmdSmmRelocationLib usage in OVMF, do you prefer: 1. use the AmdSmmRelocationLib directly in this patch set? Or 2. still keep the original to create the OvmfPkg/SmmRelocationLib, and clean the code in the future patch? Both are fine to me, depends on you. Thanks, Jiaxin > -Original Message- > From: Gerd Hoffmann > Sent: Monday, April 22, 2024 3:58 PM > To: Wu, Jiaxin > Cc: devel@edk2.groups.io; Ni, Ray ; Zeng, Star > ; Kumar, Rahul R ; Dong, > Guo ; Rhodes, Sean ; Lu, > James ; Guo, Gua ; Ard Biesheuvel > ; Yao, Jiewen ; Abdul > Lateef Attar ; Abner Chang > ; Tom Lendacky > Subject: Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > On Thu, Apr 18, 2024 at 08:02:43AM +, Wu, Jiaxin wrote: > > Hi Gerd, > > > > Could you help review & check below OVMF related patches? > > > > > OvmfPkg/SmmRelocationLib: Add library instance for OVMF > > > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > > > OvmfPkg: Refine SmmAccess implementation > > > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > > > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase > > Patch series breaks S3 suspend support in OVMF. > > On a quick check (OvmfPkgX64 only) using AmdSmmRelocationLib.inf for > OVMF seems to work fine (S3 is broken too though). > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118128): https://edk2.groups.io/g/devel/message/118128 Mute This Topic: https://groups.io/mt/105593568/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
As I documented in the comment: This patch provides the SmmRelocationLib library instance for OVMF to handle the logic difference, and it won't change the existing implementation code logic. But as I said, it depends on you. I will drop the OvmfPkg/SmmRelocationLib since confirmed we can use the ADM version for OVMF. Thanks, Jiaxin > -Original Message- > From: Gerd Hoffmann > Sent: Tuesday, April 23, 2024 4:43 PM > To: Wu, Jiaxin > Cc: devel@edk2.groups.io; Ni, Ray ; Zeng, Star > ; Kumar, Rahul R ; Dong, > Guo ; Rhodes, Sean ; Lu, > James ; Guo, Gua ; Ard Biesheuvel > ; Yao, Jiewen ; Abdul > Lateef Attar ; Abner Chang > ; Tom Lendacky > Subject: Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > On Tue, Apr 23, 2024 at 07:31:18AM +, Wu, Jiaxin wrote: > > Thanks Gerd, I will try the S3 on OVMF. > > > > And for AmdSmmRelocationLib usage in OVMF, do you prefer: > > 1. use the AmdSmmRelocationLib directly in this patch set? Or > > 2. still keep the original to create the OvmfPkg/SmmRelocationLib, and clean > the code in the future patch? > > Clear preference for (1), why introduce OvmfPkg/SmmRelocationLib only to > delete it shortly thereafter? > > take care, > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118137): https://edk2.groups.io/g/devel/message/118137 Mute This Topic: https://groups.io/mt/105593568/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
> > > +SmramHobDescriptorBlock = > (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); > > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = > PlatformInfoHob->LowMemory - TsegSize; > > +SmramHobDescriptorBlock->Descriptor[0].CpuStart = > PlatformInfoHob->LowMemory - TsegSize; > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; > > +SmramHobDescriptorBlock->Descriptor[0].RegionState = > EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; > > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = > SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; > > +SmramHobDescriptorBlock->Descriptor[1].CpuStart = > SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalSize = TsegSize - > EFI_PAGE_SIZE; > > +SmramHobDescriptorBlock->Descriptor[1].RegionState = > EFI_SMRAM_CLOSED | EFI_CACHEABLE; > > This is not going to fly. > > First, smram allocation doesn't work that way. Have a look at > OvmfPkg/SmmAccess. I guess that easily explains why this series > breaks S3 suspend. > Oh? Could you explain a bit more for 1) how smram allocation works? 2) what's the possible reason break the S3? I haven't check yet. > Second, storing these descriptors in a HOB (which is PEI memory) > is questionable from a security point of view. > HOB is only to expose the SMRAM address and size, not the contents in smram, what's the security concern? Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118138): https://edk2.groups.io/g/devel/message/118138 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
More info: I quick dump the SMRAM info with original SmmAccess implementation, it's same as I produced in the gEfiSmmSmramMemoryGuid HOB. SmmAccess: SmmAccessPeiEntryPoint: SMRAM map follows, 2 entries SmmAccessPeiEntryPoint: 7F00 1000 7F00 1A---> for the S3 Resume in gEfiAcpiVariableGuid SmmAccessPeiEntryPoint: 7F001000 FFF000 7F001000A Smram map in the gEfiSmmSmramMemoryGuid: PlatformQemuInitializeRam: 7F00 1000 7F00 1A--> ---> for the S3 Resume in gEfiAcpiVariableGuid PlatformQemuInitializeRam: 7F001000 FFF000 7F001000A Thanks, Jiaxin > -Original Message- > From: Wu, Jiaxin > Sent: Tuesday, April 23, 2024 8:19 PM > To: Gerd Hoffmann > Cc: devel@edk2.groups.io; Ard Biesheuvel ; Yao, > Jiewen ; Ni, Ray > Subject: RE: [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create > gEfiSmmSmramMemoryGuid > > > > > > +SmramHobDescriptorBlock = > > (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); > > > > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = > > PlatformInfoHob->LowMemory - TsegSize; > > > +SmramHobDescriptorBlock->Descriptor[0].CpuStart = > > PlatformInfoHob->LowMemory - TsegSize; > > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = > EFI_PAGE_SIZE; > > > +SmramHobDescriptorBlock->Descriptor[0].RegionState = > > EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; > > > > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = > > SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; > > > +SmramHobDescriptorBlock->Descriptor[1].CpuStart = > > SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; > > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalSize = TsegSize - > > EFI_PAGE_SIZE; > > > +SmramHobDescriptorBlock->Descriptor[1].RegionState = > > EFI_SMRAM_CLOSED | EFI_CACHEABLE; > > > > This is not going to fly. > > > > First, smram allocation doesn't work that way. Have a look at > > OvmfPkg/SmmAccess. I guess that easily explains why this series > > breaks S3 suspend. > > > > Oh? Could you explain a bit more for 1) how smram allocation works? 2) > what's the possible reason break the S3? I haven't check yet. > > > Second, storing these descriptors in a HOB (which is PEI memory) > > is questionable from a security point of view. > > > > HOB is only to expose the SMRAM address and size, not the contents in > smram, what's the security concern? > > > Thanks, > Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118141): https://edk2.groups.io/g/devel/message/118141 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
Hi Gerd, There was the issue in my patch to change the smm access driver: SmmAccessPeiOpen(), I removed below code due to the comment in original code that indicate the DescriptorIndex is not considered at all: ... if (DescriptorIndex >= DescIdxCount) { return EFI_INVALID_PARAMETER; } // // According to current practice, *DescriptorIndex is not considered at all*, // beyond validating it. // ... But it's important for smmlockboxpeilib to check the return status of SmmAccessPeiOpen (EFI_INVALID_PARAMETER) to continue the RestoreLockBox(): for (Index = 0; !EFI_ERROR (Status); Index++) { Status = SmmAccess->Open ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), SmmAccess, Index); } So, it hangs at for() loop once I removed above code in the SmmAccessPeiOpen!!! After that fix, I still found S3 doesn't work, I checked the master code without my patch. It also can't work for S3, which means S3 broken on latest master code. You can also double confirm the log that stop as below: ... S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE S3BootScriptDone - Success Call AsmDisablePaging64() to return to S3 Resume in PEI Phase Install PPI: 88C9D306-0900-4EB5-8260-3E2DBEDA1F89 Install PPI: 605EA650-C65C-42E1-BA80-91A52AB618C6 Notify: PPI Guid: 605EA650-C65C-42E1-BA80-91A52AB618C6, Peim notify entry point: 82B5B0 Signal EndOfS3Resume Signal 96F5296D-05F7-4F3C-8467-E456890E0CB5 to SMM - Enter Locate Smm Communicate Ppi failed (Not Found)! Transfer to 16bit OS waking vector - 991F0 > hang here!!! Thanks, Jiaxin > -Original Message- > From: Wu, Jiaxin > Sent: Tuesday, April 23, 2024 9:20 PM > To: Gerd Hoffmann > Cc: devel@edk2.groups.io; Ard Biesheuvel ; Yao, > Jiewen ; Ni, Ray > Subject: RE: [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create > gEfiSmmSmramMemoryGuid > > More info: > I quick dump the SMRAM info with original SmmAccess implementation, it's > same as I produced in the gEfiSmmSmramMemoryGuid HOB. > > SmmAccess: > SmmAccessPeiEntryPoint: SMRAM map follows, 2 entries > SmmAccessPeiEntryPoint: 7F00 1000 > 7F00 > 1A---> for the S3 Resume in gEfiAcpiVariableGuid > SmmAccessPeiEntryPoint: 7F001000 FFF000 > 7F001000 > A > > Smram map in the gEfiSmmSmramMemoryGuid: > PlatformQemuInitializeRam: 7F00 1000 >7F00 > 1A--> ---> for the S3 Resume in gEfiAcpiVariableGuid > PlatformQemuInitializeRam: 7F001000 FFF000 >7F001000 > A > > > Thanks, > Jiaxin > > > -Original Message- > > From: Wu, Jiaxin > > Sent: Tuesday, April 23, 2024 8:19 PM > > To: Gerd Hoffmann > > Cc: devel@edk2.groups.io; Ard Biesheuvel ; > Yao, > > Jiewen ; Ni, Ray > > Subject: RE: [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create > > gEfiSmmSmramMemoryGuid > > > > > > > > > +SmramHobDescriptorBlock = > > > (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); > > > > > > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = > > > PlatformInfoHob->LowMemory - TsegSize; > > > > +SmramHobDescriptorBlock->Descriptor[0].CpuStart = > > > PlatformInfoHob->LowMemory - TsegSize; > > > > +SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = > > EFI_PAGE_SIZE; > > > > +SmramHobDescriptorBlock->Descriptor[0].RegionState = > > > EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; > > > > > > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = > > > SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; > > > > +SmramHobDescriptorBlock->Descriptor[1].CpuStart = > > > SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; > > > > +SmramHobDescriptorBlock->Descriptor[1].PhysicalSize = TsegSize - > > > EFI_PAGE_SIZE; > > > > +SmramHobDescriptorBlock->Descriptor[1].RegionState = > > > EFI_SMRAM_CLOSED | EFI_CACHEABLE; > > > > > > This is not going to fly. > > > > > > First, smram allocation doesn't work that way. Have a look at > > > OvmfPkg/SmmAccess. I guess that easily explains why this series > > > breaks S3 suspend. > > > > > > > Oh? Could you explain a bit more for 1) how smram allocation works? 2) > > what's the possible reason break the S3? I haven't check yet. > > > > > Second, storing these descriptors in a HOB (which is PEI memory) > > > is questionable from a security point of view. > > > > > > > HOB is only to expose the SMRAM address and size, not the contents in > > smram, what's the security concern? > > > > > > Thanks, > > Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118174): https://edk2.groups.io/g/devel/message/118174 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
Hi Gerd, AMD version is not work for IA32X64 ovmf. I checked the detailed: CpuSaveState->x64 is always used for OVMF no matter IA32 or X64, while AMD is not, which is decided by the MSR EFER_ADDRESS LMA bit check. There is a potential issue/open in OVMF why need use the X64 CpuSaveState for IA32. Before this open resolved, I still prefer to keep use the ovmf specific lib instance. Thanks, Jiaxin > -Original Message- > From: Wu, Jiaxin > Sent: Tuesday, April 23, 2024 8:16 PM > To: Gerd Hoffmann > Cc: devel@edk2.groups.io; Ni, Ray ; Zeng, Star > ; Kumar, Rahul R ; Dong, > Guo ; Rhodes, Sean ; Lu, > James ; Guo, Gua ; Ard Biesheuvel > ; Yao, Jiewen ; Abdul > Lateef Attar ; Abner Chang > ; Tom Lendacky > Subject: RE: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > As I documented in the comment: > > This patch provides the SmmRelocationLib library instance > for OVMF to handle the logic difference, and it won't change > the existing implementation code logic. > > But as I said, it depends on you. I will drop the OvmfPkg/SmmRelocationLib > since confirmed we can use the ADM version for OVMF. > > Thanks, > Jiaxin > > > -Original Message----- > > From: Gerd Hoffmann > > Sent: Tuesday, April 23, 2024 4:43 PM > > To: Wu, Jiaxin > > Cc: devel@edk2.groups.io; Ni, Ray ; Zeng, Star > > ; Kumar, Rahul R ; Dong, > > Guo ; Rhodes, Sean ; Lu, > > James ; Guo, Gua ; Ard > Biesheuvel > > ; Yao, Jiewen ; Abdul > > Lateef Attar ; Abner Chang > > ; Tom Lendacky > > Subject: Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib > > > > On Tue, Apr 23, 2024 at 07:31:18AM +, Wu, Jiaxin wrote: > > > Thanks Gerd, I will try the S3 on OVMF. > > > > > > And for AmdSmmRelocationLib usage in OVMF, do you prefer: > > > 1. use the AmdSmmRelocationLib directly in this patch set? Or > > > 2. still keep the original to create the OvmfPkg/SmmRelocationLib, and > clean > > the code in the future patch? > > > > Clear preference for (1), why introduce OvmfPkg/SmmRelocationLib only to > > delete it shortly thereafter? > > > > take care, > > Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118180): https://edk2.groups.io/g/devel/message/118180 Mute This Topic: https://groups.io/mt/105593568/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 00/13] Add SmmRelocationLib
> > > > AMD version is not work for IA32X64 ovmf. > > > > I checked the detailed: CpuSaveState->x64 is always used for OVMF no > matter IA32 or X64, while AMD is not, which is decided by the MSR > EFER_ADDRESS LMA bit check. > > Hmm, probably because only PEI runs in 32-bit mode whereas DXE and SMM > run in 64-bit mode, so 32-bit PEI has to prepare things for the 64-bit > SMM. > > > There is a potential issue/open in OVMF why need use the X64 > > CpuSaveState for IA32. Before this open resolved, I still prefer to > > keep use the ovmf specific lib instance. > > Yes, lets stick to the ovmf version for now, and maybe remove it later > when fixing the ia32 ovmf builds. > Ok, no problem. -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118249): https://edk2.groups.io/g/devel/message/118249 Mute This Topic: https://groups.io/mt/105593568/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
> > > Transfer to 16bit OS waking vector - 991F0 > hang here!!! > > That is the last ovmf message of a successful S3 resume, after that the > OS should have back control. Looks fine to me. > Great, got it. Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118250): https://edk2.groups.io/g/devel/message/118250 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
> > SmramInternal.c handles that. It creates two regions, one is a page at > the start of SMRAM where S3 state is stored (and marked as allocated), > one is all the rest. > Yes, the same logic is moved to the OvmfPkg/Library/PlatformInitLib/MemDetect.c: // // Create first SMRAM descriptor, which contains data structures used in S3 resume. // One page is enough for the data structure // SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].CpuStart = PlatformInfoHob->LowMemory - TsegSize; SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; // // Create second SMRAM descriptor, which is free and will be used by SMM foundation. // SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].CpuStart = SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].PhysicalSize = TsegSize - EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE; > So, if you need some smram to initialize SMM in PEI I'd suggest to > either add a third region, or make the first region larger. > > It's not clear to me why you put the logic upside down and introduce > that HOB in the first place. > Let me explain more why need this change: 1. The EFI_SMM_SMRAM_MEMORY_GUID HOB, as defined in the PI specification, is used to describe the SMRAM memory regions supported by the platform. This HOB should be produced during the memory detection phase to align with the PI spec. 2. In addition to the memory reserved for ACPI S3 resume, an increasing number of features require reserving SMRAM for specific purposes, such as SmmRelocation. Other advanced features in Intel platforms also necessitate this. The implementation of these features varies and is entirely dependent on the platform. This is why an increasing number of platforms are adopting the EFI_SMM_SMRAM_MEMORY_GUID HOB for SMRAM description. 3. It is crucial that the SMRAM information remains consistent when retrieved from the platform, whether through the SMM ACCESS PPI/Protocol or the EFI_SMM_SMRAM_MEMORY_GUID HOB. Inconsistencies can lead to unexpected issues, most commonly memory region conflicts. 4. The SMM ACCESS PPI/Protocol can be naturally implemented for general use. The common approach is to utilize the EFI_SMM_SMRAM_MEMORY_GUID HOB. For reference, see the existing implementation in the EDK2 repository at edk2/UefiPayloadPkg/SmmAccessDxe/SmmAccessDxe.inf and edk2-platforms/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLib/PeiSmmAccessLib.inf. For the reasons mentioned, we are moving the SMRAM memory regions to HOBs and allowing SMM access to consume these HOBs. I will add the above info into commit message. > > Storing anything SMM related outside SMRAM makes me nervous. > I'd strongly suggest to avoid that. > > It might be that in this specific case it is not a problem. But it > needs very careful review of the implications (which I have not done) > and you have to hope you don't miss a possible attack vector, such as > someone modifying the HOB and the firmware then storing SMM data + code > outside SMRAM. > Understand, but here is the case we can record the info in non-smram since PI spec exposes that, there is no difference the info retrieved from PPI/ non-smm Protocol or the non-smram. Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118253): https://edk2.groups.io/g/devel/message/118253 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
> > Creating the EFI_SMM_SMRAM_MEMORY_GUID HOB should be moved to its > own > function. Also move over the comments from SmmAccess describing the > regions please. > > Adding a reference to the PI spec section describing this would be good > too. > Got it, I will refine the patch to V4 based on your comments. Thanks, Jiaxin -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118276): https://edk2.groups.io/g/devel/message/118276 Mute This Topic: https://groups.io/mt/105593577/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib
PR: https://github.com/tianocore/edk2/pull/5546 Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Tom Lendacky Signed-off-by: Jiaxin Wu Jiaxin Wu (14): UefiCpuPkg: Add SmmRelocationLib class UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance UefiCpuPkg/SmmRelocationLib: Rename global variables UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex UefiCpuPkg/SmmRelocationLib: Add library instance for AMD OvmfPkg/SmmRelocationLib: Add library instance for OVMF OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg: Refine SmmAccess implementation OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Library/PlatformInitLib/MemDetect.c| 135 +++-- .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../Library/SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 60 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 100 .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/Platform.c | 3 + OvmfPkg/PlatformPei/Platform.h | 5 + OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 116 ++--- OvmfPkg/SmmAccess/SmmAccessPei.inf | 11 +- OvmfPkg/SmmAccess/SmramInternal.c | 72 +-- OvmfPkg/SmmAccess/SmramInternal.h | 19 +- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ .../SmmRelocationLib/AmdSmmRelocationLib.inf | 60 +++ .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 125 + .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- .../SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 136 + .../SmmRelocationLib}/X64/Semaphore.c | 13 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 334 ++--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 +--- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + UefiPayloadPkg/UefiPayloadPkg.dsc | 2 + 48 files changed, 2578 insertions(+), 796 deletions(-) copy {UefiCpuPkg/PiSmmCpuDxeSmm => OvmfPkg/Library/SmmRelocationLib}/Ia32/Semaphore.c (71%) copy {UefiCpuPkg/PiSmmCpuDxeSmm => OvmfPkg/Library/SmmRelocationLib
[edk2-devel] [PATCH v4 01/14] UefiCpuPkg: Add SmmRelocationLib class
Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) shall: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. This patch just provides the SmmRelocationLib class. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 +++ UefiCpuPkg/UefiCpuPkg.dec | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmRelocationLib.h diff --git a/UefiCpuPkg/Include/Library/SmmRelocationLib.h b/UefiCpuPkg/Include/Library/SmmRelocationLib.h new file mode 100644 index 00..999a5b46d1 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmRelocationLib.h @@ -0,0 +1,42 @@ +/** @file + Header file for SMM Relocation Library. + + The SmmRelocationLib class provides the SmmRelocationInit() + interface for platform to do the smbase relocation, which + shall provide below 2 functionalities: + 1. Relocate SmBases for each processor. + 2. Create the SmBase HOB (gSmmBaseHobGuid). + + With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) + shall: + 1. Consume the gSmmBaseHobGuid for the relocated smbase for each Processor. + 2. Execute early SMM init. + + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_RELOCATION_LIB_H_ +#define SMM_RELOCATION_LIB_H_ + +#include + +/** + CPU SmmBase Relocation Init. + + This function is to relocate CPU SmmBase. + + @param[in] MpServices2Pointer to this instance of the MpServices. + + @retval EFI_SUCCESS CPU SmmBase Relocated successfully. + @retval OthersCPU SmmBase Relocation failed. + +**/ +EFI_STATUS +EFIAPI +SmmRelocationInit ( + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2 + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index f412ac0ce2..f86a6d2bcb 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -69,10 +69,13 @@ MmSaveStateLib|Include/Library/MmSaveStateLib.h ## @libraryclass Provides functions for SMM CPU Sync Operation. SmmCpuSyncLib|Include/Library/SmmCpuSyncLib.h + ## @libraryclass Provides functions for SMM Relocation Operation. + SmmRelocationLib|Include/Library/SmmRelocationLib.h + [LibraryClasses.RISCV64] ## @libraryclass Provides functions to manage MMU features on RISCV64 CPUs. ## RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118325): https://edk2.groups.io/g/devel/message/118325 Mute This Topic: https://groups.io/mt/105748912/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v4 02/14] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance
This patch just separates the smbase relocation logic from PiSmmCpuDxeSmm driver, and moves to the SmmRelocationInit interface. It maintains the original implementation of most functions and leaves the definitions of global variables intact. Further refinements to the code are planned for subsequent patches. Platform shall consume the interface for the smbase relocation if need SMM support. Note: Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates the SMRAM to be used for SMI handler and Save state area of each processor from Smst->AllocatePages(). With SmmRelocationLib, the SMRAM allocation for SMI handlers and Save state areas is moved to early PEI phase (Smst->AllocatePages() service is not available). So, the allocation is done by splitting the SMRAM out of the SMRAM regions reported from gEfiSmmSMramMemoryGuid. So, Platform must produce the gEfiSmmSMramMemoryGuid HOB for SmmRelocationLib usage. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../SmmRelocationLib}/Ia32/Semaphore.c | 10 +- .../SmmRelocationLib}/Ia32/SmmInit.nasm| 67 ++- .../SmmRelocationLib/InternalSmmRelocationLib.h| 132 + .../Library/SmmRelocationLib/SmmRelocationLib.c| 600 + .../Library/SmmRelocationLib/SmmRelocationLib.inf | 61 +++ .../SmmRelocationLib/SmramSaveStateConfig.c| 139 + .../SmmRelocationLib}/X64/Semaphore.c | 10 +- .../SmmRelocationLib}/X64/SmmInit.nasm | 69 ++- UefiCpuPkg/UefiCpuPkg.dsc | 1 + 9 files changed, 1066 insertions(+), 23 deletions(-) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/Semaphore.c (79%) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/Ia32/SmmInit.nasm (53%) create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf create mode 100644 UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/Semaphore.c (84%) copy UefiCpuPkg/{PiSmmCpuDxeSmm => Library/SmmRelocationLib}/X64/SmmInit.nasm (64%) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 79% copy from UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c copy to UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c index a9fcc89dda..ba329d6ba2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -1,15 +1,15 @@ /** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2024, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include "PiSmmCpuDxeSmm.h" +#include "InternalSmmRelocationLib.h" UINTN mSmmRelocationOriginalAddress; volatile BOOLEAN *mRebasedFlag; /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm similarity index 53% copy from UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm copy to UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm index b5e77a1a5b..3d845e9e16 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -1,7 +1,7 @@ ;-- ; -; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. +; Copyright (c) 2024, Intel Corporation. All rights reserved. ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; ; SmmInit.nasm @@ -27,15 +27,70 @@ global ASM_PFX(gcSmmInitSize) global ASM_PFX(gcSmmInitTemplate) %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -SECTION .text +SECTION .data -ASM_PFX(gcSmiInitGdtr): +NullSeg: DQ 0 ; reserved by architecture +CodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeCodeSeg32: +DW -1 ; LimitLow +DW 0 ; BaseLow +DB 0 ; BaseMid +DB 0x9b +DB 0xcf; LimitHigh +DB 0 ; BaseHigh +ProtModeSsSeg32: +DW -1 ; LimitLow +
[edk2-devel] [PATCH v4 03/14] UefiCpuPkg/SmmRelocationLib: Rename global variables
This patch aims to rename global variables for clearer association with Smm Init, ensuring their names are distinct from those used in the PiSmmCpuDxeSmm Driver. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 18 +++ .../SmmRelocationLib/InternalSmmRelocationLib.h| 8 +++ .../Library/SmmRelocationLib/SmmRelocationLib.c| 26 +++--- .../Library/SmmRelocationLib/X64/SmmInit.nasm | 18 +++ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm index 3d845e9e16..8916cb7d06 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm @@ -16,15 +16,15 @@ extern ASM_PFX(SmmInitHandler) extern ASM_PFX(mRebasedFlag) extern ASM_PFX(mSmmRelocationOriginalAddress) -global ASM_PFX(gPatchSmmCr3) -global ASM_PFX(gPatchSmmCr4) -global ASM_PFX(gPatchSmmCr0) +global ASM_PFX(gPatchSmmInitCr3) +global ASM_PFX(gPatchSmmInitCr4) +global ASM_PFX(gPatchSmmInitCr0) global ASM_PFX(gPatchSmmInitStack) -global ASM_PFX(gcSmiInitGdtr) +global ASM_PFX(gcSmmInitGdtr) global ASM_PFX(gcSmmInitSize) global ASM_PFX(gcSmmInitTemplate) %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 @@ -81,11 +81,11 @@ CodeSeg64: DB 0x9b DB 0xaf; LimitHigh DB 0 ; BaseHigh GDT_SIZE equ $ - NullSeg -ASM_PFX(gcSmiInitGdtr): +ASM_PFX(gcSmmInitGdtr): DW GDT_SIZE - 1 DD NullSeg SECTION .text @@ -98,22 +98,22 @@ ASM_PFX(SmmStartup): cpuid mov ebx, edx; rdmsr will change edx. keep it in ebx. and ebx, BIT20 ; extract NX capability bit shr ebx, 9 ; shift bit to IA32_EFER.NXE[BIT11] position mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr3): +ASM_PFX(gPatchSmmInitCr3): mov cr3, eax -o32 lgdt[cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))] +o32 lgdt[cs:ebp + (ASM_PFX(gcSmmInitGdtr) - ASM_PFX(SmmStartup))] mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr4): +ASM_PFX(gPatchSmmInitCr4): mov cr4, eax mov ecx, 0xc080 ; IA32_EFER MSR rdmsr or eax, ebx; set NXE bit if NX is available wrmsr mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr0): +ASM_PFX(gPatchSmmInitCr0): mov di, PROTECT_MODE_DS mov cr0, eax jmp PROTECT_MODE_CS : dword @32bit BITS 32 diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h index a9d3f271a9..ede61b956f 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h +++ b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h @@ -30,17 +30,17 @@ #include #include #include #include -extern IA32_DESCRIPTOR gcSmiInitGdtr; +extern IA32_DESCRIPTOR gcSmmInitGdtr; extern CONST UINT16 gcSmmInitSize; extern CONST UINT8 gcSmmInitTemplate[]; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr0; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr3; +X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitCr4; X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack; // // The size 0x20 must be bigger than // the size of template code of SmmInit. Currently, diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 13e62b662d..ca98f06a05 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -22,11 +22,11 @@ UINTN mNumberOfCpus= 1; EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; // // IDT used during SMM Init // -IA32_DESCRIPTOR gcSmiIdtr; +IA32_DESCRIPTOR gcSmmInitIdtr; // // Smbase for all CPUs // UINT64 *mSmBase = NULL; @@ -118,11 +118,11 @@ SmmInitHandler ( UINTN Index; // // Update SMM IDT entries' code segment and load IDT // - AsmWriteIdtr (&gcSmiIdtr); + AsmWriteIdtr (&gcSmmInitIdtr); ApicId = GetApicId (); for (Index = 0; Index < mNumberOfCpus; Index++) { if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { // @@ -167,13 +167,13 @@ SmmRelocateBases ( ASSERT (sizeof (BakBuf) >= gcSmmInitSize); // // Patch ASM code template with current CR0, CR3, and CR4 values // - PatchInstructionX86 (gPatchSmmCr0, AsmReadCr0 (), 4); - PatchInstructionX86 (gPatchSmmCr3, AsmReadCr3 (), 4); - PatchInstru
[edk2-devel] [PATCH v4 04/14] UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation
Since SMM relocation is performed serially for each CPU, there is no need to allocate buffers for all CPUs to store the SmBase address in mSmBase and the Rebased flag in mRebased. A defined global variable is sufficient. This patch focuses on the mSmBase and mRebased global variables to prevent unnecessary memory allocation for these variables. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/SmmRelocationLib.c| 201 + 1 file changed, 90 insertions(+), 111 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index ca98f06a05..3694a07cbb 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -25,31 +25,57 @@ EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; // IDT used during SMM Init // IA32_DESCRIPTOR gcSmmInitIdtr; // -// Smbase for all CPUs +// Smbase for current CPU // -UINT64 *mSmBase = NULL; +UINT64 mSmBase; // -// SmBase Rebased flag for all CPUs +// SmBase Rebased flag for current CPU // -volatile BOOLEAN *mRebased; +volatile BOOLEAN mRebased; + +/** + This function will get the SmBase for CpuIndex. + + @param[in] CpuIndexThe processor index. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. + + @retval The value of SmBase for CpuIndex. + +**/ +UINTN +GetSmBase ( + IN UINTN CpuIndex, + IN EFI_PHYSICAL_ADDRESS SmmRelocationStart, + IN UINTN TileSize + ) +{ + return (UINTN)(SmmRelocationStart) + CpuIndex * TileSize - SMM_HANDLER_OFFSET; +} /** This function will create SmBase for all CPUs. - @param[in] SmBasePointer to SmBase for all CPUs. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. @retval EFI_SUCCESS Create SmBase for all CPUs successfully. @retval OthersFailed to create SmBase for all CPUs. **/ EFI_STATUS CreateSmmBaseHob ( - IN UINT64 *SmBase + IN EFI_PHYSICAL_ADDRESS SmmRelocationStart, + IN UINTN TileSize ) { UINTN Index; SMM_BASE_HOB_DATA *SmmBaseHobData; UINT32 CpuCount; @@ -90,11 +116,11 @@ CreateSmmBaseHob ( DEBUG ((DEBUG_INFO, "CreateSmmBaseHob - SmmBaseHobData[%d]->NumberOfProcessors: %d\n", HobCount, SmmBaseHobData->NumberOfProcessors)); for (Index = 0; Index < SmmBaseHobData->NumberOfProcessors; Index++) { // // Calculate the new SMBASE address // - SmmBaseHobData->SmBase[Index] = SmBase[Index + CpuCount]; + SmmBaseHobData->SmBase[Index] = GetSmBase (Index + CpuCount, SmmRelocationStart, TileSize); DEBUG ((DEBUG_INFO, "CreateSmmBaseHob - SmmBaseHobData[%d]->SmBase[%d]: 0x%08x\n", HobCount, Index, SmmBaseHobData->SmBase[Index])); } CpuCount += NumberOfProcessorsInHob; HobCount++; @@ -126,18 +152,18 @@ SmmInitHandler ( for (Index = 0; Index < mNumberOfCpus; Index++) { if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { // // Configure SmBase. // - ConfigureSmBase (mSmBase[Index]); + ConfigureSmBase (mSmBase); // // Hook return after RSM to set SMM re-based flag // SMM re-based flag can't be set before RSM, because SMM save state context might be override // by next AP flow before it take effect. // - SemaphoreHook (Index, &mRebased[Index]); + SemaphoreHook (Index, &mRebased); return; } } ASSERT (FALSE); @@ -145,14 +171,22 @@ SmmInitHandler ( /** Relocate SmmBases for each processor. Execute on first boot and all S3 resumes + @param[in] MpServices2 Pointer to this instance of the MpServices. + @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. + @param[in] TileSizeThe total size required for a CPU save state, any + additional CPU-specific context and the size of code + for the SMI entry point. + **/ VOID SmmRelocateBases ( - VOID + IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2, + IN EFI_PHYSICAL_ADDRESSSmmRelocationStart, + IN UINTN TileSize ) { UINT8 BakBuf[BACK_BUF_SIZE]; SMRAM_SAVE_STATE_MAP BakBuf2; SMRAM_SAVE_ST
[edk2-devel] [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable
This patch aims on mProcessorInfo global variable, which can be defined as local variable in SmmRelocateBases(). With this patch, no need to allocate the memory for all CPUs to store the Processor Info. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/SmmRelocationLib.c| 88 -- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 3694a07cbb..86df66a280 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -14,15 +14,10 @@ #include "InternalSmmRelocationLib.h" UINTN mMaxNumberOfCpus = 1; UINTN mNumberOfCpus= 1; -// -// Record all Processors Info -// -EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; - // // IDT used during SMM Init // IA32_DESCRIPTOR gcSmmInitIdtr; @@ -34,10 +29,15 @@ UINT64 mSmBase; // // SmBase Rebased flag for current CPU // volatile BOOLEAN mRebased; +// +// CpuIndex for current CPU +// +UINTN mCpuIndex; + /** This function will get the SmBase for CpuIndex. @param[in] CpuIndexThe processor index. @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. @@ -138,37 +138,26 @@ VOID EFIAPI SmmInitHandler ( VOID ) { - UINT32 ApicId; - UINTN Index; - // // Update SMM IDT entries' code segment and load IDT // AsmWriteIdtr (&gcSmmInitIdtr); - ApicId = GetApicId (); - for (Index = 0; Index < mNumberOfCpus; Index++) { -if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { - // - // Configure SmBase. - // - ConfigureSmBase (mSmBase); - - // - // Hook return after RSM to set SMM re-based flag - // SMM re-based flag can't be set before RSM, because SMM save state context might be override - // by next AP flow before it take effect. - // - SemaphoreHook (Index, &mRebased); - return; -} - } + // + // Configure SmBase. + // + ConfigureSmBase (mSmBase); - ASSERT (FALSE); + // + // Hook return after RSM to set SMM re-based flag + // SMM re-based flag can't be set before RSM, because SMM save state context might be override + // by next AP flow before it take effect. + // + SemaphoreHook (mCpuIndex, &mRebased); } /** Relocate SmmBases for each processor. Execute on first boot and all S3 resumes @@ -185,17 +174,19 @@ SmmRelocateBases ( IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2, IN EFI_PHYSICAL_ADDRESSSmmRelocationStart, IN UINTN TileSize ) { - UINT8 BakBuf[BACK_BUF_SIZE]; - SMRAM_SAVE_STATE_MAP BakBuf2; - SMRAM_SAVE_STATE_MAP *CpuStatePtr; - UINT8 *U8Ptr; - UINTN Index; - UINTN BspIndex; - UINT32BspApicId; + EFI_STATUS Status; + UINT8 BakBuf[BACK_BUF_SIZE]; + SMRAM_SAVE_STATE_MAP BakBuf2; + SMRAM_SAVE_STATE_MAP *CpuStatePtr; + UINT8 *U8Ptr; + UINTN Index; + UINTN BspIndex; + UINT32 BspApicId; + EFI_PROCESSOR_INFORMATION ProcessorInfo; // // Make sure the reserved size is large enough for procedure SmmInitTemplate. // ASSERT (sizeof (BakBuf) >= gcSmmInitSize); @@ -230,14 +221,18 @@ SmmRelocateBases ( // Relocate SM bases for all APs // This is APs' 1st SMI - rebase will be done here, and APs' default SMI handler will be overridden by gcSmmInitTemplate // BspIndex = (UINTN)-1; for (Index = 0; Index < mNumberOfCpus; Index++) { -if (BspApicId != (UINT32)mProcessorInfo[Index].ProcessorId) { - mRebased = FALSE; - mSmBase = GetSmBase (Index, SmmRelocationStart, TileSize); - SendSmiIpi ((UINT32)mProcessorInfo[Index].ProcessorId); +Status = MpServices2->GetProcessorInfo (MpServices2, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo); +ASSERT_EFI_ERROR (Status); + +if (BspApicId != (UINT32)ProcessorInfo.ProcessorId) { + mRebased = FALSE; + mSmBase = GetSmBase (Index, SmmRelocationStart, TileSize); + mCpuIndex = Index; + SendSmiIpi ((UINT32)ProcessorInfo.ProcessorId); // // Wait for this AP to finish its 1st SMI // while (!mRebased) { } @@ -443,11 +438,10 @@ SmmRelocationInit ( UINTN TileSize; UINT64SmmRelocationSize; EFI_PHYSICAL_ADDRESS SmmRelocationStart; UINTN SmmStackSize; UINT8 *SmmStacks; - UINTN Index; SmmRelocationStart = 0; SmmStacks = NULL; DEBUG ((DEBUG_INFO, "SmmRelocationInit Start \n")); @@ -473,28 +467,10 @@ SmmRelocationInit ( mMaxNumberOfCpus = mNumberOfCpus; } ASSERT (mNumb
[edk2-devel] [PATCH v4 06/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex
This patch is to remove unnecessary CpuIndex. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c | 3 --- .../Library/SmmRelocationLib/InternalSmmRelocationLib.h | 5 - UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c | 12 +++- UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c | 3 --- UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c | 3 --- 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c index ba329d6ba2..5d9eea3de9 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c @@ -15,28 +15,25 @@ volatile BOOLEAN *mRebasedFlag; /** Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. - @param[in] CpuIndex The processor index. @param[in] RebasedFlag A pointer to a flag that is set to TRUE immediately after AP exits SMM. **/ VOID SemaphoreHook ( - IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag ) { SMRAM_SAVE_STATE_MAP *CpuState; mRebasedFlag = RebasedFlag; CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, CpuState, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, (UINT64)(UINTN)&SmmRelocationSemaphoreComplete ); } diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h index ede61b956f..d1387f2dfb 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h +++ b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h @@ -81,12 +81,10 @@ SmmRelocationSemaphoreComplete ( Hook the code executed immediately after an RSM instruction on the currently executing CPU. The mode of code executed immediately after RSM must be detected, and the appropriate hook must be selected. Always clear the auto HALT restart flag if it is set. - @param[in] CpuIndex The processor index for the currently - executing CPU. @param[in,out] CpuState Pointer to SMRAM Save State Map for the currently executing CPU. @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to 32-bit mode from 64-bit SMM. @param[in] NewInstructionPointerInstruction pointer to use if resuming to @@ -96,29 +94,26 @@ SmmRelocationSemaphoreComplete ( **/ UINT64 EFIAPI HookReturnFromSmm ( - IN UINTN CpuIndex, IN OUT SMRAM_SAVE_STATE_MAP *CpuState, IN UINT64NewInstructionPointer32, IN UINT64NewInstructionPointer ); /** Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. - @param[in] CpuIndex The processor index. @param[in] RebasedFlag A pointer to a flag that is set to TRUE immediately after AP exits SMM. **/ VOID SemaphoreHook ( - IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag ); /** This function fixes up the address of the global variable or function diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 86df66a280..7e65bbf929 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -29,15 +29,10 @@ UINT64 mSmBase; // // SmBase Rebased flag for current CPU // volatile BOOLEAN mRebased; -// -// CpuIndex for current CPU -// -UINTN mCpuIndex; - /** This function will get the SmBase for CpuIndex. @param[in] CpuIndexThe processor index. @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. @@ -153,11 +148,11 @@ SmmInitHandler ( // // Hook return after RSM to set SMM re-based flag // SMM re-based flag can't be set before RSM, because SMM save state context might be override // by next AP flow before it take effect. // - SemaphoreHook (mCpuIndex, &mRebased); + SemaphoreHook (&mRebased); } /** Relocat
[edk2-devel] [PATCH v4 07/14] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD
Due to the definition difference of SMRAM Save State, SmmBase config in SMRAM Save State for AMD is also different. This patch provides the AmdSmmRelocationLib library instance to handle the SMRAM Save State difference. Cc: Abdul Lateef Attar Cc: Abner Chang Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Acked-by: Ray Ni Reviewed-by: Abdul Lateef Attar --- ...mmRelocationLib.inf => AmdSmmRelocationLib.inf} | 5 +- ...SaveStateConfig.c => AmdSmramSaveStateConfig.c} | 91 ++ UefiCpuPkg/UefiCpuPkg.dsc | 1 + 3 files changed, 43 insertions(+), 54 deletions(-) copy UefiCpuPkg/Library/SmmRelocationLib/{SmmRelocationLib.inf => AmdSmmRelocationLib.inf} (89%) copy UefiCpuPkg/Library/SmmRelocationLib/{SmramSaveStateConfig.c => AmdSmramSaveStateConfig.c} (47%) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf similarity index 89% copy from UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf index 45fdaf35bc..e69079fa02 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmmRelocationLib.inf @@ -13,18 +13,18 @@ ## [Defines] INF_VERSION= 0x00010005 BASE_NAME = SmmRelocationLib - FILE_GUID = 853E97B3-790C-4EA3-945C-8F622FC47FE8 + FILE_GUID = 65C74DCD-0D09-494A-8BFF-A64226EB8054 MODULE_TYPE= PEIM VERSION_STRING = 1.0 LIBRARY_CLASS = SmmRelocationLib [Sources] InternalSmmRelocationLib.h - SmramSaveStateConfig.c + AmdSmramSaveStateConfig.c SmmRelocationLib.c [Sources.Ia32] Ia32/Semaphore.c Ia32/SmmInit.nasm @@ -40,11 +40,10 @@ [LibraryClasses] BaseLib BaseMemoryLib CpuExceptionHandlerLib - CpuLib DebugLib HobLib LocalApicLib MemoryAllocationLib PcdLib diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c similarity index 47% copy from UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c copy to UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c index 76d798aba5..068ae60887 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c @@ -1,14 +1,17 @@ /** @file Config SMRAM Save State for SmmBases Relocation. + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. Copyright (c) 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalSmmRelocationLib.h" -#include +#include + +#define EFER_ADDRESS 0XC080ul /** Get the mode of the CPU at the time an SMI occurs @retval EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT 32 bit. @@ -18,44 +21,18 @@ UINT8 GetMmSaveStateRegisterLma ( VOID ) { - CPUID_VERSION_INFO_EAX RegEax; - CPUID_EXTENDED_CPU_SIG_EDX RegEdx; - UINTN FamilyId; - UINTN ModelId; - UINT32 Eax; - UINT8 SmmSaveStateRegisterLma; - - // - // Determine the mode of the CPU at the time an SMI occurs - // Intel(R) 64 and IA-32 Architectures Software Developer's Manual - // Volume 3C, Section 34.4.1.1 - // - RegEax.Uint32 = GetCpuFamilyModel (); - FamilyId = RegEax.Bits.FamilyId; - ModelId = RegEax.Bits.Model; - if ((FamilyId == 0x06) || (FamilyId == 0x0f)) { -ModelId = ModelId | RegEax.Bits.ExtendedModelId << 4; - } - - RegEdx.Uint32 = 0; - AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); - if (Eax >= CPUID_EXTENDED_CPU_SIG) { -AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &(RegEdx.Uint32)); - } + UINT8 SmmSaveStateRegisterLma; + UINT32 LMAValue; SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT; - if (RegEdx.Bits.LM) { -SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; - } - if (FamilyId == 0x06) { -if ((ModelId == 0x17) || (ModelId == 0x0f) || (ModelId == 0x1c)) { - SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; -} + LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA; + if (LMAValue) { +SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; } return SmmSaveStateRegisterLma; } @@ -69,22 +46,32 @@ VOID EFIAPI ConfigureSmBase ( IN UINT64 SmBase ) { - SMRAM_SAVE_STATE_MAP *CpuState; + AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState; - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); + AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - CpuState->x
[edk2-devel] [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF
There are below 2 differences between AMD & OVMF according existing implementation: 1.The mode of the CPU check is different between the AMD & OVMF. OVMF: CpuSaveState->x86.SMMRevId & 0X AMD: LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA 2.Existing SmBase configuration is different between the AMD & OVMF. OVMF: if ((CpuSaveState->x86.SMMRevId & 0x) == 0) { CpuSaveState->x86.SMBASE = mSmBaseForAllCpus[CpuIndex]; } else { CpuSaveState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; } AMD: AmdCpuState->x64.SMBASE = mSmBaseForAllCpus[CpuIndex]; This patch provides the SmmRelocationLib library instance for OVMF to handle the logic difference, and it won't change the existing implementation code logic. Cc: Ray Ni Cc: Zeng Star Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + .../Library/SmmRelocationLib/Ia32/Semaphore.c | 0 .../Library/SmmRelocationLib/Ia32/SmmInit.nasm | 0 .../SmmRelocationLib/InternalSmmRelocationLib.h| 0 .../Library/SmmRelocationLib/SmmRelocationLib.c| 0 .../Library/SmmRelocationLib/SmmRelocationLib.inf | 3 +- .../SmmRelocationLib/SmramSaveStateConfig.c| 65 +++--- .../Library/SmmRelocationLib/X64/Semaphore.c | 0 .../Library/SmmRelocationLib/X64/SmmInit.nasm | 0 OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc| 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 14 files changed, 27 insertions(+), 47 deletions(-) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/Ia32/SmmInit.nasm (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/InternalSmmRelocationLib.h (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/SmmRelocationLib.inf (90%) copy UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c => OvmfPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c (60%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/Semaphore.c (100%) copy {UefiCpuPkg => OvmfPkg}/Library/SmmRelocationLib/X64/SmmInit.nasm (100%) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index a7540bb636..8eb6f4f24f 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -108,10 +108,11 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index b1911d6ab4..4996885301 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -124,10 +124,11 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c b/OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c copy to OvmfPkg/Library/SmmRelocationLib/Ia32/Semaphore.c diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm b/OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm copy to OvmfPkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h b/OvmfPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h copy to OvmfPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.c similarity index 100% copy from UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c copy to OvmfPkg/Li
[edk2-devel] [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid
In the PiSmmCpuDxeSmm driver, SMRAM allocation for SMI handlers and processor Save State areas was traditionally performed using the Smst->AllocatePages() function during the DXE phase. The introduction of SmmRelocationLib changes this process by moving the allocation to the PEI phase, where Smst->AllocatePages() is not accessible. Instead, the allocation is now handled by partitioning the SMRAM based on the information provided by a GUID HOB (identified by gEfiSmmSMramMemoryGuid). This patch is to ensure that OVMF produces the gEfiSmmSMramMemoryGuid HOB, allowing SmmRelocationLib to reserve the necessary memory for SMBASE relocation. More info for the change: 1. The EFI_SMM_SMRAM_MEMORY_GUID HOB, as defined in the PI specification, vol.3, section 5, which is used to describe the SMRAM memory regions supported by the platform. This HOB should be produced during the memory detection phase to align with the PI spec. 2. In addition to the memory reserved for ACPI S3 resume, an increasing number of features require reserving SMRAM for specific purposes, such as SmmRelocation. Other advanced features in Intel platforms also necessitate this. The implementation of these features varies and is entirely dependent on the platform. This is why an increasing number of platforms are adopting the EFI_SMM_SMRAM_MEMORY_GUID HOB for SMRAM description. 3. It is crucial that the SMRAM information remains consistent when retrieved from the platform, whether through the SMM ACCESS PPI/Protocol or the EFI_SMM_SMRAM_MEMORY_GUID HOB. Inconsistencies can lead to unexpected issues, most commonly memory region conflicts. 4. The SMM ACCESS PPI/Protocol can be naturally implemented for general use. The common approach is to utilize the EFI_SMM_SMRAM_MEMORY_GUID HOB. For reference, see the existing implementation in the EDK2 repository at edk2/UefiPayloadPkg/SmmAccessDxe/SmmAccessDxe.inf and edk2-platforms/Silicon/Intel/IntelSiliconPkg/Feature/ SmmAccess/Library/PeiSmmAccessLib/PeiSmmAccessLib.inf. Next patch will refine the OVMF SMM Access to consume the EFI_SMM_SMRAM_MEMORY_GUID HOB. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 125 ++--- .../Library/PlatformInitLib/PlatformInitLib.inf| 5 +- 2 files changed, 90 insertions(+), 40 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 7b6e5102ad..19abb16e79 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1,9 +1,9 @@ /**@file Memory Detection for Virtual Machines. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved. + Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: MemDetect.c @@ -40,10 +40,11 @@ Module Name: #include #include #include #include +#include #define MEGABYTE_SHIFT 20 VOID EFIAPI @@ -980,10 +981,61 @@ PlatformAddressWidthInitialization ( #endif PlatformInfoHob->PhysMemAddressWidth = PhysMemAddressWidth; } +/** + Create gEfiSmmSmramMemoryGuid HOB defined in the PI specification Vol. 3, + section 5, which is used to describe the SMRAM memory regions supported + by the platform. + + @param[in] StartAddress StartAddress of smram. + @param[in] Size Size of smram. + +**/ +STATIC +VOID +CreateSmmSmramMemoryHob ( + IN EFI_PHYSICAL_ADDRESS StartAddress, + IN UINT32Size + ) +{ + UINTN BufferSize; + UINT8 SmramRanges; + EFI_PEI_HOB_POINTERSHob; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + + SmramRanges = 2; + BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); + + Hob.Raw = BuildGuidHob ( + &gEfiSmmSmramMemoryGuid, + BufferSize + ); + ASSERT (Hob.Raw); + + SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw); + SmramHobDescriptorBlock->NumberOfSmmReservedRegions = SmramRanges; + + // + // 1. Create first SMRAM descriptor, which contains data structures used in S3 resume. + // One page is enough for the data structure + // + SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = StartAddress; + SmramHobDescriptorBlock->Descriptor[0].CpuStart = StartAddress; + SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; + SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; + + // + // 2. Create second SMRAM descriptor, which is free and will be used by SMM foundation. + // + SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; + SmramHobDescriptorBlock->Descripto
[edk2-devel] [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation
This patch refines the SmmAccess implementation: 1. SmramMap will be retrieved from the gEfiSmmSmramMemoryGuid instead of original from the TSEG Memory Base register. 2. Remove the gEfiAcpiVariableGuid creation, thus the DESCRIPTOR_INDEX definition can be also cleaned. 3. The gEfiAcpiVariableGuid HOB is moved to the OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c| 10 ++ .../Library/PlatformInitLib/PlatformInitLib.inf| 1 + OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + OvmfPkg/SmmAccess/SmmAccessPei.c | 116 +++-- OvmfPkg/SmmAccess/SmmAccessPei.inf | 11 +- OvmfPkg/SmmAccess/SmramInternal.c | 72 - OvmfPkg/SmmAccess/SmramInternal.h | 19 +--- 8 files changed, 87 insertions(+), 151 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 19abb16e79..e64c0ee324 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -40,10 +40,12 @@ Module Name: #include #include #include #include + +#include #include #define MEGABYTE_SHIFT 20 VOID @@ -1001,10 +1003,11 @@ CreateSmmSmramMemoryHob ( { UINTN BufferSize; UINT8 SmramRanges; EFI_PEI_HOB_POINTERSHob; EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + VOID*GuidHob; SmramRanges = 2; BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); Hob.Raw = BuildGuidHob ( @@ -1023,10 +1026,17 @@ CreateSmmSmramMemoryHob ( SmramHobDescriptorBlock->Descriptor[0].PhysicalStart = StartAddress; SmramHobDescriptorBlock->Descriptor[0].CpuStart = StartAddress; SmramHobDescriptorBlock->Descriptor[0].PhysicalSize = EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[0].RegionState = EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED; + // + // 1.1 Create gEfiAcpiVariableGuid according SmramHobDescriptorBlock->Descriptor[0] since it's used in S3 resume. + // + GuidHob = BuildGuidHob (&gEfiAcpiVariableGuid, sizeof (EFI_SMRAM_DESCRIPTOR)); + ASSERT (GuidHob != NULL); + CopyMem (GuidHob, &SmramHobDescriptorBlock->Descriptor[0], sizeof (EFI_SMRAM_DESCRIPTOR)); + // // 2. Create second SMRAM descriptor, which is free and will be used by SMM foundation. // SmramHobDescriptorBlock->Descriptor[1].PhysicalStart = SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; SmramHobDescriptorBlock->Descriptor[1].CpuStart = SmramHobDescriptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf index 2bb1c0296f..21e6efa5e0 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -56,10 +56,11 @@ [LibraryClasses.X64] TdxLib [Guids] gEfiSmmSmramMemoryGuid + gEfiAcpiVariableGuid [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c index 4b9e6df37f..3371592de7 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.c +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.c @@ -4,11 +4,11 @@ Q35 TSEG is expected to have been verified and set up by the SmmAccessPei driver. Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. + Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -113,12 +113,10 @@ SmmAccess2DxeGetCapabilities ( IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR*SmramMap ) { return SmramAccessGetCapabilities ( - This->LockState, - This->OpenState, SmramMapSize, SmramMap ); } diff --git a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf index d86381d0fb..d9f01a13c4 100644 --- a/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf +++ b/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf @@ -3,10 +3,11 @@ # # Q35 TSEG is expected to have been verified and set up by the SmmAccessPei # driver. # # Copyright (C) 2013, 2015, Red Hat, Inc. +# Copyright (c) 2024 Intel Corporation. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,17 +40,21 @@ DebugLib PcdLib PciLib UefiBootServicesTableLib UefiDriverEntryPoint + HobLib [Protocols] gEfiSmmAccess2ProtocolGuid ## PRODUCES [FeaturePcd] gUefiOvmfPk
[edk2-devel] [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not
Based on gSmmBaseHobGuid: If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded in the SmBase array. So, this patch check smbase relocation is done or not in SmmCpuFeaturesInitializeProcessor(). With SmmRelocationLib, gSmmBaseHobGuid will be always created. Here this patch just makes the function/logic correct. The SMM Relocation logic can be totally cleaned from the SmmCpuFeaturesLib. But it will happen in the future patch set, this patch does not target to the cleanup work. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 ++ 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 63822b126e..0a6f33c2b1 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -26,10 +26,16 @@ // // EFER register LMA bit // #define LMA BIT10 +// +// Indicate SmBase for each Processors has been relocated or not. If TRUE, +// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor(). +// +BOOLEAN mSmmCpuFeaturesSmmRelocated; + /** The constructor function @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @@ -44,13 +50,13 @@ SmmCpuFeaturesLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { // // If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded - // in the SmBase array. ASSERT it's not supported in OVMF. + // in the SmBase array. // - ASSERT (GetFirstGuidHob (&gSmmBaseHobGuid) == NULL); + mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL); // // No need to program SMRRs on our virtual platform. // return EFI_SUCCESS; @@ -90,20 +96,25 @@ SmmCpuFeaturesInitializeProcessor ( ) { AMD_SMRAM_SAVE_STATE_MAP *CpuState; // - // Configure SMBASE. + // No need to configure SMBASE if SmBase relocation has been done. // - CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( - SMM_DEFAULT_SMBASE + - SMRAM_SAVE_STATE_MAP_OFFSET - ); - if ((CpuState->x86.SMMRevId & 0x) == 0) { -CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; - } else { -CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; + if (!mSmmCpuFeaturesSmmRelocated) { +// +// Configure SMBASE. +// +CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)( + SMM_DEFAULT_SMBASE + + SMRAM_SAVE_STATE_MAP_OFFSET + ); +if ((CpuState->x86.SMMRevId & 0x) == 0) { + CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} else { + CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; +} } // // No need to program SMRRs on our virtual platform. // -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118335): https://edk2.groups.io/g/devel/message/118335 Mute This Topic: https://groups.io/mt/105748925/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase
This patch is to consume SmmRelocationInit for SmBase Relocation. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/PlatformPei/Platform.c | 3 + OvmfPkg/PlatformPei/Platform.h | 5 ++ OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- .../ClearCache.c => PlatformPei/SmmRelocation.c} | 79 ++ 4 files changed, 34 insertions(+), 58 deletions(-) copy OvmfPkg/{Bhyve/PlatformPei/ClearCache.c => PlatformPei/SmmRelocation.c} (32%) diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8..df35726ff6 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -365,8 +365,11 @@ InitializePlatform ( MiscInitialization (PlatformInfoHob); } IntelTdxInitialize (); InstallFeatureControlCallback (PlatformInfoHob); + if (PlatformInfoHob->SmmSmramRequire) { +RelocateSmBase (); + } return EFI_SUCCESS; } diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 1cf44844a7..0a59547cfc 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -76,10 +76,15 @@ InstallFeatureControlCallback ( VOID InstallClearCacheCallback ( VOID ); +VOID +RelocateSmBase ( + VOID + ); + VOID AmdSevInitialize ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 20b1b98292..e036018eab 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -1,10 +1,10 @@ ## @file # Platform PEI driver # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. +# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -30,10 +30,11 @@ MemDetect.c MemTypeInfo.c Platform.c Platform.h IntelTdx.c + SmmRelocation.c [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -64,10 +65,11 @@ MtrrLib MemEncryptSevLib PcdLib CcExitLib PlatformInitLib + SmmRelocationLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase @@ -140,9 +142,10 @@ [Ppis] gEfiPeiMasterBootModePpiGuid gEfiPeiMpServicesPpiGuid gEfiPeiReadOnlyVariable2PpiGuid + gEdkiiPeiMpServices2PpiGuid [Depex] TRUE diff --git a/OvmfPkg/Bhyve/PlatformPei/ClearCache.c b/OvmfPkg/PlatformPei/SmmRelocation.c similarity index 32% copy from OvmfPkg/Bhyve/PlatformPei/ClearCache.c copy to OvmfPkg/PlatformPei/SmmRelocation.c index 9e59f31df7..1151fc9220 100644 --- a/OvmfPkg/Bhyve/PlatformPei/ClearCache.c +++ b/OvmfPkg/PlatformPei/SmmRelocation.c @@ -1,45 +1,21 @@ /**@file - Install a callback to clear cache on all processors. - This is for conformance with the TCG "Platform Reset Attack Mitigation - Specification". Because clearing the CPU caches at boot doesn't impact - performance significantly, do it unconditionally, for simplicity's - sake. + Install a callback to do smm relocation. - Copyright (C) 2018, Red Hat, Inc. + Copyright (c) 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include #include #include -#include - +#include +#include #include "Platform.h" /** - Invalidate data & instruction caches. - All APs execute this function in parallel. The BSP executes the function - separately. - - @param[in,out] WorkSpace Pointer to the input/output argument workspace -shared by all processors. -**/ -STATIC -VOID -EFIAPI -ClearCache ( - IN OUT VOID *WorkSpace - ) -{ - WriteBackInvalidateDataCache (); - InvalidateInstructionCache (); -} - -/** - Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available. + Notification function called when EDKII_PEI_MP_SERVICES2_PPI becomes available. @param[in] PeiServices Indirect reference to the PEI Services Table. @param[in] NotifyDescriptor Address of the notification descriptor data structure. @param[in] Ppi Address of the PPI that was installed. @@ -48,68 +24,57 @@ ClearCache ( function is ignored. **/ STATIC EFI_STATUS EFIAPI -ClearCacheOnMpServicesAvailable ( +OnMpServices2Available ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi ) { - EFI_PEI_MP_SERVICES_PPI *MpServices; - EFI_STATUS Status; + EDKII_PEI_MP_SERVICES2_PPI *MpServices2; + EFI_STATUS Status; DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __func__)); + MpServices2 = Ppi; + // - // Clear
[edk2-devel] [PATCH v4 13/14] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib
This patch just includes SmmRelocationLib in UefiPayloadPkg. Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ray Ni Signed-off-by: Jiaxin Wu Reviewed-by: Gua Guo Reviewed-by: Guo Dong --- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index e1b9d5ecf1..2860a659f6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -314,10 +314,12 @@ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf + SmmRelocationLib|UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.inf + [LibraryClasses.common] !if $(BOOTSPLASH_IMAGE) SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf !endif -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118337): https://edk2.groups.io/g/devel/message/118337 Mute This Topic: https://groups.io/mt/105748927/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic
This patch is to remove legacy SmBase relocation in PiSmmCpuDxeSmm Driver. The responsibility for SmBase relocation has been transferred to the SmmRelocationInit interface, which now handles the following tasks: 1. Relocates the SmBase for each processor. 2. Generates the gSmmBaseHobGuid HOB. As a result of this change, the PiSmmCpuDxeSmm driver's role in SMM environment setup is simplified to: 1. Utilize the gSmmBaseHobGuid to determine the SmBase. 2. Perform the ExecuteFirstSmiInit() to do early SMM initialization. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c| 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 42 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 96 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c| 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 334 +++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h| 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c| 69 -- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm | 146 11 files changed, 40 insertions(+), 856 deletions(-) delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index b14c289a27..d67fb49890 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -639,27 +639,14 @@ InitializeCpuProcedure ( // InitializeCpuBeforeRebase (IsBsp); } if (IsBsp) { -DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated is %d\n", mSmmRelocated)); - // -// Check whether Smm Relocation is done or not. -// If not, will do the SmmBases Relocation here!!! +// Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. // -if (!mSmmRelocated) { - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); -} else { - // - // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init. - // - ExecuteFirstSmiInit (); -} +ExecuteFirstSmiInit (); } // // Skip initialization if mAcpiCpuData is not valid // @@ -978,13 +965,13 @@ InitSmmS3ResumeState ( SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); if (SmmS3ResumeState->SmmS3StackBase == 0) { SmmS3ResumeState->SmmS3StackSize = 0; } -SmmS3ResumeState->SmmS3Cr0 = mSmmCr0; +SmmS3ResumeState->SmmS3Cr0 = (UINT32)AsmReadCr0 (); SmmS3ResumeState->SmmS3Cr3 = Cr3; -SmmS3ResumeState->SmmS3Cr4 = mSmmCr4; +SmmS3ResumeState->SmmS3Cr4 = (UINT32)AsmReadCr4 (); if (sizeof (UINTN) == sizeof (UINT64)) { SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64; } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c deleted file mode 100644 index a9fcc89dda..00 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - - mRebasedFlag = RebasedFlag; - - CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, - (UINT64)(UINTN)&SmmRelocationSemaphoreComplete - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/
Re: [edk2-devel] [PATCH v1] Add MmUnblockMemoryLib to MdeLibs.dsc
Reviewed-by: Jiaxin Wu > -Original Message- > From: Zhang, Hongbin1 > Sent: Monday, April 29, 2024 11:08 AM > To: devel@edk2.groups.io > Cc: Zhang, Hongbin1 ; Kinney, Michael D > ; Ni, Ray ; Liming Gao > ; Liu, Zhiguang ; Wu, > Jiaxin ; Xie, Yuanhao > Subject: [PATCH v1] Add MmUnblockMemoryLib to MdeLibs.dsc > > It is for unblocking certain data pages to be accessible inside MM environment > > Cc: Michael D Kinney > Cc: Ray Ni > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Jiaxin Wu > Cc: Yuanhao Xie > --- > MdePkg/MdeLibs.dsc.inc | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc > index d782dbf4ff..ddd27115f5 100644 > --- a/MdePkg/MdeLibs.dsc.inc > +++ b/MdePkg/MdeLibs.dsc.inc > @@ -5,7 +5,7 @@ > # by using "!include MdePkg/MdeLibs.dsc.inc" to specify the library instances > # of some EDKII basic/common library classes. > # > -# Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved. > +# Copyright (c) 2021 - 2024, Intel Corporation. All rights reserved. > # > #SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -18,3 +18,4 @@ > > SmmCpuRendezvousLib|MdePkg/Library/SmmCpuRendezvousLibNull/SmmC > puRendezvousLibNull.inf >SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf > > SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniz > ationLib.inf > + > MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblo > ckMemoryLibNull.inf > -- > 2.37.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118362): https://edk2.groups.io/g/devel/message/118362 Mute This Topic: https://groups.io/mt/105794629/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1] UefiCpuPkg/Library: Cleanup debug message in LmceSupport
ProcessorNumber 0 is not always BSP. Debug message based on 0 of ProcessorNumber is incorrect. This patch is to clean the debug message in LmceSupport directly. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c index d8b070d9f1..cb569769a1 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c @@ -1,9 +1,9 @@ /** @file Machine Check features. - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. + Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "CpuCommonFeatures.h" @@ -287,13 +287,10 @@ LmceSupport ( if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) { return FALSE; } McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP); - if (ProcessorNumber == 0) { -DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0))); - } return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0); } /** -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118366): https://edk2.groups.io/g/devel/message/118366 Mute This Topic: https://groups.io/mt/105795776/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1] UefiCpuPkg/Library: Cleanup debug message in LmceSupport
ProcessorNumber 0 is not always BSP. Debug message based on 0 of ProcessorNumber is incorrect. This patch is to clean the debug message in LmceSupport directly. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c index d8b070d9f1..cb569769a1 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c @@ -1,9 +1,9 @@ /** @file Machine Check features. - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. + Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "CpuCommonFeatures.h" @@ -287,13 +287,10 @@ LmceSupport ( if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) { return FALSE; } McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP); - if (ProcessorNumber == 0) { -DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0))); - } return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0); } /** -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118367): https://edk2.groups.io/g/devel/message/118367 Mute This Topic: https://groups.io/mt/105795776/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v1] Maintainers.txt: Update StandaloneMmPkg and UefiCpuPkg Reviewer
This is to update StandaloneMmPkg and UefiCpuPkg Reviewer. Cc: Ray Ni Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Jiaxin Wu --- Maintainers.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 7d9cdca611..6fccbb6788 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -624,17 +624,19 @@ W: https://github.com/tianocore/tianocore.github.io/wiki/SourceLevelDebugPkg StandaloneMmPkg F: StandaloneMmPkg/ M: Ard Biesheuvel [ardbiesheuvel] M: Sami Mujawar [samimujawar] M: Ray Ni [niruiyu] +R: Jiaxin Wu [jiaxinwu] UefiCpuPkg F: UefiCpuPkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/UefiCpuPkg M: Ray Ni [niruiyu] R: Rahul Kumar [rahul1-kumar] R: Gerd Hoffmann [kraxel] +R: Jiaxin Wu [jiaxinwu] UefiCpuPkg: Sec related modules F: UefiCpuPkg/SecCore/ F: UefiCpuPkg/ResetVector/ R: Catharine West [catharine-intl] -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118368): https://edk2.groups.io/g/devel/message/118368 Mute This Topic: https://groups.io/mt/105795833/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib
Hi Gerd, Could you help review & check below OVMF changes in v4: OvmfPkg/SmmRelocationLib: Add library instance for OVMF OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid OvmfPkg: Refine SmmAccess implementation OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not OvmfPkg/PlatformPei: Relocate SmBases in PEI phase Thanks, Jiaxin > -Original Message- > From: devel@edk2.groups.io On Behalf Of Wu, > Jiaxin > Sent: Friday, April 26, 2024 8:17 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Zeng, Star ; Gerd > Hoffmann ; Kumar, Rahul R ; > Dong, Guo ; Rhodes, Sean ; > Lu, James ; Guo, Gua ; Ard > Biesheuvel ; Yao, Jiewen > ; Abdul Lateef Attar ; > Abner Chang ; Tom Lendacky > > Subject: [edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib > > PR: https://github.com/tianocore/edk2/pull/5546 > > Intel plans to separate the smbase relocation logic from > PiSmmCpuDxeSmm driver, and the related behavior will be > moved to the new interface defined by the SmmRelocationLib > class. > > The SmmRelocationLib class provides the SmmRelocationInit() > interface for platform to do the smbase relocation, which > shall provide below 2 functionalities: > 1. Relocate smbases for each processor. > 2. Create the gSmmBaseHobGuid HOB. > > With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at > a later phase) can be simplfied as below for SMM init: > 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases > for each Processor. > 2. Execute the early SMM Init. > > Cc: Ray Ni > Cc: Zeng Star > Cc: Gerd Hoffmann > Cc: Rahul Kumar > Cc: Guo Dong > Cc: Sean Rhodes > Cc: James Lu > Cc: Gua Guo > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Abdul Lateef Attar > Cc: Abner Chang > Cc: Tom Lendacky > Signed-off-by: Jiaxin Wu > > Jiaxin Wu (14): > UefiCpuPkg: Add SmmRelocationLib class > UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance > UefiCpuPkg/SmmRelocationLib: Rename global variables > UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation > UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable > UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex > UefiCpuPkg/SmmRelocationLib: Add library instance for AMD > OvmfPkg/SmmRelocationLib: Add library instance for OVMF > OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid > OvmfPkg: Refine SmmAccess implementation > OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not > OvmfPkg/PlatformPei: Relocate SmBases in PEI phase > UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib > UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic > > OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + > OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + > OvmfPkg/Library/PlatformInitLib/MemDetect.c| 135 +++-- > .../Library/PlatformInitLib/PlatformInitLib.inf| 6 +- > .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 33 +- > .../Library/SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/Ia32/SmmInit.nasm| 83 +++- > .../SmmRelocationLib/InternalSmmRelocationLib.h| 127 + > .../Library/SmmRelocationLib/SmmRelocationLib.c| 549 > + > .../Library/SmmRelocationLib/SmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/SmramSaveStateConfig.c| 100 > .../Library/SmmRelocationLib}/X64/Semaphore.c | 13 +- > .../Library/SmmRelocationLib}/X64/SmmInit.nasm | 85 +++- > OvmfPkg/Microvm/MicrovmX64.dsc | 1 + > OvmfPkg/OvmfPkgIa32.dsc| 1 + > OvmfPkg/OvmfPkgIa32X64.dsc | 1 + > OvmfPkg/OvmfPkgX64.dsc | 1 + > OvmfPkg/PlatformPei/Platform.c | 3 + > OvmfPkg/PlatformPei/Platform.h | 5 + > OvmfPkg/PlatformPei/PlatformPei.inf| 5 +- > OvmfPkg/PlatformPei/SmmRelocation.c| 80 +++ > OvmfPkg/SmmAccess/SmmAccess2Dxe.c | 4 +- > OvmfPkg/SmmAccess/SmmAccess2Dxe.inf| 5 + > OvmfPkg/SmmAccess/SmmAccessPei.c | 116 ++--- > OvmfPkg/SmmAccess/SmmAccessPei.inf | 11 +- > OvmfPkg/SmmAccess/SmramInternal.c | 72 +-- > OvmfPkg/SmmAccess/SmramInternal.h | 19 +- > UefiCpuPkg/Include/Library/SmmRelocationLib.h | 42 ++ > .../SmmRelocationLib/AmdSmmRelocationLib.inf | 60 +++ > .../SmmRelocationLib/AmdSmramSaveStateConfig.c | 125 + > .../SmmRelocationLib}/Ia32/Semaphore.c | 13 +- > .../SmmRelocationLib}/Ia32/SmmInit.na
[edk2-devel] [PATCH v1] UefiCpuPkg/Library: Support to get processor extended info
Intel has some features need to use processor extended information under CPU feature InitializeFunc(), so add code to support it: This patch is to add CPU_V2_EXTENDED_TOPOLOGY to get processor extended info. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c | 4 ++-- UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c index e635cade5d..d799b7f5d1 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c @@ -1,9 +1,9 @@ /** @file CPU Register Table Library functions. - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. + Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include @@ -99,11 +99,11 @@ GetProcessorInformation ( CpuFeaturesData = GetCpuFeaturesData (); MpServices = CpuFeaturesData->MpService.Protocol; Status = MpServices->GetProcessorInfo ( MpServices, - ProcessorNumber, + ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY, ProcessorInfoBuffer ); return Status; } diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c index d4c528b3e9..1db6adc280 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c @@ -1,9 +1,9 @@ /** @file CPU Register Table Library functions. - Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved. + Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include @@ -137,11 +137,11 @@ GetProcessorInformation ( CpuFeaturesData = GetCpuFeaturesData (); CpuMp2Ppi = CpuFeaturesData->MpService.Ppi; Status = CpuMp2Ppi->GetProcessorInfo ( CpuMp2Ppi, -ProcessorNumber, +ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY, ProcessorInfoBuffer ); return Status; } -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118404): https://edk2.groups.io/g/devel/message/118404 Mute This Topic: https://groups.io/mt/105815222/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1] UefiCpuPkg/Library: Support to get processor extended info
Thanks Ray, please help add the push label for the PR: https://github.com/tianocore/edk2/pull/5608 From: Ni, Ray Sent: Tuesday, April 30, 2024 1:33 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R Subject: Re: [PATCH v1] UefiCpuPkg/Library: Support to get processor extended info Reviewed-by: Ray Ni mailto:ray...@intel.com>> Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Tuesday, April 30, 2024 11:33 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>> Subject: [PATCH v1] UefiCpuPkg/Library: Support to get processor extended info Intel has some features need to use processor extended information under CPU feature InitializeFunc(), so add code to support it: This patch is to add CPU_V2_EXTENDED_TOPOLOGY to get processor extended info. Cc: Ray Ni mailto:ray...@intel.com>> Cc: Zeng Star mailto:star.z...@intel.com>> Cc: Gerd Hoffmann mailto:kra...@redhat.com>> Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> Signed-off-by: Jiaxin Wu mailto:jiaxin...@intel.com>> --- UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c | 4 ++-- UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c index e635cade5d..d799b7f5d1 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c @@ -1,9 +1,9 @@ /** @file CPU Register Table Library functions. - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. + Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include @@ -99,11 +99,11 @@ GetProcessorInformation ( CpuFeaturesData = GetCpuFeaturesData (); MpServices = CpuFeaturesData->MpService.Protocol; Status = MpServices->GetProcessorInfo ( MpServices, - ProcessorNumber, + ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY, ProcessorInfoBuffer ); return Status; } diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c index d4c528b3e9..1db6adc280 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c @@ -1,9 +1,9 @@ /** @file CPU Register Table Library functions. - Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved. + Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include @@ -137,11 +137,11 @@ GetProcessorInformation ( CpuFeaturesData = GetCpuFeaturesData (); CpuMp2Ppi = CpuFeaturesData->MpService.Ppi; Status = CpuMp2Ppi->GetProcessorInfo ( CpuMp2Ppi, -ProcessorNumber, +ProcessorNumber | CPU_V2_EXTENDED_TOPOLOGY, ProcessorInfoBuffer ); return Status; } -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118409): https://edk2.groups.io/g/devel/message/118409 Mute This Topic: https://groups.io/mt/105815222/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1] UefiCpuPkg/Library: Cleanup debug message in LmceSupport
Thanks Ray, please help add the push label for the PR: https://github.com/tianocore/edk2/pull/5610 From: Ni, Ray Sent: Tuesday, April 30, 2024 1:33 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R Subject: Re: [PATCH v1] UefiCpuPkg/Library: Cleanup debug message in LmceSupport Reviewed-by: Ray Ni mailto:ray...@intel.com>> Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Monday, April 29, 2024 13:31 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>> Subject: [PATCH v1] UefiCpuPkg/Library: Cleanup debug message in LmceSupport ProcessorNumber 0 is not always BSP. Debug message based on 0 of ProcessorNumber is incorrect. This patch is to clean the debug message in LmceSupport directly. Cc: Ray Ni mailto:ray...@intel.com>> Cc: Zeng Star mailto:star.z...@intel.com>> Cc: Gerd Hoffmann mailto:kra...@redhat.com>> Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> Signed-off-by: Jiaxin Wu mailto:jiaxin...@intel.com>> --- UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c index d8b070d9f1..cb569769a1 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c @@ -1,9 +1,9 @@ /** @file Machine Check features. - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. + Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "CpuCommonFeatures.h" @@ -287,13 +287,10 @@ LmceSupport ( if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) { return FALSE; } McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP); - if (ProcessorNumber == 0) { -DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0))); - } return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0); } /** -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118410): https://edk2.groups.io/g/devel/message/118410 Mute This Topic: https://groups.io/mt/105795776/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v1] Maintainers.txt: Update StandaloneMmPkg and UefiCpuPkg Reviewer
Thanks Ray, please help add the push label for the PR: https://github.com/tianocore/edk2/pull/5611 From: Ni, Ray Sent: Tuesday, April 30, 2024 1:34 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Ard Biesheuvel ; Sami Mujawar ; Kumar, Rahul R ; Gerd Hoffmann Subject: Re: [PATCH v1] Maintainers.txt: Update StandaloneMmPkg and UefiCpuPkg Reviewer Reviewed-by: Ray Ni mailto:ray...@intel.com>> Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Monday, April 29, 2024 13:32 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Sami Mujawar mailto:sami.muja...@arm.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>> Subject: [PATCH v1] Maintainers.txt: Update StandaloneMmPkg and UefiCpuPkg Reviewer This is to update StandaloneMmPkg and UefiCpuPkg Reviewer. Cc: Ray Ni mailto:ray...@intel.com>> Cc: Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>> Cc: Sami Mujawar mailto:sami.muja...@arm.com>> Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> Cc: Gerd Hoffmann mailto:kra...@redhat.com>> Signed-off-by: Jiaxin Wu mailto:jiaxin...@intel.com>> --- Maintainers.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 7d9cdca611..6fccbb6788 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -624,17 +624,19 @@ W: https://github.com/tianocore/tianocore.github.io/wiki/SourceLevelDebugPkg StandaloneMmPkg F: StandaloneMmPkg/ M: Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>> [ardbiesheuvel] M: Sami Mujawar mailto:sami.muja...@arm.com>> [samimujawar] M: Ray Ni mailto:ray...@intel.com>> [niruiyu] +R: Jiaxin Wu mailto:jiaxin...@intel.com>> [jiaxinwu] UefiCpuPkg F: UefiCpuPkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/UefiCpuPkg M: Ray Ni mailto:ray...@intel.com>> [niruiyu] R: Rahul Kumar mailto:rahul1.ku...@intel.com>> [rahul1-kumar] R: Gerd Hoffmann mailto:kra...@redhat.com>> [kraxel] +R: Jiaxin Wu mailto:jiaxin...@intel.com>> [jiaxinwu] UefiCpuPkg: Sec related modules F: UefiCpuPkg/SecCore/ F: UefiCpuPkg/ResetVector/ R: Catharine West mailto:catharine.w...@intel.com>> [catharine-intl] -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118411): https://edk2.groups.io/g/devel/message/118411 Mute This Topic: https://groups.io/mt/105795833/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib
Thanks Ray, I missed to add some already reviewed-by tag in v4. All V4 patches are tested & acted by Gerd: Tested-by: Gerd Hoffmann mailto:kra...@redhat.com>> Acked-by: Gerd Hoffmann mailto:kra...@redhat.com>> For each one: listed as below, *so need Ray "reviewed-by" tag on the patch: 05/06/14, need Gerd "reviewed-by" tag on the patch: 08/09/10/11/12* [PATCH v4 01/14] UefiCpuPkg: Add SmmRelocationLib class Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 02/14] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 03/14] UefiCpuPkg/SmmRelocationLib: Rename global variables Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 04/14] UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable [PATCH v4 06/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex * Change Based on Ray's comment on V3: split the removal of CpuIndex parameter in a new patch, so add the 06 patch in V4.* [PATCH v4 07/14] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD Reviewed-by: Abdul Lateef Attar --> no change compared to V3 [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase *Change Based on Gerd's comment on V3: 1. Creating the EFI_SMM_SMRAM_MEMORY_GUID HOB should be moved to its own function. 2) refine the comment in SmmAccess 3) refine the commit log.* [PATCH v4 13/14] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib Reviewed-by: Gua Guo Reviewed-by: Guo Dong [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic *Change Based on Ray's comment on V3: move the "TileSize" check just below the original TileSize calculation logic* Thanks, Jiaxin From: Ni, Ray Sent: Tuesday, April 30, 2024 2:01 PM To: Wu, Jiaxin ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R ; Dong, Guo ; Rhodes, Sean ; Lu, James ; Guo, Gua ; Ard Biesheuvel ; Yao, Jiewen ; Abdul Lateef Attar ; Abner Chang ; Tom Lendacky Subject: Re: [PATCH v4 00/14] Add SmmRelocationLib Jiaxin, You need to add the missing Reviewed-by for each patch if the patch doesn't change in V4. Can you reply to this mail to list what patches have already got Reviewed-by from whom? Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Friday, April 26, 2024 20:17 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>>; Abdul Lateef Attar mailto:abdullateef.at...@amd.com>>; Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky mailto:thomas.lenda...@amd.com>> Subject: [PATCH v4 00/14] Add SmmRelocationLib PR: https://github.com/tianocore/edk2/pull/5546 Intel plans to separate the smbase relocation logic from PiSmmCpuDxeSmm driver, and the related behavior will be moved to the new interface defined by the SmmRelocationLib class. The SmmRelocationLib class provides the SmmRelocationInit() interface for platform to do the smbase relocation, which shall provide below 2 functionalities: 1. Relocate smbases for each processor. 2. Create the gSmmBaseHobGuid HOB. With SmmRelocationLib, PiSmmCpuDxeSmm driver (which runs at a later phase) can be simplfied as below for SMM init: 1. Consume the gSmmBaseHobGuid HOB for the relocated smbases for each Processor. 2. Execute the early SMM Init. Cc: Ray Ni mailto:ray...@intel.com>> Cc: Zeng Star mailto:star.z...@intel.com>> Cc: Gerd Hoffmann mailto:kra...@redhat.com>> Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>> Cc: Guo Dong mailto:guo.d...@intel.com>> Cc: Sean Rhodes mailto:sean@starlabs.systems>> Cc: James Lu mailto:james...@intel.com>> Cc: Gua Guo mailto:gua@intel.com>> Cc: Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>> Cc: Jiew
Re: [edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib
Hi Jiewen and Ard, @Yao, Jiewen<mailto:jiewen@intel.com>, @Ard Biesheuvel<mailto:ardb+tianoc...@kernel.org>, do you agree we merge the change related to OVMF package since you are the OVMF maintainers. Please help check /review. The patches have been acked/tested by the Gerd. [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase Thanks, Jiaxin From: Wu, Jiaxin Sent: Tuesday, April 30, 2024 6:14 PM To: Ni, Ray ; devel@edk2.groups.io Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R ; Dong, Guo ; Rhodes, Sean ; Lu, James ; Guo, Gua ; Ard Biesheuvel ; Yao, Jiewen ; Abdul Lateef Attar ; Abner Chang ; Tom Lendacky Subject: RE: [PATCH v4 00/14] Add SmmRelocationLib Thanks Ray, I missed to add some already reviewed-by tag in v4. All V4 patches are tested & acted by Gerd: Tested-by: Gerd Hoffmann mailto:kra...@redhat.com>> Acked-by: Gerd Hoffmann mailto:kra...@redhat.com>> For each one: listed as below, *so need Ray "reviewed-by" tag on the patch: 05/06/14, need Gerd "reviewed-by" tag on the patch: 08/09/10/11/12* [PATCH v4 01/14] UefiCpuPkg: Add SmmRelocationLib class Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 02/14] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 03/14] UefiCpuPkg/SmmRelocationLib: Rename global variables Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 04/14] UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable [PATCH v4 06/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex * Change Based on Ray's comment on V3: split the removal of CpuIndex parameter in a new patch, so add the 06 patch in V4.* [PATCH v4 07/14] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD Reviewed-by: Abdul Lateef Attar mailto:abdullateef.at...@amd.com>> --> no change compared to V3 [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase *Change Based on Gerd's comment on V3: 1. Creating the EFI_SMM_SMRAM_MEMORY_GUID HOB should be moved to its own function. 2) refine the comment in SmmAccess 3) refine the commit log.* [PATCH v4 13/14] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib Reviewed-by: Gua Guo mailto:gua@intel.com>> Reviewed-by: Guo Dong mailto:guo.d...@intel.com>> [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic *Change Based on Ray's comment on V3: move the "TileSize" check just below the original TileSize calculation logic* Thanks, Jiaxin From: Ni, Ray mailto:ray...@intel.com>> Sent: Tuesday, April 30, 2024 2:01 PM To: Wu, Jiaxin mailto:jiaxin...@intel.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io> Cc: Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>>; Abdul Lateef Attar mailto:abdullateef.at...@amd.com>>; Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky mailto:thomas.lenda...@amd.com>> Subject: Re: [PATCH v4 00/14] Add SmmRelocationLib Jiaxin, You need to add the missing Reviewed-by for each patch if the patch doesn't change in V4. Can you reply to this mail to list what patches have already got Reviewed-by from whom? Thanks, Ray From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Friday, April 26, 2024 20:17 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> mailto:devel@edk2.groups.io>> Cc: Ni, Ray mailto:ray...@intel.com>>; Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong,
Re: [edk2-devel] [PATCH v2] MdePkg: Add MmUnblockMemoryLib to MdeLibs.dsc
Reviewed-by: Jiaxin Wu > -Original Message- > From: Zhang, Hongbin1 > Sent: Monday, April 29, 2024 2:25 PM > To: devel@edk2.groups.io > Cc: Zhang, Hongbin1 ; Kinney, Michael D > ; Ni, Ray ; Liming Gao > ; Liu, Zhiguang ; Wu, > Jiaxin ; Xie, Yuanhao > Subject: [PATCH v2] MdePkg: Add MmUnblockMemoryLib to MdeLibs.dsc > > MdeLibs.dsc.inc included some default libraries provided by MdePkg. > Platform can include MdeLibs.dsc.inc file to avoid some potential > incompatible changes to platform dsc file in future. > > Cc: Michael D Kinney > Cc: Ray Ni > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Jiaxin Wu > Cc: Yuanhao Xie > --- > MdePkg/MdeLibs.dsc.inc | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc > index d782dbf4ff..ddd27115f5 100644 > --- a/MdePkg/MdeLibs.dsc.inc > +++ b/MdePkg/MdeLibs.dsc.inc > @@ -5,7 +5,7 @@ > # by using "!include MdePkg/MdeLibs.dsc.inc" to specify the library instances > # of some EDKII basic/common library classes. > # > -# Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved. > +# Copyright (c) 2021 - 2024, Intel Corporation. All rights reserved. > # > #SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -18,3 +18,4 @@ > > SmmCpuRendezvousLib|MdePkg/Library/SmmCpuRendezvousLibNull/SmmC > puRendezvousLibNull.inf >SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf > > SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniz > ationLib.inf > + > MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblo > ckMemoryLibNull.inf > -- > 2.37.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118633): https://edk2.groups.io/g/devel/message/118633 Mute This Topic: https://groups.io/mt/105796510/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v4 00/14] Add SmmRelocationLib
Thanks Jiewen. From: Yao, Jiewen Sent: Tuesday, May 7, 2024 12:59 PM To: Wu, Jiaxin ; Ni, Ray ; devel@edk2.groups.io; Ard Biesheuvel Cc: Zeng, Star ; Gerd Hoffmann ; Kumar, Rahul R ; Dong, Guo ; Rhodes, Sean ; Lu, James ; Guo, Gua ; Abdul Lateef Attar ; Abner Chang ; Tom Lendacky Subject: RE: [PATCH v4 00/14] Add SmmRelocationLib Acked-by: Jiewen Yao mailto:jiewen@intel.com>> From: Wu, Jiaxin mailto:jiaxin...@intel.com>> Sent: Tuesday, May 7, 2024 11:39 AM To: Ni, Ray mailto:ray...@intel.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>> Cc: Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Abdul Lateef Attar mailto:abdullateef.at...@amd.com>>; Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky mailto:thomas.lenda...@amd.com>> Subject: RE: [PATCH v4 00/14] Add SmmRelocationLib Hi Jiewen and Ard, @Yao, Jiewen<mailto:jiewen@intel.com>, @Ard Biesheuvel<mailto:ardb+tianoc...@kernel.org>, do you agree we merge the change related to OVMF package since you are the OVMF maintainers. Please help check /review. The patches have been acked/tested by the Gerd. [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase Thanks, Jiaxin From: Wu, Jiaxin Sent: Tuesday, April 30, 2024 6:14 PM To: Ni, Ray mailto:ray...@intel.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io> Cc: Zeng, Star mailto:star.z...@intel.com>>; Gerd Hoffmann mailto:kra...@redhat.com>>; Kumar, Rahul R mailto:rahul.r.ku...@intel.com>>; Dong, Guo mailto:guo.d...@intel.com>>; Rhodes, Sean mailto:sean@starlabs.systems>>; Lu, James mailto:james...@intel.com>>; Guo, Gua mailto:gua@intel.com>>; Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen mailto:jiewen@intel.com>>; Abdul Lateef Attar mailto:abdullateef.at...@amd.com>>; Abner Chang mailto:abner.ch...@amd.com>>; Tom Lendacky mailto:thomas.lenda...@amd.com>> Subject: RE: [PATCH v4 00/14] Add SmmRelocationLib Thanks Ray, I missed to add some already reviewed-by tag in v4. All V4 patches are tested & acted by Gerd: Tested-by: Gerd Hoffmann mailto:kra...@redhat.com>> Acked-by: Gerd Hoffmann mailto:kra...@redhat.com>> For each one: listed as below, *so need Ray "reviewed-by" tag on the patch: 05/06/14, need Gerd "reviewed-by" tag on the patch: 08/09/10/11/12* [PATCH v4 01/14] UefiCpuPkg: Add SmmRelocationLib class Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 02/14] UefiCpuPkg/SmmRelocationLib: Add SmmRelocationLib library instance Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 03/14] UefiCpuPkg/SmmRelocationLib: Rename global variables Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 04/14] UefiCpuPkg/SmmRelocationLib: Avoid unnecessary memory allocation Reviewed-by: Ray Ni mailto:ray...@intel.com>> --> no change compared to V3 [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable [PATCH v4 06/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary CpuIndex * Change Based on Ray's comment on V3: split the removal of CpuIndex parameter in a new patch, so add the 06 patch in V4.* [PATCH v4 07/14] UefiCpuPkg/SmmRelocationLib: Add library instance for AMD Reviewed-by: Abdul Lateef Attar mailto:abdullateef.at...@amd.com>> --> no change compared to V3 [PATCH v4 08/14] OvmfPkg/SmmRelocationLib: Add library instance for OVMF [PATCH v4 09/14] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid [PATCH v4 10/14] OvmfPkg: Refine SmmAccess implementation [PATCH v4 11/14] OvmfPkg/SmmCpuFeaturesLib: Check Smbase Relocation is done or not [PATCH v4 12/14] OvmfPkg/PlatformPei: Relocate SmBases in PEI phase *Change Based on Gerd's comment on V3: 1. Creating the EFI_SMM_SMRAM_MEMORY_GUID HOB should be moved to its own function. 2) refine the comment in SmmAccess 3) refine the commit log.* [PATCH v4 13/14] UefiPayloadPkg/UefiPayloadPkg.dsc: Include SmmRelocationLib Reviewed-by: Gua Guo mailto:gua@intel.com>> Reviewed-by: Guo D