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.7471.1679290475232002420 for ; Sun, 19 Mar 2023 22:34:58 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=HlCHc5Gf; spf=pass (domain: intel.com, ip: 134.134.136.31, 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=1679290498; x=1710826498; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=885hkYmSZI8QcS8WKO3tm1xSx22ql8sOzI8sLej7CIk=; b=HlCHc5GfEOIMNIqqHFoQ5birbpefyMJj92Hdj2BaDVx291e5JCzNj0YO H5/CUUjk5K/5POsMaDPChTv0e8tIZvnIx+MvI6KPuF76Cxx0gsJXae9Vk Dl7vEUmTsintosyQ5cfU9J4ppR3blnQ5nOiFsRJp775+pBw3dAEdWiv6V Yp+9jCdEmDO+Lwe3sxx0xM6BVeoeDZyOmaZ7lO9Dsx2T0q1GT9N2nv75o TWq/KD/n3jOww/u3l5GvIFLv/+pAhILH9SDU7UKZOcWJTXtDyK8LzKD9m AoTfRtt/f08R5FJ0r90hQjNQNoqyZe2vXqm9VU5/xRvb4yYonae5SqXFg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="401155694" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="401155694" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2023 22:34:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="770059590" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="770059590" Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2023 22:34:55 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Zhiguang Liu Subject: [Patch V3 13/18] UefiCpuPkg/CpuPageTableLib: Modify RandomTest to check IsModified Date: Mon, 20 Mar 2023 13:33:24 +0800 Message-Id: <20230320053329.410-14-dun.tan@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20230320053329.410-1-dun.tan@intel.com> References: <20230320053329.410-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 Cc: Ray Ni Cc: Rahul Kumar Cc: 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 5fbc43c9d1..81dd9e5836 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 ( UINT64 PreviousAddress; UINT64 RangeLimit; BOOLEAN IsNotPresent; + BOOLEAN IsModified; MapsIndex = MapEntrys->Count; MapCount = 0; PreviousAddress = 0; IsNotPresent = FALSE; + IsModified = FALSE; GenerateSingleRandomMapEntry (MaxAddress, MapEntrys); RangeLimit = MapEntrys->Maps[MapsIndex].LinearAddress + MapEntrys->Maps[MapsIndex].Length; @@ -696,7 +700,7 @@ SingleMapEntryTest ( MapEntrys->Maps[MapsIndex].Length, &MapEntrys->Maps[MapsIndex].Attribute, &MapEntrys->Maps[MapsIndex].Mask, - NULL + &IsModified ); Attribute = &MapEntrys->Maps[MapsIndex].Attribute; @@ -757,7 +761,7 @@ SingleMapEntryTest ( MapEntrys->Maps[MapsIndex].Length, &MapEntrys->Maps[MapsIndex].Attribute, &MapEntrys->Maps[MapsIndex].Mask, - NULL + &IsModified ); } @@ -771,18 +775,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); @@ -792,17 +809,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); @@ -816,6 +833,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