From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.4082.1649840922150046074 for ; Wed, 13 Apr 2022 02:08:47 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=YrInrk7R; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1649840927; x=1681376927; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lXFGL0U8nPU/aEIXPGCaTzCES/sw8mPspSL76XnAaXA=; b=YrInrk7R5jX5VXpGFyKHUgMRSanqrpYVvC8GdNwmalrfLfL9C7icraTu lXVaasaboUf2/gTA7Z47ja5h8+aLzg/YYQPGbAykKdAnRfDAwsDsPF6KL d0Xykq4W+5vapVg3mb7RFgKTvmlFRdY/34AF2FAPmIE2Ajx7PedeetqS1 CWLA3BWZDkUtAKAw9qLcI5zxDEF/YBOD/9OOIUUhJkdD8opjaNy2S4eqX DLvfx957Y9b+0S0fdIxeua1HHXEmjwAi6XAnCE2g0Ukh3++Sc9kwq3rgf 0IemKq64RsDGHj1ru8uhW+7X+vrwszDX946H9iL2KDlHLhUAnHAxn+aPk A==; X-IronPort-AV: E=McAfee;i="6400,9594,10315"; a="242551965" X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="242551965" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 02:08:46 -0700 X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="573183443" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.28.56]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 02:08:44 -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 3/4] MdePkg: Probe Td guest in BaseIoLibIntrinsicSev Date: Wed, 13 Apr 2022 17:08:23 +0800 Message-Id: <1326dd74e9c143cbc0d4f95b7e2b165f253e02c6.1649840073.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 TdProbe instead of IsTdxGuest. Null instance of TdProbe returns TD_PROBE_NON anyway. Its OvmfPkg version checks the Ovmf work area to determine the Td guest type. 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..76f11438f40b 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf @@ -55,6 +55,7 @@ DebugLib BaseLib RegisterFilterLib + TdProbeLib [LibraryClasses.X64] TdxLib diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c index 1e539dbfbbad..9aed9f312858 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 TdProbe () == TD_PROBE_TDX; } /** -- 2.29.2.windows.2