From: Star Zeng <star.zeng@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Baraneedharan Anbazhagan <anbazhagan@hp.com>
Subject: [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion for COMM buffer
Date: Fri, 21 Jul 2017 14:40:21 +0800 [thread overview]
Message-ID: <1500619221-300708-1-git-send-email-star.zeng@intel.com> (raw)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=593
Currently, SmmCommunciate fails in RestoreLockBox after
SmmReadyToLock since COMM buffer is in stack instead of
using SmmCommRegion by gEdkiiPiSmmCommunicationRegionTableGuid.
This patch is to get SmmCommRegion by
gEdkiiPiSmmCommunicationRegionTableGuid for COMM buffer
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Baraneedharan Anbazhagan <anbazhagan@hp.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
.../Library/SmmLockBoxLib/SmmLockBoxDxeLib.c | 199 +++++++++++++++------
.../Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf | 6 +-
2 files changed, 147 insertions(+), 58 deletions(-)
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
index 9659f014e937..b75f81e69e04 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
@@ -1,6 +1,6 @@
/** @file
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
@@ -20,11 +20,108 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/BaseMemoryLib.h>
#include <Library/LockBoxLib.h>
#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
#include <Protocol/SmmCommunication.h>
#include <Guid/SmmLockBox.h>
+#include <Guid/PiSmmCommunicationRegionTable.h>
#include "SmmLockBoxLibPrivate.h"
+EFI_SMM_COMMUNICATION_PROTOCOL *mLockBoxSmmCommProtocol = NULL;
+UINT8 *mLockBoxSmmCommBuffer = NULL;
+
+/**
+ Get smm communication protocol for lockbox.
+
+ @return Pointer to smm communication protocol, NULL if not found.
+
+**/
+EFI_SMM_COMMUNICATION_PROTOCOL *
+LockBoxGetSmmCommProtocol (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // If the protocol has been got previously, return it.
+ //
+ if (mLockBoxSmmCommProtocol != NULL) {
+ return mLockBoxSmmCommProtocol;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiSmmCommunicationProtocolGuid,
+ NULL,
+ (VOID **)&mLockBoxSmmCommProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ mLockBoxSmmCommProtocol = NULL;
+ }
+ return mLockBoxSmmCommProtocol;
+}
+
+/**
+ Get smm communication buffer for lockbox.
+
+ @return Pointer to smm communication buffer, NULL if not found.
+
+**/
+UINT8 *
+LockBoxGetSmmCommBuffer (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN MinimalSizeNeeded;
+ EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
+ UINT32 Index;
+ EFI_MEMORY_DESCRIPTOR *Entry;
+ UINTN Size;
+
+ //
+ // If the buffer has been got previously, return it.
+ //
+ if (mLockBoxSmmCommBuffer != NULL) {
+ return mLockBoxSmmCommBuffer;
+ }
+
+ MinimalSizeNeeded = sizeof (EFI_GUID) +
+ sizeof (UINTN) +
+ MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE),
+ MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES),
+ MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE),
+ MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE),
+ sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)))));
+
+ Status = EfiGetSystemConfigurationTable (
+ &gEdkiiPiSmmCommunicationRegionTableGuid,
+ (VOID **) &PiSmmCommunicationRegionTable
+ );
+ if (EFI_ERROR (Status)) {
+ mLockBoxSmmCommBuffer = NULL;
+ return mLockBoxSmmCommBuffer;
+ }
+ ASSERT (PiSmmCommunicationRegionTable != NULL);
+ Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1);
+ Size = 0;
+ for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
+ if (Entry->Type == EfiConventionalMemory) {
+ Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages);
+ if (Size >= MinimalSizeNeeded) {
+ break;
+ }
+ }
+ Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize);
+ }
+ if (Index >= PiSmmCommunicationRegionTable->NumberOfEntries) {
+ mLockBoxSmmCommBuffer = NULL;
+ } else {
+ mLockBoxSmmCommBuffer = (UINT8 *) (UINTN) Entry->PhysicalStart;
+ }
+ return mLockBoxSmmCommBuffer;
+}
+
/**
This function will save confidential information to lockbox.
@@ -52,7 +149,8 @@ SaveLockBox (
EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave;
EFI_SMM_COMMUNICATE_HEADER *CommHeader;
- UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];
+ UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];
+ UINT8 *CommBuffer;
UINTN CommSize;
DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SaveLockBox - Enter\n"));
@@ -64,21 +162,18 @@ SaveLockBox (
return EFI_INVALID_PARAMETER;
}
- //
- // Get needed resource
- //
- Status = gBS->LocateProtocol (
- &gEfiSmmCommunicationProtocolGuid,
- NULL,
- (VOID **)&SmmCommunication
- );
- if (EFI_ERROR (Status)) {
+ SmmCommunication = LockBoxGetSmmCommProtocol ();
+ if (SmmCommunication == NULL) {
return EFI_NOT_STARTED;
}
//
// Prepare parameter
//
+ CommBuffer = LockBoxGetSmmCommBuffer ();
+ if (CommBuffer == NULL) {
+ CommBuffer = &TempCommBuffer[0];
+ }
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
CommHeader->MessageLength = sizeof(*LockBoxParameterSave);
@@ -94,7 +189,7 @@ SaveLockBox (
//
// Send command
//
- CommSize = sizeof(CommBuffer);
+ CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE);
Status = SmmCommunication->Communicate (
SmmCommunication,
&CommBuffer[0],
@@ -136,7 +231,8 @@ SetLockBoxAttributes (
EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes;
EFI_SMM_COMMUNICATE_HEADER *CommHeader;
- UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)];
+ UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)];
+ UINT8 *CommBuffer;
UINTN CommSize;
DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SetLockBoxAttributes - Enter\n"));
@@ -149,21 +245,18 @@ SetLockBoxAttributes (
return EFI_INVALID_PARAMETER;
}
- //
- // Get needed resource
- //
- Status = gBS->LocateProtocol (
- &gEfiSmmCommunicationProtocolGuid,
- NULL,
- (VOID **)&SmmCommunication
- );
- if (EFI_ERROR (Status)) {
+ SmmCommunication = LockBoxGetSmmCommProtocol ();
+ if (SmmCommunication == NULL) {
return EFI_NOT_STARTED;
}
//
// Prepare parameter
//
+ CommBuffer = LockBoxGetSmmCommBuffer ();
+ if (CommBuffer == NULL) {
+ CommBuffer = &TempCommBuffer[0];
+ }
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
CommHeader->MessageLength = sizeof(*LockBoxParameterSetAttributes);
@@ -178,7 +271,7 @@ SetLockBoxAttributes (
//
// Send command
//
- CommSize = sizeof(CommBuffer);
+ CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES);
Status = SmmCommunication->Communicate (
SmmCommunication,
&CommBuffer[0],
@@ -225,7 +318,8 @@ UpdateLockBox (
EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate;
EFI_SMM_COMMUNICATE_HEADER *CommHeader;
- UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)];
+ UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)];
+ UINT8 *CommBuffer;
UINTN CommSize;
DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib UpdateLockBox - Enter\n"));
@@ -237,21 +331,18 @@ UpdateLockBox (
return EFI_INVALID_PARAMETER;
}
- //
- // Get needed resource
- //
- Status = gBS->LocateProtocol (
- &gEfiSmmCommunicationProtocolGuid,
- NULL,
- (VOID **)&SmmCommunication
- );
- if (EFI_ERROR (Status)) {
+ SmmCommunication = LockBoxGetSmmCommProtocol ();
+ if (SmmCommunication == NULL) {
return EFI_NOT_STARTED;
}
//
// Prepare parameter
//
+ CommBuffer = LockBoxGetSmmCommBuffer ();
+ if (CommBuffer == NULL) {
+ CommBuffer = &TempCommBuffer[0];
+ }
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
CommHeader->MessageLength = sizeof(*LockBoxParameterUpdate);
@@ -268,7 +359,7 @@ UpdateLockBox (
//
// Send command
//
- CommSize = sizeof(CommBuffer);
+ CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE);
Status = SmmCommunication->Communicate (
SmmCommunication,
&CommBuffer[0],
@@ -316,7 +407,8 @@ RestoreLockBox (
EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore;
EFI_SMM_COMMUNICATE_HEADER *CommHeader;
- UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)];
+ UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)];
+ UINT8 *CommBuffer;
UINTN CommSize;
DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreLockBox - Enter\n"));
@@ -330,21 +422,18 @@ RestoreLockBox (
return EFI_INVALID_PARAMETER;
}
- //
- // Get needed resource
- //
- Status = gBS->LocateProtocol (
- &gEfiSmmCommunicationProtocolGuid,
- NULL,
- (VOID **)&SmmCommunication
- );
- if (EFI_ERROR (Status)) {
+ SmmCommunication = LockBoxGetSmmCommProtocol ();
+ if (SmmCommunication == NULL) {
return EFI_NOT_STARTED;
}
//
// Prepare parameter
//
+ CommBuffer = LockBoxGetSmmCommBuffer ();
+ if (CommBuffer == NULL) {
+ CommBuffer = &TempCommBuffer[0];
+ }
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
CommHeader->MessageLength = sizeof(*LockBoxParameterRestore);
@@ -364,7 +453,7 @@ RestoreLockBox (
//
// Send command
//
- CommSize = sizeof(CommBuffer);
+ CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE);
Status = SmmCommunication->Communicate (
SmmCommunication,
&CommBuffer[0],
@@ -403,26 +492,24 @@ RestoreAllLockBoxInPlace (
EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestoreAllInPlace;
EFI_SMM_COMMUNICATE_HEADER *CommHeader;
- UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)];
+ UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)];
+ UINT8 *CommBuffer;
UINTN CommSize;
DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n"));
- //
- // Get needed resource
- //
- Status = gBS->LocateProtocol (
- &gEfiSmmCommunicationProtocolGuid,
- NULL,
- (VOID **)&SmmCommunication
- );
- if (EFI_ERROR (Status)) {
+ SmmCommunication = LockBoxGetSmmCommProtocol ();
+ if (SmmCommunication == NULL) {
return EFI_NOT_STARTED;
}
//
// Prepare parameter
//
+ CommBuffer = LockBoxGetSmmCommBuffer ();
+ if (CommBuffer == NULL) {
+ CommBuffer = &TempCommBuffer[0];
+ }
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
CommHeader->MessageLength = sizeof(*LockBoxParameterRestoreAllInPlace);
@@ -435,7 +522,7 @@ RestoreAllLockBoxInPlace (
//
// Send command
//
- CommSize = sizeof(CommBuffer);
+ CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE);
Status = SmmCommunication->Communicate (
SmmCommunication,
&CommBuffer[0],
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
index 48cdb9c66ab7..f3120ccb42d5 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
@@ -1,7 +1,7 @@
## @file
# DXE LockBox library instance.
#
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions
@@ -42,9 +42,11 @@ [LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
+ UefiLib
[Guids]
- gEfiSmmLockBoxCommunicationGuid ## SOMETIMES_CONSUMES ## GUID # Used to do smm communication
+ gEfiSmmLockBoxCommunicationGuid ## SOMETIMES_CONSUMES ## GUID # Used to do smm communication
+ gEdkiiPiSmmCommunicationRegionTableGuid ## SOMETIMES_CONSUMES ## SystemTable
[Protocols]
gEfiSmmCommunicationProtocolGuid ## SOMETIMES_CONSUMES
--
2.7.0.windows.1
next reply other threads:[~2017-07-21 6:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 6:40 Star Zeng [this message]
2017-07-26 2:51 ` [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion for COMM buffer Yao, Jiewen
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=1500619221-300708-1-git-send-email-star.zeng@intel.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