From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.7409.1639642302885722940 for ; Thu, 16 Dec 2021 00:11:43 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=nmuDnkuf; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1639642302; x=1671178302; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=4kQ600zXUGVPajUV2fAneQ2g+IYGQlQSseR9h4bcg38=; b=nmuDnkufGcCmpO1hOIm9FQa3HLjIs2osJ7krhs0zUoP4CDe87AQOP8Eu O4sB5mKdumJx5wIjCsF9q/pw0/v9V10BuHy8ba1wVK+3oKTo3jjXpxrS5 aIhAvdCZaTlbFCH6lGRVJiM+1X0y3OMA+kKvBNm+PeOpl/QTvQDO6Kr+a BGE6RxM53Q/EvfrfA1TYO74pRIQX+yPPuZX/rDEDYVEEyM4ynRjfoZjVg wwaUx1JPMOf5hAfnQPcZNYD6ZTIfbhp3p4SUJ1Y1BEPpbpFr2IkmCFULg Xf6nH1QodMjailTDwOW61CluEuQGvPkL85j2VcEZ1L7/o3jHyfusZ9TWB A==; X-IronPort-AV: E=McAfee;i="6200,9189,10199"; a="226713959" X-IronPort-AV: E=Sophos;i="5.88,210,1635231600"; d="scan'208";a="226713959" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Dec 2021 00:11:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,210,1635231600"; d="scan'208";a="615062660" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga004.jf.intel.com with ESMTP; 16 Dec 2021 00:11:42 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 16 Dec 2021 00:11:41 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Thu, 16 Dec 2021 00:11:41 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.177) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Thu, 16 Dec 2021 00:11:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q86tvXqKNbyKEGeSpG1LKRspfuecmROAS9Z5q2nwa3d+iEBnK4nPgznUPf4N6bX3ckvZ5JIOH/5+ogn/IGDH2iWQQxQ3l4jgBTEZrHiqHD17ipDmurEy1kGmOkLtZ7VXG/mSGPLz/N8Vqn0yPmtKeo4EoSuwFZQtV67vxiKMg6O0IBKFMlp4RS4B2D74ekexMC1D1teKDxvwgK3IgncisAaYkPwTz+tifvKNO9Qmcmxa4fwmnH39W6xNvTPnovOLPu8oolve0WKAM59tv/AqczT6xi+CdtqOFaVoZpY3evVgKg/pFWGHO4L1krzTGpWiWp5kivzPGPtwHQaBcIsDNQ== 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=xpajI+FPbKvIV934MJlC5KjAxTtT/cEyrrT//o2tLtU=; b=AqgkZyms7MyTW8MQzUshbNOCi7yNqA9tynaFxHSgXiMclvaOxN7tlbtUx0ElIQ4pcGPhiWjA4KHU/JRbevBfMIDtjYEfDKeZzFuK837gAncfyG8fS6Q8JJwGf89fQ+zeHyDg1Y+YF+6YAkn/WaTjVF5CU9QSKAQbZD1OwHisbN0a9pE8PBJMoGd2343vrvbdfqGle5tlB5TAI0zdbfZW3S5+9pbLAcNjN45CP/NhIubUBGA+xgQQbdnlxo0CpiHcndUgvNcQPY2cTDVEY9/eaCWeF4gjB6S8aOdEzkVGfpvxXaDb4280XO+QW5euQ67myX8/rA0AFkru58POSW8lBA== 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 PH0PR11MB5064.namprd11.prod.outlook.com (2603:10b6:510:3b::15) by PH0PR11MB4919.namprd11.prod.outlook.com (2603:10b6:510:34::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Thu, 16 Dec 2021 08:11:40 +0000 Received: from PH0PR11MB5064.namprd11.prod.outlook.com ([fe80::fd42:b334:5030:af8d]) by PH0PR11MB5064.namprd11.prod.outlook.com ([fe80::fd42:b334:5030:af8d%6]) with mapi id 15.20.4778.018; Thu, 16 Dec 2021 08:11:40 +0000 From: "Min Xu" To: "devel@edk2.groups.io" , "kraxel@redhat.com" CC: Ard Biesheuvel , "Justen, Jordan L" , Brijesh Singh , "Aktas, Erdem" , James Bottomley , "Yao, Jiewen" , Tom Lendacky Subject: Re: [edk2-devel] [PATCH V4 17/31] OvmfPkg: Update Sec to support Tdx Thread-Topic: [edk2-devel] [PATCH V4 17/31] OvmfPkg: Update Sec to support Tdx Thread-Index: AQHX8CE/4NH+8gDBT0y8gKw4vKbzu6wzOHsAgAGHFNA= Date: Thu, 16 Dec 2021 08:11:39 +0000 Message-ID: References: <1ecb7543dda024e55e9f7a0253b0af0c610407c4.1639399598.git.min.m.xu@intel.com> <20211215081842.stsakfl3ub3thycu@sirius.home.kraxel.org> In-Reply-To: <20211215081842.stsakfl3ub3thycu@sirius.home.kraxel.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b55b7348-00af-4f90-80b7-08d9c06bb042 x-ms-traffictypediagnostic: PH0PR11MB4919:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xdcfFBSNasLQXBwkgiTrolidOPcOm0lWzUL5wA1BLM6pFWv7iIKGGgAjEzxltflfEo8FHsq/2iaJTXOGR2BZ3Tlx/grKpq12hTElJYH6z2Fi1t67UFYef/EPsgMpiwowywofuzm8vDMi9ss1fTG3hiS1X7ZllvpgTH1RaabW5DHKW9rcg75G03CPOw23znB/ebR1vHvghJUameCAfqXtLH+EPO2Tk/juydyRMTCdHDKOAhkWPGFPelsYCkridKskx557qyMXp2g7PTlSpcior1RDPrBbOs9oJ1S3c9ss87bwTeuDJVL2qX01/FOJZ/17Wfdm2ziWwreA1Lu1XJIUYv+wJLAW99IqupuyAMIDYGEiy0ybSWkohgKBKXEBxa6Wv0bf0iGzfY13aR8xulhPJq8PNihGib3sQgSnkjKSJPgR41KbFaiP5wKEx7s1zNQg8/wW2OChFUV3SIJ/AgKMP8trIkn+3pWDJRE+pP48+NIi9owO6lnBYbFIxk2aFemHFe2sVER3GIiOpsP7+1QdUXz9vx7omlFMZqWt6li2EPXOJaHMmePg3YCoMTlVXhNFC6WjUrNsdRtgkr2QPaMtF2g1ApokgrIF4hgVvUkzn9xGqordUbb5IyIARsdW4pqZgCLkPY5RkBeK4WSaTN+Q9ZN/FC5/OIMDA6NU9f+3I35twDEHQCdkgjzh7o5yiYywkqe4UE/FfQVC8z24Jt23WQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5064.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(33656002)(83380400001)(186003)(64756008)(508600001)(76116006)(9686003)(66446008)(66476007)(66556008)(316002)(122000001)(55016003)(66946007)(8676002)(38100700002)(26005)(5660300002)(4326008)(2906002)(38070700005)(7696005)(15650500001)(82960400001)(71200400001)(8936002)(52536014)(6506007)(110136005)(54906003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?JnlN/dv6xLpryhh4Ju+ssJ6fqUo+q8PlmWVd0TVRHinS4fYcEhyE5iY21AQn?= =?us-ascii?Q?xe+nVqQflKO5bFMybOyaevCq81shnWM8Lm1QkIfS2tOlzZSMZEd8f8Yjf1w2?= =?us-ascii?Q?mwvET1rAwQtQh+FjCioVj+yafFUAHRxlUBgDRf+Ru7rjnEV1lARVJMlwNcRR?= =?us-ascii?Q?rWeYtD3DTTuCcd7oFVjrVsw24jMvWHMbs8CQd1IC99zs+6fAya/7lCZR7Yer?= =?us-ascii?Q?P8YER4fOAGDaHn1HQXwdQcqMsifMKqYi8hjHZA/UFrrBa0uSYYxSB/V+RplY?= =?us-ascii?Q?19JGXrjOUhXI58Ny82B3sWF7znvU87rMD2tkJqSd/eqXm0bPsv7c1ZLXQosw?= =?us-ascii?Q?BJ/To+gFcotBpjqdcmquVzZPU+1scbIQjjo8diyGRFaAgTl72fcPu+Jr8okb?= =?us-ascii?Q?tsZLVFWxzsVeRUfEB0kooVbUruWg9ALhvBY2kpu8u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73vBH6rjk7kegixES/npAQoGDL5SZ9B9z3UB3usV?= =?us-ascii?Q?MlJXhnIOGVwV4OBjSkS0gP+zFOQiJyThBSYv+EULDbcyZL6i/YeGCu1nwhfS?= =?us-ascii?Q?flZBezar9gLI1hSAxB2u6Ffn8EqcbTtcDu8BKeQJRY2ihA1UFWSpi4J8UtG8?= =?us-ascii?Q?m+2mNMARwupbDCbkIKb03jQu5s6ZsJh+ud0AvEB1dAAHQGRGoEl/u8Mo+Wm/?= =?us-ascii?Q?f3lOG055Rip2qPwHjaIE2hMQi6DgmgLNhhLuLsSSlFR4sxj4668u+wBTVOwI?= =?us-ascii?Q?Cg=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5064.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b55b7348-00af-4f90-80b7-08d9c06bb042 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Dec 2021 08:11:39.9563 (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: culeopDFGWr9hwKiSgrbLmGSKZUCkVyKVlstODgFaRXmJPhS32BoARnwDHinf57vn6Mo7RW4lqYQHYxP3nx5Eg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4919 Return-Path: min.m.xu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi > > +EFI_STATUS > > +EFIAPI > > +BspAcceptMemoryResourceRange ( > > + IN EFI_PHYSICAL_ADDRESS PhysicalAddress, > > + IN EFI_PHYSICAL_ADDRESS PhysicalEnd > > + ) > > +{ > > + EFI_STATUS Status; > > + UINT32 AcceptPageSize; > > + UINT64 StartAddress1; > > + UINT64 StartAddress2; > > + UINT64 StartAddress3; > > + UINT64 TotalLength; > > + UINT64 Length1; > > + UINT64 Length2; > > + UINT64 Length3; > > + UINT64 Pages; > > + > > + AcceptPageSize =3D FixedPcdGet32 (PcdTdxAcceptPageSize); > > + TotalLength =3D PhysicalEnd - PhysicalAddress; > > + StartAddress1 =3D 0; > > + StartAddress2 =3D 0; > > + StartAddress3 =3D 0; > > + Length1 =3D 0; > > + Length2 =3D 0; > > + Length3 =3D 0; > > + > > + if (TotalLength =3D=3D 0) { > > + return EFI_SUCCESS; > > + } > > + > > + if ((AcceptPageSize =3D=3D SIZE_4KB) || (TotalLength <=3D SIZE_2MB))= { > > + // > > + // if total length is less than 2M, then we accept pages in 4k > > + // > > + StartAddress1 =3D 0; > > + Length1 =3D 0; > > + StartAddress2 =3D PhysicalAddress; > > + Length2 =3D PhysicalEnd - PhysicalAddress; > > + StartAddress3 =3D 0; > > + Length3 =3D 0; > > + AcceptPageSize =3D SIZE_4KB; >=20 > You've zero-initialized everything above, no need to do that again. Thanks for reminder. It will be updated in the next version. > You also can just use StartAddress1 + Length1 which uses 4k pages anyway. In the origin design, StartAddress1+Length1 and StartAddress3+Length3 are f= or BSP, StartAddress2+Length2 is for BSP/APs. Now only BSP accepts memory. = So you're right. We can just use StartAddress1+Length1 which uses 4k pages = anyway. >=20 > > + } else if (AcceptPageSize =3D=3D SIZE_2MB) { > > + // > > + // Total length is bigger than 2M and Page Accept size 2M is suppo= rted. > > + // > > + if ((PhysicalAddress & ALIGNED_2MB_MASK) =3D=3D 0) { >=20 > The logic is rather messy. It should become much simpler if you update > PhysicalAddress and TotalLength. You can also use the alignment macros. >=20 > if (ALIGN_VALUE(PhysicalAddress, SIZE_2MB) !=3D PhysicalAddress) { > StartAddress1 =3D PhysicalAddress; > Length1 =3D ALIGN_VALUE(PhysicalAddress, SIZE_2MB) - PhysicalAddr= ess; > PhysicalAddress +=3D Length1; > TotalLength -=3D Length1; > } > if (TotalLength > SIZE_2MB) { > StartAddress2 =3D PhysicalAddress; > Length2 =3D TotalLength & ~(UINT64)ALIGNED_2MB_MASK > PhysicalAddress +=3D Length2; > TotalLength -=3D Length2; > } > if (TotalLength) { > StartAddress3 =3D PhysicalAddress; > Length3 =3D TotalLength; > } >=20 Thanks for the suggestion. It's better. It will be updated in the next vers= ion. Thanks Min