Date   

[edk2-staging][PATCH v2 1/3] edk2-staging/RedfishClientPkg: Introduce Redfish event library

Nickle Wang
 

Add RedfishEventLib to Redfish client package. This library provides
interface for Redfish feature drivers to listen to Redfish event
such as the event before provisioning and the event after
provisioning. Feature driver can perform additional operation before
and after Redfish provisioning.

Signed-off-by: Nickle Wang <nickle.wang@...>
Cc: Abner Chang <abner.chang@...>
---
.../Include/Guid/RedfishClientEventGroup.h | 27 ++++
.../Include/Library/RedfishEventLib.h | 77 ++++++++++
.../Library/RedfishEventLib/RedfishEventLib.c | 139 ++++++++++++++++++
.../RedfishEventLib/RedfishEventLib.inf | 38 +++++
RedfishClientPkg/RedfishClientLibs.dsc.inc | 2 +-
RedfishClientPkg/RedfishClientPkg.dec | 7 +-
6 files changed, 288 insertions(+), 2 deletions(-)
create mode 100644 RedfishClientPkg/Include/Guid/RedfishClientEventGroup.h
create mode 100644 RedfishClientPkg/Include/Library/RedfishEventLib.h
create mode 100644 RedfishClientPkg/Library/RedfishEventLib/RedfishEventLi=
b.c
create mode 100644 RedfishClientPkg/Library/RedfishEventLib/RedfishEventLi=
b.inf

diff --git a/RedfishClientPkg/Include/Guid/RedfishClientEventGroup.h b/Redf=
ishClientPkg/Include/Guid/RedfishClientEventGroup.h
new file mode 100644
index 0000000000..0d88dd4726
--- /dev/null
+++ b/RedfishClientPkg/Include/Guid/RedfishClientEventGroup.h
@@ -0,0 +1,27 @@
+/** @file=0D
+ GUID for Redfish Client Event Group GUID=0D
+=0D
+ (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#ifndef REDFISH_CLIENT_EVENT_GROUP_GUID_H_=0D
+#define REDFISH_CLIENT_EVENT_GROUP_GUID_H_=0D
+=0D
+#define REDFISH_CLIENT_FEATURE_READY_TO_PROVISIONING_GUID \=0D
+ { \=0D
+ 0x77E4FC1C, 0x2428, 0x47EE, { 0x9E, 0xEC, 0x8B, 0x77, 0xEF, 0x9D, 0x4E=
, 0xF0 } \=0D
+ }=0D
+=0D
+extern EFI_GUID gEfiRedfishClientFeatureReadyToProvisioningGuid;=0D
+=0D
+#define REDFISH_CLIENT_FEATURE_AFTER_PROVISIONING_GUID \=0D
+ { \=0D
+ 0xE547CB6F, 0x306F, 0x4226, { 0xAB, 0x70, 0xA0, 0x6E, 0x26, 0xF1, 0x2E=
, 0xD0 } \=0D
+ }=0D
+=0D
+extern EFI_GUID gEfiRedfishClientFeatureAfterProvisioningGuid;=0D
+=0D
+#endif=0D
diff --git a/RedfishClientPkg/Include/Library/RedfishEventLib.h b/RedfishCl=
ientPkg/Include/Library/RedfishEventLib.h
new file mode 100644
index 0000000000..9b553f4425
--- /dev/null
+++ b/RedfishClientPkg/Include/Library/RedfishEventLib.h
@@ -0,0 +1,77 @@
+/** @file=0D
+ This file defines the Redfish event library interface.=0D
+=0D
+ (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#ifndef REDFISH_EVENT_LIB_H_=0D
+#define REDFISH_EVENT_LIB_H_=0D
+=0D
+#include <Uefi.h>=0D
+=0D
+/**=0D
+ Create an EFI event before Redfish provisioning start.=0D
+=0D
+ @param NotifyFunction The notification function to call when=
the event is signaled.=0D
+ @param NotifyContext The content to pass to NotifyFunction =
when the event is signaled.=0D
+ @param ReadyToProvisioningEvent Returns the EFI event returned from gB=
S->CreateEvent(Ex).=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+CreateReadyToProvisioningEvent (=0D
+ IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL=0D
+ IN VOID *NotifyContext, OPTIONAL=0D
+ OUT EFI_EVENT *ReadyToProvisioningEvent=0D
+ );=0D
+=0D
+/**=0D
+ Create an EFI event after Redfish provisioning finished.=0D
+=0D
+ @param NotifyFunction The notification function to call when=
the event is signaled.=0D
+ @param NotifyContext The content to pass to NotifyFunction =
when the event is signaled.=0D
+ @param ReadyToProvisioningEvent Returns the EFI event returned from gB=
S->CreateEvent(Ex).=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+CreateAfterProvisioningEvent (=0D
+ IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL=0D
+ IN VOID *NotifyContext, OPTIONAL=0D
+ OUT EFI_EVENT *ReadyToProvisioningEvent=0D
+ );=0D
+=0D
+/**=0D
+ Signal ready to provisioning event.=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+SignalReadyToProvisioningEvent (=0D
+ VOID=0D
+ );=0D
+=0D
+/**=0D
+ Signal after provisioning event.=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+SignalAfterProvisioningEvent (=0D
+ VOID=0D
+ );=0D
+=0D
+#endif=0D
diff --git a/RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.c b/R=
edfishClientPkg/Library/RedfishEventLib/RedfishEventLib.c
new file mode 100644
index 0000000000..34aa4cac46
--- /dev/null
+++ b/RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.c
@@ -0,0 +1,139 @@
+/** @file=0D
+ Redfish event library implementation.=0D
+=0D
+ (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include <Uefi.h>=0D
+=0D
+#include <Guid/RedfishClientEventGroup.h>=0D
+=0D
+#include <Library/UefiLib.h>=0D
+#include <Library/BaseLib.h>=0D
+#include <Library/DebugLib.h>=0D
+#include <Library/UefiBootServicesTableLib.h>=0D
+#include <Library/RedfishEventLib.h>=0D
+=0D
+/**=0D
+ Create an EFI event before Redfish provisioning start.=0D
+=0D
+ @param NotifyFunction The notification function to call when=
the event is signaled.=0D
+ @param NotifyContext The content to pass to NotifyFunction =
when the event is signaled.=0D
+ @param ReadyToProvisioningEvent Returns the EFI event returned from gB=
S->CreateEvent(Ex).=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+CreateReadyToProvisioningEvent (=0D
+ IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL=0D
+ IN VOID *NotifyContext, OPTIONAL=0D
+ OUT EFI_EVENT *ReadyToProvisioningEvent=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+=0D
+ Status =3D gBS->CreateEventEx (=0D
+ EVT_NOTIFY_SIGNAL,=0D
+ TPL_CALLBACK,=0D
+ (NotifyFunction =3D=3D NULL ? EfiEventEmptyFunction : No=
tifyFunction),=0D
+ NotifyContext,=0D
+ &gEfiRedfishClientFeatureReadyToProvisioningGuid,=0D
+ ReadyToProvisioningEvent=0D
+ );=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
+/**=0D
+ Create an EFI event after Redfish provisioning finished.=0D
+=0D
+ @param NotifyFunction The notification function to call when=
the event is signaled.=0D
+ @param NotifyContext The content to pass to NotifyFunction =
when the event is signaled.=0D
+ @param ReadyToProvisioningEvent Returns the EFI event returned from gB=
S->CreateEvent(Ex).=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+CreateAfterProvisioningEvent (=0D
+ IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL=0D
+ IN VOID *NotifyContext, OPTIONAL=0D
+ OUT EFI_EVENT *ReadyToProvisioningEvent=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+=0D
+ Status =3D gBS->CreateEventEx (=0D
+ EVT_NOTIFY_SIGNAL,=0D
+ TPL_CALLBACK,=0D
+ (NotifyFunction =3D=3D NULL ? EfiEventEmptyFunction : No=
tifyFunction),=0D
+ NotifyContext,=0D
+ &gEfiRedfishClientFeatureAfterProvisioningGuid,=0D
+ ReadyToProvisioningEvent=0D
+ );=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
+/**=0D
+ Signal ready to provisioning event.=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+SignalReadyToProvisioningEvent (=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_EVENT Event;=0D
+=0D
+ Status =3D CreateReadyToProvisioningEvent (NULL, NULL, &Event);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "%a, failed to create after provisioning event\n"=
, __FUNCTION__));=0D
+ return Status;=0D
+ }=0D
+=0D
+ gBS->SignalEvent (Event);=0D
+ gBS->CloseEvent (Event);=0D
+=0D
+ return EFI_SUCCESS;=0D
+}=0D
+=0D
+/**=0D
+ Signal after provisioning event.=0D
+=0D
+ @retval EFI_SUCCESS Event was created.=0D
+ @retval Other Event was not created.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+SignalAfterProvisioningEvent (=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_EVENT Event;=0D
+=0D
+ Status =3D CreateAfterProvisioningEvent (NULL, NULL, &Event);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "%a, failed to create after provisioning event\n"=
, __FUNCTION__));=0D
+ return Status;=0D
+ }=0D
+=0D
+ gBS->SignalEvent (Event);=0D
+ gBS->CloseEvent (Event);=0D
+=0D
+ return EFI_SUCCESS;=0D
+}=0D
+=0D
diff --git a/RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf b=
/RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf
new file mode 100644
index 0000000000..edafca0c65
--- /dev/null
+++ b/RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.inf
@@ -0,0 +1,38 @@
+## @file=0D
+#=0D
+# (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>=0D
+#=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 0x00010006=0D
+ BASE_NAME =3D RedfishEventLib=0D
+ FILE_GUID =3D C4F7E27D-2338-43EA-9D1F-D10960E36521=
=0D
+ MODULE_TYPE =3D DXE_DRIVER=0D
+ VERSION_STRING =3D 1.0=0D
+ LIBRARY_CLASS =3D RedfishEventLib| DXE_DRIVER UEFI_DRIV=
ER=0D
+=0D
+#=0D
+# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D
+#=0D
+=0D
+[Sources]=0D
+ RedfishEventLib.c=0D
+=0D
+[Packages]=0D
+ MdePkg/MdePkg.dec=0D
+ MdeModulePkg/MdeModulePkg.dec=0D
+ RedfishPkg/RedfishPkg.dec=0D
+ RedfishClientPkg/RedfishClientPkg.dec=0D
+=0D
+[LibraryClasses]=0D
+ BaseLib=0D
+ DebugLib=0D
+ UefiBootServicesTableLib=0D
+ UefiLib=0D
+=0D
+[Guids]=0D
+ gEfiRedfishClientFeatureReadyToProvisioningGuid=0D
+ gEfiRedfishClientFeatureAfterProvisioningGuid=0D
diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/=
RedfishClientLibs.dsc.inc
index 5467acedd0..91e5de4296 100644
--- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
+++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
@@ -27,4 +27,4 @@
RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/Red=
fishPlatformConfigLib.inf=0D
RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/R=
edfishContentCodingLibNull.inf=0D
ConverterCommonLib|RedfishClientPkg/ConverterLib/edk2library/ConverterCo=
mmonLib/ConverterCommonLib.inf=0D
-=0D
+ RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib=
.inf=0D
diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/Redfi=
shClientPkg.dec
index 09df062dd3..56e542f03c 100644
--- a/RedfishClientPkg/RedfishClientPkg.dec
+++ b/RedfishClientPkg/RedfishClientPkg.dec
@@ -1,7 +1,7 @@
## @file=0D
# Redfish Client Package=0D
#=0D
-# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>=0D
+# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>=0D
#=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
##=0D
@@ -21,6 +21,7 @@
=0D
[LibraryClasses]=0D
RedfishFeatureUtilityLib|Include/Library/RedfishFeatureUtilityLib.h=0D
+ RedfishEventLib|Include/Library/RedfishEventLib.h=0D
=0D
[LibraryClasses.Common.Private]=0D
## @libraryclass Redfish Helper Library=0D
@@ -39,6 +40,10 @@
## Include/Guid/RedfishClientPkgTokenSpace.h=0D
gEfiRedfishClientPkgTokenSpaceGuid =3D { 0x8c444dae, 0x728b, 0x48ee, =
{ 0x9e, 0x19, 0x8f, 0x0a, 0x3d, 0x4e, 0x9c, 0xc8 } }=0D
=0D
+ ## Include/Guid/RedfishClientEventGroup.h=0D
+ gEfiRedfishClientFeatureReadyToProvisioningGuid =3D { 0x77E4FC1C, 0x2428=
, 0x47EE, { 0x9E, 0xEC, 0x8B, 0x77, 0xEF, 0x9D, 0x4E, 0xF0 } }=0D
+ gEfiRedfishClientFeatureAfterProvisioningGuid =3D { 0xE547CB6F, 0x306F=
, 0x4226, { 0xAB, 0x70, 0xA0, 0x6E, 0x26, 0xF1, 0x2E, 0xD0 } }=0D
+=0D
[PcdsFixedAtBuild]=0D
gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize|32|UINT=
32|0x10000001=0D
gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize|8|UINT=
32|0x10000002=0D
--=20
2.32.0.windows.2


Re: [PATCH] OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop

Yao, Jiewen
 

Agree to merge to stable tag. Thanks for the reminder.

Reviewed-by: Jiewen Yao@...

-----Original Message-----
From: gaoliming <gaoliming@...>
Sent: Wednesday, May 25, 2022 10:40 AM
To: devel@edk2.groups.io; Xu, Min M <min.m.xu@...>; Yamahata, Isaku
<isaku.yamahata@...>
Cc: Yao, Jiewen <jiewen.yao@...>
Subject: 回复: [edk2-devel] [PATCH] OvmfPkg: TdxDxe: Fix
AsmRelocateApMailBoxLoop

Min, Isaku, Jiewen:
Is this patch required to catch edk2 202205 stable tag?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Min Xu
发送时间: 2022年5月24日 17:14
收件人: Yamahata, Isaku <isaku.yamahata@...>;
devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH] OvmfPkg: TdxDxe: Fix
AsmRelocateApMailBoxLoop

On May 24, 2022 3:54 PM, Yamahata, Isaku wrote:

In TDX, Application Processor busy-loops on Mailbox for OS to issue
MpProtectedModeWakeupCommandWakeup command to UEFI. As the
AP
acking to it, it clears the command member according to ACPI spec 6.4,
5.2.12.19 Multiprocessor Wakeup Structure: "The application processor
need clear the command to Noop(0) as the acknowledgement that the
command is received."
However, AsmRelocateApMailBoxLoop wrongly clears WakeupVector.
Correctly clear command instead of WakeupVector.

Without this patch, TD guest kernel fails to boot APs.

Fixes: fae5c1464d ("OvmfPkg: Add TdxDxe driver")
Cc: Min Xu <min.m.xu@...>
Signed-off-by: Isaku Yamahata <isaku.yamahata@...>
---
OvmfPkg/TdxDxe/X64/ApRunLoop.nasm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
index 49bd04415c..a859375fb8 100644
--- a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
+++ b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
@@ -69,7 +69,7 @@ MailBoxWakeUp:
mov rax, [rbx + WakeupVectorOffset] ; OS sends a
wakeup command
for a given APIC ID, firmware is supposed to reset ; the command
field
back
to zero as acknowledgement.- mov qword [rbx +
WakeupVectorOffset],
0+ mov qword [rbx + CommandOffset], 0 jmp
rax MailBoxSleep:
jmp $--
2.25.1
Thanks Isaku.
Reviewed-by: Min Xu <min.m.xu@...>





Re: [PATCH 1/1] OvmfPkg: fix PcdFSBClock

Yao, Jiewen
 

Agree to merge to stable tag. Thanks for the reminder.

Reviewed-by: Jiewen Yao@...

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming
Sent: Wednesday, May 25, 2022 9:43 AM
To: devel@edk2.groups.io; kraxel@...
Cc: 'Pawel Polawski' <ppolawsk@...>; 'Oliver Steffen'
<osteffen@...>; 'Laszlo Ersek' <lersek@...>
Subject: 回复: [edk2-devel] [PATCH 1/1] OvmfPkg: fix PcdFSBClock

Gerd:
I am OK to merge this bug fix for stable tag 202205 once this patch passes
code review.

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Gerd
Hoffmann
发送时间: 2022年5月24日 14:29
收件人: devel@edk2.groups.io; gaoliming@...
抄送: Pawel Polawski <ppolawsk@...>; Oliver Steffen
<osteffen@...>; Laszlo Ersek <lersek@...>
主题: Re: [edk2-devel] [PATCH 1/1] OvmfPkg: fix PcdFSBClock

On Mon, May 23, 2022 at 03:45:04PM +0200, Gerd Hoffmann wrote:
kvm FSB clock is 1GHz, not 100 MHz. Timings are off by factor 10.
Fix all affected build configurations. Not changed: Microvm and
Cloudhw (they have already have the correct value), and Xen (has
no fixed frequency, the PCD is configured at runtime by platform
initialization code).

Fixes: c37cbc030d96 ("OvmfPkg: Switch timer in build time for OvmfPkg")
Cc'ing gaoliming.

This fixes a regression and should go into 220205

thanks,
Gerd










回复: [edk2-devel] [PATCH] OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop

gaoliming
 

Min, Isaku, Jiewen:
Is this patch required to catch edk2 202205 stable tag?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Min Xu
发送时间: 2022年5月24日 17:14
收件人: Yamahata, Isaku <isaku.yamahata@...>;
devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH] OvmfPkg: TdxDxe: Fix
AsmRelocateApMailBoxLoop

On May 24, 2022 3:54 PM, Yamahata, Isaku wrote:

In TDX, Application Processor busy-loops on Mailbox for OS to issue
MpProtectedModeWakeupCommandWakeup command to UEFI. As the
AP
acking to it, it clears the command member according to ACPI spec 6.4,
5.2.12.19 Multiprocessor Wakeup Structure: "The application processor
need clear the command to Noop(0) as the acknowledgement that the
command is received."
However, AsmRelocateApMailBoxLoop wrongly clears WakeupVector.
Correctly clear command instead of WakeupVector.

Without this patch, TD guest kernel fails to boot APs.

Fixes: fae5c1464d ("OvmfPkg: Add TdxDxe driver")
Cc: Min Xu <min.m.xu@...>
Signed-off-by: Isaku Yamahata <isaku.yamahata@...>
---
OvmfPkg/TdxDxe/X64/ApRunLoop.nasm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
index 49bd04415c..a859375fb8 100644
--- a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
+++ b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
@@ -69,7 +69,7 @@ MailBoxWakeUp:
mov rax, [rbx + WakeupVectorOffset] ; OS sends a
wakeup command
for a given APIC ID, firmware is supposed to reset ; the command
field
back
to zero as acknowledgement.- mov qword [rbx +
WakeupVectorOffset],
0+ mov qword [rbx + CommandOffset], 0 jmp
rax MailBoxSleep:
jmp $--
2.25.1
Thanks Isaku.
Reviewed-by: Min Xu <min.m.xu@...>





回复: [edk2-devel] [PATCH 1/1] OvmfPkg: fix PcdFSBClock

gaoliming
 

Gerd:
I am OK to merge this bug fix for stable tag 202205 once this patch passes
code review.

Thanks
Liming

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Gerd
Hoffmann
发送时间: 2022年5月24日 14:29
收件人: devel@edk2.groups.io; gaoliming@...
抄送: Pawel Polawski <ppolawsk@...>; Oliver Steffen
<osteffen@...>; Laszlo Ersek <lersek@...>
主题: Re: [edk2-devel] [PATCH 1/1] OvmfPkg: fix PcdFSBClock

On Mon, May 23, 2022 at 03:45:04PM +0200, Gerd Hoffmann wrote:
kvm FSB clock is 1GHz, not 100 MHz. Timings are off by factor 10.
Fix all affected build configurations. Not changed: Microvm and
Cloudhw (they have already have the correct value), and Xen (has
no fixed frequency, the PCD is configured at runtime by platform
initialization code).

Fixes: c37cbc030d96 ("OvmfPkg: Switch timer in build time for OvmfPkg")
Cc'ing gaoliming.

This fixes a regression and should go into 220205

thanks,
Gerd





Can you create a PCI Option ROM and place it in an FV in a single build?

Andrew Fish
 

I realize I can use syntax like this to control the construction of an option ROM from an FDF file.

1
[OptionRom.AtapiPassThru]
2
INF USE = IA32 OptionRomPkg/AtapiPassThruDxe/AtapiPassThruDxe.inf {
3
PCI_REVISION = 0x0020
4
PCI_DEVICE_ID = 0x0A03 0x0B03
5
}
6
INF USE = EBC OptionRomPkg/AtapiPassThruDxe/AtapiPassThruDxe.inf


What I can’t figure out is how to get that PCI ROM in the FV?

Thanks,

Andrew Fish


Re: [PATCH 1/1] OvmfPkg: fix PcdFSBClock

Laszlo Ersek
 

On 05/23/22 15:45, Gerd Hoffmann wrote:
kvm FSB clock is 1GHz, not 100 MHz. Timings are off by factor 10.
Fix all affected build configurations. Not changed: Microvm and
Cloudhw (they have already have the correct value), and Xen (has
no fixed frequency, the PCD is configured at runtime by platform
initialization code).

Fixes: c37cbc030d96 ("OvmfPkg: Switch timer in build time for OvmfPkg")
Consider adding "Fixes: 44a53a3bdd9c7" too, on a separate line; commit
44a53a3bdd9c ("OvmfPkg: Introduce IntelTdxX64 for TDVF Config-B",
2022-04-02) copied the wrong setting when creating
"OvmfPkg/IntelTdx/IntelTdxX64.dsc".

(Obviously it needs no repost.)

Reported-by: Laszlo Ersek <lersek@...>
Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +-
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 +-
OvmfPkg/OvmfPkgIa32.dsc | 2 +-
OvmfPkg/OvmfPkgIa32X64.dsc | 2 +-
OvmfPkg/OvmfPkgX64.dsc | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
Using "OvmfPkg/OvmfPkgX64.dsc":

Tested-by: Laszlo Ersek <lersek@...>

By the way: "kvm FSB clock is 1GHz" -- where is that constant set in
KVM?

... is it "target/i386/kvm/kvm.c" in QEMU:

/* From arch/x86/kvm/lapic.h */
#define KVM_APIC_BUS_CYCLE_NS 1
#define KVM_APIC_BUS_FREQUENCY (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
FWIW, APIC_BUS_CYCLE_NS=1 goes back to historical KVM commit
97222cc83163 ("KVM: Emulate local APIC in kernel", 2007-10-13). The
commit does not say anything about this particular choice. (Maybe I
should look at the QEMU source from 2007 -- perhaps the KVM commit was
inspired by QEMU practice back then. And now we've come full circle: the
definitive constant lives in the kernel, which is where QEMU is taking
it from...)

... I think these macros are pretty difficult to find, unless one knows
already what they're looking for!

BTW is there a chance that TCG uses a different frequency?

Thanks!
Laszlo


diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index bead9722eab8..fc1fdb2e2297 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -578,7 +578,7 @@ [PcdsDynamicDefault]

!include OvmfPkg/OvmfTpmPcds.dsc.inc

- gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
+ gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000

[PcdsDynamicHii]
!include OvmfPkg/OvmfTpmPcdsHii.dsc.inc
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 00bc1255bc4e..dd8d446f4a56 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -511,7 +511,7 @@ [PcdsDynamicDefault]
# Set ConfidentialComputing defaults
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0

- gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
+ gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000

################################################################################
#
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index c16a840fff16..a9841cbfc3ca 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -651,7 +651,7 @@ [PcdsDynamicDefault]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0

!if $(CSM_ENABLE) == FALSE
- gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
+ gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif

[PcdsDynamicHii]
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index d3a80cb56892..f7949780fa38 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -659,7 +659,7 @@ [PcdsDynamicDefault]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0

!if $(CSM_ENABLE) == FALSE
- gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
+ gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif

[PcdsDynamicDefault.X64]
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 7b3d48aac430..1448f925b782 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -684,7 +684,7 @@ [PcdsDynamicDefault]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0

!if $(CSM_ENABLE) == FALSE
- gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
+ gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif

[PcdsDynamicHii]


Re: How to create a account on bugzilla.tianocore.org ?

Michael D Kinney
 

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of joeyli via groups.io
Sent: Sunday, May 22, 2022 8:23 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] How to create a account on bugzilla.tianocore.org ?

Hi experts,

We want to report bug on bugzilla.tianocore.org but the system doesn't
provide link for creating new account. How should I do for creating
a account on bugzilla.tianocore.org?

Thanks!
Joey Lee





Re: [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

Wang, Jian J
 

I see. With its addressed,

Reviewed-by: Jian J Wang <jian.j.wang@...>

Regards,
Jian

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Tuesday, May 24, 2022 4:02 PM
To: Wang, Jian J <jian.j.wang@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: Re: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code
pages for DXE instance

Jian,
Ia32/ExceptionHandlerAsm.nasm is used by 32bit DxeCpuExceptionHandlerLib
instance.

I agree the commit message is not correct. The commit message says
SEC still creates 32 entries but 32bit SEC creates 256 entries.

I will update the commit message to align to code behavior.

Thanks,
Ray

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:40
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code
pages for DXE instance

Ray,

You changed "%rep 32" to "%rep 256" in Ia32/ExceptionHandlerAsm.nasm.
According to my understanding and your comments, this should be done
only to X64 code, right?

Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages
for DXE instance

Today the DXE instance allocates code page and then copies the IDT
vectors to the allocated code page. Then it fixes up the vector number
in the IDT vector.

But if we update the NASM file to generate 256 IDT vectors, there is
no need to do the copy and fix-up.

A side effect is up to 4096 bytes (HOOKAFTER_STUB_SIZE * 256) is
used for 256 IDT vectors. While 32 IDT vectors only require 512 bytes.

But considering the code logic simplification, 3.5K space is not a big
deal. SEC instance still generates 32 IDT vectors so no impact to SEC.
If 3.5K is too much a waste in PEI phase, we can enhance the code
further to generate 32 vectors for PEI.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../CpuExceptionHandlerLib/DxeException.c | 22 -------------------
.../Ia32/ExceptionHandlerAsm.nasm | 4 ++--
.../X64/ExceptionHandlerAsm.nasm | 2 ++
.../X64/Xcode5ExceptionHandlerAsm.nasm | 9 ++++----
4 files changed, 9 insertions(+), 28 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index 61f11e98f8..5083c4b8e8 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -95,9 +95,6 @@ InitializeCpuInterruptHandlers (
IA32_DESCRIPTOR IdtDescriptor;

UINTN IdtEntryCount;

EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;

- UINTN Index;

- UINTN InterruptEntry;

- UINT8 *InterruptEntryCode;

RESERVED_VECTORS_DATA *ReservedVectors;

EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;



@@ -138,25 +135,6 @@ InitializeCpuInterruptHandlers (
AsmGetTemplateAddressMap (&TemplateMap);

ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);



- Status = gBS->AllocatePool (

- EfiBootServicesCode,

- TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,

- (VOID **)&InterruptEntryCode

- );

- ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);

-

- InterruptEntry = (UINTN)InterruptEntryCode;

- for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {

- CopyMem (

- (VOID *)InterruptEntry,

- (VOID *)TemplateMap.ExceptionStart,

- TemplateMap.ExceptionStubHeaderSize

- );

- AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID
*)TemplateMap.ExceptionStart);

- InterruptEntry += TemplateMap.ExceptionStubHeaderSize;

- }

-

- TemplateMap.ExceptionStart = (UINTN)InterruptEntryCode;

mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;

mExceptionHandlerData.ReservedVectors = ReservedVectors;

mExceptionHandlerData.ExternalInterruptHandler =
ExternalInterruptHandler;

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
index 3fe9aed1e8..8ed2b8f455 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
@@ -33,7 +33,7 @@ ALIGN 8
;

AsmIdtVectorBegin:

%assign Vector 0

-%rep 32

+%rep 256

push byte %[Vector];

push eax

mov eax, ASM_PFX(CommonInterruptEntry)

@@ -439,7 +439,7 @@ ASM_PFX(AsmGetTemplateAddressMap):


mov ebx, dword [ebp + 0x8]

mov dword [ebx], AsmIdtVectorBegin

- mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

mov dword [ebx + 0x8], HookAfterStubBegin



popad

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
index 9a806d1f86..aaf8d622e6 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
@@ -31,6 +31,8 @@ SECTION .text


ALIGN 8



+; Generate 32 IDT vectors.

+; 32 IDT vectors are enough because interrupts (32+) are not enabled in SEC
and
PEI phase.

AsmIdtVectorBegin:

%assign Vector 0

%rep 32

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
index 9c72fa5815..7c0e3d3b0b 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
@@ -53,9 +53,10 @@ SECTION .text


ALIGN 8



+; Generate 256 IDT vectors.

AsmIdtVectorBegin:

%assign Vector 0

-%rep 32

+%rep 256

push byte %[Vector]

push rax

mov rax, strict qword 0 ; mov rax, ASM_PFX(CommonInterruptEntry)

@@ -453,16 +454,16 @@ global ASM_PFX(AsmGetTemplateAddressMap)
ASM_PFX(AsmGetTemplateAddressMap):

lea rax, [AsmIdtVectorBegin]

mov qword [rcx], rax

- mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

lea rax, [HookAfterStubHeaderBegin]

mov qword [rcx + 0x10], rax



; Fix up CommonInterruptEntry address

lea rax, [ASM_PFX(CommonInterruptEntry)]

lea rcx, [AsmIdtVectorBegin]

-%rep 32

+%rep 256

mov qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)],
rax

- add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

%endrep

; Fix up HookAfterStubHeaderEnd

lea rax, [HookAfterStubHeaderEnd]

--
2.35.1.windows.2



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89916): https://edk2.groups.io/g/devel/message/89916
Mute This Topic: https://groups.io/mt/91231767/1768734
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
-=-=-=-=-=-=


Re: [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

Wang, Jian J
 

Another patch works for me.

Reviewed-by: Jian J Wang <jian.j.wang@...>

Regards,
Jian

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Tuesday, May 24, 2022 4:04 PM
To: Wang, Jian J <jian.j.wang@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: Re: [edk2-devel] [PATCH 4/5] CpuException: Remove
InitializeCpuInterruptHandlers

Jian,
I think we need discussion on where to put the common CPU_INTERRUPT_NUM
definition.

Do you agree that we can leave that to another patch?

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:27
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 4/5] CpuException: Remove
InitializeCpuInterruptHandlers

Hi Ray,

Both CpuDxe.c and CpuExceptionCommon.h have CPU_INTERRUPT_NUM
defined.
I'd suggest to move it to a common place, such as BaseLib.h. I don't see any
issue
if they are defined to different value. It just gives me a feeling that it might
cause
potential problems sometimes in the future.


Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [edk2-devel] [PATCH 4/5] CpuException: Remove
InitializeCpuInterruptHandlers

InitializeCpuExceptionHandlers() expects caller allocates IDT while
InitializeCpuInterruptHandlers() allocates 256 IDT entries itself.

InitializeCpuExceptionHandlers() fills max 32 IDT entries allocated
by caller. If caller allocates 10 entries, the API just fills 10 IDT
entries.

The inconsistency between the two APIs makes code hard to
unerstand and hard to share.

Because there is only one caller (CpuDxe) for
InitializeCpuInterruptHandler(), this patch updates CpuDxe driver
to allocates 256 IDT entries then call
InitializeCpuExceptionHandlers().

With this change, InitializeCpuInterruptHandlers() is removed
completely.

And InitializeCpuExceptionHandlers() fills max 32 entries for PEI
and SMM instance, max 256 entries for DXE instance.
Such behavior matches to the original one.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../Include/Library/CpuExceptionHandlerLib.h | 28 +------
.../CpuExceptionHandlerLibNull.c | 31 +------
UefiCpuPkg/CpuDxe/CpuDxe.c | 33 ++++++--
.../CpuExceptionHandlerLib/DxeException.c | 80 ++-----------------
.../CpuExceptionHandlerLib/PeiCpuException.c | 61 +-------------
.../PeiDxeSmmCpuException.c | 19 ++---
.../SecPeiCpuException.c | 31 +------
.../CpuExceptionHandlerLib/SmmException.c | 35 ++------
8 files changed, 56 insertions(+), 262 deletions(-)

diff --git a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
index 22a4408f9f..d4649bebe1 100644
--- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
+++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
@@ -2,7 +2,7 @@
CPU Exception library provides the default CPU interrupt/exception handler.

It also provides capability to register user interrupt/exception handler.



- Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -132,28 +132,6 @@ InitializeCpuExceptionHandlersEx (
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL

);



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- );

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -161,8 +139,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git
a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
index 35ab5a8db5..54f38788fe 100644
---
a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
+++
b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
@@ -1,7 +1,7 @@
/** @file

CPU Exception Handler library implementition with empty functions.



- Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -33,31 +33,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_SUCCESS;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -65,8 +40,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
index 00f3cb0957..a6a91507f6 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.c
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
@@ -1,7 +1,7 @@
/** @file

CPU DXE Module to produce CPU ARCH Protocol.



- Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -10,6 +10,8 @@
#include "CpuMp.h"

#include "CpuPageTable.h"



+#define CPU_INTERRUPT_NUM 256

+

//

// Global Variables

//

@@ -924,9 +926,12 @@ InitInterruptDescriptorTable (
VOID

)

{

- EFI_STATUS Status;

- EFI_VECTOR_HANDOFF_INFO *VectorInfoList;

- EFI_VECTOR_HANDOFF_INFO *VectorInfo;

+ EFI_STATUS Status;

+ EFI_VECTOR_HANDOFF_INFO *VectorInfoList;

+ EFI_VECTOR_HANDOFF_INFO *VectorInfo;

+ IA32_IDT_GATE_DESCRIPTOR *IdtTable;

+ IA32_DESCRIPTOR IdtDescriptor;

+ UINTN IdtEntryCount;



VectorInfo = NULL;

Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid,
(VOID **)&VectorInfoList);

@@ -934,7 +939,25 @@ InitInterruptDescriptorTable (
VectorInfo = VectorInfoList;

}



- Status = InitializeCpuInterruptHandlers (VectorInfo);

+ AsmReadIdtr (&IdtDescriptor);

+ IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

+ if (IdtEntryCount < CPU_INTERRUPT_NUM) {

+ //

+ // Increase Interrupt Descriptor Table and Copy the old IDT table in

+ //

+ IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM);

+ ASSERT (IdtTable != NULL);

+ CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
(IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);

+

+ //

+ // Load Interrupt Descriptor Table

+ //

+ IdtDescriptor.Base = (UINTN)IdtTable;

+ IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM - 1);

+ AsmWriteIdtr (&IdtDescriptor);

+ }

+

+ Status = InitializeCpuExceptionHandlers (VectorInfo);

ASSERT_EFI_ERROR (Status);

}



diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index f139131a7c..c7c1fe31d2 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implemenation for DXE modules.



- Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -17,8 +17,8 @@ CONST UINTN mDoFarReturnFlag = 0;
RESERVED_VECTORS_DATA
mReservedVectorsData[CPU_INTERRUPT_NUM];

EFI_CPU_INTERRUPT_HANDLER
mExternalInterruptHandlerTable[CPU_INTERRUPT_NUM];

EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

- 0, // To be fixed

- 0, // To be fixed

+ CPU_INTERRUPT_NUM,

+ 0, // To be fixed

mReservedVectorsData,

mExternalInterruptHandlerTable

};

@@ -69,76 +69,6 @@ InitializeCpuExceptionHandlers (
return InitializeCpuExceptionHandlersWorker (VectorInfo,
&mExceptionHandlerData);

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- EFI_STATUS Status;

- IA32_IDT_GATE_DESCRIPTOR *IdtTable;

- IA32_DESCRIPTOR IdtDescriptor;

- UINTN IdtEntryCount;

- EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;

-

- SetMem ((VOID *)mReservedVectorsData, sizeof
(RESERVED_VECTORS_DATA)
* CPU_INTERRUPT_NUM, 0xff);

- if (VectorInfo != NULL) {

- Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectorsData,
CPU_INTERRUPT_NUM);

- if (EFI_ERROR (Status)) {

- return EFI_INVALID_PARAMETER;

- }

- }

-

- //

- // Read IDT descriptor and calculate IDT size

- //

- AsmReadIdtr (&IdtDescriptor);

- IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

- if (IdtEntryCount > CPU_INTERRUPT_NUM) {

- IdtEntryCount = CPU_INTERRUPT_NUM;

- }

-

- //

- // Create Interrupt Descriptor Table and Copy the old IDT table in

- //

- IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM);

- ASSERT (IdtTable != NULL);

- CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
(IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);

-

- AsmGetTemplateAddressMap (&TemplateMap);

- ASSERT (TemplateMap.ExceptionStubHeaderSize <=
HOOKAFTER_STUB_SIZE);

-

- mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;

- InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);

-

- UpdateIdtTable (IdtTable, &TemplateMap, &mExceptionHandlerData);

-

- //

- // Load Interrupt Descriptor Table

- //

- IdtDescriptor.Base = (UINTN)IdtTable;

- IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM - 1);

- AsmWriteIdtr ((IA32_DESCRIPTOR *)&IdtDescriptor);

-

- return EFI_SUCCESS;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -146,8 +76,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
index 687fc4177f..1ae611c75e 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implementation for PEIM module.



-Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -133,6 +133,7 @@ InitializeCpuExceptionHandlers (


ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));

ASSERT (ExceptionHandlerData != NULL);

+ ExceptionHandlerData->IdtEntryCount = CPU_EXCEPTION_NUM;

ExceptionHandlerData->ReservedVectors = ReservedVectors;

ExceptionHandlerData->ExternalInterruptHandler = NULL;

InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);

@@ -148,64 +149,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

-/**

- Registers a function to be called from the processor interrupt handler.

-

- This function registers and enables the handler specified by InterruptHandler
for a processor

- interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

- handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

- The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

-

- @param[in] InterruptType Defines which interrupt or exception to hook.

- @param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

- when a processor interrupt occurs. If this parameter is NULL,
then the handler

- will be uninstalled.

-

- @retval EFI_SUCCESS The handler for the processor interrupt was
successfully installed or uninstalled.

- @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a
handler
for InterruptType was

- previously installed.

- @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler
for
InterruptType was not

- previously installed.

- @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is
not
supported,

- or this function is not supported.

-**/

-EFI_STATUS

-EFIAPI

-RegisterCpuInterruptHandler (

- IN EFI_EXCEPTION_TYPE InterruptType,

- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Initializes all CPU exceptions entries with optional extra initializations.



diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
index f47a80dcab..a7d0897ef1 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU Exception Library provides PEI/DXE/SMM CPU common exception
handler.



-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -261,31 +261,26 @@ InitializeCpuExceptionHandlersWorker (
RESERVED_VECTORS_DATA *ReservedVectors;



ReservedVectors = ExceptionHandlerData->ReservedVectors;

- SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
CPU_EXCEPTION_NUM, 0xff);

+ SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
ExceptionHandlerData->IdtEntryCount, 0xff);

if (VectorInfo != NULL) {

- Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
CPU_EXCEPTION_NUM);

+ Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
ExceptionHandlerData->IdtEntryCount);

if (EFI_ERROR (Status)) {

return EFI_INVALID_PARAMETER;

}

}



//

- // Read IDT descriptor and calculate IDT size

+ // Setup the exception handlers according to IDT size, but no more than

+ // ExceptionHandlerData->IdtEntryCount (32 in PEI and SMM, 256 in DXE)
handlers.

//

AsmReadIdtr (&IdtDescriptor);

- IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

- if (IdtEntryCount > CPU_EXCEPTION_NUM) {

- //

- // CPU exception library only setup CPU_EXCEPTION_NUM exception
handler
at most

- //

- IdtEntryCount = CPU_EXCEPTION_NUM;

- }

+ IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

+ ExceptionHandlerData->IdtEntryCount = MIN (IdtEntryCount,
ExceptionHandlerData->IdtEntryCount);



IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;

AsmGetTemplateAddressMap (&TemplateMap);

ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);



- ExceptionHandlerData->IdtEntryCount = IdtEntryCount;

UpdateIdtTable (IdtTable, &TemplateMap, ExceptionHandlerData);



return EFI_SUCCESS;

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
index 6e5216380d..e894ead612 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implemenation for SEC/PEIM modules.



-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -166,31 +166,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -198,8 +173,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
index 9f0af4120a..ec643556c7 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implementation for SMM modules.



- Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -14,8 +14,8 @@ CONST UINTN mDoFarReturnFlag = 1;
RESERVED_VECTORS_DATA
mReservedVectorsData[CPU_EXCEPTION_NUM];

EFI_CPU_INTERRUPT_HANDLER
mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];

EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

- 0, // To be fixed

- 0, // To be fixed

+ CPU_EXCEPTION_NUM,

+ 0, // To be fixed

mReservedVectorsData,

mExternalInterruptHandlerTable

};

@@ -62,31 +62,6 @@ InitializeCpuExceptionHandlers (
return InitializeCpuExceptionHandlersWorker (VectorInfo,
&mExceptionHandlerData);

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that
are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo
to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -94,8 +69,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

--
2.35.1.windows.2



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89919): https://edk2.groups.io/g/devel/message/89919
Mute This Topic: https://groups.io/mt/91231770/1768734
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
-=-=-=-=-=-=


How to create a account on bugzilla.tianocore.org ?

joeyli
 

Hi experts,

We want to report bug on bugzilla.tianocore.org but the system doesn't
provide link for creating new account. How should I do for creating
a account on bugzilla.tianocore.org?

Thanks!
Joey Lee


Re: [PATCH v2 08/17] Silicon/Qemu: Update ARM_CORE_INFO initializer for MPIDR field change

Graeme Gregory <graeme@...>
 

On Thu, Dec 16, 2021 at 03:07:51PM -0700, Rebecca Cran wrote:
The ARM_CORE_INFO struct has been updated so the MPIDR is now a single
field instead of separate cluster/core fields. Update the initializer.

Signed-off-by: Rebecca Cran <rebecca@...>
Looks sane to me

Reviewed-by: Graeme Gregory <quic_ggregory@...>

---
Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.c
index fa9047020e6c..411f653913bd 100644
--- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.c
+++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.c
@@ -15,7 +15,7 @@
ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
{
// Cluster 0, Core 0
- 0x0, 0x0,
+ 0x000,

// MP Core MailBox Set/Get/Clear Addresses and Clear Value
(EFI_PHYSICAL_ADDRESS)0,
@@ -25,7 +25,7 @@ ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
},
{
// Cluster 0, Core 1
- 0x0, 0x1,
+ 0x001,

// MP Core MailBox Set/Get/Clear Addresses and Clear Value
(EFI_PHYSICAL_ADDRESS)0,
@@ -35,7 +35,7 @@ ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
},
{
// Cluster 0, Core 2
- 0x0, 0x2,
+ 0x002,

// MP Core MailBox Set/Get/Clear Addresses and Clear Value
(EFI_PHYSICAL_ADDRESS)0,
@@ -45,7 +45,7 @@ ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
},
{
// Cluster 0, Core 3
- 0x0, 0x3,
+ 0x003,

// MP Core MailBox Set/Get/Clear Addresses and Clear Value
(EFI_PHYSICAL_ADDRESS)0,
--
2.31.1


[PATCH] OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop

Isaku Yamahata
 

In TDX, Application Processor busy-loops on Mailbox for OS to issue
MpProtectedModeWakeupCommandWakeup command to UEFI. As the AP acking to
it, it clears the command member according to ACPI spec 6.4, 5.2.12.19
Multiprocessor Wakeup Structure: "The application processor need clear the
command to Noop(0) as the acknowledgement that the command is received."
However, AsmRelocateApMailBoxLoop wrongly clears WakeupVector. Correctly
clear command instead of WakeupVector.

Without this patch, TD guest kernel fails to boot APs.

Fixes: fae5c1464d ("OvmfPkg: Add TdxDxe driver")
Cc: Min Xu <min.m.xu@...>
Signed-off-by: Isaku Yamahata <isaku.yamahata@...>
---
OvmfPkg/TdxDxe/X64/ApRunLoop.nasm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm b/OvmfPkg/TdxDxe/X64/ApRunLo=
op.nasm
index 49bd04415c..a859375fb8 100644
--- a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
+++ b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
@@ -69,7 +69,7 @@ MailBoxWakeUp:
mov rax, [rbx + WakeupVectorOffset]=0D
; OS sends a wakeup command for a given APIC ID, firmware is supposed =
to reset=0D
; the command field back to zero as acknowledgement.=0D
- mov qword [rbx + WakeupVectorOffset], 0=0D
+ mov qword [rbx + CommandOffset], 0=0D
jmp rax=0D
MailBoxSleep:=0D
jmp $=0D
--=20
2.25.1


Re: [PATCH] OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop

Min Xu
 

On May 24, 2022 3:54 PM, Yamahata, Isaku wrote:

In TDX, Application Processor busy-loops on Mailbox for OS to issue
MpProtectedModeWakeupCommandWakeup command to UEFI. As the AP
acking to it, it clears the command member according to ACPI spec 6.4,
5.2.12.19 Multiprocessor Wakeup Structure: "The application processor
need clear the command to Noop(0) as the acknowledgement that the
command is received."
However, AsmRelocateApMailBoxLoop wrongly clears WakeupVector.
Correctly clear command instead of WakeupVector.

Without this patch, TD guest kernel fails to boot APs.

Fixes: fae5c1464d ("OvmfPkg: Add TdxDxe driver")
Cc: Min Xu <min.m.xu@...>
Signed-off-by: Isaku Yamahata <isaku.yamahata@...>
---
OvmfPkg/TdxDxe/X64/ApRunLoop.nasm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
index 49bd04415c..a859375fb8 100644
--- a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
+++ b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
@@ -69,7 +69,7 @@ MailBoxWakeUp:
mov rax, [rbx + WakeupVectorOffset] ; OS sends a wakeup command
for a given APIC ID, firmware is supposed to reset ; the command field back
to zero as acknowledgement.- mov qword [rbx + WakeupVectorOffset],
0+ mov qword [rbx + CommandOffset], 0 jmp rax MailBoxSleep:
jmp $--
2.25.1
Thanks Isaku.
Reviewed-by: Min Xu <min.m.xu@...>


Re: [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

Ni, Ray
 

Jian,
I think we need discussion on where to put the common CPU_INTERRUPT_NUM definition.

Do you agree that we can leave that to another patch?

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:27
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

Hi Ray,

Both CpuDxe.c and CpuExceptionCommon.h have CPU_INTERRUPT_NUM defined.
I'd suggest to move it to a common place, such as BaseLib.h. I don't see any issue
if they are defined to different value. It just gives me a feeling that it might cause
potential problems sometimes in the future.


Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [edk2-devel] [PATCH 4/5] CpuException: Remove
InitializeCpuInterruptHandlers

InitializeCpuExceptionHandlers() expects caller allocates IDT while
InitializeCpuInterruptHandlers() allocates 256 IDT entries itself.

InitializeCpuExceptionHandlers() fills max 32 IDT entries allocated
by caller. If caller allocates 10 entries, the API just fills 10 IDT
entries.

The inconsistency between the two APIs makes code hard to
unerstand and hard to share.

Because there is only one caller (CpuDxe) for
InitializeCpuInterruptHandler(), this patch updates CpuDxe driver
to allocates 256 IDT entries then call
InitializeCpuExceptionHandlers().

With this change, InitializeCpuInterruptHandlers() is removed
completely.

And InitializeCpuExceptionHandlers() fills max 32 entries for PEI
and SMM instance, max 256 entries for DXE instance.
Such behavior matches to the original one.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../Include/Library/CpuExceptionHandlerLib.h | 28 +------
.../CpuExceptionHandlerLibNull.c | 31 +------
UefiCpuPkg/CpuDxe/CpuDxe.c | 33 ++++++--
.../CpuExceptionHandlerLib/DxeException.c | 80 ++-----------------
.../CpuExceptionHandlerLib/PeiCpuException.c | 61 +-------------
.../PeiDxeSmmCpuException.c | 19 ++---
.../SecPeiCpuException.c | 31 +------
.../CpuExceptionHandlerLib/SmmException.c | 35 ++------
8 files changed, 56 insertions(+), 262 deletions(-)

diff --git a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
index 22a4408f9f..d4649bebe1 100644
--- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
+++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
@@ -2,7 +2,7 @@
CPU Exception library provides the default CPU interrupt/exception handler.

It also provides capability to register user interrupt/exception handler.



- Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -132,28 +132,6 @@ InitializeCpuExceptionHandlersEx (
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL

);



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- );

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -161,8 +139,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git
a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
index 35ab5a8db5..54f38788fe 100644
---
a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
+++
b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
Null.c
@@ -1,7 +1,7 @@
/** @file

CPU Exception Handler library implementition with empty functions.



- Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -33,31 +33,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_SUCCESS;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -65,8 +40,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
index 00f3cb0957..a6a91507f6 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.c
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
@@ -1,7 +1,7 @@
/** @file

CPU DXE Module to produce CPU ARCH Protocol.



- Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -10,6 +10,8 @@
#include "CpuMp.h"

#include "CpuPageTable.h"



+#define CPU_INTERRUPT_NUM 256

+

//

// Global Variables

//

@@ -924,9 +926,12 @@ InitInterruptDescriptorTable (
VOID

)

{

- EFI_STATUS Status;

- EFI_VECTOR_HANDOFF_INFO *VectorInfoList;

- EFI_VECTOR_HANDOFF_INFO *VectorInfo;

+ EFI_STATUS Status;

+ EFI_VECTOR_HANDOFF_INFO *VectorInfoList;

+ EFI_VECTOR_HANDOFF_INFO *VectorInfo;

+ IA32_IDT_GATE_DESCRIPTOR *IdtTable;

+ IA32_DESCRIPTOR IdtDescriptor;

+ UINTN IdtEntryCount;



VectorInfo = NULL;

Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid,
(VOID **)&VectorInfoList);

@@ -934,7 +939,25 @@ InitInterruptDescriptorTable (
VectorInfo = VectorInfoList;

}



- Status = InitializeCpuInterruptHandlers (VectorInfo);

+ AsmReadIdtr (&IdtDescriptor);

+ IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

+ if (IdtEntryCount < CPU_INTERRUPT_NUM) {

+ //

+ // Increase Interrupt Descriptor Table and Copy the old IDT table in

+ //

+ IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM);

+ ASSERT (IdtTable != NULL);

+ CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
(IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);

+

+ //

+ // Load Interrupt Descriptor Table

+ //

+ IdtDescriptor.Base = (UINTN)IdtTable;

+ IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM - 1);

+ AsmWriteIdtr (&IdtDescriptor);

+ }

+

+ Status = InitializeCpuExceptionHandlers (VectorInfo);

ASSERT_EFI_ERROR (Status);

}



diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index f139131a7c..c7c1fe31d2 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implemenation for DXE modules.



- Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -17,8 +17,8 @@ CONST UINTN mDoFarReturnFlag = 0;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_INTERRUPT_NUM];

EFI_CPU_INTERRUPT_HANDLER
mExternalInterruptHandlerTable[CPU_INTERRUPT_NUM];

EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

- 0, // To be fixed

- 0, // To be fixed

+ CPU_INTERRUPT_NUM,

+ 0, // To be fixed

mReservedVectorsData,

mExternalInterruptHandlerTable

};

@@ -69,76 +69,6 @@ InitializeCpuExceptionHandlers (
return InitializeCpuExceptionHandlersWorker (VectorInfo,
&mExceptionHandlerData);

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- EFI_STATUS Status;

- IA32_IDT_GATE_DESCRIPTOR *IdtTable;

- IA32_DESCRIPTOR IdtDescriptor;

- UINTN IdtEntryCount;

- EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;

-

- SetMem ((VOID *)mReservedVectorsData, sizeof (RESERVED_VECTORS_DATA)
* CPU_INTERRUPT_NUM, 0xff);

- if (VectorInfo != NULL) {

- Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectorsData,
CPU_INTERRUPT_NUM);

- if (EFI_ERROR (Status)) {

- return EFI_INVALID_PARAMETER;

- }

- }

-

- //

- // Read IDT descriptor and calculate IDT size

- //

- AsmReadIdtr (&IdtDescriptor);

- IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

- if (IdtEntryCount > CPU_INTERRUPT_NUM) {

- IdtEntryCount = CPU_INTERRUPT_NUM;

- }

-

- //

- // Create Interrupt Descriptor Table and Copy the old IDT table in

- //

- IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM);

- ASSERT (IdtTable != NULL);

- CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
(IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);

-

- AsmGetTemplateAddressMap (&TemplateMap);

- ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);

-

- mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;

- InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);

-

- UpdateIdtTable (IdtTable, &TemplateMap, &mExceptionHandlerData);

-

- //

- // Load Interrupt Descriptor Table

- //

- IdtDescriptor.Base = (UINTN)IdtTable;

- IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
CPU_INTERRUPT_NUM - 1);

- AsmWriteIdtr ((IA32_DESCRIPTOR *)&IdtDescriptor);

-

- return EFI_SUCCESS;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -146,8 +76,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
index 687fc4177f..1ae611c75e 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implementation for PEIM module.



-Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -133,6 +133,7 @@ InitializeCpuExceptionHandlers (


ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));

ASSERT (ExceptionHandlerData != NULL);

+ ExceptionHandlerData->IdtEntryCount = CPU_EXCEPTION_NUM;

ExceptionHandlerData->ReservedVectors = ReservedVectors;

ExceptionHandlerData->ExternalInterruptHandler = NULL;

InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);

@@ -148,64 +149,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

-/**

- Registers a function to be called from the processor interrupt handler.

-

- This function registers and enables the handler specified by InterruptHandler
for a processor

- interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

- handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

- The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

-

- @param[in] InterruptType Defines which interrupt or exception to hook.

- @param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

- when a processor interrupt occurs. If this parameter is NULL,
then the handler

- will be uninstalled.

-

- @retval EFI_SUCCESS The handler for the processor interrupt was
successfully installed or uninstalled.

- @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
for InterruptType was

- previously installed.

- @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
InterruptType was not

- previously installed.

- @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not
supported,

- or this function is not supported.

-**/

-EFI_STATUS

-EFIAPI

-RegisterCpuInterruptHandler (

- IN EFI_EXCEPTION_TYPE InterruptType,

- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Initializes all CPU exceptions entries with optional extra initializations.



diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
index f47a80dcab..a7d0897ef1 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.



-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -261,31 +261,26 @@ InitializeCpuExceptionHandlersWorker (
RESERVED_VECTORS_DATA *ReservedVectors;



ReservedVectors = ExceptionHandlerData->ReservedVectors;

- SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
CPU_EXCEPTION_NUM, 0xff);

+ SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
ExceptionHandlerData->IdtEntryCount, 0xff);

if (VectorInfo != NULL) {

- Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
CPU_EXCEPTION_NUM);

+ Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
ExceptionHandlerData->IdtEntryCount);

if (EFI_ERROR (Status)) {

return EFI_INVALID_PARAMETER;

}

}



//

- // Read IDT descriptor and calculate IDT size

+ // Setup the exception handlers according to IDT size, but no more than

+ // ExceptionHandlerData->IdtEntryCount (32 in PEI and SMM, 256 in DXE)
handlers.

//

AsmReadIdtr (&IdtDescriptor);

- IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

- if (IdtEntryCount > CPU_EXCEPTION_NUM) {

- //

- // CPU exception library only setup CPU_EXCEPTION_NUM exception handler
at most

- //

- IdtEntryCount = CPU_EXCEPTION_NUM;

- }

+ IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
(IA32_IDT_GATE_DESCRIPTOR);

+ ExceptionHandlerData->IdtEntryCount = MIN (IdtEntryCount,
ExceptionHandlerData->IdtEntryCount);



IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;

AsmGetTemplateAddressMap (&TemplateMap);

ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);



- ExceptionHandlerData->IdtEntryCount = IdtEntryCount;

UpdateIdtTable (IdtTable, &TemplateMap, ExceptionHandlerData);



return EFI_SUCCESS;

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
index 6e5216380d..e894ead612 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implemenation for SEC/PEIM modules.



-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -166,31 +166,6 @@ InitializeCpuExceptionHandlers (
return EFI_SUCCESS;

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -198,8 +173,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
index 9f0af4120a..ec643556c7 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
@@ -1,7 +1,7 @@
/** @file

CPU exception handler library implementation for SMM modules.



- Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -14,8 +14,8 @@ CONST UINTN mDoFarReturnFlag = 1;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];

EFI_CPU_INTERRUPT_HANDLER
mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];

EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

- 0, // To be fixed

- 0, // To be fixed

+ CPU_EXCEPTION_NUM,

+ 0, // To be fixed

mReservedVectorsData,

mExternalInterruptHandlerTable

};

@@ -62,31 +62,6 @@ InitializeCpuExceptionHandlers (
return InitializeCpuExceptionHandlersWorker (VectorInfo,
&mExceptionHandlerData);

}



-/**

- Initializes all CPU interrupt/exceptions entries and provides the default
interrupt/exception handlers.

-

- Caller should try to get an array of interrupt and/or exception vectors that are
in use and need to

- persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.

- If caller cannot get reserved vector list or it does not exists, set VectorInfo to
NULL.

- If VectorInfo is not NULL, the exception vectors will be initialized per vector
attribute accordingly.

-

- @param[in] VectorInfo Pointer to reserved vector list.

-

- @retval EFI_SUCCESS All CPU interrupt/exception entries have been
successfully initialized

- with default interrupt/exception handlers.

- @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
VectorInfo is not NULL.

- @retval EFI_UNSUPPORTED This function is not supported.

-

-**/

-EFI_STATUS

-EFIAPI

-InitializeCpuInterruptHandlers (

- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL

- )

-{

- return EFI_UNSUPPORTED;

-}

-

/**

Registers a function to be called from the processor interrupt handler.



@@ -94,8 +69,8 @@ InitializeCpuInterruptHandlers (
interrupt or exception type specified by InterruptType. If InterruptHandler is
NULL, then the

handler for the processor interrupt or exception type specified by
InterruptType is uninstalled.

The installed handler is called once for each processor interrupt or exception.

- NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
or

- InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
returned.

+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
is invoked,

+ otherwise EFI_UNSUPPORTED returned.



@param[in] InterruptType Defines which interrupt or exception to hook.

@param[in] InterruptHandler A pointer to a function of type
EFI_CPU_INTERRUPT_HANDLER that is called

--
2.35.1.windows.2



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89919): https://edk2.groups.io/g/devel/message/89919
Mute This Topic: https://groups.io/mt/91231770/1768734
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
-=-=-=-=-=-=


Re: [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

Ni, Ray
 

Jian,
Ia32/ExceptionHandlerAsm.nasm is used by 32bit DxeCpuExceptionHandlerLib instance.

I agree the commit message is not correct. The commit message says
SEC still creates 32 entries but 32bit SEC creates 256 entries.

I will update the commit message to align to code behavior.

Thanks,
Ray

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:40
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

Ray,

You changed "%rep 32" to "%rep 256" in Ia32/ExceptionHandlerAsm.nasm.
According to my understanding and your comments, this should be done
only to X64 code, right?

Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages
for DXE instance

Today the DXE instance allocates code page and then copies the IDT
vectors to the allocated code page. Then it fixes up the vector number
in the IDT vector.

But if we update the NASM file to generate 256 IDT vectors, there is
no need to do the copy and fix-up.

A side effect is up to 4096 bytes (HOOKAFTER_STUB_SIZE * 256) is
used for 256 IDT vectors. While 32 IDT vectors only require 512 bytes.

But considering the code logic simplification, 3.5K space is not a big
deal. SEC instance still generates 32 IDT vectors so no impact to SEC.
If 3.5K is too much a waste in PEI phase, we can enhance the code
further to generate 32 vectors for PEI.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../CpuExceptionHandlerLib/DxeException.c | 22 -------------------
.../Ia32/ExceptionHandlerAsm.nasm | 4 ++--
.../X64/ExceptionHandlerAsm.nasm | 2 ++
.../X64/Xcode5ExceptionHandlerAsm.nasm | 9 ++++----
4 files changed, 9 insertions(+), 28 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index 61f11e98f8..5083c4b8e8 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -95,9 +95,6 @@ InitializeCpuInterruptHandlers (
IA32_DESCRIPTOR IdtDescriptor;

UINTN IdtEntryCount;

EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;

- UINTN Index;

- UINTN InterruptEntry;

- UINT8 *InterruptEntryCode;

RESERVED_VECTORS_DATA *ReservedVectors;

EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;



@@ -138,25 +135,6 @@ InitializeCpuInterruptHandlers (
AsmGetTemplateAddressMap (&TemplateMap);

ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);



- Status = gBS->AllocatePool (

- EfiBootServicesCode,

- TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,

- (VOID **)&InterruptEntryCode

- );

- ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);

-

- InterruptEntry = (UINTN)InterruptEntryCode;

- for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {

- CopyMem (

- (VOID *)InterruptEntry,

- (VOID *)TemplateMap.ExceptionStart,

- TemplateMap.ExceptionStubHeaderSize

- );

- AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID
*)TemplateMap.ExceptionStart);

- InterruptEntry += TemplateMap.ExceptionStubHeaderSize;

- }

-

- TemplateMap.ExceptionStart = (UINTN)InterruptEntryCode;

mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;

mExceptionHandlerData.ReservedVectors = ReservedVectors;

mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
index 3fe9aed1e8..8ed2b8f455 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
m
@@ -33,7 +33,7 @@ ALIGN 8
;

AsmIdtVectorBegin:

%assign Vector 0

-%rep 32

+%rep 256

push byte %[Vector];

push eax

mov eax, ASM_PFX(CommonInterruptEntry)

@@ -439,7 +439,7 @@ ASM_PFX(AsmGetTemplateAddressMap):


mov ebx, dword [ebp + 0x8]

mov dword [ebx], AsmIdtVectorBegin

- mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

mov dword [ebx + 0x8], HookAfterStubBegin



popad

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
index 9a806d1f86..aaf8d622e6 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
@@ -31,6 +31,8 @@ SECTION .text


ALIGN 8



+; Generate 32 IDT vectors.

+; 32 IDT vectors are enough because interrupts (32+) are not enabled in SEC and
PEI phase.

AsmIdtVectorBegin:

%assign Vector 0

%rep 32

diff --git
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
index 9c72fa5815..7c0e3d3b0b 100644
---
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
+++
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
m.nasm
@@ -53,9 +53,10 @@ SECTION .text


ALIGN 8



+; Generate 256 IDT vectors.

AsmIdtVectorBegin:

%assign Vector 0

-%rep 32

+%rep 256

push byte %[Vector]

push rax

mov rax, strict qword 0 ; mov rax, ASM_PFX(CommonInterruptEntry)

@@ -453,16 +454,16 @@ global ASM_PFX(AsmGetTemplateAddressMap)
ASM_PFX(AsmGetTemplateAddressMap):

lea rax, [AsmIdtVectorBegin]

mov qword [rcx], rax

- mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

lea rax, [HookAfterStubHeaderBegin]

mov qword [rcx + 0x10], rax



; Fix up CommonInterruptEntry address

lea rax, [ASM_PFX(CommonInterruptEntry)]

lea rcx, [AsmIdtVectorBegin]

-%rep 32

+%rep 256

mov qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)],
rax

- add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32

+ add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256

%endrep

; Fix up HookAfterStubHeaderEnd

lea rax, [HookAfterStubHeaderEnd]

--
2.35.1.windows.2



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89916): https://edk2.groups.io/g/devel/message/89916
Mute This Topic: https://groups.io/mt/91231767/1768734
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
-=-=-=-=-=-=


Re: [PATCH 1/1] OvmfPkg: fix PcdFSBClock

Gerd Hoffmann
 

On Mon, May 23, 2022 at 03:45:04PM +0200, Gerd Hoffmann wrote:
kvm FSB clock is 1GHz, not 100 MHz. Timings are off by factor 10.
Fix all affected build configurations. Not changed: Microvm and
Cloudhw (they have already have the correct value), and Xen (has
no fixed frequency, the PCD is configured at runtime by platform
initialization code).

Fixes: c37cbc030d96 ("OvmfPkg: Switch timer in build time for OvmfPkg")
Cc'ing gaoliming.

This fixes a regression and should go into 220205

thanks,
Gerd


Re: [PATCH v5 1/6] MdeModulePkg/PciHostBridge: io range is not mandatory

Gerd Hoffmann
 

On Mon, May 23, 2022 at 04:48:05AM -0700, Albecki, Mateusz wrote:
@Ni, Ray

I think EDK2 needs to provide a way for root port to operate without IO space assigned in a platform-independent way. I can think of the following cases when root port didn't get IO space:

1. We have run out of IO space but it's fine since the device under the root port doesn't use IO or has only non-critical functionalities under IO
2. We have run out of IO space and it's really not fine since device needs IO
3. We are running on a CPU which doesn't support IO

For 1. the question is whether the device driver in EDK2 understands that IO bar for that device is optional and will bother to check if it has been assigned and either fail gracefully or continue operation in limited capacity. For 2. the question is whether the driver will fail gracefully. 3 is for completeness at this point I think since the only other architecture that uses EDK2 is ARM which has to deal with it in some way right now which I think maps IO region into MMIO so in a way it supports IO.
Well, the case I'm trying to handle here is qemu microvm. It's x86, but
io address space support for pcie devices is not wired up. So the pcie
host bridge doesn't support io, which is rather close to case (3).

I've checked the device driver behavior in EDK2 for devices which use IO bar here is the rundown:
1. IDE - Doesn't check if IO has been assigned, not giving IO results in undefined behavior
2. SerialIo -> Doesn't check, will assert the system when IO is not assigned (although the logic there is really strange as it can use 3 different access methods)
3. UHCI -> Checks but too late, will most likely result in undefined behavior
Current edk2 behavior is that the initialization of the pcie host bridge
fails in case no io space is present (and all devices connected to it are
not initialized either of course).

With this patch applied pcie host bridge initialization works. PCIe
devices without io bars are enumerated and initialized sucessfully.
PCIe devices with io bar fail to initialize. That isn't much of a
problem tough as a qemu microvm typically has no pcie devices with io
bars.

Even with those bad device drivers I would agree that taking this
change presents low risk given that those devices are pretty old and
should be mostly unused on new systems(SerialIo being an exception but
that one is usually an RCIEP).
Also note that for pcie root bridges which do support io address space
this patch changes nothing.

That said I think we are missing a larger issue here - why are we
running out of IO when we have 16 root ports?
I don't think so. I see the *linux kernel* hand out io address space to
pcie root ports (until it runs out). edk2 doesn't.

take care,
Gerd


Re: [GSoC 2022] Introducing myself & seeking for project ideas

Gerd Hoffmann
 

Hi,

SimicsOpenBoardPkg can partially boot QEMU with a minimum of changes. It
makes it into the DXE phase (where we'd eventually get a shell), but fails
to initialise SMM, so it can't load the variable driver in there. Many
drivers depend on the variable protocol, including critical
UEFI-architecture ones, so the DXE core will assert and hang after printing
a bunch of "driver GUID discovered but not loaded" messages. To fix this,
the SMM access, maybe SMM control drivers would need to be patched; some
register definitions differ between chipsets.
One issue with QEMU is that you currently have 3 machines worth supporting:
the i440fx (i440fx + PIIX), which is the default, the Q35 (Q35 + ICH9), and
the microvm (probably not going to be apart of the scope of this project,
at least for now, even though OVMF supports it).
If you want support for authenticated variables (+ secure boot I guess)
and SMM q35 is pretty much the only option you have. microvm doesn't
support smm at all, and the i440fx is too old and hasn't enough SMM
memory (no TSEG).

take care,
Gerd


Now: Tools, CI, Code base construction meeting series - 05/23/2022 #cal-notice

Group Notification <noreply@...>
 

Tools, CI, Code base construction meeting series

When:
05/23/2022
4:30pm to 5:30pm
(UTC-07:00) America/Los Angeles

Where:
https://github.com/tianocore/edk2/discussions/2614

View Event

Description:

TianoCore community,

Microsoft and Intel will be hosting a series of open meetings to discuss build, CI, tools, and other related topics. If you are interested, have ideas/opinions please join us. These meetings will be Monday 4:30pm Pacific Time on Microsoft Teams.

MS Teams Link in following discussion: * https://github.com/tianocore/edk2/discussions/2614

Anyone is welcome to join.

MS Teams Browser Clients * https://docs.microsoft.com/en-us/microsoftteams/get-clients?tabs=Windows#browser-client

6741 - 6760 of 96644