From nobody Sun May 12 15:28:15 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+114185+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+114185+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1706000990; cv=none; d=zohomail.com; s=zohoarc; b=Oqxaze3InKkhDE6eg+qRELE4FpTqzbPKs89Pf++IJaStdIzwkc9dO7jUZWuD2pglMAe8t13fy79Y7ATreR7wtyqqCk/mRkpvgmFkRerRMC8o7FEUhJr/10zSGDoMWbb9IbqQjAkgIiqdObxz6BuwkxhEB+DExSo4bQ3sWSsJQgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706000990; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=yclqXPnOClA3j+BXbxaGJ4E0Y5XOYMZRGQxeA5eaKNA=; b=eng7VGMcxCLqvIGqFYJXq7rBnHH+CbXuytcVUxbgYOA5aHpVjaocqJJf6TfFNF47xxhg0a6HBceW+qA+yCsmRboPoK8kbyc2XAT+6cjljrLAbfjAfeRJQOlqRbEwdA+67Hbzyv16oYo96xAxPwDuDYkIjNTUL8cBAri3AXlUZOQ= 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+114185+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 1706000990358534.6624244118572; Tue, 23 Jan 2024 01:09:50 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=/bQcAdkrqBd7lZFaLQE7AvRwHIMSJOUfzVdT0zP3CLg=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706000989; v=1; b=XNIcaOtOL1WKOw4WTFotA+57mkTmsfEM6aC9peQp489XpkPcywIwgEFryY1MMuDOt3GQhynG YE7YAREe2WVrBRUwJcFp3SDUWeWLdnzFwGup44L817D6AiYG5aE9fUV/VjFRm82J4hqQ5HjzdwQ hqiFK7uL/BXxjcUvpFLuAruE= X-Received: by 127.0.0.2 with SMTP id wcwIYY1788612xqGBqUK91kf; Tue, 23 Jan 2024 01:09:49 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.7975.1706000989050636364 for ; Tue, 23 Jan 2024 01:09:49 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="391884823" X-IronPort-AV: E=Sophos;i="6.05,214,1701158400"; d="scan'208";a="391884823" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 01:09:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="735504519" X-IronPort-AV: E=Sophos;i="6.05,214,1701158400"; d="scan'208";a="735504519" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 01:09:46 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann , Crystal Lee , Pedro Falcato Subject: [edk2-devel] [PATCH v3] UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap Date: Tue, 23 Jan 2024 15:15:58 +0800 Message-Id: <20240123071558.1211-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk 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,zhiguang.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: FsSUjVQQFWSBtuIJ7CFVBe2Yx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706000991109100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4614 About the IsModified, current function doesn't consider that hardware also may change the pagetable. The issue is that in the first call of internal function PageTableLibMapInLevel, the function assume page table is not changed, and add ASSERT to check. But hardware may change the page table, which cause the ASSERT happens. Fix the issue by adding addtional condition to only check if the page table is changed when the software want to modify the page table. Also, add more comment to explain this behavior. Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Crystal Lee Cc: Pedro Falcato Signed-off-by: Zhiguang Liu Reviewed-by: Laszlo Ersek Reviewed-by: Ray Ni --- .../Library/CpuPageTableLib/CpuPageTableMap.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 36b2c4e6a3..ea6547970a 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -274,7 +274,7 @@ IsAttributesAndMaskValidForNonPresentEntry ( Page table entries that map the linear= address range are reset to 0 before set to the new attribute when a new physical base address is se= t. @param[in] Mask The mask used for attribute. The corre= sponding field in Attribute is ignored if that in Mask is 0. - @param[out] IsModified TRUE means page table is modified. FAL= SE means page table is not modified. + @param[in, out] IsModified Change IsModified to True if page tabl= e is modified and input parameter Modify is TRUE. =20 @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Pres= ent is 0 but some other attributes are provided. @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Pres= ent is 1, Attribute->Bits.Present is 1 but some other attributes are not pr= ovided. @@ -294,7 +294,7 @@ PageTableLibMapInLevel ( IN UINT64 Offset, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask, - OUT BOOLEAN *IsModified + IN OUT BOOLEAN *IsModified ) { RETURN_STATUS Status; @@ -567,7 +567,10 @@ PageTableLibMapInLevel ( OriginalCurrentPagingEntry.Uint64 =3D CurrentPagingEntry->Uint64; PageTableLibSetPle (Level, CurrentPagingEntry, Offset, Attribute, = &CurrentMask); =20 - if (OriginalCurrentPagingEntry.Uint64 !=3D CurrentPagingEntry->Uin= t64) { + if (Modify && (OriginalCurrentPagingEntry.Uint64 !=3D CurrentPagin= gEntry->Uint64)) { + // + // The page table entry can be changed by this function only whe= n Modify is true. + // *IsModified =3D TRUE; } } @@ -609,7 +612,10 @@ PageTableLibMapInLevel ( // Check if ParentPagingEntry entry is modified here is enough. Except t= he changes happen in leaf PagingEntry during // the while loop, if there is any other change happens in page table, t= he ParentPagingEntry must has been modified. // - if (OriginalParentPagingEntry.Uint64 !=3D ParentPagingEntry->Uint64) { + if (Modify && (OriginalParentPagingEntry.Uint64 !=3D ParentPagingEntry->= Uint64)) { + // + // The page table entry can be changed by this function only when Modi= fy is true. + // *IsModified =3D TRUE; } =20 @@ -633,7 +639,9 @@ PageTableLibMapInLevel ( Page table entries that map the linear ad= dress range are reset to 0 before set to the new attribute when a new physical base address is set. @param[in] Mask The mask used for attribute. The correspo= nding field in Attribute is ignored if that in Mask is 0. - @param[out] IsModified TRUE means page table is modified. FALSE = means page table is not modified. + @param[out] IsModified TRUE means page table is modified by soft= ware or hardware. FALSE means page table is not modified by software. + If the output IsModified is FALSE, there = is possibility that the page table is changed by hardware. It is ok + because page table can be changed by hard= ware anytime, and caller don't need to Flush TLB. =20 @retval RETURN_UNSUPPORTED PagingMode is not supported. @retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute or Ma= sk is NULL. --=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 (#114185): https://edk2.groups.io/g/devel/message/114185 Mute This Topic: https://groups.io/mt/103906298/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-