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.web09.1635.1624412002204095704 for ; Tue, 22 Jun 2021 18:33:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=U2bjr/xc; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: hao.a.wu@intel.com) IronPort-SDR: ZxwTczEKyPcEWPJHp26rIaQzj+n0CIgNyfH9cLwywljo57yWhvV2hRBQ5CBZNDa8laFI6xCbkj DLLzEvPQEcGQ== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="207113118" X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="207113118" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 18:33:20 -0700 IronPort-SDR: OR7NPRDtZ3hIEeao1i7qnvtJhpGI8HyYqZZ1f8C/nhRMoTwUYbsB6CBVz3flhx3KI2wEHmWAl7 /1D/L0YP2dkg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="556805575" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga001.fm.intel.com with ESMTP; 22 Jun 2021 18:33:20 -0700 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) 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.2242.4; Tue, 22 Jun 2021 18:33:19 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Tue, 22 Jun 2021 18:33:19 -0700 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (104.47.73.44) 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.2242.4; Tue, 22 Jun 2021 18:33:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W1p8bRTsYpkYsbsJ/zQ4CVcdqK78yL9Ly3IGKXU4bgDui9lY04Q7vaPrnaVVQkqT1J+uZmtzcJcDjo83TucNVC7ZhO7Z0W+w1jCioMWKUS046wT/xEZqbe2ThIVCFNF8/I3xFdkfuHVQJxZTyovsrL6Nj++aC39Kt1rEHxamHj+7eeJFMjwxvcbS81XJRXrCT4YQogbKZn+/z3Mja4WEv6QWja77xjpOJmidSMawqltRb2oZSSzTuEJ54fHSDq1DIRgOSvwxtOKHo8VTdeYtxGWPEBa1wDtloXyzUIO4mUfOQpv0Od/Pk8r1fh0qRZ6uMC/J64lJjrsbfVdhouQJ1Q== 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=+25BNfH5yjmvLMP3T3/0VWA5WPHU+hTlSBj0E6zNwl4=; b=bBX9XI++XEygdI42cZtteMB7av1ChTmBKY3dSNHPPaWcrm4/YdtLJuExyiV2sh2y5sfbtJvL/dzvEToRhKNyZjbZ7OOHMjxGMKtywekjQd4BzxdqOXUOGxoFanvNbAFgUVSbdfiyN2lfBnNvXaJwHa69HeettxFDJ4j1Y73tnxgK5r71dy5Co7eTKVbGiY2nYb71Z3A3ZdQ4pLnMGzCwmjA+AvJoYMnTG6UAd02YWIFcNY39Ya9vf9oX1glQRJHBbmxWeeL5nXpxtaQ7EILWLej2fYQauRYzLyC3CKvjmEyxW8Ix7wxCMD1MEVpIOLQ6sLzMyBBw07xhh1fWO7YEFQ== 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=+25BNfH5yjmvLMP3T3/0VWA5WPHU+hTlSBj0E6zNwl4=; b=U2bjr/xcdVJIUEFYZSCsqpXtLWpNyMmsiqNcCgfhFfAL2+hWNQnRFEql+1tElGWg8NlxjpTPopfV37i8u+d0ZiAYD0AQt0pHq1R/gQC9iJ/if368KNPbkWz7Nb+Yu0KCBa0XFNizDK9FYLoIQ132VanICxzWqqEmcZ1JCzzNt6A= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB2033.namprd11.prod.outlook.com (2603:10b6:404:47::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.23; Wed, 23 Jun 2021 01:33:18 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::cd58:25ce:5017:619d]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::cd58:25ce:5017:619d%5]) with mapi id 15.20.4242.024; Wed, 23 Jun 2021 01:33:17 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "kuqin12@gmail.com" CC: "Wang, Jian J" Subject: Re: [edk2-devel] [PATCH v2 3/6] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Thread-Topic: [edk2-devel] [PATCH v2 3/6] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Thread-Index: AQHXZCDEYc54KK5ZcUeB/7lYUh2NmKsg0eng Date: Wed, 23 Jun 2021 01:33:17 +0000 Message-ID: References: <20210618090243.2517-1-kuqin12@gmail.com> <20210618090243.2517-4-kuqin12@gmail.com> In-Reply-To: <20210618090243.2517-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: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.142.16] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7755cfdd-4c84-459b-c96a-08d935e6e08a x-ms-traffictypediagnostic: BN6PR11MB2033: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: unfzbgtDzn66IRYAGVkUpkeAtuUtXAkI9PPIZYAvGxkLrZb2LF4fxp9yZbVlyeVZQNJKOkKCWIZb2TVbzXjaISCAnT7tda24KHkST6KxqJHV3M//OlxAu1pvuMjaL/4cQ621tVnjvjOL+E+uiWZdBKoNLLTOMsD3l34ayxdz9H8Odun/O+XhtLVD7A4LnFX1B4/sQbELN+gkO32bj6EDI5y/gb5z6nyM21KDAgBlSWLsviE7HJGLGqw+5WJ8cyufANaDuQ9N5BDDpfO229UMMQsfp2XqPYnBrLaRlRODv5ukvQ2asf2WnubJPsKDXHUGBTmiYJJnKASGEB9RLN/ycXZUiL5uCpZSC4mOeA8lWr3xnFRxt8BFah3QpcRmZjizKUFanltmqorc/CKUgK+OGA6bojyn7sxlLhhGrPkNsANrIeC1K7dhpljCCcvRQ+NPzujhGEIOriFF0DRYDE5l5drJcv6wPWd+fdti88IF/6FrrD2sNYExpQodLa8fmBSBUNSrf5Q3D89Nld0Ja9NuiB6jUrmhjj1+V3KyqjP21IPZHgUsPf/GcwK4BxB1KBBoVBjnhS4AXS4gpBEbFTjgK6g0TONHje8ygSwBf/XYcn1Anh8OBK0mylpdzXIpYFAkntEiUzeHpTr/fPmmyug0gqeqcwTzkgCxtS+4SggpKs18Cd/RoEAMB6rUEXwgJcyz3RpRdPsJ1Gs4tSvE3UPGfm6/XMogV3SXEn0lLB8PEi4ZH0x7O2f2ug5WAE1TLAjM8dF7+mAV3tDjnyIgmhXiS9bhanbY82A8ktyjU39PTJyMiqdGwnvyqtmVv98Vmk7j 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:(376002)(39860400002)(346002)(366004)(396003)(136003)(8676002)(8936002)(38100700002)(83380400001)(107886003)(53546011)(55016002)(9686003)(186003)(966005)(2906002)(33656002)(26005)(122000001)(4326008)(478600001)(6506007)(316002)(66446008)(64756008)(66556008)(86362001)(7696005)(110136005)(71200400001)(15650500001)(66476007)(66946007)(76116006)(5660300002)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?WsfBrwUo44CQvop8U3X+JsJNUuLWwu1Ju4Cvr3uqJ8EK2nGdSyJkuloMUAZu?= =?us-ascii?Q?9PE09/3BfagPj0MARHg9l7pu+WOns2GeMuLkUQLsqFr4HHjChzAk282ONEC8?= =?us-ascii?Q?w5z5Kk6e/Fp53QveEKj73rioeEl5UMnS+P4b/p1dbbMenqmMVNcyRWmysrr2?= =?us-ascii?Q?Tw7fIB3BnuQyvcT3z01Bgmd22PjoyQ+vjDCIV+YH93pfF1mO4YutGTo7LQBK?= =?us-ascii?Q?ETDU/KDGZAAPV0WsRqbFe/Lf2w829Q176nZPEIZ6LfNu2pctUsC4ODQ3HQbc?= =?us-ascii?Q?wPn2Z0s54r/Zo17y68H9HSSmTMwWbOffX9KfdXculcuA1aypPi004+Sz+Y4A?= =?us-ascii?Q?HfuOsIVaHA8MYoDWjAXEvKRvG3TLzuEI1QWVA5tf/Oht2XF908JFFFa4NNBW?= =?us-ascii?Q?9nqiSG+aDKYn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+pvVXp?= =?us-ascii?Q?zIC3HgrauiZk4gJ2Q6e3SFYB?= 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: 7755cfdd-4c84-459b-c96a-08d935e6e08a X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2021 01:33:17.4468 (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: 001wj9bIMluCD/a41Gx0vvlkWU2FtXK069G83V+cx7QNJMAUU6ZMz1yyI9S/+XOoEKjlvqN1trRJpn5lt8Miuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB2033 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: devel@edk2.groups.io On Behalf Of Kun Qin > Sent: Friday, June 18, 2021 5:03 PM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A > Subject: [edk2-devel] [PATCH v2 3/6] 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 > consumers. >=20 > Cc: Jian J Wang > Cc: Hao A Wu >=20 > Signed-off-by: Kun Qin > --- >=20 > Notes: > v2: > - Added a missed case this change should cover [Hao] > - Removed "BZ" tags from comments [Hao] Reviewed-by: Hao A Wu Best Regards, Hao Wu >=20 > MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 28 > +++++++++++++++----- > 1 file changed, 21 insertions(+), 7 deletions(-) >=20 > diff --git > a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > index 191c31068545..69f78c090e7c 100644 > --- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > +++ > b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c > @@ -1140,8 +1140,7 @@ GetSmramProfileData ( > return Status; > } >=20 > - MinimalSizeNeeded =3D sizeof (EFI_GUID) + > - sizeof (UINTN) + > + MinimalSizeNeeded =3D OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, > Data) + > MAX (sizeof > (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO), > MAX (sizeof > (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET), > sizeof > (SMRAM_PROFILE_PARAMETER_RECORDING_STATE))); > @@ -1190,7 +1189,10 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_DISABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // > + // 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); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "SmramProfile: SmmCommunication - %r\n", > Status)); > @@ -1213,7 +1215,10 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_DISABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // > + // 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 +1235,10 @@ GetSmramProfileData ( > CommGetProfileInfo->Header.ReturnStatus =3D (UINT64)-1; > CommGetProfileInfo->ProfileSize =3D 0; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // > + // 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 +1269,10 @@ GetSmramProfileData ( > CommGetProfileData->Header.DataLength =3D sizeof > (*CommGetProfileData); > CommGetProfileData->Header.ReturnStatus =3D (UINT64)-1; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // > + // 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 +1331,10 @@ GetSmramProfileData ( > CommRecordingState->Header.ReturnStatus =3D (UINT64)-1; > CommRecordingState->RecordingState =3D > MEMORY_PROFILE_RECORDING_ENABLE; >=20 > - CommSize =3D sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader- > >MessageLength; > + // > + // 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 >=20 >=20 >=20 >=20 >=20