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 B1AF874003B for ; Wed, 24 Jan 2024 12:24:16 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=arrfH3o7y9k9mtQxAgVTToX9ydpBY2OS1Zms+2bkb+o=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version: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=1706099055; v=1; b=dzZu3NEr5Yba+rPA/sr0f7um/uDxiS0NJf6sbcEm7iYqluIh9a/4C1rw892QpXqfgpv7VbMf 7ZAcnqQlBCaJjMvGHqgOuPHsdrprnRkM8EK2QX8g6lWiMl3OABw1GrDlQV1hYYAwzmSdMFDny+D iPuHY/gKAo/OvaC7haf2XyQg= X-Received: by 127.0.0.2 with SMTP id MJp2YY7687511xQtECsH980y; Wed, 24 Jan 2024 04:24:15 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mx.groups.io with SMTP id smtpd.web11.21279.1706099054299083771 for ; Wed, 24 Jan 2024 04:24:14 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="1668428" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="1668428" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 04:24:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="909650522" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="909650522" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga004.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 24 Jan 2024 04:24:13 -0800 X-Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 24 Jan 2024 04:24:12 -0800 X-Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 24 Jan 2024 04:24:12 -0800 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Wed, 24 Jan 2024 04:24:12 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.169) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 24 Jan 2024 04:24:12 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cNjmTAK8OpCiAp0HILtP866eYk1Gc4jXwvvVYOAjPTvswT8Z6zDNmYwHSuVEHcSdZOWA5QPlNq//CbR48+j3ILpU4mkMpTW8fXy6FZBczeh7EU2Nc5HLScstqUlDibz3nYScayU82HBshkAhNRb/TI2Lxl32vHgv0wGLcvVr7O7jebr1BVqEofCXsmd5SuulkGlhp7LovFDqdQ61mBm4dWmgGYnJ9NDqlx4NIG9ss6J4JG+cXF9SEMUNkWNjqingR6xuvaJ4/g0I36wsF5/6xK/OF91++Um8ICgL4+yiMv/sVBWDnD2GLh5rCBBNS+DC19LtlddaXLqDviHytvh4Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SW/6eTLk+Khnkyz+TrVFVryor5UPKP4M0yh9GLYNO/U=; b=ntTdbmKpe02C3bpoczAIW4Dz0sRvaslwOiVcss8BlMeOF7cklE4ZfwjzX5SC69BUEDK+eWSA6y3vS9UM+WHvClMIwEUnxI0Ji4VAgowWX7hsF7ggDx9MBrkmaX3w31tv4UnODCkFBy0XCZfpkYrMt1SrQ99dZTkLArr8sgKn59ElYTws7dk6YFPoO/zI3r4BoPL4mv+XOymsSYeK4UmR7uCKQZUyAV15Qc8iABWFEXVXZpriCOmsYMmqEBIh0/2f+99C9ZpHEBvCLNs0kiwNZDjyh8iSQ22XG46Oec8N5YNaaFjX+QsX51mJk1vKeIz9tHTu1e4VZp8J8a78Mt9JlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by CO1PR11MB5153.namprd11.prod.outlook.com (2603:10b6:303:95::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.24; Wed, 24 Jan 2024 12:24:09 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::fdd3:11d7:1c15:6c2d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::fdd3:11d7:1c15:6c2d%7]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 12:24:09 +0000 From: "Ni, Ray" To: "Liu, Zhiguang" , "devel@edk2.groups.io" CC: Laszlo Ersek , "Kumar, Rahul R" , Gerd Hoffmann , "Lee, Crystal" , Pedro Falcato Subject: Re: [edk2-devel] [PATCH v3] UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap Thread-Topic: [PATCH v3] UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap Thread-Index: AQHaTdvwQASvWwXj7kSwmeuaQ0O33LDo5KnQ Date: Wed, 24 Jan 2024 12:24:09 +0000 Message-ID: References: <20240123071558.1211-1-zhiguang.liu@intel.com> In-Reply-To: <20240123071558.1211-1-zhiguang.liu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|CO1PR11MB5153:EE_ x-ms-office365-filtering-correlation-id: 6aefc470-e4b6-4fba-20e9-08dc1cd75d85 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: ct/s9BjRBNInBSYdD+5M1QyQT5o1TRlUNKxq8ZEABjfAa/Sm6wLOUpmlUDFHo6pD8Qu4wpGyaDSSEzjFTtx2u/f3LAbnESeSb/ucxqBCrBD4ThIalMf048KFkpelV7vk6uUIykxUKdQF8gpmUwcWHjAVLT7b6oEiKSL4xrV5nVxJUs56Kvo57o/1IopBOVEoWbw0UAxZ7DJ7LLaSCObnu2VTRZCtbODQQ7TwjZcP+jMmBVNAVbeGw+ViTL9Vz1AxvnT0zhSq+qGdTzq1ylr6I8C2Ng7yeIjFo50OstNdeS4ug0v6GoraoTvH75KpbTGaWSm6v0zhebR+T0E39gqRyYx9BOuWZoAvUIFLTRMHkTsQPhRiO/jNPwjk4cvn6J1Ja8qcMy1jaqiUhFnfbgozVhowIz2jyzD13NaEfwkyqZWSRFCeToE8wF05hE/X7iZD2hJRFZyCMknRaRGaVYMnwU57hHhSUIREY4QMcw9sxOfxUSLbp/vO0k0ptgrXWZO9MHrJ6uuaNYsBgbEz24Nc3JapXtaxR5+gvpM8SPWLWghqh1VHlHepZnx9X7zFqerAZs99k7DAGpp6cqgTkINbdey7mbVwPLvLn2Srun9Zz4A= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?RbKYAOdmadFC+jQ3EwvXSzry4OIY7r0cMp8V0opk3W8RF3oAoXJx0VhZkAMu?= =?us-ascii?Q?zC9ImAt7ZCvEkZsVVMsp71TNGkuEavO7aTrFIpXFs7m7tJXR0K/MxMFQkUlc?= =?us-ascii?Q?OxjgsBWDHN9ZwSIc8t7pZVsFnrnNd6OtGaT5aHn0qibst+Fr1gCF+dTDvJF7?= =?us-ascii?Q?MFIGhh9fDVrHK76R+yHcVBolyYFdsEq7Gk+g7EYxdkbtjD3Sn1laVdYv3Flm?= =?us-ascii?Q?WxP3skBIQ7DFYMpKmcKOou0ez1hzC3G0crCataTskL5MRbCPqLBU8sBXRCkH?= =?us-ascii?Q?mE4/Ui5oFTxnJI4GEyog9M+Xl2yKq4GqLS8iBpzi/puYOYJfaCPMwjBcKh5U?= =?us-ascii?Q?bR/GNSUlbXxDrXROrQ8HH0+pN1I59x/0bI+3QDKuB016b8G711aEGP4MAoem?= =?us-ascii?Q?D5P6voDiEFJbfPaqcjuvdHeysxgMlzDJMABGL0ojRrXu+pCimDDAdO4cvZaV?= =?us-ascii?Q?V3YySBw1kw0ePOZIC7L71+/wZIbMIqqV8mkOKkptSsrW3Ick1iqx89mBMbGk?= =?us-ascii?Q?MylNomHvUGDWELC28TZpKBTFJgxit6grnZ+rc479v12TrEZq67EgQWbNa5FD?= =?us-ascii?Q?GnG8nZHkH7WMbHM2Wn0MkLKPGNTQXsDgIOhQfQCUz6LsNaXfltL7TNogKGG6?= =?us-ascii?Q?fSOiHsgkH+FJIHBzHe0VKBXpcNGYyvxWyuAbLZKyDsjtquuPiGl0C1OzPxe0?= =?us-ascii?Q?c+s7nWiRphsC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1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6aefc470-e4b6-4fba-20e9-08dc1cd75d85 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2024 12:24:09.1875 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: LQpTH6UN60NSrWSh0ZC+rpfM8eW50C1WDSFC390tLKnt7Jk1O3S3PG2BGw037N3oJUDxumf1r2VnXhTLw8aVtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB5153 X-OriginatorOrg: intel.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,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: K1vySE2w9ZQhUgTjkewuVtPex7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" 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=dzZu3NEr; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Reviewed-by: Ray Ni Thanks, Ray > -----Original Message----- > From: Liu, Zhiguang > Sent: Tuesday, January 23, 2024 3:16 PM > To: devel@edk2.groups.io > Cc: Liu, Zhiguang ; Ni, Ray ; L= aszlo > Ersek ; Kumar, Rahul R ; Gerd > Hoffmann ; Lee, Crystal ; > Pedro Falcato > Subject: [PATCH v3] UefiCpuPkg: Fix issue that IsModified is wrongly set = in > PageTableMap >=20 > 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 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. >=20 > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Rahul Kumar > Cc: Gerd Hoffmann > Cc: Crystal Lee > Cc: Pedro Falcato > Signed-off-by: Zhiguang Liu > --- > .../Library/CpuPageTableLib/CpuPageTableMap.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > b/UefiCpuPkg/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 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.Present is 0 but some other attributes are provided. > @retval RETURN_INVALID_PARAMETER For non-present range, Mask- > >Bits.Present is 1, Attribute->Bits.Present is 1 but some other attribute= s are > not provided. > @@ -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->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 > software 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. > -- > 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 (#114281): https://edk2.groups.io/g/devel/message/114281 Mute This Topic: https://groups.io/mt/103906298/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-