From mboxrd@z Thu Jan 1 00:00:00 1970 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:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=c2gbQC6n; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1649981244; x=1681517244; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uHKdqd90sXLWv2Wxi8P9KFvG5Un8zdxEEpszNLUD6K4=; b=c2gbQC6n1zJQ9XBJuupqzlArZKl2m3euV63BDuqUruZTIJyqvmxPr5bq ssLPv4LMg6lrd0WRqI5P3m5pY1R+WUgPp3uAHYKtOcg/rbDQe7mBdRFEk B5PK1cvBfqgb1a7DIU2Ce5aZCHqnytNOXoNrJKUyp0Guiwu3f41M8avt/ +dqm6Uq3E7XGDytG0ejTH84822YUsR5XrG9wdlHBHxXM+xK46ECPkG4Nb s7ORyxGIUgGpprlGPMIcLmvvIAPBkRFEyCE92ME2lWB5SObN/m9mUsIy4 CtjG+6ioE69jEKDyvh4rjJtjDy9JcszJ0aLFcKscturUdrb+QtRSz+nuq Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10317"; a="262504525" X-IronPort-AV: E=Sophos;i="5.90,261,1643702400"; d="scan'208";a="262504525" 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:23 -0700 X-IronPort-AV: E=Sophos;i="5.90,261,1643702400"; d="scan'208";a="552923248" 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:20 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , James Bottomley , Jiewen Yao , Gerd Hoffmann , Brijesh Singh , Erdem Aktas , Tom Lendacky Subject: [PATCH V2 0/6] Introduce CcProbe in MdePkg Date: Fri, 15 Apr 2022 08:07:03 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 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. CcProbe is introduced in this patch-set. It is called in BaseIoLibIntrinsicSev instead of IsTdxGuest. There are 2 versions of the CcProbeLib. Null instance of CcProbe always returns CCGuestTypeNonEncrypted. Its OvmfPkg version checks the Ovmf work area and returns the CC guest type. Code is at: https://github.com/mxu9/edk2/tree/cc_probe.v2 v2 changes: - Rename TdProbe to CcProbe to make the lib work for Confidential Computing guests. - Rename the GUEST_TYPE to CC_GUEST_TYPE and move it from WorkArea.h@OvmfPkg to ConfidentialComputingGuestAttr.h@MdePkg. This is because CcProbeLib is designed to return the CC Guest type and the lib is located at MdePkg. - Rename the CC_GUEST_TYPE's fields name to Camel style. See the commit message in patch #1. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Brijesh Singh Cc: Erdem Aktas Cc: Tom Lendacky Signed-off-by: Min Xu Min Xu (6): MdePkg: Add CC_GUEST_TYPE in ConfidentialComputingGuestAttr.h OvmfPkg: Replace GUEST_TYPE with CC_GUEST_TYPE MdePkg: Add CcProbeLib OvmfPkg: Add CcProbeLib MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev OvmfPkg: Add CcProbeLib in *.dsc .../Include/ConfidentialComputingGuestAttr.h | 11 ++++++- MdePkg/Include/Library/CcProbeLib.h | 26 ++++++++++++++++ .../BaseIoLibIntrinsicSev.inf | 1 + .../BaseIoLibIntrinsic/IoLibInternalTdx.c | 13 ++------ .../Library/CcProbeLibNull/CcProbeLibNull.c | 26 ++++++++++++++++ .../Library/CcProbeLibNull/CcProbeLibNull.inf | 21 +++++++++++++ MdePkg/MdePkg.dec | 5 +++ MdePkg/MdePkg.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Include/WorkArea.h | 9 +----- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + .../PeiMemEncryptSevLibInternal.c | 2 +- .../SecMemEncryptSevLibInternal.c | 2 +- OvmfPkg/Library/CcProbeLib/CcProbeLib.c | 31 +++++++++++++++++++ OvmfPkg/Library/CcProbeLib/CcProbeLib.inf | 25 +++++++++++++++ OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c | 2 +- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + OvmfPkg/Sec/AmdSev.c | 2 +- 24 files changed, 162 insertions(+), 24 deletions(-) create mode 100644 MdePkg/Include/Library/CcProbeLib.h create mode 100644 MdePkg/Library/CcProbeLibNull/CcProbeLibNull.c create mode 100644 MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf create mode 100644 OvmfPkg/Library/CcProbeLib/CcProbeLib.c create mode 100644 OvmfPkg/Library/CcProbeLib/CcProbeLib.inf -- 2.29.2.windows.2