Skip to content

Commit

Permalink
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Restore C-bit when SEV is active
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Justen Jordan L <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Regression-tested-by: Laszlo Ersek <[email protected]>
  • Loading branch information
codomania authored and lersek committed Jul 6, 2018
1 parent 3b3d016 commit 75b7aa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
DebugLib
DevicePathLib
DxeServicesTableLib
MemEncryptSevLib
MemoryAllocationLib
PcdLib
UefiBootServicesTableLib
Expand Down
17 changes: 17 additions & 0 deletions OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/MemEncryptSevLib.h>
#include <Library/PcdLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
Expand Down Expand Up @@ -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;
}

0 comments on commit 75b7aa9

Please sign in to comment.