From nobody Mon Feb 9 07:26:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+89035+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89035+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1650328020; cv=none; d=zohomail.com; s=zohoarc; b=dJMIGN2R7gCifxDYFIcgdffAUsjIL3qTDRqPp7PPCkCGLR34VQ7Vf+3oQY67+Ax7jj9iIQ/+Ei0cyReYavSeJZm8p15B+GfzNpRRAL/8rE3rbDhzZT0BPDEDQ8piLrogupsFVKVrw0LMpLj/vFKXKazsofRjoNeNfMU9Pgpn1QI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650328019; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=iEz+JxnFjyS93QdvSaOIhIpAFVLbTw4C53oruI0BG5Y=; b=B3VIqhE440JPMvFVPihfX4ot9UYesgNxQIBZ1aknPbmfnsV7jJn2oKxHWo2eQYqufg8qK1XWOIp8Ddncq8EdWBRz36Y+qd6FVwg9SixRFPUIqqAySRyjaKfBAAyVlpdS57XTLm5nJbF7HxV6eQoLObmcDILOfYUzyH06P8SKZK8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89035+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1650328019995932.3152158579032; Mon, 18 Apr 2022 17:26:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gJiWYY1788612x9vFx7i5g3j; Mon, 18 Apr 2022 17:26:59 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: PrhwPcr6bEK4EwffeOqFaFrex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1650328019; bh=PuE2Mj+9MNLCkA+Fi7qzsJshSEF+u6qn7Z4p+RhFZC4=; h=Cc:Date:From:Reply-To:Subject:To; b=pzdzM2b49Z7WaZsKfFP02ZLo9O8X8hcI4fswoZ6pHdxlIH7djb/w1TVtpycC6xbvDR4 Yq3LGRjhpPWyAFRzz70W1AJNSLP2Cy3vUJnQOgiS+r/BoSXbpk2HaYgOhADuQVX5yfs7q DxD2tscguOncnTuvpHISwDMcxb6xTcuEdHY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1650328020406100025 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3902 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 =20 [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" =20 // Size of TDVMCALL Access, including IO and MMIO @@ -22,9 +23,6 @@ #define TDVMCALL_ACCESS_READ 0 #define TDVMCALL_ACCESS_WRITE 1 =20 -BOOLEAN mTdxEnabled =3D FALSE; -BOOLEAN mTdxProbed =3D FALSE; - /** Check if it is Tdx guest. =20 @@ -38,14 +36,7 @@ IsTdxGuest ( VOID ) { - if (mTdxProbed) { - return mTdxEnabled; - } - - mTdxEnabled =3D TdIsEnabled (); - mTdxProbed =3D TRUE; - - return mTdxEnabled; + return CcProbe () =3D=3D CcGuestTypeIntelTdx; } =20 /** --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#89035): https://edk2.groups.io/g/devel/message/89035 Mute This Topic: https://groups.io/mt/90552658/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-