I'm using a SEC phase which has a TPM driver to experiment with sorting
out measured boot, which is how I noticed (usually SEC doesn't do MMIO)
.  What I'm seeing is after commit b6b2de884864 ("MdePkg: Support mmio
for Tdx guest in BaseIoLibIntrinsic") we get a massive slowdown of
about 100x in TPM performance.  The reason seems to be this addition to
the mmioreadX/mmiowriteX code:

     MemoryFence ();
-    *(volatile UINT16 *)Address = Value;
+
+    if (IsTdxGuest ()) {
+      TdMmioWrite16 (Address, Value);
+    } else {
+      *(volatile UINT16 *)Address = Value;
+    }
+
     MemoryFence ();


The problem is that IsTdxGuest () has this structure:

BOOLEAN
EFIAPI
IsTdxGuest (
  VOID
  )
{
  if (mTdxProbed) {
    return mTdxEnabled;
  }

  mTdxEnabled = TdIsEnabled ();
  mTdxProbed  = TRUE;

  return mTdxEnabled;
}

Which 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.

James




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88800): https://edk2.groups.io/g/devel/message/88800
Mute This Topic: https://groups.io/mt/90427994/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to