From nobody Sun May 19 19:10:23 2024 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+92880+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+92880+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581335; cv=none; d=zohomail.com; s=zohoarc; b=jMkDYKGMzEZYtKuevQN//V+tV+SWCNggZ7j6ftjDGYXZ+5hTNITtH6GoUtbZJTuUEWnC5H81B40dFL01TVx9yiedO1DFiFmMo/v2oPGHeMud7U16GKyZr2QBkWaVZHkmDfx9wfaNz7rOV5NcVvdykQmz1+4jQGQ3wfw5+iO+d9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581335; 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=u/TcR+fkwfxNLSq8QyQxNLSYi2wn144XXFEVMmPP+2E=; b=TXFZC8lW4upIpMHzgfdo4cOh/YfWBIr3iwyMn76SYA+GJhPHUyOXvVRmbuak9DLpnq7swZ9xsHLOepjoC3j4QSh9c6nCow4GR6e3mi4kc7f24FViRmTJdID2MfuG8y0M/doEPiR1g+fBfhmQyInHgPvYZkijFqjBQc/6Z96LdkU= 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+92880+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 1661581335813301.677044501017; Fri, 26 Aug 2022 23:22:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iCdUYY1788612xWjIhNUCB1A; Fri, 26 Aug 2022 23:22:15 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:14 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355784" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355784" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:14 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738700" X-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 23:22:12 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Jian J Wang , Liming Gao , Ray Ni , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 01/14] MdeModulePkg: Add PrePiHob.h Date: Sat, 27 Aug 2022 14:21:08 +0800 Message-Id: <46718f8e631711ce83f7db30cc6d6290a325f899.1661579220.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: HpOhvG4CuzszGVQVax6fjpddx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581335; bh=oUb7Ocav+mzJfD6ZS6usKVA0dl5JbArHT61NIEJRl4Q=; h=Cc:Date:From:Reply-To:Subject:To; b=qCefMLLbODFmww7lxQ9FWmPSz7nfLKkmo1FPPtt5OnVg9xWvi2vpChC/oYbb9jyehy6 ZCLiV/12Ttrm8D+Gnn3C7hc26T56xP5LWzCc35t4tP7SZMa+wt+93Dgyb8T1k1rDQ1s8Q x2+Vlr5ycKlUVusT6Rdqm9cgy9JRIBIhGHg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581337101100007 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory. But this defitinion has not been officially in the PI spec. Base on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at MdeModulePkg/Include/Pi/PrePiHob.h. Cc: Jian J Wang Cc: Liming Gao Cc: Ray Ni Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- MdeModulePkg/Include/Pi/PrePiHob.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h diff --git a/MdeModulePkg/Include/Pi/PrePiHob.h b/MdeModulePkg/Include/Pi/P= rePiHob.h new file mode 100644 index 000000000000..38a8f1be149d --- /dev/null +++ b/MdeModulePkg/Include/Pi/PrePiHob.h @@ -0,0 +1,20 @@ +/** @file + HOB related definitions which has not been officially published in PI. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MDE_MODULEPKG_PRE_PI_HOB_H_ +#define MDE_MODULEPKG_PRE_PI_HOB_H_ + +// +// EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory. +// But this defitinion has not been officially in the PI spec. Base +// on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at +// MdeModulePkg/Include/Pi/PrePiHob.h. +// +#define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007 + +#endif --=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 (#92880): https://edk2.groups.io/g/devel/message/92880 Mute This Topic: https://groups.io/mt/93285598/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- From nobody Sun May 19 19:10:23 2024 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+92881+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+92881+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581338; cv=none; d=zohomail.com; s=zohoarc; b=n0duK1B+kE8gwKrCHunFY5wXpV4Ei5dRe6/7q0mi/lhlDrgEDpuTLG9NQSoXg0UZLT1QySAEEFdEt6Mg3jVspyuqgKs85eUJEnA+hZT8kAKAKdBuPO3JKBbvRKH1ULiJ9SdgTkNpG2XUP9rigx9N1UAtgQvDqyv+MOPXCEKzDoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581338; 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=oquwRJ9NOxPK6FOzMz+k0ccF2rLVslyXHo45fXxyI3o=; b=gWyb/Wu00N3NgA37DMjI1hxcXuEOPjQsFuXbOs1G1zBYiy37vt4opccQsZOvpINhKeRqvM3VRJoFP+d4br6fiRF2JyZCDnhh7jY+mVPiC/pn+YYq2C0K+v1lpowUmFB2Y+3KjBJKEh4TQ8tKAUivU0eYII1xOrxqUqW3bODVPHk= 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+92881+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 1661581338330852.4222179226564; Fri, 26 Aug 2022 23:22:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aauVYY1788612xwOidOOkvMN; Fri, 26 Aug 2022 23:22:18 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:17 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355790" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355790" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:17 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738712" X-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 23:22:14 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 02/14] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Date: Sat, 27 Aug 2022 14:21:09 +0800 Message-Id: <45e1ef46d658cba4f0ff751079fe89321e2eee25.1661579220.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: JQoY4CPjtrDF43IKGB5dRhbdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581338; bh=NrYb4NEhrv/NOeF8oTATIidqUv4IOr1du4MsBR5zmRQ=; h=Cc:Date:From:Reply-To:Subject:To; b=Is9WGcBDVUNNX6o5tsNa4GdnyqH2UxwqNgXp32Y2sJ8TGTeBobxR6k7wd/Kim/tg+Ff uBmWSzynB9Dd6lnrwFn8OIiB1eiNyhn+7lbeENBkbyQBxbtHm4L0GIWBcKNZLnnzqd1Iv X6SzWcEwtLhAsse1wxYDO1rYSl7y5wyK/Mc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581339119100009 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory. But this defitinion has not been officially in the PI spec. Base on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE to 8. After EFI_RESOURCE_MEMORY_UNACCEPTED is officially published in PI spec, we will re-visit here. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Reviewed-by: Jiewen Yao Signed-off-by: Min Xu --- MdePkg/Include/Pi/PiHob.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/MdePkg/Include/Pi/PiHob.h b/MdePkg/Include/Pi/PiHob.h index e9f0ab4309d1..9af2e957fee5 100644 --- a/MdePkg/Include/Pi/PiHob.h +++ b/MdePkg/Include/Pi/PiHob.h @@ -232,7 +232,16 @@ typedef UINT32 EFI_RESOURCE_TYPE; #define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT 0x00000004 #define EFI_RESOURCE_MEMORY_RESERVED 0x00000005 #define EFI_RESOURCE_IO_RESERVED 0x00000006 -#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000007 +// +// EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory. +// But this defitinion has not been officially in the PI spec. Base +// on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at +// MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_T= YPE +// to 8. After EFI_RESOURCE_MEMORY_UNACCEPTED is officially published +// in PI spec, we will re-visit here. +// +// #define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007 +#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000008 =20 /// /// A type of recount attribute type. --=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 (#92881): https://edk2.groups.io/g/devel/message/92881 Mute This Topic: https://groups.io/mt/93285599/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- From nobody Sun May 19 19:10:23 2024 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+92882+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+92882+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581340; cv=none; d=zohomail.com; s=zohoarc; b=ATgsJbglOPys3ZA6Zy9gOuRWpH2OFys7gyG9ugT3NP1vBTGJYhIm9/ly4p60eQSOelPE+gklG+ZICv5ozoUGhh6skgnCgK+5ImocIdSEA3U9dkuOYiCuNURNFB7kqUGjVlRstQqOUD1IUMuvHryAPOreH8f7Mgv2qP1A/udKZgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581340; 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=pp1hjquiz6DcT3uCEe/KSAKw78ION5jsNrOHA9OFSZo=; b=KgU7oNqoaS3icbcK7njM6vNJ1Fw+a4D6OJVLfP1C+ECjmXUjJbta9GuhrK7tvaxTQmegsoMoLX3DM+e8QOGKvEzc/Ij7Ry9OdxCyom93XJbN4EurouPOj881ufYZaRPRKgfjDe8IV7Tvk40jtemlobGByxccVlA4YmuCLiZeVi8= 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+92882+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 1661581340163600.2620278799584; Fri, 26 Aug 2022 23:22:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CA16YY1788612xGZ5B5WjBgc; Fri, 26 Aug 2022 23:22:19 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:19 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355791" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355791" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:18 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738720" X-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 23:22:17 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 03/14] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg Date: Sat, 27 Aug 2022 14:21:10 +0800 Message-Id: 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: IHVcfU7r22hfdgsal9WvFsolx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581339; bh=hIWRSSwaY8Ai4PU3M+LDDF+ns2K5K2p51qyUdA0reRo=; h=Cc:Date:From:Reply-To:Subject:To; b=Ml5Umg5zQVUMO663exmiL0wzTKF8ot4lYDllbLhru8NrIwY++y2DyDHAFJP9Rk8hXbX 7/fk4IEAraX0RZ+49a20hnY8oWHAoAGrnjNEAtraLCYnyfKUB79v8SpHPiPWOZy7Z2Zb1 B9rXIcGlAoa6eWB7uiG6c/UW5MAKns5PTLY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581341301100015 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 EFI_RESOURCE_MEMORY_UNACCEPTED is defined in MdeModulePkg. The files which use the definition are updated as well. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Library/PeilessStartupLib/Hob.c | 3 +-- OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/Peil= essStartupLib/Hob.c index 5fc84a809025..a9b92b5fbaba 100644 --- a/OvmfPkg/Library/PeilessStartupLib/Hob.c +++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c @@ -20,10 +20,9 @@ #include #include #include +#include #include "PeilessStartupInternal.h" =20 -#define EFI_RESOURCE_MEMORY_UNACCEPTED 7 - /** * Construct the HobList in SEC phase. * diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/P= latformInitLib/IntelTdx.c index c6d7c8bb6e0e..396b14d919d2 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -20,11 +20,11 @@ #include #include #include +#include #include #include =20 #define ALIGNED_2MB_MASK 0x1fffff -#define EFI_RESOURCE_MEMORY_UNACCEPTED 7 =20 /** This function will be called to accept pages. Only BSP accepts pages. --=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 (#92882): https://edk2.groups.io/g/devel/message/92882 Mute This Topic: https://groups.io/mt/93285600/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- From nobody Sun May 19 19:10:23 2024 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+92883+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+92883+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581342; cv=none; d=zohomail.com; s=zohoarc; b=UWtNDHVQJUe6OPl//TViL9SMMb3VLiiwVmzUS+QZS0/f43dxCYyQrrGWElO2RyriePfRNjSw6ZZKOm/9HAWa5qqd3HAJGGMez3YdGh9X9tBy5PqAY1fnxfcIWxyO6YQj2oulSKiz8GaEID20S9is3uSgizft/IFkejRdI/O1/Pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581342; 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=r/8jco5biThRi8J3gih+h0JivHLgT0v5u5M6+7Lr5H4=; b=ePfd/IO51c/b2Gi55z0zSMHs1Go+ZoBfctSWkObCGyWlz2RRvPFfz29qiN9wVb1SVFYCRs0oQYcaVpgF9I44KU7DrFmc0/6bBF2IhonLefZfq0djgYG8uFScsK8cDIv1qZ7CmnAwZPwYrAncmxVT28K2WPEBJ1j1/Uh8b8adNWE= 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+92883+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 1661581342723293.14738830282863; Fri, 26 Aug 2022 23:22:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EIA9YY1788612x1pc5aJtdJ6; Fri, 26 Aug 2022 23:22:22 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355793" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355793" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:21 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738726" X-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 23:22:19 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 04/14] MdePkg: Add UEFI Unaccepted memory definition Date: Sat, 27 Aug 2022 14:21:11 +0800 Message-Id: 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: fLLRpTMQU0YmXzfiBB11m807x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581342; bh=VwZo7bQUg7b6EppeLBT/yJgtGsXNDB35m+06dpKmnF8=; h=Cc:Date:From:Reply-To:Subject:To; b=XywTGuHB9rT0P/X/Ui1qZX/CgaX+evB3cVrr1WpceRfw7zGf5h6UsJPWiuMmbq1mXoo jm3G/nP+p4DFvgThySLKCZMKj0918h02vN+McTyN2XLepsS12j8px5Jn48xQJmV5xyBB3 4hNFGLE2DoWxDZpTK+d2VM/heGI+8gnUt4I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581343138100017 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 Plase refer to: UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices() Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Reviewed-by: Jiewen Yao Signed-off-by: Min Xu --- MdeModulePkg/Include/Pi/PrePiDxeCis.h | 25 +++++++++++++++++++++++++ MdePkg/Include/Pi/PiDxeCis.h | 10 +++++++++- MdePkg/Include/Uefi/UefiMultiPhase.h | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h diff --git a/MdeModulePkg/Include/Pi/PrePiDxeCis.h b/MdeModulePkg/Include/P= i/PrePiDxeCis.h new file mode 100644 index 000000000000..113ac37924cc --- /dev/null +++ b/MdeModulePkg/Include/Pi/PrePiDxeCis.h @@ -0,0 +1,25 @@ +/** @file + Include file matches things in PI. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MDE_MODULEPKG_PRE_PI_DXE_CIS_H_ +#define MDE_MODULEPKG_PRE_PI_DXE_CIS_H_ + +/// +/// A memory region that describes system memory that has not been accepted +/// by a corresponding call to the underlying isolation architecture. +/// +/// This memory region has not been defined in PI spec, so it is defined in +/// PrePiDxeCis.h. And it is defined in the format of captial letters +/// because only capital letters are allowed to be used for #define declar= ations. +/// +/// After this memory region is defined in PI spec, it should be a value in +/// EFI_GCD_MEMORY_TYPE in PiDxeCis.h. +/// +#define EFI_GCD_MEMORY_TYPE_UNACCEPTED 7 + +#endif diff --git a/MdePkg/Include/Pi/PiDxeCis.h b/MdePkg/Include/Pi/PiDxeCis.h index d0f2ed0e58df..27b219aa3ffa 100644 --- a/MdePkg/Include/Pi/PiDxeCis.h +++ b/MdePkg/Include/Pi/PiDxeCis.h @@ -56,7 +56,15 @@ typedef enum { /// system. If all memory has the same reliability, then this bit is not= used. /// EfiGcdMemoryTypeMoreReliable, - EfiGcdMemoryTypeMaximum + // /// + // /// A memory region that describes system memory that has not been ac= cepted + // /// by a corresponding call to the underlying isolation architecture. + // /// + // /// Please be noted: + // /// EfiGcdMemoryTypeUnaccepted is defined in PrePiDxeCis.h because it= has not been + // /// defined in PI spec. + // EfiGcdMemoryTypeUnaccepted, + EfiGcdMemoryTypeMaximum =3D 8 } EFI_GCD_MEMORY_TYPE; =20 /// diff --git a/MdePkg/Include/Uefi/UefiMultiPhase.h b/MdePkg/Include/Uefi/Uef= iMultiPhase.h index 22bae43e36e8..7884913371a9 100644 --- a/MdePkg/Include/Uefi/UefiMultiPhase.h +++ b/MdePkg/Include/Uefi/UefiMultiPhase.h @@ -103,6 +103,11 @@ typedef enum { /// however it happens to also support byte-addressable non-volatility. /// EfiPersistentMemory, + /// + /// A memory region that describes system memory that has not been accep= ted + /// by a corresponding call to the underlying isolation architecture. + /// + EfiUnacceptedMemoryType, EfiMaxMemoryType } EFI_MEMORY_TYPE; =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 (#92883): https://edk2.groups.io/g/devel/message/92883 Mute This Topic: https://groups.io/mt/93285602/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- From nobody Sun May 19 19:10:23 2024 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+92884+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+92884+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581346; cv=none; d=zohomail.com; s=zohoarc; b=KYYtCf2g/nwOf2p6OBgD9Oz0g9D8pP7YH4fQpk/o2ppbEb+RF7GSEJnoPzR+baYDKy7GB7kUnuVANiBR7NbR98m0G0/u+Bv0YV3xc12iaP5UCHBH7jNwXjHLhIQNma31X5AbnmTSMYxc7IHTaapEqrr0MTb81UcfPJ/sbUP8Y3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581346; 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=Bsr3D5FiEHILoUVXgX3ExNF2tvVj25zU7rym4B+R8cc=; b=ma6SrmD+n8bFsQE3OGQkfa10cu92eTKK1uiGqPIJKatAuvKEifgQtcLJBCh2nYzqtSgD9jCVvh/if/1/zT8iTyY/yib7gG6eym9P/JG+GHtg8cyy5Q/j95FYU2/NRUKBVJBSoV4o6AABKvkisLErNuiwLT3r4/7ZM1LSHBbLPFs= 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+92884+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 1661581346727791.1838674319127; Fri, 26 Aug 2022 23:22:26 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DrxTYY1788612xFoLVVoGwW6; Fri, 26 Aug 2022 23:22:25 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:24 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355794" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355794" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:24 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738738" X-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 23:22:21 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Jian J Wang , Liming Gao , Ray Ni , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 05/14] MdeModulePkg: Update Dxe to handle unaccepted memory type Date: Sat, 27 Aug 2022 14:21:12 +0800 Message-Id: <500dc32a6b42ae03535dc5a4505778a78024115b.1661579220.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: Ud1rrkW7dyKVCtn6qM5CRf3zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581345; bh=yvPpDoBYsLoPJLkQlGvBjyplg/wtv9XZmc7iZvs1W6U=; h=Cc:Date:From:Reply-To:Subject:To; b=XpXqsBOHN5crBMuDsK6oeYw6WFHEUklTn6v01zIEKWKeHJT6uH4jjTrmPKRDeKIhntz aYxt+pQvjKz7l2gg5QDBsgD+ty8xr+eicBNvJ9XV9XDJYEF69Ib+wf+Ec0tN4cVim9rRy uKXzIt5aDzcq9tgQwm6bRxM3/umOgv2+buA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581347176100023 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 Unaccepted memory is a kind of new memory type, CoreInitializeGcdServices() and CoreGetMemoryMap() are updated to handle the unaccepted memory type. Ref: microsoft/mu_basecore@97e9c31 Cc: Jian J Wang Cc: Liming Gao Cc: Ray Ni Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 6 +++ MdeModulePkg/Core/Dxe/Mem/Page.c | 63 +++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gc= d.c index 3763467bdbc0..9ba73d148af3 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 +#include +#include #include "DxeMain.h" #include "Gcd.h" #include "Mem/HeapGuard.h" @@ -103,6 +105,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryT= ypeNames[] =3D { "MMIO ", // EfiGcdMemoryTypeMemoryMappedIo "PersisMem", // EfiGcdMemoryTypePersistent "MoreRelia", // EfiGcdMemoryTypeMoreReliable + "Unaccepte", // EFI_GCD_MEMORY_TYPE_UNACCEPTED "Unknown " // EfiGcdMemoryTypeMaximum }; =20 @@ -2600,6 +2603,9 @@ CoreInitializeGcdServices ( case EFI_RESOURCE_MEMORY_RESERVED: GcdMemoryType =3D EfiGcdMemoryTypeReserved; break; + case EFI_RESOURCE_MEMORY_UNACCEPTED: + GcdMemoryType =3D EFI_GCD_MEMORY_TYPE_UNACCEPTED; + break; case EFI_RESOURCE_IO: GcdIoType =3D EfiGcdIoTypeIo; break; diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/P= age.c index cc0b90ac0df5..160289c1f9ec 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h" #include "Imem.h" #include "HeapGuard.h" +#include =20 // // Entry for tracking the memory regions for each memory type to coalesce = similar memory types @@ -61,6 +62,7 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxM= emoryType + 1] =3D { { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiM= emoryMappedIOPortSpace { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiP= alCode { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiP= ersistentMemory + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiU= nacceptedMemoryType { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiM= axMemoryType }; =20 @@ -68,22 +70,23 @@ EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress =3D MAX_AL= LOC_ADDRESS; EFI_PHYSICAL_ADDRESS mDefaultBaseAddress =3D MAX_ALLOC_ADDRESS; =20 EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = =3D { - { EfiReservedMemoryType, 0 }, - { EfiLoaderCode, 0 }, - { EfiLoaderData, 0 }, - { EfiBootServicesCode, 0 }, - { EfiBootServicesData, 0 }, - { EfiRuntimeServicesCode, 0 }, - { EfiRuntimeServicesData, 0 }, - { EfiConventionalMemory, 0 }, - { EfiUnusableMemory, 0 }, - { EfiACPIReclaimMemory, 0 }, - { EfiACPIMemoryNVS, 0 }, - { EfiMemoryMappedIO, 0 }, - { EfiMemoryMappedIOPortSpace, 0 }, - { EfiPalCode, 0 }, - { EfiPersistentMemory, 0 }, - { EfiMaxMemoryType, 0 } + { EfiReservedMemoryType, 0 }, + { EfiLoaderCode, 0 }, + { EfiLoaderData, 0 }, + { EfiBootServicesCode, 0 }, + { EfiBootServicesData, 0 }, + { EfiRuntimeServicesCode, 0 }, + { EfiRuntimeServicesData, 0 }, + { EfiConventionalMemory, 0 }, + { EfiUnusableMemory, 0 }, + { EfiACPIReclaimMemory, 0 }, + { EfiACPIMemoryNVS, 0 }, + { EfiMemoryMappedIO, 0 }, + { EfiMemoryMappedIOPortSpace, 0 }, + { EfiPalCode, 0 }, + { EfiPersistentMemory, 0 }, + { EFI_GCD_MEMORY_TYPE_UNACCEPTED, 0 }, + { EfiMaxMemoryType, 0 } }; // // Only used when load module at fixed address feature is enabled. True me= ans the memory is alreay successfully allocated @@ -1286,7 +1289,7 @@ CoreInternalAllocatePages ( } =20 if (((MemoryType >=3D EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM= _RESERVED_MIN)) || - (MemoryType =3D=3D EfiConventionalMemory) || (MemoryType =3D=3D EfiP= ersistentMemory)) + (MemoryType =3D=3D EfiConventionalMemory) || (MemoryType =3D=3D EfiP= ersistentMemory) || (MemoryType =3D=3D EfiUnacceptedMemoryType)) { return EFI_INVALID_PARAMETER; } @@ -1961,6 +1964,32 @@ CoreGetMemoryMap ( MemoryMap =3D MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, S= ize); } =20 + if (MergeGcdMapEntry.GcdMemoryType =3D=3D EFI_GCD_MEMORY_TYPE_UNACCEPT= ED) { + // + // Page Align GCD range is required. When it is converted to EFI_MEM= ORY_DESCRIPTOR, + // it will be recorded as page PhysicalStart and NumberOfPages. + // + ASSERT ((MergeGcdMapEntry.BaseAddress & EFI_PAGE_MASK) =3D=3D 0); + ASSERT (((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress= + 1) & EFI_PAGE_MASK) =3D=3D 0); + + // + // Create EFI_MEMORY_DESCRIPTOR for every Unaccepted GCD entries + // + MemoryMap->PhysicalStart =3D MergeGcdMapEntry.BaseAddress; + MemoryMap->VirtualStart =3D 0; + MemoryMap->NumberOfPages =3D RShiftU64 ((MergeGcdMapEntry.EndAddress= - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT); + MemoryMap->Attribute =3D MergeGcdMapEntry.Attributes | + (MergeGcdMapEntry.Capabilities & (EFI_MEM= ORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO | + EFI_MEM= ORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB)); + MemoryMap->Type =3D EfiUnacceptedMemoryType; + + // + // Check to see if the new Memory Map Descriptor can be merged with = an + // existing descriptor if they are adjacent and have the same attrib= utes + // + MemoryMap =3D MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, S= ize); + } + if (Link =3D=3D &mGcdMemorySpaceMap) { // // break loop when arrive at head. --=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 (#92884): https://edk2.groups.io/g/devel/message/92884 Mute This Topic: https://groups.io/mt/93285603/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- From nobody Sun May 19 19:10:23 2024 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+92885+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+92885+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581348; cv=none; d=zohomail.com; s=zohoarc; b=Av7Yr3i9+vWK5sYROjGt634gczq/IxkrjPxbrCS6o7SJ8lD4cJcv5tuKzNz1fE8oNJ79oMqVNc5f4Ok5xJPcKBpMNhGsSYicp3n8GZdnBmLNj14hTenf2LNmH5RQPiaNbJUpeDxpHrGWU1G1alzy80484V6jFeAyPSghy4k3yYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581348; 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=isXlOSQHY2XQulKM4tbgrufEvCHn42jZqeG6gQGC4Uk=; b=VACvCE+ja/lZuWfeFEbn3tDqyZ3/nE2q/nyt2UipRvu+GDBQuDdDFbgEbLF6JxuHG5uPx4ciAXxzJoneFgQUfSf9Ft4Hs6jeWKtyrbvOeBZyuKMbfkjLOe84+PEJw6qYY5TypdUeHvmmye5UYnLChfW909pNoMbL/wFrxoC4Q2M= 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+92885+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 1661581348045477.3394966843506; Fri, 26 Aug 2022 23:22:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qExnYY1788612xcmn6BqjNEO; Fri, 26 Aug 2022 23:22:27 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:27 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355799" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355799" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:26 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738749" X-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 23:22:24 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Ray Ni , Zhichao Gao , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 06/14] ShellPkg: Update shell command memmap to show unaccepted memory Date: Sat, 27 Aug 2022 14:21:13 +0800 Message-Id: <2c8660413371b8f455961258d6c2ab1e00b8d751.1661579220.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: czwsuu6wIUvzX5K0cDuqem7Wx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581347; bh=Ek674jh60djvCsgfkustfcN+9BphlTu08qzs2CUvOa8=; h=Cc:Date:From:Reply-To:Subject:To; b=vWqE4M0wNdJKoTyeJvLP1zsIFKsm4O2CLKcV59HxB+/B/onS/y+FWjiqSyvudKhyX2K gSZUymASOvm3wtEumueRJnUEaFg48QL1XpnB0aUuwwOU9pM4KR7lVQb5CKio2TW6Z6pxs SPQYzG3fW/8EDclKLfQtReNq5j/+w1dyhJs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581349165100027 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 ShellCommandRunMemMap() is updated to handle the case of unaccepted memory type. Cc: Ray Ni Cc: Zhichao Gao Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Acked-by: Gerd Hoffmann --- .../Library/UefiShellDebug1CommandsLib/MemMap.c | 13 +++++++++++++ .../UefiShellDebug1CommandsLib.uni | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPk= g/Library/UefiShellDebug1CommandsLib/MemMap.c index 72f3c58b0970..a089953b286f 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -26,6 +26,7 @@ STATIC CONST CHAR16 NameEfiACPIMemoryNVS[] =3D= L"ACPIMemoryNVS"; STATIC CONST CHAR16 NameEfiMemoryMappedIO[] =3D L"MemoryMappedIO= "; STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] =3D L"MemoryMappedIO= PortSpace"; STATIC CONST CHAR16 NameEfiPalCode[] =3D L"PalCode"; +STATIC CONST CHAR16 NameEfiUnacceptedMemoryType[] =3D L"Unaccepted"; =20 // // Need short names for some memory types @@ -151,6 +152,8 @@ ShellCommandRunMemMap ( UINT64 UnusableMemoryPagesSize; UINT64 PalCodePages; UINT64 PalCodePagesSize; + UINT64 UnacceptedPages; + UINT64 UnacceptedPagesSize; UINT64 PersistentPages; UINT64 PersistentPagesSize; BOOLEAN Sfo; @@ -175,6 +178,7 @@ ShellCommandRunMemMap ( PalCodePages =3D 0; PersistentPages =3D 0; Size =3D 0; + UnacceptedPages =3D 0; Descriptors =3D NULL; ShellStatus =3D SHELL_SUCCESS; Status =3D EFI_SUCCESS; @@ -303,6 +307,11 @@ ShellCommandRunMemMap ( TotalPages +=3D Walker->NumberOfPages; PalCodePages +=3D Walker->NumberOfPages; break; + case EfiUnacceptedMemoryType: + ShellPrintHiiEx (-1, -1, NULL, (EFI_STRING_ID)(!Sfo ? STRING= _TOKEN (STR_MEMMAP_LIST_ITEM) : STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), g= ShellDebug1HiiHandle, NameEfiUnacceptedMemoryType, Walker->PhysicalStart, W= alker->PhysicalStart+MultU64x64 (SIZE_4KB, Walker->NumberOfPages)-1, Walker= ->NumberOfPages, Walker->Attribute); + TotalPages +=3D Walker->NumberOfPages; + UnacceptedPages +=3D Walker->NumberOfPages; + break; default: // // Shell Spec defines the SFO format. @@ -335,6 +344,7 @@ ShellCommandRunMemMap ( MmioSpacePagesSize =3D MultU64x64 (SIZE_4KB, MmioSpacePages); MmioPortPagesSize =3D MultU64x64 (SIZE_4KB, MmioPortPages); PalCodePagesSize =3D MultU64x64 (SIZE_4KB, PalCodePages); + UnacceptedPagesSize =3D MultU64x64 (SIZE_4KB, UnacceptedPages); PersistentPagesSize =3D MultU64x64 (SIZE_4KB, PersistentPages); UnusableMemoryPagesSize =3D MultU64x64 (SIZE_4KB, UnusableMemoryPa= ges); if (!Sfo) { @@ -368,6 +378,8 @@ ShellCommandRunMemMap ( MmioPortPagesSize, PalCodePages, PalCodePagesSize, + UnacceptedPages, + UnacceptedPagesSize, AvailPages, AvailPagesSize, PersistentPages, @@ -422,6 +434,7 @@ ShellCommandRunMemMap ( AcpiReclaimPagesSize, AcpiNvsPagesSize, PalCodePagesSize, + UnacceptedPagesSize, PersistentPagesSize ); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1C= ommandsLib.uni index 6693be26e699..b1d239ed37ea 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni @@ -88,13 +88,14 @@ " MMIO : %,14ld Pa= ges (%,ld Bytes)\r\n" " MMIO_Port : %,14ld Pa= ges (%,ld Bytes)\r\n" " PalCode : %,14ld Pa= ges (%,ld Bytes)\r\n" + " Unaccepted: %,14ld Pa= ges (%,ld Bytes)\r\n" " Available : %,14ld Pa= ges (%,ld Bytes)\r\n" " Persistent: %,14ld Pa= ges (%,ld Bytes)\r\n" #string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pa= ges (%,ld Bytes)\r\n" #string STR_MEMMAP_LIST_SUMM2 #language en-US " ---------= ----- \r\n" "Total Memory: %,14ld MB= (%,ld Bytes)\r\n" #string STR_MEMMAP_LIST_ITEM_SFO #language en-US "MemoryMap,"%s","%LX","%= LX","%LX","%LX"\r\n" -#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld",= "%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%L= d","%Ld","%Ld"\r\n" +#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld",= "%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%L= d","%Ld","%Ld", "%Ld"\r\n" =20 #string STR_EFI_COMPRESS_FAIL #language en-US "Unable to compress: %r.= \r\n" #string STR_EFI_DECOMPRESS_FAIL #language en-US "Unable to decompress: %= r.\r\n" --=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 (#92885): https://edk2.groups.io/g/devel/message/92885 Mute This Topic: https://groups.io/mt/93285604/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- From nobody Sun May 19 19:10:23 2024 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+92886+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+92886+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581351; cv=none; d=zohomail.com; s=zohoarc; b=N/4yAyw+oM1WhI0rUNEatBTkwxFPLbpthYwnzzM690jjVyGCOBhjFv/X8SeaBtazYJh8XFSbg/s7neiX4QLUgttnK7cj0yrrvKmDgvc4CF+01XL6HkUKMlx1SHyy+bucL825nhxgQzjX6N/CJa+ryuF1reWt06yHS+QHeancc7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581351; 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=m2t33S8373of0GLg5QyxLgQdgmyjTDX5s4X6kx0Bqlc=; b=dtxA4W3Svu1lvZLj7DbSR8U4MZQek7sZRVLkbW5AtJf05saikFgpMqIRB1EtNUwbZiR55gS84h+evPYwtxukxJKhPCcadVSEi/pVz4JN4W40dltWfFQVkhddM4GCUpTG4oMq6vw3eIwLPGnSE8yJuKnBbco9byx7mWBuUQ9CoAM= 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+92886+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 1661581351463722.226822920985; Fri, 26 Aug 2022 23:22:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id etdzYY1788612xooMHJDMKOV; Fri, 26 Aug 2022 23:22:30 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:29 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355828" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355828" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:28 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738760" X-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 23:22:26 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 07/14] OvmfPkg: Add PCD and DEFINEs for Lazy Accept page. Date: Sat, 27 Aug 2022 14:21:14 +0800 Message-Id: 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: qj4JWNDDaLGFqV2TFlKsGZfbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581350; bh=XF+++JJpAoSGevYhf3zL+BJDzn8rRP+QgN9eKi8uiTs=; h=Cc:Date:From:Reply-To:Subject:To; b=fJJxuJo0LHXyoA9/OBoM3dkiT7LE43e5Mw1uSzBBvW3rL5fVkc6efrMGV0bC0f1uELu +LH3tJ/X6J+cqgfr+rMofDCtEgflC5GmcfQVsAD2aikVJ7FTPavV3lRHnf8boAn2dyh5d kvKTAmjhlod8OVU+AlFlfpIuLsIucAmvpM8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581353180100006 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 Lazy accept page can be controlled in build time like below: -D LAZY_ACCEPT_PARTIAL_MEM=3D512 The unit is MB. If it is 0 then it means Lazy-accept is turned off. Lazy-accept is turned off by default in OvmfPkgX64. Lazy-accept is turned on with 512MB by default in IntelTdxX64. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 8 ++++++++ OvmfPkg/OvmfPkg.dec | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 71b1cf8e7090..7ab2dc6fffe4 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -62,6 +62,11 @@ # DEFINE UP_CPU_DXE_GUID =3D 6490f1c5-ebcc-4665-8892-0075b9bb49b7 =20 + # + # Define the size of lazy accepted memory. The unit is MB. + # + DEFINE LAZY_ACCEPT_PARTIAL_MEM =3D 512 + [BuildOptions] GCC:RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG INTEL:RELEASE_*_*_CC_FLAGS =3D /D MDEPKG_NDEBUG @@ -453,6 +458,9 @@ # Point to the MdeModulePkg/Application/UiApp/UiApp.inf gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } =20 + # The partial memory size in Lazy accept + gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|$(LAZY_ACCEPT_= PARTIAL_MEM) + ##########################################################################= ###### # # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Pla= tform diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 5af76a540529..49fc20831ad0 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -399,6 +399,10 @@ ## The Tdx accept page size. 0x1000(4k),0x200000(2M) gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize|0x200000|UINT32|0x65 =20 + ## The partial memory size in Lazy accept. Its unit is MB. + ## The default value is 0 which means lazy accept is turned off. + gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|0|UINT64|0x68 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 6e68f60dc90f..026251ae7e69 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -78,6 +78,12 @@ DEFINE UP_CPU_PEI_GUID =3D 280251c4-1d09-4035-9062-839acb5f18c1 DEFINE UP_CPU_DXE_GUID =3D 6490f1c5-ebcc-4665-8892-0075b9bb49b7 =20 + # + # Define the size of lazy accepted memory. The unit is MB. + # In OvmfPkgX64, the lazy accept page is disabled by default. + # + DEFINE LAZY_ACCEPT_PARTIAL_MEM =3D 0 + [BuildOptions] GCC:RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG INTEL:RELEASE_*_*_CC_FLAGS =3D /D MDEPKG_NDEBUG @@ -600,6 +606,9 @@ # Point to the MdeModulePkg/Application/UiApp/UiApp.inf gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } =20 + # The partial memory size in Lazy accept + gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|$(LAZY_ACCEPT_= PARTIAL_MEM) + ##########################################################################= ###### # # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Pla= tform --=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 (#92886): https://edk2.groups.io/g/devel/message/92886 Mute This Topic: https://groups.io/mt/93285605/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- From nobody Sun May 19 19:10:23 2024 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+92887+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+92887+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581351; cv=none; d=zohomail.com; s=zohoarc; b=Sgo/nAYlWXiWnQOw9lQY6u+goPzgdoose+MTxW2zX0ph+0x6P2Jl7qr/lNXy4NCRV5jyR88zErCX98DK8DBMGgtVDIKJpFtGciFeCIPOH9guBdW3MYzaYMTO6cT4hVFifaDgXRk+FolQ2qQLrVqd3eUm8kHE0Tlt/WXfmKpvb/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581351; 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=ZL5lMBaKSNDGYT1uXPV99L9VQHnI0NoOoiaf5fMvefI=; b=n4V9B4hE+0uEvTnaujCJ/H3gHan0RwB7g20lpgD+Tk5bOf2oFK8dTvRFcZUpgrOk+u/qt4JBxzDt9QBYNpKGdN5njESkvJ/E/ox0azoBHafYY0lQ8515Iqb9jW0LPJNRylV4iCnoO9EGUdxA+8b4FbTk1Y9MLirGuUpQ7Ux0fs4= 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+92887+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 1661581351742821.8009808034951; Fri, 26 Aug 2022 23:22:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gsrDYY1788612x9jRg4cJurB; Fri, 26 Aug 2022 23:22:31 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:31 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355851" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355851" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:30 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738777" X-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 23:22:28 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 08/14] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area Date: Sat, 27 Aug 2022 14:21:15 +0800 Message-Id: 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: oFOAv7ZfCMcXt4g1IvVJ5RuKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581351; bh=xFQA16PdBBX23pXCtg4rL6Mt8lPRRh4m0s/ta8kAPoM=; h=Cc:Date:From:Reply-To:Subject:To; b=F/uKWpdIYRwAif+PkNhXMJFR9aGDKBvDFsZlYQB/irS6g8lHngrf+3p+tMd6Kcb/UoT +7N7AoSmJkCImNY3FpNg2acow3aCIwuWeAtozVUWOCPPOkfnmLI6aeu2YXTnYTAPQmrjf YvHfznEcn+3yOw+NK3TfW6b2qTHf/4DBHjc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581353161100005 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 In lazy-accept the MaxAcceptedMemoryAddress is needed in TransferTdxHobList and ContructFwHobList(at PeilessStartupLib). But in SEC phase we cannot use a global variable to pass this value. So we add a new field (MaxAcceptedMemoryAddress) in Tdx work area. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Include/WorkArea.h | 1 + 1 file changed, 1 insertion(+) diff --git a/OvmfPkg/Include/WorkArea.h b/OvmfPkg/Include/WorkArea.h index bf56fc4a6f65..2c2a5816b0dc 100644 --- a/OvmfPkg/Include/WorkArea.h +++ b/OvmfPkg/Include/WorkArea.h @@ -71,6 +71,7 @@ typedef struct _SEC_TDX_WORK_AREA { UINT32 PageTableReady; UINT32 Gpaw; UINT64 HobList; + UINT64 MaxAcceptedMemoryAddress; } SEC_TDX_WORK_AREA; =20 typedef struct _TDX_WORK_AREA { --=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 (#92887): https://edk2.groups.io/g/devel/message/92887 Mute This Topic: https://groups.io/mt/93285606/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- From nobody Sun May 19 19:10:23 2024 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+92888+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+92888+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581353; cv=none; d=zohomail.com; s=zohoarc; b=RBNlET2C9qzYdqm1A9fB3L6VgDVpG+UxjUuP77BX+8l/q0YEayevqThHuvZvwl6OTWOEE1AGpT49yJ+8gJsKOSWeLVqVeLmSzYMd1ZrNg/QvM69poDCBTM81OXRJP6QfPJGS4JXWYCsDJzWgqAutkBz+Z5l7UY+cMtHf8xS+7CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581353; 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=kaAa5L23Vyz8lTSvkIg1HfXMQWlJKUiXMiOchuPBAWw=; b=KZWidzKdrmbRAus4fSCpDokh6aaW1SZLx3A/RXZs+nByQ1cjoV2OrV0E7GvmlZ/Y0pCHTshFURUS6le1v3XFJUCOy2fo1gLGvBc/9A1YgU7h2HFUYvd3M5V9/tBhHp+SvSza+rXdjrnD3I+7urvqNcGBKQa82QIgOaG+w5MeFxo= 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+92888+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 1661581353833704.0307825489292; Fri, 26 Aug 2022 23:22:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 05zQYY1788612xgkeYZQwTjy; Fri, 26 Aug 2022 23:22:33 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:32 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355873" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355873" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:32 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738805" X-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 23:22:30 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 09/14] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Date: Sat, 27 Aug 2022 14:21:16 +0800 Message-Id: <24efa78fa0cac5bf3c8293734215f61a4ba1f405.1661579220.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: drLPE4sXA7rhykr2yPiEAs9xx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581353; bh=RQcJIFXPnWqcJ/wDdCcOE87uaDUnDfLNBWy06Q7rIHE=; h=Cc:Date:From:Reply-To:Subject:To; b=SdIy/2QAtB3v1VG2c810O+6UQ0goxjHhK9U/Qy0ckanAZmvO0xtiiyK+Rxyilp6cIPD 6DyzJBfT59MaMoH+ymheX/JIg6dQtGqHxQW38LdDpWgvXHLrh7BV6j3jmbjXQ6kqbydVH PIUDS7QxHa7iLeZyC7aQ05PxTvnIc5eP0WU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581355198100011 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 There are below major changes in PlatformInitLib/PlatformPei 1. ProcessHobList The unaccepted memory is accepted if the accumulated accepted memory is smaller than the LazyAcceptMemSize. If a EFI_RESOURCE_MEMORY_UNACCEPTED hob is cross the LazyAcceptMemSize, it will be split into 2 parts and only the left one is accepted. The max accepted memory address is stored in Tdx workarea which will be used in TransferTdxHobList. Please be noted: in current stage, we only accept the memory under 4G. 2. TransferTdxHobList Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob if it is accepted. As it is mentioned in 1), there may be a EFI_RESOURCE_MEMORY_UNACCEPTED hob which only part of the memory describes in the hob is accepted. We also handles this situation in TransferTdxHobList. 3. PlatformAdjustSystemMemorySizeBelow4gbForLazyAccep The system memory size below 4GB may be larger than the accepted memory. This function is used to handle this situation. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Include/Library/PlatformInitLib.h | 6 + OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 152 ++++++++++++++++-- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 27 ++++ .../PlatformInitLib/PlatformInitLib.inf | 1 + OvmfPkg/PlatformPei/MemDetect.c | 5 + 5 files changed, 180 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index 2987a367cc9c..187efcf34e14 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -144,6 +144,12 @@ PlatformGetSystemMemorySizeBelow4gb ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); =20 +UINT32 +EFIAPI +PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept ( + IN UINT32 LowerMemorySize + ); + /** Initialize the PhysMemAddressWidth field in PlatformInfoHob based on gue= st RAM size. **/ diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/P= latformInitLib/IntelTdx.c index 396b14d919d2..5c408758756e 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -7,6 +7,7 @@ =20 **/ =20 +#include #include #include #include @@ -24,7 +25,8 @@ #include #include =20 -#define ALIGNED_2MB_MASK 0x1fffff +#define ALIGNED_2MB_MASK 0x1fffff +#define MEGABYTE_SHIFT 20 =20 /** This function will be called to accept pages. Only BSP accepts pages. @@ -375,15 +377,33 @@ ProcessHobList ( EFI_STATUS Status; EFI_PEI_HOB_POINTERS Hob; EFI_PHYSICAL_ADDRESS PhysicalEnd; + TDX_WORK_AREA *WorkArea; + UINT64 ResourceLength; + UINT64 AccumulateAcceptedMemory; + UINT64 LazyAcceptMemSize; + UINT64 MaxAcceptedMemoryAddress; =20 Status =3D EFI_SUCCESS; ASSERT (VmmHobList !=3D NULL); Hob.Raw =3D (UINT8 *)VmmHobList; =20 + AccumulateAcceptedMemory =3D 0; + MaxAcceptedMemoryAddress =3D 0; + LazyAcceptMemSize =3D FixedPcdGet64 (PcdLazyAcceptPartialMemorySi= ze); + // + // If specified accept size is zero, accept all of the memory. + // Else transfer the size in megabyte to the number in byte. + // + if (LazyAcceptMemSize =3D=3D 0) { + LazyAcceptMemSize =3D MAX_UINT64; + } else { + LazyAcceptMemSize <<=3D MEGABYTE_SHIFT; + } + // // Parse the HOB list until end of list or matching type is found. // - while (!END_OF_HOB_LIST (Hob)) { + while (!END_OF_HOB_LIST (Hob) && AccumulateAcceptedMemory < LazyAcceptMe= mSize) { if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { DEBUG ((DEBUG_INFO, "\nResourceType: 0x%x\n", Hob.ResourceDescriptor= ->ResourceType)); =20 @@ -393,7 +413,26 @@ ProcessHobList ( DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescri= ptor->ResourceLength)); DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owne= r)); =20 - PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Resour= ceDescriptor->ResourceLength; + PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Res= ourceDescriptor->ResourceLength; + ResourceLength =3D Hob.ResourceDescriptor->ResourceLength; + + if (AccumulateAcceptedMemory + ResourceLength > LazyAcceptMemSize)= { + // + // If the memory can't be accepted completely, accept the part o= f it to meet the + // PcdLazyAcceptPartialMemorySize. + // + ResourceLength =3D LazyAcceptMemSize - AccumulateAcceptedMemory; + PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Resou= rceLength; + } + + if (PhysicalEnd > SIZE_4GB) { + // + // In current stage, we only accept the memory under 4G + // + ResourceLength -=3D (PhysicalEnd - SIZE_4GB); + LazyAcceptMemSize -=3D (PhysicalEnd - SIZE_4GB); + PhysicalEnd =3D SIZE_4GB; + } =20 Status =3D BspAcceptMemoryResourceRange ( Hob.ResourceDescriptor->PhysicalStart, @@ -402,12 +441,25 @@ ProcessHobList ( if (EFI_ERROR (Status)) { break; } + + AccumulateAcceptedMemory +=3D ResourceLength; + MaxAcceptedMemoryAddress =3D PhysicalEnd; } } =20 Hob.Raw =3D GET_NEXT_HOB (Hob); } =20 + // + // Record MaxAcceptedMemoryAddress in OvmfWorkArea. + // This information is useful later but in SEC phase we cannot use a glo= bal + // variable to pass this value. So it is stored in OvmfWorkarea. + // + WorkArea =3D (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + ASSERT (WorkArea !=3D NULL); + ASSERT (WorkArea->Header.GuestType =3D=3D CcGuestTypeIntelTdx); + WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress =3D MaxAcceptedMemoryA= ddress; + return Status; } =20 @@ -460,6 +512,74 @@ ProcessTdxHobList ( return Status; } =20 +/** + * Build ResourceDescriptorHob for the unaccepted memory region. + * This memory region may be splitted into 2 parts because of lazy accept. + * + * @param Hob Point to the EFI_HOB_RESOURCE_DESCRIPTOR + * @param MaxAcceptedMemoryAddress The max accepted memory address + * @return VOID + */ +VOID +BuildResourceDescriptorHobForUnacceptedMemory ( + IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob, + IN UINT64 MaxAcceptedMemoryAddress + ) +{ + EFI_PHYSICAL_ADDRESS PhysicalStart; + EFI_PHYSICAL_ADDRESS PhysicalEnd; + UINT64 ResourceLength; + EFI_RESOURCE_TYPE ResourceType; + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; + UINT64 AcceptedResourceLength; + + ASSERT (Hob->ResourceType =3D=3D EFI_RESOURCE_MEMORY_UNACCEPTED); + + ResourceType =3D EFI_RESOURCE_MEMORY_UNACCEPTED; + ResourceAttribute =3D Hob->ResourceAttribute; + PhysicalStart =3D Hob->PhysicalStart; + ResourceLength =3D Hob->ResourceLength; + PhysicalEnd =3D PhysicalStart + ResourceLength; + + if (PhysicalEnd <=3D MaxAcceptedMemoryAddress) { + // + // This memory region has been accepted. + // + ResourceType =3D EFI_RESOURCE_SYSTEM_MEMORY; + ResourceAttribute |=3D (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_= ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED); + } else if (PhysicalStart >=3D MaxAcceptedMemoryAddress) { + // + // This memory region hasn't been accepted. + // So keep the ResourceType and ResourceAttribute unchange. + // + } else { + // + // This memory region is splitted into 2 parts: + // the accepted and unaccepted. + // + AcceptedResourceLength =3D MaxAcceptedMemoryAddress - Hob->PhysicalSta= rt; + + // We build the ResourceDescriptorHob for the accepted part. + // The unaccepted part will be build out side the if-else block. + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttribute | (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_A= TTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED), + Hob->PhysicalStart, + AcceptedResourceLength + ); + + PhysicalStart =3D Hob->PhysicalStart + AcceptedResourceLength; + ResourceLength -=3D AcceptedResourceLength; + } + + BuildResourceDescriptorHob ( + ResourceType, + ResourceAttribute, + PhysicalStart, + ResourceLength + ); +} + /** Transfer the incoming HobList for the TD to the final HobList for Dxe. The Hobs transferred in this function are ResourceDescriptor hob and @@ -477,6 +597,16 @@ TransferTdxHobList ( EFI_PEI_HOB_POINTERS Hob; EFI_RESOURCE_TYPE ResourceType; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; + UINT64 MaxAcceptedMemoryAddress; + TDX_WORK_AREA *WorkArea; + + WorkArea =3D (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + ASSERT (WorkArea !=3D NULL); + ASSERT (WorkArea->Header.GuestType =3D=3D CcGuestTypeIntelTdx); + MaxAcceptedMemoryAddress =3D WorkArea->SecTdxWorkArea.MaxAcceptedMemoryA= ddress; + if (MaxAcceptedMemoryAddress =3D=3D 0) { + MaxAcceptedMemoryAddress =3D MAX_UINT64; + } =20 // // PcdOvmfSecGhcbBase is used as the TD_HOB in Tdx guest. @@ -489,16 +619,16 @@ TransferTdxHobList ( ResourceAttribute =3D Hob.ResourceDescriptor->ResourceAttribute; =20 if (ResourceType =3D=3D EFI_RESOURCE_MEMORY_UNACCEPTED) { - ResourceType =3D EFI_RESOURCE_SYSTEM_MEMORY; - ResourceAttribute |=3D (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RES= OURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED); + BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescr= iptor, MaxAcceptedMemoryAddress); + } else { + BuildResourceDescriptorHob ( + ResourceType, + ResourceAttribute, + Hob.ResourceDescriptor->PhysicalStart, + Hob.ResourceDescriptor->ResourceLength + ); } =20 - BuildResourceDescriptorHob ( - ResourceType, - ResourceAttribute, - Hob.ResourceDescriptor->PhysicalStart, - Hob.ResourceDescriptor->ResourceLength - ); break; case EFI_HOB_TYPE_MEMORY_ALLOCATION: BuildMemoryAllocationHob ( diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 942eaf89cfcf..d7c8b938f263 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -42,6 +42,8 @@ Module Name: =20 #include =20 +#define MEGABYTE_SHIFT 20 + VOID EFIAPI PlatformQemuUc32BaseInitialization ( @@ -289,6 +291,31 @@ GetHighestSystemMemoryAddressFromPvhMemmap ( return HighestAddress; } =20 +UINT32 +EFIAPI +PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept ( + IN UINT32 LowerMemorySize + ) +{ + #ifdef MDE_CPU_X64 + UINT64 LazyAcceptMemSize; + + LazyAcceptMemSize =3D FixedPcdGet64 (PcdLazyAcceptPartialMemorySize); + // + // If specified accept size is not zero, + // transfer the size in megabyte to the number in byte. + // + if (LazyAcceptMemSize !=3D 0) { + LazyAcceptMemSize <<=3D MEGABYTE_SHIFT; + if (LazyAcceptMemSize < LowerMemorySize) { + LowerMemorySize =3D (UINT32)(UINTN)LazyAcceptMemSize; + } + } + + #endif + return LowerMemorySize; +} + UINT32 EFIAPI PlatformGetSystemMemorySizeBelow4gb ( diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index d2fa2d998df8..1c5ed1067ad4 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -96,6 +96,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize =20 gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize + gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize =20 [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 2e47b1322990..acc1d7f63ee8 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -279,6 +279,11 @@ PublishPeiMemory ( LowerMemorySize -=3D mPlatformInfoHob.Q35TsegMbytes * SIZE_1MB; } =20 + // + // Adjustment for Lazy accept because it may accept part of the memory. + // + LowerMemorySize =3D PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept = (LowerMemorySize); + S3AcpiReservedMemoryBase =3D 0; S3AcpiReservedMemorySize =3D 0; =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 (#92888): https://edk2.groups.io/g/devel/message/92888 Mute This Topic: https://groups.io/mt/93285607/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- From nobody Sun May 19 19:10:23 2024 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+92889+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+92889+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581355; cv=none; d=zohomail.com; s=zohoarc; b=Iv3cLHxE38y+iOD3EFNM5L79Rs4m32zpJbzkkt4EIqAtRvdxlncRisF2c+8e2VOsR0w7qlKYt1qy6NAFY3AT4UOgTFA97IaphgyQq4NW/NKDmD3tDxo9en3/aemODsLm8wHtx4TXatyn3vJ8fTzqEf9w8MQX+UiNp3myNjIH97Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581355; 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=4G5ELWOajRpkiVhb4SrDIRdvNCDo+yyhc0h336WBmKc=; b=MSiZ9CkK9sZ8A86myDnBnsV8dY+9VxVBlfrGWssdbxqadeCPpLViYCHA/+rfCC4HpZAP5Y1cC/0Oz4P7dLqdFlFoVdfa+sKSr4N8mDbAC9/3mRClleEZJD8cxbZy6xKTeIoQ6RSpVi2JdZerVI2pHkT7VezPS1FpMcA3PFaTdYw= 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+92889+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 1661581355868256.998559160529; Fri, 26 Aug 2022 23:22:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3a9TYY1788612xvs805pa83P; Fri, 26 Aug 2022 23:22:35 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:34 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355901" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355901" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:34 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738837" X-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 23:22:32 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 10/14] OvmfPkg: Update ConstructFwHobList for lazy accept Date: Sat, 27 Aug 2022 14:21:17 +0800 Message-Id: <5612fa3b0241ccca119bcc58b009b399a2214b25.1661579220.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: ubv7BatwYWZDPzoDKtVBtTxRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581355; bh=KaHPJxu0M3ZT5FGJNrFefROmF4N0Pv3Lq6lZiJqP2eg=; h=Cc:Date:From:Reply-To:Subject:To; b=S1geHrp2oX+ON8MWGna0sl1OqFGpKpgXb474kQhsg+j3CC1x7s2ppBAVYfHmmg2uL1x Dy7hzZ899joQCRKhYfUDmTd+kyHq2FVsyfjl6Q/76h8ETDiK5pZuKbcu8hi/ypZeM+sXC 4gfDbbpbkjfRpIvZHrvicngRDnIMisAtFPE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581357185100015 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 In TDVF the hob list is constructed at the memory region which is the largest one below 4GB. After lazy accept is introduced, the MaxAcceptedMemoryAddress (which is tha max accpeted memory address in lazy accept) should be considered. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Library/PeilessStartupLib/Hob.c | 23 ++++++++++++++++++- .../PeilessStartupLib/PeilessStartupLib.inf | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/Peil= essStartupLib/Hob.c index a9b92b5fbaba..884490af68fd 100644 --- a/OvmfPkg/Library/PeilessStartupLib/Hob.c +++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "PeilessStartupInternal.h" =20 /** @@ -74,10 +75,13 @@ ConstructFwHobList ( ) { EFI_PEI_HOB_POINTERS Hob; + EFI_PHYSICAL_ADDRESS PhysicalStart; EFI_PHYSICAL_ADDRESS PhysicalEnd; UINT64 ResourceLength; EFI_PHYSICAL_ADDRESS LowMemoryStart; UINT64 LowMemoryLength; + UINT64 MaxAcceptedMemoryAddress; + TDX_WORK_AREA *WorkArea; =20 ASSERT (VmmHobList !=3D NULL); =20 @@ -86,14 +90,31 @@ ConstructFwHobList ( LowMemoryLength =3D 0; LowMemoryStart =3D 0; =20 + WorkArea =3D (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + ASSERT (WorkArea !=3D NULL); + ASSERT (WorkArea->Header.GuestType =3D=3D CcGuestTypeIntelTdx); + MaxAcceptedMemoryAddress =3D WorkArea->SecTdxWorkArea.MaxAcceptedMemoryA= ddress; + if (MaxAcceptedMemoryAddress =3D=3D 0) { + MaxAcceptedMemoryAddress =3D MAX_UINT64; + } + // // Parse the HOB list until end of list or matching type is found. // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { - if (Hob.ResourceDescriptor->ResourceType =3D=3D EFI_RESOURCE_MEMORY_= UNACCEPTED) { + if ((Hob.ResourceDescriptor->ResourceType =3D=3D EFI_RESOURCE_MEMORY= _UNACCEPTED) && (Hob.ResourceDescriptor->PhysicalStart < MaxAcceptedMemoryA= ddress)) { PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Res= ourceDescriptor->ResourceLength; ResourceLength =3D Hob.ResourceDescriptor->ResourceLength; + PhysicalStart =3D Hob.ResourceDescriptor->PhysicalStart; + + if ((PhysicalEnd >=3D MaxAcceptedMemoryAddress) && (PhysicalStart = < MaxAcceptedMemoryAddress)) { + // + // This memory region is split into 2 parts. The left part is ac= cepted. + // + PhysicalEnd =3D MaxAcceptedMemoryAddress; + ResourceLength =3D PhysicalEnd - PhysicalStart; + } =20 if (PhysicalEnd <=3D BASE_4GB) { if (ResourceLength > LowMemoryLength) { diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index def50b4b019e..eed9f27d3d01 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -88,3 +88,4 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase --=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 (#92889): https://edk2.groups.io/g/devel/message/92889 Mute This Topic: https://groups.io/mt/93285608/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- From nobody Sun May 19 19:10:23 2024 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+92890+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+92890+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581358; cv=none; d=zohomail.com; s=zohoarc; b=QCGdy+ykWXPlrvYDrdRtiQtZ0ugEEP9LLaASKHmsznOdT65FywcB9CHysOUlZvJa1Sksd+2y25ZtLXqVmAvfr9yc6XSkCByiQEaC0I7ckMsr61Q8beHRhetxdRFa4qD13IL6GBIE0HwlE7Ym68IXhA+wf6K381O6zljYdxnm+7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581358; 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=j/dgfvUeM712xgyLp+hY3J/5rJbg9lRE9NUK2uXF8Pc=; b=MYzet9fslWyXPnHjPevDTEtCtoGQffXK7GQYHmh8xuMQW7w8YrDoL7UpB1QXl//4u4k9TSRYxL9wyqX/mFD+8x0I1GwDW1WprO8O3UK617ejgzbJ0OZm1YIEwOUsI01Hn+xD9OIUxNBPrWsLETooO6k8Zu5NKf3m/3ncsNGzaAk= 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+92890+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 1661581358465767.3670018476927; Fri, 26 Aug 2022 23:22:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kST2YY1788612x6hqh8cnRtS; Fri, 26 Aug 2022 23:22:38 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:37 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355927" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355927" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:37 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738858" X-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 23:22:34 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Jiaqi Gao , Michael D Kinney , Liming Gao , Zhiguang Liu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Min Xu Subject: [edk2-devel] [PATCH V2 11/14] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Date: Sat, 27 Aug 2022 14:21:18 +0800 Message-Id: <7c23f5b0ce50a800e75d5f51e8c8333578a5a5f2.1661579220.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: biZ6b4yxg5JySbCGf3apgs1kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581358; bh=Sa/r1xmDH+1ZOGuARk8fpQEIoH6LSt4jdZDCctQ4UdE=; h=Cc:Date:From:Reply-To:Subject:To; b=QtAH8RVxkB2+qm6bzIWRZl/y0Kw58JiII1MzhytWIcRTj+MNpJBak8FfCufdBZakbpA v73FTYUu0WZi+o7nOr1u9ZwezdR0kECwYbp4Euusj+oKDWHHeVi+wYb+w6L7dZWrilhac w/L1GZgO6SIejQH7KKo2rRSyJDzL5rel2ss= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581359336100001 Content-Type: text/plain; charset="utf-8" From: Jiaqi Gao RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 EdkiiMemoryAcceptProtocol is defined in MdePkg, the method AcceptMemory() can be called when memory needs to be accepted. EdkiiMemoryAcceptProtocol can be installed by architecture-specific drivers such as TdxDxe. This allows different isolation architectures to realize their own low-level methods to accept memory. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Jiaqi Gao Signed-off-by: Min Xu Acked-by: Gerd Hoffmann --- MdePkg/Include/Protocol/MemoryAccept.h | 37 ++++++++++++++++++++++++++ MdePkg/MdePkg.dec | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h diff --git a/MdePkg/Include/Protocol/MemoryAccept.h b/MdePkg/Include/Protoc= ol/MemoryAccept.h new file mode 100644 index 000000000000..f7646e04d8a1 --- /dev/null +++ b/MdePkg/Include/Protocol/MemoryAccept.h @@ -0,0 +1,37 @@ +/** @file + The file provides the protocol to provide interface to accept memory. + + Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MEMORY_ACCEPT_H_ +#define MEMORY_ACCEPT_H_ + +#define EDKII_MEMORY_ACCEPT_PROTOCOL_GUID \ + { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80= , 0x26 } }; + +typedef struct _EDKII_MEMORY_ACCEPT_PROTOCOL EDKII_MEMORY_ACCEPT_PROTOCOL; + +/** + @param This A pointer to a EDKII_MEMORY_ACCEPT_PROTOCO= L. +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_ACCEPT_MEMORY)( + IN EDKII_MEMORY_ACCEPT_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS StartAddress, + IN UINTN Size + ); + +/// +/// The EDKII_MEMORY_ACCEPT_PROTOCOL provides the ability for memory servi= ces +/// to accept memory. +/// +struct _EDKII_MEMORY_ACCEPT_PROTOCOL { + EDKII_ACCEPT_MEMORY AcceptMemory; +}; + +extern EFI_GUID gEdkiiMemoryAcceptProtocolGuid; + +#endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index f1ebf9e251c1..6b6bfbec29b3 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -1019,6 +1019,9 @@ gEfiPeiDelayedDispatchPpiGuid =3D { 0x869c711d, 0x649c, 0x44fe, { 0x8b,= 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }} =20 [Protocols] + ## Include/Protocol/MemoryAccept.h + gEdkiiMemoryAcceptProtocolGuid =3D { 0x38c74800, 0x5590, 0x4db4, { 0xa0,= 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 }} + ## Include/Protocol/Pcd.h gPcdProtocolGuid =3D { 0x11B34006, 0xD85B, 0x4D0A, { 0xA2,= 0x90, 0xD5, 0xA5, 0x71, 0x31, 0x0E, 0xF7 }} =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 (#92890): https://edk2.groups.io/g/devel/message/92890 Mute This Topic: https://groups.io/mt/93285609/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- From nobody Sun May 19 19:10:23 2024 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+92891+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+92891+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581361; cv=none; d=zohomail.com; s=zohoarc; b=GvCPlGwgRDwgMh+u9q94oPVnnY3BXohtWyYnU6AtAzJI6iJzkbJ9Gp0G01vWQoimDwgA88uzyopssUytF1aE7UJ7yaYszC7OH+kjOZDIaI1CVxbRxyBUnlgFRNowbBbjR4B+cSctzx+91FkcErg33xmse6xi0AkKx+dBQ0JYsoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581361; 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=TqHEke1eOPGNeuaSK3pJpBDJy31Y+SYL/6arJmlD9Ys=; b=IEyAlqFzEFWZlcvuz/hM77nVsEyCOM3KWuQOY414gaKF6DW2WfJPkwB8VkCm+hSNstI7yPcTLjr9TZW566EdP1Y9T7Tt/wwUqRNGUklJzjN/6Wb90agHXpMLXZfW0riGuJEPG4cOyMLhU8x8ZZq/ZykO1ShHDL/TaRruBIB12n4= 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+92891+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 1661581361284189.25505798528525; Fri, 26 Aug 2022 23:22:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3ftlYY1788612x0Jecy74NHS; Fri, 26 Aug 2022 23:22:40 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355940" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355940" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:39 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738897" X-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 23:22:37 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 12/14] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Date: Sat, 27 Aug 2022 14:21:19 +0800 Message-Id: <4308ce519f4c39e5943212d109cac24a9a626721.1661579220.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: Uc7Mj6Gzxo9iuxomt76bdxINx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581360; bh=wiKKXfOgGsKBzMsyNtCN1F+4tOksapIIwyOog1grH4I=; h=Cc:Date:From:Reply-To:Subject:To; b=aI3savD2rSTzQ18QRX++xOYQvEC2dKMOGupvWSUqdML6AI5fpyew9LECnb8hv8c8jE8 8KRqmFzXUOp+t3MW858MfP18dJ+43bXZqhqw1AvaYDcIpfH2FbRjH7ZJtVA/NIsZXXw8e 5UXUW7MliFCAEzbYDR8F5hsDfq/54O4TYVU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581363274100010 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 Memory usage may exceed the amount accepted at the begining (SEC), TDVF needs to accept memory dynamically when OUT_OF_RESOURCE occurs. EdkiiMemoryAcceptProtocol is defined in MdePkg and is implementated / installed in TdxDxe for Intel TDX memory acceptance. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Acked-by: Gerd Hoffmann --- OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++++++++++++++++++++++ OvmfPkg/TdxDxe/TdxDxe.inf | 2 + 2 files changed, 105 insertions(+) diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c index 2318db989792..ca948522a42c 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.c +++ b/OvmfPkg/TdxDxe/TdxDxe.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,95 @@ #include #include =20 +#define ALIGNED_2MB_MASK 0x1fffff +EFI_HANDLE mTdxDxeHandle =3D NULL; + +EFI_STATUS +EFIAPI +TdxMemoryAccept ( + IN EDKII_MEMORY_ACCEPT_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS StartAddress, + IN UINTN Size + ) +{ + EFI_STATUS Status; + UINT32 AcceptPageSize; + UINT64 StartAddress1; + UINT64 StartAddress2; + UINT64 StartAddress3; + UINT64 Length1; + UINT64 Length2; + UINT64 Length3; + UINT64 Pages; + + AcceptPageSize =3D FixedPcdGet32 (PcdTdxAcceptPageSize); + StartAddress1 =3D 0; + StartAddress2 =3D 0; + StartAddress3 =3D 0; + Length1 =3D 0; + Length2 =3D 0; + Length3 =3D 0; + + if (Size =3D=3D 0) { + return EFI_SUCCESS; + } + + if (ALIGN_VALUE (StartAddress, SIZE_2MB) !=3D StartAddress) { + StartAddress1 =3D StartAddress; + Length1 =3D ALIGN_VALUE (StartAddress, SIZE_2MB) - StartAddress; + if (Length1 >=3D Size) { + Length1 =3D Size; + } + + StartAddress +=3D Length1; + Size -=3D Length1; + } + + if (Size > SIZE_2MB) { + StartAddress2 =3D StartAddress; + Length2 =3D Size & ~(UINT64)ALIGNED_2MB_MASK; + StartAddress +=3D Length2; + Size -=3D Length2; + } + + if (Size) { + StartAddress3 =3D StartAddress; + Length3 =3D Size; + } + + Status =3D EFI_SUCCESS; + if (Length1 > 0) { + Pages =3D Length1 / SIZE_4KB; + Status =3D TdAcceptPages (StartAddress1, Pages, SIZE_4KB); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (Length2 > 0) { + Pages =3D Length2 / AcceptPageSize; + Status =3D TdAcceptPages (StartAddress2, Pages, AcceptPageSize); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (Length3 > 0) { + Pages =3D Length3 / SIZE_4KB; + Status =3D TdAcceptPages (StartAddress3, Pages, SIZE_4KB); + ASSERT (!EFI_ERROR (Status)); + if (EFI_ERROR (Status)) { + return Status; + } + } + + return Status; +} + +EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol =3D { + TdxMemoryAccept +}; + VOID SetPcdSettings ( EFI_HOB_PLATFORM_INFO *PlatformInfoHob @@ -277,6 +367,19 @@ TdxDxeEntryPoint ( NULL ); =20 + // + // Install MemoryAccept protocol for TDX + // + Status =3D gBS->InstallProtocolInterface ( + &mTdxDxeHandle, + &gEdkiiMemoryAcceptProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMemoryAcceptProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Install EdkiiMemoryAcceptProtocol failed.\n")); + } + // // Call TDINFO to get actual number of cpus in domain // diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf index a7e0abda1522..9be021f28648 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.inf +++ b/OvmfPkg/TdxDxe/TdxDxe.inf @@ -52,6 +52,7 @@ gEfiAcpiTableProtocolGuid ## CONSUMES gEfiMpInitLibMpDepProtocolGuid gEfiMpInitLibUpDepProtocolGuid + gEdkiiMemoryAcceptProtocolGuid =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase @@ -68,3 +69,4 @@ gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack + gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize --=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 (#92891): https://edk2.groups.io/g/devel/message/92891 Mute This Topic: https://groups.io/mt/93285610/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- From nobody Sun May 19 19:10:23 2024 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+92892+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+92892+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581362; cv=none; d=zohomail.com; s=zohoarc; b=bnEM2toaSm28W7irFkh/zRo3S9zHLQVLhktA3c9LQxvPFJzrPExedJNBMCBwnjrAhYDLvDOunjv2NMl+u5+YQDnpssbRZAOZKG3lw1SB3wBGKiM3NhInmPH3o2JHdZqK1UuHRfEBZ1zC6/2C2RBsIztz8T0DNkaULnTv02VvaIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581362; 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=7kAkOxDUjjN/04JHvKqJArRFUUVV6b8j8nE2YSpGW4U=; b=gqRRnWUgFieEclhNLk2sxihWS73W2OiGxIqpWwO4rlYub0K7js6os7P+KkfiN/4gUuKiLl8200q/5T6rh+a9M35twp7n++tZHbb3Ne2wtciGd+/oC1kv1EwgTY6NI0UV5tt4AOS+vSUaQoxILoQ5gVQA/WH4uea0O2CGCkL+3aM= 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+92892+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 1661581362219933.3810295521239; Fri, 26 Aug 2022 23:22:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PpKwYY1788612xvfHNIdwuHt; Fri, 26 Aug 2022 23:22:41 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:41 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355960" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355960" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:40 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738925" X-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 23:22:39 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [edk2-devel] [PATCH V2 13/14] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Date: Sat, 27 Aug 2022 14:21:20 +0800 Message-Id: <45f2baece31f3fab25e6571fff590cc7bf45ac8d.1661579220.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: EBgzPPHJ1SWIRzB1Kkpg2Fprx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581361; bh=A5ccVxmQp19Bgoa8Hk2afT34AJJgVOvjcve8O8EH56g=; h=Cc:Date:From:Reply-To:Subject:To; b=TK4TQGrm9BN68caOlTx3UdqMUdPU52/tWQ+u1GqqFpGve83fkWqtZeIC0DmbCRyxCpz 9+CMDV2CrtbnGePXWgXF/suKBUmdZrlGiOSOcbQOHczQ6OAScZFztqROAYyruNYItiJWv u/bJfqGWXwFf/tVKroCOOrsVQh+mOQP2Gpc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581363262100009 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 After EdkiiMemoryAcceptProtocol is implemented in TdxDxe driver, we can call it to accept pages in DXE phase. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Signed-off-by: Min Xu Acked-by: Gerd Hoffmann --- .../BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf | 3 +++ .../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf = b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf index a8abfec12fa3..11768825f8ca 100644 --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf @@ -42,3 +42,6 @@ =20 [Pcd] gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr + +[Protocols] + gEdkiiMemoryAcceptProtocolGuid diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/Ovmf= Pkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c index 9d11c6e4df72..503f626d75c6 100644 --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c @@ -27,6 +27,8 @@ #include "VirtualMemory.h" #include #include +#include +#include #include =20 typedef enum { @@ -517,8 +519,9 @@ SetOrClearSharedBit ( IN UINT64 Length ) { - UINT64 AddressEncMask; - UINT64 Status; + UINT64 AddressEncMask; + UINT64 Status; + EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol; =20 AddressEncMask =3D GetMemEncryptionAddressMask (); =20 @@ -539,7 +542,10 @@ SetOrClearSharedBit ( // If changing shared to private, must accept-page again // if (Mode =3D=3D ClearSharedBit) { - TdAcceptPages (PhysicalAddress, Length / EFI_PAGE_SIZE, EFI_PAGE_SIZE); + Status =3D gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL,= (VOID **)&MemoryAcceptProtocol); + ASSERT (!EFI_ERROR (Status)); + Status =3D MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, P= hysicalAddress, Length); + ASSERT (!EFI_ERROR (Status)); } =20 DEBUG (( --=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 (#92892): https://edk2.groups.io/g/devel/message/92892 Mute This Topic: https://groups.io/mt/93285611/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- From nobody Sun May 19 19:10:23 2024 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+92893+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+92893+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661581365; cv=none; d=zohomail.com; s=zohoarc; b=j8RrO3wodtRJLVanz/tPOAqct2K0C0R8CcSTVWFwM7r1aIHqqpd1wocpHyxa8L/l3gwP+HZWExtXdisds+9Qa74DabcAvUSmadd5ZfKVFE60b509GrxbndCoywSJrnxzSHyRt6ifQY5SqIwshnmbUiwhmUHk5zFIVoV9U7JIX/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661581365; 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=79CuToS/QwzICt5z8lEBfNagnIv4bs9XREF9vBSgwlE=; b=merJoITh/iTF3P69dsc3plVBGgsr4QUqafkuKqcRBkeQ4xcpwW3O+jaCtAEuP1uC9mJiqwyo76drbZN3ztuYRrEZXH82SOKQjLFTDpzXsWYT7Lf/b0wN64fKTdkMX+7XX6z/AaJmcin3mA3N3sp8ac/22AEymySlAsvO6PFaxsU= 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+92893+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 1661581365308273.82452921373715; Fri, 26 Aug 2022 23:22:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id F851YY1788612x5AEUcp3h5i; Fri, 26 Aug 2022 23:22:45 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.46431.1661581332997885650 for ; Fri, 26 Aug 2022 23:22:44 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356355997" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356355997" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 23:22:43 -0700 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="671738946" X-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 23:22:41 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Jiaqi Gao , Jian J Wang , Liming Gao , Dandan Bi , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann , Min Xu Subject: [edk2-devel] [PATCH V2 14/14] MdeModulePkg: Pool and page functions accept memory when OOM occurs Date: Sat, 27 Aug 2022 14:21:21 +0800 Message-Id: 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: ZdWrcIBnA13xzdBVMP8YICWzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661581365; bh=rd0bkKy44yTY04qyAj43Eov736Iu/dbzyMJzAs7Yopw=; h=Cc:Date:From:Reply-To:Subject:To; b=KnSy+nBBCRe8E2tiJPqf7q61tDTrNrBjH+KNJbn6jwBm+TIT2ZszhVOh3fajSXvN0Pu tpRsMLACm3fc8uMnB6A6cyH+g1bgyFsLjrkDpuwNJo8TIAVBpdRIN9s+sLWfg0Ygw4qEd uN1QXb9Lu6LhSZlRZVOq44Z4hFypip7qVKw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661581367293100003 Content-Type: text/plain; charset="utf-8" From: Jiaqi Gao RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 When CoreAllocatePages() / CoreAllocatePool() meets error of EFI_OUT_OF_RESOURCES, locate the EdkiiMemoryAcceptProtocol and accept extra memory dynamically. Firstly, find the unaccpeted memory region with enough size in GCD entries. Then locate the EdkiiMemoryAcceptProtocol and accept the memory. Finally, update the GCD memory and gMemoryMap entries. After updating the memory infomation, CoreInternalAllocatePages() / CoreInternalAllocatePool() will be recalled to allocate pages / pool. Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Jiaqi Gao Signed-off-by: Min Xu --- MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/Mem/Imem.h | 16 +++ MdeModulePkg/Core/Dxe/Mem/Page.c | 190 ++++++++++++++++++++++++++++++ MdeModulePkg/Core/Dxe/Mem/Pool.c | 14 +++ 4 files changed, 221 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeM= ain.inf index e4bca895773d..371ba45357be 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -169,6 +169,7 @@ gEfiVariableArchProtocolGuid ## CONSUMES gEfiCapsuleArchProtocolGuid ## CONSUMES gEfiWatchdogTimerArchProtocolGuid ## CONSUMES + gEdkiiMemoryAcceptProtocolGuid ## CONSUMES =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressBootTimeCodePageNumber = ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Core/Dxe/Mem/Imem.h b/MdeModulePkg/Core/Dxe/Mem/I= mem.h index 2f0bf2bf631f..22e0d0e44030 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Imem.h +++ b/MdeModulePkg/Core/Dxe/Mem/Imem.h @@ -47,6 +47,22 @@ typedef struct { // Internal prototypes // =20 +/** + Internal function. Used by the pool and page functions to accept memory + when OOM occurs. + + @param Type The type of allocation to perform. + @param AcceptSize Size of memory to be accepted. + @param Memory Accept memory address + +**/ +EFI_STATUS +AcceptMemoryResource ( + IN EFI_ALLOCATE_TYPE Type, + IN UINTN AcceptSize, + IN OUT EFI_PHYSICAL_ADDRESS *Memory + ); + /** Internal function. Used by the pool functions to allocate pages to back pool allocation requests. diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/P= age.c index 160289c1f9ec..513792a7fe04 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -10,6 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Imem.h" #include "HeapGuard.h" #include +#include =20 // // Entry for tracking the memory regions for each memory type to coalesce = similar memory types @@ -379,6 +380,176 @@ CoreFreeMemoryMapStack ( mFreeMapStack -=3D 1; } =20 +/** + Used to accept memory when OOM occurs. + + @param Type The type of allocation to perform. + @param AcceptSize Size of memory to be accepted. + @param Memory Accept memory address + +**/ +EFI_STATUS +AcceptMemoryResource ( + IN EFI_ALLOCATE_TYPE Type, + IN UINTN AcceptSize, + IN OUT EFI_PHYSICAL_ADDRESS *Memory + ) +{ + #ifdef MDE_CPU_X64 + + LIST_ENTRY *Link; + EFI_GCD_MAP_ENTRY *GcdEntry; + EFI_GCD_MAP_ENTRY UnacceptedEntry; + EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol; + UINTN Start; + UINTN End; + EFI_STATUS Status; + + // + // We accept n*32MB at one time to improve the efficiency. + // + AcceptSize =3D (AcceptSize + SIZE_32MB - 1) & ~(SIZE_32MB - 1); + + if (AcceptSize =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (= VOID **)&MemoryAcceptProtocol); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + if (Type =3D=3D AllocateAddress) { + Start =3D *Memory; + End =3D *Memory + AcceptSize; + } + + if (Type =3D=3D AllocateMaxAddress) { + if (*Memory < EFI_PAGE_MASK) { + return EFI_INVALID_PARAMETER; + } + + if ((*Memory & EFI_PAGE_MASK) !=3D EFI_PAGE_MASK) { + // + // Change MaxAddress to be 1 page lower + // + *Memory -=3D EFI_PAGE_SIZE; + + // + // Set MaxAddress to a page boundary + // + *Memory &=3D ~(UINT64)EFI_PAGE_MASK; + + // + // Set MaxAddress to end of the page + // + *Memory |=3D EFI_PAGE_MASK; + } + } + + // + // Traverse the mGcdMemorySpaceMap to find out the unaccepted + // memory entry with big enough size. + // + Link =3D mGcdMemorySpaceMap.ForwardLink; + while (Link !=3D &mGcdMemorySpaceMap) { + GcdEntry =3D CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); + if (GcdEntry->GcdMemoryType =3D=3D EFI_GCD_MEMORY_TYPE_UNACCEPTED) { + if (Type =3D=3D AllocateMaxAddress) { + if (GcdEntry->BaseAddress + AcceptSize - 1 > *Memory) { + Link =3D Link->ForwardLink; + continue; + } + } else if (Type =3D=3D AllocateAddress) { + if ((GcdEntry->BaseAddress > *Memory) || (GcdEntry->EndAddress < *= Memory + AcceptSize - 1)) { + Link =3D Link->ForwardLink; + continue; + } + } + + // + // Is the entry big enough? + // + if (AcceptSize <=3D GcdEntry->EndAddress - GcdEntry->BaseAddress + 1= ) { + UnacceptedEntry =3D *GcdEntry; + if (Type !=3D AllocateAddress) { + Start =3D UnacceptedEntry.BaseAddress; + End =3D UnacceptedEntry.BaseAddress + AcceptSize - 1; + } + + break; + } + } + + Link =3D Link->ForwardLink; + } + + if (Link =3D=3D &mGcdMemorySpaceMap) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Accept memory using the interface provide by the protocol. + // + Status =3D MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, Sta= rt, AcceptSize); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + // + // If memory is accepted successfully, remove the target memory space fr= om GCD. + // + CoreRemoveMemorySpace (UnacceptedEntry.BaseAddress, UnacceptedEntry.EndA= ddress - UnacceptedEntry.BaseAddress + 1); + + // + // Add the remain lower part of unaccepted memory to the + // Gcd memory space and memory map. + // + if (Start > UnacceptedEntry.BaseAddress) { + CoreAddMemorySpace ( + EFI_GCD_MEMORY_TYPE_UNACCEPTED, + UnacceptedEntry.BaseAddress, + Start - UnacceptedEntry.BaseAddress, + UnacceptedEntry.Capabilities + ); + } + + // + // Update accepted part of the memory entry to type of EfiGcdMemoryTypeS= ystemMemory + // and add the range to the memory map. + // + CoreAddMemorySpace ( + EfiGcdMemoryTypeSystemMemory, + Start, + AcceptSize, + // + // Hardcode memory space attributes. + // + EFI_MEMORY_CPU_CRYPTO | EFI_MEMORY_XP | EFI_MEMORY_RO | EFI_MEMORY_RP + ); + + // + // Add the remain higher part of unaccepted memory to the + // Gcd memory space and memory map. + // + if (UnacceptedEntry.EndAddress > End) { + CoreAddMemorySpace ( + EFI_GCD_MEMORY_TYPE_UNACCEPTED, + End + 1, + UnacceptedEntry.EndAddress - End, + UnacceptedEntry.Capabilities + ); + } + + return EFI_SUCCESS; + + #else + + return EFI_UNSUPPORTED; + + #endif +} + /** Find untested but initialized memory regions in GCD map and convert them= to be DXE allocatable. =20 @@ -1486,6 +1657,25 @@ CoreAllocatePages ( Memory, NeedGuard ); + #ifdef MDE_CPU_X64 + + if (Status =3D=3D EFI_OUT_OF_RESOURCES) { + Status =3D AcceptMemoryResource (Type, NumberOfPages << EFI_PAGE_SHIFT= , Memory); + if (!EFI_ERROR (Status)) { + Status =3D CoreInternalAllocatePages ( + Type, + MemoryType, + NumberOfPages, + Memory, + NeedGuard + ); + } else { + Status =3D EFI_OUT_OF_RESOURCES; + } + } + + #endif + if (!EFI_ERROR (Status)) { CoreUpdateProfile ( (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0), diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/P= ool.c index 7aaf501600cf..9e8c8611c1ef 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -273,6 +273,20 @@ CoreAllocatePool ( EFI_STATUS Status; =20 Status =3D CoreInternalAllocatePool (PoolType, Size, Buffer); + + #ifdef MDE_CPU_X64 + + if (Status =3D=3D EFI_OUT_OF_RESOURCES) { + Status =3D AcceptMemoryResource (AllocateAnyPages, Size, NULL); + if (!EFI_ERROR (Status)) { + Status =3D CoreInternalAllocatePool (PoolType, Size, Buffer); + } else { + Status =3D EFI_OUT_OF_RESOURCES; + } + } + + #endif + if (!EFI_ERROR (Status)) { CoreUpdateProfile ( (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0), --=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 (#92893): https://edk2.groups.io/g/devel/message/92893 Mute This Topic: https://groups.io/mt/93285612/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-