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.web11.95534.1679645172285279396 for ; Fri, 24 Mar 2023 01:06:13 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=RzLvj15c; 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=1679645172; x=1711181172; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=toQJa6PcC5F5haE4bvQ6jI6E1FJQ+2ZBbSa/+kKTwYw=; b=RzLvj15cUWDjL4a/V5Ba3dixkHckR7nhK7oXUm2R6ooQUVxkg0MM1s2X bFuAkax9dFN3ld6soIhrvES1Nk53djeFgn06OUA52r1MV1ynzAlwFetEc grzeE+f1MKxYxdb45YHoHnB6stU7s/1BwBk/4RhOwFpmbzBLc2Us0s69V c0db1yOWXlDBm3GuhqnFTXUFpivkZuI49xNyTGUKhwKxC2XkWPV4VBYVF +M7znZowuyABSXH5SkJwoz7vDLLP+AaKmfq0/akVS5zxhWD8GXltXxqU/ 5McT2MV74W9MokNRtS/BzxIO8y3nD5dfq5ow5rcdWFuU11Ux9Flo4BwQZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="320113618" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="320113618" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 01:06:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="928571217" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="928571217" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga006.fm.intel.com with ESMTP; 24 Mar 2023 01:06:03 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) 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.21; Fri, 24 Mar 2023 01:06:02 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Fri, 24 Mar 2023 01:06:02 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Fri, 24 Mar 2023 01:06:02 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.172) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Fri, 24 Mar 2023 01:06:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EIs3SHE+1ubs/I9iCr+4gaeU/JsDRIUtbSz0CJwG0ZRe7RVSgjCms2pLlnCUo7gkyNBfsM9L9YGZoSvxPLRGmv8nEpd//o6aDm4f+4ExAHvMLcteuRiMwByJSfNze7A/Mp1T1VWDxp4/SEe1X/A0SAL/w3hO4kUEF2bb5q5g2F7Y/EwQhPP000kzQN0cQTOXUMzLjC8wMT0s1NWuP3RKiTRFCjXVrBpzPd7quWCf4YUAuPBxsbmhrLcZp2m3HzX8itSw1/GbEWgWObRRWfwcCpkqdAdP561CTnlH/kSNNvhoUBltCOqJITjJnxcGUXsRK9xwLWmypAQU0yR6kDx1wg== 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=jVNpYpeuzyGrA9o3bnC/CO1AnSyf38QMJ2u+V7vsC/Q=; b=bo84TP5vvfs5FuD9fXSSx9d9NkpRN6uK77uQRSpAm3oIQFmh9GFlgu4HUlcHEiTTQ+6rRv01Aj9h9TRUPbovyvbmXdsLrbedA1lSjXuTcpTjywqww8PTkMppUzHnCo0XRJ+IpVlIDtP4i3WO7N0C6Ufvn0R4hoqbHqfrkCQRDcLAwF4fyYobKOtbt77VaN1NLRYc3fhASpt+h5TuDpbNWlBFzKRClhGrDvNajEs9f+7x+cA7W0IRhXWr31tPs6E+iFDuVjZSFCTjqBeOVLXXovC2xmgXKUFoL6Cpw8Sm/CQVZM8oPQimTp9i78WaYWC8M1vLZ+Tk8AwwjdTIvpjVIw== 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 PH8PR11MB6705.namprd11.prod.outlook.com (2603:10b6:510:1c4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Fri, 24 Mar 2023 08:06:00 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::ae07:e96a:4a24:8a69]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::ae07:e96a:4a24:8a69%7]) with mapi id 15.20.6178.037; Fri, 24 Mar 2023 08:06:00 +0000 From: "Ni, Ray" To: "Tan, Dun" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann Subject: Re: [Patch V5 08/22] UefiCpuPkg/CpuPageTableLib:Add check for Mask and Attr Thread-Topic: [Patch V5 08/22] UefiCpuPkg/CpuPageTableLib:Add check for Mask and Attr Thread-Index: AQHZXhYBfCwmeJ/Om0aN2TWJGqVETK8JkrhQ Date: Fri, 24 Mar 2023 08:06:00 +0000 Message-ID: References: <20230324060020.940-1-dun.tan@intel.com> <20230324060020.940-9-dun.tan@intel.com> In-Reply-To: <20230324060020.940-9-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_|PH8PR11MB6705:EE_ x-ms-office365-filtering-correlation-id: 58cd388d-94bb-4177-d0a9-08db2c3e9ae0 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bj/OMo+/N31O0wMdME47YKfXsqK3SxF1O+RB5xxfufTCef9MzoRS8cHlD1MdMLWftqdislesmulatJknBWK8ZCy/iBrxX1XuoMCoGZCQFZ+2Zc1m71o/scYwk0Bpdu9o9+bkH784Ib3syfAYDsCoWeCXZJ+DftEm4jrfJ+DsV3+77BRLDwHgSxvBSH9O7OUOxKiyW4UQB0fmheMP24BVgCcp3bZcmkFzhZLGBGLpA8p66eRHUs4zAyFNdqYI4yLT01lRJnVa+rHzkGqL/0hifNyaIRHCDQ2qUCQOZhRnlMi7nfKsiEI+lMhUB3V1h+ucRmHeWvETxFM8QB8OvAZzdul8WozeH2wZTSYXvwW2u5e3JQDv5PDEw5tNrm/cpPfjt6PmHcZlBVbVZbKDJ02Plgei23TLRcNRfwHPqOnLyF69ZXBIuQ7e2Pyl6XXUtjDf/HITg+6Gehx5lWEK/Us7NHNGN4NW838yrcyrlLF4vRoG5YswgJKuhdCzBOCJPL7mVN+40M1KP1vOyjtAWnLDbH3Vgrvs6YMzoGyPtli7hh8NS95C7q5x4EVAbFEXC5eFAtrjsURtXB6ignHg64hd7FTmS4REuGG1l+u2YXxSOJrP2fSxOhdvWL7t1MCdjtmlQ1wjipJjg9T6UVzEYDu+B+a0r6m+iOHSxZazgZn1993r72FXvFRas+JH8HAb690PDygGkJx2ZRYJHfuS2FEmeg== 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:(13230025)(346002)(396003)(366004)(136003)(39860400002)(376002)(451199018)(33656002)(186003)(26005)(6506007)(53546011)(83380400001)(86362001)(38070700005)(2906002)(66946007)(66556008)(66446008)(71200400001)(76116006)(64756008)(54906003)(9686003)(8676002)(110136005)(66476007)(55016003)(4326008)(82960400001)(122000001)(478600001)(38100700002)(41300700001)(316002)(7696005)(52536014)(5660300002)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?MutyUl83j8uHWok2lcIK/qX/RMXc2dqx2Wf6bQoGsFGpgnbWPS1462jpDiPr?= =?us-ascii?Q?w2qWPfDBTdirnrehgWqcpFJUmfpGqAUsL4Fo4mZlrdjCMYdKX4KjpRpW88Bf?= =?us-ascii?Q?LguyIlEC438+Sao1Z4Aj7fdbgM8HGw28DzhKkRdTOZN9P6WqeHLiMWokRXSU?= =?us-ascii?Q?WxudRhDw4bP1cF3iY57x2mFjz6QldgXlW3S11YL2A0uwUQKwRmtJOdJN0Tle?= =?us-ascii?Q?DHuxyyR8Eofrsi9Ar016dqHRJansbBgbs7tZyOIybI3ojN7w8uWC7Gz8FzL6?= =?us-ascii?Q?XUNJAQnuB+OEqSIgM3beoIkW4zWaOK3QHclA8W7V63XSTNNOu5VwN+zZgMa1?= =?us-ascii?Q?atSoqtTDjB7J1EyC4nYLLU+8OemnnZUll13ATUbiUEciRO2kmywkzHyCcL3v?= =?us-ascii?Q?wLY/L3k/WLaTIhVRjC3qnDo4KL4V4EEmla8ofsHOVPQBM8mbRyIAnh/m+XXo?= =?us-ascii?Q?zvmehh7rl5b9kdosdEavIEwDJQnnXVCTziVJBbUxhtIZIMOwCLbCAyDt1rEB?= =?us-ascii?Q?nuWmlqC9fss8WDrO8MfAUpvL8JMW2ZSVULbAJY4Rc/4PpNeachf8BzAPHCfZ?= =?us-ascii?Q?+mp6q2J6UOrs4rW57R5J+Zt1koWjMPGUFTA0N+DkN6TpVk3tplhH5LIdPbKW?= =?us-ascii?Q?xCiqGuUle716Mr8jom3+ghTVwlAYqOfVAo64vt2atej4plxyCowgumP1WHr7?= =?us-ascii?Q?PC2l8C5x/+ZCc8us7FrmwjVad1MJAzAgxBA47+ltDZyutmlfEbefa3klb/jX?= =?us-ascii?Q?ss9w6irvylzXVcHVJ9tls8alOk2CSt97WrY4SKR0lu/84zy7rTlVdXK7SThh?= =?us-ascii?Q?1v3tHTAO7Z5inG54dXmCDuzDlAQubqwqAxYlym7Z0IAanEljCXtC026fUlg2?= =?us-ascii?Q?sZCD4M3ixrY785cJ6/ggl2+YViqtjSNqYTj6BTCBaOE18gJzjydL22/zxciv?= =?us-ascii?Q?dzbPS+4uhWglfpHAoE0rtY9AvV0hB3ko7Hpp3dGZ/wplc4TTq3uhMyYmVlHX?= =?us-ascii?Q?0i/G3yy9hiV+5u/whMe6cebJiFx5/wlNS/NvlL2Mpgng4RwrqHAC0179BqNy?= =?us-ascii?Q?HzfFZf/wjwqEBzoDk0rLf7Xu7w+S2C43QJNSgdtKAQYGt9Q3QbOueefbDqAQ?= =?us-ascii?Q?7subG3VfvnFow35k33fMyLJPCEhcqvP3QZOQQK85v/A2vEiG4oEXoYCM1644?= =?us-ascii?Q?Q0SS2frvoyBQC2LHIRN5N+qhxFtrSX8O77eUinQJXKnCUqWwVg6g6lW/AoqN?= =?us-ascii?Q?ls35AJdnnDPPsNWffSvvLWeFf04JtSZzmR2PP/KIOCdGXMVLH6VfqBm7Y+yd?= =?us-ascii?Q?r7k0OfL0GPpQ6orkV0VeJsPsgeqbp5GHFQ93siHLnyDgkKlF38VSVVX9YkcB?= =?us-ascii?Q?Hxj79d/i9ay2hYGOHn9rw+RJVuz78Hmkq++5P8jPwzRgMZg8lgvQy4tRxMWo?= =?us-ascii?Q?cNxIK9jYl3tZUISWEIbVu/nKYuN3sdq+hw5sVk3LPRV7hKmzapQP2VZJmDSA?= =?us-ascii?Q?KAa7gUkfITq6m02gqtupAL7HWApgzNgfs1fgI4tY8I/V9PZxF/4tOMuJhMK4?= =?us-ascii?Q?D2RfbaJl3gzLvZEkjL4=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: 58cd388d-94bb-4177-d0a9-08db2c3e9ae0 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Mar 2023 08:06:00.0434 (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: KKSR64tgt1GaA4JkLtvaD8pujOVzInJZSMqqJZlZWTOtFHEZufwsn/jNCx82dqLT5zj6HkwCMd1LfLuTiUqSyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB6705 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: Friday, March 24, 2023 2:00 PM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Gerd Hoffmann > Subject: [Patch V5 08/22] UefiCpuPkg/CpuPageTableLib:Add check for Mask > and Attr >=20 > For different usage, check if the combination for Mask and > Attr is valid when creating or updating page table. >=20 > 1.For non-present range > 1.1Mask.Present is 0 but some other attributes is provided. > This case is invalid. > 1.2Mask.Present is 1 and Attr.Present is 0. In this case,all > other attributes should not be provided. > 1.3Mask.Present is 1 and Attr.Present is 1. In this case,all > attributes should be provided to intialize the attribute. >=20 > 2.For present range > 2.1Mask.Present is 1 and Attr.Present is 0.In this case, all > other attributes should not be provided. > All other usage for present range is permitted. > In the mentioned cases, 1.2 and 2.1 can be merged into 1 check. >=20 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Tested-by: Gerd Hoffmann > Acked-by: Gerd Hoffmann > --- > UefiCpuPkg/Include/Library/CpuPageTableLib.h | 4 ++++ > UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 83 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++- > 2 files changed, 86 insertions(+), 1 deletion(-) >=20 > diff --git a/UefiCpuPkg/Include/Library/CpuPageTableLib.h > b/UefiCpuPkg/Include/Library/CpuPageTableLib.h > index 5f44ece548..4ef4a8b6af 100644 > --- a/UefiCpuPkg/Include/Library/CpuPageTableLib.h > +++ b/UefiCpuPkg/Include/Library/CpuPageTableLib.h > @@ -77,6 +77,10 @@ typedef enum { >=20 > @retval RETURN_UNSUPPORTED PagingMode is not supported. > @retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute > or Mask is NULL. > + @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. > + @retval RETURN_INVALID_PARAMETER For non-present range, Mask- > >Bits.Present is 1, Attribute->Bits.Present is 0 but some other attribute= s are > provided. > + @retval RETURN_INVALID_PARAMETER For present range, Mask- > >Bits.Present is 1, Attribute->Bits.Present is 0 but some other attribute= s are > provided. > @retval RETURN_INVALID_PARAMETER *BufferSize is not multiple of 4KB. > @retval RETURN_BUFFER_TOO_SMALL The buffer is too small for page > table creation/updating. > BufferSize is updated to indicate th= e expected buffer size. > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > index c87eb23248..c0b41472ce 100644 > --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > @@ -215,6 +215,44 @@ PageTableLibSetPnle ( > Pnle->Bits.CacheDisabled =3D 0; > } >=20 > +/** > + Check if the combination for Attribute and Mask is valid for non-prese= nt > entry. > + 1.Mask.Present is 0 but some other attributes is provided. This case s= hould > be invalid. > + 2.Map non-present range to present. In this case, all attributes shoul= d be > provided. > + > + @param[in] Attribute The attribute of the linear address range. > + @param[in] Mask The mask used for attribute to check. > + > + @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. > + @retval RETURN_SUCCESS The combination for Attribute and Ma= sk is > valid. > +**/ > +RETURN_STATUS > +IsAttributesAndMaskValidForNonPresentEntry ( > + IN IA32_MAP_ATTRIBUTE *Attribute, > + IN IA32_MAP_ATTRIBUTE *Mask > + ) > +{ > + if ((Mask->Bits.Present =3D=3D 1) && (Attribute->Bits.Present =3D=3D 1= )) { > + // > + // Creating new page table or remapping non-present range to present= . > + // > + if ((Mask->Bits.ReadWrite =3D=3D 0) || (Mask->Bits.UserSupervisor = =3D=3D 0) || > (Mask->Bits.WriteThrough =3D=3D 0) || (Mask->Bits.CacheDisabled =3D=3D 0)= || > + (Mask->Bits.Accessed =3D=3D 0) || (Mask->Bits.Dirty =3D=3D 0) ||= (Mask- > >Bits.Pat =3D=3D 0) || (Mask->Bits.Global =3D=3D 0) || > + (Mask->Bits.PageTableBaseAddress =3D=3D 0) || (Mask->Bits.Protec= tionKey > =3D=3D 0) || (Mask->Bits.Nx =3D=3D 0)) > + { > + return RETURN_INVALID_PARAMETER; > + } > + } else if ((Mask->Bits.Present =3D=3D 0) && (Mask->Uint64 > 1)) { > + // > + // Only change other attributes for non-present range is not permitt= ed. > + // > + return RETURN_INVALID_PARAMETER; > + } > + > + return RETURN_SUCCESS; > +} > + > /** > Update page table to map [LinearAddress, LinearAddress + Length) with > specified attribute in the specified level. >=20 > @@ -237,6 +275,8 @@ PageTableLibSetPnle ( > 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. >=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. > @retval RETURN_SUCCESS PageTable is created/updated success= fully. > **/ > RETURN_STATUS > @@ -260,6 +300,7 @@ PageTableLibMapInLevel ( > UINTN Index; > IA32_PAGING_ENTRY *PagingEntry; > UINTN PagingEntryIndex; > + UINTN PagingEntryIndexEnd; > IA32_PAGING_ENTRY *CurrentPagingEntry; > UINT64 RegionLength; > UINT64 SubLength; > @@ -306,6 +347,14 @@ PageTableLibMapInLevel ( > // >=20 > if (ParentPagingEntry->Pce.Present =3D=3D 0) { > + // > + // [LinearAddress, LinearAddress + Length] contains non-present rang= e. > + // > + Status =3D IsAttributesAndMaskValidForNonPresentEntry (Attribute, Ma= sk); > + if (RETURN_ERROR (Status)) { > + return Status; > + } > + > // > // The parent entry is CR3 or PML5E/PML4E/PDPTE/PDE. > // It does NOT point to an existing page directory. > @@ -383,6 +432,27 @@ PageTableLibMapInLevel ( > ParentPagingEntry->Uint64 =3D ((UINTN)(VOID *)PagingEntry) | > (ParentPagingEntry->Uint64 & (~IA32_PE_BASE_ADDRESS_MASK_40)); > } > } else { > + // > + // If (LinearAddress + Length - 1) is not in the same ParentPagingEn= try > with (LinearAddress + Offset), then the remaining child PagingEntry > + // starting from PagingEntryIndex of ParentPagingEntry is all covere= d by > [LinearAddress + Offset, LinearAddress + Length - 1]. > + // > + PagingEntryIndexEnd =3D (BitFieldRead64 (LinearAddress + Length - 1, > BitStart + 9, 63) !=3D BitFieldRead64 (LinearAddress + Offset, BitStart += 9, 63)) ? > 511 : > + (UINTN)BitFieldRead64 (LinearAddress + Length = - 1, BitStart, > BitStart + 9 - 1); > + PagingEntry =3D (IA32_PAGING_ENTRY > *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&ParentPagingEntry- > >Pnle); > + for (Index =3D PagingEntryIndex; Index <=3D PagingEntryIndexEnd; Ind= ex++) { > + if (PagingEntry[Index].Pce.Present =3D=3D 0) { > + // > + // [LinearAddress, LinearAddress + Length] contains non-present = range. > + // > + Status =3D IsAttributesAndMaskValidForNonPresentEntry (Attribute= , > Mask); > + if (RETURN_ERROR (Status)) { > + return Status; > + } > + > + break; > + } > + } > + > // > // It's a non-leaf entry > // > @@ -430,7 +500,6 @@ PageTableLibMapInLevel ( > // Update child entries to use restrictive attribute inherited f= rom parent. > // e.g.: Set PDE[0-255].ReadWrite =3D 0 > // > - PagingEntry =3D (IA32_PAGING_ENTRY > *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&ParentPagingEntry- > >Pnle); > for (Index =3D 0; Index < 512; Index++) { > if (PagingEntry[Index].Pce.Present =3D=3D 0) { > continue; > @@ -557,6 +626,10 @@ PageTableLibMapInLevel ( >=20 > @retval RETURN_UNSUPPORTED PagingMode is not supported. > @retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute > or Mask is NULL. > + @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. > + @retval RETURN_INVALID_PARAMETER For non-present range, Mask- > >Bits.Present is 1, Attribute->Bits.Present is 0 but some other attribute= s are > provided. > + @retval RETURN_INVALID_PARAMETER For present range, Mask- > >Bits.Present is 1, Attribute->Bits.Present is 0 but some other attribute= s are > provided. > @retval RETURN_INVALID_PARAMETER *BufferSize is not multiple of 4KB. > @retval RETURN_BUFFER_TOO_SMALL The buffer is too small for page > table creation/updating. > BufferSize is updated to indicate th= e expected buffer size. > @@ -618,6 +691,14 @@ PageTableMap ( > return RETURN_INVALID_PARAMETER; > } >=20 > + // > + // If to map [LinearAddress, LinearAddress + Length] as non-present, > + // all attributes except Present should not be provided. > + // > + if ((Attribute->Bits.Present =3D=3D 0) && (Mask->Bits.Present =3D=3D 1= ) && (Mask- > >Uint64 > 1)) { > + return RETURN_INVALID_PARAMETER; > + } > + > MaxLeafLevel =3D (IA32_PAGE_LEVEL)(UINT8)PagingMode; > MaxLevel =3D (IA32_PAGE_LEVEL)(UINT8)(PagingMode >> 8); > MaxLinearAddress =3D LShiftU64 (1, 12 + MaxLevel * 9); > -- > 2.31.1.windows.1