audk/OvmfPkg/Library
Tom Lendacky 1b0db1ec87 UefiCpuPkg, OvmfPkg: Disable interrupts when using the GHCB
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3008

The QemuFlashPtrWrite() flash services runtime uses the GHCB and VmgExit()
directly to perform the flash write when running as an SEV-ES guest. If an
interrupt arrives between VmgInit() and VmgExit(), the Dr7 read in the
interrupt handler will generate a #VC, which can overwrite information in
the GHCB that QemuFlashPtrWrite() has set. This has been seen with the
timer interrupt firing and the CpuExceptionHandlerLib library code,
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/
  Xcode5ExceptionHandlerAsm.nasm and
  ExceptionHandlerAsm.nasm
reading the Dr7 register while QemuFlashPtrWrite() is using the GHCB. In
general, it is necessary to protect the GHCB whenever it is used, not just
in QemuFlashPtrWrite().

Disable interrupts around the usage of the GHCB by modifying the VmgInit()
and VmgDone() interfaces:
- VmgInit() will take an extra parameter that is a pointer to a BOOLEAN
  that will hold the interrupt state at the time of invocation. VmgInit()
  will get and save this interrupt state before updating the GHCB.
- VmgDone() will take an extra parameter that is used to indicate whether
  interrupts are to be (re)enabled. Before exiting, VmgDone() will enable
  interrupts if that is requested.

Fixes: 437eb3f7a8
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Acked-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <c326a4fd78253f784b42eb317589176cf7d8592a.1604685192.git.thomas.lendacky@amd.com>
2020-11-10 19:07:55 +00:00
..
AcpiTimerLib OvmfPkg: Add bhyve support into AcpiTimerLib 2020-04-30 13:46:11 +00:00
BaseMemEncryptSevLib OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function 2020-08-17 02:46:39 +00:00
BasePciCapLib OvmfPkg/BasePciCapLib: suppress invalid "nullptr deref" warning 2019-04-18 16:06:04 +02:00
BasePciCapPciSegmentLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
BhyveFwCtlLib OvmfPkg: fix DEC spec violation introduced by Bhyve addition 2020-08-01 20:38:55 +00:00
DxePciLibI440FxQ35 OvmfPkg/Qemu: Fix various typos 2020-02-10 22:30:07 +00:00
EmuVariableFvbLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
GenericQemuLoadImageLib OvmfPkg/GenericQemuLoadImageLib: log "Not Found" at INFO level 2020-06-10 07:55:55 +00:00
LoadLinuxLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
LockBoxLib OvmfPkg: strip trailing whitespace 2019-10-04 11:18:32 +01:00
NvVarsFileLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
PciHostBridgeLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
PlatformBmPrintScLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformBootManagerLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
PlatformBootManagerLibBhyve OvmfPkg: fix DEC spec violation introduced by Bhyve addition 2020-08-01 20:38:55 +00:00
PlatformDebugLibIoPort OvmfPkg/PlatformDebugLibIoPort: Introduce a Nocheck variant 2020-04-28 21:12:01 +00:00
PlatformFvbLibNull OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformHasIoMmuLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformSecureLib OvmfPkg: strip trailing whitespace 2019-10-04 11:18:32 +01:00
PxeBcPcdProducerLib OvmfPkg: control PXEv4 / PXEv6 boot support from the QEMU command line 2020-04-28 22:37:35 +00:00
QemuBootOrderLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
QemuFwCfgLib OvmfPkg: Add QemuFwCfgLibNull 2020-05-05 16:57:57 +00:00
QemuFwCfgS3Lib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
QemuFwCfgSimpleParserLib OvmfPkg: introduce QemuFwCfgSimpleParserLib 2020-04-28 22:37:35 +00:00
ResetSystemLib OvmfPkg: Add BaseResetSystemLibBhyve 2020-05-05 19:40:40 +00:00
SerializeVariablesLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
SmbiosVersionLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
SmmCpuFeaturesLib OvmfPkg/SEV: don't manage the lifecycle of the SMRAM at the default SMBASE 2020-02-05 12:59:32 +00:00
SmmCpuPlatformHookLibQemu OvmfPkg: enable SMM Monarch Election in PiSmmCpuDxeSmm 2020-03-04 12:22:07 +00:00
Tcg2PhysicalPresenceLibNull OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
Tcg2PhysicalPresenceLibQemu OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
TlsAuthConfigLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
UefiPciCapPciIoLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
VirtioLib OvmfPkg/Virtio: Fix few typos 2020-02-10 22:30:07 +00:00
VirtioMmioDeviceLib OvmfPkg: drop redundant VendorID check in VirtioMmioDeviceLib 2020-09-17 12:01:11 +00:00
VmgExitLib UefiCpuPkg, OvmfPkg: Disable interrupts when using the GHCB 2020-11-10 19:07:55 +00:00
X86QemuLoadImageLib OvmfPkg/X86QemuLoadImageLib: handle EFI_ACCESS_DENIED from LoadImage() 2020-06-09 20:19:04 +00:00
XenConsoleSerialPortLib OvmfPkg/Xen: Fix various typos 2020-02-10 22:30:07 +00:00
XenHypercallLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
XenIoMmioLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
XenPlatformLib OvmfPkg/XenPlatformLib: Cache result for XenDetected 2019-08-21 18:03:49 +02:00
XenRealTimeClockLib OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg 2019-08-21 18:03:50 +02:00