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.6263.1661821454207048478 for ; Mon, 29 Aug 2022 18:04:14 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kbaBq6f8; spf=permerror, err=too many SPF records (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=1661821454; x=1693357454; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ubpx51wEa3sapn2d1eGaJC4r2HSLVwY3z3cqDemVk2Y=; b=kbaBq6f8VZUMXzs6MtmXcZRzlZ0gqFQMmIUuTGmEpjmUWpSymKElmbzw YQgnwVv68XQLMJyup8gWvVvxKFgv8FU8eFb7RSgA8HRA1l978tjoCvu7k X6rkUKGe/8tx6bjbFrJyWqsoanJHhMGqghh0Un+3REJfzgIdMZX1+3V40 XctLY+l7vII3EMW8Rc08QHkeurca+K1inBeTiTkDZWV34sYL6S7CWF8CP 5jiKF5OsZUMv0M5xHDUkeTWy5Vqu/r8Pb2nAbFDg5159dPuDHMqmA8Ale VIRZJp6wR2Cx26mJ0Mbu+kqSQkCEFA/KNVAL5NFbNjkGZ3vWNzQIqWuqP A==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="274794049" X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="274794049" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 18:03:53 -0700 X-IronPort-AV: E=Sophos;i="5.93,273,1654585200"; d="scan'208";a="672612240" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.4.200]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 18:03:51 -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 V5 0/2] Re-design CcProbeLib Date: Tue, 30 Aug 2022 09:03:38 +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 variable. Global variable cannot be used in SEC/PEI and CcProbe is called very frequently. Code: https://github.com/mxu9/edk2/tree/CcProbeLib.BZ3974.v4 v5 changes: - Fix typos in commit message. - No other changes in code. 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 Acked: Gerd Hoffmann 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