From nobody Mon Apr 29 05:29:08 2024 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+100685+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+100685+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837832; cv=none; d=zohomail.com; s=zohoarc; b=G1XlY5a5zAuuzYq+p63EOvjw96QZ/h028w5SvTxIlk3+F8FSApgc85gmQaZz0enNwRgW8VpslsBMXv263qesG6Vh8VcV7Qw22geiwvvHBkmYjDfxOQfU0ro+ccBGrfZdanxk7HvGSkm3BXGicptHFnu/lrEkmiXQmcaE+1BbZx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837832; 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=HlsJq6aINIHyuXMKoqsac5H2sVDHpNxQtWzxIWU39pY=; b=IgK1C6p2FL2XgNVodyyGqqjlCoRU9CuwPbwFoTrXs6tSWpbMafHiQSkMldmo2bAqeKtxhMYkyxDtNV0ak6qJgo1tPHquaryU8SE5McO9Iq2nrPABP3dFnulOQb79VORAjTJM1dTIP/VE+XOAb0S+psCEnKNiXtD2GpPdVkQzEm4= 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+100685+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 1677837832385427.24488092883644; Fri, 3 Mar 2023 02:03:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7MqoYY1788612xr2rW1VbpzQ; Fri, 03 Mar 2023 02:03:52 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:03:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831650" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831650" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818420967" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818420967" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:50 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 1/6] UefiCpuPkg/CpuPageTableLib: Remove unneeded 'if' condition Date: Fri, 3 Mar 2023 18:03:31 +0800 Message-Id: <20230303100336.2138-2-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: 42y4mnR3S1lqPFXs4Xr9KPoUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837832; bh=F0igOjWV9Hxrg3qjifQdvBYLJ+CKwaWQveau5PaQXXg=; h=Cc:Date:From:Reply-To:Subject:To; b=wYy6+fkEmHkiOLhgfpAXIZzZ+oqerWJji6iXLC/R+oHmilLmjxy1dtMlzvaNH9D0Uru Y4RgKAdsYdVxIr9FncUhbPOPtE6gsElFxYsBcSSPTanIcjE1tzS8mT3MXl4L6nrFS4HKE Bz7KrGsVGnegPeP3KoBxhZ5xNQ0BXutavD4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837834433100001 Content-Type: text/plain; charset="utf-8" Remove unneeded 'if' condition in CpuPageTableLib code. The deleted code is in the code branch for present non-leaf parent entry. So the check for (ParentPagingEntry->Pnle.Bits.Present =3D=3D 0) won't is always FALSE. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 37713ec659..47027917d9 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -375,15 +375,6 @@ PageTableLibMapInLevel ( // we need to change PDPTE[0].ReadWrite =3D 1 and let all P= DE[0-255].ReadWrite =3D 0 in this step. // when PDPTE[0].Nx =3D 1 but caller wants to map [0-2MB] as Nx = =3D 0 (PDT[0].Nx =3D 0) // we need to change PDPTE[0].Nx =3D 0 and let all PDE[0-25= 5].Nx =3D 1 in this step. - if ((ParentPagingEntry->Pnle.Bits.Present =3D=3D 0) && (Mask->Bits.Pre= sent =3D=3D 1) && (Attribute->Bits.Present =3D=3D 1)) { - if (Modify) { - ParentPagingEntry->Pnle.Bits.Present =3D 1; - } - - ChildAttribute.Bits.Present =3D 0; - ChildMask.Bits.Present =3D 1; - } - if ((ParentPagingEntry->Pnle.Bits.ReadWrite =3D=3D 0) && (Mask->Bits.R= eadWrite =3D=3D 1) && (Attribute->Bits.ReadWrite =3D=3D 1)) { if (Modify) { ParentPagingEntry->Pnle.Bits.ReadWrite =3D 1; --=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 (#100685): https://edk2.groups.io/g/devel/message/100685 Mute This Topic: https://groups.io/mt/97358970/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- From nobody Mon Apr 29 05:29:08 2024 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+100686+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+100686+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837834; cv=none; d=zohomail.com; s=zohoarc; b=ANZ6fDU7LuPffULBhLtqQHGV6MzE2HsXTREefcFVrgD9tBfxIRyPMadknDG9rwDZao3BnCMC5QDIlIHVoNWpBbzVTaH7HmobZo8U8u4dZ98IzuCjMqM9O0HN7wh1Wc7Cllodcw4B91IJaQwTVM6zpxX2vWjG7uI7z8pyW8eLBYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837834; 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=+ESCDOgRDbJTFKziCZE+QDRinm03I4Ks2cH++/gcs2U=; b=f6yh+rM5KDRbKyp0USwv+p8nVLLyCH0wY9M0jd7bVj7pqDrPSj/3gkqjS+o4f2ImaORAChJ2TCz6RTdJT1J4gn8Aiz27S8O9kJfRLpfAtm+gNfI7AoqOhixVclZQmDprJ/qRHOZhXkdmaq8Dez0ghDIiElraNyrW+CLGsscY/wU= 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+100686+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 1677837834837361.97676251493453; Fri, 3 Mar 2023 02:03:54 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EWxFYY1788612x6XYseHiZyB; Fri, 03 Mar 2023 02:03:54 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:03:54 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831677" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831677" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818420998" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818420998" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:52 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 2/6] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue Date: Fri, 3 Mar 2023 18:03:32 +0800 Message-Id: <20230303100336.2138-3-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: tIoKeTT3vgPOm24qXOIhbYtGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837834; bh=Ig3+v5xDgC3O9FaPhkLZZrFvdjMlm7OXTuP0ovzdOps=; h=Cc:Date:From:Reply-To:Subject:To; b=exL8fq7yy/IraxerSG0PCUFp2nc0VfY6keycK9OPs/x+VA+ogDeauZVZGFlaLq6CiFD K9A6W/YssjdoYhvBSjI/rAbszYHTHXDj0aoWqGA+U2vWEI1nO+gykaYwd8zSg5YnJ3i1Q TJ5zMVP9h8yhkxyMHaQ6ofLsn+TGNn1pFrQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837836436100005 Content-Type: text/plain; charset="utf-8" Fix the non-1:1 mapping issue in PageTableMap () of CpuPageTableLib Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 27 ++++++++++++++++= +---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 47027917d9..d2f35aa375 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -258,6 +258,7 @@ PageTableLibMapInLevel ( UINTN BitStart; UINTN Index; IA32_PAGING_ENTRY *PagingEntry; + UINTN PagingEntryIndex; IA32_PAGING_ENTRY *CurrentPagingEntry; UINT64 RegionLength; UINT64 SubLength; @@ -288,6 +289,13 @@ PageTableLibMapInLevel ( LocalParentAttribute.Uint64 =3D ParentAttribute->Uint64; ParentAttribute =3D &LocalParentAttribute; =20 + // + // RegionLength: 256T (1 << 48) 512G (1 << 39), 1G (1 << 30), 2M (1 << 2= 1) or 4K (1 << 12). + // + BitStart =3D 12 + (Level - 1) * 9; + PagingEntryIndex =3D (UINTN)BitFieldRead64 (LinearAddress + Offset, BitS= tart, BitStart + 9 - 1); + RegionLength =3D REGION_LENGTH (Level); + // // ParentPagingEntry ONLY is deferenced for checking Present and MustBeO= ne bits // when Modify is FALSE. @@ -325,8 +333,11 @@ PageTableLibMapInLevel ( // the actual attributes of grand-parents when determing the memory ty= pe. // PleBAttribute.Uint64 =3D PageTableLibGetPleBMapAttribute (&ParentPagin= gEntry->PleB, ParentAttribute); - if ((IA32_MAP_ATTRIBUTE_ATTRIBUTES (&PleBAttribute) & IA32_MAP_ATTRIBU= TE_ATTRIBUTES (Mask)) - =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & IA32_MAP_ATTRI= BUTE_ATTRIBUTES (Mask))) + if ((((IA32_MAP_ATTRIBUTE_ATTRIBUTES (&PleBAttribute) & IA32_MAP_ATTRI= BUTE_ATTRIBUTES (Mask)) + =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & IA32_MAP_ATT= RIBUTE_ATTRIBUTES (Mask)))) && + ( (Mask->Bits.PageTableBaseAddress =3D=3D 0) + || ((IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS (&PleBAttribute) += PagingEntryIndex * RegionLength) + =3D=3D (IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS (Attribute)= + Offset)))) { // // This function is called when the memory length is less than the r= egion length of the parent level. @@ -353,8 +364,7 @@ PageTableLibMapInLevel ( // PageTableLibSetPnle (&ParentPagingEntry->Pnle, &NopAttribute, &AllOn= eMask); =20 - RegionLength =3D REGION_LENGTH (Level); - PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BA= SE_ADDRESS (&ParentPagingEntry->Pnle); + PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BAS= E_ADDRESS (&ParentPagingEntry->Pnle); for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffset; SubOffset +=3D RegionLength; @@ -425,14 +435,11 @@ PageTableLibMapInLevel ( } =20 // - // RegionLength: 256T (1 << 48) 512G (1 << 39), 1G (1 << 30), 2M (1 << 2= 1) or 4K (1 << 12). // RegionStart: points to the linear address that's aligned on RegionLe= ngth and lower than (LinearAddress + Offset). // - BitStart =3D 12 + (Level - 1) * 9; - Index =3D (UINTN)BitFieldRead64 (LinearAddress + Offset, BitStart= , BitStart + 9 - 1); - RegionLength =3D LShiftU64 (1, BitStart); - RegionMask =3D RegionLength - 1; - RegionStart =3D (LinearAddress + Offset) & ~RegionMask; + Index =3D PagingEntryIndex; + RegionMask =3D RegionLength - 1; + RegionStart =3D (LinearAddress + Offset) & ~RegionMask; =20 ParentAttribute->Uint64 =3D PageTableLibGetPnleMapAttribute (&ParentPagi= ngEntry->Pnle, ParentAttribute); =20 --=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 (#100686): https://edk2.groups.io/g/devel/message/100686 Mute This Topic: https://groups.io/mt/97358971/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- From nobody Mon Apr 29 05:29:08 2024 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+100687+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+100687+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837837; cv=none; d=zohomail.com; s=zohoarc; b=dGTVqI8VtGvpq4t4lDFzXt0GC0+5KmrRjUmZaEjMks4nWvUC4Dm8NctQp9d7N7ylw2kMS9jeU7BK08uMz0SvA1MEnDC/4fxRxFwUg9bq3EUOfTkG24Tk8I1mr+c6GdRsaQdOt99T8oJcfvLlGMOzhx+5kLOLMFeQoHay+WNrV9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837837; 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=QXSRsT3Ve617g8nj8P1qsZlb1j/nAq+A41mB+WwjiBU=; b=Z1nwCyuo7khbpey5HcJ2vVNuA5T2sjxXKaEXJX/Wt2+Ym+4T2fY9TVBe8sZJpLOCbCbM4O9yOdPALsxaPc0VIU255L/j0XAOTc7PfBZ0BN4Lmx35vGUtZJZTqzGmsxNRSPGTh87PngaiiY1vEpKZZVGLW3BkjnBVpP1Udxk5FWM= 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+100687+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 1677837837452964.1873092559813; Fri, 3 Mar 2023 02:03:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id NUgPYY1788612xHjLxrDEuy0; Fri, 03 Mar 2023 02:03:57 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:03:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831707" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831707" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818421017" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818421017" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:54 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 3/6] UefiCpuPkg/CpuPageTebleLib: Check input Mask in PageTableMap Date: Fri, 3 Mar 2023 18:03:33 +0800 Message-Id: <20230303100336.2138-4-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: JgemA9Or4McXw2QDGfCqjcjpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837837; bh=x8XLAiHTwzkoD9Ip/QDPXtSrkZn+R2n9O2YF7IlN+1E=; h=Cc:Date:From:Reply-To:Subject:To; b=vTrFhLqYxwB55cdJStAU4hN1+1eXgLfV8b3dgCUlUl+a8NizcXD1GLUnrEiJEr9fE+1 RYtXORDmIZPOVg74TtuhpvLGUnP3WLjlVjm5KPZWUjprNc2JGtnthumnOIjrDPovtMwRY bxZktia+SPKaoNyahv+5XCO91PTxwIuj4mY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837838484100009 Content-Type: text/plain; charset="utf-8" When creating new page table or mapping not-present range in existing page table, we need to make sure all the non-reserved fields of input Mask are not 0. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 50 ++++++++++++++++= +++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index d2f35aa375..21fdfb53c1 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -214,6 +214,28 @@ PageTableLibSetPnle ( Pnle->Bits.CacheDisabled =3D 0; } =20 +/** + Check if any Non-Reserved field of Mask is 0. When creating new page tab= le or mapping not-present + range, we need to make sure all the non-reserved fields of input Mask ar= e not 0. + + @param[in] Mask The mask used for attribute to check. +**/ +RETURN_STATUS +CheckMaskNonReservedBit ( + IN IA32_MAP_ATTRIBUTE *Mask + ) +{ + if ((Mask->Bits.Present =3D=3D 0) || (Mask->Bits.ReadWrite =3D=3D 0) || = (Mask->Bits.UserSupervisor =3D=3D 0) || + (Mask->Bits.WriteThrough =3D=3D 0) || (Mask->Bits.CacheDisabled =3D= =3D 0) || (Mask->Bits.Accessed =3D=3D 0) || + (Mask->Bits.Dirty =3D=3D 0) || (Mask->Bits.Pat =3D=3D 0) || (Mask->B= its.Global =3D=3D 0) || + (Mask->Bits.PageTableBaseAddress =3D=3D 0) || (Mask->Bits.Protection= Key =3D=3D 0) || (Mask->Bits.Nx =3D=3D 0)) + { + return RETURN_INVALID_PARAMETER; + } + + return RETURN_SUCCESS; +} + /** Update page table to map [LinearAddress, LinearAddress + Length) with sp= ecified attribute in the specified level. =20 @@ -259,6 +281,7 @@ PageTableLibMapInLevel ( UINTN Index; IA32_PAGING_ENTRY *PagingEntry; UINTN PagingEntryIndex; + UINTN PagingEntryIndexLimit; IA32_PAGING_ENTRY *CurrentPagingEntry; UINT64 RegionLength; UINT64 SubLength; @@ -302,6 +325,15 @@ PageTableLibMapInLevel ( // =20 if (ParentPagingEntry->Pce.Present =3D=3D 0) { + // + // [LinearAddress, LinearAddress + Length] contains not-present range,= we need to + // make sure all the non-reserved fields of Mask are not 0. + // + Status =3D CheckMaskNonReservedBit (Mask); + if (RETURN_ERROR (Status)) { + return Status; + } + // // The parent entry is CR3 or PML5E/PML4E/PDPTE/PDE. // It does NOT point to an existing page directory. @@ -371,6 +403,23 @@ PageTableLibMapInLevel ( } } } else { + PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_T= ABLE_BASE_ADDRESS (&ParentPagingEntry->Pnle); + PagingEntryIndexLimit =3D (UINTN)BitFieldRead64 (LinearAddress + Lengt= h - 1, BitStart, BitStart + 9 - 1); + for (Index =3D PagingEntryIndex; Index <=3D PagingEntryIndexLimit; Ind= ex++) { + if (PagingEntry[Index].Pce.Present =3D=3D 0) { + // + // [LinearAddress, LinearAddress + Length] contains not-present ra= nge, we need to + // make sure all the non-reserved fields of Mask are not 0. + // + Status =3D CheckMaskNonReservedBit (Mask); + if (RETURN_ERROR (Status)) { + return Status; + } + + break; + } + } + // // It's a non-leaf entry // @@ -418,7 +467,6 @@ PageTableLibMapInLevel ( // Update child entries to use restrictive attribute inherited fro= m parent. // e.g.: Set PDE[0-255].ReadWrite =3D 0 // - PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_B= ASE_ADDRESS (&ParentPagingEntry->Pnle); for (Index =3D 0; Index < 512; Index++) { if (PagingEntry[Index].Pce.Present =3D=3D 0) { continue; --=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 (#100687): https://edk2.groups.io/g/devel/message/100687 Mute This Topic: https://groups.io/mt/97358972/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- From nobody Mon Apr 29 05:29:08 2024 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+100688+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+100688+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837840; cv=none; d=zohomail.com; s=zohoarc; b=hlvh4gIWCqQHrDaTMPArvzd/4e2nZRRdQYfxjLB1XvX/p6nhuKdoEcr/IDvsG+eMh1gWXsFSwii4LkNsj6MMVCMw33dm0EM2xGawfgB7u/xG91lyrS1QZEwCGYGf5lb6fsoXKAnWTTJuVni5KKSVy7o4PNIyFtTDhGhfmiDd9vo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837840; 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=qY6FmyLRsut7VNxlg+AhGFwnm9dl6we3QMHeFGEmPsM=; b=C1aa/sF7nGOFf2gOdptEdNVynyStDGyjmpB1wQSX4Ii2ToPWrAmKcTjtDy4eriM0uDkdYYGx1wHD8aj34DAhmxZXY9jyTWWhEHwNOq/Mi/Cv104je01gM56dspftyRIds8r0nRaT2CpJrpM020RHJDlgXvo8lZkmVYXkd7WzITE= 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+100688+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 1677837840018606.5760523369042; Fri, 3 Mar 2023 02:04:00 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id cX6KYY1788612xJG4EkTt5zt; Fri, 03 Mar 2023 02:03:59 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:03:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831733" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831733" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818421040" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818421040" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:56 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 4/6] UefiCpuPkg/CpuPageTableLib: Add manual TestCase to check input Mask Date: Fri, 3 Mar 2023 18:03:34 +0800 Message-Id: <20230303100336.2138-5-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: pvq7SP1NgPo67uJXqur9Phgdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837839; bh=8aQ/sBW9QqVpZpySXmcOF9ZXzdmeHmQJGHtijNhSSHI=; h=Cc:Date:From:Reply-To:Subject:To; b=CxHU38OChQpEs50hA06CrX4XXzmI5EUr9ZOj0M++VQgm/q+D6DpUcpmpqomNJaJQWuv 2Wlml8FLIwhFUwzP6V9zROK13SQ4n/2S/giBb/Epu+5kfawTLtT1qHombOgFImLfiJ0TM MIkwfw6qqIhUK/89c01aYMNxrYhuNPO1KE0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837840502100014 Content-Type: text/plain; charset="utf-8" Add manual test case to check input Mask. When creating new page table or mapping not-present range in existing page table, all the non-reserved fields of Mask should not be 0. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.c = | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUni= tTestHost.c b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUn= itTestHost.c index 3014a03243..5957b80d6e 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHo= st.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHo= st.c @@ -697,6 +697,126 @@ TestCaseManualChangeNx ( return UNIT_TEST_PASSED; } =20 +/** + Check if the input Mask is expected when creating new page table or map = not-present + range in existing page table. + + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that = the + contents are well understood by all test cases th= at may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestCaseToCheckMapMask ( + IN UNIT_TEST_CONTEXT Context + ) +{ + UINTN PageTable; + PAGING_MODE PagingMode; + VOID *Buffer; + UINTN PageTableBufferSize; + IA32_MAP_ATTRIBUTE MapAttribute; + IA32_MAP_ATTRIBUTE ExpectedMapAttribute; + IA32_MAP_ATTRIBUTE MapMask; + RETURN_STATUS Status; + IA32_MAP_ENTRY *Map; + UINTN MapCount; + + PagingMode =3D Paging4Level; + PageTableBufferSize =3D 0; + PageTable =3D 0; + Buffer =3D NULL; + MapAttribute.Uint64 =3D 0; + MapAttribute.Bits.Present =3D 1; + MapMask.Uint64 =3D 0; + MapMask.Bits.Present =3D 1; + // + // Create Page table to cover [0, 1G]. All fields of MapMask should be s= et. + // + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBuffe= rSize, 0, SIZE_1GB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_INVALID_PARAMETER); + MapMask.Uint64 =3D MAX_UINT64; + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTa= bleBufferSize, 0, SIZE_1GB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); + Buffer =3D AllocatePages (EFI_SIZE_TO_PAGES (PageTableBufferSize)); + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBuffe= rSize, 0, SIZE_1GB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); + + // + // Update Page table to cover [1G, 2G - 8K]. All fields of MapMask shoul= d be set. + // + PageTableBufferSize =3D 0; + MapAttribute.Uint64 =3D SIZE_1GB; + MapAttribute.Bits.Present =3D 1; + MapMask.Uint64 =3D 0; + MapMask.Bits.Present =3D 1; + Status =3D PageTableMap (&PageTable, PagingMode, Buff= er, &PageTableBufferSize, SIZE_1GB, SIZE_1GB - SIZE_8KB, &MapAttribute, &Ma= pMask); + UT_ASSERT_EQUAL (Status, RETURN_INVALID_PARAMETER); + MapMask.Uint64 =3D MAX_UINT64; + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTa= bleBufferSize, SIZE_1GB, SIZE_1GB - SIZE_8KB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); + Buffer =3D AllocatePages (EFI_SIZE_TO_PAGES (PageTableBufferSize)); + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTableBuffe= rSize, SIZE_1GB, SIZE_1GB - SIZE_8KB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); + + // + // Update Page table to cover [2G - 8K, 2G]. All fields of MapMask shoul= d be set. + // + PageTableBufferSize =3D 0; + MapAttribute.Uint64 =3D SIZE_2GB - SIZE_8KB; + MapAttribute.Bits.Present =3D 1; + MapMask.Uint64 =3D 0; + MapMask.Bits.Present =3D 1; + Status =3D PageTableMap (&PageTable, PagingMode, Buff= er, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &Ma= pMask); + UT_ASSERT_EQUAL (Status, RETURN_INVALID_PARAMETER); + MapMask.Uint64 =3D MAX_UINT64; + Status =3D PageTableMap (&PageTable, PagingMode, Buffer, &PageTa= bleBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &MapMask); + UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); + + // + // Update Page table to set [2G - 8K, 2G] as RW. Only need to set the Ma= pMask.Bits.ReadWrite to 1. + // + PageTableBufferSize =3D 0; + MapAttribute.Uint64 =3D 0; + MapAttribute.Bits.ReadWrite =3D 1; + MapMask.Uint64 =3D 0; + MapMask.Bits.ReadWrite =3D 1; + Status =3D PageTableMap (&PageTable, PagingMode, Bu= ffer, &PageTableBufferSize, SIZE_2GB - SIZE_8KB, SIZE_8KB, &MapAttribute, &= MapMask); + UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); + + MapCount =3D 0; + Status =3D PageTableParse (PageTable, PagingMode, NULL, &MapCount); + UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); + Map =3D AllocatePages (EFI_SIZE_TO_PAGES (MapCount* sizeof (IA32_MAP_= ENTRY))); + Status =3D PageTableParse (PageTable, PagingMode, Map, &MapCount); + UT_ASSERT_EQUAL (Status, RETURN_SUCCESS); + + // + // There should be two ranges [0, 2G-8k] with RW =3D 0 and [2G-8k, 2G] w= ith RW =3D 1 + // + UT_ASSERT_EQUAL (MapCount, 2); + UT_ASSERT_EQUAL (Map[0].LinearAddress, 0); + UT_ASSERT_EQUAL (Map[0].Length, SIZE_2GB - SIZE_8KB); + ExpectedMapAttribute.Uint64 =3D 0; + ExpectedMapAttribute.Bits.Present =3D 1; + UT_ASSERT_EQUAL (Map[0].Attribute.Uint64, ExpectedMapAttribute.Uint64); + UT_ASSERT_EQUAL (Map[1].LinearAddress, SIZE_2GB - SIZE_8KB); + UT_ASSERT_EQUAL (Map[1].Length, SIZE_8KB); + ExpectedMapAttribute.Uint64 =3D SIZE_2GB - SIZE_8KB; + ExpectedMapAttribute.Bits.Present =3D 1; + ExpectedMapAttribute.Bits.ReadWrite =3D 1; + UT_ASSERT_EQUAL (Map[1].Attribute.Uint64, ExpectedMapAttribute.Uint64); + return UNIT_TEST_PASSED; +} + /** Initialize the unit test framework, suite, and unit tests for the sample unit tests and run the unit tests. @@ -746,7 +866,7 @@ UefiTestMain ( AddTestCase (ManualTestCase, "Check if the parent entry has different Re= adWrite attribute", "Manual Test Case5", TestCaseManualChangeReadWrite, NUL= L, NULL, NULL); AddTestCase (ManualTestCase, "Check if the parent entry has different Nx= attribute", "Manual Test Case6", TestCaseManualChangeNx, NULL, NULL, NULL); AddTestCase (ManualTestCase, "Check if the needed size is expected", "Ma= nual Test Case7", TestCaseManualSizeNotMatch, NULL, NULL, NULL); - + AddTestCase (ManualTestCase, "Check MapMask when creating new page table= or mapping not-present range", "Manual Test Case8", TestCaseToCheckMapMask= , NULL, NULL, NULL); // // Populate the Random Test Cases. // --=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 (#100688): https://edk2.groups.io/g/devel/message/100688 Mute This Topic: https://groups.io/mt/97358975/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- From nobody Mon Apr 29 05:29:08 2024 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+100689+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+100689+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837841; cv=none; d=zohomail.com; s=zohoarc; b=J/p30mzLmgeTRr6PpRIHsXMqRQzeehH1bpsYUgfopDspa2ShsDtyzKecv/BXGaChuYtJJ8q3eH753YVFF6i7EjoMFtUIO/29lf3aDmBsQXav/owRHV1cSlQg0WP+SduzbgyQbXdftxRvdCzCjoYvX62pexG/gKOC+iNpfeg+tlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837841; 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=+5bFHzg4KJ/R8n5vGP6V8VKeaT6YhY4mOf4uNQ62lFo=; b=d9cm3gWdKNeFLD9xMSwVqATwyPT2bRAUA512LHaAGokm2/nXf4YYOr4sp3IrzWtKMmAWDkekSsc1hyRlErzzj8qDmYUor6rxjOXO6poLVSG7A5n73H2gy0/jH8BSZQSyNCBjnqq32A59weDqsW58V5llJchlxHH+eKLpw4qU150= 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+100689+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 1677837841628346.41192352840517; Fri, 3 Mar 2023 02:04:01 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uRQbYY1788612x2mzTQo2bDU; Fri, 03 Mar 2023 02:04:01 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:04:00 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831753" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831753" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:04:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818421061" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818421061" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:03:58 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Zhiguang Liu Subject: [edk2-devel] [PATCH 5/6] UefiCpuPkg/CpuPageTableLib: Modify RandomTest to check Mask Date: Fri, 3 Mar 2023 18:03:35 +0800 Message-Id: <20230303100336.2138-6-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: twjhqhHGO7BPaf22PVqcTWgnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837841; bh=vN1p9f77s1PGQKzlQG8No2H8ZAW5G+lNhT/5NLQMhUE=; h=Cc:Date:From:Reply-To:Subject:To; b=FLcxzdyKE4t3lVhkdSckjWveXIu4yva9I4R0eqWBjvYwz5LE1GgqfaJ4vQOU/feVNPx ZWjCLTk5JpH0eornMrwLxr2uEeUR+SKWxk07XfNOMx4kyJspbc24Y37BusrNJMp7qBEQa CR5+Qh2iSO/QFUjTAC3zlGf38K+BAq15Ttc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837842503100017 Content-Type: text/plain; charset="utf-8" Modify RandomTest to check invalid input. When creating new page table or mapping not-present range in existing page table, if any non-reserved field of input Mask are 0, the return status of PageTableMap () should be RETURN_INVALID_PARAMETER. 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 | 164 +++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++-----------------------------------------= --- 1 file changed, 120 insertions(+), 44 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c b/Uef= iCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c index 97a388ca1c..69d01db451 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/RandomTest.c @@ -81,22 +81,6 @@ LocalRandomBytes ( } } =20 -/** - Return a random boolean. - - @return boolean -**/ -BOOLEAN -RandomBoolean ( - VOID - ) -{ - BOOLEAN Value; - - LocalRandomBytes ((UINT8 *)&Value, sizeof (BOOLEAN)); - return Value%2; -} - /** Return a 32bit random number. =20 @@ -139,6 +123,21 @@ Random64 ( return (UINT64)(Value % (Limit - Start + 1)) + Start; } =20 +/** + Returns true with the percentage of input Probability. + + @param[in] Probability The percentage to return true. + + @return boolean +**/ +BOOLEAN +RandomBoolean ( + UINT8 Probability + ) +{ + return ((Probability > ((UINT8)Random64 (0, 100))) ? TRUE : FALSE); +} + /** Check if the Page table entry is valid =20 @@ -178,7 +177,7 @@ ValidateAndRandomeModifyPageTablePageTableEntry ( UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskLeaf[Level].Uint64= ), PagingEntry->Uint64); } =20 - if ((RandomNumber < 100) && RandomBoolean ()) { + if ((RandomNumber < 100) && RandomBoolean (50)) { RandomNumber++; if (Level =3D=3D 1) { TempPhysicalBase =3D PagingEntry->Pte4K.Bits.PageTableBaseAddress; @@ -211,7 +210,7 @@ ValidateAndRandomeModifyPageTablePageTableEntry ( UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskNoLeaf[Level].Uint64= ), PagingEntry->Uint64); } =20 - if ((RandomNumber < 100) && RandomBoolean ()) { + if ((RandomNumber < 100) && RandomBoolean (50)) { RandomNumber++; TempPhysicalBase =3D PagingEntry->Pnle.Bits.PageTableBaseAddress; =20 @@ -274,6 +273,27 @@ ValidateAndRandomeModifyPageTable ( return Status; } =20 +/** + Remove the last MAP_ENTRY in MapEntrys. + + @param MapEntrys Pointer to MapEntrys buffer +**/ +VOID +RemoveLastMapEntry ( + IN OUT MAP_ENTRYS *MapEntrys + ) +{ + UINTN MapsIndex; + + if (MapEntrys->Count =3D=3D 0) { + return; + } + + MapsIndex =3D MapEntrys->Count - 1; + ZeroMem (&(MapEntrys->Maps[MapsIndex]), sizeof (MAP_ENTRY)); + MapEntrys->Count =3D MapsIndex; +} + /** Generate single random map entry. The map entry can be the input of function PageTableMap @@ -299,7 +319,7 @@ GenerateSingleRandomMapEntry ( // // use AlignedTable to avoid that a random number can be very hard to be= 1G or 2M aligned // - if ((MapsIndex !=3D 0) && (RandomBoolean ())) { + if ((MapsIndex !=3D 0) && (RandomBoolean (50))) { FormerLinearAddress =3D MapEntrys->Maps[Random32 (0, (UINT32)MapsIndex= -1)].LinearAddress; if (FormerLinearAddress < 2 * (UINT64)SIZE_1GB) { FormerLinearAddressBottom =3D 0; @@ -323,12 +343,21 @@ GenerateSingleRandomMapEntry ( // MapEntrys->Maps[MapsIndex].Length =3D Random64 (0, MIN (MaxAddress - Map= Entrys->Maps[MapsIndex].LinearAddress, 10 * (UINT64)SIZE_1GB)) & AlignedTab= le[Random32 (0, ARRAY_SIZE (AlignedTable) -1)]; =20 - if ((MapsIndex !=3D 0) && (RandomBoolean ())) { + if ((MapsIndex !=3D 0) && (RandomBoolean (50))) { MapEntrys->Maps[MapsIndex].Attribute.Uint64 =3D MapEntrys->Maps[Random= 32 (0, (UINT32)MapsIndex-1)].Attribute.Uint64; MapEntrys->Maps[MapsIndex].Mask.Uint64 =3D MapEntrys->Maps[Random= 32 (0, (UINT32)MapsIndex-1)].Mask.Uint64; } else { MapEntrys->Maps[MapsIndex].Attribute.Uint64 =3D Random64 (0, MAX_UINT6= 4) & mSupportedBit.Uint64; - MapEntrys->Maps[MapsIndex].Mask.Uint64 =3D Random64 (0, MAX_UINT6= 4) & mSupportedBit.Uint64; + if (RandomBoolean (5)) { + // + // The probability to get random Mask should be small since all bits= of a random number + // have a high probability of containing 0, which may be a invalid i= nput. + // + MapEntrys->Maps[MapsIndex].Mask.Uint64 =3D Random64 (0, MAX_UINT64) = & mSupportedBit.Uint64; + } else { + MapEntrys->Maps[MapsIndex].Mask.Uint64 =3D MAX_UINT64; + } + if (MapEntrys->Maps[MapsIndex].Mask.Bits.ProtectionKey !=3D 0) { MapEntrys->Maps[MapsIndex].Mask.Bits.ProtectionKey =3D 0xF; } @@ -338,15 +367,7 @@ GenerateSingleRandomMapEntry ( MapEntrys->Maps[MapsIndex].Attribute.Bits.PageTableBaseAddress =3D Map= Entrys->Maps[MapsIndex].LinearAddress >> 12; MapEntrys->Maps[MapsIndex].Mask.Bits.PageTableBaseAddress =3D 0xF= FFFFFFFFF; } else { - // - // Todo: If the mask bit for base address is zero, when dump the paget= able, every entry mapping to physical address zeor. - // This means the map count will be a large number, and impossib= le to finish in proper time. - // Need to avoid such case when remove the Random option ONLY_ON= E_ONE_MAPPING - // MapEntrys->Maps[MapsIndex].Attribute.Bits.PageTableBaseAddress =3D (Ra= ndom64 (0, (((UINT64)1)<<52) - 1) & AlignedTable[Random32 (0, ARRAY_SIZE (A= lignedTable) -1)])>> 12; - if (RandomBoolean ()) { - MapEntrys->Maps[MapsIndex].Mask.Bits.PageTableBaseAddress =3D 0; - } } =20 MapEntrys->Count +=3D 1; @@ -609,23 +630,65 @@ SingleMapEntryTest ( IN UINTN InitMapCount ) { - UINTN MapsIndex; - RETURN_STATUS Status; - UINTN PageTableBufferSize; - VOID *Buffer; - IA32_MAP_ENTRY *Map; - UINTN MapCount; - UINTN Index; - UINTN KeyPointCount; - UINTN NewKeyPointCount; - UINT64 *KeyPointBuffer; - UINTN Level; - UINT64 Value; - UNIT_TEST_STATUS TestStatus; - - MapsIndex =3D MapEntrys->Count; + UINTN MapsIndex; + RETURN_STATUS Status; + UINTN PageTableBufferSize; + VOID *Buffer; + IA32_MAP_ENTRY *Map; + UINTN MapCount; + UINTN Index; + UINTN KeyPointCount; + UINTN NewKeyPointCount; + UINT64 *KeyPointBuffer; + UINTN Level; + UINT64 Value; + UNIT_TEST_STATUS TestStatus; + IA32_MAP_ATTRIBUTE *Mask; + UINTN PreviousAddress; + BOOLEAN IsNotPresent; + + MapsIndex =3D MapEntrys->Count; + MapCount =3D 0; + PreviousAddress =3D 0; + IsNotPresent =3D FALSE; =20 GenerateSingleRandomMapEntry (MaxAddress, MapEntrys); + Status =3D PageTableParse (*PageTable, PagingMode, NULL, &MapCount); + + // + // Return Status should be InvalidParameter when: + // 1. MapEntrys->Maps[MapsIndex] contains not-present range. + // 2. MapEntrys->Maps[MapsIndex].Mask contains zero value field. + // + if (MapEntrys->Maps[MapsIndex].Length > 0) { + if (MapCount !=3D 0) { + UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); + Map =3D AllocatePages (EFI_SIZE_TO_PAGES (MapCount * sizeof (IA32_MA= P_ENTRY))); + ASSERT (Map !=3D NULL); + Status =3D PageTableParse (*PageTable, PagingMode, Map, &MapCount); + + if (Map[MapCount - 1].LinearAddress + Map[MapCount - 1].Length < Map= Entrys->Maps[MapsIndex].LinearAddress + MapEntrys->Maps[MapsIndex].Length) { + IsNotPresent =3D TRUE; + } else { + for (Index =3D 0; Index < MapCount; Index++) { + if ((PreviousAddress < Map[Index].LinearAddress) && + (MapEntrys->Maps[MapsIndex].LinearAddress < Map[Index].Linea= rAddress) && + ((MapEntrys->Maps[MapsIndex].LinearAddress + MapEntrys->Maps= [MapsIndex].Length) > PreviousAddress)) + { + // + // MapEntrys->Maps[MapsIndex] contains not-present range in ex= siting page table. + // + IsNotPresent =3D TRUE; + break; + } + + PreviousAddress =3D (UINTN)(Map[Index].LinearAddress + Map[Index= ].Length); + } + } + } else { + IsNotPresent =3D TRUE; + } + } =20 PageTableBufferSize =3D 0; Status =3D PageTableMap ( @@ -638,6 +701,19 @@ SingleMapEntryTest ( &MapEntrys->Maps[MapsIndex].Attribute, &MapEntrys->Maps[MapsIndex].Mask ); + + Mask =3D &MapEntrys->Maps[MapsIndex].Mask; + if (((Mask->Bits.Present =3D=3D 0) || (Mask->Bits.ReadWrite =3D=3D 0) ||= (Mask->Bits.UserSupervisor =3D=3D 0) || + (Mask->Bits.WriteThrough =3D=3D 0) || (Mask->Bits.CacheDisabled =3D= =3D 0) || (Mask->Bits.Accessed =3D=3D 0) || + (Mask->Bits.Dirty =3D=3D 0) || (Mask->Bits.Pat =3D=3D 0) || (Mask->= Bits.Global =3D=3D 0) || + (Mask->Bits.PageTableBaseAddress =3D=3D 0) || (Mask->Bits.Protectio= nKey =3D=3D 0) || (Mask->Bits.Nx =3D=3D 0)) && + IsNotPresent) + { + RemoveLastMapEntry (MapEntrys); + UT_ASSERT_EQUAL (Status, RETURN_INVALID_PARAMETER); + return UNIT_TEST_PASSED; + } + if (PageTableBufferSize !=3D 0) { UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); =20 --=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 (#100689): https://edk2.groups.io/g/devel/message/100689 Mute This Topic: https://groups.io/mt/97358976/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- From nobody Mon Apr 29 05:29:08 2024 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+100690+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+100690+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1677837843; cv=none; d=zohomail.com; s=zohoarc; b=Ba5JuMYwZpF3JMool9HAmmdlQjIemX5pvlCmNz1BP6lKBwPztFYh4ExdmaxeTfKx5CHQ5naVLgxfOIhh2DP00vGndyyuycCJF7jRX/3sz0CZtqcJn/n4Si4la58c/aSTKO1SP5sND1y7lUGdkmRowbQ/Y0I+K+BOnCWX500XO2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677837843; 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=GeK+Q0kjM/08HPnUxo/MEqzLPSueI28+ILQ3GD04KmY=; b=XxKXGI7j3fYDu+ae/5TkFHVHl6s+pk3xHraR3HqHGe+RGTGbNwo0FFD7Fag2dNCasyT4HZtsSdC2C7FFTr/OoSsx8W0SH8JEuPnuHdOA7mVU6qqYKd5Eeg4J7JV3neRSg6UPqhsW91lQHVS9wvAZZTu2NqkR7iWiXaBqxIAEe5A= 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+100690+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 1677837843959477.6253630685758; Fri, 3 Mar 2023 02:04:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id h9LHYY1788612x7liKeAWdzK; Fri, 03 Mar 2023 02:04:03 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.19850.1677837828807486048 for ; Fri, 03 Mar 2023 02:04:02 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="318831779" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="318831779" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:04:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="818421087" X-IronPort-AV: E=Sophos;i="5.98,230,1673942400"; d="scan'208";a="818421087" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2023 02:04:01 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 6/6] UefiCpuPkg/CpuPageTableLib: Enable non-1:1 mapping in random test Date: Fri, 3 Mar 2023 18:03:36 +0800 Message-Id: <20230303100336.2138-7-dun.tan@intel.com> In-Reply-To: <20230303100336.2138-1-dun.tan@intel.com> References: <20230303100336.2138-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: RYlbP6ry00A0c0l9GcR2CafTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677837843; bh=yWKR3E/imBWU/sNJIFj7fPDgckzOTEQSJsJL+z1or8k=; h=Cc:Date:From:Reply-To:Subject:To; b=w38lqqv0J4/owHhFXlC2bE5Xm+Jmgxgar2u9dsTlpF2gmxGYRaHlpofk2VMvP4XY/VC VGnbNLpHo+uD2LBNTUowAjmaJ2AGr7TzJh3DiKA7Fd7TBS2CDX+hudhU3He5Ribx3OmUH 57QxeZ3l+4F4KmVW5nFtvTj5OOPJtaetoLs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677837844469100021 Content-Type: text/plain; charset="utf-8" Enable non-1:1 mapping in random test. In previous test, non-1:1 test will fail due to the non-1:1 mapping issue in CpuPageTableLib and invalid Input Mask when creating new page table or mapping not-present range. Now these issue have been fixed. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHost.c = | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUni= tTestHost.c b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUn= itTestHost.c index 5957b80d6e..65b717b9ac 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHo= st.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/CpuPageTableLibUnitTestHo= st.c @@ -9,10 +9,10 @@ #include "CpuPageTableLibUnitTest.h" =20 // -----------------------------------------------------------------------= PageMode--TestCount-TestRangeCount---RandomOptions -static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging4Level = =3D { Paging4Level, 100, 20, ONLY_ONE_ONE_MAPPING|USE_RANDOM_ARRAY }; -static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging4Level1GB= =3D { Paging4Level1GB, 100, 20, ONLY_ONE_ONE_MAPPING|USE_RANDOM_ARRAY }; -static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging5Level = =3D { Paging5Level, 100, 20, ONLY_ONE_ONE_MAPPING|USE_RANDOM_ARRAY }; -static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging5Level1GB= =3D { Paging5Level1GB, 100, 20, ONLY_ONE_ONE_MAPPING|USE_RANDOM_ARRAY }; +static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging4Level = =3D { Paging4Level, 100, 20, USE_RANDOM_ARRAY }; +static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging4Level1GB= =3D { Paging4Level1GB, 100, 20, USE_RANDOM_ARRAY }; +static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging5Level = =3D { Paging5Level, 100, 20, USE_RANDOM_ARRAY }; +static CPU_PAGE_TABLE_LIB_RANDOM_TEST_CONTEXT mTestContextPaging5Level1GB= =3D { Paging5Level1GB, 100, 20, USE_RANDOM_ARRAY }; =20 /** Check if the input parameters are not supported. --=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 (#100690): https://edk2.groups.io/g/devel/message/100690 Mute This Topic: https://groups.io/mt/97358977/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-