From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=C5yspxvv; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686191351; x=1717727351; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Os0+1B9i7SFRVrXlfTVR1ZVbdJad0gEezsWgrrHwVis=; b=C5yspxvvzZuizpUAhhyWpc21f4bgjplaKfT7dXNO/TDMcMlLYYliyz6E YmsqDzcZn0+Chjm9PxESjIVekxR+rpnMaA14CFyW4pS/BL7aFf6eZufCz x5AeKYNk9zt63O78qSGNWWGQ8JeJJS2F6aS+bGHmnnQooEw3S+7HzrvBl zsRQ9eWb2JB/vGsgSsx/H3vOyWLJuS3RngrrF9D1nVUXlPGv4CIeXUxB5 6KxyZH/EtFlj3RqHIyP6MxI8YAGqPG3mlOfrk51/X0b+NkLj+/Nsdf23/ yTypAlHn+M72nPCDvc063K5bAqxjrSTBjw6kHzQIWUciU4S5NTwyFgrx9 g==; 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" 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" 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: [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> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20230608022742.1292-1-dun.tan@intel.com> References: <20230608022742.1292-1-dun.tan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sort mProtectionMemRange in InitProtectedMemRange() when ReadyToLock. 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(+) 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; } +/** + 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. @@ -397,6 +423,7 @@ InitProtectedMemRange ( EFI_PHYSICAL_ADDRESS Base2MBAlignedAddress; UINT64 High4KBPageSize; UINT64 Low4KBPageSize; + MEMORY_PROTECTION_RANGE MemProtectionRange; NumberOfDescriptors = 0; NumberOfAddedDescriptors = mSmmCpuSmramRangeCount; @@ -533,6 +560,11 @@ InitProtectedMemRange ( mSplitMemRangeCount = NumberOfSpliteRange; + // + // 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 = 0; Index < mProtectionMemRangeCount; Index++) { DEBUG ((DEBUG_INFO, "mProtectionMemRange[%d].Base = %lx\n", Index, mProtectionMemRange[Index].Range.Base)); -- 2.31.1.windows.1