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 B9093D8119E for ; Thu, 11 Jan 2024 08:56:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PclY9PQanJilFOEZmGbU7NJGVxt4rugEpqHPWYSLkwk=; 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=1704963404; v=1; b=Kk8ySAYefPXbS3ez1cK+jlAnU4P6DepcZDNalitLBFt33dCOHY0bT7iF+yTAFsimY2jhRNX7 0voIKA4GOGTo+3pYJSyYHShzScouyFrCFHlorQher6O6VZR8+f9BfcyApFvC50GNmX7mKRmvjFq uTQUnSo15+moF8rkrA/PH8Ek= X-Received: by 127.0.0.2 with SMTP id 7m7uYY7687511xPC8TcswvEX; Thu, 11 Jan 2024 00:56:44 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.7576.1704963403868767801 for ; Thu, 11 Jan 2024 00:56:44 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-hzmh__C-PNqIpPz5UmEkWg-1; Thu, 11 Jan 2024 03:56:41 -0500 X-MC-Unique: hzmh__C-PNqIpPz5UmEkWg-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 03A6C86794E; Thu, 11 Jan 2024 08:56:41 +0000 (UTC) X-Received: from [10.39.193.20] (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AD572166B31; Thu, 11 Jan 2024 08:56:39 +0000 (UTC) Message-ID: Date: Thu, 11 Jan 2024 09:56:39 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap To: devel@edk2.groups.io, ray.ni@intel.com, "Liu, Zhiguang" Cc: "Kumar, Rahul R" , Gerd Hoffmann , "Lee, Crystal" References: <20240110053828.1473-1-zhiguang.liu@intel.com> <95163437-75ea-9265-a5e1-35cf01f186eb@redhat.com> From: "Laszlo Ersek" In-Reply-To: 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: gAE2DyWRBIR3FNQjkbZ1fw8Qx7686176AA= 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=Kk8ySAYe; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) On 1/11/24 03:03, Ni, Ray wrote: >> This function is incredibly complicated, so reviewing this patch is >> hard, even after reading the bugzilla ticket. >> >> The commit message is useless. It should contain a brief description of >> the problem, and how the fix resolves the problem. >> >> The documentation of the PageTableLibMapInLevel() function is wrong, >> even before this patch. It documents the "IsModified" output-only >> parameter as follows: >> >> "TRUE means page table is modified. FALSE means page table is not >> modified." >> >> This states that "IsModified" is always set on output, to either FALSE >> or TRUE. Which is an incorrect statement; in reality the caller is >> expected to pre-set (*IsModified) to FALSE, and PageTableLibMapInLevel() >> will (conditionally!) perform a FALSE->TRUE transition only. >> >> Now, this patch may fix a bug, but it makes the above-described >> documentation issue worse, by further restricting the condition for said >> FALSE->TRUE transition. >=20 > Laszlo, thanks for the comments! > Though the fixing looks simple, Zhiguang and I did have several rounds of= offline discussions > regarding how to fix it. >=20 > When the lib accesses the page table content, CPU would set the "Access" = bit in the page entry > that points to the page table memory being accessed by the lib. >=20 > So, even when the "Modify" is FALSE (indicating caller doesn't want the l= ib to modify the page table), > lib code should not modify the page table but CPU still sets the "Access"= bit in some of the entries due to > the reasons above. Huh, tricky! Should the comparison explicitly mask out the Accessed bit from each of the "before" page table entry and the "after" one, perhaps? > I agree it will be better that the commit message carries above details. >=20 > Zhiguang, > Can we update the code to always assign "IsModified"? I thought we did th= at but it seems not. That seems doable by (e.g.) setting (*IsModified) to FALSE right at the top of the function, and then the logic would match the existent comments, I think. However, I've not checked whether callers actually rely on this "summing" logic of the IsModified output parameter -- like call the function a number of times in a row, using a common local variable to receive IsModified, and then check the local variable to see if *any one* of the calls in the loop has modified the page table. Thanks Laszlo >=20 >> >> The fix per se looks vaguely reasonable to me (really the function is so >> complicated that verifying this change from scratch would take me ages), >> but minimally, the documentation of "IsModified" should certainly be >> updated too. To something like this: >> >> @param[out] IsModified If "Modify" is TRUE on input and the function >> has actually modified the page table, then >> set >> to TRUE on output. Not overwritten >> otherwise. >> >> Laszlo >=20 >=20 >=20 >=20 >=20 >=20 -=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 (#113598): https://edk2.groups.io/g/devel/message/113598 Mute This Topic: https://groups.io/mt/103636407/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-