From nobody Fri Dec 19 16:04:34 2025 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+101398+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+101398+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1679290509; cv=none; d=zohomail.com; s=zohoarc; b=VKLqN5FM1K/PmpFZaM//zKQw9S3ICyqsPosgxQegPVwK4WrQH3RGCvEMxGISr1cLZPSUyVZSJgH5P+WuboXNJSLfTCbyE9jgkyz9EHLJ7bMl3hDEH3Z9d7hxiXjPTVSgzR8AbxSrEq2mYhoDKbXMhFFXJhA1owNgumR02Dc+BLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679290509; 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=5W8mg/jX5LQf6xZZiRK5GXMtt/YBUbkIA/OvCTYusjU=; b=GB57l74CmvFb2FhQoZBDC+lVjEEMdB1q4hXRnDFGkbyHjAv+DPlo7/DvufIxRxYG5YKYNenKXTFF6+picZiUzG5Fg82ecw+D4/61Xq/wBll6JvI2weExUslf64HdvPg4/JUgQHPyMI8QjC9d/cO5Tdvi90l+NQZobD4j913F7to= 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+101398+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 1679290509835375.5240425043462; Sun, 19 Mar 2023 22:35:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5bAIYY1788612xrPzjZfPLSK; Sun, 19 Mar 2023 22:35:09 -0700 X-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:35:09 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="401155796" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="401155796" X-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:35:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="770059695" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="770059695" X-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:35:07 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V3 18/18] UefiCpuPkg: Combine branch for non-present and leaf ParentEntry Date: Mon, 20 Mar 2023 13:33:29 +0800 Message-Id: <20230320053329.410-19-dun.tan@intel.com> In-Reply-To: <20230320053329.410-1-dun.tan@intel.com> References: <20230320053329.410-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: NtcYigj31hYwOezfOdyVdBc4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679290509; bh=yR1vvWDO3om9A0+pytyYqN6xrJFk/IUqU5KeOyagfGQ=; h=Cc:Date:From:Reply-To:Subject:To; b=E+HXYbmUSmBxNLbEl9Maykp8nXIpV6tXn+z2ellA+CD+VDBbapYpNH8M84qFEePIlPa JR8A7Tc/Vi+Ye8W/XIt5TXP5ItFlwMKmoNSOjHd9hSTumCFi7TFxbai673qz9anpLq41g sSLgBmddUQjvID2appa3Dsd8sfvC25LZkyw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679290510632100013 Content-Type: text/plain; charset="utf-8" Combine the 'if' condition branch for non-present and leaf Parent Entry in PageTableLibMapInLevel. Most steps of these two condition are the same. This commit doesn't change any functionality. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 76 ++++++++++++++++= ++++++------------------------------------------------------ 1 file changed, 22 insertions(+), 54 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 29191d26b5..3e7cc2839f 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -345,65 +345,32 @@ PageTableLibMapInLevel ( // ParentPagingEntry ONLY is deferenced for checking Present and MustBeO= ne bits // when Modify is FALSE. // - - if (ParentPagingEntry->Pce.Present =3D=3D 0) { - // - // [LinearAddress, LinearAddress + Length] contains non-present range. - // - Status =3D IsAttributesAndMaskValidForNonPresentEntry (Attribute, Mask= ); - if (RETURN_ERROR (Status)) { - return Status; - } - - // - // Use NOP attributes as the attribute of grand-parents because CPU wi= ll consider - // 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_ATTRI= BUTE_ATTRIBUTES (Mask)) - =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & IA32_MAP_ATT= RIBUTE_ATTRIBUTES (Mask)))) && - ( ((Mask->Bits.PageTableBaseAddressLow =3D=3D 0) && (Mask->Bits.P= ageTableBaseAddressHigh =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. - // No need to split the page when the attributes equal. - // - return RETURN_SUCCESS; - } - + if ((ParentPagingEntry->Pce.Present =3D=3D 0) || IsPle (ParentPagingEntr= y, Level + 1)) { // - // The parent entry is CR3 or PML5E/PML4E/PDPTE/PDE. + // When ParentPagingEntry is non-present, parent entry is CR3 or PML5E= /PML4E/PDPTE/PDE. // It does NOT point to an existing page directory. + // When ParentPagingEntry is present, parent entry is leaf PDPTE_1G or= PDE_2M. Split to 2M or 4K pages. + // Note: it's impossible the parent entry is a PTE_4K. // - ASSERT (Buffer =3D=3D NULL || *BufferSize >=3D SIZE_4KB); - CreateNew =3D TRUE; - *BufferSize -=3D SIZE_4KB; + OneOfPagingEntry.Pnle.Uint64 =3D 0; + PleBAttribute.Uint64 =3D PageTableLibGetPleBMapAttribute (&Par= entPagingEntry->PleB, ParentAttribute); =20 - if (Modify) { - ParentPagingEntry->Uintn =3D (UINTN)Buffer + *BufferSize; - ZeroMem ((VOID *)ParentPagingEntry->Uintn, SIZE_4KB); + if (ParentPagingEntry->Pce.Present =3D=3D 0) { // - // Set default attribute bits for PML5E/PML4E/PDPTE/PDE. + // [LinearAddress, LinearAddress + Length] contains non-present rang= e. // - PageTableLibSetPnle (&ParentPagingEntry->Pnle, &NopAttribute, &AllOn= eMask); + Status =3D IsAttributesAndMaskValidForNonPresentEntry (Attribute, Ma= sk); + if (RETURN_ERROR (Status)) { + return Status; + } } else { - // - // Just make sure Present and MustBeZero (PageSize) bits are accurat= e. - // - OneOfPagingEntry.Pnle.Uint64 =3D 0; + PageTableLibSetPle (Level, &OneOfPagingEntry, 0, &PleBAttribute, &Al= lOneMask); } - } else if (IsPle (ParentPagingEntry, Level + 1)) { - // - // The parent entry is a PDPTE_1G or PDE_2M. Split to 2M or 4K pages. - // Note: it's impossible the parent entry is a PTE_4K. - // + // // Use NOP attributes as the attribute of grand-parents because CPU wi= ll consider // 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_ATTRI= BUTE_ATTRIBUTES (Mask)) =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & IA32_MAP_ATT= RIBUTE_ATTRIBUTES (Mask)))) && ( ((Mask->Bits.PageTableBaseAddressLow =3D=3D 0) && (Mask->Bits.P= ageTableBaseAddressHigh =3D=3D 0)) @@ -420,17 +387,18 @@ PageTableLibMapInLevel ( ASSERT (Buffer =3D=3D NULL || *BufferSize >=3D SIZE_4KB); CreateNew =3D TRUE; *BufferSize -=3D SIZE_4KB; - PageTableLibSetPle (Level, &OneOfPagingEntry, 0, &PleBAttribute, &AllO= neMask); if (Modify) { - // - // Create 512 child-level entries that map to 2M/4K. - // PagingEntry =3D (IA32_PAGING_ENTRY *)((UINTN)Buffer + *BufferSize); ZeroMem (PagingEntry, SIZE_4KB); =20 - for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { - PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffset; - SubOffset +=3D RegionLength; + if (ParentPagingEntry->Pce.Present) { + // + // Create 512 child-level entries that map to 2M/4K. + // + for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { + PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffse= t; + SubOffset +=3D RegionLength; + } } =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 (#101398): https://edk2.groups.io/g/devel/message/101398 Mute This Topic: https://groups.io/mt/97725716/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-