public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.
@ 2017-03-10  7:35 Jiewen Yao
  2017-03-10  7:35 ` [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister Jiewen Yao
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jiewen Yao @ 2017-03-10  7:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan, Feng Tian, Star Zeng, Bret Barkelew

This issue is reported by Bret.Barkelew@microsoft.com.

We observe that a platform may use same Handler
for different context.

In order to support Unregister such handler, we have to input
context information as well.


The patch does not impact any platform with SmiHandlerProfile disabled.

Unit tests below:
1) register same handler with different context, and unregister each.
2) register and unregister UsbContext.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>

Jiewen Yao (3):
  MdePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister.

 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                |   8 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                        | 103 ++++++++++++++++----
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                          |  41 +++++++-
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c |  10 +-
 MdePkg/Include/Library/SmiHandlerProfileLib.h                          |   8 +-
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c     |   8 +-
 6 files changed, 151 insertions(+), 27 deletions(-)

-- 
2.7.4.windows.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister
  2017-03-10  7:35 [PATCH 0/3] Add Context in SmiHandlerProfileUnregister Jiewen Yao
@ 2017-03-10  7:35 ` Jiewen Yao
  2017-03-10  7:35 ` [PATCH 2/3] MdeModulePkg/SmiHandlerProfile: " Jiewen Yao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jiewen Yao @ 2017-03-10  7:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan, Liming Gao, Michael D Kinney, Bret Barkelew

The reason is that we observe that a platform may use same Handler
for different context.

In order to support Unregister such handler, we have to input
context information as well.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdePkg/Include/Library/SmiHandlerProfileLib.h                      | 8 +++++++-
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Library/SmiHandlerProfileLib.h b/MdePkg/Include/Library/SmiHandlerProfileLib.h
index 10b7323..77d19f9 100644
--- a/MdePkg/Include/Library/SmiHandlerProfileLib.h
+++ b/MdePkg/Include/Library/SmiHandlerProfileLib.h
@@ -66,6 +66,10 @@ SmiHandlerProfileRegisterHandler (
                          For the SmmChildDispatch protocol, the HandlerGuid
                          must be the GUID of SmmChildDispatch protocol.
   @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
 
   @retval EFI_SUCCESS           The original record is removed.
   @retval EFI_UNSUPPORTED       The feature is unsupported.
@@ -75,7 +79,9 @@ EFI_STATUS
 EFIAPI
 SmiHandlerProfileUnregisterHandler (
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   );
 
 #endif
diff --git a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
index 6ae4718..7f4855b 100644
--- a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
@@ -56,6 +56,10 @@ SmiHandlerProfileRegisterHandler (
                          For the SmmChildDispatch protocol, the HandlerGuid
                          must be the GUID of SmmChildDispatch protocol.
   @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
 
   @retval EFI_SUCCESS           The original record is removed.
   @retval EFI_UNSUPPORTED       The feature is unsupported.
@@ -65,7 +69,9 @@ EFI_STATUS
 EFIAPI
 SmiHandlerProfileUnregisterHandler (
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   )
 {
   return EFI_UNSUPPORTED;
-- 
2.7.4.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
  2017-03-10  7:35 [PATCH 0/3] Add Context in SmiHandlerProfileUnregister Jiewen Yao
  2017-03-10  7:35 ` [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister Jiewen Yao
@ 2017-03-10  7:35 ` Jiewen Yao
  2017-03-10  7:35 ` [PATCH 3/3] MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister Jiewen Yao
  2017-03-13  2:05 ` [PATCH 0/3] " Fan, Jeff
  3 siblings, 0 replies; 6+ messages in thread
From: Jiewen Yao @ 2017-03-10  7:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan, Feng Tian, Star Zeng, Bret Barkelew

The reason is that we observe that a platform may use same Handler
for different context.

In order to support Unregister such handler, we have to input
context information as well.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                          | 41 +++++++++++++++++++-
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c | 10 ++++-
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Include/Guid/SmiHandlerProfile.h b/MdeModulePkg/Include/Guid/SmiHandlerProfile.h
index b81631d..c5d29e8 100644
--- a/MdeModulePkg/Include/Guid/SmiHandlerProfile.h
+++ b/MdeModulePkg/Include/Guid/SmiHandlerProfile.h
@@ -150,6 +150,26 @@ extern EFI_GUID gSmiHandlerProfileGuid;
 
 typedef struct _SMI_HANDLER_PROFILE_PROTOCOL  SMI_HANDLER_PROFILE_PROTOCOL;
 
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
 typedef
 EFI_STATUS
 (EFIAPI  *SMI_HANDLER_PROFILE_REGISTER_HANDLER) (
@@ -161,12 +181,31 @@ EFI_STATUS
   IN UINTN                          ContextSize OPTIONAL
   );
 
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
 typedef
 EFI_STATUS
 (EFIAPI  *SMI_HANDLER_PROFILE_UNREGISTER_HANDLER) (
   IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   );
 
 struct _SMI_HANDLER_PROFILE_PROTOCOL {
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
index 2edc71b..2911619 100644
--- a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
@@ -63,6 +63,10 @@ SmiHandlerProfileRegisterHandler (
                          For the SmmChildDispatch protocol, the HandlerGuid
                          must be the GUID of SmmChildDispatch protocol.
   @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
 
   @retval EFI_SUCCESS           The original record is removed.
   @retval EFI_UNSUPPORTED       The feature is unsupported.
@@ -72,11 +76,13 @@ EFI_STATUS
 EFIAPI
 SmiHandlerProfileUnregisterHandler (
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   )
 {
   if (mSmiHandlerProfile != NULL) {
-    return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler);
+    return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, Context, ContextSize);
   }
   return EFI_UNSUPPORTED;
 }
-- 
2.7.4.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister.
  2017-03-10  7:35 [PATCH 0/3] Add Context in SmiHandlerProfileUnregister Jiewen Yao
  2017-03-10  7:35 ` [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister Jiewen Yao
  2017-03-10  7:35 ` [PATCH 2/3] MdeModulePkg/SmiHandlerProfile: " Jiewen Yao
@ 2017-03-10  7:35 ` Jiewen Yao
  2017-03-13  2:05 ` [PATCH 0/3] " Fan, Jeff
  3 siblings, 0 replies; 6+ messages in thread
From: Jiewen Yao @ 2017-03-10  7:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan, Feng Tian, Star Zeng, Bret Barkelew

The reason is that we observe that a platform may use same Handler
for different context.

In order to support Unregister such handler, we have to input
context information as well.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h         |   8 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c | 103 ++++++++++++++++----
 2 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 45b9d97..c12805a 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -1139,6 +1139,10 @@ SmiHandlerProfileRegisterHandler (
                          For the SmmChildDispatch protocol, the HandlerGuid
                          must be the GUID of SmmChildDispatch protocol.
   @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
 
   @retval EFI_SUCCESS           The original record is removed.
   @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
@@ -1148,7 +1152,9 @@ EFIAPI
 SmiHandlerProfileUnregisterHandler (
   IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   );
 
 extern UINTN                    mFullSmramRangeCount;
diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
index f85c0f0..1e36039 100644
--- a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
+++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
@@ -1089,6 +1089,40 @@ SmmCoreFindHardwareSmiEntry (
 }
 
 /**
+  Convert EFI_SMM_USB_REGISTER_CONTEXT to SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT.
+
+  @param UsbContext                   A pointer to EFI_SMM_USB_REGISTER_CONTEXT
+  @param UsbContextSize               The size of EFI_SMM_USB_REGISTER_CONTEXT in bytes
+  @param SmiHandlerUsbContextSize     The size of SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT in bytes
+
+  @return SmiHandlerUsbContext  A pointer to SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT
+**/
+SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *
+ConvertSmiHandlerUsbContext (
+  IN EFI_SMM_USB_REGISTER_CONTEXT   *UsbContext,
+  IN UINTN                          UsbContextSize,
+  OUT UINTN                         *SmiHandlerUsbContextSize
+  )
+{
+  UINTN                                     DevicePathSize;
+  SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT  *SmiHandlerUsbContext;
+
+  ASSERT (UsbContextSize == sizeof(EFI_SMM_USB_REGISTER_CONTEXT));
+
+  DevicePathSize = GetDevicePathSize (UsbContext->Device);
+  SmiHandlerUsbContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize);
+  if (SmiHandlerUsbContext == NULL) {
+    *SmiHandlerUsbContextSize = 0;
+    return NULL;
+  }
+  SmiHandlerUsbContext->Type = UsbContext->Type;
+  SmiHandlerUsbContext->DevicePathSize = (UINT32)DevicePathSize;
+  CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize);
+  *SmiHandlerUsbContextSize = sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize;
+  return SmiHandlerUsbContext;
+}
+
+/**
   This function is called by SmmChildDispatcher module to report
   a new SMI handler is registered, to SmmCore.
 
@@ -1123,6 +1157,11 @@ SmiHandlerProfileRegisterHandler (
   SMI_ENTRY    *SmiEntry;
   LIST_ENTRY   *List;
 
+  if (((ContextSize == 0) && (Context != NULL)) ||
+      ((ContextSize != 0) && (Context == NULL))) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   SmiHandler = AllocateZeroPool (sizeof (SMI_HANDLER));
   if (SmiHandler == NULL) {
     return EFI_OUT_OF_RESOURCES;
@@ -1131,33 +1170,24 @@ SmiHandlerProfileRegisterHandler (
   SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
   SmiHandler->Handler = Handler;
   SmiHandler->CallerAddr = (UINTN)CallerAddress;
-  if (ContextSize != 0 && Context != NULL) {
+  SmiHandler->Context = Context;
+  SmiHandler->ContextSize = ContextSize;
+
+  if (Context != NULL) {
     if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
-      EFI_SMM_USB_REGISTER_CONTEXT              *UsbContext;
-      UINTN                                     DevicePathSize;
-      SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT  *SmiHandlerUsbContext;
-
-      ASSERT (ContextSize == sizeof(EFI_SMM_USB_REGISTER_CONTEXT));
-
-      UsbContext = (EFI_SMM_USB_REGISTER_CONTEXT *)Context;
-      DevicePathSize = GetDevicePathSize (UsbContext->Device);
-      SmiHandlerUsbContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize);
-      if (SmiHandlerUsbContext != NULL) {
-        SmiHandlerUsbContext->Type = UsbContext->Type;
-        SmiHandlerUsbContext->DevicePathSize = (UINT32)DevicePathSize;
-        CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize);
-        SmiHandler->Context = SmiHandlerUsbContext;
-      }
+      SmiHandler->Context = ConvertSmiHandlerUsbContext (Context, ContextSize, &SmiHandler->ContextSize);
     } else {
       SmiHandler->Context = AllocateCopyPool (ContextSize, Context);
     }
   }
-  if (SmiHandler->Context != NULL) {
-    SmiHandler->ContextSize = ContextSize;
+  if (SmiHandler->Context == NULL) {
+    SmiHandler->ContextSize = 0;
   }
 
   SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE);
   if (SmiEntry == NULL) {
+    FreePool (SmiHandler->Context);
+    FreePool (SmiHandler);
     return EFI_OUT_OF_RESOURCES;
   }
 
@@ -1178,6 +1208,10 @@ SmiHandlerProfileRegisterHandler (
                          For the SmmChildDispatch protocol, the HandlerGuid
                          must be the GUID of SmmChildDispatch protocol.
   @param Handler         The SMI handler.
+  @param Context         The context of the SMI handler.
+                         If it is NOT NULL, it will be used to check what is registered.
+  @param ContextSize     The size of the context in bytes.
+                         If Context is NOT NULL, it will be used to check what is registered.
 
   @retval EFI_SUCCESS           The original record is removed.
   @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
@@ -1187,7 +1221,9 @@ EFIAPI
 SmiHandlerProfileUnregisterHandler (
   IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
   IN EFI_GUID                       *HandlerGuid,
-  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
   )
 {
   LIST_ENTRY   *Link;
@@ -1195,21 +1231,46 @@ SmiHandlerProfileUnregisterHandler (
   SMI_HANDLER  *SmiHandler;
   SMI_ENTRY    *SmiEntry;
   SMI_HANDLER  *TargetSmiHandler;
+  VOID         *SearchContext;
+  UINTN        SearchContextSize;
+
+  if (((ContextSize == 0) && (Context != NULL)) ||
+      ((ContextSize != 0) && (Context == NULL))) {
+    return EFI_INVALID_PARAMETER;
+  }
 
   SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, FALSE);
   if (SmiEntry == NULL) {
     return EFI_NOT_FOUND;
   }
 
+  SearchContext = Context;
+  SearchContextSize = ContextSize;
+  if (Context != NULL) {
+    if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
+      SearchContext = ConvertSmiHandlerUsbContext (Context, ContextSize, &SearchContextSize);
+    }
+  }
+
   TargetSmiHandler = NULL;
   Head = &SmiEntry->SmiHandlers;
   for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
     SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
     if (SmiHandler->Handler == Handler) {
-      TargetSmiHandler = SmiHandler;
-      break;
+      if ((SearchContext == NULL) ||
+          ((SearchContextSize == SmiHandler->ContextSize) && (CompareMem (SearchContext, SmiHandler->Context, SearchContextSize) == 0))) {
+        TargetSmiHandler = SmiHandler;
+        break;
+      }
+    }
+  }
+
+  if (SearchContext != NULL) {
+    if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
+      FreePool (SearchContext);
     }
   }
+
   if (TargetSmiHandler == NULL) {
     return EFI_NOT_FOUND;
   }
-- 
2.7.4.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.
  2017-03-10  7:35 [PATCH 0/3] Add Context in SmiHandlerProfileUnregister Jiewen Yao
                   ` (2 preceding siblings ...)
  2017-03-10  7:35 ` [PATCH 3/3] MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister Jiewen Yao
@ 2017-03-13  2:05 ` Fan, Jeff
  2017-03-13  3:11   ` Tian, Feng
  3 siblings, 1 reply; 6+ messages in thread
From: Fan, Jeff @ 2017-03-13  2:05 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@lists.01.org
  Cc: Tian, Feng, Zeng, Star, Bret Barkelew

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Yao, Jiewen 
Sent: Friday, March 10, 2017 3:35 PM
To: edk2-devel@lists.01.org
Cc: Fan, Jeff; Tian, Feng; Zeng, Star; Bret Barkelew
Subject: [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.

This issue is reported by Bret.Barkelew@microsoft.com.

We observe that a platform may use same Handler for different context.

In order to support Unregister such handler, we have to input context information as well.


The patch does not impact any platform with SmiHandlerProfile disabled.

Unit tests below:
1) register same handler with different context, and unregister each.
2) register and unregister UsbContext.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>

Jiewen Yao (3):
  MdePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister.

 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                |   8 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                        | 103 ++++++++++++++++----
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                          |  41 +++++++-
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c |  10 +-
 MdePkg/Include/Library/SmiHandlerProfileLib.h                          |   8 +-
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c     |   8 +-
 6 files changed, 151 insertions(+), 27 deletions(-)

--
2.7.4.windows.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.
  2017-03-13  2:05 ` [PATCH 0/3] " Fan, Jeff
@ 2017-03-13  3:11   ` Tian, Feng
  0 siblings, 0 replies; 6+ messages in thread
From: Tian, Feng @ 2017-03-13  3:11 UTC (permalink / raw)
  To: Fan, Jeff, Yao, Jiewen, edk2-devel@lists.01.org
  Cc: Zeng, Star, Bret Barkelew, Tian, Feng

Reviewed-by: Feng Tian <feng.tian@intel.com>

Thanks
Feng

-----Original Message-----
From: Fan, Jeff 
Sent: Monday, March 13, 2017 10:06 AM
To: Yao, Jiewen <jiewen.yao@intel.com>; edk2-devel@lists.01.org
Cc: Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: RE: [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Yao, Jiewen 
Sent: Friday, March 10, 2017 3:35 PM
To: edk2-devel@lists.01.org
Cc: Fan, Jeff; Tian, Feng; Zeng, Star; Bret Barkelew
Subject: [PATCH 0/3] Add Context in SmiHandlerProfileUnregister.

This issue is reported by Bret.Barkelew@microsoft.com.

We observe that a platform may use same Handler for different context.

In order to support Unregister such handler, we have to input context information as well.


The patch does not impact any platform with SmiHandlerProfile disabled.

Unit tests below:
1) register same handler with different context, and unregister each.
2) register and unregister UsbContext.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>

Jiewen Yao (3):
  MdePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
  MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister.

 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                |   8 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                        | 103 ++++++++++++++++----
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                          |  41 +++++++-
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c |  10 +-
 MdePkg/Include/Library/SmiHandlerProfileLib.h                          |   8 +-
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c     |   8 +-
 6 files changed, 151 insertions(+), 27 deletions(-)

--
2.7.4.windows.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-13  3:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-10  7:35 [PATCH 0/3] Add Context in SmiHandlerProfileUnregister Jiewen Yao
2017-03-10  7:35 ` [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister Jiewen Yao
2017-03-10  7:35 ` [PATCH 2/3] MdeModulePkg/SmiHandlerProfile: " Jiewen Yao
2017-03-10  7:35 ` [PATCH 3/3] MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister Jiewen Yao
2017-03-13  2:05 ` [PATCH 0/3] " Fan, Jeff
2017-03-13  3:11   ` Tian, Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox