From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 33F3B740038 for ; Mon, 27 Nov 2023 08:32:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lo8xrk7/wY8FNW6iKvTRZoDDQ2rl4Cuq4O83imIdzSQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701073959; v=1; b=h06coWbLLvJNNhnHKIC/5pydCuuRz/iVRKpSheLpqjJZC7IzEKT5aCbgeNbMhDI7RRxqPQjd xbdDdGsWuQ4jir/lbz0GA0E08T6sJE4o2HH4YS+Fs+08iYX30iFpUk2Gdn2XwnznULxyphj83lY g5Xoc0PdCWMPbsj7OXIrBvEY= X-Received: by 127.0.0.2 with SMTP id zkSjYY7687511xor9knd4hCL; Mon, 27 Nov 2023 00:32:39 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by mx.groups.io with SMTP id smtpd.web11.88702.1701073954686202086 for ; Mon, 27 Nov 2023 00:32:39 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="14219767" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="14219767" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 00:32:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="771849170" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="771849170" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 00:32:37 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Ray Ni , Rahul Kumar , Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH 2/3] UefiCpuPkg/CpuPageTableLib/TestCase: Refine test case for PAE paging. Date: Mon, 27 Nov 2023 16:32:24 +0800 Message-Id: <20231127083225.1294-2-zhiguang.liu@intel.com> In-Reply-To: <20231127083225.1294-1-zhiguang.liu@intel.com> References: <20231127083225.1294-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk 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,zhiguang.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: t6WQ8gCDvmtwY4LdZh8i0bURx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=h06coWbL; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Refine test case: 1. Check PAE paging reserved bits is zero. 2. Set stack as random value. Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Laszlo Ersek Signed-off-by: Zhiguang Liu --- .../UnitTest/CpuPageTableLibUnitTestHost.inf | 3 +++ .../CpuPageTableLib/UnitTest/RandomTest.c | 23 ++++++++++++++++++- .../CpuPageTableLib/UnitTest/TestHelper.c | 14 ++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.inf b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.inf index eb71c5ad68..3714b18492 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.inf +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.inf @@ -40,3 +40,6 @@ UnitTestLib MemoryAllocationLib BaseCryptLib + +[BuildOptions] + GCC:*_*_*_CC_FLAGS = -Wno-unused-but-set-variable diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c index f7a77d00e7..50e40aa002 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c @@ -138,6 +138,22 @@ RandomBoolean ( return ((Probability > ((UINT8)Random64 (0, 100))) ? TRUE : FALSE); } +/** + Set 8K stack as random value. +**/ +VOID +SetRandomStack ( + VOID + ) +{ + UINT64 Buffer[SIZE_1KB]; + UINTN Index; + + for (Index = 0; Index < SIZE_1KB; Index++) { + Buffer[Index] = Random64 (0, MAX_UINT64); + } +} + /** Check if the Page table entry is valid @@ -670,6 +686,7 @@ SingleMapEntryTest ( IsNotPresent = FALSE; IsModified = FALSE; + SetRandomStack (); GenerateSingleRandomMapEntry (MaxAddress, MapEntrys); LastMapEntry = &MapEntrys->Maps[MapsIndex]; Status = PageTableParse (*PageTable, PagingMode, NULL, &MapCount); @@ -1039,7 +1056,11 @@ TestCaseforRandomTest ( mSupportedBit.Bits.Pat = 1; mSupportedBit.Bits.Global = 1; mSupportedBit.Bits.ProtectionKey = 0xF; - mSupportedBit.Bits.Nx = 1; + if (((CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT *)Context)->PagingMode == PagingPae) { + mSupportedBit.Bits.ProtectionKey = 0; + } + + mSupportedBit.Bits.Nx = 1; mRandomOption = ((CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT *)Context)->RandomOption; mNumberIndex = 0; diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c index 67776255c2..d2c50a6c8a 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c @@ -9,6 +9,7 @@ #include "CpuPageTableLibUnitTest.h" #include "../CpuPageTable.h" +#define IA32_PAE_RESERVED_MASK 0x7FF0000000000000ull // // Global Data to validate if the page table is legal // mValidMaskNoLeaf[0] is not used @@ -95,6 +96,7 @@ InitGlobalData ( @param[in] Level the level of PagingEntry. @param[in] MaxLeafLevel Max leaf entry level. @param[in] LinearAddress The linear address verified. + @param[in] PagingMode The paging mode. @retval Leaf entry. **/ @@ -103,13 +105,18 @@ IsPageTableEntryValid ( IN IA32_PAGING_ENTRY *PagingEntry, IN UINTN Level, IN UINTN MaxLeafLevel, - IN UINT64 Address + IN UINT64 Address, + IN PAGING_MODE PagingMode ) { UINT64 Index; IA32_PAGING_ENTRY *ChildPageEntry; UNIT_TEST_STATUS Status; + if (PagingMode == PagingPae) { + UT_ASSERT_EQUAL (PagingEntry->Uint64 & IA32_PAE_RESERVED_MASK, 0); + } + if (PagingEntry->Pce.Present == 0) { return UNIT_TEST_PASSED; } @@ -142,7 +149,7 @@ IsPageTableEntryValid ( ChildPageEntry = (IA32_PAGING_ENTRY *)(UINTN)(IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&PagingEntry->Pnle)); for (Index = 0; Index < 512; Index++) { - Status = IsPageTableEntryValid (&ChildPageEntry[Index], Level-1, MaxLeafLevel, Address + (Index<<(9*(Level-1) + 3))); + Status = IsPageTableEntryValid (&ChildPageEntry[Index], Level-1, MaxLeafLevel, Address + (Index<<(9*(Level-1) + 3)), PagingMode); if (Status != UNIT_TEST_PASSED) { return Status; } @@ -190,9 +197,10 @@ IsPageTableValid ( if (PagingMode == PagingPae) { UT_ASSERT_EQUAL (PagingEntry[Index].PdptePae.Bits.MustBeZero, 0); UT_ASSERT_EQUAL (PagingEntry[Index].PdptePae.Bits.MustBeZero2, 0); + UT_ASSERT_EQUAL (PagingEntry[Index].PdptePae.Bits.MustBeZero3, 0); } - Status = IsPageTableEntryValid (&PagingEntry[Index], MaxLevel, MaxLeafLevel, Index << (9 * MaxLevel + 3)); + Status = IsPageTableEntryValid (&PagingEntry[Index], MaxLevel, MaxLeafLevel, Index << (9 * MaxLevel + 3), PagingMode); if (Status != UNIT_TEST_PASSED) { return Status; } -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111730): https://edk2.groups.io/g/devel/message/111730 Mute This Topic: https://groups.io/mt/102825576/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-