From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.5479.1686219437752596620 for ; Thu, 08 Jun 2023 03:17:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=cawvxinq; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686219437; x=1717755437; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=/H7yhFCSGK3P7Qkg70evV7L7OgJnE0Me8sDyIBGadqo=; b=cawvxinqczTrSbRG2LxeZBB1XY+Shxg4F5Q2oFzq/hBPO3Eg00lC5CcQ 7CJVYnu4s6hmRNoxW9/QKFnd4gIccvUifrHcT83ZBJTzw6/EnRwvg8oZK 62utI10bZaS0ZakOOtvXyzDtqBR1RR3NE/ufkHPqjObGoPmj+CcOYWonk h6F/4WrnNcHshZ+NE4Pw/wlbRnk7R5DFt4DPpW/0NN2p8wwUWg8v4gopc 09GZdeZCXBuVsqC157TMyq8Z4ZILpbt2PMHoZWuzPcujHiCD2cPG7tQhJ reNc70FDULYpQWmsIVggXr7E1j1YN36zxtOu0+yGjyWcUzvpw3tSSzwtE Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="420833001" X-IronPort-AV: E=Sophos;i="6.00,226,1681196400"; d="scan'208";a="420833001" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 03:17:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="660327512" X-IronPort-AV: E=Sophos;i="6.00,226,1681196400"; d="scan'208";a="660327512" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga003.jf.intel.com with ESMTP; 08 Jun 2023 03:17:17 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) 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.2507.23; Thu, 8 Jun 2023 03:17:16 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 8 Jun 2023 03:17:16 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 8 Jun 2023 03:17:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aqsHOnQOq0ZkYtqD/knt31qRt+FSUh4QsnbNY7iVLPf6CjAiLbzYgVj06FyMKfkaiH+arYZMxxyKxktOhe7ppPBtQFUpguMsv/PL4bDnz//VtGUXjujrOjiDeFbMvgrWlEUxlUjFomzhTbv9RZ3xNgB/9JLoLcqSbMNat+1LBnbRVYfHjyc4C0CQAywnbrpc31P3ftJ1FHSXctxdjInTHS4ynX1PtWs16eY1ZQzrt0UabAX4pDO3dgzjkpJiyZW5sjwUBlxPYbQ0eDakE1A51eN+ivsb7w+65OQytgTo2+ELI9rSU7b7sSJwCOFrJi3WAo35Bot3QP/Em6/dEtNA4Q== 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=h/SOfskoDaK/yjggYT89fZ5dKpse8xe6tcHxX7u0A/c=; b=m8Oz6KbO76hekvoSsXeU8yQllaFhDuJ4cbyUyO1uNboBhTY/Merzuh6cDDlKVbftRFsDOWbT9piYDpm/v0ekttOo8fMkhIOdLlPapxMvuJfAW7fn8G6xRIaiUYqg0jhWqDILrGLYr9SqLQrp+M113T8OHJXaCIYIRuNJYYOKqC8yDrh52I7uC2V1/ykE4JI/gyy6EXDVjtk/+26tcZ0UeBcmMfvoBmJCHBE7PJQfAmkO4K1FCJFrW797y8519BjBOp+FJu5vcFjg7YrndWGoSgRHRq5aIbDw8V5YcONTtipmzImh/HIVv29K7+0jejUHTiL2DWxe6bbKUJYz0qLzFg== 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 MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by PH0PR11MB4934.namprd11.prod.outlook.com (2603:10b6:510:30::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Thu, 8 Jun 2023 10:17:15 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%2]) with mapi id 15.20.6455.034; Thu, 8 Jun 2023 10:17:15 +0000 From: "Ni, Ray" To: "Tan, Dun" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann Subject: Re: [Patch V5 12/14] UefiCpuPkg: Sort mProtectionMemRange when ReadyToLock Thread-Topic: [Patch V5 12/14] UefiCpuPkg: Sort mProtectionMemRange when ReadyToLock Thread-Index: AQHZmbEJwT12jeeSKUOWT/Z8jVr2g6+AsVyA Date: Thu, 8 Jun 2023 10:17:15 +0000 Message-ID: References: <20230608022742.1292-1-dun.tan@intel.com> <20230608022742.1292-13-dun.tan@intel.com> In-Reply-To: <20230608022742.1292-13-dun.tan@intel.com> 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: MN6PR11MB8244:EE_|PH0PR11MB4934:EE_ x-ms-office365-filtering-correlation-id: 6b626624-3e3a-4a98-d8ad-08db68098893 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NbkMCvK+YULrcefARRAZpYTmq5zrFL8tjHYyKm9dL8xXuvHcKtbY5upyBoIE2Zt4RJYmqsszFToC1Pfx4IddWEHK/oiizWO/DK3woRJwK6wYwHZMpuR4M2sPN1hxP9tNqerHETPWVkB88SBfLPunMZHu4SVdVB5npZlOpqimE/hFo8zxAdTIYBm+JszGKVHyRhOh+V8XnrWA2z33PvStzuxVr+EotFKYwGqtqD/MYZCgLpbkuwp3flG/mumFYYZwG4UcaEf4gnTcazqzNvFTRUuNH8X3qpmM52qOWP0jnX99Bw1073dljBelBAkiGKcFoLDgmWIVMWmhM6ALUNr8WprCVLBO8KnL2aF/LwhUOdrFcBbBU8TLxx5d9CttE5nLtN2o6NoYKE50erCgS3fnIg0/eo5tEsPOR6fsMZUeTDgl+FSLGwcj3LTsZcBGUPrxA2Vd3C/mGC/98xMyMh8bgHpw2n4gJtGTL6tkWKgVMoYwq9ckOlID6FcAWzVu1N6Odkiof3/5cvo/n5li6pqowvDsEx9RTbf0eHgB5wdRFih/9yg5flg2haMX3OZ8Q50+mAYiwlliQ16Nior2i2uHfd4BBTAf+aAfENMpXW7dscSn2fm8ny63b7FUH+dlh01ZdsnduKT63D+XUt6mxJoJww== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(6029001)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199021)(41300700001)(8676002)(4326008)(66446008)(76116006)(66556008)(66476007)(64756008)(8936002)(66946007)(110136005)(5660300002)(316002)(52536014)(54906003)(55016003)(2906002)(478600001)(38100700002)(82960400001)(122000001)(9686003)(6506007)(53546011)(86362001)(26005)(186003)(71200400001)(7696005)(83380400001)(38070700005)(33656002)(145543001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?VRAC5p7sysZuyblwpDiWlAk3VmPSjvfJ00K/cEAK16EvibWFJr7jDL8K0KAn?= =?us-ascii?Q?s+twa8gR3fn/LNb3OMls6PmGyXMK8OtL/uCr62U9RrhjIT8W0bQFspibOTOt?= =?us-ascii?Q?CILmUk6NcxoFeAF0GVxegOu46R+zzLHcM+Jim9QTC+lhPDQbB5Fge3BK6oXB?= =?us-ascii?Q?6qyAlz2Hri+vgxt/V7n7w17IoeOhXiYbOBN30wpcXx69xPh5Iaxb17JlJug+?= =?us-ascii?Q?X16FDwDzzoXx8hLJD39huRuGIyQ320sNFwprGiuBpWP13OCFbqNOUrnAQpqn?= =?us-ascii?Q?4fbP3AUX7pDRe1tsZOmlAVyGylxxwrNIYVM4CvurNqZaZRYzVllWf9Tpju+G?= =?us-ascii?Q?DQIIebRgpdv5/Nfp44b1kAkrQ31l2cLdmjRpGIfgF/uVdlQmc5SecCxdQWa8?= =?us-ascii?Q?1P4C1070YV/PoSVeVYRjM38jEtT28pjMb+lUf19n1D6bgptmFGEu6DbgJGYX?= =?us-ascii?Q?Pt50qWHWaShizVI8FggfKVZ1+C5FGBBeFo6OAZhUclSAb2YCPGlIWdsUlC45?= =?us-ascii?Q?GRNOJsfWYVZqQ5gwfdkuhkXeYcmY/nYokabuCQTj7kThEVyN/7z/gbInNKxR?= =?us-ascii?Q?pHiVP9Bpq8LQicmaUZ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?E9j4DHdhVk0fI5G7I9NXb/AgiZ8Vjb0Y1lcOqkbFZixl8QXp0x0UuyILTM5h?= =?us-ascii?Q?1KuCKvBnJz34uvNRmRDeBjWPLEGOiOYdEHB/Noxa?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b626624-3e3a-4a98-d8ad-08db68098893 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jun 2023 10:17:15.8269 (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: Ohy5SLG5Gxsd2peIXY8FbO/9omCz0ChrqIsk+V1TZv6rQJ44c4ls6JFAb1FceJlx0fDDDNSEPAmcVGzljuhoiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4934 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Tan, Dun > Sent: Thursday, June 8, 2023 10:28 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Gerd Hoffmann > Subject: [Patch V5 12/14] UefiCpuPkg: Sort mProtectionMemRange when > ReadyToLock >=20 > Sort mProtectionMemRange in InitProtectedMemRange() when > ReadyToLock. >=20 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 32 > ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > index 5625ba0cac..2a1f132b29 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > @@ -375,6 +375,32 @@ IsAddressSplit ( > return FALSE; > } >=20 > +/** > + Function to compare 2 MEMORY_PROTECTION_RANGE based on range > base. > + > + @param[in] Buffer1 pointer to Device Path poiner to compare > + @param[in] Buffer2 pointer to second DevicePath pointer to = compare > + > + @retval 0 Buffer1 equal to Buffer2 > + @retval <0 Buffer1 is less than Buffer2 > + @retval >0 Buffer1 is greater than Buffer2 > +**/ > +INTN > +EFIAPI > +ProtectionRangeCompare ( > + IN CONST VOID *Buffer1, > + IN CONST VOID *Buffer2 > + ) > +{ > + if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base > > ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) { > + return 1; > + } else if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base < > ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) { > + return -1; > + } > + > + return 0; > +} > + > /** > Initialize the protected memory ranges and the 4KB-page mapped memory > ranges. >=20 > @@ -397,6 +423,7 @@ InitProtectedMemRange ( > EFI_PHYSICAL_ADDRESS Base2MBAlignedAddress; > UINT64 High4KBPageSize; > UINT64 Low4KBPageSize; > + MEMORY_PROTECTION_RANGE MemProtectionRange; >=20 > NumberOfDescriptors =3D 0; > NumberOfAddedDescriptors =3D mSmmCpuSmramRangeCount; > @@ -533,6 +560,11 @@ InitProtectedMemRange ( >=20 > mSplitMemRangeCount =3D NumberOfSpliteRange; >=20 > + // > + // Sort the mProtectionMemRange > + // > + QuickSort (mProtectionMemRange, mProtectionMemRangeCount, sizeof > (MEMORY_PROTECTION_RANGE), > (BASE_SORT_COMPARE)ProtectionRangeCompare, &MemProtectionRange); > + > DEBUG ((DEBUG_INFO, "SMM Profile Memory Ranges:\n")); > for (Index =3D 0; Index < mProtectionMemRangeCount; Index++) { > DEBUG ((DEBUG_INFO, "mProtectionMemRange[%d].Base =3D %lx\n", Index, > mProtectionMemRange[Index].Range.Base)); > -- > 2.31.1.windows.1