From nobody Fri Dec 19 15:59:36 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+101397+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+101397+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1679290507; cv=none; d=zohomail.com; s=zohoarc; b=VZG/0M++fq4qtNAEP7k4n70RVLNVnfM0pqxiArcR24rxYz7QnqTcJ39TCTsYATHccYnhhKb5gT+JyYITx2E7LGPIDWWq/1kCcovAl3OTKA5aJmQ1UekOctSAYhHW+5NsekqYfLxHqFFF81T7gt9jslM0aBlzxYuCtQPhLlh8GHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679290507; 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=rjR2+XKSz0eFE84oRsvgzTzyfK6fMXQ8yipwr7oO5YQ=; b=SKSylPZ1gOucevzgWH8sRWkJuBo8Z8hscKqhQ3/55NPJm9j8/d+kCrvdLKXk4XruXN7SjFPEn8e+EHg8PlQbHDn5vYLRcpxHbsS1gkNQwgaQ/g7My3Wae4wPNxwM3vZ3PZCF6ch+DPAqH7oX3XUzvoPF3BraEA/CSHM6bqaVa+U= 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+101397+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 1679290507776361.52987054986636; Sun, 19 Mar 2023 22:35:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3mdiYY1788612xsbVZIBquqh; Sun, 19 Mar 2023 22:35:07 -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:06 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="401155770" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="401155770" 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:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10654"; a="770059676" X-IronPort-AV: E=Sophos;i="5.98,274,1673942400"; d="scan'208";a="770059676" 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:04 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V3 17/18] UefiCpuPkg/CpuPageTableLib: Add check for page table creation Date: Mon, 20 Mar 2023 13:33:28 +0800 Message-Id: <20230320053329.410-18-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: cjuG77vpWmYeVb9BTLx8Frzox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679290507; bh=I4TTdKpxWdxqEJxscWGl6J9N5qE0DWIOKEUKneXwrXo=; h=Cc:Date:From:Reply-To:Subject:To; b=jUPKc13+mpGHpSXUJ1bUxX+AVgV84N7Lunu6KiWr+2gaPc6pvvW2UsgSbqNIeQmsAJ5 grscV1+wPsfDR9ruG0KPL893X5tPuvMXpproByOFzeqtg2FFlWgMN+3MiUK+0UPyo76RN s9vRtyOL4y7SSTg9AvZN5SrbK6XyaUYSb3g= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679290508630100009 Content-Type: text/plain; charset="utf-8" Add code to compare ParentPagingEntry Attribute&Mask and input Attribute&Mask to decide if new next level page table is needed in non-present ParentPagingEntry condition. This can help avoid unneccessary page table creation. For example, there is a page table in which [0, 1G] is mapped(Lv4[0] ,Lv3[0,0], a non-leaf level4 entry and a leaf level3 entry).And we only want to map [1G, 1G+2M] linear address still as non-present. The expected behaviour should be nothing happens in the process. However, previous code logic doesn't check if ParentPagingEntry Attribute&Mask and input Attribute&Mask are the same in non-present ParentPagingEntry condition. Then a new 4K memory is allocated for Lv2 since 1G+2M is not 1G-aligned. So when ParentPagingEntry is non-present, before allocate 4K memory for next level paging, we also check if ParentPagingEntry Attribute& Mask and input Attribute&Mask are the same. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 18 ++++++++++++++++= ++ 1 file changed, 18 insertions(+) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index fbfd6389dc..29191d26b5 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -355,6 +355,24 @@ PageTableLibMapInLevel ( return Status; } =20 + // + // 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; + } + // // The parent entry is CR3 or PML5E/PML4E/PDPTE/PDE. // It does NOT point to an existing page directory. --=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 (#101397): https://edk2.groups.io/g/devel/message/101397 Mute This Topic: https://groups.io/mt/97725715/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-