From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.25369.1650164497717213024 for ; Sat, 16 Apr 2022 20:01:51 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=OALYxrbB; spf=pass (domain: intel.com, ip: 192.55.52.43, 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=1650164511; x=1681700511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pae3XcV9zZWDpGnJyDd7UhY4W2EYjHhsDjGBhVJQVbI=; b=OALYxrbBX1J93XxTtuYIlC4Qr2QUcisaG9K1n7iYK8kfa6FhDrHot3sb Fka10puPgQod8sm7rmsHLIuwfvnT+ZhypbLTueiAviicyRK0+Mz3VSrDk 0gsR9eveWeaBoZrEevHqTOMbTrPi2+iV50ebB1XydlaWuJRmb/Pz106dV YA0Ad1PNaycqruj/jdi8u/Oyth+GUSqpOSpm9Yyavyas26exSe0ZLOTsE HiejwoIcK8pt4rrxrI9G2LeBlC2GYT+nUtdHNCf073ki7yLmEIGcHbsxY 6EeL8tvox/J9Z+958p/z06h8K0s37oJTMJq/CqK3YJOjH3cQ2NlxaGEwV Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10318"; a="349806289" X-IronPort-AV: E=Sophos;i="5.90,266,1643702400"; d="scan'208";a="349806289" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2022 20:01:50 -0700 X-IronPort-AV: E=Sophos;i="5.90,266,1643702400"; d="scan'208";a="575044378" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.191]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2022 20:01:48 -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 V3 6/7] MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev Date: Sun, 17 Apr 2022 11:01:12 +0800 Message-Id: <691f7730593f6eec692344fb0c59afb31c343c6c.1650163941.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