From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.1927.1649981244283090489 for ; Thu, 14 Apr 2022 17:07:38 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Cg5mJOIl; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1649981258; x=1681517258; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pae3XcV9zZWDpGnJyDd7UhY4W2EYjHhsDjGBhVJQVbI=; b=Cg5mJOIlPFMvd238p/79XYZFngkOe/7hGqJ87HX53fT8GalnTuZB/Icm 3isbG4+Hey/GKes/QEHBFWyacgbtiLE8g4XQtBmz6zW7BmP8N8W+sAwus hdd+/qQDQn4JAaH7e6f24zVvVJo+2Hz9SsTcWSdSv4CYa8eX1ZoZBtC3s 2IufB3j+yU+hTpSy90SGL3mt9hkqP0FUeT+XwSOciqZMfekZDUQmilrVc UNk8zH5z1LOxMhMYOJPgZuEramPMy9gYwqTW20BS1K38HIRU/d1+f2hDW 1YittKh4idaqbfYpC9+I928/vymGC09rZypkvw2ulAgz6IOZOF/WMGex0 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10317"; a="262504608" X-IronPort-AV: E=Sophos;i="5.90,261,1643702400"; d="scan'208";a="262504608" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2022 17:07:37 -0700 X-IronPort-AV: E=Sophos;i="5.90,261,1643702400"; d="scan'208";a="552923336" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.168.38]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2022 17:07:35 -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 Subject: [PATCH V2 5/6] MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev Date: Fri, 15 Apr 2022 08:07:08 +0800 Message-Id: <7af1cd76cb8b4684bbff0de2ab2dafa9b43d5d9f.1649980548.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 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..8af6fc35c591 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