From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.94534.1679637641374533517 for ; Thu, 23 Mar 2023 23:01:04 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kCa+m62u; spf=pass (domain: intel.com, ip: 192.55.52.151, 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=1679637664; x=1711173664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x9zsQXFHY+57nElux/655EBqX8uYpJZ0rombzBN1mQM=; b=kCa+m62u5BAoGbREWsxK3q9dAAWo8IudLfFXIW/AvPg6vb1ijpiYD+fe KstAt5pdbpQr6VsyjCwn8QxlXjgLhRUV/LCvHMxyMsww29Uy9owBG9cTl 58ZKiVjR1RAPHKbltP1XF71tC2BeJbiz0CQjzEvfYhdbp9hoNyGGU9hv3 U0ry21Fs3Z+dEfqqDsW6gDxGuy6Ic6PtUAT+TSZeZrPrW4AWoNo53bi4d z/Lfj7iPjy00jTpP1D7QzxNVFXiTUzqFYZsT3HX45fIJlbhrK5HrkcCWX ZHh1bIJAKW1aDreMWOM66VppUaXSVpdDw25ozhwOkXPd9BPQ1ooEwJHUi A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="320094040" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="320094040" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 23:01:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="1012122199" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="1012122199" Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 23:01:03 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Zhiguang Liu Subject: [Patch V5 15/22] UefiCpuPkg/CpuPageTableLib: Modify RandomTest to check IsModified Date: Fri, 24 Mar 2023 14:00:13 +0800 Message-Id: <20230324060020.940-16-dun.tan@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20230324060020.940-1-dun.tan@intel.com> References: <20230324060020.940-1-dun.tan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Modify RandomTest to check if parameter IsModified of PageTableMap() correctlly indicates whether input page table is modified or not. Signed-off-by: Dun Tan Cc: Eric Dong Reviewed-by: Ray Ni Cc: Rahul Kumar Tested-by: Gerd Hoffmann Acked-by: Gerd Hoffmann Cc: Zhiguang Liu --- UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c index e603dba269..bffd95c898 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c @@ -636,6 +636,8 @@ SingleMapEntryTest ( VOID *Buffer; IA32_MAP_ENTRY *Map; UINTN MapCount; + IA32_MAP_ENTRY *Map2; + UINTN MapCount2; UINTN Index; UINTN KeyPointCount; UINTN NewKeyPointCount; @@ -648,11 +650,13 @@ SingleMapEntryTest ( IA32_MAP_ATTRIBUTE *Attribute; UINT64 LastNotPresentRegionStart; BOOLEAN IsNotPresent; + BOOLEAN IsModified; MapsIndex = MapEntrys->Count; MapCount = 0; LastNotPresentRegionStart = 0; IsNotPresent = FALSE; + IsModified = FALSE; GenerateSingleRandomMapEntry (MaxAddress, MapEntrys); LastMapEntry = &MapEntrys->Maps[MapsIndex]; @@ -700,7 +704,7 @@ SingleMapEntryTest ( LastMapEntry->Length, &LastMapEntry->Attribute, &LastMapEntry->Mask, - NULL + &IsModified ); Attribute = &LastMapEntry->Attribute; @@ -761,7 +765,7 @@ SingleMapEntryTest ( LastMapEntry->Length, &LastMapEntry->Attribute, &LastMapEntry->Mask, - NULL + &IsModified ); } @@ -775,18 +779,31 @@ SingleMapEntryTest ( return TestStatus; } - MapCount = 0; - Status = PageTableParse (*PageTable, PagingMode, NULL, &MapCount); - if (MapCount != 0) { + MapCount2 = 0; + Status = PageTableParse (*PageTable, PagingMode, NULL, &MapCount2); + if (MapCount2 != 0) { UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); // - // Allocate memory for Maps + // Allocate memory for Map2 // Note the memory is only used in this one Single MapEntry Test // - Map = AllocatePages (EFI_SIZE_TO_PAGES (MapCount * sizeof (IA32_MAP_ENTRY))); - ASSERT (Map != NULL); - Status = PageTableParse (*PageTable, PagingMode, Map, &MapCount); + Map2 = AllocatePages (EFI_SIZE_TO_PAGES (MapCount2 * sizeof (IA32_MAP_ENTRY))); + ASSERT (Map2 != NULL); + Status = PageTableParse (*PageTable, PagingMode, Map2, &MapCount2); + } + + // + // Check if PageTable has been modified. + // + if (MapCount2 != MapCount) { + UT_ASSERT_EQUAL (IsModified, TRUE); + } else { + if (CompareMem (Map, Map2, MapCount2 * sizeof (IA32_MAP_ENTRY)) != 0) { + UT_ASSERT_EQUAL (IsModified, TRUE); + } else { + UT_ASSERT_EQUAL (IsModified, FALSE); + } } UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); @@ -796,17 +813,17 @@ SingleMapEntryTest ( // Note the memory is only used in this one Single MapEntry Test // KeyPointCount = 0; - GetKeyPointList (MapEntrys, Map, MapCount, NULL, &KeyPointCount); + GetKeyPointList (MapEntrys, Map2, MapCount2, NULL, &KeyPointCount); KeyPointBuffer = AllocatePages (EFI_SIZE_TO_PAGES (KeyPointCount * sizeof (UINT64))); ASSERT (KeyPointBuffer != NULL); NewKeyPointCount = 0; - GetKeyPointList (MapEntrys, Map, MapCount, KeyPointBuffer, &NewKeyPointCount); + GetKeyPointList (MapEntrys, Map2, MapCount2, KeyPointBuffer, &NewKeyPointCount); // // Compare all key point's attribute // for (Index = 0; Index < NewKeyPointCount; Index++) { - if (!CompareEntrysforOnePoint (KeyPointBuffer[Index], MapEntrys, Map, MapCount, InitMap, InitMapCount)) { + if (!CompareEntrysforOnePoint (KeyPointBuffer[Index], MapEntrys, Map2, MapCount2, InitMap, InitMapCount)) { DEBUG ((DEBUG_INFO, "Error happens at below key point\n")); DEBUG ((DEBUG_INFO, "Index = %d KeyPointBuffer[Index] = 0x%lx\n", Index, KeyPointBuffer[Index])); Value = GetEntryFromPageTable (*PageTable, PagingMode, KeyPointBuffer[Index], &Level); @@ -820,6 +837,10 @@ SingleMapEntryTest ( FreePages (Map, EFI_SIZE_TO_PAGES (MapCount * sizeof (IA32_MAP_ENTRY))); } + if (MapCount2 != 0) { + FreePages (Map2, EFI_SIZE_TO_PAGES (MapCount2 * sizeof (IA32_MAP_ENTRY))); + } + return UNIT_TEST_PASSED; } -- 2.31.1.windows.1