From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.2229.1678844656229167852 for ; Tue, 14 Mar 2023 18:44:16 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=BTh7tZLY; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1678844656; x=1710380656; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=R7tDewIsDyaui0afjMiNPglsFo+GAVxMR/2gFjRdlBY=; b=BTh7tZLYVoaPzdLtJ37O4TUfGx2e5H9PpSniuIUProFry89b5ugLVThv VYU1NcVab2tEavBKJW1c8JlbE1+1PEnGeG9yyPjmHwVzOW6WJu6JKTTuk BG5X/1YTeH21UYoCFzrewHfb8m9JVvKF/4tq5n0Vp4UpdJyt19495J13c BlojIVM6pu2BGQzd0afdXqM+Pm2CXXJ0JixLorRkwmpnsjand776Vm6Q9 SY6ydHCbKLxRerEQVCE9V/jIQOOhEoj18VRRHqO95yKki5uGTYOTgpaL6 /PnKWtkqUaS0nBV5fMvt9IGhV+fgVHYIcRuKWbXNdo9icbFIFDpyOdrye A==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="339127522" X-IronPort-AV: E=Sophos;i="5.98,261,1673942400"; d="scan'208";a="339127522" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2023 18:44:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="709507177" X-IronPort-AV: E=Sophos;i="5.98,261,1673942400"; d="scan'208";a="709507177" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga008.jf.intel.com with ESMTP; 14 Mar 2023 18:44:15 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) 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.21; Tue, 14 Mar 2023 18:44:14 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) 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.21; Tue, 14 Mar 2023 18:44:14 -0700 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.21 via Frontend Transport; Tue, 14 Mar 2023 18:44:14 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.172) 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.21; Tue, 14 Mar 2023 18:44:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JR0/4uvwBreyiF+HIVGDUTB87g8xHUE4/SiS9fyd6CHty/AW85sdyekde0SS91vDB0dQw7iJ/YlTZ5JdAVL2A3IHaAS50S82LppJok3Q4HUI/krw6vgeF8l/Lkc9PG6YKCvwIV252q6eMSYB8rMBY6f3pDlpvBiveetP8rssmgwwGOxaCkkiS14JNiCIVX9dPxRNRNrWU0v8N1lT7XE48fqfDqL30iu2tw2pC4Nhm63PD64ljR7o/hqiMi40/UbUD4UWBPkpSr99tfrLnqeZvkn39O8Br2Fa0ZQKqqYneapG+OcR+XIX+4fyaywRC4feDy6nU4sfuWElcak9X65Q7Q== 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=3ejViyOQix1AaqxR8KFimHFWz7+USYMYhM0f8IBmmYE=; b=fweqY806+9cdsPrpOmU+IHgCCCo4+V3A9NwlpIt51guqsX0O+229LQMwT+1xsxNI+CaeTe+P9scSLDPTSSX0ILa2tbfHqrFi/m65y3QMSINsYoe+5Wcl2VUf131XnmjZGjInkGx5mUzNexRa0bjtxrwgLvBLZPddLjCUK7cOTFVYrq1S03Cf1BsjmkJFqoCzDvdi4ksDrEYbcNsozn/fkdJflUKRgvBZG6Vfj3UKBMKRr0YgoUe3M9PKWpkfDCuW1hijkXBsHxPGt2pIVshY6PynIepvOh5ZphXvh9HoKnSJfiRpYaspAfg7ijaQ1RmatGNlbvNbKt3/ZantBRNyVQ== 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 DM4PR11MB5421.namprd11.prod.outlook.com (2603:10b6:5:398::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Wed, 15 Mar 2023 01:44:12 +0000 Received: from BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::af70:de56:4a6f:b2cc]) by BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::af70:de56:4a6f:b2cc%8]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 01:44:12 +0000 From: "duntan" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann Subject: Re: [Patch V2 03/14] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue Thread-Topic: [Patch V2 03/14] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue Thread-Index: AQHZUaYDj4YsQZZz/kelX3Cy0v5QEa77F1HggAAEdEA= Date: Wed, 15 Mar 2023 01:44:11 +0000 Message-ID: References: <20230308100758.669-1-dun.tan@intel.com> <20230308100758.669-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_|DM4PR11MB5421:EE_ x-ms-office365-filtering-correlation-id: edadcc7d-5acb-4aa0-8cc8-08db24f6c6bc x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: htNwSiYfmViE1/PjLiSaWp3sGU67n2Nf6cw2v3o0ReIxCIh2Sr8gv01tDUdOBjbcZ5ECVyKq+BGFLMBHNoHIux1BeFFr/CnQa16SlaQ9dHvyKHAjIuqJqK82jdD12pYF69CHdS1X7S2oJQQ8tun1Y4zkpYtpzNgtbom3VE4zMDQXvhz1K8J1AEaYauHLRMR5vmfv3Z5w/wCwxLisbRffdufEE3jWMaSLy4Xf5R1S1+GB1iqOQuoO45dmi/eCz4U7z+YCOIYgBw2TPZ5LloeT/J15yqrmn5TP88LMs7ifaA6tQuh0i/mvw7sR8aPurf/thL5BxOdOdsFu3mcnsX3iU/cpHtQ5K0Msa+CKV11V3D/w+NCquqWt+en83GcAP4KZbFU6C+wR44od7u38mPvuW7BV+640+B086q4wHY2u3iGhz5WrZJHDUVHp5MuhBZuQ/1SDhD+X2Ylx4o7HicOZc/oxy3wasZFo+6gn2RnUR0kobFZYSffrv7REkjVIwvnra8g4zH0qOiGTDkhPcbcT67XHJ0wuc+z7oaJ7+3lziVsya1hSlO0Q8z6LkcA8YCSsvp9thWsO3mtWHYArDE1+b8cP5AzX9GgudNpvTnvUm8Zq4roy8NraWA46QhVuG8+y+FJ0o10b7NOsI3BvodHb9W0kVAICO5P53fEn4MW6+r5YdupcFvl1ItOJJb3NDLp79Edl1r3QeXD6NnhWZSjA1g== 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:(13230025)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(38100700002)(82960400001)(122000001)(66446008)(64756008)(4326008)(41300700001)(316002)(83380400001)(66556008)(66946007)(54906003)(19627235002)(110136005)(76116006)(8676002)(66476007)(38070700005)(52536014)(8936002)(5660300002)(71200400001)(7696005)(478600001)(86362001)(53546011)(6506007)(9686003)(26005)(55016003)(2906002)(186003)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?dpeOtaCr/iWGeJsETag+zkD0pOVGEKJjs2LK4XKSp8WfLn3+cAuBW9QSfnzK?= =?us-ascii?Q?BGvOlsFh4+pRDDDDHcM7qnapTtjO1iyX7vCCDVlBLhwlIPagX+pWgzjDUHrs?= =?us-ascii?Q?KoY6OafJESvT8mmgEtUXKs2vGpMtDZvp4I7D2OdckW6cJZ/6WIICPf5dRSGM?= =?us-ascii?Q?Vy/VYzi69FwYnuGtEe3wNkxY9KH3XJ/mlN0p7JLMQcVzAcIHSrSICfvpEEOA?= =?us-ascii?Q?/Hps70SRWfRpp45GgybLiDgJN9vClXRJeFD1lTzBdK982aaFkAVTMagK9jZJ?= =?us-ascii?Q?Mm194mWkgUOFdJu4ei1DartfIAoHlNec9AFUArUrNL+p4QiXpBDb403ycl/L?= =?us-ascii?Q?gH10k/EXNzihgEUn1CM2Dasi+7Bh7i9rM1PiJtjaMAS69HURGnB3ok/ga5wD?= =?us-ascii?Q?FxNR3sZcLNhF/PdXZ5o+Lxp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ascii?Q?yetDejD64oF4Wh/L76GAY20BI4jT6S/U6CUTpobfiyl/qhsFgGvOnV/umo5l?= =?us-ascii?Q?rpNLoLF4cYvl8XtkA32dzwJzHWCgKirpBLrNMhobVKU0hM8Uby3r6miDlR3W?= =?us-ascii?Q?xynzlIfT+HuzTMNnNPuGSr1PQwG3YQoFaioAvZmmkQ5ebijTxYolZXPPZSHN?= =?us-ascii?Q?8Qn1MY76cATD3Z76G/fydq1wKm59l/d/dKrUeiC+aMLpC7n+eX4BRklknP/c?= =?us-ascii?Q?VvpQOD9A3tf8AU7z0Z1hVCYM20+JqTFIt/Jwb0Ce?= 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: edadcc7d-5acb-4aa0-8cc8-08db24f6c6bc X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2023 01:44:11.7544 (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: 7Y7yuqJLXtS7yYuTwejOD9L6KbAt0en2AV6DlQAKUkYvKwWySWFkUrn7MJMGX5N5osbWgZvH53JI++/rGmX4pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5421 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 Okay, I'll split this patch into 2 patches in next version Thanks, Dun -----Original Message----- From: Ni, Ray =20 Sent: Wednesday, March 15, 2023 9:28 AM To: Tan, Dun ; devel@edk2.groups.io Cc: Dong, Eric ; Kumar, Rahul R ; Gerd Hoffmann Subject: RE: [Patch V2 03/14] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 m= apping issue Dun, Can you split this patch to 2 patches? One to move some local variable initialization to the beginning of the func= tion. The other to fix the bug. So the bug fix changes look smaller. Thanks, Ray > -----Original Message----- > From: Tan, Dun > Sent: Wednesday, March 8, 2023 6:08 PM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ;=20 > Kumar, Rahul R ; Gerd Hoffmann=20 > > Subject: [Patch V2 03/14] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1=20 > mapping issue >=20 > In previous code logic, when splitting a leaf parent entry to smaller=20 > granularity child page table, if the parent entry=20 > Attribute&Mask(without PageTableBaseAddress field) is equal to the=20 > input attribute&mask(without PageTableBaseAddress field), the split=20 > process won't happen. This may lead to failure in non-1:1 mapping. >=20 > For example, there is a page table in which [0, 1G] is mapped(Lv4[0]=20 > ,Lv3[0,0], a non-leaf level4 entry and a leaf level3 entry). And we=20 > want to remap [0, 2M] linear address range to [1G, 1G + 2M] with the=20 > same attibute. The expected behaviour should be: split Lv3[0,0] entry=20 > into 512 level2 entries and remap the first level2 entry to cover [0,=20 > 2M]. But the split won't happen in previous code since=20 > PageTableBaseAddress of input Attribute is not checked. >=20 > So, when checking if a leaf parent entry needs to be splitted, we=20 > should also check if PageTableBaseAddress calculated by parent entry=20 > is equal to the value caculated by input attribute. >=20 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > --- > UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 27 > +++++++++++++++++---------- > 1 file changed, 17 insertions(+), 10 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > index 4c9d70fa0a..ee27238edb 100644 > --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > @@ -258,6 +258,7 @@ PageTableLibMapInLevel ( > UINTN BitStart; > UINTN Index; > IA32_PAGING_ENTRY *PagingEntry; > + UINTN PagingEntryIndex; > IA32_PAGING_ENTRY *CurrentPagingEntry; > UINT64 RegionLength; > UINT64 SubLength; > @@ -288,6 +289,13 @@ PageTableLibMapInLevel ( > LocalParentAttribute.Uint64 =3D ParentAttribute->Uint64; > ParentAttribute =3D &LocalParentAttribute; >=20 > + // > + // RegionLength: 256T (1 << 48) 512G (1 << 39), 1G (1 << 30), 2M (1=20 > + << 21) > or 4K (1 << 12). > + // > + BitStart =3D 12 + (Level - 1) * 9; > + PagingEntryIndex =3D (UINTN)BitFieldRead64 (LinearAddress + Offset, > BitStart, BitStart + 9 - 1); > + RegionLength =3D REGION_LENGTH (Level); > + > // > // ParentPagingEntry ONLY is deferenced for checking Present and=20 > MustBeOne bits > // when Modify is FALSE. > @@ -325,8 +333,11 @@ PageTableLibMapInLevel ( > // the actual attributes of grand-parents when determing the=20 > memory type. > // > PleBAttribute.Uint64 =3D PageTableLibGetPleBMapAttribute=20 > (&ParentPagingEntry->PleB, ParentAttribute); > - if ((IA32_MAP_ATTRIBUTE_ATTRIBUTES (&PleBAttribute) & > IA32_MAP_ATTRIBUTE_ATTRIBUTES (Mask)) > - =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & > IA32_MAP_ATTRIBUTE_ATTRIBUTES (Mask))) > + if ((((IA32_MAP_ATTRIBUTE_ATTRIBUTES (&PleBAttribute) & > IA32_MAP_ATTRIBUTE_ATTRIBUTES (Mask)) > + =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & > IA32_MAP_ATTRIBUTE_ATTRIBUTES (Mask)))) && > + ( (Mask->Bits.PageTableBaseAddress =3D=3D 0) > + || ((IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS > (&PleBAttribute) + PagingEntryIndex * RegionLength) > + =3D=3D (IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS=20 > + (Attribute) > + Offset)))) > { > // > // This function is called when the memory length is less than=20 > the region length of the parent level. > @@ -353,8 +364,7 @@ PageTableLibMapInLevel ( > // > PageTableLibSetPnle (&ParentPagingEntry->Pnle, &NopAttribute,=20 > &AllOneMask); >=20 > - RegionLength =3D REGION_LENGTH (Level); > - PagingEntry =3D (IA32_PAGING_ENTRY > *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&ParentPagingEntry- > >Pnle); > + PagingEntry =3D (IA32_PAGING_ENTRY > *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&ParentPagingEntry- > >Pnle); > for (SubOffset =3D 0, Index =3D 0; Index < 512; Index++) { > PagingEntry[Index].Uint64 =3D OneOfPagingEntry.Uint64 + SubOffse= t; > SubOffset +=3D RegionLength; > @@ -425,14 +435,11 @@ PageTableLibMapInLevel ( > } >=20 > // > - // RegionLength: 256T (1 << 48) 512G (1 << 39), 1G (1 << 30), 2M (1=20 > << 21) or 4K (1 << 12). > // RegionStart: points to the linear address that's aligned on=20 > RegionLength and lower than (LinearAddress + Offset). > // > - BitStart =3D 12 + (Level - 1) * 9; > - Index =3D (UINTN)BitFieldRead64 (LinearAddress + Offset, BitSta= rt, > BitStart + 9 - 1); > - RegionLength =3D LShiftU64 (1, BitStart); > - RegionMask =3D RegionLength - 1; > - RegionStart =3D (LinearAddress + Offset) & ~RegionMask; > + Index =3D PagingEntryIndex; > + RegionMask =3D RegionLength - 1; > + RegionStart =3D (LinearAddress + Offset) & ~RegionMask; >=20 > ParentAttribute->Uint64 =3D PageTableLibGetPnleMapAttribute=20 > (&ParentPagingEntry->Pnle, ParentAttribute); >=20 > -- > 2.31.1.windows.1