From: "Kun Qin" <kuqin12@gmail.com>
To: "Wu, Hao A" <hao.a.wu@intel.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
"Liu, Zhiguang" <zhiguang.liu@intel.com>,
Andrew Fish <afish@apple.com>, Laszlo Ersek <lersek@redhat.com>,
Leif Lindholm <leif@nuviainc.com>
Subject: Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update
Date: Tue, 15 Jun 2021 13:51:11 -0700 [thread overview]
Message-ID: <ad9d6481-c551-41e0-4bbe-5bb93fa6ba5a@gmail.com> (raw)
In-Reply-To: <BN8PR11MB366691A1E14B56BF21A1BC20CA349@BN8PR11MB3666.namprd11.prod.outlook.com>
Hi Hao,
Sorry that I missed comments for this patch earlier. You are correct. I
only inspected SmmLockBoxPeiLib. The PEI instance handled mode switch
with ```OFFSET_OF ``` function. But DXE instance still have a few use
cases that will be impacted.
I will update this read me file and add a code change patch for this
library in v2. Thanks for pointing this out.
Regards,
Kun
On 06/11/2021 00:46, Wu, Hao A wrote:
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
>> Sent: Thursday, June 10, 2021 9:43 AM
>> To: devel@edk2.groups.io
>> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Liming Gao
>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
>> Andrew Fish <afish@apple.com>; Laszlo Ersek <lersek@redhat.com>; Leif
>> Lindholm <leif@nuviainc.com>
>> Subject: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification:
>> EFI_MM_COMMUNICATE_HEADER Update
>>
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3430
>>
>> This change includes specification update markdown file that describes the
>> proposed PI Specification v1.7 Errata A in detail and potential impact to the
>> existing codebase.
>>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
>> Cc: Andrew Fish <afish@apple.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Leif Lindholm <leif@nuviainc.com>
>>
>> Signed-off-by: Kun Qin <kuqin12@gmail.com>
>> ---
>> BZ3430-SpecChange.md | 88 ++++++++++++++++++++
>> 1 file changed, 88 insertions(+)
>>
>> diff --git a/BZ3430-SpecChange.md b/BZ3430-SpecChange.md new file mode
>> 100644 index 000000000000..33a1ffda447b
>> --- /dev/null
>> +++ b/BZ3430-SpecChange.md
>> @@ -0,0 +1,88 @@
>> +# Title: Change MessageLength Field of EFI_MM_COMMUNICATE_HEADER
>> to
>> +UINT64
>> +
>> +## Status: Draft
>> +
>> +## Document: UEFI Platform Initialization Specification Version 1.7
>> +Errata A
>> +
>> +## License
>> +
>> +SPDX-License-Identifier: CC-BY-4.0
>> +
>> +## Submitter: [TianoCore Community](https://www.tianocore.org)
>> +
>> +## Summary of the change
>> +
>> +Change the `MessageLength` Field of `EFI_MM_COMMUNICATE_HEADER`
>> from UINTN to UINT64 to remove architecture dependency:
>> +
>> +```c
>> +typedef struct {
>> + EFI_GUID HeaderGuid;
>> + UINT64 MessageLength;
>> + UINT8 Data[ANYSIZE_ARRAY];
>> +} EFI_MM_COMMUNICATE_HEADER;
>> +```
>> +
>> +## Benefits of the change
>> +
>> +In PI Spec v1.7 Errata A, Vol.4, Sec 5.7 MM Communication Protocol, the
>> MessageLength field of `EFI_MM_COMMUNICATE_HEADER` (also defined as
>> `EFI_SMM_COMMUNICATE_HEADER`) is defined as type UINTN.
>> +
>> +But this structure, as a generic definition, could be used for both PEI and
>> DXE MM communication. Thus for a system that supports PEI MM launch,
>> but operates PEI in 32bit mode and MM foundation in 64bit, the current
>> `EFI_MM_COMMUNICATE_HEADER` definition will cause structure parse
>> error due to UINTN used.
>> +
>> +## Impact of the change
>> +
>> +This change will impact the known structure consumers including:
>> +
>> +```bash
>> +MdeModulePkg/Core/PiSmmCore/PiSmmIpl
>> +MdeModulePkg/Application/SmiHandlerProfileInfo
>> +MdeModulePkg/Application/MemoryProfileInfo
>> +```
>> +
>> +For consumers that are not using
>> `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)`, but performing
>> explicit addition such as the existing
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c,
>> one will need to change code implementation to match new structure
>> definition. Otherwise, the code compiled on IA32 architecture will
>> experience structure field dereference error.
>> +
>> +User who currently uses UINTN local variables as place holder of
>> MessageLength will need to use caution to make cast from UINTN to UINT64
>> and vice versa. It is recommended to use `SafeUint64ToUintn` for such
>> operations when the value is indeterministic.
>> +
>> +Note: MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib is also
>> consuming this structure, but it handled this size discrepancy internally. If this
>
>
> Hello Kun,
>
> Sorry for a question.
> I am not sure why the current codes in file SmmLockBoxDxeLib.c will work properly after the UINTN -> UINT64 change.
>
> For example:
> LockBoxGetSmmCommBuffer():
> MinimalSizeNeeded = sizeof (EFI_GUID) +
> sizeof (UINTN) +
> MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE),
> MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES),
> MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE),
> MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE),
> sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)))));
>
> SaveLockBox():
> UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];
>
> Is the series missed changes for SmmLockBoxDxeLib or I got something wrong?
>
> Best Regards,
> Hao Wu
>
>
>> potential spec change is not applied, all applicable PEI MM communicate
>> callers will need to use the same routine as that of SmmLockBoxPeiLib to
>> invoke a properly populated EFI_MM_COMMUNICATE_HEADER to be used
>> in X64 MM foundation.
>> +
>> +## Detailed description of the change [normative updates]
>> +
>> +### Specification Changes
>> +
>> +1. In PI Specification v1.7 Errata A: Vol. 4 Page-91, the definition of
>> `EFI_MM_COMMUNICATE_HEADER` should be changed from current:
>> +
>> +```c
>> +typedef struct {
>> + EFI_GUID HeaderGuid;
>> + UINTN MessageLength;
>> + UINT8 Data[ANYSIZE_ARRAY];
>> +} EFI_MM_COMMUNICATE_HEADER;
>> +```
>> +
>> +to:
>> +
>> +```c
>> +typedef struct {
>> + EFI_GUID HeaderGuid;
>> + UINT64 MessageLength;
>> + UINT8 Data[ANYSIZE_ARRAY];
>> +} EFI_MM_COMMUNICATE_HEADER;
>> +```
>> +
>> +### Code Changes
>> +
>> +1. Remove the explicit calculation of the offset of `Data` in
>> `EFI_MM_COMMUNICATE_HEADER`. Thus applicable calculations of
>> `sizeof(EFI_GUID) + sizeof(UINTN)` should be replaced with
>> `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)` or similar
>> alternatives. These calculations are identified in:
>> +
>> +```bash
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.
>> c
>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
>> +```
>> +
>> +1. Resolve potentially mismatched type between `UINTN` and `UINT64`.
>> This would occur when `MessageLength` or its derivitive are used for local
>> calculation with existing `UINTN` typed variables. Code change regarding this
>> perspective is per case evaluation: if the variables involved are all
>> deterministic values, and there is no overflow or underflow risk, a cast
>> operation (from `UINTN` to `UINT64`) can be safely used. Otherwise, the
>> calculation will be performed in `UINT64` bitwidth and then convert to
>> `UINTN` using `SafeUint64*` and `SafeUint64ToUintn`, respectively. These
>> operations are identified in:
>> +
>> +```bash
>> +MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.
>> c
>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
>> +```
>> +
>> +1. After all above changes applied and specification updated,
>> `MdePkg/Include/Protocol/MmCommunication.h` will need to be updated to
>> match new definition that includes the field type update.
>> --
>> 2.31.1.windows.1
>>
>>
>>
>>
>>
>
next prev parent reply other threads:[~2021-06-15 20:51 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 [this message]
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
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=ad9d6481-c551-41e0-4bbe-5bb93fa6ba5a@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