From nobody Mon Feb 9 15:08:50 2026 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+91458+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+91458+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1658150333; cv=none; d=zohomail.com; s=zohoarc; b=WlJ/2hqSPiViGR/eASrV2+IXNo8vwa25xPuZnGV/9OK+X6zdnOSVPuTYfzCjcz3/hQnCGiTnj2ixCgjT4BRTvhRdovYTD4DPTSOEym/UDDDF5fghBvBRca6nVQff1wMvkDcW4UKMeDsgBIJ6BVccNDHCCq85qIHeApRyJMBmHEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658150333; 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=3RYuJkjhD8qxFhIS7EHYINdqH5xxf/lwmGqrD2sKiEg=; b=lY5c6NxmvSj2szXmq3ngQMbe1OWcfQJXx9S8CMPqP19xVIi/BMLZAxA1sXNrYrrXId81wq17eHmBLNYrbS7WEwB1OYmnUcgz/T6RpAPTxluE7r/tNCqkDz0dVJ4MgnUdRExf9Qrz0hAAEV0NNByDLHSunbpdH3Ig7vCGLDUU2rw= 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+91458+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 1658150333571818.7291638005823; Mon, 18 Jul 2022 06:18:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tS8WYY1788612xY61vcHlC6k; Mon, 18 Jul 2022 06:18:53 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web08.27105.1658150328221476289 for ; Mon, 18 Jul 2022 06:18:52 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10411"; a="287363982" X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="287363982" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 06:18:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="624725037" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga008.jf.intel.com with ESMTP; 18 Jul 2022 06:18:50 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Zhiguang Liu , Eric Dong Subject: [edk2-devel] [PATCH 09/10] CpuPageTableLib: Fix bug that wrongly requires extra size for mapping Date: Mon, 18 Jul 2022 21:18:30 +0800 Message-Id: <20220718131831.660-10-ray.ni@intel.com> In-Reply-To: <20220718131831.660-1-ray.ni@intel.com> References: <20220718131831.660-1-ray.ni@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,ray.ni@intel.com X-Gm-Message-State: vOcmdVjo7RBclytku9wMJPGtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1658150333; bh=FKXzjuzsFGcsmjzlJtu6W8Q1RvuU4WYa0OqO7jxVq2s=; h=Cc:Date:From:Reply-To:Subject:To; b=DxnooW0iKfjwAKVyVdNcsF+Ys1xU0DHrn1/l6WAmHAfu89nQJbxDhRmasPTs+dgFYMg 3XGkjRBCQgCGoUUQsHWjQo+sFFTZZ5N8tHaGIepmZy7//hKVXoi6lHSlaZdP5c+kOdeha Sfzocc7f75XB0RhsibLv5XpGKAcZQ8PodeI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1658150335562100041 Content-Type: text/plain; charset="utf-8" With following paging structure to map [2M-4K, 2M] as P =3D 1, RW =3D 0, [2M, 4M] as P =3D 1, RW =3D 1: PML4[0] -> PDPTE[0] -> PDE[0](RW =3D 0) -> PTE[255](P =3D 0, RW =3D 0) -> PDE[1](RW =3D 1) When a new request to map [2M-4K, 2M+4K] as P =3D 1, RW =3D 1, CpuPageTableMap() wrongly requests 4K buffer size for the new mapping request. But in fact, for [2M-4K, 2M] request, PTE[255] can be changed in place, for [2M, 2M+4K], no change is needed because PDE[1].RW =3D 1 already. The change fixes the bug. Signed-off-by: Ray Ni Signed-off-by: Zhiguang Liu Cc: Eric Dong --- .../Library/CpuPageTableLib/CpuPageTableMap.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 1205119fc8..16e6697ed4 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -272,6 +272,7 @@ PageTableLibMapInLevel ( IA32_MAP_ATTRIBUTE ChildAttribute; IA32_MAP_ATTRIBUTE ChildMask; IA32_MAP_ATTRIBUTE CurrentMask; + IA32_MAP_ATTRIBUTE LocalParentAttribute; =20 ASSERT (Level !=3D 0); ASSERT ((Attribute !=3D NULL) && (Mask !=3D NULL)); @@ -284,6 +285,9 @@ PageTableLibMapInLevel ( NopAttribute.Bits.ReadWrite =3D 1; NopAttribute.Bits.UserSupervisor =3D 1; =20 + LocalParentAttribute.Uint64 =3D ParentAttribute->Uint64; + ParentAttribute =3D &LocalParentAttribute; + // // ParentPagingEntry ONLY is deferenced for checking Present and MustBeO= ne bits // when Modify is FALSE. @@ -420,7 +424,7 @@ PageTableLibMapInLevel ( } =20 if (IsPle (&PagingEntry[Index], Level)) { - PageTableLibSetPle (Level - 1, &PagingEntry[Index], 0, &ChildA= ttribute, &ChildMask); + PageTableLibSetPle (Level, &PagingEntry[Index], 0, &ChildAttri= bute, &ChildMask); } else { PageTableLibSetPnle (&PagingEntry[Index].Pnle, &ChildAttribute= , &ChildMask); } @@ -664,13 +668,6 @@ PageTableMap ( // // Update the page table when the supplied buffer is sufficient. // - ParentAttribute.Uint64 =3D 0; - ParentAttribute.Bits.PageTableBaseAddress =3D 1; - ParentAttribute.Bits.Present =3D 1; - ParentAttribute.Bits.ReadWrite =3D 1; - ParentAttribute.Bits.UserSupervisor =3D 1; - ParentAttribute.Bits.Nx =3D 0; - Status =3D PageTableLibMapInLevel ( &TopPagingEntry, &ParentAttribute, --=20 2.35.1.windows.2 -=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 (#91458): https://edk2.groups.io/g/devel/message/91458 Mute This Topic: https://groups.io/mt/92458167/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-