From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 81F52740054 for ; Wed, 8 Nov 2023 08:45:11 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=42UFkULYa/8evDgrLohOLMIj3H6Or9ivTu1cWnFks90=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1699433110; v=1; b=IhNbgGnYZnzIA41y55UY44mY4W9KZoAG2kJxHtavV6j/7+S+lBdsieg6RyFhou9DY4aMJ3EJ 9O649KEEBtvT9gXOgsqSOkwsPh9ZdUpa26x9e37kIy6WNkc4+UZ77/jObwNxMOgipOEFFmhCH+Z mXXOPV200zyxsMU8TD1EuPIs= X-Received: by 127.0.0.2 with SMTP id Aad0YY7687511xs6gwirZzE4; Wed, 08 Nov 2023 00:45:10 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.9389.1699433109265209171 for ; Wed, 08 Nov 2023 00:45:09 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10887"; a="374763104" X-IronPort-AV: E=Sophos;i="6.03,285,1694761200"; d="scan'208";a="374763104" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 00:45:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10887"; a="766587024" X-IronPort-AV: E=Sophos;i="6.03,285,1694761200"; d="scan'208";a="766587024" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga007.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Nov 2023 00:45:08 -0800 X-Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 8 Nov 2023 00:45:07 -0800 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 8 Nov 2023 00:45:07 -0800 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (104.47.73.40) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Wed, 8 Nov 2023 00:45:07 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hPYH9Ftq+47yHgtvWlOJSonOAltP0JdU3BGphVRBKpUFxXURGGY9K0AQjZn4RLkl6eY38tpm5ERcsXvUGcS2lBhoQujK4oZxeacUi+5ritePVZ6jMCUBgFASBnd93u3MqI5YohudKZ2V0m9f9nOuKSrkMkTJppV2op1ZNrSFJNSfQQhycuWZ3PGAdN79/Lo0tS1EgqGS2Du6wc2PwEQwiZArk5DbrIkADNn+7vfrdPPWz7KudHkms2R98CwPVCk07sQxVgea2XGh27WSu4Xu3O+TSbQNF/IjYb4PwxYDKqDqrNr+BwWHSVU17ldKmv/qWta/SV0Ck36v5dTmInhjXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lzW2OYgCE48qKdN8c0bRateJB9Y/Hfbr1eA1T0r0teY=; b=fakphXA4GMfKGjGGuqqMFRxjZ1SX0t5w9oanAsMbbCswehx49CaGkSWjMA4hzKN5agX3ct3CEQK0jvDsazKdqTvNswPu97+4oJ1XfAOCN39CHYp1bKwPoKo+YoGhwrRlmJ8LOOsDxt4kGm0A0nK2CMDjH2XeQyYaxkS8mizQ5LBx2LnhsHTgG1rMRibrsv6my9jk/XNR3G9IjTqTYi6e6BjZBc45Tui+iFb2HsojmdYPZ4i4k0JQRwnB9ctye6OLt2HM9vnNhBhf5NdC7tUmnw0t4cT84EXgOvEZhHcH7LTrK9m4xStvIIrozPS8jI/1TPsBRjYjcwiHOLa3loBYpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by IA1PR11MB6124.namprd11.prod.outlook.com (2603:10b6:208:3ec::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.27; Wed, 8 Nov 2023 08:45:05 +0000 X-Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::2f2f:41ab:b556:7257]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::2f2f:41ab:b556:7257%3]) with mapi id 15.20.6954.027; Wed, 8 Nov 2023 08:45:04 +0000 From: "Yao, Jiewen" To: "Sun, CepingX" , "devel@edk2.groups.io" CC: "Aktas, Erdem" , James Bottomley , "Xu, Min M" , Tom Lendacky , Michael Roth , Gerd Hoffmann Subject: Re: [edk2-devel] [PATCH V3 2/2] OvmfPkg/BaseMemEncryptTdxLib: Handle retry result of MapGPA Thread-Topic: [PATCH V3 2/2] OvmfPkg/BaseMemEncryptTdxLib: Handle retry result of MapGPA Thread-Index: AQHaEh68wEV2F1LzLkOJ5am8GEkI67BwGuAA Date: Wed, 8 Nov 2023 08:45:04 +0000 Message-ID: References: <20231108083203.1417-1-cepingx.sun@intel.com> <20231108083203.1417-3-cepingx.sun@intel.com> In-Reply-To: <20231108083203.1417-3-cepingx.sun@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5872:EE_|IA1PR11MB6124:EE_ x-ms-office365-filtering-correlation-id: 4352580d-8843-4a45-a16a-08dbe03700da x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: I6QIvuVMW9qol1j+qEimOMpamoDL1Q9JP6q679WpZvB9ahSJLtxN89bE1toIEuGxFP1vO9aJEOMaBiqH+mZ5qPTJ0kiT6KKSNr7rnBGlvprSJZrodTnQreODfoeArSSE2J5J5JTD+e8IZs3DBSTVV2KZWDb8WMysisI+I6BVBocxs2GLSim4i06TPrV0XGZBt2532OQeyaBuOW5y5LJQnkxdWO4v7gMQddQQI27WLqrQ1pA+kEAK5t6FU8zH82sMWEiyL+LmTbMgdmg8etmcXmqzZCKuxWWaE8aIjWE53grTmLw328nvpMX8cV00Sl2EJQ/jNCX6FzEfA5a1ScU2N0md/qIIcBuEn4Cps9iFjY6tK+DDd5PCkeyYHgfwdyKuLeEGnXXHkbtF4YaKXDfFUzF7YU2I8GtoDVywObNXG0K0ZR7Tlt0ldOwQBF+PFgXhTy2BwrN3ldSdVyKgZoHek+RDcj2rsTeYgqi3C3oCwlREEprmPmUDXV83uklrPdNLracJZQnKh/4KKp/NY1DxZS5jJWSGrbh07WVI710UQM6QbLOPsipxeldtktZfmVL7NrIW8wsONAnOd7TrA51BkOl17N/3LR69lY5NSSL/SfpQEJL3QXJNUB5x1Qfbzx+tGunW7QjvjkA9P4TOcKjLl0u74sZHzRezLQWJdF4/Dio= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?8CRay1tQ41hr36TR92pXB0S8QQpyQgPwj7q5jip/erWcrc1JVhPmtRdcyAaR?= =?us-ascii?Q?41qtFzhq8fPYD/sjSlwVdWAJ596t9xZPi4odjSiwBBakIPTr6P1Ba7G4/BXi?= =?us-ascii?Q?tQ84QvyRNXynSkPJW8u7b4f26AVm5nGJPpxbnPSnGILIQC/ms2g1pU4Iff3o?= =?us-ascii?Q?rASjm0IufP9H2V34u8GKLW3Sor9pfBB4qnHy5cDxl5/ru5nkb/pHuKMZtwA2?= =?us-ascii?Q?hJtpP6m/uDLOi5+8x86Ycf/wRN+JZgxYLynJgGIqbjCw2iIFJ8xQZNUtYFXl?= =?us-ascii?Q?Ud3Evy6V0AG2Bp4fhcJP4KcKz4WjfBVo2L/AiwnTy7Yuvev67VwP7ocOQfPe?= =?us-ascii?Q?aL0fWde7S4aM7T9fI/djD2RoRBD74dgfyvjeb4YTFTt5CS2JOTX06SA+c3jg?= =?us-ascii?Q?5TehJhgv/wZPrmTsM8n5mNmfkPW1oSbWkTmO066ZNKzfN/hHw3KJ1GZrK8AB?= =?us-ascii?Q?VasbqljxXdhUqRQ6Li/1ft2CPXqDpzMPYrUeBiaHAA+ugp3tdwK+dKIpDwAI?= =?us-ascii?Q?ZFdYmMjDAl5MnDb4BAAy4aCv2IqErNGceoAwCqP78EAbpd+5+/YQ5c9vejVw?= =?us-ascii?Q?3gIMdWM7oGRKGNkn1+Eh+Wb/SdR/HAqzOfZNrp8mqcTgaPsUSBhYNnlQQjpV?= =?us-ascii?Q?uAEu8FTc0teWLVtb868mR2WWkhYixJ12VqRTKsQpNv6KbahtqIqpb6eR4X1w?= =?us-ascii?Q?qWA2pylcg4Oq9CqGqWbJZ+xwXzCDP880uyRKvO0/EiocfgRlHUDBA8IvFB/O?= =?us-ascii?Q?8tNQgEST63dZludpeVWiC/md5CbzzERmbWxtA1oxYV/e+9P/vNbUTp0zkU2L?= =?us-ascii?Q?k1M+9P7/oXMn+C99WTxNFWUURIMKgQVFJtCcwMlhX6V50KkV6LzhkN8qEz0L?= =?us-ascii?Q?4y8p8RYgW3wpDUAQzPuUJq8rz5z8BAqf1RGps/uiNnCKPxnqyWlbUR0LXTnB?= =?us-ascii?Q?g2w5KVMndSGPwrI+TrJqrQjB8hMpwN4hVo9jsLIM11Oy5OeMxoLw9Z8snxxy?= =?us-ascii?Q?jDWmaoiESbKMStrLLUXn/ip419N/b5M/oaqbYBvNBtaomc5yptsEuPsqwEJ2?= =?us-ascii?Q?bGKUxz3dZoNhu6Dq0x2WQrt81VldCURocLe/nGMOGSm/kXTpHBJUGyaFfPwi?= =?us-ascii?Q?B6L1m4FRnCLuKUR2QBKLFDxXfedJjuoMEGQi0E7sA6N2ugCdRNJJve6ZGh5/?= =?us-ascii?Q?0Bhj2O7rlhv88wKRSPybzbM8dRTC4yQPP0akvGux1TOBU3o5VYJG3pjz1N9w?= =?us-ascii?Q?Mx/vMBCF/4TG71jrW8fEKiOpZb0gTWzYnClzuDhw2d0PYLqP1l10QI3WrYCT?= =?us-ascii?Q?q37G36/p8sMS4w4EwDRUPvY8TuMnf0DDS9/jhAdbMpHWURYlnm8olKVuVFuB?= =?us-ascii?Q?duvYOHJ/aa0za3pKIbJ1h4jHgN8AUunzTrFlGkzbewTm1hnOT7UAtJ6pqG4O?= =?us-ascii?Q?jinD4kfu+pvO9rGcQHBWmk0MQDClWZHDHCaWwJPyc0voQNAgqrcBScjO3Kz3?= =?us-ascii?Q?gLkmRGD0TueHneQ/5c128wsneYt90+K3En5GVCjbOocc8rqmFBmlz+LAXzlb?= =?us-ascii?Q?iM07YzgAr+lS2AzjyRkRbOC2wTquutE81n1FYRRs?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5872.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4352580d-8843-4a45-a16a-08dbe03700da X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Nov 2023 08:45:04.4884 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DEW7SbiJ0VhSL9D4b5J+8jWMFHG0k4UWPQKqDRXiOteAV/G4IJwvxy4F0f8hXhVp65YDAekCozwzvtpL/+n0cA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB6124 X-OriginatorOrg: intel.com Precedence: Bulk 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,jiewen.yao@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gyFwQTziTfKa3BV7qAQx2qzHx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=IhNbgGnY; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Hey Ceping Please don't change two packages in one patch, because it is hard to let th= e corresponding maintainer to review and give R-B, if he/she only reviews p= art of them. The patch should be split to MdePkg update and OvmfPkg update. Thank you Yao, Jiewen > -----Original Message----- > From: Sun, CepingX > Sent: Wednesday, November 8, 2023 4:32 PM > To: devel@edk2.groups.io > Cc: Sun, CepingX ; Aktas, Erdem > ; James Bottomley ; Yao, > Jiewen ; Xu, Min M ; Tom > Lendacky ; Michael Roth > ; Gerd Hoffmann > Subject: [PATCH V3 2/2] OvmfPkg/BaseMemEncryptTdxLib: Handle retry result= of > MapGPA >=20 > From: Ceping Sun >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4572 >=20 > According to section 3.2 of the [GHCI] document, if the return status > of MapGPA is "TDG.VP.VMCALL_RETRY", TD must retry this operation for the > pages in the region starting at the GPA specified in R11. >=20 > In this patch, when a retry state is detected, TDVF needs to retry the > mapping with the specified address from the output results of TdVmCall. >=20 > Reference: > [GHCI]: TDX Guest-Host-Communication Interface v1.0 > https://cdrdv2.intel.com/v1/dl/getContent/726790 >=20 > Cc: Erdem Aktas > Cc: James Bottomley > Cc: Jiewen Yao > Cc: Min Xu > Cc: Tom Lendacky > Cc: Michael Roth > Cc: Gerd Hoffmann > Signed-off-by: Ceping Sun > --- > MdePkg/Include/IndustryStandard/Tdx.h | 2 + > .../BaseMemEncryptTdxLib/MemoryEncryption.c | 41 ++++++++++++++++++- > 2 files changed, 42 insertions(+), 1 deletion(-) >=20 > diff --git a/MdePkg/Include/IndustryStandard/Tdx.h > b/MdePkg/Include/IndustryStandard/Tdx.h > index 81df1361842b..2662761883e5 100644 > --- a/MdePkg/Include/IndustryStandard/Tdx.h > +++ b/MdePkg/Include/IndustryStandard/Tdx.h > @@ -103,6 +103,8 @@ > #define TDVMCALL_REPORT_FATAL_ERR 0x10003 > #define TDVMCALL_SETUP_EVENT_NOTIFY 0x10004 >=20 > +#define TDVMCALL_STATUS_RETRY 0x1 > + > #pragma pack(1) > typedef struct { > UINT64 Data[6]; > diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > index a01dc98852b8..a71b1efbca7a 100644 > --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > @@ -38,6 +38,8 @@ typedef enum { >=20 > STATIC PAGE_TABLE_POOL *mPageTablePool =3D NULL; >=20 > +#define MAX_RETRIES_PER_PAGE 3 > + > /** > Returns boolean to indicate whether to indicate which, if any, memory > encryption is enabled >=20 > @@ -527,6 +529,13 @@ SetOrClearSharedBit ( > EFI_STATUS Status; > EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol; >=20 > + UINT64 MapGpaRetryAddr; > + UINT32 RetryCount; > + UINT64 EndAddress; > + > + MapGpaRetryAddr =3D 0; > + RetryCount =3D 0; > + > AddressEncMask =3D GetMemEncryptionAddressMask (); >=20 > // > @@ -540,7 +549,37 @@ SetOrClearSharedBit ( > PhysicalAddress &=3D ~AddressEncMask; > } >=20 > - TdStatus =3D TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, > NULL); > + EndAddress =3D PhysicalAddress + Length; > + while (RetryCount < MAX_RETRIES_PER_PAGE) { > + TdStatus =3D TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, = 0, > &MapGpaRetryAddr); > + if (TdStatus !=3D TDVMCALL_STATUS_RETRY) { > + break; > + } > + > + DEBUG ((DEBUG_VERBOSE, "%a: TdVmcall(MAPGPA) Retry PhysicalAddress > is %llx, MapGpaRetryAddr is %llx\n", __func__, PhysicalAddress, > MapGpaRetryAddr)); > + > + if ((MapGpaRetryAddr < PhysicalAddress) || (MapGpaRetryAddr >=3D > EndAddress)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: TdVmcall(MAPGPA) failed with MapGpaRetryAddr(%llx) less tha= n > PhysicalAddress(%llx) or more than or equal to EndAddress(%llx) \n", > + __func__, > + MapGpaRetryAddr, > + PhysicalAddress, > + EndAddress > + )); > + break; > + } > + > + if (MapGpaRetryAddr =3D=3D PhysicalAddress) { > + RetryCount++; > + continue; > + } > + > + PhysicalAddress =3D MapGpaRetryAddr; > + Length =3D EndAddress - PhysicalAddress; > + RetryCount =3D 0; > + } > + > if (TdStatus !=3D 0) { > DEBUG ((DEBUG_ERROR, "%a: TdVmcall(MAPGPA) failed with %llx\n", > __func__, TdStatus)); > ASSERT (FALSE); > -- > 2.34.1 -=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 (#110907): https://edk2.groups.io/g/devel/message/110907 Mute This Topic: https://groups.io/mt/102460273/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-