From nobody Fri Oct 18 08:33:37 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+101743+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+101743+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1679637672; cv=none; d=zohomail.com; s=zohoarc; b=CPCQXKCJYjCpw+4kefSfXiZze7rJUoe/XcXQG83LE4HnURaDcTGZP+pdtiYwfPNc8eFzVKhgbHyWgdDVgchsqDWUO7mlc1oVd+A0OvVbZoU+Fij7SLbQEdmy4JzlRrvYzahE3iaB7xNooTOI/n9kcg9J0klUmHy56oS0kSunYZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679637672; 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=AUH6HSnJEknbY5iZUoVXgICyrFU7jLDH/OPVDLDYLQs=; b=UYMohwFCNSZhzMq5Lq8m60/3aQCk0aT13SNJ6LiuiQTodUI13Tx/WbSRQ3ypHLVQCWijt6pESu9xZX7y5nc3fqOyKcj0G3z50vA9Z9+JPcCIiUX1fykNS/aHVWjO6GGicq+yOruhH+EuCcv3u9gbp3O2v+bEKaMMYcfKE8jfpPg= 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+101743+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 1679637672440892.6076081458109; Thu, 23 Mar 2023 23:01:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q3HqYY1788612xmpGJB1Z9u8; Thu, 23 Mar 2023 23:01:11 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.94534.1679637641374533517 for ; Thu, 23 Mar 2023 23:01:11 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="320094066" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="320094066" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 23:01:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="1012122311" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="1012122311" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 23:01:09 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V5 18/22] UefiCpuPkg/CpuPageTableLib: Add check for page table creation Date: Fri, 24 Mar 2023 14:00:16 +0800 Message-Id: <20230324060020.940-19-dun.tan@intel.com> In-Reply-To: <20230324060020.940-1-dun.tan@intel.com> References: <20230324060020.940-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: qDL4yy3p4caYwzDzLCVWymN1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679637671; bh=ZHMpPvDZFd41fIo2nQOIyG6X7E6mZ2lWyv9DzyaUoJQ=; h=Cc:Date:From:Reply-To:Subject:To; b=imi0aH6dvAh0+2dgjUAgCYWOyitAP829pik8RgGF6Bc2fNHGQ57lbWWiLG+dUKCQjxC Gabv1yGCyX/4PVMvqC9M7TbGkGLa+dI6ZV/1+L3wf+aMFRVELLdv6s+cN/+yN6RbBn0wf EVjNMLFTb2mPYLBysKtZ3Y+GsBfgKPB4+u4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679637673430100026 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 Reviewed-by: Ray Ni Cc: Rahul Kumar Tested-by: Gerd Hoffmann Acked-by: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 3ea89aacaf..ad1e263084 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -361,6 +361,16 @@ PageTableLibMapInLevel ( return Status; } =20 + // + // Check the attribute in ParentPagingEntry is equal to attribute calc= ulated by input Attribue and Mask. + // + 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))) + { + 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 (#101743): https://edk2.groups.io/g/devel/message/101743 Mute This Topic: https://groups.io/mt/97818241/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-