From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.4082.1649840922150046074 for ; Wed, 13 Apr 2022 02:08:42 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kfQaLrgU; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1649840922; x=1681376922; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=47pRXt+GAN1KqGSlhlVJ0flXPyptjCDICLdbxZfmR6M=; b=kfQaLrgUDCswdElputT6F9+pgZg7jwd+rnxRg6SHd17X2UViqGn3MQei h+pTYhc4qjVMYCj9FAXoOYrPKsIEuhLyKOuP0z0BrxKx193a+fAwSHG2h fd+T8EK57Nz07Ldh9OYkXsLe4cJb9vyCWpCIxQtvtcsF9QA6n6zx7naD7 OTMUz1ZHjuLGEtvl88RzbDMZFrza6z0N0cFsfsH2R1Gn3rY5hP8m+lcvK 8EFcddEVv3jH76uqeOwabCzOSz1N/FeawmShaK29KWfS2on61CrEwpBLE NAxh38pLd99OROBJMiCjlIjjrYvr80oAhfbf5Fpw5QKpcQt2PjeOOCTpP Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10315"; a="242551903" X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="242551903" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 02:08:39 -0700 X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="573183397" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.28.56]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 02:08:36 -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 , Brijesh Singh , Erdem Aktas , Tom Lendacky Subject: [PATCH 0/4] Introduce TdProbe in MdePkg Date: Wed, 13 Apr 2022 17:08:20 +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. TdProbe is introduced in this patch-set. It is called in BaseIoLibIntrinsicSev instead of IsTdxGuest. There are 2 versions of the TdProbeLib. Null instance of TdProbe always returns TD_PROBE_NON. Its OvmfPkg version checks the Ovmf work area to determine the Td guest type. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: James Bottomley 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 (4): MdePkg: Add TdProbeLib OvmfPkg/IntelTdx: Add TdProbeLib MdePkg: Probe Td guest in BaseIoLibIntrinsicSev OvmfPkg: Add TdProbeLib in *.dsc MdePkg/Include/Library/TdProbeLib.h | 26 +++++++++++++ .../BaseIoLibIntrinsicSev.inf | 1 + .../BaseIoLibIntrinsic/IoLibInternalTdx.c | 13 +------ .../Library/TdProbeLibNull/TdProbeLibNull.c | 25 ++++++++++++ .../Library/TdProbeLibNull/TdProbeLibNull.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/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/IntelTdx/TdProbeLib/TdProbeLib.c | 38 +++++++++++++++++++ OvmfPkg/IntelTdx/TdProbeLib/TdProbeLib.inf | 25 ++++++++++++ OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 18 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 MdePkg/Include/Library/TdProbeLib.h create mode 100644 MdePkg/Library/TdProbeLibNull/TdProbeLibNull.c create mode 100644 MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf create mode 100644 OvmfPkg/IntelTdx/TdProbeLib/TdProbeLib.c create mode 100644 OvmfPkg/IntelTdx/TdProbeLib/TdProbeLib.inf -- 2.29.2.windows.2