From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.58294.1672727380307259983 for ; Mon, 02 Jan 2023 22:29:40 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=cirTo1xZ; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672727380; x=1704263380; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=5Yn0h55a8U59D6GrT+Gzj3lfnSaLa6lgvnEoqHaK91c=; b=cirTo1xZYZrD/EBhgGGz+rz0fJr/h7yPf07MtIjpxVQVch/Vfjp88nD5 /cEsHtGfgCw1LxcZMzJAFcZ2WPYkG2qtGziKGOCC9htwStTnUGZd1dA46 gPmpnNDN7e7uxo/QuzuJ7v1ypN09GeUKZvTRbQEYnAnVneJFe1YgRbrWN n2OZCS7SBOijsCVuQDC/T0gZUGlvEVcPzG3j5hnSfcDFQs7p5mk3udutY C/yebHYcyKpxDUrsOtRuZY1Nj284hSdMCOnUtOy6ZWIlNuvIkD0TCArH+ rUJcFw84V3hGNJXW3BKVS34baR6gNO93kBnz5gnj8L3lL0G0VtogEwYLs Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301967997" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301967997" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2023 22:29:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="685289667" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="685289667" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga008.jf.intel.com with ESMTP; 02 Jan 2023 22:29:38 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 2 Jan 2023 22:29:37 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 2 Jan 2023 22:29:37 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Mon, 2 Jan 2023 22:29:37 -0800 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.168) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Mon, 2 Jan 2023 22:29:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XWmwNNrIknaJFIhcfUMvwszDVOt/AApLtkNMw+JRLH/nmqkCVtbk7hvJufDqSraQcISofNU2+ZKyQMsEj7pzwHFii1K0AGHB3NsmwOCHhqk9FeK/7EBM5fab2IVIoGUe0VktQNEPpm8Z4s0XpCeOp6cEK3au9DIEn7KiZ2XnQh77ZHUOOVQoYX1JfSipRYDb3z4lJaMqX2oUg1LybpzHvLh6Tcqcnc9aWaaBQWMQfmvT+pzL4pWpnwtLNgNPpMxAGN1iXfi2cy4x9yV+3GQj3Fa84Z9fbJILpUDdGYj0sbdeTLtMwL1Z3gZYqesmfBgESbC5QaGcTaFZ35DdZ/Wvtg== 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=JedeYb9EPlsVCPpRF2PqxDg0XzLOTTwt6Z/26BN/YMI=; b=EFei99VSt26OZvd/aC4L0/7WZWP4POXFNmAtAVxnynFVIqGMHFt53grROeIUhGGPI4n/DZBQPI2iQqA6JDsnm5kWFzZjfPoLCr0dBNby5axO4YnE2r4iZbqrb+qEzFRmqiPSiLDCXedqzzMOMVMkA/Z3c0UsPk3xrJeQONG6LYS4e1XtMmp4z54OYo+8+7UkXc10ylY/iaDDwf661x42iZ9pihQIgpLODf4fuVk6QWCZlOMdNH/Pp9VkPlFrCY1BYjKgSoxYORA/yq2G5dYeA0AzkABr8zr8wckDU9wqyyJYf6UizNYhBPe2X3R9GWBUI7ej5kzfT5M/c2teiukstw== 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 Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by DS7PR11MB6248.namprd11.prod.outlook.com (2603:10b6:8:97::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.18; Tue, 3 Jan 2023 06:29:35 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831%4]) with mapi id 15.20.5944.019; Tue, 3 Jan 2023 06:29:35 +0000 From: "Ni, Ray" To: "Tan, Dun" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" Subject: Re: [Patch V4] UefiCpuPkg/PiSmmCpuDxeSmm:Fix PF issue caused by smm page table code Thread-Topic: [Patch V4] UefiCpuPkg/PiSmmCpuDxeSmm:Fix PF issue caused by smm page table code Thread-Index: AQHZHzgw4fy1LGx34EWUPPU7vUSWAa6MOqzQ Date: Tue, 3 Jan 2023 06:29:35 +0000 Message-ID: References: <20230103055617.2103-1-dun.tan@intel.com> In-Reply-To: <20230103055617.2103-1-dun.tan@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|DS7PR11MB6248:EE_ x-ms-office365-filtering-correlation-id: b16a5168-d556-49ad-148e-08daed53e1bd x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: srBlNFw0HsNQruCMh0Pa3/Uk/2o7YEkZorC2O/nRBov4d/4siblXjWqlozCj/PggR77fN7GLkltsuWEAyiXxTddQQQxG+DmxfadrFbrV+Jz+3BXuH0a8lVrvwEGgv4MPSnA6VP78xcfDOoyKHGIzHni6rpoyppUedMDqHMUvjbbl/YgZ2LBqLa37Y1705WftYCursz+bJQkpXIWq92tDBaiTQarVGav6JoK4JvtJQ2stlxNZscFhxG9EQHmhEj65A2c7xw1OWuYxKr3mFmEmNjbwI9T4ZuBHF+WKcyfNdI9VerfJoSyQZgYW2ltK9Np1if1kiEh8loOulgKqzTd96SmVdcU/INnldLIhEhyDl4CoLUS/C6n38LIelv05/ZZM4czm6E4oouJmWmGjG9fpIVKhZPXte27w0INKRYOy+xVbImVnRJ8vrUgVFCWmmp9C0RW4gyNVLsyuc6Ev8c0trWXSoAKM3R37+3vLhVLjZ6aqhVWKWOrW71+qE6yfN6noSfsjcd5hMRpsSVHiQ9oew92e0ODcR5rpR8peJleV0aVCICdKmx32OXaTSB4D+6JYcm2LX2pdc//pem6FBlIcgUitVQ4HpYhfZpcmvDQxUSP8WjpU8gNZQUKauiaK6Uz5vjgIynVAkz6MEoqSRftuywTxuj6y44wc6heoT8mHgQrwGGlcvAjaugyZAU6JicjBZchGQ6OeYSIao3nZOv2GAMf/0xJE/MO8EdBMg+T43F/apWfp0ka8PAq+V6dfa59Q x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(6029001)(136003)(376002)(39860400002)(366004)(396003)(346002)(451199015)(83380400001)(122000001)(82960400001)(38100700002)(33656002)(38070700005)(86362001)(2906002)(66446008)(5660300002)(66556008)(4326008)(64756008)(66476007)(66946007)(8676002)(76116006)(8936002)(41300700001)(55016003)(9686003)(186003)(6506007)(26005)(53546011)(107886003)(7696005)(110136005)(316002)(71200400001)(54906003)(478600001)(52536014)(966005)(22166006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Uc0WDZqvxmAwO7L5oyG+FfxKccCl3Z+iaZ1YHoTqCVY9epWVyoiw6wYEXWiV?= =?us-ascii?Q?/gbGQzoIBlQ40IiNpVWnNYegWQPRIrDbiVMlKI+1LTQ6kS2tdG1RcxdsEh93?= =?us-ascii?Q?xiKiCeBgv0jo2zPnd308BHzm0S9n9nVVoX6zk+syQzf+FGCkNfdTUxQbC1jY?= =?us-ascii?Q?jMnS67FqEr9tibU5wGtEjsGVVmoO/uYu82jdMUlE3Z0by75dQXdL8d20OnkV?= =?us-ascii?Q?Mii0uOefyDZ7DvRVFjiosMGwas8DNZZGLYNhSw0DHgAT/LCH8JurjEX/QdOG?= =?us-ascii?Q?CcoNEHv4LSt9vROGfTs9g+n3/Zr6VuxolvkR8p3b/TfeOlGlaPZpL64/EOZv?= =?us-ascii?Q?teBj027D8JROOKRLiR0TcmvXluCoHHouib+067q23byirbpGoSkwkn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IUNvQLmtIyKHlKi/IPqgd?= =?us-ascii?Q?4MERHT6qTecOcHY/WrXhQbE22aram0oq9Kys95CaxOmTvw/BxN3cN9lTp8RW?= =?us-ascii?Q?GWvZ00ug7fpQdP8nA3av3xVDn8VJVkKy66rdmjZpZn+rDqh9BUKg/0snTzt9?= =?us-ascii?Q?pw57qKlsk+h5O/xUFoNImZx2yxSXkObwGL1pPFXfLuVis920FvP+9dhG4QJ4?= =?us-ascii?Q?Gkxa4czlpuwvuoBuZU94GT7R2UP1I9k279v3hoFu2T6I3tRJZsKxePrRTXHs?= =?us-ascii?Q?J3QLHKoR4CYDXwIbmX4=3D?= MIME-Version: 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: b16a5168-d556-49ad-148e-08daed53e1bd X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jan 2023 06:29:35.1523 (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: 6wmiPbRjvSuVdib40nvVl2abckXuEk3DOzd8v+lQAtIxqpJykYpPQ4GYHZe/g3jBsYghKJXZm9QYXIPVdwCz3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB6248 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Since it fixes a critical boot hang issue, I created PR for push @ https://= github.com/tianocore/edk2/pull/3845 I removed following confusing comments. + // Only disable/enable WP when Cr0.Bits.WP has been set to 1. > -----Original Message----- > From: Tan, Dun > Sent: Tuesday, January 3, 2023 1:56 PM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, = Rahul R > Subject: [Patch V4] UefiCpuPkg/PiSmmCpuDxeSmm:Fix PF issue caused by smm = page table code >=20 > When setting new page table pool to RO, only disable/enable WP when > Cr0.WP has been set to 1 to fix potential PF caused by b822be1a20 > (UefiCpuPkg/PiSmmCpuDxeSmm: Introduce page table pool mechanism). > With previous code, if someone want to modify the page table and > Cr0.WP has been cleared before modify page table, Cr0.WP may be set > to 1 again since new pool may be generated during this process > Then PF fault may happens. >=20 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 40 ++++++++++++++++= ++++++++++++------------ > 1 file changed, 28 insertions(+), 12 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > index 4bb23f6920..bab7f1887b 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > @@ -67,8 +67,10 @@ InitializePageTablePool ( > IN UINTN PoolPages > ) > { > - VOID *Buffer; > - BOOLEAN CetEnabled; > + VOID *Buffer; > + BOOLEAN CetEnabled; > + BOOLEAN WpEnabled; > + IA32_CR0 Cr0; >=20 > // > // Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one p= age for > @@ -106,21 +108,35 @@ InitializePageTablePool ( > // > if (mIsReadOnlyPageTable) { > CetEnabled =3D ((AsmReadCr4 () & CR4_CET_ENABLE) !=3D 0) ? TRUE : FA= LSE; > - if (CetEnabled) { > + Cr0.UintN =3D AsmReadCr0 (); > + WpEnabled =3D (Cr0.Bits.WP !=3D 0) ? TRUE : FALSE; > + if (WpEnabled) { > + if (CetEnabled) { > + // > + // CET must be disabled if WP is disabled. Disable CET before cl= earing CR0.WP. > + // > + DisableCet (); > + } > + > // > - // CET must be disabled if WP is disabled. > + // Only disable/enable WP when Cr0.Bits.WP has been set to 1. > // > - DisableCet (); > + Cr0.Bits.WP =3D 0; > + AsmWriteCr0 (Cr0.UintN); > } >=20 > - AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP); > SmmSetMemoryAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAG= ES_TO_SIZE (PoolPages), > EFI_MEMORY_RO); > - AsmWriteCr0 (AsmReadCr0 () | CR0_WP); > - if (CetEnabled) { > - // > - // re-enable CET. > - // > - EnableCet (); > + if (WpEnabled) { > + Cr0.UintN =3D AsmReadCr0 (); > + Cr0.Bits.WP =3D 1; > + AsmWriteCr0 (Cr0.UintN); > + > + if (CetEnabled) { > + // > + // re-enable CET. > + // > + EnableCet (); > + } > } > } >=20 > -- > 2.31.1.windows.1