From nobody Sun Feb 8 12:51:50 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+88921+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+88921+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1649981259; cv=none; d=zohomail.com; s=zohoarc; b=EQBO7HXChYS9IRGc2OqYyK46bixBW4TbvGedN/Z8MRCHcJM/d+iS0VtlGYxSpgaxow3Ruv88dmEf7cGU8EnXXElNpHAZ+b0yyiKVfC23i29uOdKjy9AU4Mk91CN03RAGxddyHtjlmTfuW26TutQ1fUbs+WS8bvYDs2+qIp/lpm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649981259; 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=IxzPUsEpKuUkf9X9CzYFV/jlKG2TZeNBjBp4bLAdokg=; b=ee2lGgEfTeABA8QX2tRnihNVpTU18kd82yNrvJkqIGJa2uF2i1lDg3Ock6KnaaQNhjjNjkqOEZkD/vpRna1SqvK6xqa6NfdhICsEcSm5y1krB0CJ+UvjXqlL1HlIvH2zJOBzylCFRPngE6XgVXPo9AjG2DRlP2b9XGN3C2RjHRE= 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+88921+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 1649981259252708.4598684652693; Thu, 14 Apr 2022 17:07:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RLihYY1788612xklJDLNIR5Z; Thu, 14 Apr 2022 17:07:38 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> 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: va9ifDBPIYMGVHi0LucqlXIXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649981258; bh=Y/wyG3S4Fb7+efpApYGIVcPIk8E9vQf4efQEUZOgYq8=; h=Cc:Date:From:Reply-To:Subject:To; b=hwpdnmsnixtds/qDg/+4tZctO2BsDYkXM6eoJSrWvo2sh2z0OmLa7DaOoXUqYf6RA2G 20zdSKSk7blD7ueRnFKQEvdD43yiwaZOO4Y+gIMmKxTkm892BNx+fK+0jfgszcg1Dflay LfPFXOd9nRzBZM1TJgszJt6kYikXLJBNfE0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649981259730100015 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 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..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" =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 (#88921): https://edk2.groups.io/g/devel/message/88921 Mute This Topic: https://groups.io/mt/90477280/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-