From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outbound.mail.eo.outlook.com (outbound.mail.eo.outlook.com [40.93.3.9]) by mx.groups.io with SMTP id smtpd.web09.2401.1624505203584996515 for ; Wed, 23 Jun 2021 20:26:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=IqQ3IL/s; spf=pass (domain: microsoft.com, ip: 40.93.3.9, mailfrom: bret.barkelew@microsoft.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kppeZSumdxsjh378klwJj8fFMyOii/cKiUq7vzDboaIVOo+PBUouZjOPLSLccMyJLv5RZkGss/RjI/XAAB7lEfZ+f4hyvpuuA7UbrOoRYAXlu5X48RhmP/4/jgQBExpLpwD5hcS+uAaCRV/0OBhX1zgmD5VJD6IIm6fWvec4J1KVGFwHwyun82zbdWg5KWP7SFCT4XtWUPP+rd/hBjM515FO27Hk40p4nkZICZdg93zKKYxY3A4b+0gJ4a47YcuADCZ9t/fBU3S7beueyokZepKNooZGvrRYpMLs56lPZGSDmIwLxLTGo4nyiMW27tDxncVDXSlNVIpnyt5GtScGWQ== 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=hx328LHbfgJOzKZe+Vg8UzaABZuiJL6Irg4uAPZv90E=; b=Th6APjgiyeXN5vn+taR4/KZa/zjpx0e6lbMsSt0dzaucrY4+9WefFAFRutYGzqU2Okm1P9ofs7R1IbgiUANpvh6UAHuxbmAv/Iim44UwJM/xmefLsXtKbslwySuehHofjvyoOle3P2ua0LGZHvcMhljMYND8131vaioVC63I2q72bW2rZr501b8RFkV1rCT8P+wIa/gAqZkG66rM2KlWcdLKQFp9DVERF+Mu2B4dkIF6EvdcVaWMK6AQ96em+BOUY48EE++KuzpzunLeLyPo7EuySeXxV8qzLWCCffIl52LWweDnXcgPUh6utZEPS4WWOWt07JjuoP7mRmpjUNOmqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hx328LHbfgJOzKZe+Vg8UzaABZuiJL6Irg4uAPZv90E=; b=IqQ3IL/sdn6CNheXJdrqYyQdPeeICCxyNvUU3hNRApDBtcOif42HRo3GuLxe1q/TfORmjJSaYBBSggw83kTQb3YQfrAlkb8xmh00OcxjFGXb4SlabD5pXcB7TJYatM+mul/sluB35Jso12GfMn4UStNsVgIDEHYTPwHB6WsgyxE= Received: from MW4PR21MB1907.namprd21.prod.outlook.com (2603:10b6:303:71::8) by MW4PR21MB2075.namprd21.prod.outlook.com (2603:10b6:303:122::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.10; Thu, 24 Jun 2021 03:26:39 +0000 Received: from MW4PR21MB1907.namprd21.prod.outlook.com ([fe80::99fb:d530:b703:2b6e]) by MW4PR21MB1907.namprd21.prod.outlook.com ([fe80::99fb:d530:b703:2b6e%8]) with mapi id 15.20.4287.005; Thu, 24 Jun 2021 03:26:39 +0000 From: "Bret Barkelew" To: "devel@edk2.groups.io" , "kuqin12@gmail.com" , "Wu, Hao A" CC: "Kinney, Michael D" , Liming Gao , "Liu, Zhiguang" , Andrew Fish , Laszlo Ersek , "Lindholm, Leif" , Michael Kubacki Subject: Re: [EXTERNAL] Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update Thread-Topic: [EXTERNAL] Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update Thread-Index: AQHXYk0fpJB7E0RCoEGZzKN2zKIfd6siYhEAgAAqcCA= Date: Thu, 24 Jun 2021 03:26:39 +0000 Message-ID: References: <20210610014259.1151-1-kuqin12@gmail.com> <20210610014259.1151-2-kuqin12@gmail.com> ,<064c216a-bb12-e2b2-6ae8-17f836a8e0a7@gmail.com> In-Reply-To: <064c216a-bb12-e2b2-6ae8-17f836a8e0a7@gmail.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-06-24T03:25:17.4038706Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Privileged authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1375f6e6-c101-4a48-3116-08d936bfe15d x-ms-traffictypediagnostic: MW4PR21MB2075: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RL5numeMMUX1hLEJy4zM1oFjE6ZkNQsJ0zGuVzoq8pou0fTR90jOHd69XUvRWz7VCTkOSyUw0gjqy/yOAilLINW7Px2oy5VQJWICyEGSMNaShcj1c7qjI78c6PdVVCwqyIsBkQDNFKDAK4Rvoi2AcVAxLLEAgJQOz47dGDFw+MJVECuhPELLFxsvQYiXzBKNNQd85jDJBlAHefI65OQJo7r0kFyVi0CE4By4RrXTFc2fNZArzfnOXddBLuStpG9lPKr8//JJc7qWJkGjYDzN9f/NcyCi5GdOzvf0ZVlX6YwLFKSFndlj6nvcE40aLpQUsREZKZ2jJCjJ0lRmedOuWaFuBKqJAH4u9S/EV2t8TsrmKziS0YxRflfXjOS8HaCO70ozLGk8S/D75O0ua//+oJJ339ttnv+/VilmNETkpezXZJ4M+u7EiKOHqrgJWAG2N4x3OQ7VInq6m1g+ZpHtl6flZQnXc+StoAprMmhN6ZjEI5+h/Zx2plobX9vWtvidhw8uhmlvhRIHefq69uRx0aOFOLMXONkEffaLJahrEkAahX7cnkSr1z544uwLqc9CJCdXwdaNGX9gGvP4i9VGjI/3qcHCbDa+CMl1Czl1NXRwEE2eN1yXd6U4J1veq44pHMiyEeS7wqzAsfZEY1YceqsSC1p3ZqZwclcOOehaBIL7xoV7aSW8gXjvzHiupVjUzEnPcZJY61t3P2l2BQ4mT2wqllrjaP597G093edX5fLWOtsCICZ56KrWYPGRpdO9Mqq0h5pgKr9NqcyK+ZRy+w== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR21MB1907.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(107886003)(7696005)(316002)(54906003)(53546011)(19627235002)(110136005)(6506007)(38100700002)(82960400001)(83380400001)(55016002)(5660300002)(26005)(8676002)(52536014)(186003)(166002)(66476007)(122000001)(66446008)(8936002)(8990500004)(76116006)(71200400001)(66556008)(66946007)(64756008)(9686003)(30864003)(86362001)(10290500003)(966005)(2906002)(478600001)(15650500001)(82950400001)(33656002)(4326008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?Windows-1252?Q?XeTsE4nbnuYGp5YeAW4dhAvYbOWb1xeFHUE3TWcJmMtxEDjROktzXt/C?= =?Windows-1252?Q?m4vXqOylO/rlgrW7TEDUYYgBeFHgckAl69KWaoTrTOCh3ycUv8sni/Yk?= =?Windows-1252?Q?uX9uAVRWkq1rqph8IBUvNXq8vAU2UaRQMTrchjnvPiQ0EkKJSfJRrG81?= =?Windows-1252?Q?1hQRxEYRIUZfbCet0vU27XXdf8ukiNDzIwR50cz5NtoEnhMywKm80vTn?= =?Windows-1252?Q?KrFMfc4dd1QTjqKKICgYXEp1yPh72NdwScx6HBeK4PusbGu8rrYQbFw7?= =?Windows-1252?Q?ntqejOVC8A5PUySwx26TyzDUFvKx7QgGBJnqcXBps3cppbIjB8XMImRj?= =?Windows-1252?Q?UkK9pQzIAO2AeBk6DaCctou9ejJZmDEXF4AstpTKO77/mH4oM4xaN2JI?= =?Windows-1252?Q?BB4ip3oleBM2wxepdEQ/FGCwP/h9c7bqJPlRJjrFaXb79V6zoywoMiJa?= =?Windows-1252?Q?Xl9bXfXpE11trGZXH3bIu4QYW4NkljGnz5o7Rb0erEfzNsXexmZeeCNE?= =?Windows-1252?Q?Y3NNkK13Tm+9DwmFaFKSg4w08ejJYgrGvXeRWipoo6n06GtCYtOn5f/X?= =?Windows-1252?Q?3X7UhhVZP0ZX3R+861BKm5qi7HH/6m3V2WH63x2I+lWPy8tK7zUAp7R8?= =?Windows-1252?Q?T/LXuVst9oIJeH6AFPVcra+M7dNNu/aYp+KRQlU9Ya4AxVq2NcLcdwBt?= =?Windows-1252?Q?TjvMx6JyUhji6yhyrZ3WN7QLRf3nvi7WWmwvlfVSoPR5ubpgMuqfyXNH?= =?Windows-1252?Q?q1cYppRyaeD17mrOU/qHaJhKp2j5sWBqE/ttn72dYAUZ4CuyYOYCCsqd?= =?Windows-1252?Q?GZuMj4uZMDnPzQzZ20gax9PjcqIbg6h/oTIAs83nOhjVVp3TkCkdeHD1?= =?Windows-1252?Q?OLGAYpaRPlRTE+ENS3FWPZamapVHvhuO86oOUBgGNN6g3+MV3d/Spqpn?= =?Windows-1252?Q?3oKPEgk0tWH5jqmJInGKYKdNyGLGnDYEbfPsdhz4WitQNHhgxYbecty6?= =?Windows-1252?Q?dffuMf/+w6XU8Mbw7Gq5GyNsF+k+xEgGpIGTSoOVU9LMTox16ljrt0Ea?= =?Windows-1252?Q?WET0yLHQ2QTYDPVE1nm3Njzj9X6D4oUMvIuiGITn3H+LRcPoiCwzvVnD?= =?Windows-1252?Q?RFofhMZA4c/QND6Gd+QuuQX4ZVuwFSLKKdYgxfJ3ht9vWzaV5GVVfXEq?= =?Windows-1252?Q?vq4AhxlTgXDdAtO0FvPjuYCHXq6HWrx0/geL9cxYyzMCweAYYdtvZX9X?= =?Windows-1252?Q?qrfHLDQMYePN/jdT4f524YpyM4B8iINdkXBdnAEOi6/MBKxZIGTnuFKf?= =?Windows-1252?Q?qtLD7yvZuRj/m9V9TIhZozNt8Dj52NxS9nAN7q9lBQBEHrPyndfiEqQi?= =?Windows-1252?Q?T1yyfycGjs9+Vlrfv9TX8vDs2AvaBuqd+JNBlGQTkZ2fW1PkVNZEKTXw?= =?Windows-1252?Q?wXyla1qQMG7av5HnwLfEwg=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR21MB1907.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1375f6e6-c101-4a48-3116-08d936bfe15d X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2021 03:26:39.5229 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uP3sv1m6o7A8xWSCwIEgaQfcxcwUaifyEBLT67Kby3WbFf+OFBk/0eSyNpBdLOTzTYt7sby5zZ/fosn9kEq+ow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2075 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MW4PR21MB1907D1CA5A6944517E2529D6EF079MW4PR21MB1907namp_" --_000_MW4PR21MB1907D1CA5A6944517E2529D6EF079MW4PR21MB1907namp_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Yeah, the only other thought I had for moving forwards quickly (i.e. hackil= y) is to define a new GUID that just means =93I use an updated header confi= guration=94 since the EFI_GUID field comes first and is a well-understood s= ize. I would prefer the =93deprecate, break builds, fix code, move forward=94 a= pproach. - Bret From: Kun Qin via groups.io Sent: Wednesday, June 23, 2021 5:53 PM To: Wu, Hao A; devel@edk2.groups.io Cc: Kinney, Michael D; Liming Gao; Liu, Zhiguang; = Andrew Fish; Laszlo Ersek= ; Lindholm, Leif; Bret Barkelew; Michael Kubacki Subject: [EXTERNAL] Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Sp= ecification: EFI_MM_COMMUNICATE_HEADER Update Hi Hao, We have been circulating different ideas internally about how to enforce a warning around this change. There is an idea of deprecating the old structure and replacing it with a newly defined EFI_MM_COMMUNICATE_HEADER_V2. That way all consumers will be enforced to update their implementation and (hopefully) inspect the compatibility accordingly. In addition, we could add other fields such as signature and/or header version number for further extensibility. If there are code instances that uses "sizeof(EFI_GUID) + sizeof(UINTN)" in lieu of OFFSET_OF, this implementation is essentially decoupled from the structure definition. So compiler might not be able to help. In that case, runtime protections such as pool guard or stack guard might be usefu= l. Please let me know if you think header structure V2 is an idea worth to tr= y. Thanks, Kun On 06/15/2021 18:15, Wu, Hao A wrote: > Thanks Kun, > > I am a little concerned on whether there will be other missing cases tha= t are not covered by this patch series. > > 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. > Otherwise, it will be the burden for the platform owners to review the p= latform codes following your guide mentioned in this patch. > > Hoping others can provide some inputs on this. > > Best Regards, > Hao Wu > >> -----Original Message----- >> From: Kun Qin >> Sent: Wednesday, June 16, 2021 4:51 AM >> To: Wu, Hao A ; devel@edk2.groups.io >> Cc: Kinney, Michael D ; Liming Gao >> ; Liu, Zhiguang ; >> Andrew Fish ; Laszlo Ersek ; Leif >> Lindholm >> Subject: Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specificat= ion: >> EFI_MM_COMMUNICATE_HEADER Update >> >> 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 li= brary 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 On Behalf Of Kun >>>> Qin >>>> Sent: Thursday, June 10, 2021 9:43 AM >>>> To: devel@edk2.groups.io >>>> Cc: Kinney, Michael D ; Liming Gao >>>> ; Liu, Zhiguang ; >>>> Andrew Fish ; Laszlo Ersek ; Leif >>>> Lindholm >>>> Subject: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Specificatio= n: >>>> EFI_MM_COMMUNICATE_HEADER Update >>>> >>>> REF: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2= F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3430&data=3D04%7C01%7C= Bret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf= 86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb= 3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100= 0&sdata=3D483mG24s%2Bp0xSF90Wf%2Fmh2TN1atrIQa5mOrLyEPCTuE%3D&reserv= ed=3D0 >>>> >>>> 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 >>>> Cc: Liming Gao >>>> Cc: Zhiguang Liu >>>> Cc: Andrew Fish >>>> Cc: Laszlo Ersek >>>> Cc: Leif Lindholm >>>> >>>> Signed-off-by: Kun Qin >>>> --- >>>> 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://nam06.safelinks.protecti= on.outlook.com/?url=3Dhttps%3A%2F%2Fwww.tianocore.org%2F&data=3D04%7C01= %7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f98= 8bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbG= Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C= 1000&sdata=3DeRu4We7iSzuwrsS9MqIO2iqLxXHZ6CpUkInVpty554c%3D&reserve= d=3D0) >>>> + >>>> +## 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 wo= rk >> properly after the UINTN -> UINT64 change. >>> >>> For example: >>> LockBoxGetSmmCommBuffer(): >>> MinimalSizeNeeded =3D 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 >>>> >>>> >>>> >>>> >>>> >>> --_000_MW4PR21MB1907D1CA5A6944517E2529D6EF079MW4PR21MB1907namp_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable

Yeah, the only other thought I had for moving forwa= rds quickly (i.e. hackily) is to define a new GUID that just means =93I use= an updated header configuration=94 since the EFI_GUID field comes first an= d is a well-understood size.

 

I would prefer the =93deprecate, break builds, fix = code, move forward=94 approach.

 

- Bret

 

From: Kun Qin via groups.io
Sent: Wednesday, June 23, 2021 5:53 PM
To: Wu, Hao A; devel@edk2.groups.io
Cc: Kinney, Michael D= ; Liming Gao; Liu, Zhiguang; Andrew Fish; Laszlo Ersek; Lindholm, Leif; Bret Ba= rkelew; Michael Kubacki
Subject: [EXTERNAL] Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First= : PI Specification: EFI_MM_COMMUNICATE_HEADER Update

 

Hi Hao,

We have been circulating different ideas internally about how to enforce <= br> a warning around this change.

There is an idea of deprecating the old structure and replacing it with a newly defined EFI_MM_COMMUNICATE_HEADER_V2. That way all consumers
will be enforced to update their implementation and (hopefully) inspect the compatibility accordingly. In addition, we could add other fields
such as signature and/or header version number for further extensibility.<= br>
If there are code instances that uses "sizeof(EFI_GUID) + sizeof(UINT= N)"
in lieu of OFFSET_OF, this implementation is essentially decoupled from 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 usefu= l.

Please let me know if you think header structure V2 is an idea worth to tr= y.

Thanks,
Kun

On 06/15/2021 18:15, Wu, Hao A wrote:
> Thanks Kun,
>
> I am a little concerned on whether there will be other missing cases = that are not covered by this patch series.
>
> I am also wondering is there any detection can be made to warn the ca= ses that code modification should be made after this structure update.
> Otherwise, it will be the burden for the platform owners to review th= e platform codes following your guide mentioned in this patch.
>
> Hoping others can provide some inputs on this.
>
> Best Regards,
> Hao Wu
>
>> -----Original Message-----
>> From: Kun Qin <kuqin12@gmail.com>
>> Sent: Wednesday, June 16, 2021 4:51 AM
>> To: Wu, Hao A <hao.a.wu@intel.com>; 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@redh= at.com>; Leif
>> Lindholm <leif@nuviainc.com>
>> Subject: Re: [edk2-devel] [PATCH v1 1/5] EDK2 Code First: PI Spec= ification:
>> EFI_MM_COMMUNICATE_HEADER Update
>>
>> Hi Hao,
>>
>> Sorry that I missed comments for this patch earlier. You are corr= ect. 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 t= his 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> O= n 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 <zhigu= ang.liu@intel.com>;
>>>> Andrew Fish <afish@apple.com>; Laszlo Ersek <ler= sek@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://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugzil= la.tianocore.org%2Fshow_bug.cgi%3Fid%3D3430&amp;data=3D04%7C01%7CBret.B= arkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72f988bf86f141= af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWFpbGZsb3d8eyJ= WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&= amp;sdata=3D483mG24s%2Bp0xSF90Wf%2Fmh2TN1atrIQa5mOrLyEPCTuE%3D&amp;rese= rved=3D0
>>>>
>>>> This change includes specification update markdown file t= hat
>>>> 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://nam06.safelinks.protectio= n.outlook.com/?url=3Dhttps%3A%2F%2Fwww.tianocore.org%2F&amp;data=3D04%7= C01%7CBret.Barkelew%40microsoft.com%7Ca480819ff5e84e12239f08d936aa7bc5%7C72= f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637600928127681913%7CUnknown%7CTWF= pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D= %7C1000&amp;sdata=3DeRu4We7iSzuwrsS9MqIO2iqLxXHZ6CpUkInVpty554c%3D&= amp;reserved=3D0)
>>>> +
>>>> +## 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 Communicatio= n Protocol,
>>>> +the
>>>> MessageLength field of `EFI_MM_COMMUNICATE_HEADER` (also<= br> >> defined as
>>>> `EFI_SMM_COMMUNICATE_HEADER`) is defined as type UINTN. >>>> +
>>>> +But this structure, as a generic definition, could be us= ed 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 in= cluding:
>>>> +
>>>> +```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 perform= ing
>> explicit
>>>> addition such as the existing
>>>>
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileI= nfo.
>>>> c, one will need to change code implementation to match n= ew structure
>>>> definition. Otherwise, the code compiled on IA32 architec= ture will
>>>> experience structure field dereference error.
>>>> +
>>>> +User who currently uses UINTN local variables as place h= older of
>>>> MessageLength will need to use caution to make cast from = UINTN to
>>>> UINT64 and vice versa. It is recommended to use `SafeUint= 64ToUintn`
>>>> for such operations when the value is indeterministic. >>>> +
>>>> +Note: MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLi= b is
>> also
>>>> consuming this structure, but it handled this size discre= pancy
>>>> 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 =3D sizeof (EFI_GUI= D) +
>>>          &n= bsp;            = ;  sizeof (UINTN) +
>>>          &n= bsp;            = ;  MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE),
>>>          &n= bsp;            = ;       MAX (sizeof
>> (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES),
>>>          &n= bsp;            = ;            MAX (si= zeof
>> (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE),
>>>          &n= bsp;            = ;            &n= bsp;    MAX (sizeof
>> (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE),
>>>          &n= bsp;            = ;            &n= bsp;         sizeof
>>> (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)))));
>>>
>>> SaveLockBox():
>>>     UINT8     &n= bsp;            = ;         TempCommBuffer[sizeof(EFI= _GUID) + sizeof(UINTN)
>> + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];
>>>
>>> Is the series missed changes for SmmLockBoxDxeLib or I got so= mething
>> 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, th= e definition
>>>> +of
>>>> `EFI_MM_COMMUNICATE_HEADER` should be changed from curren= t:
>>>> +
>>>> +```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 `Dat= a` in
>>>> `EFI_MM_COMMUNICATE_HEADER`. Thus applicable calculations= of
>>>> `sizeof(EFI_GUID) + sizeof(UINTN)` should be replaced wit= h
>>>> `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)` or similar >> alternatives.
>>>> These calculations are identified in:
>>>> +
>>>> +```bash
>>>>
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfile= Info.
>>>> c
>>>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfile= Info.c
>>>> +```
>>>> +
>>>> +1. Resolve potentially mismatched type between `UINTN` a= nd `UINT64`.
>>>> This would occur when `MessageLength` or its derivitive a= re 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 ov= erflow 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 i= dentified in:
>>>> +
>>>> +```bash
>>>> +MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
>>>>
>> +MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfile= Info.
>>>> c
>>>> +MdeModulePkg/Application/MemoryProfileInfo/MemoryProfile= Info.c
>>>> +```
>>>> +
>>>> +1. After all above changes applied and specification upd= ated,
>>>> `MdePkg/Include/Protocol/MmCommunication.h` will need to = be
>> updated
>>>> to match new definition that includes the field type upda= te.
>>>> --
>>>> 2.31.1.windows.1
>>>>
>>>>
>>>>
>>>>
>>>>
>>>




 

--_000_MW4PR21MB1907D1CA5A6944517E2529D6EF079MW4PR21MB1907namp_--