Date   

Re: [PATCH v1] Intel/TigerlakeOpenBoardPkg: Simplify microcode related PCD usage

Chaganty, Rangasai V
 

Reviewed-by: Sai Chaganty <rangasai.v.chaganty@...>


Re: [EXTERNAL] [PATCH v1 1/1] UnitTestFrameworkPkg: Sample unit test hangs when running in OVMF/QEMU

Bret Barkelew
 

This change should also be made in:

UnitTestFrameworkPkg\Library\UnitTestResultReportLib\UnitTestResultReportLibDebugLib.c

UnitTestFrameworkPkg\Library\UnitTestResultReportLib\UnitTestResultReportLib.c (for the prototype)

 

- Bret

 

From: Getnat Ejigu
Sent: Thursday, April 29, 2021 10:43 AM
To: devel@edk2.groups.io
Cc: Kinney, Michael D; Sean Brogan; Bret Barkelew
Subject: [EXTERNAL] [PATCH v1 1/1] UnitTestFrameworkPkg: Sample unit test hangs when running in OVMF/QEMU

 

Sample unit tests in UnitTestFrameworkPkg hangs when running in OVMF/QEMU
environment. Build target is X64/GCC5. Fixing this issue by adding EFIAPI
to ReportPrint() function that use VA_ARGS.

Signed-off-by: Getnat Ejigu <getnatejigu@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
---
 UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
index cfb0c5972bd1..db5402d6a210 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
@@ -12,6 +12,7 @@
 #include <Library/DebugLib.h>

 

 VOID

+EFIAPI

 ReportPrint (

   IN CONST CHAR8  *Format,

   ...

--
2.25.1

 


[PATCH v1 1/1] UnitTestFrameworkPkg: Sample unit test hangs when running in OVMF/QEMU

Getnat Ejigu
 

Sample unit tests in UnitTestFrameworkPkg hangs when running in OVMF/QEMU
environment. Build target is X64/GCC5. Fixing this issue by adding EFIAPI
to ReportPrint() function that use VA_ARGS.

Signed-off-by: Getnat Ejigu <getnatejigu@gmail.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
---
UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportL=
ibConOut.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestR=
esultReportLibConOut.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportL=
ib/UnitTestResultReportLibConOut.c
index cfb0c5972bd1..db5402d6a210 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultRe=
portLibConOut.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultRe=
portLibConOut.c
@@ -12,6 +12,7 @@
#include <Library/DebugLib.h>=0D
=0D
VOID=0D
+EFIAPI=0D
ReportPrint (=0D
IN CONST CHAR8 *Format,=0D
...=0D
--=20
2.25.1


[PATCH v1 0/1] Sample unit test hangs when running in OVMF/QEMU

Getnat Ejigu
 

*** BLURB HERE ***

Getnat Ejigu (1):
UnitTestFrameworkPkg: Sample unit test hangs when running in OVMF/QEMU

UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c | 1 +
1 file changed, 1 insertion(+)

--
2.25.1


Re: [PATCH 1/2] Silicon/Broadcom/BcmGenetDxe: Delay for linkup in transmit

Andrei Warkentin
 

Looks fine to me

Reviewed-by: Andrei Warkentin <awarkentin@...>


From: Jeremy Linton <jeremy.linton@...>
Sent: Thursday, April 15, 2021 2:22 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: ard.biesheuvel@... <ard.biesheuvel@...>; leif@... <leif@...>; pete@... <pete@...>; samer.el-haj-mahmoud@... <samer.el-haj-mahmoud@...>; Andrei Warkentin <awarkentin@...>; Jeremy Linton <jeremy.linton@...>
Subject: [PATCH 1/2] Silicon/Broadcom/BcmGenetDxe: Delay for linkup in transmit
 
Under normal circumstances GenetSimpleNetworkTransmit won't be
called unless the rest of the network stack detects the link is
up. So, during normal operation when the adapter is initialized
the link naturally transitions to link up, and then is ready for
activity later in the boot sequence. If that hasn't happened by
the time PXE runs then it will itself wait for the link.

OTOH, the normal distro PXE sequence involves PXE loading shim
which in turn loads grub, which tries to read machine specific
configs, modules, and grub.cfg in order to prepare the boot menu.
Then, once a grub selection is picked, it might try to load the
kernel+initrd.

In this sequence the network stack is shutdown and restarted
multiple times. Grub though, starts up, notices its been network
booted, reads saved network parameters and immediately tries to
transmit data assuming the link is still up.

When that happens grub will print "couldn't send network packet"
and if that lasts long enough it fails to load grub.cfg and the
user gets dropped to the grub prompt because no one in the path
bothers to assure the link state has transitioned back up.

For reference: https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpftf%2FRPi4%2Fissues%2F113&amp;data=04%7C01%7Cawarkentin%40vmware.com%7Cadf7e9a53f9b4c6cff9608d90043c562%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637541113365821315%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=Gdg67x%2Fv75%2B5r9bWhz8SvB%2B4VBTgZ6sEZ9SeYor%2B02E%3D&amp;reserved=0

Signed-off-by: Jeremy Linton <jeremy.linton@...>
---
 .../Drivers/Net/BcmGenetDxe/SimpleNetwork.c        | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
index 1bda18f157..29c76d8495 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
@@ -13,6 +13,7 @@
 #include <Library/DebugLib.h>
 #include <Library/DmaLib.h>
 #include <Library/NetLib.h>
+#include <Library/UefiBootServicesTableLib.h>
 #include <Protocol/SimpleNetwork.h>
 
 #include "BcmGenetDxe.h"
@@ -590,9 +591,28 @@ GenetSimpleNetworkTransmit (
 
   if (!Genet->SnpMode.MediaPresent) {
     //
-    // Don't bother transmitting if there's no link.
+    // We should only really get here if the link was up
+    // and is now down due to a stop/shutdown sequence, and
+    // the app (grub) doesn't bother to check link state
+    // because it was up a moment before.
+    // Lets wait a bit for the link to resume, rather than
+    // failing to send. In the case of grub it works either way
+    // but we can't be sure that is universally true, and
+    // hanging for a couple seconds is nicer than a screen of
+    // grub send failure messages.
     //
-    return EFI_NOT_READY;
+    int retries = 1000;
+    DEBUG ((DEBUG_INFO, "%a: Waiting 10s for link\n", __FUNCTION__));
+    do {
+      gBS->Stall (10000);
+      Status = GenericPhyUpdateConfig (&Genet->Phy);
+    } while (EFI_ERROR (Status) && retries--);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: no link\n", __FUNCTION__));
+      return EFI_NOT_READY;
+    } else {
+      Genet->SnpMode.MediaPresent = TRUE;
+    }
   }
 
   if (HeaderSize != 0) {
--
2.13.7


Re: [PATCH 1/2] Silicon/Broadcom/BcmGenetDxe: Delay for linkup in transmit

Jeremy Linton
 

+Jared McNeill for review.

Thanks,

On 4/15/21 2:22 PM, Jeremy Linton wrote:
Under normal circumstances GenetSimpleNetworkTransmit won't be
called unless the rest of the network stack detects the link is
up. So, during normal operation when the adapter is initialized
the link naturally transitions to link up, and then is ready for
activity later in the boot sequence. If that hasn't happened by
the time PXE runs then it will itself wait for the link.
OTOH, the normal distro PXE sequence involves PXE loading shim
which in turn loads grub, which tries to read machine specific
configs, modules, and grub.cfg in order to prepare the boot menu.
Then, once a grub selection is picked, it might try to load the
kernel+initrd.
In this sequence the network stack is shutdown and restarted
multiple times. Grub though, starts up, notices its been network
booted, reads saved network parameters and immediately tries to
transmit data assuming the link is still up.
When that happens grub will print "couldn't send network packet"
and if that lasts long enough it fails to load grub.cfg and the
user gets dropped to the grub prompt because no one in the path
bothers to assure the link state has transitioned back up.
For reference: https://github.com/pftf/RPi4/issues/113
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
.../Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 24 ++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
index 1bda18f157..29c76d8495 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c
@@ -13,6 +13,7 @@
#include <Library/DebugLib.h>
#include <Library/DmaLib.h>
#include <Library/NetLib.h>
+#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/SimpleNetwork.h>
#include "BcmGenetDxe.h"
@@ -590,9 +591,28 @@ GenetSimpleNetworkTransmit (
if (!Genet->SnpMode.MediaPresent) {
//
- // Don't bother transmitting if there's no link.
+ // We should only really get here if the link was up
+ // and is now down due to a stop/shutdown sequence, and
+ // the app (grub) doesn't bother to check link state
+ // because it was up a moment before.
+ // Lets wait a bit for the link to resume, rather than
+ // failing to send. In the case of grub it works either way
+ // but we can't be sure that is universally true, and
+ // hanging for a couple seconds is nicer than a screen of
+ // grub send failure messages.
//
- return EFI_NOT_READY;
+ int retries = 1000;
+ DEBUG ((DEBUG_INFO, "%a: Waiting 10s for link\n", __FUNCTION__));
+ do {
+ gBS->Stall (10000);
+ Status = GenericPhyUpdateConfig (&Genet->Phy);
+ } while (EFI_ERROR (Status) && retries--);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: no link\n", __FUNCTION__));
+ return EFI_NOT_READY;
+ } else {
+ Genet->SnpMode.MediaPresent = TRUE;
+ }
}
if (HeaderSize != 0) {


Cancelled Event: TianoCore Design Meeting - APAC/NAMO - Friday, 30 April 2021 #cal-cancelled

devel@edk2.groups.io Calendar <noreply@...>
 

Cancelled: TianoCore Design Meeting - APAC/NAMO

This event has been cancelled.

When:
Friday, 30 April 2021
9:30am to 10:30am
(UTC+08:00) Asia/Shanghai

Where:
Microsoft Teams

Organizer: Ray Ni ray.ni@...

Description:

TOPIC

  1. NA

For more info, see here: https://www.tianocore.org/design-meeting/


Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Join with a video conferencing device

teams@...

Video Conference ID: 119 715 416 0

Alternate VTC dialing instructions

Learn More | Meeting options


Re: [PATCH v3 3/5] OvmfPkg: Define a new PPI GUID to signal TPM MMIO accessability

Lendacky, Thomas
 

On 4/29/21 12:12 PM, Tom Lendacky wrote:
Define a new PPI GUID that is to be used as a signal of when it is safe
to access the TPM MMIO range. This is needed so that, when SEV is active,
the MMIO range can be mapped unencrypted before it is accessed.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Sorry, Laszlo, I forgot to include your Reviewed-by: on this patch.

Tom

---
OvmfPkg/OvmfPkg.dec | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9629707020ba..6ae733f6e39f 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -128,6 +128,10 @@ [Ppis]
# has been discovered and recorded
gOvmfTpmDiscoveredPpiGuid = {0xb9a61ad0, 0x2802, 0x41f3, {0xb5, 0x13, 0x96, 0x51, 0xce, 0x6b, 0xd5, 0x75}}

+ # This PPI signals that accessing the MMIO range of the TPM is possible in
+ # the PEI phase, regardless of memory encryption
+ gOvmfTpmMmioAccessiblePpiGuid = {0x35c84ff2, 0x7bfe, 0x453d, {0x84, 0x5f, 0x68, 0x3a, 0x49, 0x2c, 0xf7, 0xb7}}
+
[Protocols]
gVirtioDeviceProtocolGuid = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
gXenBusProtocolGuid = {0x3d3ca290, 0xb9a5, 0x11e3, {0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}}


Re: [PATCH v3 2/5] OvmfPkg/VmgExitLib: Add support for new MMIO MOV opcodes

Lendacky, Thomas
 

On 4/29/21 12:12 PM, Tom Lendacky wrote:
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

Enabling TPM support results in guest termination of an SEV-ES guest
because it uses MMIO opcodes that are not currently supported.

Add support for the new MMIO opcodes (0xA0 - 0xA3), MOV instructions which
use a memory offset directly encoded in the instruction. Also, add a DEBUG
statement to identify an unsupported MMIO opcode being used.

Fixes: c45f678a1ea2080344e125dc55b14e4b9f98483d
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Sorry, Laszlo, I forgot to include your Acked-by: on this patch.

Tom

---
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 111 ++++++++++++++++++++
1 file changed, 111 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index b716541ad170..41b0c8cc5312 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -680,6 +680,7 @@ MmioExit (
UINTN Bytes;
UINT64 *Register;
UINT8 OpCode, SignByte;
+ UINTN Address;

Bytes = 0;

@@ -729,6 +730,57 @@ MmioExit (
}
break;

+ //
+ // MMIO write (MOV moffsetX, aX)
+ //
+ case 0xA2:
+ Bytes = 1;
+ //
+ // fall through
+ //
+ case 0xA3:
+ Bytes = ((Bytes != 0) ? Bytes :
+ (InstructionData->DataSize == Size16Bits) ? 2 :
+ (InstructionData->DataSize == Size32Bits) ? 4 :
+ (InstructionData->DataSize == Size64Bits) ? 8 :
+ 0);
+
+ InstructionData->ImmediateSize = (UINTN) (1 << InstructionData->AddrSize);
+ InstructionData->End += InstructionData->ImmediateSize;
+
+ //
+ // This code is X64 only, so a possible 8-byte copy to a UINTN is ok.
+ // Use a STATIC_ASSERT to be certain the code is being built as X64.
+ //
+ STATIC_ASSERT (
+ sizeof (UINTN) == sizeof (UINT64),
+ "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
+ );
+
+ Address = 0;
+ CopyMem (
+ &Address,
+ InstructionData->Immediate,
+ InstructionData->ImmediateSize
+ );
+
+ Status = ValidateMmioMemory (Ghcb, Address, Bytes);
+ if (Status != 0) {
+ return Status;
+ }
+
+ ExitInfo1 = Address;
+ ExitInfo2 = Bytes;
+ CopyMem (Ghcb->SharedBuffer, &Regs->Rax, Bytes);
+
+ Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer;
+ VmgSetOffsetValid (Ghcb, GhcbSwScratch);
+ Status = VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);
+ if (Status != 0) {
+ return Status;
+ }
+ break;
+
//
// MMIO write (MOV reg/memX, immX)
//
@@ -811,6 +863,64 @@ MmioExit (
CopyMem (Register, Ghcb->SharedBuffer, Bytes);
break;

+ //
+ // MMIO read (MOV aX, moffsetX)
+ //
+ case 0xA0:
+ Bytes = 1;
+ //
+ // fall through
+ //
+ case 0xA1:
+ Bytes = ((Bytes != 0) ? Bytes :
+ (InstructionData->DataSize == Size16Bits) ? 2 :
+ (InstructionData->DataSize == Size32Bits) ? 4 :
+ (InstructionData->DataSize == Size64Bits) ? 8 :
+ 0);
+
+ InstructionData->ImmediateSize = (UINTN) (1 << InstructionData->AddrSize);
+ InstructionData->End += InstructionData->ImmediateSize;
+
+ //
+ // This code is X64 only, so a possible 8-byte copy to a UINTN is ok.
+ // Use a STATIC_ASSERT to be certain the code is being built as X64.
+ //
+ STATIC_ASSERT (
+ sizeof (UINTN) == sizeof (UINT64),
+ "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
+ );
+
+ Address = 0;
+ CopyMem (
+ &Address,
+ InstructionData->Immediate,
+ InstructionData->ImmediateSize
+ );
+
+ Status = ValidateMmioMemory (Ghcb, Address, Bytes);
+ if (Status != 0) {
+ return Status;
+ }
+
+ ExitInfo1 = Address;
+ ExitInfo2 = Bytes;
+
+ Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer;
+ VmgSetOffsetValid (Ghcb, GhcbSwScratch);
+ Status = VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
+ if (Status != 0) {
+ return Status;
+ }
+
+ if (Bytes == 4) {
+ //
+ // Zero-extend for 32-bit operation
+ //
+ Regs->Rax = 0;
+ }
+ CopyMem (&Regs->Rax, Ghcb->SharedBuffer, Bytes);
+ break;
+
//
// MMIO read w/ zero-extension ((MOVZX regX, reg/memX)
//
@@ -888,6 +998,7 @@ MmioExit (
break;

default:
+ DEBUG ((DEBUG_ERROR, "Invalid MMIO opcode (%x)\n", OpCode));
Status = GP_EXCEPTION;
ASSERT (FALSE);
}


[PATCH v3 5/5] OvmfPkg/Tcg2ConfigPei: Update Depex for IA32 and X64

Lendacky, Thomas
 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

The OVMF Tcg2Config PEIM adds the gOvmfTpmMmioAccessiblePpiGuid as a
Depex for IA32 and X64 builds so that the MMIO range is properly mapped
as unencrypted for an SEV-ES guest before the Tcg2Config PEIM is loaded.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
index 6776ec931ce0..39d1deeed16b 100644
--- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
+++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
@@ -57,7 +57,7 @@ [Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## PRODUCES

[Depex.IA32, Depex.X64]
- TRUE
+ gOvmfTpmMmioAccessiblePpiGuid

[Depex.ARM, Depex.AARCH64]
gOvmfTpmDiscoveredPpiGuid
--
2.31.0


[PATCH v3 4/5] OvmfPkg/Tcg2ConfigPei: Mark TPM MMIO range as unencrypted for SEV-ES

Lendacky, Thomas
 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

During PEI, the MMIO range for the TPM is marked as encrypted when running
as an SEV guest. While this isn't an issue for an SEV guest because of
the way the nested page fault is handled, it does result in an SEV-ES
guest terminating because of a mitigation check in the #VC handler to
prevent MMIO to an encrypted address. For an SEV-ES guest, this range
must be marked as unencrypted.

Create a new x86 PEIM for TPM support that will map the TPM MMIO range as
unencrypted when SEV-ES is active. The gOvmfTpmMmioAccessiblePpiGuid PPI
will be unconditionally installed before exiting. The PEIM will exit with
the EFI_ABORTED status so that the PEIM does not stay resident. This new
PEIM will depend on the installation of the permanent PEI RAM, by
PlatformPei, so that in case page table splitting is required during the
clearing of the encryption bit, the new page table(s) will be allocated
from permanent PEI RAM.

Update all OVMF Ia32 and X64 build packages to include this new PEIM.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/AmdSev/AmdSevX64.fdf | 1 +
OvmfPkg/OvmfPkgIa32.fdf | 1 +
OvmfPkg/OvmfPkgIa32X64.fdf | 1 +
OvmfPkg/OvmfPkgX64.fdf | 1 +
OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf | 40 +++++++++
OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c | 87 ++++++++++++++++++++
10 files changed, 135 insertions(+)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index cdb29d53142d..66bbbc80cd18 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -626,6 +626,7 @@ [Components]
OvmfPkg/AmdSev/SecretPei/SecretPei.inf

!if $(TPM_ENABLE) == TRUE
+ OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
SecurityPkg/Tcg/TcgPei/TcgPei.inf
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 1730b6558b5c..33fbd767903e 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -706,6 +706,7 @@ [Components]
UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+ OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
SecurityPkg/Tcg/TcgPei/TcgPei.inf
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 78a559da0d0b..b13e5cfd9047 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -719,6 +719,7 @@ [Components.IA32]
UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+ OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
SecurityPkg/Tcg/TcgPei/TcgPei.inf
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index a7d747f6b4ab..999738dc39cd 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -718,6 +718,7 @@ [Components]
UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+ OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
SecurityPkg/Tcg/TcgPei/TcgPei.inf
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf
index c0098502aa90..dd0030dbf189 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.fdf
+++ b/OvmfPkg/AmdSev/AmdSevX64.fdf
@@ -147,6 +147,7 @@ [FV.PEIFV]
INF OvmfPkg/AmdSev/SecretPei/SecretPei.inf

!if $(TPM_ENABLE) == TRUE
+INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
INF SecurityPkg/Tcg/TcgPei/TcgPei.inf
INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index f400c845b9c9..b3c8b56f3b60 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -162,6 +162,7 @@ [FV.PEIFV]
INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
INF SecurityPkg/Tcg/TcgPei/TcgPei.inf
INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index d055552fd09f..86592c2364a3 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -162,6 +162,7 @@ [FV.PEIFV]
INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
INF SecurityPkg/Tcg/TcgPei/TcgPei.inf
INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index d519f8532822..d6be798fcadd 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -174,6 +174,7 @@ [FV.PEIFV]
INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf

!if $(TPM_ENABLE) == TRUE
+INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
INF SecurityPkg/Tcg/TcgPei/TcgPei.inf
INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
diff --git a/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
new file mode 100644
index 000000000000..51ad6d0d055d
--- /dev/null
+++ b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
@@ -0,0 +1,40 @@
+## @file
+# Map TPM MMIO range unencrypted when SEV-ES is active.
+# Install gOvmfTpmMmioAccessiblePpiGuid unconditionally.
+#
+# Copyright (C) 2021, Advanced Micro Devices, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = TpmMmioSevDecryptPei
+ FILE_GUID = F12F698A-E506-4A1B-B32E-6920E55DA1C4
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ ENTRY_POINT = TpmMmioSevDecryptPeimEntryPoint
+
+[Sources]
+ TpmMmioSevDecryptPeim.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ MemEncryptSevLib
+ PcdLib
+ PeimEntryPoint
+ PeiServicesLib
+
+[Ppis]
+ gOvmfTpmMmioAccessiblePpiGuid ## PRODUCES
+
+[FixedPcd]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
+
+[Depex]
+ gEfiPeiMemoryDiscoveredPpiGuid
diff --git a/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c
new file mode 100644
index 000000000000..df2ad623308d
--- /dev/null
+++ b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c
@@ -0,0 +1,87 @@
+/** @file
+ Map TPM MMIO range unencrypted when SEV-ES is active.
+ Install gOvmfTpmMmioAccessiblePpiGuid unconditionally.
+
+ Copyright (C) 2021, Advanced Micro Devices, Inc.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+
+#include <PiPei.h>
+
+#include <Library/DebugLib.h>
+#include <Library/MemEncryptSevLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PeiServicesLib.h>
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmMmioRangeAccessible = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gOvmfTpmMmioAccessiblePpiGuid,
+ NULL
+};
+
+/**
+ The entry point for TPM MMIO range mapping driver.
+
+ @param[in] FileHandle Handle of the file being invoked.
+ @param[in] PeiServices Describes the list of possible PEI Services.
+
+ @retval EFI_ABORTED No need to keep this PEIM resident
+**/
+EFI_STATUS
+EFIAPI
+TpmMmioSevDecryptPeimEntryPoint (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ RETURN_STATUS DecryptStatus;
+ EFI_STATUS Status;
+
+ DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));
+
+ //
+ // If SEV is active, MMIO succeeds against an encrypted physical address
+ // because the nested page fault (NPF) that occurs on access does not
+ // include the encryption bit in the guest physical address provided to the
+ // hypervisor.
+ //
+ // If SEV-ES is active, MMIO would succeed against an encrypted physical
+ // address because the #VC handler uses the virtual address (which is an
+ // identity mapped physical address without the encryption bit) as the guest
+ // physical address of the MMIO target in the VMGEXIT.
+ //
+ // However, if SEV-ES is active, before performing the actual MMIO, an
+ // additional MMIO mitigation check is performed in the #VC handler to ensure
+ // that MMIO is being done to/from an unencrypted address. To prevent guest
+ // termination in this scenario, mark the range unencrypted ahead of access.
+ //
+ if (MemEncryptSevEsIsEnabled ()) {
+ DEBUG ((DEBUG_INFO,
+ "%a: mapping TPM MMIO address range unencrypted\n",
+ __FUNCTION__));
+
+ DecryptStatus = MemEncryptSevClearPageEncMask (
+ 0,
+ FixedPcdGet64 (PcdTpmBaseAddress),
+ EFI_SIZE_TO_PAGES ((UINTN) 0x5000),
+ FALSE
+ );
+
+ if (RETURN_ERROR (DecryptStatus)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: failed to map TPM MMIO address range unencrypted\n",
+ __FUNCTION__));
+ ASSERT_RETURN_ERROR (DecryptStatus);
+ }
+ }
+
+ //
+ // MMIO range available
+ //
+ Status = PeiServicesInstallPpi (&mTpmMmioRangeAccessible);
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_ABORTED;
+}
--
2.31.0


[PATCH v3 3/5] OvmfPkg: Define a new PPI GUID to signal TPM MMIO accessability

Lendacky, Thomas
 

Define a new PPI GUID that is to be used as a signal of when it is safe
to access the TPM MMIO range. This is needed so that, when SEV is active,
the MMIO range can be mapped unencrypted before it is accessed.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/OvmfPkg.dec | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9629707020ba..6ae733f6e39f 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -128,6 +128,10 @@ [Ppis]
# has been discovered and recorded
gOvmfTpmDiscoveredPpiGuid = {0xb9a61ad0, 0x2802, 0x41f3, {0xb5, 0x13, 0x96, 0x51, 0xce, 0x6b, 0xd5, 0x75}}

+ # This PPI signals that accessing the MMIO range of the TPM is possible in
+ # the PEI phase, regardless of memory encryption
+ gOvmfTpmMmioAccessiblePpiGuid = {0x35c84ff2, 0x7bfe, 0x453d, {0x84, 0x5f, 0x68, 0x3a, 0x49, 0x2c, 0xf7, 0xb7}}
+
[Protocols]
gVirtioDeviceProtocolGuid = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
gXenBusProtocolGuid = {0x3d3ca290, 0xb9a5, 0x11e3, {0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}}
--
2.31.0


[PATCH v3 2/5] OvmfPkg/VmgExitLib: Add support for new MMIO MOV opcodes

Lendacky, Thomas
 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

Enabling TPM support results in guest termination of an SEV-ES guest
because it uses MMIO opcodes that are not currently supported.

Add support for the new MMIO opcodes (0xA0 - 0xA3), MOV instructions which
use a memory offset directly encoded in the instruction. Also, add a DEBUG
statement to identify an unsupported MMIO opcode being used.

Fixes: c45f678a1ea2080344e125dc55b14e4b9f98483d
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 111 ++++++++++++++++++++
1 file changed, 111 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index b716541ad170..41b0c8cc5312 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -680,6 +680,7 @@ MmioExit (
UINTN Bytes;
UINT64 *Register;
UINT8 OpCode, SignByte;
+ UINTN Address;

Bytes = 0;

@@ -729,6 +730,57 @@ MmioExit (
}
break;

+ //
+ // MMIO write (MOV moffsetX, aX)
+ //
+ case 0xA2:
+ Bytes = 1;
+ //
+ // fall through
+ //
+ case 0xA3:
+ Bytes = ((Bytes != 0) ? Bytes :
+ (InstructionData->DataSize == Size16Bits) ? 2 :
+ (InstructionData->DataSize == Size32Bits) ? 4 :
+ (InstructionData->DataSize == Size64Bits) ? 8 :
+ 0);
+
+ InstructionData->ImmediateSize = (UINTN) (1 << InstructionData->AddrSize);
+ InstructionData->End += InstructionData->ImmediateSize;
+
+ //
+ // This code is X64 only, so a possible 8-byte copy to a UINTN is ok.
+ // Use a STATIC_ASSERT to be certain the code is being built as X64.
+ //
+ STATIC_ASSERT (
+ sizeof (UINTN) == sizeof (UINT64),
+ "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
+ );
+
+ Address = 0;
+ CopyMem (
+ &Address,
+ InstructionData->Immediate,
+ InstructionData->ImmediateSize
+ );
+
+ Status = ValidateMmioMemory (Ghcb, Address, Bytes);
+ if (Status != 0) {
+ return Status;
+ }
+
+ ExitInfo1 = Address;
+ ExitInfo2 = Bytes;
+ CopyMem (Ghcb->SharedBuffer, &Regs->Rax, Bytes);
+
+ Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer;
+ VmgSetOffsetValid (Ghcb, GhcbSwScratch);
+ Status = VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);
+ if (Status != 0) {
+ return Status;
+ }
+ break;
+
//
// MMIO write (MOV reg/memX, immX)
//
@@ -811,6 +863,64 @@ MmioExit (
CopyMem (Register, Ghcb->SharedBuffer, Bytes);
break;

+ //
+ // MMIO read (MOV aX, moffsetX)
+ //
+ case 0xA0:
+ Bytes = 1;
+ //
+ // fall through
+ //
+ case 0xA1:
+ Bytes = ((Bytes != 0) ? Bytes :
+ (InstructionData->DataSize == Size16Bits) ? 2 :
+ (InstructionData->DataSize == Size32Bits) ? 4 :
+ (InstructionData->DataSize == Size64Bits) ? 8 :
+ 0);
+
+ InstructionData->ImmediateSize = (UINTN) (1 << InstructionData->AddrSize);
+ InstructionData->End += InstructionData->ImmediateSize;
+
+ //
+ // This code is X64 only, so a possible 8-byte copy to a UINTN is ok.
+ // Use a STATIC_ASSERT to be certain the code is being built as X64.
+ //
+ STATIC_ASSERT (
+ sizeof (UINTN) == sizeof (UINT64),
+ "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
+ );
+
+ Address = 0;
+ CopyMem (
+ &Address,
+ InstructionData->Immediate,
+ InstructionData->ImmediateSize
+ );
+
+ Status = ValidateMmioMemory (Ghcb, Address, Bytes);
+ if (Status != 0) {
+ return Status;
+ }
+
+ ExitInfo1 = Address;
+ ExitInfo2 = Bytes;
+
+ Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer;
+ VmgSetOffsetValid (Ghcb, GhcbSwScratch);
+ Status = VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
+ if (Status != 0) {
+ return Status;
+ }
+
+ if (Bytes == 4) {
+ //
+ // Zero-extend for 32-bit operation
+ //
+ Regs->Rax = 0;
+ }
+ CopyMem (&Regs->Rax, Ghcb->SharedBuffer, Bytes);
+ break;
+
//
// MMIO read w/ zero-extension ((MOVZX regX, reg/memX)
//
@@ -888,6 +998,7 @@ MmioExit (
break;

default:
+ DEBUG ((DEBUG_ERROR, "Invalid MMIO opcode (%x)\n", OpCode));
Status = GP_EXCEPTION;
ASSERT (FALSE);
}
--
2.31.0


[PATCH v3 1/5] OvfmPkg/VmgExitLib: Properly decode MMIO MOVZX and MOVSX opcodes

Lendacky, Thomas
 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

The MOVZX and MOVSX instructions use the ModRM byte in the instruction,
but the instruction decoding support was not decoding it. This resulted
in invalid decoding and failing of the MMIO operation. Also, when
performing the zero-extend or sign-extend operation, the memory operation
should be using the size, and not the size enumeration value.

Add the ModRM byte decoding for the MOVZX and MOVSX opcodes and use the
true data size to perform the extend operations. Additionally, add a
DEBUG statement identifying the MMIO address being flagged as encrypted
during the MMIO address validation.

Fixes: c45f678a1ea2080344e125dc55b14e4b9f98483d
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 24259060fd65..b716541ad170 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -643,6 +643,9 @@ ValidateMmioMemory (
//
// Any state other than unencrypted is an error, issue a #GP.
//
+ DEBUG ((DEBUG_ERROR,
+ "MMIO using encrypted memory: %lx\n",
+ (UINT64) MemoryAddress));
GpEvent.Uint64 = 0;
GpEvent.Elements.Vector = GP_EXCEPTION;
GpEvent.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
@@ -817,6 +820,7 @@ MmioExit (
// fall through
//
case 0xB7:
+ DecodeModRm (Regs, InstructionData);
Bytes = (Bytes != 0) ? Bytes : 2;

Status = ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Bytes);
@@ -835,7 +839,7 @@ MmioExit (
}

Register = GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg);
- SetMem (Register, InstructionData->DataSize, 0);
+ SetMem (Register, (UINTN) (1 << InstructionData->DataSize), 0);
CopyMem (Register, Ghcb->SharedBuffer, Bytes);
break;

@@ -848,6 +852,7 @@ MmioExit (
// fall through
//
case 0xBF:
+ DecodeModRm (Regs, InstructionData);
Bytes = (Bytes != 0) ? Bytes : 2;

Status = ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Bytes);
@@ -878,7 +883,7 @@ MmioExit (
}

Register = GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg);
- SetMem (Register, InstructionData->DataSize, SignByte);
+ SetMem (Register, (UINTN) (1 << InstructionData->DataSize), SignByte);
CopyMem (Register, Ghcb->SharedBuffer, Bytes);
break;

--
2.31.0


[PATCH v3 0/5] SEV-ES TPM enablement fixes

Lendacky, Thomas
 

This patch series provides fixes for using TPM support with an SEV-ES
guest.

The fixes include:

- Decode ModRM byte for MOVZX and MOVSX opcodes.
- Add MMIO support for MOV opcodes 0xA0-0xA3.
- Create a new TPM MMIO ready PPI guid, gOvmfTpmMmioAccessiblePpiGuid
- Mark TPM MMIO range as un-encrypted during PEI phase for an SEV-ES
guest and install the TPM MMIO ready PPI guid.
- Update the Tcg2Config Depex to ensure the new PEIM runs before the
Tcg2Config PEIM

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

---

These patches are based on commit:
ab957f036f67 ("BaseTools/Source/Python: New Target/ToolChain/Arch in DSC [BuildOptions]")

Changes since:

v2:
- Update the TPM PEIM to only perform the mapping change when SEV-ES is
active (with a comment in the code to explain why).
- Update the TPM PEIM file header comment.
- Updates to the INF file (INF_VERSION, Packages, LibraryClasses, etc.).
- Updates to PEIM file order in DSC and FDF files.
- Split out Tcg2Config Depex change to a separate patch.

v1:
- Create a TPM PEIM that will map the TPM address range as unencrypted and
install a new PPI to indicate the mapping change is complete.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>

Tom Lendacky (5):
OvfmPkg/VmgExitLib: Properly decode MMIO MOVZX and MOVSX opcodes
OvmfPkg/VmgExitLib: Add support for new MMIO MOV opcodes
OvmfPkg: Define a new PPI GUID to signal TPM MMIO accessability
OvmfPkg/Tcg2ConfigPei: Mark TPM MMIO range as unencrypted for SEV-ES
OvmfPkg/Tcg2ConfigPei: Update Depex for IA32 and X64

OvmfPkg/OvmfPkg.dec | 4 +
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/AmdSev/AmdSevX64.fdf | 1 +
OvmfPkg/OvmfPkgIa32.fdf | 1 +
OvmfPkg/OvmfPkgIa32X64.fdf | 1 +
OvmfPkg/OvmfPkgX64.fdf | 1 +
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 2 +-
OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf | 40 +++++++
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 120 +++++++++++++++++++-
OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c | 87 ++++++++++++++
13 files changed, 258 insertions(+), 3 deletions(-)
create mode 100644 OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf
create mode 100644 OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c

--
2.31.0


Re: Problem: TPM 2.0 event log by OVMF is shown empty in Linux kernel versions after 5.8

Thore Sommer <public@...>
 

I think I found my problem.
The latest kernel from master probes if the table actually includes some values. This was introduced in 3dcd15665aca80197333500a4be3900948afccc1
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3dcd15665aca80197333500a4be3900948afccc1

This commit is not in the 5.12 release, but is in the latest master branch.

Thank you for helping me troubleshoot this problem.
I've learned a lot over the last few days.

Thore


Re: Problem: TPM 2.0 event log by OVMF is shown empty in Linux kernel versions after 5.8

Thore Sommer <public@...>
 

This is somewhat tricky to get right in grub, so you
can rule this out by booting ovmf to a shell and then executing vmlinuz
directly from the shell.
I've now tried this and unfortunately it produces the same result.
The ACPI "TPM2" table is there and the tpm eventlog is empty.

Thore


Re: 回复: [PATCH 3/3] SecurityPkg: Add support for RngDxe on AARCH64

Rebecca Cran
 

On 4/28/21 7:13 PM, gaoliming wrote:
Rebecca:

-----邮件原件-----
发件人: Rebecca Cran <rebecca@nuviainc.com>
发送时间: 2021年4月29日 4:44
收件人: devel@edk2.groups.io
抄送: Rebecca Cran <rebecca@nuviainc.com>; Jiewen Yao
<jiewen.yao@intel.com>; Jian J Wang <jian.j.wang@intel.com>; Michael D
Kinney <michael.d.kinney@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>; Ard
Biesheuvel <ardb+tianocore@kernel.org>; Sami Mujawar
<Sami.Mujawar@arm.com>
主题: [PATCH 3/3] SecurityPkg: Add support for RngDxe on AARCH64

AARCH64 support has been added to BaseRngLib via the optional
ARMv8.5 FEAT_RNG.

Refactor RngDxe to support AARCH64, note support for it in the
VALID_ARCHITECTURES line of RngDxe.inf and enable it in SecurityPkg.dsc.

Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
---
SecurityPkg/SecurityPkg.dsc |
11 +-
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf |
19 +++-
SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.h |
37 ++++++
SecurityPkg/RandomNumberGenerator/RngDxe/{ => Rand}/AesCore.h |
0
SecurityPkg/RandomNumberGenerator/RngDxe/{ => Rand}/RdRand.h |
0
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h |
88 ++++++++++++++
SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.c |
54 +++++++++
SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c |
108 ++++++++++++++++++
SecurityPkg/RandomNumberGenerator/RngDxe/{ => Rand}/AesCore.c |
0
SecurityPkg/RandomNumberGenerator/RngDxe/{ => Rand}/RdRand.c |
0
SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c |
120 ++++++++++++++++++++
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c |
117 ++++---------------
12 files changed, 450 insertions(+), 104 deletions(-)

diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 12ccd1634941..bd4b810bce61 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -259,6 +259,12 @@ [Components]
[Components.IA32, Components.X64, Components.ARM,
Components.AARCH64]
SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf

+[Components.IA32, Components.X64, Components.AARCH64]
+ #
+ # Random Number Generator
+ #
+ SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+
[Components.IA32, Components.X64]

SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigD
xe.inf

@@ -334,11 +340,6 @@ [Components.IA32, Components.X64]

SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresence
Lib.inf

SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Physic
alPresenceLib.inf

- #
- # Random Number Generator
- #
- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
-
#
# Opal Password solution
#
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
index 99d6f6b35fc2..c188b6076c00 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
@@ -26,15 +26,24 @@ [Defines]
#
# The following information is for reference only and not required by the
build tools.
#
-# VALID_ARCHITECTURES = IA32 X64
+# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources.common]
RngDxe.c
- RdRand.c
- RdRand.h
- AesCore.c
- AesCore.h
+ RngDxeInternals.h
+
+[Sources.IA32, Sources.X64]
+ Rand/RngDxe.c
+ Rand/RdRand.c
+ Rand/RdRand.h
+ Rand/AesCore.c
+ Rand/AesCore.h
+
+[Sources.AARCH64]
+ AArch64/RngDxe.c
+ AArch64/Rndr.c
+ AArch64/Rndr.h

[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.h
b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.h
new file mode 100644
index 000000000000..458faa834a3d
--- /dev/null
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.h
@@ -0,0 +1,37 @@
+/** @file
+ Header for the RNDR APIs used by RNG DXE driver.
+
+ Support API definitions for RNDR instruction access.
+
+
+ Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RNDR_H_
+#define RNDR_H_
+
+#include <Library/BaseLib.h>
+#include <Protocol/Rng.h>
+
+/**
+ Calls RNDR to fill a buffer of arbitrary size with random bytes.
+
+ @param[in] Length Size of the buffer, in bytes, to fill with.
+ @param[out] RandBuffer Pointer to the buffer to store the random
result.
+
+ @retval EFI_SUCCESS Random bytes generation succeeded.
+ @retval EFI_NOT_READY Failed to request random bytes.
+
+**/
+EFI_STATUS
+EFIAPI
+RndrGetBytes (
+ IN UINTN Length,
+ OUT UINT8 *RandBuffer
+ );
+
+#endif // RNDR_H_
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h
b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h
similarity index 100%
rename from SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h
rename to SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h
b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h
similarity index 100%
rename from SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h
rename to SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
new file mode 100644
index 000000000000..7e38fc2564f6
--- /dev/null
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
@@ -0,0 +1,88 @@
+/** @file
+ Function prototypes for UEFI Random Number Generator protocol
support.
+
+ Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RNGDXE_INTERNALS_H_
+#define RNGDXE_INTERNALS_H_
+
+extern EFI_RNG_ALGORITHM *mSUpportedRngAlgorithms;
+
+/**
+ Returns information about the random number generation
implementation.
+
+ @param[in] This A pointer to the
EFI_RNG_PROTOCOL instance.
+ @param[in,out] RNGAlgorithmListSize On input, the size in bytes of
RNGAlgorithmList.
+ On output with a return code
of EFI_SUCCESS, the size
+ in bytes of the data returned
in RNGAlgorithmList. On output
+ with a return code of
EFI_BUFFER_TOO_SMALL,
+ the size of RNGAlgorithmList
required to obtain the list.
+ @param[out] RNGAlgorithmList A caller-allocated memory
buffer filled by the driver
+ with one
EFI_RNG_ALGORITHM element for each supported
+ RNG algorithm. The list must
not change across multiple
+ calls to the same driver. The
first algorithm in the list
+ is the default algorithm for
the driver.
+
+ @retval EFI_SUCCESS The RNG algorithm list was
returned successfully.
+ @retval EFI_UNSUPPORTED The services is not supported
by this driver.
+ @retval EFI_DEVICE_ERROR The list of algorithms could
not be retrieved due to a
+ hardware or firmware error.
+ @retval EFI_INVALID_PARAMETER One or more of the
parameters are incorrect.
+ @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList
is too small to hold the result.
+
+**/
+EFI_STATUS
+EFIAPI
+RngGetInfo (
+ IN EFI_RNG_PROTOCOL *This,
+ IN OUT UINTN *RNGAlgorithmListSize,
+ OUT EFI_RNG_ALGORITHM *RNGAlgorithmList
+ );
+
+/**
+ Produces and returns an RNG value using either the default or specified
RNG algorithm.
+
+ @param[in] This A pointer to the
EFI_RNG_PROTOCOL instance.
+ @param[in] RNGAlgorithm A pointer to the
EFI_RNG_ALGORITHM that identifies the RNG
+ algorithm to use. May be
NULL in which case the function will
+ use its default RNG
algorithm.
+ @param[in] RNGValueLength The length in bytes of the
memory buffer pointed to by
+ RNGValue. The driver shall
return exactly this numbers of bytes.
+ @param[out] RNGValue A caller-allocated memory
buffer filled by the driver with the
+ resulting RNG value.
+
+ @retval EFI_SUCCESS The RNG value was returned
successfully.
+ @retval EFI_UNSUPPORTED The algorithm specified by
RNGAlgorithm is not supported by
+ this driver.
+ @retval EFI_DEVICE_ERROR An RNG value could not be
retrieved due to a hardware or
+ firmware error.
+ @retval EFI_NOT_READY There is not enough random
data available to satisfy the length
+ requested by
RNGValueLength.
+ @retval EFI_INVALID_PARAMETER RNGValue is NULL or
RNGValueLength is zero.
+
+**/
+EFI_STATUS
+EFIAPI
+RngGetRNG (
+ IN EFI_RNG_PROTOCOL *This,
+ IN EFI_RNG_ALGORITHM *RNGAlgorithm, OPTIONAL
+ IN UINTN RNGValueLength,
+ OUT UINT8 *RNGValue
+ );
+
+/**
+ Returns the size of the RNG algorithms structure.
+
+ @return Size of the EFI_RNG_ALGORITHM list.
+**/
+UINTN
+EFIAPI
+ArchGetSupportedRngAlgorithmsSize (
+ VOID
+ );
+
+#endif // RNGDXE_INTERNALS_H_
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.c
b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.c
new file mode 100644
index 000000000000..36166a9cbc13
--- /dev/null
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/Rndr.c
@@ -0,0 +1,54 @@
+/** @file
+ Support routines for RNDR instruction access.
+
+ Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+ Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/RngLib.h>
+
+#include "Rndr.h"
+
+/**
+ Calls RNDR to fill a buffer of arbitrary size with random bytes.
+
+ @param[in] Length Size of the buffer, in bytes, to fill with.
+ @param[out] RandBuffer Pointer to the buffer to store the random
result.
+
+ @retval EFI_SUCCESS Random bytes generation succeeded.
+ @retval EFI_NOT_READY Failed to request random bytes.
+
+**/
+EFI_STATUS
+EFIAPI
+RndrGetBytes (
+ IN UINTN Length,
+ OUT UINT8 *RandBuffer
+ )
+{
+ BOOLEAN IsRandom;
+ UINT64 TempRand;
+
+ while (Length > 0) {
+ IsRandom = GetRandomNumber64 (&TempRand);
+ if (!IsRandom) {
+ return EFI_NOT_READY;
+ }
+ if (Length >= sizeof (TempRand)) {
+ WriteUnaligned64 ((UINT64*)RandBuffer, TempRand);
+ RandBuffer += sizeof (UINT64);
+ Length -= sizeof (TempRand);
+ } else {
+ CopyMem (RandBuffer, &TempRand, Length);
+ Length = 0;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
Can this function be shared between X86 and AARCH64?
Yes. I've removed it, and will send out a v2 series.

--
Rebecca Cran


Re: [edk2][PATCH 1/1] MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform recovery

Samer El-Haj-Mahmoud
 

All,

Please take a moment to add any comments to this UEFI ECR BZ. This is needed to UEFI Forum can make a decision and close the ECR.
https://bugzilla.tianocore.org/show_bug.cgi?id=3336


Thanks,
--Samer

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Samer
El-Haj-Mahmoud via groups.io
Sent: Tuesday, April 13, 2021 3:48 PM
To: devel@edk2.groups.io; pete@akeo.ie; Laszlo Ersek
<lersek@redhat.com>; Leif Lindholm <leif@nuviainc.com>; Ni, Ray
<ray.ni@intel.com>; zhichao.gao@intel.com
Cc: Andrei Warkentin (awarkentin@vmware.com)
<awarkentin@vmware.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>;
Andrew Fish <afish@apple.com>; Michael D Kinney
<michael.d.kinney@intel.com>; Jian J Wang <jian.j.wang@intel.com>; Hao A
Wu <hao.a.wu@intel.com>; Sunny.Hsuanwen.Wang@gmail.com; Samer El-
Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Sunny Wang
<Sunny.Wang@arm.com>
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform
recovery

In order to make progress on this, I opened a code-first ECR against the UEFI
spec to clarify the language around the Boot#### options processing.

Code First ECR: https://bugzilla.tianocore.org/show_bug.cgi?id=3336

Feedback on the proposed language is appreciated. Please provide the
feedback directly in the BZ above.

I will update the thread/BZ with results from USWG.

Thanks,
--Samer

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Pete
Batard via groups.io
Sent: Thursday, February 25, 2021 5:55 AM
To: Wang, Sunny (HPS SW) <sunnywang@hpe.com>; Laszlo Ersek
<lersek@redhat.com>; Leif Lindholm <leif@nuviainc.com>;
devel@edk2.groups.io; Ni, Ray <ray.ni@intel.com>;
zhichao.gao@intel.com
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Andrei
Warkentin (awarkentin@vmware.com) <awarkentin@vmware.com>; Ard
Biesheuvel <ardb+tianocore@kernel.org>; Andrew Fish
<afish@apple.com>;
Michael D Kinney <michael.d.kinney@intel.com>; Jian J Wang
<jian.j.wang@intel.com>; Hao A Wu <hao.a.wu@intel.com>;
Sunny.Hsuanwen.Wang@gmail.com
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform
recovery

Hi Sunny,

I appreciate the input, but seeing that it is clear that no consensus
has been reached with regards to how the specs should be interpreted,
and that at least 4 separate people have now indicated that their
interpretation is different from the one you are putting forward (i.e.
you assert that the current code implementation is specs compliant
whereas we assert that the current code implementation is not specs
compliant), I believe that any further work on this will have to be
conditioned, first, by a specs update, that removes any ambiguity as
to the scope in which ReadyToBoot should apply.

Until that has happened, it seems very pointless to me to start
talking possible code workarounds, because we still can't appear to be
in agreement as to whether the current code implementation of
ReadyToBoot is specs compliant or not.

Now, even as I am the one proposing it, I'm afraid that I am not
planning to be the one opening a formal specs update request, since
there really is only so much more time I am willing to devote to this
matter. But I am hoping somebody else will.

Regards,

/Pete

On 2021.02.22 09:28, Wang, Sunny (HPS SW) wrote:
Hi all,

How about we signal ReadyToBoot ONLY for the default platform
recovery
option? The default platform recovery option here means the one
created by the code below in BdsEntry().
Status = EfiBootManagerInitializeLoadOption (
&PlatformDefaultBootOption,
LoadOptionNumberUnassigned,
LoadOptionTypePlatformRecovery,
LOAD_OPTION_ACTIVE,
L"Default PlatformRecovery",
FilePath,
NULL,
0
);

In other words, we just need to slightly update Pete's patch as the
following (adding the code below to EfiBootManagerProcessLoadOption()):

+ if ((LoadOption->OptionType == LoadOptionTypePlatformRecovery)
+ &&
StrCmp (LoadOption ->Description, L"Default
PlatformRecovery")) {
+ //
+ // Signal the EVT_SIGNAL_READY_TO_BOOT event when we are
about
to load and execute the boot option.
+ //
+ EfiSignalEventReadyToBoot ();

+ //
+ // Report Status Code to indicate ReadyToBoot was signalled
+ //
+ REPORT_STATUS_CODE (EFI_PROGRESS_CODE,
+ (EFI_SOFTWARE_DXE_BS_DRIVER |
+ EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
+ }

I think the existing platforms that have their platform-specific
PlatformRecovery option may also do either of the following things to
make the system have no chance to load the default platform recovery
option because they do have a better way to recover the boot options:
1. Make their PlatformRecovery option have higher priority than
the
default platform recovery option (has a lower number (####) than the
default platform recovery option)
2. Remove the default platform recovery option.
Therefore, if we only signal ReadyToBoot for the default platform
recovery
option, this may not affect the existing platforms because the code
may never be run on these platforms.





If the solution above doesn't work, I think the suggestion (Solution 2:
adding a new application as a PlatformRecovery####) I mentioned, in
the beginning, can be re-considered. The suggestion (solution 2) is
based on the thoughts below:
1. I think that processing/evaluating the Boot#### can be
interpreted as
the code after the comment " 6. Load EFI boot option to ImageHandle"
in
EfiBootManagerBoot() because these code are similar to the code in
EfiBootManagerProcessLoadOption(). Based on this, I think our current
implementation is compliant with the description below in the UEFI
spec. Of course, we can improve our implementation by moving the code
for processing/evaluating the Boot#### from EfiBootManagerBoot() to
EfiBootManagerProcessLoadOption() and make EfiBootManagerBoot() call
EfiBootManagerProcessLoadOption().
“After all SysPrep#### variables have been launched
and exited,
the platform shall notify EFI_EVENT_GROUP_READY_TO_BOOT event
group
and begin to evaluate Boot#### variables with Attributes set to
LOAD_OPTION_CATEGORY_BOOT according to the order defined by
BootOrder.
The FilePathList of variables marked LOAD_OPTION_CATEGORY_BOOT shall
not be evaluated prior to the completion of
EFI_EVENT_GROUP_READY_TO_BOOT event group processing."
2. Moreover, it looks like we want to process
PlatformRecovery####
option in the same way as Boot#### (do more things like setting
BootCurrent for PlatformRecovery####). If so, I would still prefer to
do what I suggest in the beginning to create a new application as a
new PlatformRecovery#### option for generating and launching a boot
option for the bootable image that is found by using a short-form File
Path Media Device Path so that we won't run into other difficulties.
At least, I already saw the difficulty of no connection between
BootCurrent variable and PlatformRecovery#### variable. Of course,
this application can be implemented without platform specific stuff,
so it can be commonly used by all platforms that need to load a boot image
discovered by using short-form File Path Media Device Path.




Regards,
Sunny Wang

-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com>
Sent: Wednesday, February 17, 2021 10:26 PM
To: Pete Batard <pete@akeo.ie>; Leif Lindholm <leif@nuviainc.com>;
devel@edk2.groups.io
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Andrei
Warkentin (awarkentin@vmware.com) <awarkentin@vmware.com>;
Wang, Sunny
(HPS SW) <sunnywang@hpe.com>; zhichao.gao@intel.com;
ray.ni@intel.com;
Ard Biesheuvel <ardb+tianocore@kernel.org>; Andrew Fish
<afish@apple.com>; Michael D Kinney <michael.d.kinney@intel.com>;
Jian J Wang <jian.j.wang@intel.com>; Hao A Wu <hao.a.wu@intel.com>
Subject: Re: [EXTERNAL] Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform
recovery

On 02/17/21 13:18, Pete Batard wrote:
Hi Leif,

Thanks for trying to resurrect this issue.

At this stage, and despite some initial pushback in the bugzilla
ticket, I believe we can all agree with the consensus that
UefiBootManagerLib is not in fact specs-compliant and therefore
needs to be fixed, one way or another, to make it specs-compliant.

My take on this is that, rather than propose a new patch, I'd much
rather have the current maintainers agree on the course of action
to fix the library (which, as Leif suggests, might very well be to
split the library into a specs-compliant and non-specs-compliant
version), as it would of course be better if the fix came from
people who have better understanding of the ramifications we might
face with trying to correct the current behaviour, and especially,
who have knowledge of the platforms that might be impacted from
making the lib specs-
compliant.

Especially, I don't think that the patch that I originally
submitted for this, or the additional proposals we made, are still
receivable, as they seem to fall short of fixing the issue in a
manner that all platforms can be happy with. And that is why I'd
like to hear from the maintainers on what their preferred approach
would be.

A new Feature PCD could satisfy both sets of platforms, could it not?

(Sorry if the original patch already had such a PCD; I don't
remember.)

Of course then we'd have a debate around the DEC default for the new
PCD
-- I'd say the default value of the PCD should match the
spec-mandated
behavior.

I don't recall any specifics, but a bug-compat pattern that's
sometimes used
is this:

if (BugCompatEnabled) {
//
// do the right thing in the wrong place, for legacy platforms' sake
//
Foo ();
}

//
// Do some stuff.
//
Bar ();

if (!BugCompatEnabled) {
//
// do the right thing in the right place, for conformant platforms
//
Foo ();
}

Not sure if it applies here.

Thanks
Laszlo


On 2021.02.17 11:42, Leif Lindholm wrote:
Hi Pete, +various

Resurrecting this old thread since Ard pointed out an issue I ran
into myself had already been encountered by Pete.
And the bugzilla ticket (directly below this reply) has had no
relevant progress since August.

Executive summary:
The current UefiBootManagerLib implementation of the
PlatformRecovery path does not notify the
EFI_EVENT_GROUP_READY_TO_BOOT event.

The argument has been made that since changing this would affect
an unnamed number of non-public platforms, the behaviour cannot be
changed even though it violates the UEFI specification.

I disagree with that statement. If we want to fork
UefiBootManagerLib into a BrokenLegacyUefiBootManagerLib and an
actually correct one, and have those platforms move to the
BrokenLegacy variant, I'm OK with that.

But using the default version should give specification-compliant
behaviour.

/
Leif

On Tue, Jun 30, 2020 at 18:17:10 +0100, Pete Batard wrote:
Please note that I have created a bug report
(https://bugzilla.tianocore.org/show_bug.cgi?id=2831) to address
the non-compliance issue was raised during the course of the
discussion below.

Regards,

/Pete


On 2020.06.17 18:06, Samer El-Haj-Mahmoud wrote:
I worked with Pete offline on this..

This code seems to be violating the UEFI Spec:

https://github.com/tianocore/edk2/blob/a56af23f066e2816c67b7c6e64d
e
7ddefcd70780/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c#L176
3


//
// 3. Signal the EVT_SIGNAL_READY_TO_BOOT event when we
are
about to load and execute
// the boot option.
//
if (BmIsBootManagerMenuFilePath (BootOption->FilePath)) {
DEBUG ((EFI_D_INFO, "[Bds] Booting Boot Manager Menu.\n"));
BmStopHotkeyService (NULL, NULL);
} else {
EfiSignalEventReadyToBoot();
//
// Report Status Code to indicate ReadyToBoot was signalled
//
REPORT_STATUS_CODE (EFI_PROGRESS_CODE,
(EFI_SOFTWARE_DXE_BS_DRIVER |
EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
//
// 4. Repair system through DriverHealth protocol
//
BmRepairAllControllers (0);
}

The UEFI Spec section 3.1.7 clearly states that Boot Options
(and their FilePathList) *shall not* be evaluated prior to the
completion of EFI_EVENT_GROUP_READY_TO_BOOT event group
processing:

"After all SysPrep#### variables have been launched and exited,
the platform shall notify EFI_EVENT_GROUP_READY_TO_BOOT
event
group and begin to evaluate Boot#### variables with Attributes
set to LOAD_OPTION_CATEGORY_BOOT according to the order
defined
by
BootOrder. The FilePathList of variables marked
LOAD_OPTION_CATEGORY_BOOT shall not be evaluated prior to
the
completion of EFI_EVENT_GROUP_READY_TO_BOOT event group
processing."

This is a prescriptive language that is stronger than the
language in section 7.1 which defines the ReadyToBoot event
group in a general way:

"EFI_EVENT_GROUP_RESET_SYSTEM
This event group is notified by the system when ResetSystem() is
invoked and the system is about to be reset. The event group is
only notified prior to ExitBootServices() invocation."

The EDK2 code in the else block above (to call
EfiSignalEventReadyToBoot() ) need to move before the code that
is processing BootOption->FilePath. In fact, why is this
signaling even a BootManager task? It should be a higher level
BDS task (after processing SysPrp and before processing Boot
options, per the
spec).
This would be somewhere around
https://github.com/tianocore/edk2/blob/b15646484eaffcf7cc464fdea02
1
4498f26addc2/MdeModulePkg/Universal/BdsDxe/BdsEntry.c#L1007
where SysPrep is processed.

This should also take care of the issue Pete reported in this
thread, without the need for explicitly signaling ReadyToBoot
from PlatformRecovery (or changing the UEFI spec).

Thanks,
--Samer



From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Samer El-Haj-Mahmoud via groups.io
Sent: Wednesday, June 17, 2020 12:42 PM
To: devel@edk2.groups.io; Andrei Warkentin
(awarkentin@vmware.com)
<awarkentin@vmware.com>; Wang, Sunny (HPS SW)
<sunnywang@hpe.com>;
pete@akeo.ie
Cc: zhichao.gao@intel.com; ray.ni@intel.com; Ard Biesheuvel
<Ard.Biesheuvel@arm.com>; leif@nuviainc.com; Samer El-Haj-
Mahmoud
<Samer.El-Haj-Mahmoud@arm.com>
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on
platform
recovery

The UEFI spec (3.1.7) says:

"After all SysPrep#### variables have been launched and exited,
the platform shall notify EFI_EVENT_GROUP_READY_TO_BOOT
event
group and begin to evaluate Boot#### variables with Attributes
set to LOAD_OPTION_CATEGORY_BOOT according to the order
defined
by
BootOrder. The FilePathList of variables marked
LOAD_OPTION_CATEGORY_BOOT shall not be evaluated prior to
the
completion of EFI_EVENT_GROUP_READY_TO_BOOT event group
processing."

The way I read this, I expect ReadyToBoot to be signaled after
SysPrep#### (if any) are processed, but before Boot#### are
processed. Is my understanding correct that this language
implies ReadyToBoot need to be signaled even if BootOrder does
not contain any Boot#### options marked as
LOAD_OPTION_CATEGORY_BOOT?
And if
so, is EDK2 not doing this, which leads us to this patch
(signaling it in PlatformRecovery?)



From: mailto:devel@edk2.groups.io
<mailto:devel@edk2.groups.io>
On
Behalf Of Andrei Warkentin via groups.io
Sent: Wednesday, June 17, 2020 12:37 PM
To: Wang, Sunny (HPS SW) <mailto:sunnywang@hpe.com>;
mailto:devel@edk2.groups.io; mailto:pete@akeo.ie
Cc: mailto:zhichao.gao@intel.com; mailto:ray.ni@intel.com; Ard
Biesheuvel <mailto:Ard.Biesheuvel@arm.com>;
mailto:leif@nuviainc.com
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on
platform
recovery

Thanks Pete.

I think the question I have, that I hope Tiano veterans can
chime in, is whether we are doing the right thing, or if we
should be overriding the boot mode? I.e. is it normal that we
boot up in recovery until options are saved?


A


________________________________________
From: mailto:devel@edk2.groups.io
<mailto:devel@edk2.groups.io>
on
behalf of Pete Batard via groups.io
<mailto:pete=akeo.ie@groups.io>
Sent: Wednesday, June 17, 2020 11:34 AM
To: Wang, Sunny (HPS SW) <mailto:sunnywang@hpe.com>;
mailto:devel@edk2.groups.io <mailto:devel@edk2.groups.io>
Cc: mailto:zhichao.gao@intel.com <mailto:zhichao.gao@intel.com>;
mailto:ray.ni@intel.com <mailto:ray.ni@intel.com>;
mailto:ard.biesheuvel@arm.com
<mailto:ard.biesheuvel@arm.com>;
mailto:leif@nuviainc.com <mailto:leif@nuviainc.com>
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on
platform
recovery

On 2020.06.17 14:04, Wang, Sunny (HPS SW) wrote:
Thanks for checking my comments, Pete.

Or is the "one more" the issue, meaning that it would get
signaled more than once?
[Sunny] Yeah, it would get signaled more than once if the
PlatformRecovery option (a UEFI application) calls
EfiBootManagerBoot() to launch the recovered boot option inside
of the application.
Okay.

One element that I'm going to point out is that, with the
current
EDK2 code (i.e. without this proposal applied), and after a user
goes into the setup to save their boot options in order for
regular boot options to get executed instead of PlaformRecovery,
the OnReadyToBoot event is actually called twice.

So my understanding is that, while we of course want to avoid
this and any patch proposal should actively try to prevent it,
it seems we already have behaviour in EDK2 that can lead to
OnReadyToBoot being signalled more than once.

At least the current Pi 4 platform does demonstrate this behaviour.
For instance, if you run DEBUG, you will see two instances of:

RemoveDtStdoutPath: could not retrieve DT blob - Not Found

which is a one-instance message generated from the
ConsolePrefDxe's
OnReadyToBoot() call. I've also confirmed more specifically that
OnReadyToBoot() is indeed called twice.

I don't recall us doing much of any special with regards to boot
options for the Pi platform, so my guess is that it's probably
not the only platform where OnReadyToBoot might be signalled
more
than
once, and that this might be tied to a default EDK2 behaviour.
Therefore I don't see having a repeated event as a major deal
breaker (though, again, if we can avoid that, we of course will
want to).

I don't mind trying an alternative approach, but I don't
understand how what you describe would help. Can you please
be
more specific about what you have in mind?
[Sunny] Sure. I added more information below. If it is still
not clear enough, feel free to let me know.
1. Create a UEFI application with the code to signal
ReadyToBoot and pick /efi/boot/bootaa64.efi from either SD or
USB and run it.
So that would basically be adding code that duplicates, in part,
what Platform Recovery already does.

I have to be honest: Even outside of the extra work this would
require, I don't really like the idea of having to write our own
application, as it will introduce new possible points of
failures and require extra maintenance (especially as we will
want to be able to handle network boot and other options, and
before long, I fear that we're going to have to write our own Pi
specific boot manager). Doing so simply because the current
Platform Recovery, which does suit our needs otherwise, is not
designed to call ReadyToBoot does not seem like the best course
of action in my book.

Instead, I still logically believe that any option that calls a
boot loader should signal ReadyToBoot, regardless of whether it
was launched from Boot Manager or Platform Recovery, and that it
shouldn't be left to each platform to work around that.

Of course, I understand that this would require a specs change,
and that it also may have ramifications for existing platforms
that interpret the current specs pedantically. But to me,
regardless of what the specs appear to be limiting it to right
now, the logic of a "ReadyToBoot"
event is that it should be signalled whenever a bootloader is
about to be executed, rather than only when a bootloader
happened to be launched through a formal Boot Manager option.

I would therefore appreciate if other people could weigh in on
this matter, to see if I'm the only one who believes that we
could ultimately have more to gain from signalling ReadyToBoot
with PlatformRecovery options than leaving things as they stand
right now...

2. Then, call EfiBootManagerInitializeLoadOption like
the following in a DXE driver or other places before "Default
PlatformRecovery" registration:
Status = EfiBootManagerInitializeLoadOption (
&LoadOption,

0,
-> 0 is the OptionNumber to let application be load before "
Default PlatformRecovery" option
LoadOptionTypePlatformRecovery,
LOAD_OPTION_ACTIVE,
L"Application for recovering boot options",

FilePath,
-> FilePath is the Application's device path,
NULL,
0
);


My reasoning is that, if PlatformRecovery#### can execute a
regular bootloader like /efi/boot/boot####.efi from
installation media, then it should go through the same kind of
initialization that happens for a regular boot option, and
that should include signaling the ReadyToBoot event.
[Sunny] Thanks for clarifying this, and Sorry about that I
missed your cover letter for this patch. I was just thinking
that we may not really need to make this behavior change in
both EDK II code and UEFI specification for solving the problem
specific to the case that OS is loaded by "Default
PlatformRecovery" option,
The way I see it is that the Pi platform is unlikely to be the
only one where PlatformRecovery is seen as a means to install an
OS.
Granted, this may seem like abusing the option, but since UEFI
doesn't provide an "Initial OS Install" mode, I would assert
that it as good a use of this option as any.

In other words, I don't think this improvement would only
benefit the Pi platform.

and I'm also not sure if it is worth making this change to
affect some of the system or BIOS vendors who have
implemented
their PlatformRecovery option.
That's a legitimate concern, and I would agree the one major
potential pitfall of this proposal, if there happens to exist a
system where an OnReadyToBoot even before running the
recovery
option can have adverse effects.

I don't really believe that such a system exists, because I
expect most recovery boot loaders to also work (or at least have
been designed to
work) as regular boot options. But I don't have enough
experience with platform recovery to know if that's a correct
assertion to make...

If the alternative approach I mentioned works for you, I think
that would be an easier solution.
Right now, even as the patch proposal has multiple issues that
require it to be amended (Don't signal ReadyToBoot except for
PlatformRecovery
+ Prevent situations where ReadyToBoot could be signalled
+ multiple
times) I still see it as both an easier solution than the
alternative, as well as one that *should* benefit people who
design Platform Recovery UEFI applications in the long run. So
that is why I am still trying to advocate for it.

But I very much hear your concerns, and I agree that specs
changes are better avoided when possible.

Thus, at this stage, even as I don't want to drag this
discussion much further, I don't feel like I want to commit to
one solution or the other before we have had a chance to hear
other people, who may have their own opinion on the matter,
express their views.

Regards,

/Pete



Regards,
Sunny Wang

-----Original Message-----
From: Pete Batard [mailto:pete@akeo.ie]
Sent: Wednesday, June 17, 2020 6:59 PM
To: Wang, Sunny (HPS SW) <mailto:sunnywang@hpe.com>;
mailto:devel@edk2.groups.io
Cc: mailto:zhichao.gao@intel.com; mailto:ray.ni@intel.com;
mailto:ard.biesheuvel@arm.com; mailto:leif@nuviainc.com
Subject: Re: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on
platform
recovery

Hi Sunny, thanks for looking into this.

On 2020.06.17 09:16, Wang, Sunny (HPS SW) wrote:
Hi Pete.

Since the EfiBootManagerProcessLoadOption is called by
ProcessLoadOptions as well, your change would also cause some
unexpected behavior like:
1. Signal one more ReadyToBoot for the PlatformRecovery option
which is an application that calls EfiBootManagerBoot() to
launch its recovered boot option.
I'm not sure I understand how this part is unwanted.

The point of this patch is to ensure that ReadyToBoot is
signalled for the PlatformRecovery option, so isn't what you
describe above exactly what we want?

Or is the "one more" the issue, meaning that it would get
signalled more than once?


2. Signal ReadyToBoot for SysPrep#### or Driver#### that is
not really a "boot" option.
Yes, I've been wondering about that, because BdsEntry.c's
ProcessLoadOptions(), which calls
EfiBootManagerProcessLoadOption(),
mentions that it will load will load and start every
Driver####, SysPrep#### or PlatformRecovery####. But the
comment about the
while() loop in EfiBootManagerProcessLoadOption() only mentions
PlatformRecovery####.

If needed, I guess we could amend the patch to detect the type
of option and only signal ReadyToBoot for PlatformRecovery####.

To solve your problem, creating a PlatformRecovery option with
the smallest option number and using it instead of default one
(with short-form File Path Media Device Path) looks like a
simpler solution.
I don't mind trying an alternative approach, but I don't
understand how what you describe would help. Can you please be
more specific about what you have in mind?

Our main issue here is that we must have ReadyToBoot signalled
so that the ReadyToBoot() function callback from
EmbeddedPkg/Drivers/ConsolePrefDxe gets executed in order for
the
boot loader invoked from PlatformRecovery#### to use a
properly initialized graphical console. So I'm not sure I quite
get how switching from one PlatformRecovery#### option to
another would improve things.

If it helps, here is what we currently default to, in terms of
boot options, on a Raspberry Pi 4 platform with a newly build
firmware:

[Bds]=============Begin Load Options Dumping
...=============
Driver Options:
SysPrep Options:
Boot Options:
Boot0000: UiApp 0x0109
Boot0001: UEFI Shell 0x0000
PlatformRecovery Options:
PlatformRecovery0000: Default PlatformRecovery
0x0001 [Bds]=============End Load Options
Dumping=============

With this, PlatformRecovery0000 gets executed by default, which
is what we want, since it will pick /efi/boot/bootaa64.efi from
either SD or USB and run it, the only issue being that, because
ReadyToBoot has not been executed, the graphical console is not
operative so users can't interact with the OS installer.

So I'm really not sure how adding an extra PlatformRecovery####
would help. And I'm also not too familiar with how one would go
around to add such an entry...

By the way, I also checked the UEFI specification. It looks
making sense to only signal ReadyToBoot for boot option
(Boot####).

That's something I considered too, but I disagree with this
conclusion.

My reasoning is that, if PlatformRecovery#### can execute a
regular bootloader like /efi/boot/boot####.efi from
installation media, then it should go through the same kind of
initialization that happens for a regular boot option, and that
should include signalling the ReadyToBoot event.

If there was a special bootloader for PlatformRecovery#### (e.g.
/efi/boot/recovery####.efi) then I would agree with only
signalling ReadyToBoot for a formal Boot#### option. But that
isn't the case, so I think it is reasonable to want to have
ReadyToBoot also occur when a /efi/boot/boot####.efi
bootloader
is executed from PlatformRecovery####., especially when we
know
it can be crucial to ensuring that the end user can actually
use the
graphical console.

Therefore, your change may also require specification change.
Yes, I mentioned that in the cover letter for this patch
(https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%
2
Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F61327&amp;data=02%7C01%
7C
a
warkentin%40vmware.com%7C5f90d077bc7949c1122f08d812dc48d3%7Cb391
3
8
ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637280084611749324&amp;sdat
a
=
2%2B%2FcvMkrmZGTRRLDGSuMsKbiyDOGtwYwZ7qSqMyMicc%3D&amp;res
erved=0
), which also describes the issue we are trying to solve in
greater details. This is what I wrote:

---------------------------------------------------------------
--
-
------

Note however that this may require a specs update, as the
current UEFI specs for EFI_BOOT_SERVICES.CreateEventEx() have:

> EFI_EVENT_GROUP_READY_TO_BOOT
> This event group is notified by the system when the
Boot Manager
> is about to load and execute a boot option.

and, once this patch has been applied, we may want to update
this section to mention that it applies to both Boot Manager
and Platform Recovery.
---------------------------------------------------------------
--
-
------



Again, I don't have an issue with trying to use an alternate
approach to solve our problem (though I ultimately believe
that, if PlatformRecovery#### can launch a
/efi/boot/boot####.efi bootloader then we must update the
specs
and the code to have ReadyToBoot also signalled then, because
that's the logical thing to do). But right now, I'm not seeing
how to achieve that when PlatformRecovery#### is the option
that is used to launch the OS installation the bootloader. So
if you can provide mode details on how exactly you think
creating an alternate PlatformRecovery option would help, I would
appreciate it.

Regards,

/Pete


Regards,
Sunny Wang

-----Original Message-----
From: mailto:devel@edk2.groups.io
[mailto:devel@edk2.groups.io]
On Behalf Of Pete Batard
Sent: Tuesday, June 16, 2020 5:56 PM
To: mailto:devel@edk2.groups.io
Cc: mailto:zhichao.gao@intel.com; mailto:ray.ni@intel.com;
mailto:ard.biesheuvel@arm.com; mailto:leif@nuviainc.com
Subject: [edk2-devel] [edk2][PATCH 1/1]
MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on
platform
recovery

Currently, the ReadyToBoot event is only signaled when a
formal Boot Manager option is executed (in BmBoot.c ->
EfiBootManagerBoot ()).

However, with the introduction of Platform Recovery in UEFI
2.5, which may lead to the execution of a boot loader that has
similar requirements to a regular one, yet is not launched as
a Boot Manager option, it also becomes necessary to signal
ReadyToBoot when a Platform Recovery boot loader runs.

Especially, this can be critical to ensuring that the
graphical console is actually usable during platform recovery,
as some platforms do rely on the ConsolePrefDxe driver, which
only performs console initialization after ReadyToBoot is
triggered.

This patch fixes that behaviour by calling
EfiSignalEventReadyToBoot () in
EfiBootManagerProcessLoadOption
(), which is the function that sets up the platform recovery
boot process.

Signed-off-by: Pete Batard <mailto:pete@akeo.ie>
---
MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
| 9
+++++++++
1 file changed, 9 insertions(+)

diff --git
a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
index 89372b3b97b8..117f1f5b124c 100644
---
a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
+++
b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
@@ -1376,6 +1376,15 @@ EfiBootManagerProcessLoadOption (
return EFI_SUCCESS;
}

+ //
+ // Signal the EVT_SIGNAL_READY_TO_BOOT event when we
are
+about
to load and execute the boot option.
+ //
+ EfiSignalEventReadyToBoot ();
+ //
+ // Report Status Code to indicate ReadyToBoot was signalled
+// REPORT_STATUS_CODE (EFI_PROGRESS_CODE,
(EFI_SOFTWARE_DXE_BS_DRIVER |
+ EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
+
//
// Load and start the load option.
//
--
2.21.0.windows.1




IMPORTANT NOTICE: The contents of this email and any
attachments
are confidential and may also be privileged. If you are not the
intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any
purpose, or store or copy the information in any medium. Thank
you.

IMPORTANT NOTICE: The contents of this email and any
attachments
are confidential and may also be privileged. If you are not the
intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any
purpose, or store or copy the information in any medium. Thank
you.





IMPORTANT NOTICE: The contents of this email and any attachments are
confidential and may also be privileged. If you are not the intended recipient,
please notify the sender immediately and do not disclose the contents to any
other person, use it for any purpose, or store or copy the information in any
medium. Thank you.



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


Re: [PATCH 3/3] Platform/RaspberryPi/AcpiTables: Correct _DMA consumer

Samer El-Haj-Mahmoud
 

Any further comments on the ACPI ECR documented in: https://bugzilla.tianocore.org/show_bug.cgi?id=3335 ?

 

I already have comments from Jeremey and Andrew saying it looks good. If there are no objections, I will let ASWG know to approve the ECR for future ACPI spec publication.

 

Thanks,

--Samer

 

 

 

 

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Samer El-Haj-Mahmoud via groups.io
Sent: Tuesday, April 13, 2021 12:45 PM
To: Andrei Warkentin (awarkentin@...) <awarkentin@...>; Jeremy Linton <Jeremy.Linton@...>; devel@edk2.groups.io
Cc: Ard Biesheuvel <Ard.Biesheuvel@...>; leif@...; pete@...; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@...>
Subject: Re: [edk2-devel] [PATCH 3/3] Platform/RaspberryPi/AcpiTables: Correct _DMA consumer

 

I just got to this thread. Apologies for the delay.

 

I went through the ACPI spec. Here is what I see:

 

https://uefi.org/specs/ACPI/6.4/19_ASL_Reference/ACPI_Source_Language_Reference.html#qwordmemory-qword-memory-resource-descriptor-macro

 

ResourceUsage specifies whether the Memory range is consumed by this device (ResourceConsumer) or passed on to child devices (ResourceProducer). If nothing is specified, then ResourceConsumer is assumed.”
 
https://uefi.org/specs/ACPI/6.4/06_Device_Configuration/Device_Configuration.html#dma-direct-memory-access
 
“ It specifies the ranges the bus controller (bridge) decodes on the child-side of its interface. (This is analogous to the _CRS object, which describes the resources that the bus controller decodes on the parent-side of its interface.) Any ranges described in the resources of a _DMA object can be used by child devices for DMA or bus master transactions..”
 
The way I read the spec, this wording in the _DMA definition “Any ranges described in the resources of a _DMA object can be used by child devices..” suggests that this should be a ResourceProducer, per the QWordMemory resource descriptor definition above
 

The _DMA example in section 6.2.4 uses a “ResourceConsumer”, when it should really be “ResourceProducer” according to these definitions: It describes , the child devices view of the address range, so the "translation" added is the CPU's view of the same range.

 
I submitted a “code first” ECR to correct the ACPI spec example (here : https://bugzilla.tianocore.org/show_bug.cgi?id=3335). Please provide feedback on the BZ (or this thread) whether you agree or not, so we can take this to ASWG/UEFI Forum for discussion and approval
 
Thanks,
--Samer
 
 

 

From: Andrei Warkentin <awarkentin@...>
Sent: Thursday, April 8, 2021 10:24 AM
To: Jeremy Linton <Jeremy.Linton@...>; devel@edk2.groups.io
Cc: Ard Biesheuvel <Ard.Biesheuvel@...>; leif@...; pete@...; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@...>
Subject: Re: [PATCH 3/3] Platform/RaspberryPi/AcpiTables: Correct _DMA consumer

 

I don't know... the ACPI spec is weird.

 

 

...lists ResourceConsumer for _DMA.

 

A

 


From: Jeremy Linton <jeremy.linton@...>
Sent: Thursday, April 8, 2021 12:58 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: ard.biesheuvel@... <ard.biesheuvel@...>; leif@... <leif@...>; pete@... <pete@...>; samer.el-haj-mahmoud@... <samer.el-haj-mahmoud@...>; Andrei Warkentin <awarkentin@...>; Jeremy Linton <jeremy.linton@...>
Subject: [PATCH 3/3] Platform/RaspberryPi/AcpiTables: Correct _DMA consumer

 

Bridge devices should be marked as producers so that their
children can consume the resources. In linux if this isn't
true then the translation gets ignored and the DMA values
are incorrect. This fixes DMA on all the devices that
need a translation.

Signed-off-by: Jeremy Linton <jeremy.linton@...>
---
 Platform/RaspberryPi/AcpiTables/Dsdt.asl | 2 +-
 Platform/RaspberryPi/AcpiTables/Emmc.asl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
index d116f965e1..32cd5fc9f9 100644
--- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
+++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
@@ -205,7 +205,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", "RPI", 2)
         // Only the first GB is available.

         // Bus 0xC0000000 -> CPU 0x00000000.

         //

-        QWordMemory (ResourceConsumer,

+        QWordMemory (ResourceProducer,

           ,

           MinFixed,

           MaxFixed,

diff --git a/Platform/RaspberryPi/AcpiTables/Emmc.asl b/Platform/RaspberryPi/AcpiTables/Emmc.asl
index 179dd3ecdb..0fbc2a79ea 100644
--- a/Platform/RaspberryPi/AcpiTables/Emmc.asl
+++ b/Platform/RaspberryPi/AcpiTables/Emmc.asl
@@ -32,7 +32,7 @@ DefinitionBlock (__FILE__, "SSDT", 5, "RPIFDN", "RPI4EMMC", 2)
       }

 

       Name (_DMA, ResourceTemplate() {

-        QWordMemory (ResourceConsumer,

+        QWordMemory (ResourceProducer,

           ,

           MinFixed,

           MaxFixed,

--
2.13.7

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

9941 - 9960 of 84488