From nobody Tue Feb 10 23:53:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105905+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105905+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1686191352; cv=none; d=zohomail.com; s=zohoarc; b=I7jfw/Qdkad8ZM6Gi87MBkHrL18Jix7bb8rou1YyVqWqNHKzTacpxcr5DRDm/lC8gByzMQsuiICpNiOZA77/qqnjsY62zyWLAe2p3ok0ZgniMZOU4xFx7hz8sutK9aK1jo415lK/CbVpWgTP2XpeOyqTc22+jR+x/Zd9bt/N768= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686191352; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=F8N7UHcCEcISupJ/Ul9DIwSJNXVvC/FAkej9+8ai0gQ=; b=VD7HCdh0aTKmriYkwGkomfZvWolozNtOdjKN42fx6bqHMtU9gNIjZvpOIg5ErmkeqmDyN86fr/5Fp+08FOpVSyjVbjFo97rkUL0uvIZBPSnrjTlZmmymPLUHZb8AEZCrw3N45BueTCJ/toJU3ARJ+X6Gp+kvr7Js1bJ+uFjee/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105905+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1686191352166265.77987609778734; Wed, 7 Jun 2023 19:29:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id foHlYY1788612xYLCuN1aQrI; Wed, 07 Jun 2023 19:29:11 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.386.1686191344244208222 for ; Wed, 07 Jun 2023 19:29:11 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="357184439" X-IronPort-AV: E=Sophos;i="6.00,225,1681196400"; d="scan'208";a="357184439" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 19:29:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="774877933" X-IronPort-AV: E=Sophos;i="6.00,225,1681196400"; d="scan'208";a="774877933" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.158]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 19:29:09 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V5 12/14] UefiCpuPkg: Sort mProtectionMemRange when ReadyToLock Date: Thu, 8 Jun 2023 10:27:40 +0800 Message-Id: <20230608022742.1292-13-dun.tan@intel.com> In-Reply-To: <20230608022742.1292-1-dun.tan@intel.com> References: <20230608022742.1292-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,dun.tan@intel.com X-Gm-Message-State: sUW0XbX4KPs4m3E2jc3G3tdox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1686191351; bh=fkYnlcBS8HNGnCildyr0/cVWeS1Oo/2bv17ojgy6Jms=; h=Cc:Date:From:Reply-To:Subject:To; b=d4RTYqhvvKg5YjMiGoD/1jWXX4qVbL9w/6rN9CgUIn5mNnK7iPjEamB4vHv6yrIFCIW FFiBnD5v12u+QJKjGsTneQKY21041/xxhoYcZOAY7Js6pwXEL3oLh/el4f4BU0E2D/Y5I aTh3DB0sWA0p32hex/s/N9OM4eFHPcL4wHc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1686191352978100015 Content-Type: text/plain; charset="utf-8" Sort mProtectionMemRange in InitProtectedMemRange() when ReadyToLock. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 32 ++++++++++++++++++++++++++++++= ++ 1 file changed, 32 insertions(+) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/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 co= mpare + + @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_PROTECTI= ON_RANGE *)Buffer2)->Range.Base) { + return 1; + } else if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base < ((MEMORY_P= ROTECTION_RANGE *)Buffer2)->Range.Base) { + return -1; + } + + return 0; +} + /** Initialize the protected memory ranges and the 4KB-page mapped memory ra= nges. =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, &MemProtecti= onRange); + 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, m= ProtectionMemRange[Index].Range.Base)); --=20 2.31.1.windows.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 (#105905): https://edk2.groups.io/g/devel/message/105905 Mute This Topic: https://groups.io/mt/99399240/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-