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 2905CAC0AC0 for ; Wed, 8 Nov 2023 04:24:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9STPKLh1IQigvCLDXN5J1AQjxgDmNTvMxxOtc/tU4nA=; 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=1699417477; v=1; b=cXFI3tPeBrL0WHzsP3ds0MPVF8JVBZsL9t9+Nq7bGleguETlEV5J1jCDM2j/VJAAt2CgVObX mHqgc3wV5JM5kU3q0Elw6fECLnY5wFLGRGmTHsjwGERwWZmnIkAn9iUH1r9yzeiapWdInryEbxG YB5d+2EyWla35e1vhtDGs2QA= X-Received: by 127.0.0.2 with SMTP id faHQYY7687511xuU0LxKuwGK; Tue, 07 Nov 2023 20:24:37 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by mx.groups.io with SMTP id smtpd.web11.7151.1699417476540816774 for ; Tue, 07 Nov 2023 20:24:36 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10887"; a="11240855" X-IronPort-AV: E=Sophos;i="6.03,285,1694761200"; d="scan'208";a="11240855" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2023 20:24:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10887"; a="797895475" X-IronPort-AV: E=Sophos;i="6.03,285,1694761200"; d="scan'208";a="797895475" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 07 Nov 2023 20:24:34 -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; Tue, 7 Nov 2023 20:24:34 -0800 X-Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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; Tue, 7 Nov 2023 20:24:34 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.100) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Tue, 7 Nov 2023 20:24:34 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IDKQgE4oZWHHzIfuamgJAGOk8HqQpyOaudZ6EmBDgVqtwhqhhe92E9m85fh5O04qcArYUOIqMwZPcy0OGVJO4UWTdURlGKNNfUm3gtg30yT0QYY/vFUdKucSk8TML6TsR/0cfe9uWQ86oI0Jee50qzXfXCtfbhKvQuyn3FBtlQCOMnGbFSLw2WeWA11zMxx7QspMY3qZmE742zKg2fUzKizMgsuT4GR9ANpsBjZTDRu7hHQviGv73gq9n3Q1g5vMTq7xDtV3ExH6NkbUDHhflZKhIS9Gxe5itawEpr45BeFFMGqdpBIUnIJKXt/fKV1QjIdkgxRzOZKIOWXrVlX5QQ== 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=bCGh+I7KAkxFwLTpkDavCDcOCcdBeXxYbvrVSa8agco=; b=BUzwdfag3NniR+9oElhOVmNkaizhDkHBkCJhH69s/HgfPOEsF1WQwjgBc0NisgNgCsgIwkpQ+8H/KYKvJiaZMz3v0xyHf7WairT9+cRnT2fsTziihT7H1AlbyxtWb1DwV5W/cXrJUQr40krgPt+1SlL3q/4xL6zVFhm/wPIkWbImr9b6X8zGfBFyEUSqh33veiZ9XIg5qB24HuUuzAUEYWmhZRjcOYhpppDKY03Tdx9T2AHpT3LVy0UjsHE3bwgjI8NDR1jQr+RQnyp3dBZA8cFihEjsJoF4jhEiueDpD5R7MZ5FpWH/+26j1z8omf7C8f5UeP7H6qkCW8APMPxS7g== 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 PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.28; Wed, 8 Nov 2023 04:24:26 +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 04:24:26 +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 V2 2/2] OvmfPkg/BaseMemEncryptTdxLib: Handle retry result of MapGPA Thread-Topic: [PATCH V2 2/2] OvmfPkg/BaseMemEncryptTdxLib: Handle retry result of MapGPA Thread-Index: AQHaDWyBzEZnNgHIHEaH8//UsveIbrBv29uw Date: Wed, 8 Nov 2023 04:24:26 +0000 Message-ID: References: <20231102090957.2076-1-cepingx.sun@intel.com> <20231102090957.2076-3-cepingx.sun@intel.com> In-Reply-To: <20231102090957.2076-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_|PH0PR11MB5657:EE_ x-ms-office365-filtering-correlation-id: 331428ed-d8ef-4800-8e25-08dbe012980d 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: 3IaTpRm2v+9XPHGacikrx4Qrf/4O/ke/xs0o2rLGx//3MBxeUHCgC77O5C2qcmGzChz5GvI6I1IZEBD8Ap01RP2iumqPng8nT6wF/6jREiNpcVBUjTlX7pESMfSbXbBazXkzGo+UBzxJN2Js+lBLf3olqk/+eX1rFwHUYKCW9Vj2IqB0085Yoir6nUeXqCINQrEs46MbSSWAwfj2DBdYfp1lyLIOJrrtaEC1WfxR9T7Us2Fmk6s4FaboA0EdWyhgRrYSVfRkQRgfTn0Q7UIt9V1ouRpX3eLv5i5hb10vRlaawHilF37Tgl3rzw7RmO4bD0vrwkCwdgWG4lfQoi8qKCwBDh3yHNitk7rWOq2IqJ6fqFXG1nZzKn+rKzFPjWv3gKJjzRPhTkr2grvTmryEPKy6ngayqdtMPbq87oR8OfOdzKrgOt++w2uojntKUPuTB88ud4PiNVge/cEips2Fsp3Grs9T4Vg2InfEq1gERzbfURI1QCVNgUNA/fP72JLTGQfo5I6GSqsUJw2QGaSm9B+fTG87nPSEM5R6m7Z0WsCx85xhJNDlf6FdYANYdy0nD5sLQX2Dp2Vd/qRZsYwyd/KbgIIWZNLyoWRDtxOS0ZVI3tWVIhFoPOXLKCPr8EvyfallMP+snhMmPYFsIN2y4pmUj19LT5b9n7MMy0H05Fk= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?T/DLwCXLdwpXxvgus8cQiYiN0Dx6QYUUJNLLCN+FvHNfleT8lQxycZqmKOGE?= =?us-ascii?Q?TX7trMASqwBqcNUPHAf3ukrOYi5VLaka2fQzxOwt5ZtXT0wsLof3KlfUX3fp?= =?us-ascii?Q?Ll9bwB+gSBJ8eyCU7+QSqk/jXuQ+Cz9DVRrXfHDW546IJAZbDZENedh+Y1LK?= =?us-ascii?Q?DN4nnt9L2qYrbsVqJxagJKAeGz0+INR8SgSanYVwz5rFxpEH7AWqv8KvuaV+?= =?us-ascii?Q?5SqlZMySxdmKzRnUKzQv8JjuSeexijtmLHA4phgOlxCGkQsM3uzSIlJ/SQnD?= =?us-ascii?Q?4v8lB1s2YJzCEx127z/orGMI5w//gPGlvyeL3czXSXl58aJkw0x0T9151IyR?= =?us-ascii?Q?uraelXvgFjfJgcLZtlhbUzok4mUXvoKd3m835l7n19iyc/irNwlr6k3fjh0i?= =?us-ascii?Q?RenFMRmNJU/0Mf22hxHHZw5I7htfhARkeQP/5bgOPpZohpmPbrH/h6oMslWi?= =?us-ascii?Q?hLU0UuefO3Kw34dxIurF7Ogbp1YeMmnuFcuwl0r9cXCpo15EoclXTjfwLSzA?= =?us-ascii?Q?ADWOxGl0sZrHKFWmzau5h4PBhBXA2FTtWUO+ul0AXLp6He+0iXvDaRubsOdx?= =?us-ascii?Q?fAePnWbMi0VyqG5JtaASZsjcozmrGBRYfhoo5FhVO54JD9jj6YQMoxuIbbIE?= =?us-ascii?Q?2wK1qP3KGKJvcNQOWt/rJQMe8p1iqnlBGom9vTkvPDuCFb77U7crHIB1R5FR?= =?us-ascii?Q?SONlarxGTNINAE3QxMh4CAwgWvVlyeQm7JXihMthRFoPjNo7iHdHN1L0Vf+A?= =?us-ascii?Q?JQmo7Oy8Z8ZWqVp3nNV7GEiPtg/pHyj+wnsoXSWyGML0rBD0pnyJJQVqEbqN?= =?us-ascii?Q?C9LrliguZCwGP2Smnf63TmtBBvkC7aOjIUYc3EIPrSF94eOOIasxtAr/97mV?= =?us-ascii?Q?y8i4eMSiZbc4low6WKi7xH5AVRE+ZiY5Nzx7FPmpswrExRaoyITG+eV1WTjB?= =?us-ascii?Q?VmjLMczOqt+uQIHSwHHw0OXrs1R0r1VuAjsJSFkxJgi5Oe3bntmTYGPZT8yh?= =?us-ascii?Q?0mXbMDT2vnrMXsYux7LI73aULpHemkXTcM1fL4j3WoeALYBYMbA2ATtMd+VS?= =?us-ascii?Q?QjLNJd5j/We0cUWW0jylKUArD6eor4eIC7dknMw5NRuk+PWIh0r06k+vpgIE?= =?us-ascii?Q?OvWpC3N7Ovcmfi6hHXxE9YqhjKOW7f0z5gPyIrgcPKtKtqSVvOh7K+T5w3Im?= =?us-ascii?Q?u086iR84Dlre+34BYQaauZrnmeNOwHZZKmf5JN67NE6oRSXyxVD/eyt4+uwe?= =?us-ascii?Q?altyHnOPthE9PK0Cs6MaOEiUqB4YTYov6Fw7E8ZtJaDHZ1SyVZ+cYbGlYjn3?= =?us-ascii?Q?l3xffmGlleWcTXrUuv/iTo0KTwsiCVJ+ne7N8k+BGSW2BmBaWcphnVyacO63?= =?us-ascii?Q?M5T4vgAwrJGyNm5wszqNdKJwtSO1+IJU+GxobcafWe7P8o5M72N+/YwBEL/D?= =?us-ascii?Q?ApyzJyE/76JOPZR7x+/gxRX1NSSnSQHj8HEh3qN1Pj+D9nI27Csoe8GEoUTh?= =?us-ascii?Q?/KqZhBqRrsvelr/95ceBYtGzVf9bdD3QiG/DiGd8uBWTP1nhGumac7WVMirV?= =?us-ascii?Q?W2klUvww6/PaYFajyH9AEC6PJMoiQ7xgXfIwHsTz?= 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: 331428ed-d8ef-4800-8e25-08dbe012980d X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Nov 2023 04:24:26.7588 (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: z+t3LUnLRP9l1oIURwgUVPZcrjv7jOOwlqHJe/bNd4ighkMP3XaMJkte92cEnisoVbyAzPsab99zkRJS02Tdhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5657 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: 53EWjTczh98U360OkpNEy2J5x7686176AA= 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=cXFI3tPe; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 I think the macro definition (#define TDVMCALL_STATUS_RETRY 0x1) should be= in https://github.com/tianocore/edk2/blob/master/MdePkg/Include/IndustrySt= andard/Tdx.h, together with other TDX definition. Thank you Yao, Jiewen > -----Original Message----- > From: Sun, CepingX > Sent: Thursday, November 2, 2023 5:10 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 V2 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 > --- > .../BaseMemEncryptTdxLib/MemoryEncryption.c | 43 ++++++++++++++++++- > 1 file changed, 42 insertions(+), 1 deletion(-) >=20 > diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > index a01dc98852b8..b9de699a6489 100644 > --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > @@ -38,6 +38,10 @@ typedef enum { >=20 > STATIC PAGE_TABLE_POOL *mPageTablePool =3D NULL; >=20 > +#define TDVMCALL_STATUS_RETRY 0x1 > + > +#define MAX_RETRIES_PER_PAGE 3 > + > /** > Returns boolean to indicate whether to indicate which, if any, memory > encryption is enabled >=20 > @@ -527,6 +531,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 +551,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 (#110895): https://edk2.groups.io/g/devel/message/110895 Mute This Topic: https://groups.io/mt/102337977/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-