From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.10988.1671593841277636264 for ; Tue, 20 Dec 2022 19:37:21 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=K0HuabXs; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671593841; x=1703129841; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ntXi0DC8/+kQBy5+pu1zr0mXIlnxF2iPvmKvJ7KcNh0=; b=K0HuabXsJC1f0Is1YAh2JlrNBWf60lCmhir+C3hDgRB2z/Ocb3ii8oqx SmbZyX7ai0pcJ4UeWSDP1uMNXq2FgfBNyxONs2IeViLmWgfWh9a9OUWid aNsSrKhN48SqxZz5vojhku/RXkwPR2hXNQaP1R6fh2qBFYDg3mKjhAgHp 0IEcRDJ2ayHY1bNkEgqbEnRn0+EtW/jCpc9u+Tcnt2zkqdJHXO+oStQ9V YYh+YjpnWRorATrI1oh7Opbo6pa1h1WuTVyrTj8DGHoV7W//JC/hmruX6 /kPlxT8xdDOD8IfKUdW+A8LReZo26Q3F0PbGdytilhnWykl31KqKKo1/R g==; X-IronPort-AV: E=McAfee;i="6500,9779,10567"; a="321682516" X-IronPort-AV: E=Sophos;i="5.96,261,1665471600"; d="scan'208";a="321682516" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 19:37:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10567"; a="740014366" X-IronPort-AV: E=Sophos;i="5.96,261,1665471600"; d="scan'208";a="740014366" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by FMSMGA003.fm.intel.com with ESMTP; 20 Dec 2022 19:37:09 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 20 Dec 2022 19:37:09 -0800 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 20 Dec 2022 19:37:08 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Tue, 20 Dec 2022 19:37:08 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.173) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Tue, 20 Dec 2022 19:37:08 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LuaYRB85dTnEKue0+sXhv0aScLI1bwJVytKOkRThiOOMFOO44lKdLytu3W4pXxCCYYlRFJE73bPf+mJQvJ3OEUBbntBOiep0uWOJ8DLdcWCENyFyQkabeHnqOdmdBZMnSXnwvJTs+7PzmaZfF1WPZGfda4C2Y3EvzK56BamO7hIzQx+iNYlIDy/LL4aifVYAO5tS6K5xzAliKQxDx89kzwsEWQ284RDZbJlhuU+8la0+wngEF0j9MlICGAu4qI4fEecEPzErx28k+x7wb3Xi2NUlH57ko2xTF8CMLimkvVbSJO+w6/kjhcyz6Rx9ts9zEQ5YwC5KB45Q1guBvx4TIg== 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=KuVKzDhnp8+Vm1Wo0mOyCUSKpuK7rq5n70mP6+Q/VuU=; b=KDj4gebNTQDwUJxzFdgdrrCZLzD2wvAdqOxcDVbkGZJHtm8UgCbQ/bY1vRklVezvIE0LIAMy9o6umypfSbagFdPcNCYB08nYmjp2Y6MAvm/ymsLAEK08XkBJAtc+fKOEvL9mS1v7k+WmpUNf/8Tyedf08JsE9kmXWW/9sNa/zeErJUjxJWgKfom3lnCttP2Tq+IKMhbW64wVP/vmbnLH9fTFgT1BlZ42BmSsN2QfIXOX5mgj/EjTa/MPTWU2jQdFmUuvHVKKCegbc8ZD1YEbuiyELtzpQSbbTU85Dc9hzAPOf7ZMkEsxLoAdTH4r0Ke07afiWw8xX8XoRxFnD8d9bQ== 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 BN9PR11MB5483.namprd11.prod.outlook.com (2603:10b6:408:104::10) by SJ0PR11MB6719.namprd11.prod.outlook.com (2603:10b6:a03:478::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Wed, 21 Dec 2022 03:37:07 +0000 Received: from BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::b881:6d23:2b1a:c5b1]) by BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::b881:6d23:2b1a:c5b1%3]) with mapi id 15.20.5924.016; Wed, 21 Dec 2022 03:37:07 +0000 From: "duntan" To: "Ni, Ray" , "devel@edk2.groups.io" , "Wang, Jian J" CC: "Dong, Eric" , "Kumar, Rahul R" Subject: Re: [PATCH 3/3] UefiCpuPkg: Simplify the code to set smm page table as RO Thread-Topic: [PATCH 3/3] UefiCpuPkg: Simplify the code to set smm page table as RO Thread-Index: AQHZEPq2ym8iXXQ/6kery8NvmtV/I650xzbwgALvjNA= Date: Wed, 21 Dec 2022 03:37:07 +0000 Message-ID: References: <20221216030059.1373-1-dun.tan@intel.com> <20221216030059.1373-4-dun.tan@intel.com> In-Reply-To: Accept-Language: zh-CN, 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: BN9PR11MB5483:EE_|SJ0PR11MB6719:EE_ x-ms-office365-filtering-correlation-id: 68fb3416-0723-4641-9285-08dae304a277 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 49cL2OSei8G8jwVc5ZwIJI9vu746015opTtegHva7+WOc4yPg8/6jqtAOfE0SiYimKh4pNDu8elvEgKPh+iWaryRWleyrIzB98Ny/ykiXhrBBDGJSeX5NX2xlfkaDF4YdugZoiS7dT26UbnPZpxCvjgEC0FpG+rZod5Lmhce3ZiYCBfbunSkUOR/DqQXE535gcinljtSpsODWwvNt+xMVMXfuFxxQ3Iqfv/iIbbK8Yi9Pbj/avUbrw3dTdGFUPy7xu/JoJTayfUOxh3MIsxq34sijX252S9vhHvyR3qNsDIABrb9UONgejsY4C5+YzO0KyqTtcLpl4yPym/YmpsNiE8oUipGonG+YtUwvhPVGyYKnxJAGEkarG8cjwX+VtWW1qkatwOsEKAYO29tlo8eJNdIaJHL0ve3OBowW5kgA3xoW740E+v5MIprfPDQLygni+fIOoJ0zwpNDWi7BYt44dEW36y1RMM+7MJhE7t/4TJFd3xBQvTGYnmrGnKWZIJjdJlY/oCoXphDj1JIKt2VpFWR7ct5WQ5o4HE4ROilOnTq+FTe4t6aljT7/WpP93Nr4WjZ88sqMcWkhjaq3nthAHegNmhK0IzfJknTNFg/1WVqKclUJ+YjM66iXuWE43GDOIHQmY7mm+tYM17CaIbo7bGYvDjru/Zsi8iCwokufvpQ/yQ7z1UD+HJ+tVdFQEzVpl7kHFOepmm8YyBZ8HiJXqEYEUpILvjOC2pMmm1qBdgWRKHX54kYJqMxDCCalNKi x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5483.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(376002)(366004)(136003)(346002)(39860400002)(451199015)(83380400001)(55016003)(86362001)(33656002)(122000001)(38070700005)(38100700002)(82960400001)(316002)(8936002)(52536014)(110136005)(64756008)(66446008)(6636002)(66476007)(54906003)(66556008)(2906002)(76116006)(66946007)(8676002)(4326008)(5660300002)(26005)(186003)(9686003)(6506007)(7696005)(41300700001)(53546011)(107886003)(478600001)(71200400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?uRsMB7i18dSZtwjjyLhQzLKa261hMAVyg2r/P5y7oht7O2Oc/qmPgqnYnAER?= =?us-ascii?Q?acu1e4LqPTSBd/vVW3LIzCTQYZXGIX1LcikBBLdKKLx4kTV0YgomrjiSQlVp?= =?us-ascii?Q?d8ruG1XKR/Ta87RZvABi5im5vw9tWE7JSOBIndDMERqMR7/JU9UsP5K3wRI2?= =?us-ascii?Q?jWoxwMaWyaca0nY6HhQIc6PRC6Ue5rdI3ZDaw/EKBU3jB1J9Le9nvItXnOhC?= =?us-ascii?Q?PcF6foW1n8UL62PniD9btpc9yQ1IrkdkeZgeRoLgoCPFv464K2MMpseQ3dFL?= =?us-ascii?Q?1UjOtpE32yjdp61MSR0gmwQiAHVqv71vKr0LRmdGBQjMcMvXQ1knWvqBpCGc?= =?us-ascii?Q?S2RSiexXC8GKMiNExt/TTaiEpCd44ImigdldiG8+6o29qhVMZ7xMsg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OAi1xOppqRBSmZMyR9XyGHWH9bAT8nIY/nKHgh2kW6?= =?us-ascii?Q?ekCfDwzt6sJPZdICmAsCSkfBVDGRowFiLj1vcFHdP7uYWWxNmtFOHsNu0NqS?= =?us-ascii?Q?e2kkdY+r/omulG/eYbJ3ugMSUtzRUGKAQZK28siIHkN+1LCgdklpVSyAL7rT?= =?us-ascii?Q?OaOkQ8vPaD0No+4kFljyC9yYvC/ILiEdn+CPFFAOJhdD2oPKvk4Hs44+ZM+V?= =?us-ascii?Q?ktPx02A2+9arQOR8drN3256nv/69w+bWiNYPijvU5j5N+H1E06r8nh5hrLpo?= =?us-ascii?Q?CZo7kwGn+126axn6NKM=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5483.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68fb3416-0723-4641-9285-08dae304a277 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Dec 2022 03:37:07.1310 (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: HJ/g6Abv4sqWWI/USnM5FD6YDArIk8jESudJFgV4k/kgYhasPZqheXRl17x/E53oxB9OUtoud9RB4fujjvtU6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB6719 Return-Path: dun.tan@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Ray for the comments. I'll modify the code in V2 patch set. For comments 3, I'll replace the code by LinkedList library APIs from BaseL= ib in future patches. Thanks, Dun -----Original Message----- From: Ni, Ray =20 Sent: Monday, December 19, 2022 3:53 PM To: Tan, Dun ; devel@edk2.groups.io; Wang, Jian J Cc: Dong, Eric ; Kumar, Rahul R Subject: RE: [PATCH 3/3] UefiCpuPkg: Simplify the code to set smm page tabl= e as RO > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + > + // > + // ConvertMemoryPageAttributes might update mPageTablePool. It's=20 > + safer to // remember original one in advance. > + // > + HeadPool =3D mPageTablePool; > + Pool =3D HeadPool; > + do { > + Address =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Pool &=20 > + PAGE_TABLE_POOL_ALIGN_MASK; 1. When is the Pool not aligned on 128KB boundary? If it's guaranteed, can = we remove the "& PAGE_TABLE_POOL_ALIGN_MASK"? > + PoolSize =3D Pool->Offset + EFI_PAGES_TO_SIZE (Pool->FreePages); > + > + ConvertMemoryPageAttributes (PageTableBase, m5LevelPagingNeeded,=20 > + Address, PoolSize, EFI_MEMORY_RO, TRUE, > NULL, NULL); 2. Can you please explain in comments that above call is to make the entire= pool including header, used-memory, free-memory as read-only? 3. It's better to use LinkedList library APIs from BaseLib. The comments ap= ply to the first patch as well. But I am fine if you decide not to do it in= this patch. > + { > + if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { > + // > + // Restriction on access to non-SMRAM memory and heap guard could = not be enabled at the same time. > + // > + ASSERT ( > + !(IsRestrictedMemoryAccess () && > + (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) !=3D 0) > + ); > + > + // > + // Restriction on access to non-SMRAM memory and SMM profile could= not be enabled at the same time. > + // > + ASSERT (!(IsRestrictedMemoryAccess () && FeaturePcdGet (PcdCpuSmmP= rofileEnable))); > + } 4. I don't think we still need the above two assertions. But let's not clea= n up the code in your patch. @Wang, Jian J