<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Yeah, the only other thought I had for moving forwards quickly (i.e. hackily) is to define a new GUID that just means “I use an updated header configuration” since the EFI_GUID field comes first and is a well-understood size.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I would prefer the “deprecate, break builds, fix code, move forward” approach.
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">- Bret<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:kuqin12=gmail.com@groups.io">Kun Qin via groups.io</a><br>
<b>Sent: </b>Wednesday, June 23, 2021 5:53 PM<br>
<b>To: </b><a href="mailto:hao.a.wu@intel.com">Wu, Hao A</a>; <a href="mailto:devel@edk2.groups.io">
devel@edk2.groups.io</a><br>
<b>Cc: </b><a href="mailto:michael.d.kinney@intel.com">Kinney, Michael D</a>; <a href="mailto:gaoliming@byosoft.com.cn">
Liming Gao</a>; <a href="mailto:zhiguang.liu@intel.com">Liu, Zhiguang</a>; <a href="mailto:afish@apple.com">
Andrew Fish</a>; <a href="mailto:lersek@redhat.com">Laszlo Ersek</a>; <a href="mailto:leif@nuviainc.com">
Lindholm, Leif</a>; <a href="mailto:Bret.Barkelew@microsoft.com">Bret Barkelew</a>;
<a href="mailto:Michael.Kubacki@microsoft.com">Michael Kubacki</a><br>
<b>Subject: </b>[EXTERNAL] Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi Hao,<br>
<br>
We have been circulating different ideas internally about how to enforce <br>
a warning around this change.<br>
<br>
There is an idea of deprecating the old structure and replacing it with <br>
a newly defined EFI_MM_COMMUNICATE_HEADER_V2. That way all consumers <br>
will be enforced to update their implementation and (hopefully) inspect <br>
the compatibility accordingly. In addition, we could add other fields <br>
such as signature and/or header version number for further extensibility.<br>
<br>
If there are code instances that uses "sizeof(EFI_GUID) + sizeof(UINTN)" <br>
in lieu of OFFSET_OF, this implementation is essentially decoupled from <br>
the structure definition. So compiler might not be able to help. In that <br>
case, runtime protections such as pool guard or stack guard might be useful.<br>
<br>
Please let me know if you think header structure V2 is an idea worth to try.<br>
<br>
Thanks,<br>
Kun<br>
<br>
On 06/15/2021 18:15, Wu, Hao A wrote:<br>
> Thanks Kun,<br>
> <br>
> I am a little concerned on whether there will be other missing cases that are not covered by this patch series.<br>
> <br>
> I am also wondering is there any detection can be made to warn the cases that code modification should be made after this structure update.<br>
> Otherwise, it will be the burden for the platform owners to review the platform codes following your guide mentioned in this patch.<br>
> <br>
> Hoping others can provide some inputs on this.<br>
> <br>
> Best Regards,<br>
> Hao Wu<br>
> <br>
>> -----Original Message-----<br>
>> From: Kun Qin <kuqin12@gmail.com><br>
>> Sent: Wednesday, June 16, 2021 4:51 AM<br>
>> To: Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io<br>
>> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Liming Gao<br>
>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;<br>
>> Andrew Fish <afish@apple.com>; Laszlo Ersek <lersek@redhat.com>; Leif<br>
>> Lindholm <leif@nuviainc.com><br>
>> Subject: Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification:<br>
>> EFI_MM_COMMUNICATE_HEADER Update<br>
>><br>
>> Hi Hao,<br>
>><br>
>> Sorry that I missed comments for this patch earlier. You are correct. I only<br>
>> inspected SmmLockBoxPeiLib. The PEI instance handled mode switch with<br>
>> ```OFFSET_OF ``` function. But DXE instance still have a few use cases that will<br>
>> be impacted.<br>
>><br>
>> I will update this read me file and add a code change patch for this library in<br>
>> v2. Thanks for pointing this out.<br>
>><br>
>> Regards,<br>
>> Kun<br>
>><br>
>> On 06/11/2021 00:46, Wu, Hao A wrote:<br>
>>>> -----Original Message-----<br>
>>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun<br>
>>>> Qin<br>
>>>> Sent: Thursday, June 10, 2021 9:43 AM<br>
>>>> To: devel@edk2.groups.io<br>
>>>> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Liming Gao<br>
>>>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;<br>
>>>> Andrew Fish <afish@apple.com>; Laszlo Ersek <lersek@redhat.com>; Leif<br>
>>>> Lindholm <leif@nuviainc.com><br>
>>>> Subject: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification:<br>
>>>> EFI_MM_COMMUNICATE_HEADER Update<br>
>>>><br>
>>>> REF: <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3430&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=483mG24s%2Bp0xSF90Wf%2Fmh2TN1atrIQa5mOrLyEPCTuE%3D&amp;reserved=0">
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3430&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=483mG24s%2Bp0xSF90Wf%2Fmh2TN1atrIQa5mOrLyEPCTuE%3D&amp;reserved=0</a><br>
>>>><br>
>>>> This change includes specification update markdown file that<br>
>>>> describes the proposed PI Specification v1.7 Errata A in detail and<br>
>>>> potential impact to the existing codebase.<br>
>>>><br>
>>>> Cc: Michael D Kinney <michael.d.kinney@intel.com><br>
>>>> Cc: Liming Gao <gaoliming@byosoft.com.cn><br>
>>>> Cc: Zhiguang Liu <zhiguang.liu@intel.com><br>
>>>> Cc: Andrew Fish <afish@apple.com><br>
>>>> Cc: Laszlo Ersek <lersek@redhat.com><br>
>>>> Cc: Leif Lindholm <leif@nuviainc.com><br>
>>>><br>
>>>> Signed-off-by: Kun Qin <kuqin12@gmail.com><br>
>>>> ---<br>
>>>>    BZ3430-SpecChange.md | 88 ++++++++++++++++++++<br>
>>>>    1 file changed, 88 insertions(+)<br>
>>>><br>
>>>> diff --git a/BZ3430-SpecChange.md b/BZ3430-SpecChange.md new file<br>
>>>> mode<br>
>>>> 100644 index 000000000000..33a1ffda447b<br>
>>>> --- /dev/null<br>
>>>> +++ b/BZ3430-SpecChange.md<br>
>>>> @@ -0,0 +1,88 @@<br>
>>>> +# Title: Change MessageLength Field of<br>
>> EFI_MM_COMMUNICATE_HEADER<br>
>>>> to<br>
>>>> +UINT64<br>
>>>> +<br>
>>>> +## Status: Draft<br>
>>>> +<br>
>>>> +## Document: UEFI Platform Initialization Specification Version 1.7<br>
>>>> +Errata A<br>
>>>> +<br>
>>>> +## License<br>
>>>> +<br>
>>>> +SPDX-License-Identifier: CC-BY-4.0<br>
>>>> +<br>
>>>> +## Submitter: [TianoCore Community](<a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.tianocore.org%2F&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=eRu4We7iSzuwrsS9MqIO2iqLxXHZ6CpUkInVpty554c%3D&amp;reserved=0">https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.tianocore.org%2F&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=eRu4We7iSzuwrsS9MqIO2iqLxXHZ6CpUkInVpty554c%3D&amp;reserved=0</a>)<br>
>>>> +<br>
>>>> +## Summary of the change<br>
>>>> +<br>
>>>> +Change the `MessageLength` Field of<br>
>> `EFI_MM_COMMUNICATE_HEADER`<br>
>>>> from UINTN to UINT64 to remove architecture dependency:<br>
>>>> +<br>
>>>> +```c<br>
>>>> +typedef struct {<br>
>>>> +  EFI_GUID  HeaderGuid;<br>
>>>> +  UINT64    MessageLength;<br>
>>>> +  UINT8     Data[ANYSIZE_ARRAY];<br>
>>>> +} EFI_MM_COMMUNICATE_HEADER;<br>
>>>> +```<br>
>>>> +<br>
>>>> +## Benefits of the change<br>
>>>> +<br>
>>>> +In PI Spec v1.7 Errata A, Vol.4, Sec 5.7 MM Communication Protocol,<br>
>>>> +the<br>
>>>> MessageLength field of `EFI_MM_COMMUNICATE_HEADER` (also<br>
>> defined as<br>
>>>> `EFI_SMM_COMMUNICATE_HEADER`) is defined as type UINTN.<br>
>>>> +<br>
>>>> +But this structure, as a generic definition, could be used for both<br>
>>>> +PEI and<br>
>>>> DXE MM communication. Thus for a system that supports PEI MM launch,<br>
>>>> but operates PEI in 32bit mode and MM foundation in 64bit, the<br>
>>>> current `EFI_MM_COMMUNICATE_HEADER` definition will cause<br>
>> structure<br>
>>>> parse error due to UINTN used.<br>
>>>> +<br>
>>>> +## Impact of the change<br>
>>>> +<br>
>>>> +This change will impact the known structure consumers including:<br>
>>>> +<br>
>>>> +```bash<br>
>>>> +MdeModulePkg/Core/PiSmmCore/PiSmmIpl<br>
>>>> +MdeModulePkg/Application/SmiHandlerProfileInfo<br>
>>>> +MdeModulePkg/Application/MemoryProfileInfo<br>
>>>> +```<br>
>>>> +<br>
>>>> +For consumers that are not using<br>
>>>> `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)`, but performing<br>
>> explicit<br>
>>>> addition such as the existing<br>
>>>><br>
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.<br>
>>>> c, one will need to change code implementation to match new structure<br>
>>>> definition. Otherwise, the code compiled on IA32 architecture will<br>
>>>> experience structure field dereference error.<br>
>>>> +<br>
>>>> +User who currently uses UINTN local variables as place holder of<br>
>>>> MessageLength will need to use caution to make cast from UINTN to<br>
>>>> UINT64 and vice versa. It is recommended to use `SafeUint64ToUintn`<br>
>>>> for such operations when the value is indeterministic.<br>
>>>> +<br>
>>>> +Note: MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib is<br>
>> also<br>
>>>> consuming this structure, but it handled this size discrepancy<br>
>>>> internally. If this<br>
>>><br>
>>><br>
>>> Hello Kun,<br>
>>><br>
>>> Sorry for a question.<br>
>>> I am not sure why the current codes in file SmmLockBoxDxeLib.c will work<br>
>> properly after the UINTN -> UINT64 change.<br>
>>><br>
>>> For example:<br>
>>> LockBoxGetSmmCommBuffer():<br>
>>>     MinimalSizeNeeded = sizeof (EFI_GUID) +<br>
>>>                         sizeof (UINTN) +<br>
>>>                         MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE),<br>
>>>                              MAX (sizeof<br>
>> (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES),<br>
>>>                                   MAX (sizeof<br>
>> (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE),<br>
>>>                                        MAX (sizeof<br>
>> (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE),<br>
>>>                                             sizeof<br>
>>> (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)))));<br>
>>><br>
>>> SaveLockBox():<br>
>>>     UINT8                           TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN)<br>
>> + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];<br>
>>><br>
>>> Is the series missed changes for SmmLockBoxDxeLib or I got something<br>
>> wrong?<br>
>>><br>
>>> Best Regards,<br>
>>> Hao Wu<br>
>>><br>
>>><br>
>>>> potential spec change is not applied, all applicable PEI MM<br>
>>>> communicate callers will need to use the same routine as that of<br>
>>>> SmmLockBoxPeiLib to invoke a properly populated<br>
>>>> EFI_MM_COMMUNICATE_HEADER to be used in X64 MM foundation.<br>
>>>> +<br>
>>>> +## Detailed description of the change [normative updates]<br>
>>>> +<br>
>>>> +### Specification Changes<br>
>>>> +<br>
>>>> +1. In PI Specification v1.7 Errata A: Vol. 4 Page-91, the definition<br>
>>>> +of<br>
>>>> `EFI_MM_COMMUNICATE_HEADER` should be changed from current:<br>
>>>> +<br>
>>>> +```c<br>
>>>> +typedef struct {<br>
>>>> +  EFI_GUID  HeaderGuid;<br>
>>>> +  UINTN     MessageLength;<br>
>>>> +  UINT8     Data[ANYSIZE_ARRAY];<br>
>>>> +} EFI_MM_COMMUNICATE_HEADER;<br>
>>>> +```<br>
>>>> +<br>
>>>> +to:<br>
>>>> +<br>
>>>> +```c<br>
>>>> +typedef struct {<br>
>>>> +  EFI_GUID  HeaderGuid;<br>
>>>> +  UINT64    MessageLength;<br>
>>>> +  UINT8     Data[ANYSIZE_ARRAY];<br>
>>>> +} EFI_MM_COMMUNICATE_HEADER;<br>
>>>> +```<br>
>>>> +<br>
>>>> +### Code Changes<br>
>>>> +<br>
>>>> +1. Remove the explicit calculation of the offset of `Data` in<br>
>>>> `EFI_MM_COMMUNICATE_HEADER`. Thus applicable calculations of<br>
>>>> `sizeof(EFI_GUID) + sizeof(UINTN)` should be replaced with<br>
>>>> `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)` or similar<br>
>> alternatives.<br>
>>>> These calculations are identified in:<br>
>>>> +<br>
>>>> +```bash<br>
>>>><br>
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.<br>
>>>> c<br>
>>>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c<br>
>>>> +```<br>
>>>> +<br>
>>>> +1. Resolve potentially mismatched type between `UINTN` and `UINT64`.<br>
>>>> This would occur when `MessageLength` or its derivitive are used for<br>
>>>> local calculation with existing `UINTN` typed variables. Code change<br>
>>>> regarding this perspective is per case evaluation: if the variables<br>
>>>> involved are all deterministic values, and there is no overflow or<br>
>>>> underflow risk, a cast operation (from `UINTN` to `UINT64`) can be<br>
>>>> safely used. Otherwise, the calculation will be performed in `UINT64`<br>
>>>> bitwidth and then convert to `UINTN` using `SafeUint64*` and<br>
>>>> `SafeUint64ToUintn`, respectively. These operations are identified in:<br>
>>>> +<br>
>>>> +```bash<br>
>>>> +MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c<br>
>>>><br>
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.<br>
>>>> c<br>
>>>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c<br>
>>>> +```<br>
>>>> +<br>
>>>> +1. After all above changes applied and specification updated,<br>
>>>> `MdePkg/Include/Protocol/MmCommunication.h` will need to be<br>
>> updated<br>
>>>> to match new definition that includes the field type update.<br>
>>>> --<br>
>>>> 2.31.1.windows.1<br>
>>>><br>
>>>><br>
>>>><br>
>>>> <br>
>>>><br>
>>><br>
<br>
<br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/77034">View/Reply Online (#77034)</a> |    |  <a target="_blank" href="https://groups.io/mt/83753717/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>