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.web08.5598.1623397629156862269 for ; Fri, 11 Jun 2021 00:47:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=ysKf97kH; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: hao.a.wu@intel.com) IronPort-SDR: 9qZz+RNM/XFajXJGg/GI7hbHXbczH757XvjrMkfdiPycJjI5V/c24ZORegkR3Wg6lPmMXethKO t/ImAZfppGoA== X-IronPort-AV: E=McAfee;i="6200,9189,10011"; a="205510368" X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="205510368" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2021 00:47:07 -0700 IronPort-SDR: AY3yavAd0BtH2IniQgmIjX/gyWOAfceq1RPXTZ40oLZ5xJ+5rbtqoPogL32dPMuYaTiBo549u7 kN+O6Lo25IHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="620316240" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga005.jf.intel.com with ESMTP; 11 Jun 2021 00:47:07 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Fri, 11 Jun 2021 00:47:07 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Fri, 11 Jun 2021 00:47:06 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Fri, 11 Jun 2021 00:47:06 -0700 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (104.47.73.49) 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.2242.4; Fri, 11 Jun 2021 00:47:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mT9vpCdrjLGpdKnnU+z6+QbOlAoYpQoJKhI77T7qZpL/kXKbTlWj4AKmKNmo9/blVodTbw1v6Qqh2qq1AvQeOTw3/NAyB+0botumF24TCSUxvzrjufmfhRS9EKSleUdhPxh6XjTlpY9sfDmr42TXG86jVSE1jdiasjJHfHnidCve+g0MdkmYR5aiUtfg8rsMunAURZtqOFfOUf8QppnJq+Ab0tiR2IGieyg9PeeGjc4c7VX2eB0796fBmAtCppr5ErPlBqu8mg+IOPVN4aNY0oSkoOS9cvmBVHDbdexOlwd6gY2m5M4Q+bFWFAXoYvHRBULZF0h7nQKHo0lqH3TUBA== 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-SenderADCheck; bh=znGmgamp0kk+8tMwEHPQ8gDxW7VCAbiBE9C8GJEWO5E=; b=m3FG6Lswvuf3FTn9HgtoOe6nFJ0trk0SVuyef4bu9i6gJyGojs8JBSR+8Z6ocKUzBNYAmq/q43kcGjUjgfQq/j8+tPMrKjQnawopHM8e7cmHWnJ5YnuDSFVf3JU/KAx4raNGGJjejCWQ0oxLdAIo3EEot63tBbCMf1jhhxM+4A8cPQ3Dq9Y6OTaYvKmVTbd54KUmgFi3GmxItGfjeQHvR1J1TWX/FUlvy8VJM/mFKh7kwKB8f5469nOcYnizNhYubalYR7JbDHbZrS1EzjY8KKMqNh/YlCA0BBlClrXG8gBJb88wFnXmt4+++P/7zLi+5IgaEjAIO1/g7INDJ+ifxQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=znGmgamp0kk+8tMwEHPQ8gDxW7VCAbiBE9C8GJEWO5E=; b=ysKf97kHFZQzurM+UOz5+kwb8gDj3XcXmVQSoNrL02MfsRd0zZV4ESVlE3relEGF1bxEvlmEHlbJZUPwZ/riVkrMiPZBa8OnxGTMByCqPAF0Q3UXkKBDxKru2f/u4ryv6U9PoTy1lLaefBrZHsoKn6200osoUmQO5/jlQgUkkCQ= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR1101MB2161.namprd11.prod.outlook.com (2603:10b6:405:52::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.26; Fri, 11 Jun 2021 07:46:58 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::b9d0:5694:1b70:c031]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::b9d0:5694:1b70:c031%4]) with mapi id 15.20.4195.032; Fri, 11 Jun 2021 07:46:57 +0000 From: "Wu, Hao A" To: Kun Qin , "devel@edk2.groups.io" CC: "Wang, Jian J" Subject: Re: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Thread-Topic: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Thread-Index: AQHXXZoHHIsZJBMAoU6T5rwGSrxpv6sOamaw Date: Fri, 11 Jun 2021 07:46:57 +0000 Message-ID: References: <20210610014259.1151-1-kuqin12@gmail.com> <20210610014259.1151-4-kuqin12@gmail.com> In-Reply-To: <20210610014259.1151-4-kuqin12@gmail.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.143.16] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 57bd9ba2-ba0a-4e02-c12d-08d92cad1734 x-ms-traffictypediagnostic: BN6PR1101MB2161: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wRay6ekK7MtVWwBfBX6gEYM+fajWbKzpeAY0Wfne5eubGrbYc+Xenf1iO/HkuKHutBb5k6IXLGccrLO8F9wj6y6mZeK7jU5z3aRqiKSZU/+nV/TJa9jEGfwTGzEvLsXp4za+NI8PqsGSjuT6RyJkEJTU1HV4UZffbhsriNn8s9dEp6qkMD/NkQslpumn1GHZXSYLVohNsaF8sqSJdGWsdjyDEiJH/dBcypU1YfKS56TbmrexE47YpLCA4XXSaJrv0PNcAQg9jnR+4yix1MKqdT2/Xkb11jv68Q4wnaLyZJbRudTIspesigkqn/Ru8R8GP9s0JXtNDN7/kqegp0v+K/BkB1z6KZHu8PqLc5pNWJRczcofYsW/wRiblboHNdWUWLBv60S3fXUXhgCtEjkwgWNj6GyR7xEQdQVKdZfgrt0mUaklVlTl3HJyYxeeeCnMgP4kmU8KqUG/M2WJf6KatZiiaMKW55H0AHeBSkg+wUUGzkgFfnvKHhtNqtG8K8grxxyLTqRhDaka2DiutcL53uMBuA5qYtiYMpcg/UUgdVQaLaWLwoyrqnc42IHHLvMz5NJW4ocXQM8IdvcXsTjfU/zK6yS0VhKRNO/AHVNAg/iN75Vu1xbdh3a0EaC8hJOSkz2Eyq6mg6+5Wz/k2/ODDchn6VGuLTQYMbN+jPo8uPJ4D6+TWprQG5GuFfoS7+ygFeO5WgD4R2HUrxyd6hb2IEnIWVwJMU1W9kpQTJjjVIw= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(366004)(376002)(136003)(396003)(39860400002)(52536014)(107886003)(66946007)(15650500001)(76116006)(86362001)(2906002)(110136005)(66446008)(4326008)(6506007)(316002)(66556008)(7696005)(38100700002)(8936002)(33656002)(478600001)(66476007)(64756008)(53546011)(966005)(8676002)(9686003)(55016002)(5660300002)(71200400001)(186003)(122000001)(83380400001)(26005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?QBXLIXgwSguuu9HRzHNSfq0j45aMhCf8KwqEnAD9TEbnl5b+8sE52kj8Cu8f?= =?us-ascii?Q?eSOdd6U9iJwgafmpPxFWmpC8AP0ogeuaTjTxB9uZe2B6zm34D6D6TxeNcauu?= =?us-ascii?Q?hA6uwJlGhScp/hE5swHKeNyZprGXuAxXzBfxCaS4Ix+wcL9nhVb6RiKwCF95?= =?us-ascii?Q?qFiEKpnkRA1eScEGT+ztSmshIGSqSZdLKSQNmYUrV0cGopN40IhRDi+ErPfV?= =?us-ascii?Q?lnm7pKxdvzV0cJIN+LKWL52zxXM6CNPQx6DhYZ84FEos5X3aQ4lhWpP9586R?= =?us-ascii?Q?bBhyAkcIsB+eCtv9vgFFjx2Z2Tkf6VrmEXqYwyLRlwMWuiPaLHfJBK44fgXJ?= =?us-ascii?Q?GN3FfhNgHyPAayRhTy/Ox+yHPULBCuykffP2FtB33zIAHg0DxrmSv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7Qu1n/XnHcnjdHomqC9wlgCRR+aNYYJNtAVOTfU8N?= =?us-ascii?Q?qETlady2QeU8txCrbLarX2st?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57bd9ba2-ba0a-4e02-c12d-08d92cad1734 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jun 2021 07:46:57.9583 (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: i4zO6UC6iv2E1WNC0kRe9WsyIf4dRf66TAKPsPKfFvJ0z8oj/JYSeapf9glxBF7GxcqQ9sIkTBJdTN0eUZTj/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2161 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Kun Qin > Sent: Thursday, June 10, 2021 9:43 AM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A > Subject: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated > MessageLength calculation >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 >=20 > This change replaced the calculation of communication buffer size from > explicitly adding the size of each member with the OFFSET macro function. > This will make the structure field defition change transparent to consume= rs. I think there is one missing place in function GetSmramProfileData(): MinimalSizeNeeded =3D sizeof (EFI_GUID) + sizeof (UINTN) + MAX (sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO= ), MAX (sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE= _DATA_BY_OFFSET), sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_S= TATE))); More inline comments below: >=20 > Cc: Jian J Wang > Cc: Hao A Wu >=20 > Signed-off-by: Kun Qin > --- > MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 20 > +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) >=20 > diff --git > a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > index 191c31068545..39ed8b2e0484 100644 > --- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > +++ > b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > @@ -1190,7 +1190,9 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_DISABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // BZ3398: Make MessageLength the same size in > EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. > + // The CommHeader->MessageLength contains a definitive value, thus > UINTN cast is safe here. Please help to drop the explicit mention of BZ3398 in the comment. How about using: // // The CommHeader->MessageLength contains a definitive value, thus UINTN = cast is safe here. // There are 4 more similar cases below. Best Regards, Hao Wu > + CommSize =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + > + (UINTN)CommHeader->MessageLength; > Status =3D SmmCommunication->Communicate (SmmCommunication, > CommBuffer, &CommSize); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "SmramProfile: SmmCommunication - %r\n", > Status)); @@ -1213,7 +1215,9 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_DISABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // BZ3398: Make MessageLength the same size in > EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. > + // The CommHeader->MessageLength contains a definitive value, thus > UINTN cast is safe here. > + CommSize =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + > + (UINTN)CommHeader->MessageLength; > SmmCommunication->Communicate (SmmCommunication, CommBuffer, > &CommSize); > } >=20 > @@ -1230,7 +1234,9 @@ GetSmramProfileData ( > CommGetProfileInfo->Header.ReturnStatus =3D (UINT64)-1; > CommGetProfileInfo->ProfileSize =3D 0; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // BZ3398: Make MessageLength the same size in > EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. > + // The CommHeader->MessageLength contains a definitive value, thus > UINTN cast is safe here. > + CommSize =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + > + (UINTN)CommHeader->MessageLength; > Status =3D SmmCommunication->Communicate (SmmCommunication, > CommBuffer, &CommSize); > ASSERT_EFI_ERROR (Status); >=20 > @@ -1261,7 +1267,9 @@ GetSmramProfileData ( > CommGetProfileData->Header.DataLength =3D sizeof > (*CommGetProfileData); > CommGetProfileData->Header.ReturnStatus =3D (UINT64)-1; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // BZ3398: Make MessageLength the same size in > EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. > + // The CommHeader->MessageLength contains a definitive value, thus > UINTN cast is safe here. > + CommSize =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + > + (UINTN)CommHeader->MessageLength; > Buffer =3D (UINT8 *) CommHeader + CommSize; > Size -=3D CommSize; >=20 > @@ -1320,7 +1328,9 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_ENABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // BZ3398: Make MessageLength the same size in > EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. > + // The CommHeader->MessageLength contains a definitive value, thus > UINTN cast is safe here. > + CommSize =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + > + (UINTN)CommHeader->MessageLength; > SmmCommunication->Communicate (SmmCommunication, CommBuffer, > &CommSize); > } >=20 > -- > 2.31.1.windows.1