From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mx.groups.io with SMTP id smtpd.web08.5356.1624006976655080306 for ; Fri, 18 Jun 2021 02:02:56 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uMfzw7rC; spf=pass (domain: gmail.com, ip: 209.85.210.182, mailfrom: kuqin12@gmail.com) Received: by mail-pf1-f182.google.com with SMTP id u18so1842008pfk.11 for ; Fri, 18 Jun 2021 02:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UQ/bVI9j6/OUAxrfA09VTueFPjW/mzm/XY2IUB4/vHY=; b=uMfzw7rCwQUDW3ILDMsPaQG0ewg21FRtXkJCzZSplcebp/s5y2/4m2bhN3uqGX+krE zovbcVw3nLOBilM3Ho3kzR/f5KMDN4DjHn47Tiw1U/LPaZhOVC5TzF/9MoG9wdBjOI7K GyPF1f2JpthgHIgi9p8+3Ss5RPMXlb0ZpRRfABUUpU3sg8xKvaUcq0l+5ahTBQwKGt/p ckXyJmeJbg8ibdcrjRmJdhxRswjZsJfGIHu6uYhnJOIqWt9jWgogzWJfDzGbHA4bOOS+ ItpjE1DL+S+CxgGBbBHU4KZCPvf1OIs+mccFW5HavLrrLnhzclD/zWx38B4qohNxsGS9 F30g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UQ/bVI9j6/OUAxrfA09VTueFPjW/mzm/XY2IUB4/vHY=; b=hxIwbsrKqdygL/5vNBz3cdhpiu8PxTVeiIWq/vNwzoITrPYgYQwLd7CxcFc7dhfqgc ngfmaGtdtaBoYpMDBdp0lWo43Sk+dyAdzYyrW/O5IxjQwJ4W/2hPeL1KB40hwWuq7pD1 YwWqUy+oQr1ucIWDwJgE4zL2iRnYoQ+rdca1gKoAf0rHSGO2CYD72aCvOJGpAQhMWyTV ZQ5Ia/aee2ZQQ1f1qVvSWnzOCdByVKdqeazIe6GJRc3V4rxvWlCzQESadRk471n7EffQ /DTSXfszrQgQBTGzbnwjkZxXrZGjOcnZF2v02RNG/9zb9vFX4zqN2ym0QlqJegyuLO8G PFtw== X-Gm-Message-State: AOAM533Y27onQkRejHaOU5IY2jimiCqZ+oNBe7YWuM0Qlwh40tetwjce xOv3coFLtyKEJFBeLHVn1FuOrh/L1Ejkfw== X-Google-Smtp-Source: ABdhPJymcFt9H4qa1sao0fg5eO1s4uJBjtlPmql3Zov1nfVMolAr3lFNQuZPTpxMbETHM91nrfsgfg== X-Received: by 2002:a63:bc19:: with SMTP id q25mr9098396pge.211.1624006975806; Fri, 18 Jun 2021 02:02:55 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.35.88.161]) by smtp.gmail.com with ESMTPSA id b1sm7702512pgb.91.2021.06.18.02.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 02:02:55 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Andrew Fish , Laszlo Ersek , Leif Lindholm , Hao A Wu Subject: [PATCH v2 1/6] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update Date: Fri, 18 Jun 2021 02:02:38 -0700 Message-Id: <20210618090243.2517-2-kuqin12@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20210618090243.2517-1-kuqin12@gmail.com> References: <20210618090243.2517-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Cc: Zhiguang Liu Cc: Andrew Fish Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Hao A Wu Signed-off-by: Kun Qin --- Notes: v2: - Updated change impact analysis regarding SmmLockBoxDxeLib [Hao] BZ3430-SpecChange.md | 90 ++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/BZ3430-SpecChange.md b/BZ3430-SpecChange.md new file mode 100644 index 000000000000..a4f8b397e822 --- /dev/null +++ b/BZ3430-SpecChange.md @@ -0,0 +1,90 @@ +# 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 +MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib +``` + +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 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 +MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.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