From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 00B6F7803E0 for ; Wed, 17 Jan 2024 10:51:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=4/nmoU6bh5dA429yeiwcuOGfWcSc0TWurZ/7qWKrGFE=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1705488676; v=1; b=keyTIW+HZE7QihI5PpOG1yUNq/eK2/Hy+2WGe4WIb/JvTrjDMdXtFNlzFUX7FmG5Uqx7vkkw hPUWuXsziF7M/cOPuzJrv4yDaXV7DEI36wCPdQwcuoYKU9NZxI+MuYi5YJcW0X/9ItYKR92LW4G /Jedxl3TLXGwme4BOkXt3nnU= X-Received: by 127.0.0.2 with SMTP id lGriYY7687511xTvIIdZLqJG; Wed, 17 Jan 2024 02:51:16 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.6736.1705488675940211326 for ; Wed, 17 Jan 2024 02:51:16 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-wixD5gJIOfCYOlXQoiACVQ-1; Wed, 17 Jan 2024 05:51:11 -0500 X-MC-Unique: wixD5gJIOfCYOlXQoiACVQ-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 808F43C0009C; Wed, 17 Jan 2024 10:51:11 +0000 (UTC) X-Received: from [10.39.192.21] (unknown [10.39.192.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40F632166B33; Wed, 17 Jan 2024 10:51:09 +0000 (UTC) Message-ID: Date: Wed, 17 Jan 2024 11:51:08 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2] UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap To: devel@edk2.groups.io, zhiguang.liu@intel.com Cc: Ray Ni , Rahul Kumar , Gerd Hoffmann , Crystal Lee References: <20240117080954.1414-1-zhiguang.liu@intel.com> From: "Laszlo Ersek" In-Reply-To: <20240117080954.1414-1-zhiguang.liu@intel.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Gn5GufBNflV18HVNeTR1tNKgx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=keyTIW+H; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 1/17/24 09:09, Zhiguang Liu wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4614 >=20 > 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 considering the hardware may also change page table, > and document the detail in function header. >=20 > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Rahul Kumar > Cc: Gerd Hoffmann > Cc: Crystal Lee > Signed-off-by: Zhiguang Liu > --- > .../Library/CpuPageTableLib/CpuPageTableMap.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiC= puPkg/Library/CpuPageTableLib/CpuPageTableMap.c > index 36b2c4e6a3..a3076ff2f6 100644 > --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > @@ -274,7 +274,7 @@ IsAttributesAndMaskValidForNonPresentEntry ( > Page table entries that map the line= ar address 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 cor= responding field in Attribute is ignored if that in Mask is 0. > - @param[out] IsModified TRUE means page table is modified. F= ALSE means page table is not modified. > + @param[in, out] IsModified Change IsModified to True if page ta= ble is modified and input parameter Modify is TRUE. > =20 > @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Pr= esent is 0 but some other attributes are provided. > @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Pr= esent is 1, Attribute->Bits.Present is 1 but some other attributes are not = provided. > @@ -567,7 +567,10 @@ PageTableLibMapInLevel ( > OriginalCurrentPagingEntry.Uint64 =3D CurrentPagingEntry->Uint64= ; > PageTableLibSetPle (Level, CurrentPagingEntry, Offset, Attribute= , &CurrentMask); > =20 > - if (OriginalCurrentPagingEntry.Uint64 !=3D CurrentPagingEntry->U= int64) { > + if (Modify && (OriginalCurrentPagingEntry.Uint64 !=3D CurrentPag= ingEntry->Uint64)) { > + // > + // The page table entry can be changed by this function only w= hen Modify is true. > + // > *IsModified =3D TRUE; > } > } > @@ -609,7 +612,10 @@ PageTableLibMapInLevel ( > // Check if ParentPagingEntry entry is modified here is enough. Except= the changes happen in leaf PagingEntry during > // the while loop, if there is any other change happens in page table,= the 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 Mo= dify is true. > + // > *IsModified =3D TRUE; > } > =20 > @@ -633,7 +639,9 @@ PageTableLibMapInLevel ( > 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 set= . > @param[in] Mask The mask used for attribute. The corres= ponding field in Attribute is ignored if that in Mask is 0. > - @param[out] IsModified TRUE means page table is modified. FALS= E means page table is not modified. > + @param[out] IsModified TRUE means page table is modified by so= ftware or hardware. FALSE means page table is not modified by software. > + If the output IsModified is FALSE, ther= e is possibility that the page table is changed by hardware. It is ok > + because page table can be changed by ha= rdware 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 = Mask is NULL. This patch looks good to me, thanks, except for one small wart: in the documentation section of PageTableLibMapInLevel(), you change IsModified from "@param[out]" to "@param[in, out]", which is correct, *but* a similar change has been omitted for the actual parameter in the parameter list: OUT BOOLEAN *IsModified This should also become "IN OUT". Thanks! Laszlo -=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 (#113948): https://edk2.groups.io/g/devel/message/113948 Mute This Topic: https://groups.io/mt/103781942/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-