From nobody Mon Feb 9 11:08:03 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+88975+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+88975+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1650164512; cv=none; d=zohomail.com; s=zohoarc; b=AB9w1QCsTjuRf8iwRmuGnLWyOygXWRd6NUw2yOc/Xal8JGkQws0vGVuthXQ8CH0jIHH5Zt6ciIyCvM7uBZ6qQ88UsuWaaJocHtevyzPTyWHZbOIEfeuKuRd8ogrveJHEHcwdIvc0I14R6fQWgsMeTXlklxB3xK0AZiKKaALI2tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650164512; 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=mdAe+lnwikSiIyiYhSgrJvDQs+bTw3fWMKoXwgWKb5s=; b=PgSjOOvRddJNOE2a61FVJWJ8STvXN6rKss3gjHXadWu3nHEh3a21voui1pd9bpuq/OQxfVltFos4EHL9iNEJLiNy5ya3Lc1ToPP5w3ZQlSf/ANmRbwhVj3OA3ABAtZwkUVo9rwJBPWvZYmeO+MzIlALEpZEf25nw9/SqCrLuLD0= 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+88975+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 1650164512360743.002325479438; Sat, 16 Apr 2022 20:01:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id i6nUYY1788612xS9CYlGn2Vu; Sat, 16 Apr 2022 20:01:52 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> 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: 7A47gbsE7R7hLe5nv28tjeBkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1650164512; bh=ux6jT+BTIVEbR2GE8u82U0VUEwgFsPmRPWNqAbTwhag=; h=Cc:Date:From:Reply-To:Subject:To; b=sy6SrX4rPyUyJvvfaa+Lbt0RjWhogU8TUuL278kTfItPzLKq9cp15uxfDFM9wxXyMiI ChL9Oc9usWGyiiwOoQptbf0JVawglnzwcsT30RClyMV8OMfOjgrulcQ47U56JCPwnCu4D Exaxl8NTshG8ZwdAFVsxWpXF8X47AQml4N4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1650164513759100010 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 (#88975): https://edk2.groups.io/g/devel/message/88975 Mute This Topic: https://groups.io/mt/90516978/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-