From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CVsIAlRq; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658150328; x=1689686328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s70eyFZbHD51e/YgjB/YNtTOjrqdT2nsv503P7gxFxk=; b=CVsIAlRq98ZN7l/T4wGv05W0zZpf+//B65uj6qiOxJ4K79HMdlyC4cEK y3iQl4OlrcLjq2zTIZOtJQwnAMO5rIyZXFAC7iEEqRIQHFxdzpORcbN5f V0E/A5tRQnN/yEmPm7IcQBkTTkjoY9iEj25nN3kgKp1dcnNjjkFcKyJs+ TOFzOJ13NU4l00MuxMx5qxxEkCKV2erluWIp1dpzRVzkJvhhDjhDLqITO RiGRVWep9RR3eCQjICiZNeylKfBbowlxMVvfj2nEMWSQ6as5yMHs1TQa0 PNuFhete1o+aXmIftwFy22I2tIRDkpQyIgAz4MdJReNZrNPY2LmkNlOBh g==; 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" 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" 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: [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> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220718131831.660-1-ray.ni@intel.com> References: <20220718131831.660-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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;=0D UINTN Index;=0D IA32_PAGING_ENTRY *PagingEntry;=0D + IA32_PAGING_ENTRY *CurrentPagingEntry;=0D UINT64 RegionLength;=0D UINT64 SubLength;=0D UINT64 SubOffset;=0D @@ -359,18 +360,20 @@ PageTableLibMapInLevel ( //=0D PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_AD= DRESS (&ParentPagingEntry->Pnle);=0D while (Offset < Length && Index < 512) {=0D - SubLength =3D MIN (Length - Offset, RegionStart + RegionLength - (Line= arAddress + Offset));=0D + CurrentPagingEntry =3D (!Modify && CreateNew) ? &OneOfPagingEntry : &P= agingEntry[Index];=0D + SubLength =3D MIN (Length - Offset, RegionStart + RegionLengt= h - (LinearAddress + Offset));=0D if ((Level <=3D MaxLeafLevel) &&=0D (((LinearAddress + Offset) & RegionMask) =3D=3D 0) &&=0D (((IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS (Attribute) + Offset= ) & RegionMask) =3D=3D 0) &&=0D - (SubLength =3D=3D RegionLength)=0D + (SubLength =3D=3D RegionLength) &&=0D + ((CurrentPagingEntry->Pce.Present =3D=3D 0) || IsPle (CurrentPagin= gEntry, Level))=0D )=0D {=0D //=0D // Create one entry mapping the entire region (1G, 2M or 4K).=0D //=0D if (Modify) {=0D - PageTableLibSetPle (Level, &PagingEntry[Index], Offset, Attribute,= Mask);=0D + PageTableLibSetPle (Level, CurrentPagingEntry, Offset, Attribute, = Mask);=0D }=0D } else {=0D //=0D @@ -382,7 +385,7 @@ PageTableLibMapInLevel ( // but the length is SMALLER than the RegionLength.=0D //=0D Status =3D PageTableLibMapInLevel (=0D - (!Modify && CreateNew) ? &OneOfPagingEntry : &PagingEntry= [Index],=0D + CurrentPagingEntry,=0D Modify,=0D Buffer,=0D BufferSize,=0D --=20 2.35.1.windows.2