From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.8679.1674018804099277849 for ; Tue, 17 Jan 2023 21:13:24 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=f2fEdh/v; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: jiewen.yao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674018804; x=1705554804; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ciinbU3xHGK4sqYXVJKChXjc2U/QPYHoqm/rnKXaQfE=; b=f2fEdh/vUNeOGDP3K/SZ61ULkrRP8Z+FkJ4aA4hU+t4CM5vFHA5sSamq U/nSQ8skyO86YDxR7j1kwq9IJ4haqckf+fRmMTEmj485tRr7DvLtuEDgK HszK9ZayHMsOwlpMn3+x8idvYldzzpJZFR3jmhZ+OTkCwnUG6Cz7W8tDN Yx/4M/Ijr+St1AxmCwsd8H6CYLqM69EE5ADzPoJIm2sC2DP2fkxi2bdMa 86GDzFK/ufzUVP8GyARMxHgCBf4J9LEe1l9Cixg8dJAijFfv11nQEQ62C JGUwEVYufeClsQ5i45Zt6s1nJA6yGOYsk3gqdNJJn2MjbXK6QMj6wFdSx w==; X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="322589714" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="322589714" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 21:13:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="904920782" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="904920782" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga006.fm.intel.com with ESMTP; 17 Jan 2023 21:13:15 -0800 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.16; Tue, 17 Jan 2023 21:13:15 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) 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.16 via Frontend Transport; Tue, 17 Jan 2023 21:13:15 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Tue, 17 Jan 2023 21:13:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M7OCMr2nM1VTZ3pbBUrrKYy6iL7Bj93nH0eW/ZyafglHlx92Y5NOPOsDGcrzdhE1jZDiiy9hzlUmJ5aEL5eV93/hRG/eYLtd2rqneEJLiCqV4GS50adafwDPCWsEw8oxR+5AyiNBPv7G7mpeWDzA/fhpwxqKrvqixT9pxID4BpaCZXRjsiZzblXHV2Z7iWDDQmJglR8tLLr/guYrx/DpLpCbzsVA0ES1COgiXso4gUbTJEJDvFL/2UYpFA6A5cBprNrSCIIlS+2q9+iVlf4iIzpv6pqNul25M2b9CMiGvXC5vJpd+wqBlK4sTmUVs6Vl4rTg8F8uROpnPOLQObjkXQ== 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=VQDNtOXGjDz8Yxto8s3xku6dAyfk7iHT64VKUeGsyHQ=; b=dd8njTWg2giUfD8R4nQx47FJebm8WbPSPGyj2Rw0wLX6rSV6V2ua+xisNiZpOs7kERDEp3hC060DoawAtaz0zzvVJg26Lf0Tj1J6ltFtq/UMef05J16A1FIUdbBvRWctrjGsPeOLKB2XHKzdN6l9Bu87ZERhy5YEGj2m3VRVBxuv9sQZi983OeKKbwTpOsoYQqeYGCut6ZVK4OWN16XSBHByVvEXbiZtWUjKQ/bZRUAYIJr2Xa5LpTBkrP5FeXAMR/ikefyFYjuXjeDMf8wg6cqBbx1mt2KydeFR8LdPEHPMZUcoagD/AZ/yMytCvv5CHVONntEnG3viuddbpPVHmQ== 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 Received: from MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by MW3PR11MB4587.namprd11.prod.outlook.com (2603:10b6:303:58::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.23; Wed, 18 Jan 2023 05:13:11 +0000 Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::5f56:1bdc:2eae:c041]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::5f56:1bdc:2eae:c041%7]) with mapi id 15.20.6002.013; Wed, 18 Jan 2023 05:13:11 +0000 From: "Yao, Jiewen" To: "devel@edk2.groups.io" , "Yao, Jiewen" , "Xu, Min M" CC: "Aktas, Erdem" , James Bottomley , Gerd Hoffmann , Tom Lendacky , Michael Roth Subject: Re: [edk2-devel] [PATCH V2 1/1] OvmfPkg/BaseMemEncryptTdxLib: Refactor error handle of SetOrClearSharedBit Thread-Topic: [edk2-devel] [PATCH V2 1/1] OvmfPkg/BaseMemEncryptTdxLib: Refactor error handle of SetOrClearSharedBit Thread-Index: AQHZKs7VcFF8vmH3SUKefKDdr8h7ma6jTloggABTF1A= Date: Wed, 18 Jan 2023 05:13:11 +0000 Message-ID: References: <20230117235232.242-1-min.m.xu@intel.com> <173B3F0145D7A22F.14781@groups.io> In-Reply-To: <173B3F0145D7A22F.14781@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5872:EE_|MW3PR11MB4587:EE_ x-ms-office365-filtering-correlation-id: 413dd5ac-4a1a-40c9-6b42-08daf912b1c3 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GFW8IM8BTX6N8lTp7YrrZcgekh3+6ifbBm4QMWZr2kGny4lCumv7HO5g0jyBjBHGZGNPv8ZbeUB1GKjNoteNjWIGL8epWum5pBydDzgWEsa0y0/2sl/1gyxnMbMBnxoJjzxUOQ/1ixARbgRffld5vO3e6lI9NQJLMcYStt6/twmYZG+PLcgTeLhM3+aBL5yi02NbRWWiLWfqP+gm0gJtuOy54rwApKiH3R3DUnnR0SoVXcVpcsi0oeRE0qYs1gmfid+u635xHkSusYyFJgQ7vE9KyeoqSsTsEOAKFS813TT4qgk0na1G852/ws2tYBi7kyq18Ggs7TKm5kRE9YLv/jxwxOXNE1jsW6PjYoiuwMdz9e/gw3jWoOgn1sXrF7LbunPTCMg1tEU43b+hZyYafKO7BfkFKQakIWQP6/mFb5TYnkn+Z4EE5nuC69/Yn44pfmhONvl1XbOid9Qkv1DUm1ypJBpcWx+oLazft/rNjW1hDpiZtTk5JnA4I54cawyVmAQ2j6VppYjAxwBeKntJYZ8jJdiRdPlNIp0wyRhhFkqrBUvS99Rh2kRk/2UQpDfDB7ysFLa+Cota8jPmiXJhEomnq9PmsvVh+DrETgJdEzZu3iEDWzG2o37rGRu1L252oN+mjD8BTtI6l+BtUxTctGaqOmbeBXGj1JB5PiVrVbTOYZ/imp0DlgLGnUsnhPPKT/2A75BM1rSgFshWrdSROeJC0R7dzcV8+uvxO/13dslNJ3W+U7oIB+4p1Qblury+QsWDr0zbQuqCt8un0cgO5JffJ6LQJicSFWN4BzH45O0= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5872.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(6029001)(366004)(39860400002)(376002)(396003)(136003)(346002)(451199015)(66899015)(8676002)(38070700005)(86362001)(8936002)(5660300002)(66476007)(4326008)(76116006)(52536014)(66946007)(66556008)(66446008)(64756008)(55016003)(2906002)(38100700002)(82960400001)(83380400001)(33656002)(122000001)(478600001)(316002)(7696005)(966005)(54906003)(110136005)(6636002)(71200400001)(41300700001)(53546011)(26005)(9686003)(186003)(6506007)(213903007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Kv0vDgEWz2NYd3JJ8w/kGefdaP0057xxZRFROgIQi/WHWbk9m1OgYFHvBeCP?= =?us-ascii?Q?g0GZsezO++zMypWA2rSoT6uOtbO1jyd1O06gq8pIxHYvBNiWb4qxxCSPgJHR?= =?us-ascii?Q?7LeDQNEWXj8TFeniN9q3vFBo8ijCp+kCHo55c25eYjdA15EQr8HEEaifNv+y?= =?us-ascii?Q?EuLgncYFwmIzv6EAplCn7QN8pTBOLlSwphZq04MPEJ0ybVAFDfFwS8e7uww4?= =?us-ascii?Q?/IrhhWAM7ZC2xIVXf3Bv6OeaI6Hy+zWn34BIPwFOzyN1PLUpglXiDVBe9JGW?= =?us-ascii?Q?h9pfzrar+t5wCLoYyKDpitLXrGVh+ElSL7ZygI9qzuDAe5SMxnsnSc0sb+b8?= =?us-ascii?Q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fYueUFAuwukNEV0sRovN8?= =?us-ascii?Q?ydlIjX+y4pjoGdiqHkOCCoT+jWDdUPVyCxFRbJY9FIbbqWa0gaekdLASdXD9?= =?us-ascii?Q?KqjdcIs7i/5278MjhNMHWW4zwGQDgu8TatSWIdd03PxGLGiAcgPD8/Qhlxit?= =?us-ascii?Q?fxpIkeMN1UBjJTaeV1NsRU5dUkMRirYkZdnb2PV8Yigwm/hEwiDS3ndqO6ts?= =?us-ascii?Q?AmwnZf17jCabIrpwr+usYQfFRU43TSMHWL0AXpQK4Rypj7YxeNvhTbAYupcA?= =?us-ascii?Q?QG3eG/SeMqkQPqs4T599HpcJPA7om0+G8DBunJ3XRRv6Jye3Lw0izWc6DYdr?= =?us-ascii?Q?0kGKYWap8qqvCQLh/NwMdE6JTV8vyQDFPVTxD8S2?= 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: 413dd5ac-4a1a-40c9-6b42-08daf912b1c3 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2023 05:13:11.2979 (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: Fx0OgImDpvw0Fs8r0fMUJc053PYggswND5WeJGuqqBMVAt18i4kS45+G+vuMzO4h3lQE9J7w+k/Jq7c7N33uLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4587 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Merged https://github.com/tianocore/edk2/pull/3921 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Yao, > Jiewen > Sent: Wednesday, January 18, 2023 8:16 AM > To: Xu, Min M ; devel@edk2.groups.io > Cc: Aktas, Erdem ; James Bottomley > ; Gerd Hoffmann ; Tom > Lendacky ; Michael Roth > > Subject: Re: [edk2-devel] [PATCH V2 1/1] OvmfPkg/BaseMemEncryptTdxLib: > Refactor error handle of SetOrClearSharedBit >=20 > Reviewed-by: Jiewen Yao >=20 > > -----Original Message----- > > From: Xu, Min M > > Sent: Wednesday, January 18, 2023 7:53 AM > > To: devel@edk2.groups.io > > Cc: Xu, Min M ; Aktas, Erdem > > ; James Bottomley ; Yao, > > Jiewen ; Gerd Hoffmann ; > > Tom Lendacky ; Michael Roth > > > > Subject: [PATCH V2 1/1] OvmfPkg/BaseMemEncryptTdxLib: Refactor error > > handle of SetOrClearSharedBit > > > > From: Min M Xu > > > > The previous implementation of SetOrClearSharedBit doesn't handle the > > error correctly. In this patch SetOrClearSharedBit is changed to return > > error code so that the caller can handle it. > > > > Cc: Erdem Aktas > > Cc: James Bottomley > > Cc: Jiewen Yao > > Cc: Gerd Hoffmann > > Cc: Tom Lendacky > > Cc: Michael Roth > > Reviewed-by: Jiewen Yao > > Signed-off-by: Min Xu > > --- > > .../BaseMemEncryptTdxLib/MemoryEncryption.c | 48 +++++++++++++++-- > -- > > 1 file changed, 40 insertions(+), 8 deletions(-) > > > > diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > > b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > > index 503f626d75c6..5b13042512ad 100644 > > --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > > +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c > > @@ -510,8 +510,11 @@ Split1GPageTo2M ( > > @param[in] PagetablePoint Page table entry pointer (PTE)= . > > @param[in] Mode Set or Clear shared bit > > > > + @retval EFI_SUCCESS Successfully set or clear the = memory > > shared bit > > + @retval Others Other error as indicated > > **/ > > -STATIC VOID > > +STATIC > > +EFI_STATUS > > SetOrClearSharedBit ( > > IN OUT UINT64 *PageTablePointer, > > IN TDX_PAGETABLE_MODE Mode, > > @@ -520,7 +523,8 @@ SetOrClearSharedBit ( > > ) > > { > > UINT64 AddressEncMask; > > - UINT64 Status; > > + UINT64 TdStatus; > > + EFI_STATUS Status; > > EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol; > > > > AddressEncMask =3D GetMemEncryptionAddressMask (); > > @@ -536,16 +540,30 @@ SetOrClearSharedBit ( > > PhysicalAddress &=3D ~AddressEncMask; > > } > > > > - Status =3D TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, > > NULL); > > + TdStatus =3D TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, = 0, > > NULL); > > + if (TdStatus !=3D 0) { > > + DEBUG ((DEBUG_ERROR, "%a: TdVmcall(MAPGPA) failed with %llx\n", > > __FUNCTION__, TdStatus)); > > + ASSERT (FALSE); > > + return EFI_DEVICE_ERROR; > > + } > > > > // > > // If changing shared to private, must accept-page again > > // > > if (Mode =3D=3D ClearSharedBit) { > > Status =3D gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, N= ULL, > > (VOID **)&MemoryAcceptProtocol); > > - ASSERT (!EFI_ERROR (Status)); > > + if (EFI_ERROR (Status)) { > > + DEBUG ((DEBUG_ERROR, "%a: Failed to locate MemoryAcceptProtocol > > with %r\n", __FUNCTION__, Status)); > > + ASSERT (FALSE); > > + return Status; > > + } > > + > > Status =3D MemoryAcceptProtocol->AcceptMemory > (MemoryAcceptProtocol, > > PhysicalAddress, Length); > > - ASSERT (!EFI_ERROR (Status)); > > + if (EFI_ERROR (Status)) { > > + DEBUG ((DEBUG_ERROR, "%a: Failed to AcceptMemory with %r\n", > > __FUNCTION__, Status)); > > + ASSERT (FALSE); > > + return Status; > > + } > > } > > > > DEBUG (( > > @@ -558,6 +576,8 @@ SetOrClearSharedBit ( > > Mode, > > Status > > )); > > + > > + return EFI_SUCCESS; > > } > > > > /** > > @@ -747,7 +767,11 @@ SetMemorySharedOrPrivate ( > > // If we have at least 1GB to go, we can just update this entry > > // > > if (!(PhysicalAddress & (BIT30 - 1)) && (Length >=3D BIT30)) { > > - SetOrClearSharedBit (&PageDirectory1GEntry->Uint64, Mode, > > PhysicalAddress, BIT30); > > + Status =3D SetOrClearSharedBit (&PageDirectory1GEntry->Uint64,= Mode, > > PhysicalAddress, BIT30); > > + if (EFI_ERROR (Status)) { > > + goto Done; > > + } > > + > > DEBUG (( > > DEBUG_VERBOSE, > > "%a:%a: updated 1GB entry for Physical=3D0x%Lx\n", > > @@ -809,7 +833,11 @@ SetMemorySharedOrPrivate ( > > // If we have at least 2MB left to go, we can just update this= entry > > // > > if (!(PhysicalAddress & (BIT21-1)) && (Length >=3D BIT21)) { > > - SetOrClearSharedBit (&PageDirectory2MEntry->Uint64, Mode, > > PhysicalAddress, BIT21); > > + Status =3D SetOrClearSharedBit (&PageDirectory2MEntry->Uint6= 4, > Mode, > > PhysicalAddress, BIT21); > > + if (EFI_ERROR (Status)) { > > + goto Done; > > + } > > + > > PhysicalAddress +=3D BIT21; > > Length -=3D BIT21; > > } else { > > @@ -856,7 +884,11 @@ SetMemorySharedOrPrivate ( > > goto Done; > > } > > > > - SetOrClearSharedBit (&PageTableEntry->Uint64, Mode, > PhysicalAddress, > > EFI_PAGE_SIZE); > > + Status =3D SetOrClearSharedBit (&PageTableEntry->Uint64, Mode, > > PhysicalAddress, EFI_PAGE_SIZE); > > + if (EFI_ERROR (Status)) { > > + goto Done; > > + } > > + > > PhysicalAddress +=3D EFI_PAGE_SIZE; > > Length -=3D EFI_PAGE_SIZE; > > } > > -- > > 2.29.2.windows.2 >=20 >=20 >=20 >=20 >=20