From nobody Sun Feb 8 17:21:08 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+91455+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+91455+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1658150330; cv=none; d=zohomail.com; s=zohoarc; b=G8X1FgyLiJwXdtZHbUMzoLzWxwKY6w0xsG4NuDmVmZcTxSCK596C9UBcYNM19+9y4g7LjGMKPiM+q/5jTOwmMQkNaD374JkkXB4uPsHMvdnD6RXugsh95clDa7Un5gVJcomPfsVeI0wTGaz1kkSNLOkVGbLb62t2Ha22VcPjU4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658150330; 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=qwztI07HWZ7VTD4+k4W6rrTvyPOSb1oZfmAd963eHDY=; b=cyFt6L0YBLxvoejc76tPZ6JWoMhW3LQHrbx7gPZmkYSlB+LAeDwQlO23J/b92KSA2mOPmuoAUnP7l0YBek2C/7cJwg6xg1WON0+8s1sDWA06538HXWkRmpA3uREZFouqHW0dl++wh30hOiSEsTc6fzCDRs74PZMSWS7RcAA0FsA= 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+91455+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 1658150330299839.7482578044004; Mon, 18 Jul 2022 06:18:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CARvYY1788612xbnO5k6toPe; Mon, 18 Jul 2022 06:18:49 -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:48 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10411"; a="287363915" X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="287363915" 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:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="624724982" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga008.jf.intel.com with ESMTP; 18 Jul 2022 06:18:46 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Zhiguang Liu , Eric Dong Subject: [edk2-devel] [PATCH 06/10] CpuPageTableLib: Avoid treating non-leaf entry as leaf one Date: Mon, 18 Jul 2022 21:18:27 +0800 Message-Id: <20220718131831.660-7-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: BAOUbZP7Sl0SP8VVFiGLp2Dnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1658150329; bh=uL5c7Od8QYGrg2mDA/bD/TwGKqoYwCG9IC2jRK6MA2o=; h=Cc:Date:From:Reply-To:Subject:To; b=xPrHh47nNbBtFvPHKpemChKn19QEbu6m31HNUowuCX8J9fYoT6R5e+hFK4ML36Vwr59 KEGEzP/XAWDUlRvjEmse4UEWcNMmAoOnpBPyqik70M/VBztu/S9NBrmLknHzVfSmDIAeY dmPiT4uIWdQQvTDkoK28VATk/M1zJt0lIYM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1658150331549100027 Content-Type: text/plain; charset="utf-8" Today's logic wrongly treats the non-leaf entry as leaf entry and updates its paging attributes. The patch fixes the bug to only update paging attributes for non-present entries or leaf entries. Signed-off-by: Ray Ni Signed-off-by: Zhiguang Liu Cc: Eric Dong --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index dc37ca3647..a6aa1a352b 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -248,6 +248,7 @@ PageTableLibMapInLevel ( UINTN BitStart; UINTN Index; IA32_PAGING_ENTRY *PagingEntry; + IA32_PAGING_ENTRY *CurrentPagingEntry; UINT64 RegionLength; UINT64 SubLength; UINT64 SubOffset; @@ -359,18 +360,20 @@ PageTableLibMapInLevel ( // PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_AD= DRESS (&ParentPagingEntry->Pnle); while (Offset < Length && Index < 512) { - SubLength =3D MIN (Length - Offset, RegionStart + RegionLength - (Line= arAddress + Offset)); + CurrentPagingEntry =3D (!Modify && CreateNew) ? &OneOfPagingEntry : &P= agingEntry[Index]; + SubLength =3D MIN (Length - Offset, RegionStart + RegionLengt= h - (LinearAddress + Offset)); if ((Level <=3D MaxLeafLevel) && (((LinearAddress + Offset) & RegionMask) =3D=3D 0) && (((IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS (Attribute) + Offset= ) & RegionMask) =3D=3D 0) && - (SubLength =3D=3D RegionLength) + (SubLength =3D=3D RegionLength) && + ((CurrentPagingEntry->Pce.Present =3D=3D 0) || IsPle (CurrentPagin= gEntry, Level)) ) { // // Create one entry mapping the entire region (1G, 2M or 4K). // if (Modify) { - PageTableLibSetPle (Level, &PagingEntry[Index], Offset, Attribute,= Mask); + PageTableLibSetPle (Level, CurrentPagingEntry, Offset, Attribute, = Mask); } } else { // @@ -382,7 +385,7 @@ PageTableLibMapInLevel ( // but the length is SMALLER than the RegionLength. // Status =3D PageTableLibMapInLevel ( - (!Modify && CreateNew) ? &OneOfPagingEntry : &PagingEntry= [Index], + CurrentPagingEntry, Modify, Buffer, BufferSize, --=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 (#91455): https://edk2.groups.io/g/devel/message/91455 Mute This Topic: https://groups.io/mt/92458160/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-