From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85309+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85309+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521746; cv=none; d=zohomail.com; s=zohoarc; b=ArBpIZWOmW3cCivlavFXhBY2JNsKciEDEQ+6JVJsPfNblgza/3+AynVwKj6xwHKhvYIz/IIdXE/al1fuSwjJ3ZyJjzp2cd6NKqnOBDsg1FDJecohH6bIApR7yXgV3+ZGeD6qtPgqKyo1S2zSZzFJrVPmibAJcrnjpP0LaCA7A8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521746; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=U6/vKcZ3u1IiKzrXENymShWVIoFB6bvNZx+ctKcGrFo=; b=H96NdgjWPAv9uPnTTfzdzfsswBf9zdaOnZcCGS5jViJ0SXY1eXYC5nMVBLEdM0mrgh8clZlERqIrwKZEJu+tdW3ZpExkVTMD67XNci7qrO/4WZxReGJidLbfnwS04NlDHdewW9CZ7DP1tsSiLTAUNR/y2SP2DOaFr/HLr9+bfus= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85309+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521746069181.58123979065908; Thu, 6 Jan 2022 18:15:46 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q4KDYY1788612xhmNL4Fb4eu; Thu, 06 Jan 2022 18:15:45 -0800 X-Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mx.groups.io with SMTP id smtpd.web12.1452.1641521745124060835 for ; Thu, 06 Jan 2022 18:15:45 -0800 X-Received: by mail-pj1-f52.google.com with SMTP id iy13so3962257pjb.5 for ; Thu, 06 Jan 2022 18:15:45 -0800 (PST) X-Gm-Message-State: aAAb4iRTcEqkdLhLcqhYJZBZx1787277AA= X-Google-Smtp-Source: ABdhPJzoc0cwxg7/BkcRRB7swoUrEPy9jfgoTdnk89knJdwJBCs8N8uenxvxvLUeP+/YOYJiM9Eb5Q== X-Received: by 2002:a17:90a:e60c:: with SMTP id j12mr8142421pjy.156.1641521744468; Thu, 06 Jan 2022 18:15:44 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:44 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Andrew Fish , Leif Lindholm , Hao A Wu , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bret Barkelew Subject: [edk2-devel] [PATCH v4 1/7] EDK2 Code First: PI Specification: New communicate header and interfaces Date: Thu, 6 Jan 2022 18:15:26 -0800 Message-Id: <20220107021532.1322-2-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521745; bh=awaqzo/Du7b8jlsQp3eEbOoi7Z+vau/TYrarcaOpBIo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=KJlqFrjAyjoQurlrruVyNUDWGHLasHt95h4qfac/90PBklC9ohEdJ3XN9PmMXOToAh+ KPBE2Hue9z87jFjJ7e/FiGgWzxh/ni4uwewYlntGdbrKjjUK8NwRwMSvvGvWci0jHl0yF QjoDZSp+F0kGe4cl+MtMxs6cCkUYzh//iII= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521746735100003 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 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: Leif Lindholm Cc: Hao A Wu Cc: Marvin H=C3=A4user Cc: Bret Barkelew Signed-off-by: Kun Qin --- Notes: v3: - switched to use communicate v3 instead of sprinkle structure updates =20 v4: - No review, no change. CodeFirst/BZ3430-SpecChange.md | 277 ++++++++++++++++++++ 1 file changed, 277 insertions(+) diff --git a/CodeFirst/BZ3430-SpecChange.md b/CodeFirst/BZ3430-SpecChange.md new file mode 100644 index 000000000000..39a96b9a44f0 --- /dev/null +++ b/CodeFirst/BZ3430-SpecChange.md @@ -0,0 +1,277 @@ +# Title: Introduction of `EFI_MM_COMMUNICATE_HEADER_V3` and `MM_COMMUNICAT= E3_*` interface + +## 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 + +Introduce `EFI_PEI_MM_COMMUNICATION3_PPI` and `EFI_MM_COMMUNICATE3_PROTOCO= L` that works with communication buffer starts with `EFI_MM_COMMUNICATE_HEA= DER_V3` to provide better portability between different architectures (IA32= & X64) and adapt to flexible array supported by modern compilers. + +## Benefits of the change + +In PI Spec v1.7 Errata A, Vol.4, Sec 5.7 MM Communication Protocol, the Me= ssageLength 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 an= d DXE MM communication. Thus for a system that supports PEI Standalone MM l= aunch, but operates PEI in 32bit mode and MM foundation in 64bit, the curre= nt `EFI_MM_COMMUNICATE_HEADER` definition will cause structure parse error = due to UINTN used. + +This proposed data structure resolved it by introducing `EFI_MM_COMMUNICAT= E_HEADER_V3` that defines the MessageSize as UINT64 to remove data size amb= iguity. + +The data structure still starts with a `HeaderGuid` field that is typed as= `EFI_GUID`. This will be populated as `gCommunicateHeaderV3Guid` or `COMMU= NICATE_HEADER_V3_GUID` as an indicator to differentiate new data format ves= us legacy format. + +Furthermore, the addition of signature could help identifying whether the = data received is compiliant with this new data structure, which will help f= or binary release modules to identify usage of legacy `EFI_MM_COMMUNICATE_H= EADER`. + +Version field is also added to indicate the current version of header in c= ase there is need for minor modification in the future. + +In addition, the data field of MM communicate message is replaced with fle= xible array to allow users not having to consume extra data during communic= ate and author code more intrinsically. + +On the non-MM environment side, the Standalone MM DXE IPL agent can add in= stallation of `EFI_MM_COMMUNICATE3_PROTOCOL`, while the Standalone MM PEI I= PL agent that launches MM foundation should publish and only publish `EFI_P= EI_MM_COMMUNICATION3_PPI` for MM communication during PEI phase. + +For communication data that starts with `EFI_MM_COMMUNICATE_HEADER_V3`, ca= llers always need to use V3 protocol/PPI to communicate with updated MM cor= es. These interface introductions instead of replacement can maintain the c= ompatibility for existing codebase while resolving size mismatching occurre= d during data transfer between different architectures. + +## Impact of the change + +This change will impact the MM cores and IPLs: + +```bash +MdeModulePkg/Core/PiSmmCore/PiSmmCore +StandaloneMmPkg/Core/StandaloneMmCore +MdeModulePkg/Core/PiSmmCore/PiSmmIpl +``` + +To cooporate with the newly proposed data format, existing MM cores need t= o be updated to parse incoming data properly to tell if the data is complia= nt with new or legacy format. + +The existing PiSmmIpl will need to be updated to publish `EFI_MM_COMMUNICA= TE3_PROTOCOL` for consumers that would like to invoke MMI with new data for= mat. + +For potential proprietary IPLs that launches Standalone MM in PEI phase, i= f any, the PEIM should change to publish `EFI_PEI_MM_COMMUNICATION3_PPI` in= stead of `EFI_MM_COMMUNICATE_PPI`. + +Accordingly, all consumers in PEI phase that communicate to PEI launched S= tandalone MM should switch to use `EFI_PEI_MM_COMMUNICATION3_PPI` and `EFI_= MM_COMMUNICATE_HEADER_V3`. + +## Detailed description of the change [normative updates] + +### Specification Changes + +1. In PI Specification v1.7 Errata A: Vol. 4-1.5.1 Initializing MM Standal= one Mode in PEI phase, the last bullet point of step 3 should be changed to: + + ```c + Publishes the EFI_PEI_MM_COMMUNICATION3_PPI + ``` + +1. In PI Specification v1.7 Errata A: Vol. 4, section 6.5 MM Communication= PPI, add the following: + + ```markdown + # EFI_PEI_MM_COMMUNICATION_PPI + + ## Summary + + This PPI provides a means of communicating between drivers outside of = MM and MMI handlers inside of MM in PEI phase. + + ## GUID + + #define EFI_PEI_MM_COMMUNICATION3_PPI_GUID \ + { \ + 0xe70febf6, 0x13ef, 0x4a21, { 0x89, 0x9e, 0xb2, 0x36, 0xf8, 0x25, = 0xff, 0xc9 } \ + } + + ## PPI Structure + + typedef struct _EFI_PEI_MM_COMMUNICATION3_PPI { + EFI_PEI_MM_COMMUNICATE3 Communicate; + } EFI_PEI_MM_COMMUNICATION3_PPI; + + ## Members + + ### Communicate + + Sends/receives a message for a registered handler. See the Communica= te() function description. + + ## Description + + This PPI provides services for communicating between PEIM and a regi= stered MMI handler. + + # EFI_PEI_MM_COMMUNICATION_PPI.Communicate() + + ## Summary + Communicates with a registered handler. + + ## Prototype + typedef + EFI_STATUS + (EFIAPI *EFI_PEI_MM_COMMUNICATE3)( + IN CONST EFI_PEI_MM_COMMUNICATION3_PPI *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize + ); + + ## Parameters + + ### This + The EFI_PEI_MM_COMMUNICATE3 instance. + + ### CommBuffer + + Pointer to the buffer to convey into MMRAM. + + ### CommSize + + The size of the data buffer being passed in. On exit, the size of da= ta being returned. Zero if the handler does not wish to reply with any data. + + ## Description + + This function provides a service to send and receive messages from a= registered PEI service. The EFI_PEI_MM_COMMUNICATION3_PPI driver is respon= sible for doing any of the copies such that the data lives in PEI-service-a= ccessible RAM. + + A given implementation of the EFI_PEI_MM_COMMUNICATION3_PPI may choo= se to use the EFI_MM_CONTROL_PPI for effecting the mode transition, or it m= ay use some other method. + + The agent invoking the communication interface must be physical/virt= ually 1:1 mapped. + + To avoid confusion in interpreting frames, the CommBuffer parameter = should always begin with EFI_MM_COMMUNICATE_HEADER_V3. The header data is m= andatory for messages sent into the MM agent. + + Once inside of MM, the MM infrastructure will call all registered ha= ndlers with the same HandlerType as the GUID specified by HeaderGuid and th= e CommBuffer pointing to Data. + + This function is not reentrant. + + ## Status Codes Returned + EFI_SUCCESS The message was successfully posted. + EFI_INVALID_PARAMETER The CommBuffer was NULL. + ``` + +1. In PI Specification v1.7 Errata A: Vol. 4, section 6.5 MM Communication= PPI, add the following: + + ```markdown + # EFI_MM_COMMUNICATION3_PROTOCOL + + ## Summary + + This protocol provides a means of communicating between drivers outs= ide of MM and MMI handlers inside of MM, for communication buffer that is c= ompliant with EFI_MM_COMMUNICATE_HEADER_V3. + + ## GUID + + #define EFI_MM_COMMUNICATION3_PROTOCOL_GUID \ + { \ + 0xf7234a14, 0xdf2, 0x46c0, { 0xad, 0x28, 0x90, 0xe6, 0xb8, 0x83, 0= xa7, 0x2f } \ + } + + ## Prototype + typedef struct _EFI_MM_COMMUNICATION3_PROTOCOL { + EFI_MM_COMMUNICATE3 Communicate; + } EFI_MM_COMMUNICATION3_PROTOCOL; + + ## Members + + ### Communicate + + Sends/receives a message for a registered handler. See the Communica= te() function description. + + ## Description + + This protocol provides runtime services for communicating between DX= E drivers and a registered MMI handler. + + # EFI_MM_COMMUNICATION3_PROTOCOL.Communicate() + + ## Summary + + Communicates with a registered handler. + + ## Prototype + + typedef + EFI_STATUS + (EFIAPI *EFI_MM_COMMUNICATE3)( + IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This, + IN OUT VOID *CommBufferPhysical, + IN OUT VOID *CommBufferVirtual, + IN OUT UINTN *CommSize OPTIONAL + ); + + ## Parameters + + ### This + + The EFI_MM_COMMUNICATION3_PROTOCOL instance. + + ### CommBufferPhysical + + Physical address of the buffer to convey into MMRAM, of which conten= t must start with EFI_MM_COMMUNICATE_HEADER_V3. + + ### CommBufferVirtual + + Virtual address of the buffer to convey into MMRAM, of which content= must start with EFI_MM_COMMUNICATE_HEADER_V3. + + ### CommSize + + The size of the data buffer being passed in. On exit, the size of da= ta being returned. Zero if the handler does not wish to reply with any data= . This parameter is optional and may be NULL. + + ## Description + + Usage is similar to EFI_MM_COMMUNICATION_PROTOCOL.Communicate() exce= pt for the notes below: + + * Communication buffer transfer to MM core should start with EFI_MM_= COMMUNICATE_HEADER_V3. + * Instead of passing just the physical address via the CommBuffer pa= rameter, the caller must pass both the physical and the virtual addresses o= f the communication buffer. + * If no virtual remapping has taken place, the physical address will= be equal to the virtual address, and so the caller is required to pass the= same value for both parameters. + + ## Related Definitions + typedef struct { + EFI_GUID HeaderGuid; + UINT32 Signature; + UINT32 Version; + EFI_GUID MessageGuid; + UINT64 MessageSize; + UINT8 MessageData[ANYSIZE_ARRAY]; + } EFI_MM_COMMUNICATE_HEADER_V3; + + #define COMMUNICATE_HEADER_V3_GUID \ + { \ + 0x68e8c853, 0x2ba9, 0x4dd7, { 0x9a, 0xc0, 0x91, 0xe1, 0x61, 0x55, = 0xc9, 0x35 } \ + } + + #define EFI_MM_COMMUNICATE_HEADER_V3_SIGNATURE 0x4D434833 // "MCH3" + #define EFI_MM_COMMUNICATE_HEADER_V3_VERSION 3 + + ### HeaderGuid + + Indicator GUID for MM core that the communication buffer is complian= t with this v3 header. Must be COMMUNICATE_HEADER_V3_GUID. + + ### Signature + + Signature to indicate data is compliant with new MM communicate head= er structure. Must be "MCH3". + + ### Version + + MM communicate data format version, MM foundation entry point should= check if incoming data is a supported format before proceeding. Must be 3. + + ### MessageGuid + + Allows for disambiguation of the message format. + + ### MessageSize + + Describes the size of MessageData (in bytes) and does not include th= e size of the header. + + ### MessageData + + Designates an array of bytes that is MessageSize in size. + + ## Status Codes Returned + + EFI_SUCCESS The message was successfully posted. + EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommBuffe= rVirtual was NULL. + EFI_BAD_BUFFER_SIZE The buffer is too large for the MM imple= mentation. If this error is returned, the MessageLength field in the CommBu= ffer header or the integer pointed by CommSize, are updated to reflect the = maximum payload size the implementation can accommodate. + EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommS= ize parameter, if not omitted, are in address range that cannot be accessed= by the MM environment. + ``` + +### Code Changes + +1. Add data structure and its related definitions in `MdePkg/Include/Pi/Pi= MultiPhase.h` to match new definition. + +1. Add interface definition of `MdePkg/Include/Protocol/MmCommunication3.h= ` and `MdePkg/Include/Protocol/MmCommunication3.h`, respectively, to match = newly proposed interfaces. + +1. Extend PiSmmCore to inspect `HeaderGuid` of incoming communication data= . If it matches `COMMUNICATE_HEADER_V3_GUID`, parse the incoming data to st= art with `EFI_MM_COMMUNICATE_HEADER_V3`, otherwise it will be parse as exis= ting way. + +1. Extend StandaloneMmCore to inspect `HeaderGuid` of incoming communicati= on data. If it matches `COMMUNICATE_HEADER_V3_GUID`, parse the incoming dat= a to start with `EFI_MM_COMMUNICATE_HEADER_V3`, otherwise it will be parse = as existing way. + +1. Extend PiSmmIpl to publish `EFI_MM_COMMUNICATION3_PROTOCOL`, the implem= entation of `EFI_MM_COMMUNICATION3_PROTOCOL.Communicate()` should parse the= incoming data as it starts with `EFI_MM_COMMUNICATE_HEADER_V3`, when appli= cable. --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85309): https://edk2.groups.io/g/devel/message/85309 Mute This Topic: https://groups.io/mt/88253680/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85310+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85310+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521746; cv=none; d=zohomail.com; s=zohoarc; b=AU4t4Ao+RPo5vvNGz598F6qQwQu9gr52cU40O1IlfQ0IqzRj0XeFLxvhSsGzxnQqgE3or8aNg0A9JwNt8K7PyRUsmRU5PId+Mx1RtxOuDSzkieIDNkGUKgixIZa6veDAKBALZN0rLEJXB2GYP5EkrnBn9fsohfSgt/2Z6S6eDZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521746; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=P+aA7Ksqf0kMYYguMXUpbTQx+O5bSZwPHyUiP7bNpbM=; b=cudhaqYvW9LrTWRRnLuxPG34SoH2Vb7bXSxGoJolf6Z2fjogtXv7NE2TzAgksVUd0hg4pJIpaLQ0oeP3MULtLHPlpJ3bKeQa4e7xzTkD+M9zKZqn9vQo5xFraDlG3KwUVftmae5wEwhBJSOy7Sl+IZaLRPNU3CfHaHEkSQOXRvg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85310+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521746609488.6232838039865; Thu, 6 Jan 2022 18:15:46 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id GTItYY1788612xuyinZvzyix; Thu, 06 Jan 2022 18:15:46 -0800 X-Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mx.groups.io with SMTP id smtpd.web11.1478.1641521745639113798 for ; Thu, 06 Jan 2022 18:15:45 -0800 X-Received: by mail-pg1-f178.google.com with SMTP id y9so4161979pgr.11 for ; Thu, 06 Jan 2022 18:15:45 -0800 (PST) X-Gm-Message-State: 2VG15tmIkapW41zhDh9UOKgQx1787277AA= X-Google-Smtp-Source: ABdhPJwPGD29o9BIjhYDMUpYRaZ4ppbddv+TPuPnD1aiCq/kayjkoPNg6u6dGem4oSfhdKw5ae/JUQ== X-Received: by 2002:a63:5fc6:: with SMTP id t189mr55364905pgb.249.1641521745088; Thu, 06 Jan 2022 18:15:45 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:44 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Hao A Wu , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v4 2/7] MdePkg: MmCommunication: Introduce EFI_MM_COMMUNICATE_HEADER_V3 to MdePkg Date: Thu, 6 Jan 2022 18:15:27 -0800 Message-Id: <20220107021532.1322-3-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521746; bh=29JjpG8loaXdjeVx2HGXsVWmF5Jn1oo8i8P2y04aDDU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=YZOxVc5clqAdLOgS1MGYRyPU0bDHsEpsQfWO1YANQLfSP3ySwbVCOT0PlkbQFcaax6L Gbl3YjTy3X0c0PcVgUeO7NyzxaBr7cmGC2iuF9lrptYcq6xeAiH86Z/pvOb4k3ua8ehRF cBO+b9nqKYZoXkSlilp2pgv+jbvEgQz8f3U= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521748491100009 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 This change introduces a new definition for MM communicate header structure, intending to provide better portability between different architectures (IA32 & X64) and adapt to flexible array supported by modern compilers. The original MessageLength field of EFI_MM_COMMUNICATE_HEADER, as a generic definition, was used for both PEI and DXE MM communication. On 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. This introduction removes the architecture dependent field by defining this field as UINT64. The new signature could help identifying whether the data received is compiliant with this new data structure, which will help for binary release modules to identify usage of legacy data structure. Version field is also added to indicate the current version of header in case there is need for minor modification in the future. The data field of MM communicate message is replaced with flexible array to allow users not having to consume extra data during communicate and author code more intrinsically. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Hao A Wu Cc: Marvin H=C3=A4user Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin --- Notes: v3: - Newly introduced communicate v3 - Used flexible arrays [Marvin] - Added static assert [Michael] =20 v4: - Rebased with uncrusitify changes. MdePkg/Include/Pi/PiMultiPhase.h | 57 ++++++++++++++++++++ MdePkg/MdePkg.dec | 5 ++ 2 files changed, 62 insertions(+) diff --git a/MdePkg/Include/Pi/PiMultiPhase.h b/MdePkg/Include/Pi/PiMultiPh= ase.h index a7e95820ef65..178606eacfb0 100644 --- a/MdePkg/Include/Pi/PiMultiPhase.h +++ b/MdePkg/Include/Pi/PiMultiPhase.h @@ -103,6 +103,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define EFI_SMRAM_CLOSED EFI_MMRAM_CLOSED #define EFI_SMRAM_LOCKED EFI_MMRAM_LOCKED =20 +/// +/// MM Communicate header constants +/// +#define COMMUNICATE_HEADER_V3_GUID \ + { \ + 0x68e8c853, 0x2ba9, 0x4dd7, { 0x9a, 0xc0, 0x91, 0xe1, 0x61, 0x55, 0xc9= , 0x35 } \ + } + +#define EFI_MM_COMMUNICATE_HEADER_V3_SIGNATURE 0x4D434833 // "MCH3" +#define EFI_MM_COMMUNICATE_HEADER_V3_VERSION 3 + /// /// Structure describing a MMRAM region and its accessibility attributes. /// @@ -149,6 +160,50 @@ typedef struct _EFI_MM_RESERVED_MMRAM_REGION { UINT64 MmramReservedSize; } EFI_MM_RESERVED_MMRAM_REGION; =20 +#pragma pack(1) + +/// +/// To avoid confusion in interpreting frames, the buffer communicating to= MM core through +/// EFI_MM_COMMUNICATE3 or later should always start with EFI_MM_COMMUNICA= TE_HEADER_V3. +/// +typedef struct { + /// + /// Indicator GUID for MM core that the communication buffer is complian= t with this v3 header. + /// Must be gCommunicateHeaderV3Guid. + /// + EFI_GUID HeaderGuid; + /// + /// Signature to indicate data is compliant with new MM communicate head= er structure. + /// Must be "MCH3". + /// + UINT32 Signature; + /// + /// MM communicate data format version, MM foundation entry point should= check if incoming + /// data is a supported format before proceeding. + /// Must be 3. + /// + UINT32 Version; + /// + /// Allows for disambiguation of the message format. + /// + EFI_GUID MessageGuid; + /// + /// Describes the size of MessageData (in bytes) and does not include th= e size of the header. + /// + UINT64 MessageSize; + /// + /// Designates an array of bytes that is MessageSize in size. + /// + UINT8 MessageData[]; +} EFI_MM_COMMUNICATE_HEADER_V3; + +#pragma pack() + +STATIC_ASSERT ( + (sizeof (EFI_MM_COMMUNICATE_HEADER_V3) =3D=3D OFFSET_OF (EFI_MM_COMMUNIC= ATE_HEADER_V3, MessageData)), \ + "sizeof (EFI_MM_COMMUNICATE_HEADER_V3) does not align with the beginning= of flexible array MessageData" + ); + typedef enum { EFI_PCD_TYPE_8, EFI_PCD_TYPE_16, @@ -208,4 +263,6 @@ EFI_STATUS IN VOID *ProcedureArgument ); =20 +extern EFI_GUID gCommunicateHeaderV3Guid; + #endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 59b405928bf8..11c08e617511 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -826,6 +826,11 @@ [Guids] ## Include/Protocol/CcMeasurement.h gEfiCcFinalEventsTableGuid =3D { 0xdd4a4648, 0x2de7, 0x4665, { 0x96,= 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46 }} =20 + # + # GUID indicates the MM communication data is compliant with v3 communic= ation header. + # + gCommunicateHeaderV3Guid =3D { 0x68e8c853, 0x2ba9, 0x4dd7, { 0x9a,= 0xc0, 0x91, 0xe1, 0x61, 0x55, 0xc9, 0x35 } } + [Guids.IA32, Guids.X64] ## Include/Guid/Cper.h gEfiIa32X64ErrorTypeCacheCheckGuid =3D { 0xA55701F5, 0xE3EF, 0x43de, { 0= xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }} --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85310): https://edk2.groups.io/g/devel/message/85310 Mute This Topic: https://groups.io/mt/88253681/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85311+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85311+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521747; cv=none; d=zohomail.com; s=zohoarc; b=RrGKDNks1KtSAoONyBB84S3x2ThcMtKEDK7FqAhU2MUo7Fz+Tm9qUhuEPKH7Ihbt8zCnXh1MiGi1yVp4M5k7lTsmhXWfiNSQWsn/mhqRjLkLguAO5u94qgMsrxKrgCV4saDAZLjeBp+Gw++bm1qS5jEzUXxwTG+eMmXzB0qZtBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521747; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=F8duQj0jhqn2xpjQNsH50FI81F/3VQ0r/QlP8xi0vT8=; b=E8taioneupTFh+LYOoCg8yJJ790LpJAXqzYRxD8hS9VRwP4Lne5zWsJfXeOdQ0Sxd8vaIcYOvav3cOSj6QeoIbGIMWpn0urXuVy7vVpIgQ6tlIJltBnjdEwsoBuaUSJdzVWEYX01wZd9SDR5CUA5Ln7UEczcm8CiXATpC8WOV+A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85311+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521747214271.91359655384815; Thu, 6 Jan 2022 18:15:47 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id tkMRYY1788612xqlgYe18J2B; Thu, 06 Jan 2022 18:15:46 -0800 X-Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mx.groups.io with SMTP id smtpd.web12.1453.1641521746311083671 for ; Thu, 06 Jan 2022 18:15:46 -0800 X-Received: by mail-pg1-f177.google.com with SMTP id v25so4191655pge.2 for ; Thu, 06 Jan 2022 18:15:46 -0800 (PST) X-Gm-Message-State: vKDix1sKVTUerF3Yz00WCfgpx1787277AA= X-Google-Smtp-Source: ABdhPJwuI2vWSQO11DBs0JCEAfe6s7M8tHhYiuHQFYF8L4ZzLZsDJq0N7yjxGBAjwQukyBlPNT4CMw== X-Received: by 2002:a63:211a:: with SMTP id h26mr54517394pgh.239.1641521745757; Thu, 06 Jan 2022 18:15:45 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:45 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Hao A Wu , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v4 3/7] MdePkg: MmCommunication: Introduce EFI_MM_COMMUNICATION3_PROTOCOL to MdePkg Date: Thu, 6 Jan 2022 18:15:28 -0800 Message-Id: <20220107021532.1322-4-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521746; bh=jrMC5TYuKDF8UnmzojOEozuKLrTe1Ziaavy/hNEBMKY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=T2UXiBsX/xnkqGjP2AWyqtqeGn/MFlmxgorbBN7l2bw/na6MP4UZroCbXGaPXnFop0q u0cDY+9YEZ6mqgKhOunaarZjdBNdWS1ptqMYlcq6TYS3AEhvi29xr7MGZmfQHrZ/vOPwi xctK+let7yLWY0YIYbGn7qUkFZ4tRaWtIHA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641522649357100001 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 This change introduces a new definition for MM communicate protocol v3. This protocol will be installed under a new GUID in contrast to exisiting EFI_MM_COMMUNICATION_PROTOCOL. Data communicated to MM through EFI_MM_COMMUNICATION3_PROTOCOL should always start with EFI_MM_COMMUNICATE_HEADER_V3 with its HeaderGuid, Signature and Version fields properly populated. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Hao A Wu Cc: Marvin H=C3=A4user Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin --- Notes: v3: - Newly introduced v3 of communicate protocol =20 v4: - Rebased with uncrustify changes. MdePkg/Include/Protocol/MmCommunication3.h | 70 ++++++++++++++++++++ MdePkg/MdePkg.dec | 3 + 2 files changed, 73 insertions(+) diff --git a/MdePkg/Include/Protocol/MmCommunication3.h b/MdePkg/Include/Pr= otocol/MmCommunication3.h new file mode 100644 index 000000000000..0df9e5b875b7 --- /dev/null +++ b/MdePkg/Include/Protocol/MmCommunication3.h @@ -0,0 +1,70 @@ +/** @file + EFI MM Communication Protocol 2 as defined in the PI 1.7 errata A specif= ication. + + This protocol provides a means of communicating between drivers outside = of MM and MMI + handlers inside of MM. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2019, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_COMMUNICATION3_H_ +#define MM_COMMUNICATION3_H_ + +#include + +#define EFI_MM_COMMUNICATION3_PROTOCOL_GUID \ + { \ + 0xf7234a14, 0xdf2, 0x46c0, { 0xad, 0x28, 0x90, 0xe6, 0xb8, 0x83, 0xa7,= 0x2f } \ + } + +typedef struct _EFI_MM_COMMUNICATION3_PROTOCOL EFI_MM_COMMUNICATION3_PROTO= COL; + +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a reg= istered UEFI service. + + @param[in] This The EFI_MM_COMMUNICATION3_PROTOCOL i= nstance. + @param[in, out] CommBufferPhysical Physical address of the MM communica= tion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommBufferVirtual Virtual address of the MM communicat= ion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommSize The size of the data buffer being pa= ssed in. On exit, the size of data + being returned. Zero if the handler = does not wish to reply with any data. + This parameter is optional and may b= e NULL. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommB= ufferVirtual was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM i= mplementation. + If this error is returned, the Messa= geLength field + in the CommBuffer header or the inte= ger pointed by + CommSize, are updated to reflect the= maximum payload + size the implementation can accommod= ate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or C= ommSize parameter, + if not omitted, are in address range= that cannot be + accessed by the MM environment. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_MM_COMMUNICATE3)( + IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This, + IN OUT VOID *CommBufferPhysical, + IN OUT VOID *CommBufferVirtual, + IN OUT UINTN *CommSize OPTIONAL + ); + +/// +/// EFI MM Communication Protocol provides runtime services for communicat= ing +/// between DXE drivers and a registered MMI handler. +/// +struct _EFI_MM_COMMUNICATION3_PROTOCOL { + EFI_MM_COMMUNICATE3 Communicate; +}; + +extern EFI_GUID gEfiMmCommunication3ProtocolGuid; + +#endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 11c08e617511..8c61661e4ee7 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -1357,6 +1357,9 @@ [Protocols] ## Include/Protocol/MmCommunication2.h gEfiMmCommunication2ProtocolGuid =3D { 0x378daedc, 0xf06b, 0x4446, { 0x= 83, 0x14, 0x40, 0xab, 0x93, 0x3c, 0x87, 0xa3 }} =20 + ## Include/Protocol/MmCommunication3.h + gEfiMmCommunication3ProtocolGuid =3D { 0xf7234a14, 0xdf2, 0x46c0, { 0xa= d, 0x28, 0x90, 0xe6, 0xb8, 0x83, 0xa7, 0x2f }} + # # Protocols defined in UEFI2.1/UEFI2.0/EFI1.1 # --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85311): https://edk2.groups.io/g/devel/message/85311 Mute This Topic: https://groups.io/mt/88253682/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85312+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85312+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521748; cv=none; d=zohomail.com; s=zohoarc; b=TW2VPjVORzXs5/xdY0gR8wHwpPnI9IHzKMiHSvFAZ/Bf0+DmZz5vYQgxLNmPj9Ebti4Dras1Ya/SQxAKc6RRcTvGQfcNIAkK6puL21b4PLgJBdYarpF3FjkKzhN8DTPaxRybl2LiHnC9dbS1CeTQZ9u5J67y6Dy5rs5jytz8evA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521748; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=rVEwjzR0IlgIUjFldRDIq74et+9m9VoeUDLapaGJZQ0=; b=b3hA/8qtyh2BMaCTbOMI2guyk2PDK8Q6ngrXip4YQMXD+rPH2obeuxvYv23J8T9izbNZSrbH9OMJJPyRUIXYxGqu8YQ5647YzqzimbLOR7BlmYMtNkFprS2yaxwq7oD2NG1O8Tl5POr1w/hRi9g2RBZVbnO8cLQEqi3N/X9oEvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85312+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521748456708.0398964727112; Thu, 6 Jan 2022 18:15:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5UyBYY1788612xRBTEZSYep4; Thu, 06 Jan 2022 18:15:48 -0800 X-Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by mx.groups.io with SMTP id smtpd.web11.1479.1641521747425755944 for ; Thu, 06 Jan 2022 18:15:47 -0800 X-Received: by mail-pg1-f174.google.com with SMTP id g2so4171519pgo.9 for ; Thu, 06 Jan 2022 18:15:47 -0800 (PST) X-Gm-Message-State: OvLxfKOjyfhImTGEt23ImFu3x1787277AA= X-Google-Smtp-Source: ABdhPJz9swZccxr0nF/LjaiKHS/VaekeIq+HCMwvtC4g/2yrQhmHOHP0MMfCT+nOgvLH8HXSUK29Rg== X-Received: by 2002:a05:6a00:2401:b0:4bb:45fc:7829 with SMTP id z1-20020a056a00240100b004bb45fc7829mr63568406pfh.38.1641521746389; Thu, 06 Jan 2022 18:15:46 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:46 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Hao A Wu , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v4 4/7] MdePkg: MmCommunication: Introduce EFI_PEI_MM_COMMUNICATION3_PPI to MdePkg Date: Thu, 6 Jan 2022 18:15:29 -0800 Message-Id: <20220107021532.1322-5-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521748; bh=3tdh2zqL4tTSPulVpU8nQGEdt9TTX8QEX6hZBB5OBJI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=AlsrK8uo3PPbXVHIYDLlfRJsTZv1IxpYIEZN/iShnfH5NkzP1GAh0c8Hun6xPqIeF1l sfdCOYkmEeP1yEecidlAPBmqcTj8adZIxdyDPLVtsIpGZQq8nw8ogqg3UZ9zoZkC0z2Ut px9WPlJ/rZG5VPgAJi4yAScrPRh43QT6hRs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521750495100018 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 This change introduces a new definition for MM communicate PPI v3. This PPI will be installed under a new GUID in contrast to exisiting EFI_PEI_MM_COMMUNICATION_PPI. Data communicated to MM through EFI_PEI_MM_COMMUNICATION3_PPI should always start with EFI_MM_COMMUNICATE_HEADER_V3 with its HeaderGuid, Signature and Version fields properly populated. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Hao A Wu Cc: Marvin H=C3=A4user Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin --- Notes: v3: - Newly introduced v3 communicate PPI =20 v4: - Rebased with uncrustify changes. MdePkg/Include/Ppi/MmCommunication3.h | 57 ++++++++++++++++++++ MdePkg/MdePkg.dec | 3 ++ 2 files changed, 60 insertions(+) diff --git a/MdePkg/Include/Ppi/MmCommunication3.h b/MdePkg/Include/Ppi/MmC= ommunication3.h new file mode 100644 index 000000000000..1cc75c38c012 --- /dev/null +++ b/MdePkg/Include/Ppi/MmCommunication3.h @@ -0,0 +1,57 @@ +/** @file + EFI MM Communication v3 PPI definition. + + This Ppi provides a means of communicating between PEIM and MMI + handlers inside of MM. + +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. + +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_COMMUNICATION3_PPI_H_ +#define MM_COMMUNICATION3_PPI_H_ + +#include + +#define EFI_PEI_MM_COMMUNICATION3_PPI_GUID \ + { \ + 0xe70febf6, 0x13ef, 0x4a21, { 0x89, 0x9e, 0xb2, 0x36, 0xf8, 0x25, 0xff= , 0xc9 } \ + } + +typedef struct _EFI_PEI_MM_COMMUNICATION3_PPI EFI_PEI_MM_COMMUNICATION3_PP= I; + +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a reg= istered UEFI service. + + @param[in] This The EFI_PEI_MM_COMMUNICATE3 instance. + @param[in, out] CommBuffer A pointer to the buffer to convey into MM= RAM. + @param[in, out] CommSize The size of the data buffer being passed = in.On exit, the size of data + being returned. Zero if the handler does = not wish to reply with any data. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_PEI_MM_COMMUNICATE3)( + IN CONST EFI_PEI_MM_COMMUNICATION3_PPI *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize + ); + +/// +/// EFI MM Communication PPI provides runtime services for communicating +/// between DXE drivers and a registered SMI handler. +/// +struct _EFI_PEI_MM_COMMUNICATION3_PPI { + EFI_PEI_MM_COMMUNICATE3 Communicate; +}; + +extern EFI_GUID gEfiPeiMmCommunication3PpiGuid; + +#endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 8c61661e4ee7..cb42078fa330 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -1012,6 +1012,9 @@ [Ppis] ## Include/Ppi/DelayedDispatch.h gEfiPeiDelayedDispatchPpiGuid =3D { 0x869c711d, 0x649c, 0x44fe, { 0x8b,= 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }} =20 + ## Include/Ppi/MmCommunication3.h + gEfiPeiMmCommunication3PpiGuid =3D { 0xe70febf6, 0x13ef, 0x4a21, { 0x89,= 0x9e, 0xb2, 0x36, 0xf8, 0x25, 0xff, 0xc9 }} + [Protocols] ## Include/Protocol/Pcd.h gPcdProtocolGuid =3D { 0x11B34006, 0xD85B, 0x4D0A, { 0xA2,= 0x90, 0xD5, 0xA5, 0x71, 0x31, 0x0E, 0xF7 }} --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85312): https://edk2.groups.io/g/devel/message/85312 Mute This Topic: https://groups.io/mt/88253683/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85313+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85313+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521748; cv=none; d=zohomail.com; s=zohoarc; b=T7V8xJ2AZ6qy4+d2YLpT3ndPVevpjEhErKAR/Vg4lG5PRPjrbLhVI+RbK/pUrdb2wEoBTARdKyzn36DalgkUM13kW3+fGj/smJQePVF8vZBTHXcJyLUD9eIxjiRPKSx9/j12hd4amfmEy+DqwZ6aj3FnSczEmt47Xqx9WI3uVuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521748; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+AiYe/gZy/v7dcbuW3vTo8hxZc75RwY0Ob6zQVgxqZQ=; b=WrXZkGH1udtNoYDnQNC3P7UWExsm4vh3O106aHMiHkQWITW5tBelSVfz4BUjv6KNYj747JvDDpmJCDhDQc2ucfIU2nPJ7FKtTOV9wHtjxU0xM5rRdOB6kWDx4T0IqGoJfOo5Y8fCh+unbjcwYIXjlTFbroi5+lx5VryeugkQHng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85313+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521748759215.85793531607158; Thu, 6 Jan 2022 18:15:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9C8YYY1788612xLhPfGoZHIU; Thu, 06 Jan 2022 18:15:48 -0800 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web12.1454.1641521747461101721 for ; Thu, 06 Jan 2022 18:15:47 -0800 X-Received: by mail-pl1-f174.google.com with SMTP id l15so3779936pls.7 for ; Thu, 06 Jan 2022 18:15:47 -0800 (PST) X-Gm-Message-State: C9hquHblug9C0WcTHhUReSHOx1787277AA= X-Google-Smtp-Source: ABdhPJz8EcphtYUU79Z0Vu1A+vtuukFY3IiuxqfubatO//g2aSCk5yklyfN3KWUbQvpGi10GxHqOzw== X-Received: by 2002:a17:902:c40c:b0:149:7d72:15c5 with SMTP id k12-20020a170902c40c00b001497d7215c5mr49317789plk.133.1641521746963; Thu, 06 Jan 2022 18:15:46 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:46 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [edk2-devel] [PATCH v4 5/7] MdeModulePkg: PiSmmCore: Added parser of new MM communicate header Date: Thu, 6 Jan 2022 18:15:30 -0800 Message-Id: <20220107021532.1322-6-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521748; bh=X82aAkIe/P00QiLpvsi+u8QB5QLm0eBUpa1//ofsBTg=; h=Cc:Date:From:Reply-To:Subject:To; b=VhImcxZG7twnZhg5KxrKcuJyNrAUFG7VftClBpCbgxVwb5/NQkBhVdOcSt0v9/Dd5jl YzMBXD32aG+7V9ybso5FEnBaOQDK7XH7Zwz9APdv0S1M8MPbdyYquPzHnT0co0oWz1hfg hqjftlum36I4tVwOl7Wdf0DyMNEHZIbincs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521750529100021 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 MM communicate protocols are expanded with EFI_MM_COMMUNICATE_HEADER_V3 structure that cooperates with updated field types and flexible array. The PiSmmCore implementation is updated to detect and process incoming data accordingly. Two checks are also performed to prevent legacy communicate data or unsupported data is fed into MM core under agreed header guid. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin --- Notes: v3: - Newly added =20 v4: - Rebased with uncrusitify changes. MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 51 ++++++++++++++------ MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf | 1 + 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/Pi= SmmCore/PiSmmCore.c index 9e5c6cbe33dd..8d57f71dc969 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -647,12 +647,16 @@ SmmEntryPoint ( IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext ) { - EFI_STATUS Status; - EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader; - BOOLEAN InLegacyBoot; - BOOLEAN IsOverlapped; - VOID *CommunicationBuffer; - UINTN BufferSize; + EFI_STATUS Status; + EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader; + EFI_SMM_COMMUNICATE_HEADER *LegacyCommunicateHeader; + BOOLEAN InLegacyBoot; + BOOLEAN IsOverlapped; + VOID *CommunicationBuffer; + UINTN BufferSize; + EFI_GUID *CommGuid; + VOID *CommData; + UINTN CommHeaderSize; =20 // // Update SMST with contents of the SmmEntryContext structure @@ -708,19 +712,36 @@ SmmEntryPoint ( gSmmCorePrivate->CommunicationBuffer =3D NULL; gSmmCorePrivate->ReturnStatus =3D EFI_ACCESS_DENIED; } else { - CommunicateHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)CommunicationB= uffer; - BufferSize -=3D OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); - Status =3D SmiManage ( - &CommunicateHeader->HeaderGuid, - NULL, - CommunicateHeader->Data, - &BufferSize - ); + CommGuid =3D &((EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer= )->HeaderGuid; + // + // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 def= inition + // + if (CompareGuid (CommGuid, &gCommunicateHeaderV3Guid)) { + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER_V3 *)Communicat= ionBuffer; + ASSERT (CommunicateHeader->Signature =3D=3D EFI_MM_COMMUNICATE_H= EADER_V3_SIGNATURE); + ASSERT (CommunicateHeader->Version <=3D EFI_MM_COMMUNICATE_HEADE= R_V3_VERSION); + CommGuid =3D &CommunicateHeader->MessageGuid; + CommData =3D CommunicateHeader->MessageData; + CommHeaderSize =3D sizeof (EFI_MM_COMMUNICATE_HEADER_V3); + } else { + LegacyCommunicateHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)Commun= icationBuffer; + CommGuid =3D &LegacyCommunicateHeader->HeaderGuid; + CommData =3D LegacyCommunicateHeader->Data; + CommHeaderSize =3D OFFSET_OF (EFI_SMM_COMMUNICATE_HEADE= R, Data); + } + + BufferSize -=3D CommHeaderSize; + Status =3D SmiManage ( + CommGuid, + NULL, + CommData, + &BufferSize + ); // // Update CommunicationBuffer, BufferSize and ReturnStatus // Communicate service finished, reset the pointer to CommBuffer t= o NULL // - gSmmCorePrivate->BufferSize =3D BufferSize + OFFSET_OF (E= FI_SMM_COMMUNICATE_HEADER, Data); + gSmmCorePrivate->BufferSize =3D BufferSize + CommHeaderSi= ze; gSmmCorePrivate->CommunicationBuffer =3D NULL; gSmmCorePrivate->ReturnStatus =3D (Status =3D=3D EFI_SUCCES= S) ? EFI_SUCCESS : EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/= PiSmmCore/PiSmmCore.inf index c8bfae3860fc..5a0929a45e19 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -118,6 +118,7 @@ [Guids] gSmiHandlerProfileGuid gEdkiiEndOfS3ResumeGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol gEdkiiS3SmmInitDoneGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol + gCommunicateHeaderV3Guid ## CONSUMES ## GUID # Communicate header =20 [UserExtensions.TianoCore."ExtraFiles"] PiSmmCoreExtra.uni --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85313): https://edk2.groups.io/g/devel/message/85313 Mute This Topic: https://groups.io/mt/88253684/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85314+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85314+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521749; cv=none; d=zohomail.com; s=zohoarc; b=AE4LmUrTnLJ8U1Zby5ZCsi5ePhc3CMIAHGKGnGRUrvG7hAjBX7KYGoDuIiyW/caLC4JwY/xKyfyTkzOZrBzZehWPIQ/qVX2cXbh1EEqkSV9iD8oVyT+QRr+fnn0ZzyuaqqsIMDQ7L/Y65XtCGlMsTLM0xLuz+p8nf+dTwyx3KxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521749; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zhaQ37dWp1gujyZfXg6PNm5shw7FmXp4h2i7BhDQNI0=; b=GuacOaxxfLUASUHAnlO49I8j/gt5OxdKo2xJMhWSML8XNGBvwca6tRRnLVSOQweFQnsxxHWO56IdP1QpxMhiYlj4xAN8SBxtCL7DubB/adrcgZF1IBuFYCWhxI0F2XnkMnec2S7udPYhW9oAptootGz24RWhI2HFA0xE2RDC5CE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85314+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521749817180.46008640151035; Thu, 6 Jan 2022 18:15:49 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q78HYY1788612xLCm81XmMcd; Thu, 06 Jan 2022 18:15:49 -0800 X-Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web10.1546.1641521748107375532 for ; Thu, 06 Jan 2022 18:15:48 -0800 X-Received: by mail-pg1-f169.google.com with SMTP id z30so689709pge.4 for ; Thu, 06 Jan 2022 18:15:48 -0800 (PST) X-Gm-Message-State: zeaMduFDepmbLSxl0RuudDzjx1787277AA= X-Google-Smtp-Source: ABdhPJyenkgoDnVamXjCIThmrrqRPHaHUqQg7+bWcMZSYFRzmGzebfZa9xxXfj/6+fz4QWhoMCsEqA== X-Received: by 2002:aa7:8541:0:b0:4bb:b0f2:6134 with SMTP id y1-20020aa78541000000b004bbb0f26134mr57007038pfn.37.1641521747564; Thu, 06 Jan 2022 18:15:47 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:47 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh Subject: [edk2-devel] [PATCH v4 6/7] StandaloneMmPkg: StandaloneMmCore: Parsing new MM communicate header Date: Thu, 6 Jan 2022 18:15:31 -0800 Message-Id: <20220107021532.1322-7-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521749; bh=O4tyfOhLLPNXbmT/At0DJH/SMCSbf9bxL8LBIt3H7V0=; h=Cc:Date:From:Reply-To:Subject:To; b=VBKRbR7vPz80itKrASdEyoHrJIgkk6S4lHElErGamyJXh2h4D59Nx52ChibuS2WPINr V59UbHjlCJLtShfleuTSzosL9v1kdXH6Y57U8aUFQwLYeM4O6OcOaqPVed4zfKxuKApNC k+8X/OcuqkXjPE43rpSuN3ow6VpScv5/F3U= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521750498100019 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 MM communicate protocols are expanded with EFI_MM_COMMUNICATE_HEADER_V3 structure that cooperates with updated field types and flexible array. The PiSmmCore implementation is updated to detect and process incoming data accordingly. Two checks are also performed to prevent legacy communicate data or unsupported data is fed into MM core under agreed header guid. Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Jiewen Yao Cc: Supreeth Venkatesh Signed-off-by: Kun Qin --- Notes: v3: - Newly added =20 v4: - Rebased with uncrusitify changes. StandaloneMmPkg/Core/StandaloneMmCore.c | 35 ++++++++++++++++---- StandaloneMmPkg/Core/StandaloneMmCore.inf | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core= /StandaloneMmCore.c index d221f1d1115d..8afb22493cb2 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.c +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c @@ -338,8 +338,12 @@ MmEntryPoint ( IN CONST EFI_MM_ENTRY_CONTEXT *MmEntryContext ) { - EFI_STATUS Status; - EFI_MM_COMMUNICATE_HEADER *CommunicateHeader; + EFI_STATUS Status; + EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *LegacyCommunicateHeader; + EFI_GUID *CommGuid; + VOID *CommData; + UINTN CommHeaderSize; =20 DEBUG ((DEBUG_INFO, "MmEntryPoint ...\n")); =20 @@ -377,19 +381,36 @@ MmEntryPoint ( gMmCorePrivate->CommunicationBuffer =3D 0; gMmCorePrivate->ReturnStatus =3D EFI_INVALID_PARAMETER; } else { - CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)(UINTN)= gMmCorePrivate->CommunicationBuffer; - gMmCorePrivate->BufferSize -=3D OFFSET_OF (EFI_MM_COMMUNICATE_HEADER= , Data); + CommGuid =3D &((EFI_MM_COMMUNICATE_HEADER_V3 *)(UINTN)gMmCorePrivate= ->CommunicationBuffer)->HeaderGuid; + // + // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 defin= ition + // + if (CompareGuid (CommGuid, &gCommunicateHeaderV3Guid)) { + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER_V3 *)(UINTN)gMmCo= rePrivate->CommunicationBuffer; + ASSERT (CommunicateHeader->Signature =3D=3D EFI_MM_COMMUNICATE_HEA= DER_V3_SIGNATURE); + ASSERT (CommunicateHeader->Version <=3D EFI_MM_COMMUNICATE_HEADER_= V3_VERSION); + CommGuid =3D &CommunicateHeader->MessageGuid; + CommData =3D CommunicateHeader->MessageData; + CommHeaderSize =3D sizeof (EFI_MM_COMMUNICATE_HEADER_V3); + } else { + LegacyCommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)(UINTN)gM= mCorePrivate->CommunicationBuffer; + CommGuid =3D &LegacyCommunicateHeader->HeaderGuid; + CommData =3D LegacyCommunicateHeader->Data; + CommHeaderSize =3D OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, = Data); + } + + gMmCorePrivate->BufferSize -=3D CommHeaderSize; Status =3D MmiManage ( - &CommunicateHeader->HeaderGuid, + CommGuid, NULL, - CommunicateHeader->Data, + CommData, (UINTN *)&gMmCorePrivate->BufferSize ); // // Update CommunicationBuffer, BufferSize and ReturnStatus // Communicate service finished, reset the pointer to CommBuffer to = NULL // - gMmCorePrivate->BufferSize +=3D OFFSET_OF (EFI_MM_COMMUNICAT= E_HEADER, Data); + gMmCorePrivate->BufferSize +=3D CommHeaderSize; gMmCorePrivate->CommunicationBuffer =3D 0; gMmCorePrivate->ReturnStatus =3D (Status =3D=3D EFI_SUCCESS) = ? EFI_SUCCESS : EFI_NOT_FOUND; } diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Co= re/StandaloneMmCore.inf index c44b9ff33303..e2e6cd32beee 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf @@ -75,6 +75,7 @@ [Guids] gEfiEventLegacyBootGuid gEfiEventExitBootServicesGuid gEfiEventReadyToBootGuid + gCommunicateHeaderV3Guid ## CONSUMES ## GUID # Communicate header =20 # # This configuration fails for CLANGPDB, which does not support PIE in the= GCC --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85314): https://edk2.groups.io/g/devel/message/85314 Mute This Topic: https://groups.io/mt/88253685/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 18:57:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85315+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85315+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641521750; cv=none; d=zohomail.com; s=zohoarc; b=WKhTsgPMjomNnP1ffVozgrQ0v2iMgOmF12fayiiROfwYCyeyDlafubQer28OUD8H7oWJ8kOULoRpVO2Xm55Y6RA1dYq/hqZHr/QSZ5aZ42ytpv1tvrjwglEHjIxfSSxL07XfMF+FX/OTS1UBK/1BhBP/NoYEUOIFHAyKQaEpVlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641521750; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=RBWs25naZWbM/x57tFRsio2+3FrcWpHTGQga3wqc4L4=; b=dp6KdsIqbdhORcuAlHXcdUmm/xyY3vSfIvvSZX7UdP0IeEV9dHzJJPFlhOZ0xnS908I8fhEY2AzJQjuyru5Fd61Op7C4Oz6eubx4R6Glp/scXUJGH5UjkofbkB3OoJl95TFlYHa0Twdocf4lgro0s5w0knazg7EAd4xUXpplAOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+85315+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1641521750203457.86680701372313; Thu, 6 Jan 2022 18:15:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kazJYY1788612xzW43EAayCp; Thu, 06 Jan 2022 18:15:49 -0800 X-Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mx.groups.io with SMTP id smtpd.web08.1507.1641521749147974069 for ; Thu, 06 Jan 2022 18:15:49 -0800 X-Received: by mail-pl1-f182.google.com with SMTP id z3so3781905plg.8 for ; Thu, 06 Jan 2022 18:15:49 -0800 (PST) X-Gm-Message-State: DEoH5jwSIW8SctGo8gvbfetTx1787277AA= X-Google-Smtp-Source: ABdhPJwEth6429jIr7+Bv8hEFH/P+MQ2c6tCRGnNxnO+M2zU0Mw1U54zbeXEhucPqvpihWpXGu2mAQ== X-Received: by 2002:a17:903:22c1:b0:148:c3cc:54c6 with SMTP id y1-20020a17090322c100b00148c3cc54c6mr63546310plg.98.1641521748559; Thu, 06 Jan 2022 18:15:48 -0800 (PST) X-Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:48 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [edk2-devel] [PATCH v4 7/7] MdeModulePkg: PiSmmIpl: Update MessageLength calculation for MmCommunicate Date: Thu, 6 Jan 2022 18:15:32 -0800 Message-Id: <20220107021532.1322-8-kuqin12@gmail.com> In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1641521749; bh=7V3GuZAQQ6tCSXFZqpU5MlaaRV0l49odbB2bNJwCDKc=; h=Cc:Date:From:Reply-To:Subject:To; b=G9/so3TIJql3UBjvtjnMU2+0jknYwAydtRw3C271ryU0Q5q9VIhQHxoXbDxro1hK+gQ 8qP2lwIUeF0fCnTb8iXWQhv4Oa2JXklThyJfWax9PcFedCbY6Ap1hNFoSAQY67mLM7bP5 uF71izMT3qNyXotmC139J4ADe4FHUESHv24= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1641521752530100029 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3430 This change added support of installing `EFI_MM_COMMUNICATION3_PROTOCOL`. MmCommunicate v3 routine that calculates message length is also updated to remove ambiguity in contrast to v1 routine. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin --- Notes: v3: - Newly added v3 communicate protocol instance =20 v4: - Rebased with uncrustify changes. MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 190 ++++++++++++++++++++ MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf | 2 + 2 files changed, 192 insertions(+) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiS= mmCore/PiSmmIpl.c index 4f00cebaf5ed..910f54bed5fb 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include =20 #include "PiSmmCorePrivateData.h" =20 @@ -146,6 +148,41 @@ SmmCommunicationMmCommunicate2 ( IN OUT UINTN *CommSize OPTIONAL ); =20 +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a reg= istered UEFI service. + + @param[in] This The EFI_MM_COMMUNICATION3_PROTOCOL i= nstance. + @param[in, out] CommBufferPhysical Physical address of the MM communica= tion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommBufferVirtual Virtual address of the MM communicat= ion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommSize The size of the data buffer being pa= ssed in. On exit, the size of data + being returned. Zero if the handler = does not wish to reply with any data. + This parameter is optional and may b= e NULL. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommB= ufferVirtual was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM i= mplementation. + If this error is returned, the Messa= geLength field + in the CommBuffer header or the inte= ger pointed by + CommSize, are updated to reflect the= maximum payload + size the implementation can accommod= ate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or C= ommSize parameter, + if not omitted, are in address range= that cannot be + accessed by the MM environment. + +**/ +EFI_STATUS +EFIAPI +MmCommunicationMmCommunicate3 ( + IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This, + IN OUT VOID *CommBufferPhysical, + IN OUT VOID *CommBufferVirtual, + IN OUT UINTN *CommSize OPTIONAL + ); + /** Event notification that is fired every time a gEfiSmmConfigurationProtoc= ol installs. =20 @@ -275,6 +312,13 @@ EFI_MM_COMMUNICATION2_PROTOCOL mMmCommunication2 =3D { SmmCommunicationMmCommunicate2 }; =20 +// +// PI 1.7 MM Communication Protocol 3 instance +// +EFI_MM_COMMUNICATION3_PROTOCOL mMmCommunication3 =3D { + MmCommunicationMmCommunicate3 +}; + // // SMM Core Private Data structure that contains the data shared between // the SMM IPL and the SMM Core. @@ -651,6 +695,150 @@ SmmCommunicationMmCommunicate2 ( ); } =20 +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a reg= istered UEFI service. + + @param[in] This The EFI_MM_COMMUNICATION3_PROTOCOL i= nstance. + @param[in, out] CommBufferPhysical Physical address of the MM communica= tion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommBufferVirtual Virtual address of the MM communicat= ion buffer, of which content must + start with EFI_MM_COMMUNICATE_HEADER= _V3. + @param[in, out] CommSize The size of the data buffer being pa= ssed in. On exit, the size of data + being returned. Zero if the handler = does not wish to reply with any data. + This parameter is optional and may b= e NULL. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommB= ufferVirtual was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM i= mplementation. + If this error is returned, the Messa= geLength field + in the CommBuffer header or the inte= ger pointed by + CommSize, are updated to reflect the= maximum payload + size the implementation can accommod= ate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or C= ommSize parameter, + if not omitted, are in address range= that cannot be + accessed by the MM environment. + +**/ +EFI_STATUS +EFIAPI +MmCommunicationMmCommunicate3 ( + IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This, + IN OUT VOID *CommBufferPhysical, + IN OUT VOID *CommBufferVirtual, + IN OUT UINTN *CommSize OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader; + BOOLEAN OldInSmm; + UINTN TempCommSize; + UINT64 LongCommSize; + + // + // Check parameters + // + if (CommBufferPhysical =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER_V3 *)CommBufferPhysical; + + if (CommSize =3D=3D NULL) { + Status =3D SafeUint64Add (sizeof (EFI_MM_COMMUNICATE_HEADER_V3), Commu= nicateHeader->MessageSize, &LongCommSize); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D SafeUint64ToUintn (LongCommSize, &TempCommSize); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + } else { + TempCommSize =3D *CommSize; + // + // CommSize must hold the entire EFI_MM_COMMUNICATE_HEADER_V3 + // + if (TempCommSize < sizeof (EFI_MM_COMMUNICATE_HEADER_V3)) { + return EFI_INVALID_PARAMETER; + } + } + + // + // If not already in SMM, then generate a Software SMI + // + if (!gSmmCorePrivate->InSmm && gSmmCorePrivate->SmmEntryPointRegistered)= { + // + // Put arguments for Software SMI in gSmmCorePrivate + // + gSmmCorePrivate->CommunicationBuffer =3D CommBufferPhysical; + gSmmCorePrivate->BufferSize =3D TempCommSize; + + // + // Generate Software SMI + // + Status =3D mSmmControl2->Trigger (mSmmControl2, NULL, NULL, FALSE, 0); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Return status from software SMI + // + if (CommSize !=3D NULL) { + *CommSize =3D gSmmCorePrivate->BufferSize; + } + + return gSmmCorePrivate->ReturnStatus; + } + + // + // If we are in SMM, then the execution mode must be physical, which mea= ns that + // OS established virtual addresses can not be used. If SetVirtualAddre= ssMap() + // has been called, then a direct invocation of the Software SMI is not = allowed, + // so return EFI_INVALID_PARAMETER. + // + if (EfiGoneVirtual ()) { + return EFI_INVALID_PARAMETER; + } + + // + // If we are not in SMM, don't allow call SmiManage() directly when SMRA= M is closed or locked. + // + if ((!gSmmCorePrivate->InSmm) && (!mSmmAccess->OpenState || mSmmAccess->= LockState)) { + return EFI_INVALID_PARAMETER; + } + + // + // Save current InSmm state and set InSmm state to TRUE + // + OldInSmm =3D gSmmCorePrivate->InSmm; + gSmmCorePrivate->InSmm =3D TRUE; + + // + // Before SetVirtualAddressMap(), we are in SMM or SMRAM is open and unl= ocked, call SmiManage() directly. + // + TempCommSize -=3D sizeof (EFI_MM_COMMUNICATE_HEADER_V3); + Status =3D gSmmCorePrivate->Smst->SmiManage ( + &CommunicateHeader->MessageGuid, + NULL, + CommunicateHeader->MessageData, + &TempCommSize + ); + TempCommSize +=3D sizeof (EFI_MM_COMMUNICATE_HEADER_V3); + if (CommSize !=3D NULL) { + *CommSize =3D TempCommSize; + } + + // + // Restore original InSmm state + // + gSmmCorePrivate->InSmm =3D OldInSmm; + + return (Status =3D=3D EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND; +} + /** Event notification that is fired when GUIDed Event Group is signaled. =20 @@ -1859,6 +2047,8 @@ SmmIplEntry ( &mSmmCommunication, &gEfiMmCommunication2ProtocolGuid, &mMmCommunication2, + &gEfiMmCommunication3ProtocolGuid, + &mMmCommunication3, NULL ); ASSERT_EFI_ERROR (Status); diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/P= iSmmCore/PiSmmIpl.inf index 6109d6b5449c..afab228cc04c 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf @@ -46,11 +46,13 @@ [LibraryClasses] DxeServicesLib PcdLib ReportStatusCodeLib + SafeIntLib =20 [Protocols] gEfiSmmBase2ProtocolGuid ## PRODUCES gEfiSmmCommunicationProtocolGuid ## PRODUCES gEfiMmCommunication2ProtocolGuid ## PRODUCES + gEfiMmCommunication3ProtocolGuid ## PRODUCES gEfiSmmAccess2ProtocolGuid ## CONSUMES ## NOTIFY ## CONSUMES --=20 2.34.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#85315): https://edk2.groups.io/g/devel/message/85315 Mute This Topic: https://groups.io/mt/88253688/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-