From nobody Mon Feb 9 09:33:42 2026 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-