]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev
authorMin Xu <min.m.xu@intel.com>
Tue, 19 Apr 2022 00:26:27 +0000 (08:26 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 19 Apr 2022 01:26:08 +0000 (01:26 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3902

Bad IO performance in SEC phase is observed after TDX features was
introduced. (after commit b6b2de884864 - "MdePkg: Support mmio for
Tdx guest in BaseIoLibIntrinsic").

This is because IsTdxGuest() will be called in each MMIO operation.
It is trying to cache the result of the probe in the efi data segment.
However, that doesn't work in SEC, because the data segment is read only
(so the write seems to succeed but a read will always return the
original value), leading to us calling TdIsEnabled() check for every
mmio we do, which is causing the slowdown because it's very expensive.

This patch is to call CcProbe instead of TdIsEnabled in IsTdxGuest.
Null instance of CcProbe always returns CCGuestTypeNonEncrypted. Its
OvmfPkg version returns the guest type in Ovmf work area.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c

index 7fe1c60f046e2740ed24283c9819d3346ed900ca..e1b8298ac4513c959fe0c18e6ce8d8bd6228654c 100644 (file)
@@ -55,6 +55,7 @@
   DebugLib\r
   BaseLib\r
   RegisterFilterLib\r
+  CcProbeLib\r
 \r
 [LibraryClasses.X64]\r
   TdxLib\r
index 1e539dbfbbade1de7c9ef583483ff11d47a12acc..ec837f5eb03e78ae64ce180280196bff656d6ce2 100644 (file)
@@ -10,6 +10,7 @@
 #include <Include/IndustryStandard/Tdx.h>\r
 #include <Library/TdxLib.h>\r
 #include <Register/Intel/Cpuid.h>\r
+#include <Library/CcProbeLib.h>\r
 #include "IoLibTdx.h"\r
 \r
 // Size of TDVMCALL Access, including IO and MMIO\r
@@ -22,9 +23,6 @@
 #define TDVMCALL_ACCESS_READ   0\r
 #define TDVMCALL_ACCESS_WRITE  1\r
 \r
-BOOLEAN  mTdxEnabled = FALSE;\r
-BOOLEAN  mTdxProbed  = FALSE;\r
-\r
 /**\r
   Check if it is Tdx guest.\r
 \r
@@ -38,14 +36,7 @@ IsTdxGuest (
   VOID\r
   )\r
 {\r
-  if (mTdxProbed) {\r
-    return mTdxEnabled;\r
-  }\r
-\r
-  mTdxEnabled = TdIsEnabled ();\r
-  mTdxProbed  = TRUE;\r
-\r
-  return mTdxEnabled;\r
+  return CcProbe () == CcGuestTypeIntelTdx;\r
 }\r
 \r
 /**\r