OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 The flash detection routine will attempt to determine how the flash device behaves (e.g. ROM, RAM, Flash). But when SEV-ES is enabled and the flash device behaves as a ROM device (meaning it is marked read-only by the hypervisor), this check may result in an infinite nested page fault because of the attempted write. Since the instruction cannot be emulated when SEV-ES is enabled, the RIP is never advanced, resulting in repeated nested page faults. When SEV-ES is enabled, exit the flash detection early and assume that the FD behaves as Flash. This will result in QemuFlashWrite() being called to store EFI variables, which will also result in an infinite nested page fault when the write is performed. In this case, update QemuFlashWrite() to use the VMGEXIT MMIO write support to have the hypervisor perform the write without having to emulate the instruction. Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e2db781f0c
commit
437eb3f7a8
@@ -10,6 +10,9 @@
|
||||
**/
|
||||
|
||||
#include <Library/UefiRuntimeLib.h>
|
||||
#include <Library/MemEncryptSevLib.h>
|
||||
#include <Library/VmgExitLib.h>
|
||||
#include <Register/Amd/Msr.h>
|
||||
|
||||
#include "QemuFlash.h"
|
||||
|
||||
@@ -32,3 +35,40 @@ QemuFlashBeforeProbe (
|
||||
// Do nothing
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
Write to QEMU Flash
|
||||
|
||||
@param[in] Ptr Pointer to the location to write.
|
||||
@param[in] Value The value to write.
|
||||
|
||||
**/
|
||||
VOID
|
||||
QemuFlashPtrWrite (
|
||||
IN volatile UINT8 *Ptr,
|
||||
IN UINT8 Value
|
||||
)
|
||||
{
|
||||
if (MemEncryptSevEsIsEnabled ()) {
|
||||
MSR_SEV_ES_GHCB_REGISTER Msr;
|
||||
GHCB *Ghcb;
|
||||
|
||||
Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
|
||||
Ghcb = Msr.Ghcb;
|
||||
|
||||
//
|
||||
// Writing to flash is emulated by the hypervisor through the use of write
|
||||
// protection. This won't work for an SEV-ES guest because the write won't
|
||||
// be recognized as a true MMIO write, which would result in the required
|
||||
// #VC exception. Instead, use the the VMGEXIT MMIO write support directly
|
||||
// to perform the update.
|
||||
//
|
||||
VmgInit (Ghcb);
|
||||
Ghcb->SharedBuffer[0] = Value;
|
||||
Ghcb->SaveArea.SwScratch = (UINT64) (UINTN) Ghcb->SharedBuffer;
|
||||
VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1);
|
||||
VmgDone (Ghcb);
|
||||
} else {
|
||||
*Ptr = Value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user