From: "Kun Qin" <kuqin12@gmail.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
Sami Mujawar <sami.mujawar@arm.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Subject: [PATCH v3 6/7] StandaloneMmPkg: StandaloneMmCore: Parsing new MM communicate header
Date: Mon, 16 Aug 2021 22:08:06 -0700 [thread overview]
Message-ID: <20210817050807.766-7-kuqin12@gmail.com> (raw)
In-Reply-To: <20210817050807.766-1-kuqin12@gmail.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3430
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 <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
Notes:
v3:
- Newly added
StandaloneMmPkg/Core/StandaloneMmCore.c | 34 ++++++++++++++++----
StandaloneMmPkg/Core/StandaloneMmCore.inf | 1 +
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core/StandaloneMmCore.c
index fbb0ec75e557..000aca098cc8 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.c
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
@@ -340,8 +340,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;
DEBUG ((DEBUG_INFO, "MmEntryPoint ...\n"));
@@ -379,19 +383,35 @@ MmEntryPoint (
gMmCorePrivate->CommunicationBuffer = 0;
gMmCorePrivate->ReturnStatus = EFI_INVALID_PARAMETER;
} else {
- CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)gMmCorePrivate->CommunicationBuffer;
- gMmCorePrivate->BufferSize -= OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
+ CommGuid = &((EFI_MM_COMMUNICATE_HEADER_V3 *)(UINTN)gMmCorePrivate->CommunicationBuffer)->HeaderGuid;
+ //
+ // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 definition
+ //
+ if (CompareGuid (CommGuid, &gCommunicateHeaderV3Guid)) {
+ CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER_V3 *)(UINTN)gMmCorePrivate->CommunicationBuffer;
+ ASSERT (CommunicateHeader->Signature == EFI_MM_COMMUNICATE_HEADER_V3_SIGNATURE);
+ ASSERT (CommunicateHeader->Version <= EFI_MM_COMMUNICATE_HEADER_V3_VERSION);
+ CommGuid = &CommunicateHeader->MessageGuid;
+ CommData = CommunicateHeader->MessageData;
+ CommHeaderSize = sizeof (EFI_MM_COMMUNICATE_HEADER_V3);
+ } else {
+ LegacyCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)gMmCorePrivate->CommunicationBuffer;
+ CommGuid = &LegacyCommunicateHeader->HeaderGuid;
+ CommData = LegacyCommunicateHeader->Data;
+ CommHeaderSize = OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
+ }
+ gMmCorePrivate->BufferSize -= CommHeaderSize;
Status = 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 += OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
+ gMmCorePrivate->BufferSize += CommHeaderSize;
gMmCorePrivate->CommunicationBuffer = 0;
gMmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Core/StandaloneMmCore.inf
index 56042b7b39f4..41a49e23fa8f 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.inf
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf
@@ -75,6 +75,7 @@ [Guids]
gEfiEventLegacyBootGuid
gEfiEventExitBootServicesGuid
gEfiEventReadyToBootGuid
+ gCommunicateHeaderV3Guid ## CONSUMES ## GUID # Communicate header
[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fpie
--
2.32.0.windows.1
next prev parent reply other threads:[~2021-08-17 5:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 5:08 [PATCH v3 0/7] New MM Communicate header and interfaces Kun Qin
2021-08-17 5:08 ` [PATCH v3 1/7] EDK2 Code First: PI Specification: New communicate " Kun Qin
2021-08-17 5:08 ` [PATCH v3 2/7] MdePkg: MmCommunication: Introduce EFI_MM_COMMUNICATE_HEADER_V3 to MdePkg Kun Qin
2021-08-17 5:50 ` [edk2-devel] " Ni, Ray
2021-08-17 6:00 ` Kun Qin
2021-08-17 5:08 ` [PATCH v3 3/7] MdePkg: MmCommunication: Introduce EFI_MM_COMMUNICATION3_PROTOCOL " Kun Qin
2021-08-17 5:08 ` [PATCH v3 4/7] MdePkg: MmCommunication: Introduce EFI_PEI_MM_COMMUNICATION3_PPI " Kun Qin
2021-08-17 5:08 ` [PATCH v3 5/7] MdeModulePkg: PiSmmCore: Added parser of new MM communicate header Kun Qin
2021-08-17 5:08 ` Kun Qin [this message]
2021-08-17 5:08 ` [PATCH v3 7/7] MdeModulePkg: PiSmmIpl: Update MessageLength calculation for MmCommunicate Kun Qin
2021-09-16 2:15 ` [edk2-devel] [PATCH v3 0/7] New MM Communicate header and interfaces Kun Qin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210817050807.766-7-kuqin12@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox