From nobody Fri Nov 15 12:45:44 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+95802+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+95802+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1667279665; cv=none; d=zohomail.com; s=zohoarc; b=lk/VhYDTzshAOuposIqCyd94BgbA5wl/YbH5lYhfSEQsIFv+0rt3RBA9TzqwKOv14/gbijj7djyVy0huX6QjRQkLb8PI1ZDTNIkVrlLM+ldIXTgvV2UQKf+UVdY200+3+9GxuwoyoUajf1rjf8Ubw/dyr/8xLMPZYNg4PpQWODE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667279665; 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=eUtW5vWPPd1x4qMvAJEnM1mSu+kX6rzAs0yul762ex8=; b=QRTADMlGTd/z8MPcZAjkxBdRNupCmMkvTCTobWXRcrc/HKuPTnnRQNkSLCbSbDGcVtCSsed7ybjUtE6N96fw/NRBObjwka7GDOE+8qq80KaPuK8h3RG56B9/LssvtH8aD2/d/3/JYmroGjD5Rz8tVj4sYLVCjsxYIIAVNigbBTA= 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+95802+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 1667279665248454.48436427037984; Mon, 31 Oct 2022 22:14:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 60YLYY1788612x1lsW94bpsC; Mon, 31 Oct 2022 22:14:24 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.2818.1667279643333273629 for ; Mon, 31 Oct 2022 22:14:24 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="310162816" X-IronPort-AV: E=Sophos;i="5.95,229,1661842800"; d="scan'208";a="310162816" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 22:14:23 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="878985564" X-IronPort-AV: E=Sophos;i="5.95,229,1661842800"; d="scan'208";a="878985564" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.119]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 22:14:20 -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 V5 09/10] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Date: Tue, 1 Nov 2022 13:13:48 +0800 Message-Id: <20221101051349.13-10-min.m.xu@intel.com> In-Reply-To: <20221101051349.13-1-min.m.xu@intel.com> References: <20221101051349.13-1-min.m.xu@intel.com> 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: fL8mTfENe2F0Tysalr4PVD9Hx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667279664; bh=3578AmV4HfEjd9jpa7HHL62FbhoqNYSyJO5827AHRc8=; h=Cc:Date:From:Reply-To:Subject:To; b=b78Pc69qGphstEa5lf6NrqyLmsm6iRxFdWlxH+XXGsaYOLHG7eoyaqqa5DTdYaACXE2 fz+vFKqMcWClweD3VsUdjR6RThFClEes00jdAQFOltZcy2h8tez+bx4x3TwQyzbgbO51z 4olTlqh/1aPgmfUhZAFVgC+5FiT9Yw7Z+RU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667279666523100006 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. Another usage is in SetOrClearSharedBit. If a memory region is changed from shared to private, it must be accepted again. 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 Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- 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 05cfb597dc64..30732f421bb6 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 @@ -279,6 +369,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 3ce8a5c32c98..9793562884c7 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.inf +++ b/OvmfPkg/TdxDxe/TdxDxe.inf @@ -52,6 +52,7 @@ gEfiAcpiTableProtocolGuid ## CONSUMES gEfiMpInitLibMpDepProtocolGuid gEfiMpInitLibUpDepProtocolGuid + gEdkiiMemoryAcceptProtocolGuid =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase @@ -69,3 +70,4 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved + 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 (#95802): https://edk2.groups.io/g/devel/message/95802 Mute This Topic: https://groups.io/mt/94703266/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-