From: Brijesh Singh Date: Fri, 6 Jul 2018 15:00:42 +0000 (-0500) Subject: OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Restore C-bit when SEV is active X-Git-Tag: edk2-stable201903~1440 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=75b7aa9528bdd05a7ecf4e64a6beb478d31b402c OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Restore C-bit when SEV is active AmdSevDxe maps the flash memory range with C=0, but SetMemorySpaceAttributes() unconditionally resets the C-bit to '1'. Lets restore the mapping back to C=0. Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Cc: Justen Jordan L Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh Reviewed-by: Laszlo Ersek Regression-tested-by: Laszlo Ersek --- diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf index d7b4ec06c4..86b244a009 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf @@ -53,6 +53,7 @@ DebugLib DevicePathLib DxeServicesTableLib + MemEncryptSevLib MemoryAllocationLib PcdLib UefiBootServicesTableLib diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c index 37deece363..1fbe1342a5 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -203,5 +204,21 @@ MarkIoMemoryRangeForRuntimeAccess ( ); ASSERT_EFI_ERROR (Status); + // + // When SEV is active, AmdSevDxe mapped the BaseAddress with C=0 but + // SetMemorySpaceAttributes() remaps the range with C=1. Let's restore + // the mapping so that both guest and hyervisor can access the flash + // memory range. + // + if (MemEncryptSevIsEnabled ()) { + Status = MemEncryptSevClearPageEncMask ( + 0, + BaseAddress, + EFI_SIZE_TO_PAGES (Length), + FALSE + ); + ASSERT_EFI_ERROR (Status); + } + return Status; }