]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/AmdSevDxe: do not use extended PCI config space
authorBrijesh Singh via groups.io <brijesh.singh=amd.com@groups.io>
Thu, 9 Dec 2021 03:27:41 +0000 (11:27 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 9 Dec 2021 06:28:10 +0000 (06:28 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275

Commit 85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 added support to ensure
that MMIO is only performed against the un-encrypted memory. If MMIO
is performed against encrypted memory, a #GP is raised.

The AmdSevDxe uses the functions provided by the MemEncryptSevLib to
clear the memory encryption mask from the page table. If the
MemEncryptSevLib is extended to include VmgExitLib then depedency
chain will look like this:

OvmfPkg/AmdSevDxe/AmdSevDxe.inf
-----> MemEncryptSevLib                    class
-----> "OvmfPkg/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf"   instance
-----> VmgExitLib                          class
-----> "OvmfPkg/VmgExitLib"    instance
-----> LocalApicLib                        class
-----> "UefiCpuPkg/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf" instance
-----> TimerLib                            class
-----> "OvmfPkg/AcpiTimerLib/DxeAcpiTimerLib.inf"   instance
-----> PciLib                                           class
-----> "OvmfPkg/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf"    instance
-----> PciExpressLib                                          class
-----> "MdePkg/BasePciExpressLib/BasePciExpressLib.inf"  instance

The LocalApicLib provides a constructor that gets called before the
AmdSevDxe can clear the memory encryption mask from the MMIO regions.

When running under the Q35 machine type, the call chain looks like this:

AcpiTimerLibConstructor ()  [AcpiTimerLib]
  PciRead32 ()              [DxePciLibI440FxQ35]
   PciExpressRead32 ()      [PciExpressLib]

The PciExpressRead32 () reads the MMIO region. The MMIO regions are not
yet mapped un-encrypted, so the check introduced in the commit
85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 raises a #GP.

The AmdSevDxe driver does not require the access to the extended PCI
config space. Accessing a normal PCI config space, via IO port should be
sufficent. Use the module-scope override to make the AmdSevDxe use the
BasePciLib instead of BasePciExpressLib so that PciRead32 () uses the
IO ports instead of the extended config space.

Cc: Michael Roth <michael.roth@amd.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Suggested-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
OvmfPkg/AmdSev/AmdSevX64.dsc
OvmfPkg/Bhyve/BhyveX64.dsc
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/OvmfXen.dsc

index 5ee54451169b72ae13f11b729db9922959a17ed3..2997929faa0587f7e84622cab3e6f431deead0ef 100644 (file)
 !endif\r
 \r
   OvmfPkg/PlatformDxe/Platform.inf\r
-  OvmfPkg/AmdSevDxe/AmdSevDxe.inf\r
+  OvmfPkg/AmdSevDxe/AmdSevDxe.inf {\r
+    <LibraryClasses>\r
+    PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  }\r
   OvmfPkg/IoMmuDxe/IoMmuDxe.inf\r
 \r
   #\r
index d8fe607d1cf7fd1f94f869853593093a2bd31b0a..f456349962474364b128244795acf1b2f6b1836c 100644 (file)
 !endif\r
 \r
   OvmfPkg/PlatformDxe/Platform.inf\r
-  OvmfPkg/AmdSevDxe/AmdSevDxe.inf\r
+  OvmfPkg/AmdSevDxe/AmdSevDxe.inf {\r
+    <LibraryClasses>\r
+    PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  }\r
   OvmfPkg/IoMmuDxe/IoMmuDxe.inf\r
 \r
 \r
index 71227d1b709a0b83012926da5edb02a1398dca44..13d9a1f111bcc0b089e6cf83b84c7e04b937a0e8 100644 (file)
 !endif\r
 \r
   OvmfPkg/PlatformDxe/Platform.inf\r
-  OvmfPkg/AmdSevDxe/AmdSevDxe.inf\r
+  OvmfPkg/AmdSevDxe/AmdSevDxe.inf {\r
+    <LibraryClasses>\r
+    PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  }\r
   OvmfPkg/IoMmuDxe/IoMmuDxe.inf\r
 \r
 !if $(SMM_REQUIRE) == TRUE\r
index 52f7598cf1c70a09a278e059d36850edd0b88e48..97b7cb40ff88ea5fd59a1af8f746f4d8c4f7153a 100644 (file)
 !endif\r
 \r
   OvmfPkg/PlatformDxe/Platform.inf\r
-  OvmfPkg/AmdSevDxe/AmdSevDxe.inf\r
+  OvmfPkg/AmdSevDxe/AmdSevDxe.inf {\r
+    <LibraryClasses>\r
+    PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  }\r
   OvmfPkg/IoMmuDxe/IoMmuDxe.inf\r
 \r
 !if $(SMM_REQUIRE) == TRUE\r
index a31519e356b77714fd879bb1e2eec2c37b8af19f..383cb03d2a14741b0430b117cba406a13a999021 100644 (file)
   }\r
 \r
   OvmfPkg/PlatformDxe/Platform.inf\r
-  OvmfPkg/AmdSevDxe/AmdSevDxe.inf\r
+  OvmfPkg/AmdSevDxe/AmdSevDxe.inf {\r
+    <LibraryClasses>\r
+    PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  }\r
   OvmfPkg/IoMmuDxe/IoMmuDxe.inf\r
 \r
   #\r