From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.3930.1678873857903293843 for ; Wed, 15 Mar 2023 02:50:58 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=V3po6U5t; spf=pass (domain: intel.com, ip: 134.134.136.20, 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=1678873858; x=1710409858; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=HBqr+o8EdvI8DhtwNYFw7RpKeEBhaVyAChSzZg0IVJw=; b=V3po6U5tBkhA2JqIjyL6J2COM0b5HhTABh5A7pqLRC1PmgGs03lkqcBF hcexEozLckeQ5WpgU0XXjZa/aUrbQt9udYvhmo9OKM9tSb6NkS5P12ICH NdQcGpnlmJDo6AbnQLsCHrZlDqkmpfGtdHqYQM/AT0cEHrjiU6jxWoZRJ Gb1TN2ZwuSoBJPGm7sdZ8ol1XFlXoLW3T+gWfizyPvD6ON6oEgmEY2Hem ZK0Flr4ASlq9UAFKLFrMrPgM+ndJMmArSUIYDANkk/635gWm3OjJ7wbiY Ea/hCAm1njCoS2+NEu1Rlxr//ms7m8aFkTyToHRYR25oTXBgJI1VkuUMN A==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="326018882" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="326018882" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 02:49:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="768431468" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="768431468" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by FMSMGA003.fm.intel.com with ESMTP; 15 Mar 2023 02:49:30 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) 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.21; Wed, 15 Mar 2023 02:49:29 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) 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.21 via Frontend Transport; Wed, 15 Mar 2023 02:49:29 -0700 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.40) 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.21; Wed, 15 Mar 2023 02:49:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cs5Jdm84JA8cjGBuBmxEvumaVipda+yvm5IzHE1oNIiOuSRDBcaHZkA1rcV6rtv6A/pnzxcp5lx8oKR1XzvTq9msEEPedJepbf6ViHLPuX2NY52d1HqPzqTzcp9c6AKMOc1YHwS/P38fk7HwaujQ5S/8+94uRtCYrCz6fJLQk8+agQRGikCb6ykOyzOkTKVzKylmpy7Y0CeyoN1eqObwlRk8K/IAxxUCNbPXVlYTEPa6Hh0YEwurebye2VOk1XaN3PEcv/hykC3dLZO/+XHlLEjEd6bZTjoxld1a0ZAsXSf0yVS/wMtyuI83CwC31/EB3riEPfjKJKSqgricS0rVDA== 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=FqWxrgh4viVqoWohbz7EGOHtNnK3qxQgGc+wX0VOEw8=; b=mqPISFz/mVjbFJETFUqr2JxSDnAK2/o9vHyHTrxW4IkgMSFbFK4d5OkZvsIccxT+NpsAYTLFU5UCfqf+1Ag33xIs9f+xc1ytJdOFNo6seurd1ZCXrv/QnG6sEiWQZZ/fBiGWUJB9tqou/lEvIUEYE67x4vunLJlsqBEps0Ohl1cXQWb313U/DL7gp43j39aq/TNwgpzUQji0Qh8kLEM8CJg8Ttbmi60joFlvdEacxOqAlTEIsboVRzCtOBgR6J4E57M6l3xZcQQNDVvL/6EnDgITcjdrimefNP3Bp9YPB/DP4rCs4Dp3WJrM6q4cpClQB+tkZH3LD5j7KU4/oXQbrQ== 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 DM8PR11MB5574.namprd11.prod.outlook.com (2603:10b6:8:39::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29; Wed, 15 Mar 2023 09:49:26 +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 09:49:26 +0000 From: "duntan" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann , "Liu, Zhiguang" Subject: Re: [Patch V2 07/14] UefiCpuPkg/CpuPageTableLib:Modify RandomTest to check Mask/Attr Thread-Topic: [Patch V2 07/14] UefiCpuPkg/CpuPageTableLib:Modify RandomTest to check Mask/Attr Thread-Index: AQHZUaYR5FKRIuxq8EuthRWyTK7zTK77XT2QgABBenA= Date: Wed, 15 Mar 2023 09:49:26 +0000 Message-ID: References: <20230308100758.669-1-dun.tan@intel.com> <20230308100758.669-8-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_|DM8PR11MB5574:EE_ x-ms-office365-filtering-correlation-id: 78a892e0-f536-480b-dbf2-08db253a9058 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pMNANGgZJnSTxWUAV2yKGxy9+wHOxdNVV057laJPkCA/aneWea5eEAuLq+iD4fmzbVc6LemTlXIlZMGveQTcz7cjcW9OlDWtS1EcfTyo8z0XJF+4ltPxsOffQLcz5ojxJtAjg2hSxITvel3u/nZnv4udQ8EtRWjIhHW2Rho8Pdna/6DcmqQZoI7j9j80o7HAj62E5LptSF52n6EXtiR3ImsDoKYBExO2ZnYDLLnNEtB6O5L7pC0oGFDHWM++H/jon4N71y1yu0juifcvUDj0gj623GIJaiXB8f3UScgSN7v1g+SNCZYbhQGJdAb7a7HtRqSCEdZMuBuCS/38dS0l9NsrnwXWe/++WpXERADOmqG0EkcDtCBQhG7HaKl75EAJm5t/l9KcAvne24gewGzJvbOQSmjx465vLkw/uktct63CYYkiFu5SI3SS2YqilAlmP1IjqIETIVhj/tK2KLHP37P1amymuwuzbZZvLH5WhTHeFuZZpf4Y7goAuYx5eqy9VFO6rP0LpD4yG/KVClAEIfE0YBRTno860PYcAekFk1jVcH5yDKgdw7m6KPsThmjcPjjYw4sE58Lux9qyE5Z0RauWBaVTroLtRnZPPk6wKdRIfPRNS+puD9tOwu30BI5cbNJ3CvE2WAESg/XKVBFtuiUqCfXBFwaktX/70cpWr61LnKgEFv/xvLooNo/76qzynKORrwdqWPPZgsjiDWn0zw== 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)(366004)(376002)(396003)(39860400002)(136003)(346002)(451199018)(5660300002)(83380400001)(107886003)(478600001)(7696005)(53546011)(71200400001)(9686003)(6506007)(26005)(186003)(66446008)(38070700005)(76116006)(66556008)(52536014)(66946007)(55016003)(64756008)(33656002)(41300700001)(4326008)(8936002)(66476007)(86362001)(54906003)(110136005)(316002)(38100700002)(82960400001)(122000001)(2906002)(8676002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?sANaoiZS5SvF73lDpiYDweVjNDAlMAlcQNDf7IPYRTp11OMLrm1iH37fMfJk?= =?us-ascii?Q?ECTpieblkiDv6Ga7HmqweO5vJK+Uxt5txtcbQBhS5QZotltOw3JungkS4EsO?= =?us-ascii?Q?ivRkvsstq2lDtqGNnoEprbuYR4UerHfYCnFwV8Y2iv0l4KCfzlLtvH/FKRcc?= =?us-ascii?Q?WvFmLzcFvgffvLDh0CvKUNptsXAEhB8tmq8JtXNJhlcfPtVIAo+vHzixS3ph?= =?us-ascii?Q?cNIBke2JqTF51h9jPk0gm4/oF1l+6Y6cY5dMjE5OGdklxZ8tD1t/rE2TzBjf?= =?us-ascii?Q?0LNBBxjUQHI2/HDLyus4ugGVfuEjQ5GJfZcNGxma3kSuxnV6ogQvXkpb97GO?= =?us-ascii?Q?+rtJKR1ljhyH1M/bW83Oa6zpr/1jFDJC1HdbCnRtuqHh+I37jTPXuy3by+bF?= =?us-ascii?Q?o0x2cHgCVQM5VxJCwvwDnHcC9jU5u/EVoYFUuOZBD16ZfYankHJiAe8k+BZ/?= =?us-ascii?Q?qzDhoi1Gbc5wp4LEPbHG7skLEXva9CjvCe/FbHIK9CtRQphfU4pGOvmHdgEk?= =?us-ascii?Q?9MRGqHnh7kJpV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= =?us-ascii?Q?Tb/n0mStzZADvcQyu4O46WaZnlAUxM0LrbSXqS6PVwMDCWwSLdaBQUIq79Ae?= =?us-ascii?Q?fIwyncO8Bg9e6sQa8tAl9SGdSA13PavfBmR02arKkZ9iu50zWWBirRmzaDBL?= =?us-ascii?Q?rbvQVud8lu1rkJSIiJgTJvH2T7VmVF+/c5CE+gyN?= 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: 78a892e0-f536-480b-dbf2-08db253a9058 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2023 09:49:26.2505 (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: dN9q/j1jRRaC56eNsMHTRSn18z4Ux4edGp+r4r3Ao/JjqIXj/QdlY/dhlnM41gy275CaLAX3UFrcLm6PIz/FUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR11MB5574 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. Will create a new patch to split the RandomBoo= lean() and simplify the code loop in random test Thanks, Dun -----Original Message----- From: Ni, Ray =20 Sent: Wednesday, March 15, 2023 1:49 PM To: Tan, Dun ; devel@edk2.groups.io Cc: Dong, Eric ; Kumar, Rahul R ; Gerd Hoffmann ; Liu, Zhiguang Subject: RE: [Patch V2 07/14] UefiCpuPkg/CpuPageTableLib:Modify RandomTest = to check Mask/Attr >=20 > -/** > - Return a random boolean. > - > - @return boolean > -**/ > -BOOLEAN > -RandomBoolean ( > - VOID > - ) > -{ > - BOOLEAN Value; > - > - LocalRandomBytes ((UINT8 *)&Value, sizeof (BOOLEAN)); > - return Value%2; > -} > - > /** > Return a 32bit random number. >=20 > @@ -139,6 +123,21 @@ Random64 ( > return (UINT64)(Value % (Limit - Start + 1)) + Start; } >=20 > +/** > + Returns true with the percentage of input Probability. > + > + @param[in] Probability The percentage to return true. > + > + @return boolean > +**/ > +BOOLEAN > +RandomBoolean ( > + UINT8 Probability > + ) > +{ > + return ((Probability > ((UINT8)Random64 (0, 100))) ? TRUE : FALSE);=20 > +} 1. can you split the RandomBoolean() change in standalone patch? 2. can you simplify below code to only use for-loop? > + // > + if (MapEntrys->Maps[MapsIndex].Length > 0) { > + if (MapCount !=3D 0) { > + UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); > + Map =3D AllocatePages (EFI_SIZE_TO_PAGES (MapCount * sizeof > (IA32_MAP_ENTRY))); > + ASSERT (Map !=3D NULL); > + Status =3D PageTableParse (*PageTable, PagingMode, Map,=20 > + &MapCount); > + > + if (Map[MapCount - 1].LinearAddress + Map[MapCount - 1].Length=20 > + < > MapEntrys->Maps[MapsIndex].LinearAddress + MapEntrys- > >Maps[MapsIndex].Length) { > + IsNotPresent =3D TRUE; > + } else { > + for (Index =3D 0; Index < MapCount; Index++) { > + if ((PreviousAddress < Map[Index].LinearAddress) && > + (MapEntrys->Maps[MapsIndex].LinearAddress < > Map[Index].LinearAddress) && > + ((MapEntrys->Maps[MapsIndex].LinearAddress + MapEntrys- > >Maps[MapsIndex].Length) > PreviousAddress)) > + { > + // > + // MapEntrys->Maps[MapsIndex] contains not-present range=20 > + in > exsiting page table. > + // > + IsNotPresent =3D TRUE; > + break; > + } > + > + PreviousAddress =3D Map[Index].LinearAddress + Map[Index].Leng= th; > + } > + } > + } else { > + IsNotPresent =3D TRUE; > + } > + } >=20 > PageTableBufferSize =3D 0; > Status =3D PageTableMap ( > @@ -638,6 +700,25 @@ SingleMapEntryTest ( > &MapEntrys->Maps[MapsIndex].Attribute, > &MapEntrys->Maps[MapsIndex].Mask > ); > + > + // > + // Return Status should be InvalidParameter when: > + // 1. MapEntrys->Maps[MapsIndex] contains not-present range. > + // 2. MapEntrys->Maps[MapsIndex].Mask contains zero value field or > Attribute->Bits.Present is 0. > + // > + Attribute =3D &MapEntrys->Maps[MapsIndex].Attribute; > + Mask =3D &MapEntrys->Maps[MapsIndex].Mask; > + if (((Attribute->Bits.Present =3D=3D 0) || (Mask->Bits.Present =3D=3D = 0) ||=20 > + (Mask- > >Bits.ReadWrite =3D=3D 0) || > + (Mask->Bits.UserSupervisor =3D=3D 0) || (Mask->Bits.WriteThrough= =20 > + =3D=3D 0) || > (Mask->Bits.CacheDisabled =3D=3D 0) || > + (Mask->Bits.Accessed =3D=3D 0) || (Mask->Bits.Dirty =3D=3D 0) ||= =20 > + (Mask- > >Bits.Pat =3D=3D 0) || (Mask->Bits.Global =3D=3D 0) || > + (Mask->Bits.PageTableBaseAddress =3D=3D 0) ||=20 > + (Mask->Bits.ProtectionKey > =3D=3D 0) || (Mask->Bits.Nx =3D=3D 0)) && > + IsNotPresent) > + { > + RemoveLastMapEntry (MapEntrys); > + UT_ASSERT_EQUAL (Status, RETURN_INVALID_PARAMETER); > + return UNIT_TEST_PASSED; > + } > + > if (PageTableBufferSize !=3D 0) { > UT_ASSERT_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); >=20 > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c > b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c > index 5bd70c0f65..11f7e607ca 100644 > --- a/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c > +++ b/UefiCpuPkg/Library/CpuPageTableLib/UnitTest/TestHelper.c > @@ -171,6 +171,10 @@ IsPageTableValid ( > UNIT_TEST_STATUS Status; > IA32_PAGING_ENTRY *PagingEntry; >=20 > + if (PageTable =3D=3D 0) { > + return UNIT_TEST_PASSED; > + } > + > if ((PagingMode =3D=3D Paging32bit) || (PagingMode =3D=3D PagingPae) |= |=20 > (PagingMode >=3D PagingModeMax)) { > // > // 32bit paging is never supported. > -- > 2.31.1.windows.1