From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.43533.1661555241015452748 for ; Fri, 26 Aug 2022 16:07:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Pii08gQu; spf=pass (domain: intel.com, ip: 134.134.136.20, 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=1661555241; x=1693091241; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2GczHyU6UPiwhgs48UFbPI8M+kc49kuP3YmuVVPXoSs=; b=Pii08gQuhjLWezlP7Urp1QFt9899NgHc9Jt3HZu5mrNPs3d5JU9LMj+6 1h2SxhcOFvkxfPTKgHtz4XHZV5wm7Izxh1KfyNr3JpoVzjxGGx92FL10E at+l3IKM/S3gp2W+4nch38irT7mCqxdnKev+b3+UXIJuGEGuNMvONVIsI S2xLqg5vL2A/JV7rjEvLpQ3TJr7rKQGPF/I2N/OZE/l7iH8zqYyLQt7TX jdrOJmAkRafBd1I5hkBzTYRO1EfYM0PrI0axTYRK7Jbbi73bZOwZGmwpf 3uA1sT4ZBqw61oV+kOX2mPwdBy6vD+/7IgntY+GnA/7DjTsHzC2snh29+ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="281579426" X-IronPort-AV: E=Sophos;i="5.93,266,1654585200"; d="scan'208";a="281579426" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 16:07:20 -0700 X-IronPort-AV: E=Sophos;i="5.93,266,1654585200"; d="scan'208";a="671649408" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.171.119]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 16:07:18 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Gerd Hoffmann , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Yuan Yu Subject: [PATCH V4 0/2] Re-design CcProbeLib Date: Sat, 27 Aug 2022 07:07:06 +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=3974 CcProbeLib once was designed to probe the Confidential Computing guest type by checking the PcdOvmfWorkArea. But this memory is allocated with either EfiACPIMemoryNVS or EfiBootServicesData. It cannot be accessed after ExitBootService. Please see the detailed analysis in BZ#3974. To fix this issue, CcProbeLib is re-designed as 2 implementation: - SecPeiCcProbeLib - DxeCcProbeLib In SecPeiCcProbeLib we check the CC guest type by reading the PcdOvmfWorkArea. Because it is used in SEC / PEI and we don't worry about the issues in BZ#3974. In DxeCcProbeLib we cache the GuestType in Ovmf work area in a global variable. After that the Guest type is returned with the cached value. So that we don't need to worry about the access to Ovmf work area after ExitBootService. The reason why we probe CC guest type in 2 different ways is the global varialbe. Global variable cannot be used in SEC/PEI and CcProbe is called very frequently. Code: https://github.com/mxu9/edk2/tree/CcProbeLib.BZ3974.v4 v4 changes: - Read Cc guest type in both DxeCcProbeLib's constructor and CcProbe. So that we guarantee the Cc guest type is read early enough. v3 changes: - Re-design CcProbeLib to 2 implementation: SecPeiCcProbeLib and DxeCcProbeLib. The difference between the 2 implementation is the cache of the CcGuestType. v2 changes: - Reserve Ovmf work-area as RT_DATA. See https://edk2.groups.io/g/devel/message/92599 Cc: Gerd Hoffmann Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Yuan Yu Signed-off-by: Min Xu Min M Xu (2): OvmfPkg: Add SecPeiCcProbeLib OvmfPkg: Update CcProbeLib to DxeCcProbeLib OvmfPkg/IntelTdx/IntelTdxX64.dsc | 3 +- OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c | 68 +++++++++++++++++++ OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf | 26 +++++++ .../{CcProbeLib.c => SecPeiCcProbeLib.c} | 0 .../{CcProbeLib.inf => SecPeiCcProbeLib.inf} | 8 +-- OvmfPkg/OvmfPkgX64.dsc | 5 +- 6 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c create mode 100644 OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf rename OvmfPkg/Library/CcProbeLib/{CcProbeLib.c => SecPeiCcProbeLib.c} (100%) rename OvmfPkg/Library/CcProbeLib/{CcProbeLib.inf => SecPeiCcProbeLib.inf} (65%) -- 2.29.2.windows.2