From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web08.3858.1650328002343868729 for ; Mon, 18 Apr 2022 17:26:58 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Lt3HN6kt; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650328018; x=1681864018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hty9OYsG6JXuJ1WV2qYJNfuNLAu/PnN4XsRrX0Nw6ew=; b=Lt3HN6ktxEPmipG91cnme0VDr8QmiyI0SlhSD59+1d8pna3KlF42d4W1 QqloiVDOigJpKrq8iK3dF+i3wTJg50fvF3/WiEtEBD+FTbcJEQO/vyCtU /st/gIXqHGCTMUYMgOFxbbZwzFDwaICA8YvHPF0EyJ44TB7wZDZhqyPun YysmvW6HvUe3Xd3di7aPK+jnudpBWfkvvjLahkjcPw+Xgw7LteiLatpft TLuTYE1Czarvi+pz7m4a4nCPqU8i39ufQXEK4pnttUwfC3ovKauI55R3E r2PDvnMfYFyZjgsbOXkIOWR6OizDwJPG0ApCPZ1drXgKk5ZpZtEDp1gWY Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10321"; a="326540411" X-IronPort-AV: E=Sophos;i="5.90,271,1643702400"; d="scan'208";a="326540411" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 17:26:58 -0700 X-IronPort-AV: E=Sophos;i="5.90,271,1643702400"; d="scan'208";a="529080074" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.171.121]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 17:26:55 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , James Bottomley , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [PATCH V4 6/7] MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev Date: Tue, 19 Apr 2022 08:26:27 +0800 Message-Id: <1cc7e25b9bd4ca58f3e6014324327a1dac5420b5.1650326140.git.min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Cc: Zhiguang Liu Cc: James Bottomley Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Reviewed-by: Liming Gao Reviewed-by: Jiewen Yao Reviewed-by: Tom Lendacky Signed-off-by: Min Xu --- .../BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf | 1 + .../Library/BaseIoLibIntrinsic/IoLibInternalTdx.c | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf index 7fe1c60f046e..e1b8298ac451 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf @@ -55,6 +55,7 @@ DebugLib BaseLib RegisterFilterLib + CcProbeLib [LibraryClasses.X64] TdxLib diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c index 1e539dbfbbad..ec837f5eb03e 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "IoLibTdx.h" // Size of TDVMCALL Access, including IO and MMIO @@ -22,9 +23,6 @@ #define TDVMCALL_ACCESS_READ 0 #define TDVMCALL_ACCESS_WRITE 1 -BOOLEAN mTdxEnabled = FALSE; -BOOLEAN mTdxProbed = FALSE; - /** Check if it is Tdx guest. @@ -38,14 +36,7 @@ IsTdxGuest ( VOID ) { - if (mTdxProbed) { - return mTdxEnabled; - } - - mTdxEnabled = TdIsEnabled (); - mTdxProbed = TRUE; - - return mTdxEnabled; + return CcProbe () == CcGuestTypeIntelTdx; } /** -- 2.29.2.windows.2