public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Kun Qin" <kuqin12@gmail.com>
To: "Wu, Hao A" <hao.a.wu@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>
Subject: Re: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation
Date: Fri, 11 Jun 2021 14:29:48 -0700	[thread overview]
Message-ID: <dec9ac57-eb9a-07ac-951f-191a5ac24c5f@gmail.com> (raw)
In-Reply-To: <BN8PR11MB36660372B4EB87EF3C4CE1F8CA349@BN8PR11MB3666.namprd11.prod.outlook.com>

Hi Hao,

Thanks for pointing out the missing place. Will update this accordingly.

This patch series needs a PI spec update, I thought I should mark all 
changes with BZ#### before the spec update is taken. But I can drop them 
for the next patch version.

Regards,
Kun

On 06/11/2021 00:46, Wu, Hao A wrote:
>> -----Original Message-----
>> From: Kun Qin <kuqin12@gmail.com>
>> Sent: Thursday, June 10, 2021 9:43 AM
>> To: devel@edk2.groups.io
>> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>
>> Subject: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated
>> MessageLength calculation
>>
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398
>>
>> 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.
> 
> 
> I think there is one missing place in function GetSmramProfileData():
> 
>    MinimalSizeNeeded = 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_STATE)));
> 
> More inline comments below:
> 
> 
>>
>> Cc: Jian J Wang <jian.j.wang@intel.com>
>> Cc: Hao A Wu <hao.a.wu@intel.com>
>>
>> Signed-off-by: Kun Qin <kuqin12@gmail.com>
>> ---
>>   MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 20
>> +++++++++++++++-----
>>   1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> 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 = (UINT64)-1;
>>     CommRecordingState->RecordingState      =
>> MEMORY_PROFILE_RECORDING_DISABLE;
>>
>> -  CommSize = 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 = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) +
>> + (UINTN)CommHeader->MessageLength;
>>     Status = 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 = (UINT64)-1;
>>       CommRecordingState->RecordingState      =
>> MEMORY_PROFILE_RECORDING_DISABLE;
>>
>> -    CommSize = 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 = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) +
>> + (UINTN)CommHeader->MessageLength;
>>       SmmCommunication->Communicate (SmmCommunication, CommBuffer,
>> &CommSize);
>>     }
>>
>> @@ -1230,7 +1234,9 @@ GetSmramProfileData (
>>     CommGetProfileInfo->Header.ReturnStatus = (UINT64)-1;
>>     CommGetProfileInfo->ProfileSize         = 0;
>>
>> -  CommSize = 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 = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) +
>> + (UINTN)CommHeader->MessageLength;
>>     Status = SmmCommunication->Communicate (SmmCommunication,
>> CommBuffer, &CommSize);
>>     ASSERT_EFI_ERROR (Status);
>>
>> @@ -1261,7 +1267,9 @@ GetSmramProfileData (
>>     CommGetProfileData->Header.DataLength   = sizeof
>> (*CommGetProfileData);
>>     CommGetProfileData->Header.ReturnStatus = (UINT64)-1;
>>
>> -  CommSize = 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 = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) +
>> + (UINTN)CommHeader->MessageLength;
>>     Buffer = (UINT8 *) CommHeader + CommSize;
>>     Size -= CommSize;
>>
>> @@ -1320,7 +1328,9 @@ GetSmramProfileData (
>>       CommRecordingState->Header.ReturnStatus = (UINT64)-1;
>>       CommRecordingState->RecordingState      =
>> MEMORY_PROFILE_RECORDING_ENABLE;
>>
>> -    CommSize = 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 = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) +
>> + (UINTN)CommHeader->MessageLength;
>>       SmmCommunication->Communicate (SmmCommunication, CommBuffer,
>> &CommSize);
>>     }
>>
>> --
>> 2.31.1.windows.1
> 

  reply	other threads:[~2021-06-11 21:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10  1:42 [PATCH v1 0/5] EDK2 Code First: PI Specification: Update EFI_MM_COMMUNICATE_HEADER Kun Qin
2021-06-10  1:42 ` [PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update Kun Qin
2021-06-11  7:46   ` [edk2-devel] " Wu, Hao A
2021-06-15 20:51     ` Kun Qin
2021-06-16  1:15       ` Wu, Hao A
2021-06-24  0:53         ` Kun Qin
2021-06-24  3:26           ` [EXTERNAL] " Bret Barkelew
2021-06-28  6:18             ` Wu, Hao A
2021-06-10  1:42 ` [PATCH v1 2/5] MdeModulePkg: PiSmmIpl: Update MessageLength calculation for MmCommunicate Kun Qin
2021-06-11  7:46   ` Wu, Hao A
2021-06-10  1:42 ` [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Kun Qin
2021-06-11  7:46   ` Wu, Hao A
2021-06-11 21:29     ` Kun Qin [this message]
2021-06-14 23:20       ` [edk2-devel] " Wu, Hao A
2021-06-10  1:42 ` [PATCH v1 4/5] MdeModulePkg: SmiHandlerProfileInfo: " Kun Qin
2021-06-11  7:47   ` Wu, Hao A
2021-06-10  1:42 ` [PATCH v1 5/5] MdePkg: MmCommunication: Extend MessageLength field size to UINT64 Kun Qin
2021-06-16  7:02 ` [edk2-devel] [PATCH v1 0/5] EDK2 Code First: PI Specification: Update EFI_MM_COMMUNICATE_HEADER Marvin Häuser
2021-06-16 20:58   ` Kun Qin
2021-06-18  9:37     ` Marvin Häuser
2021-06-22 15:34       ` Laszlo Ersek
2021-06-23  6:54         ` Marvin Häuser
2021-06-23 15:26           ` Laszlo Ersek
2021-06-24  0:24             ` Kun Qin
2021-06-24  8:00               ` Marvin Häuser
2021-06-24 15:25                 ` Michael D Kinney
2021-06-25 18:47                   ` Kun Qin
2021-06-28 14:57                     ` Laszlo Ersek
2021-06-28 15:43                       ` Marvin Häuser
2021-06-29  6:49                         ` [EXTERNAL] " Bret Barkelew
2021-06-29  8:58                           ` Marvin Häuser
2021-06-29 15:59                             ` Bret Barkelew
2021-06-29 17:28                               ` Michael D Kinney
2021-06-29 23:10                                 ` Kun Qin
2021-06-30  1:07                                   ` Michael D Kinney
2021-06-30  7:56                                     ` Kun Qin
2021-06-29 17:22                         ` Michael D Kinney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dec9ac57-eb9a-07ac-951f-191a5ac24c5f@gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox