From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.5713.1686220389904690241 for ; Thu, 08 Jun 2023 03:33:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=dP3GXUsD; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1686220389; x=1717756389; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=8HSTjeHt00sJV2choRAdevgIl94xZr0rNXU7xqqfXGc=; b=dP3GXUsDsOxwX0EsJqpDEWBlHYSFyBVGdCoYQUSCZkBYpjMNe5C249Ap 71kr94QfcDQ2ztO9QNeUlH42NQ+7qwnWY3RPgXSWJvQejyuXJdXqUf18p MWebUUpPBK9bA3CoSzUql+/CoONy/XdO5bxh0UK9fqq76rfKw9VM1H6yF fGrLNY4oZcw48wqnkDCiSbDVknpXopLQoC5quEYtrs1fNoELnNtTfJy4T nPhneoQzhFAvRcLCn3cuPZXVvR0dtmjCQfW348hdzBlaUAkHog/J6AUxb 2cYEOCeWR4hjzgvrWa0jFRwVQlKGxjBOfFbDEUrr9Sga5y3PC2p0+S8Sc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="336900616" X-IronPort-AV: E=Sophos;i="6.00,226,1681196400"; d="scan'208";a="336900616" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 03:33:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="743064720" X-IronPort-AV: E=Sophos;i="6.00,226,1681196400"; d="scan'208";a="743064720" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga001.jf.intel.com with ESMTP; 08 Jun 2023 03:33:08 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 8 Jun 2023 03:33:08 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 8 Jun 2023 03:33:08 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.177) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 8 Jun 2023 03:33:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+Ww5MICCLunY+i30yrbYrE9fTWR5mwtJSh0q1AcBjW8gO0kovM6AsfuZH+a+68Ug6T8Z8u1YfwH482BgG8PyXiMyCyA34Dhmzbltf0UAYIpEsS6s650s6Cwna5Zakl+NRMHvOo7FviYWafbn8GW5A+B49Yh0euMxRa+5l33Xme7vRMKo4qDoByvoW6XKs+6YWNLVS4yYaYxSfziuwk/gTntkyhIt0uAc/wuVuaE4r9eZoO01j+VXT1SkKX4nvrEHsDqNqzh1rOWhRHfX9+FD9QcHBuPnXUuBG8xyAPpP00OZZudUGIDMu3LdozE647zG3fkLdcgOM6nDTfHYQFN4g== 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=Bl4clGfZaEeh8/2OKNbBXCKDQjUryyQHVibmV8GB3DY=; b=ZleI3CADeT62X9BpZI4lWinfcsoSsF5UaRc9+f3XtLZ/qp1lQxneooAxfcwKqiiJX1fSzYWtNAaOs3Pra+6DM3nMVlIpzTchCqoh+JZDCzR7RvSf27O5Mn8iY8xDFTx8S1JWwaO2dWJSf2sTyBnYgEQD1H720HqMvS4ZwWVYrrFbXG1TnI2Zqlrh2HXllJP+X+tAFrhhfH9k/hj+nPMjnyH0H0eXRmHAk/huNzxASNO6Mj4bhIBclirJaKwhhYFPe7bgCq/ac/1rXVqIWKnBvJVHpk4PcMAhOw3SxNtS+2hWZuT1sa87dWTcQhn5fxYzWLo+USsBcOl5Of/ixp56tA== 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 SJ1PR11MB6250.namprd11.prod.outlook.com (2603:10b6:a03:459::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.39; Thu, 8 Jun 2023 10:33:04 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%2]) with mapi id 15.20.6455.034; Thu, 8 Jun 2023 10:33:07 +0000 From: "Ni, Ray" To: "Tan, Dun" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann Subject: Re: [Patch V5 04/14] UefiCpuPkg: Add DEBUG_CODE for special case when clear RP Thread-Topic: [Patch V5 04/14] UefiCpuPkg: Add DEBUG_CODE for special case when clear RP Thread-Index: AQHZmbDy1Quuk/R72EuMLoz3tuaGlK+AtcIw Date: Thu, 8 Jun 2023 10:33:07 +0000 Message-ID: References: <20230608022742.1292-1-dun.tan@intel.com> <20230608022742.1292-5-dun.tan@intel.com> In-Reply-To: <20230608022742.1292-5-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_|SJ1PR11MB6250:EE_ x-ms-office365-filtering-correlation-id: 34901670-4ebd-4fe0-5534-08db680bbf8e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4umyrSl1VJs9UzMzJJJhkqaUceR28gDVhS+vVUMkfOyeodFrFlkFRhBK7KsEBJ5oQzdMEo/mwgTvEI6mnezOQfKTNt2R8Hm/eh1cSSa1o/rs6uxTclZwNZbAo7xOQB3cAy57VjPk/0OqSQ2awW8LAJCdtJBjQCWfiuDEXmBeNK+4wIYzN07rrEUIN66BgtB51SRZT2IzfNbPVM3/Y2y4Je1vt+fd4apgw7+Vyyp5h/jnrsGwn7xZIDaE6tWZ+kz6zlA3R0hn8muKFpbAoddPovRLJLvYUanXxCQtBiGVv/mN2/RfulxJ0T9HttTaF3CYhN4j35eTQdmx4ZKbhXE5D17FbUOFwHe6A4lAcDHlKKW3NiWOhvx2MO/fMe3F9ctEUPqLungOTyJcQJdtcohU0TjY91ISUyvGQFwchfqAjFiYqiLuiaTjDpw4qsP7orf+X/C4PvhsIfFRROKZTqZmZsrx3zIlJ9YtV9kavsFxqmGkmQngwrG2gg1LfgwYroFtrUYRY3uYQvOTo09lNKjGQ3t6z/vemBBHPfpVf+zL+T9ec+juIUlPxxtCfRnT26NRD+euzoUedegGc6QFfcQYcf7+ULj+SaXRPsjJi3ruD/OgpT9oUa0Sj1IXEfE5QtFL 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:(13230028)(39860400002)(366004)(136003)(376002)(396003)(346002)(451199021)(66946007)(66556008)(66446008)(64756008)(66476007)(76116006)(478600001)(54906003)(110136005)(8676002)(52536014)(8936002)(5660300002)(71200400001)(4326008)(316002)(41300700001)(7696005)(38100700002)(82960400001)(122000001)(55016003)(9686003)(53546011)(38070700005)(26005)(186003)(6506007)(83380400001)(86362001)(33656002)(2906002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?p4hPO44jBmkzhymzpRr9lx8w3dDCvraRGyYxURRf3Nss9mCLVvvueVFMZisD?= =?us-ascii?Q?t+cgrD5lh6vp2FwqnQ5aK4+pDb/7CGc42DZqn4fe3M8pLVWl90DPoP2Lv/Cl?= =?us-ascii?Q?o6a4zn19TL329yU2HFsBW0zF2w6Sq474oIzOeJ+56IcO4RKXwuOqZt8nA96V?= =?us-ascii?Q?MGcn2HzV6aC5s5Wb+LjlzYZGALF1kWgunvDY70EYqeJsRvcDxoB/9iZXSk/g?= =?us-ascii?Q?IFmkZjWpJddOCK7EnrfWsfXYzJ5DakQPfQamZ3iKQCCqY1LNduIQENcPTVWh?= =?us-ascii?Q?GQ8efbd18xO2tjsapY/e5goUYoM83ZnlWXWge09XwtaNiwYKCABBKzeamthO?= =?us-ascii?Q?EMUcknGQYn6MzyvKJ7diO8+cztTLAP30/m1tftd4I3Y7y9o+YPXBRBQweCSh?= =?us-ascii?Q?Lvpbh2K3BG37j1hZ7tVsTeKwu/qDlhc/LS5jgfI+RjRAJ63/MT3yGhhzykPk?= =?us-ascii?Q?b9Gw9uvW3iiRgYeP7+8R21XMARad0MHI+ixJ0NpHxB8Wvro8RFGfrjMvp7I6?= =?us-ascii?Q?wP74LsQ8mXe4vNsyumXBMh049dXCOCiiTHOWS+vxjdZzYnaPCB70x6Nzhizl?= =?us-ascii?Q?LX4rLMZvyoilxtBNHJqXlpWg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9UqnW0BeEbN9?= =?us-ascii?Q?SbvhBfrb/0j7xtVWTUAaDvTdIHkK/BCj1sqNrJrRdNN/Vlqg6RsVzu8gIsw+?= =?us-ascii?Q?2vjckdil/2IthgK1tDNv9IApMIa04+hIBTXrkqMe?= 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: 34901670-4ebd-4fe0-5534-08db680bbf8e X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jun 2023 10:33:07.0590 (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: 3XOSqTVOgTHJTdwfJmDWy5hnb6pA/DOQONfKytBtxO/9VRJEMHTWd7AtlmCquVqzTcPKzZxp8bGqRN09j5obew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR11MB6250 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 Reviewed-by: Ray Ni > -----Original Message----- > From: Tan, Dun > Sent: Thursday, June 8, 2023 10:28 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Gerd Hoffmann > Subject: [Patch V5 04/14] UefiCpuPkg: Add DEBUG_CODE for special case > when clear RP >=20 > In ConvertMemoryPageAttributes() function, when clear RP for a > specific range [BaseAddress, BaseAddress + Length], it means to > set the present bit to 1 and assign default value for other > attributes in page table. The default attributes for the input > specific range are NX disabled and ReadOnly. If there is existing > present range in [BaseAddress, BaseAddress + Length] and the > attributes are not NX disabled or not ReadOnly, then output the > DEBUG message to indicate that the NX and ReadOnly attributes of > the existing present range are modified in the function. >=20 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 48 > ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > index 12723e5750..862b3e9720 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > @@ -349,6 +349,8 @@ ConvertMemoryPageAttributes ( > IA32_MAP_ENTRY *Map; > UINTN Count; > UINTN Index; > + UINT64 OverlappedRangeBase; > + UINT64 OverlappedRangeLimit; >=20 > ASSERT (Attributes !=3D 0); > ASSERT ((Attributes & ~EFI_MEMORY_ATTRIBUTE_MASK) =3D=3D 0); > @@ -430,6 +432,52 @@ ConvertMemoryPageAttributes ( > // By default memory is Ring 3 accessble. > // > PagingAttribute.Bits.UserSupervisor =3D 1; > + > + DEBUG_CODE_BEGIN (); > + if (((Attributes & EFI_MEMORY_RO) =3D=3D 0) || (((Attributes & > EFI_MEMORY_XP) =3D=3D 0) && (mXdSupported))) { > + // > + // When mapping a range to present and EFI_MEMORY_RO or > EFI_MEMORY_XP is not specificed, > + // check if [BaseAddress, BaseAddress + Length] contains present= range. > + // Existing Present range in [BaseAddress, BaseAddress + Length]= is set to > NX disable or ReadOnly. > + // > + Count =3D 0; > + Map =3D NULL; > + Status =3D PageTableParse (PageTableBase, mPagingMode, NULL, &Co= unt); > + > + while (Status =3D=3D RETURN_BUFFER_TOO_SMALL) { > + if (Map !=3D NULL) { > + FreePool (Map); > + } > + > + Map =3D AllocatePool (Count * sizeof (IA32_MAP_ENTRY)); > + ASSERT (Map !=3D NULL); > + Status =3D PageTableParse (PageTableBase, mPagingMode, Map, &C= ount); > + } > + > + ASSERT_RETURN_ERROR (Status); > + for (Index =3D 0; Index < Count; Index++) { > + if (Map[Index].LinearAddress >=3D BaseAddress + Length) { > + break; > + } > + > + if ((BaseAddress < Map[Index].LinearAddress + Map[Index].Lengt= h) && > (BaseAddress + Length > Map[Index].LinearAddress)) { > + OverlappedRangeBase =3D MAX (BaseAddress, > Map[Index].LinearAddress); > + OverlappedRangeLimit =3D MIN (BaseAddress + Length, > Map[Index].LinearAddress + Map[Index].Length); > + > + if (((Attributes & EFI_MEMORY_RO) =3D=3D 0) && > (Map[Index].Attribute.Bits.ReadWrite =3D=3D 1)) { > + DEBUG ((DEBUG_ERROR, "SMM ConvertMemoryPageAttributes: > [0x%lx, 0x%lx] is set from ReadWrite to ReadOnly\n", OverlappedRangeBase, > OverlappedRangeLimit)); > + } > + > + if (((Attributes & EFI_MEMORY_XP) =3D=3D 0) && (mXdSupported= ) && > (Map[Index].Attribute.Bits.Nx =3D=3D 1)) { > + DEBUG ((DEBUG_ERROR, "SMM ConvertMemoryPageAttributes: > [0x%lx, 0x%lx] is set from NX enabled to NX disabled\n", > OverlappedRangeBase, OverlappedRangeLimit)); > + } > + } > + } > + > + FreePool (Map); > + } > + > + DEBUG_CODE_END (); > } > } >=20 > -- > 2.31.1.windows.1