From nobody Mon Sep 16 19:33:23 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+101634+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+101634+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1679557283; cv=none; d=zohomail.com; s=zohoarc; b=eivbN5W6cHth0VHX+2JM/7KD/EauOphjHH4uchBaBk40unJLnONMUOSIXOBZQSqTsOiGK1YvC5LwdLheTgP2IQyS/RtmcPfbKC3LWDNzF1d5gBubE55LDRmmw7s5BEMbpTZkl4Bh25SwuH1OQZLfS87dpYU+cGupem3MQwmN1OY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679557283; 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=HLAZdgZ/f5zYCbQVnBUW7nPMMoDZPkdOLQNhwVx+qjw=; b=PCU65F5prG+ZKyx9wcALLvd9plcVCsRvWChOiWbK25+INK0ZQXeTgqCrl49fHTZePiqnO8pEgFCXSugNG0/IbdmXPDWiMJ3Kk53TZKZfb9hwHmgBdJrQyD+HRLnQSpiWMJGH9n+Qt+u9BcVTHwOLD4nMGooKBayp3qg3DlwAFaQ= 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+101634+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 1679557283786357.1284438002597; Thu, 23 Mar 2023 00:41:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Zm1eYY1788612xSa54SPgKEg; Thu, 23 Mar 2023 00:41:23 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web10.67098.1679557268568440146 for ; Thu, 23 Mar 2023 00:41:22 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="425699572" X-IronPort-AV: E=Sophos;i="5.98,283,1673942400"; d="scan'208";a="425699572" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 00:41:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="684616831" X-IronPort-AV: E=Sophos;i="5.98,283,1673942400"; d="scan'208";a="684616831" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 00:41:21 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V4 06/21] UefiCpuPkg/CpuPageTableLib: Fix issue when splitting leaf entry Date: Thu, 23 Mar 2023 15:40:42 +0800 Message-Id: <20230323074057.549-7-dun.tan@intel.com> In-Reply-To: <20230323074057.549-1-dun.tan@intel.com> References: <20230323074057.549-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: xj2aC3dJKDsccwOx5uecfbxmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679557283; bh=O9Ae5/7F2dzTqr1duUZ9IAKPEiDUfNDliLxM6ldeT/I=; h=Cc:Date:From:Reply-To:Subject:To; b=Qe/k90lzJISE5IDZkujECSTz9P1TpnXuFc1k3Au3POmXAOqO7pr9eID0FJYfh1tDGPo J1+izpnFFzlk8eR0beCef4tfLM28yjDmmN0bN0ZXLhDIkIUeD7IOwzy9ljYJblx0LtVg8 GZt6GuOjHqLVthHMe2YtmOAeG3ey4/PkQm8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679557284280100017 Content-Type: text/plain; charset="utf-8" When splitting leaf parent entry to smaller granularity, create child page table before modifing parent entry. In previous code logic, when splitting a leaf parent entry, parent entry will point to a null 4k memory before child page table is created in this 4k memory. When the page table to be modified is the page table in CR3, if the executed CpuPageTableLib code is in the range mapped by the modified leaf parent entry, then issue will happen. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index cf0cfeca77..76febdd42d 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -363,8 +363,13 @@ PageTableLibMapInLevel ( // // Create 512 child-level entries that map to 2M/4K. // - ParentPagingEntry->Uintn =3D (UINTN)Buffer + *BufferSize; - ZeroMem ((VOID *)ParentPagingEntry->Uintn, SIZE_4KB); + PagingEntry =3D (IA32_PAGING_ENTRY *)((UINTN)Buffer + *BufferSize); + ZeroMem (PagingEntry, SIZE_4KB); + + for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { + PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffset; + SubOffset +=3D RegionLength; + } =20 // // Set NOP attributes @@ -372,12 +377,7 @@ PageTableLibMapInLevel ( // will make the entire region read-only even the child entrie= s set the RW bit. // PageTableLibSetPnle (&ParentPagingEntry->Pnle, &NopAttribute, &AllOn= eMask); - - PagingEntry =3D (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BAS= E_ADDRESS (&ParentPagingEntry->Pnle); - for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { - PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffset; - SubOffset +=3D RegionLength; - } + ParentPagingEntry->Uint64 =3D ((UINTN)(VOID *)PagingEntry) | (Parent= PagingEntry->Uint64 & (~IA32_PE_BASE_ADDRESS_MASK_40)); } } else { // --=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 (#101634): https://edk2.groups.io/g/devel/message/101634 Mute This Topic: https://groups.io/mt/97796379/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-