public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wang, Sunny (HPS SW)" <sunnywang@hpe.com>
To: Ruiyu Ni <ruiyu.ni@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: Chao B Zhang <chao.b.zhang@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	 "Wang, Sunny (HPS SW)" <sunnywang@hpe.com>,
	"Haskell, Darrell" <darrell.haskell@hpe.com>
Subject: Re: [PATCH v2 3/9] MdeModulePkg/BdsDxe: Check deferred images before booting to OS
Date: Thu, 10 Nov 2016 05:50:29 +0000	[thread overview]
Message-ID: <CS1PR84MB02956EF3E303C604FE7BF697A8B80@CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20161108122928.53984-4-ruiyu.ni@intel.com>

[-- Attachment #1: Type: text/plain, Size: 6485 bytes --]

Thanks for addressing my offline comments. This updated patch looks good to me. 
Reviewed-by: Sunny Wang <sunnywang@hpe.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu Ni
Sent: Tuesday, November 08, 2016 8:29 PM
To: edk2-devel@lists.01.org
Cc: Chao B Zhang <chao.b.zhang@intel.com>; Liming Gao <liming.gao@intel.com>
Subject: [edk2] [PATCH v2 3/9] MdeModulePkg/BdsDxe: Check deferred images before booting to OS

The patch adds check of deferred images before booting to OS.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Chao B Zhang <chao.b.zhang@intel.com>
---
 MdeModulePkg/Universal/BdsDxe/Bds.h      |  4 +-
 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  2 +  MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 90 ++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Universal/BdsDxe/Bds.h b/MdeModulePkg/Universal/BdsDxe/Bds.h
index d243932..1f8a192 100644
--- a/MdeModulePkg/Universal/BdsDxe/Bds.h
+++ b/MdeModulePkg/Universal/BdsDxe/Bds.h
@@ -1,7 +1,7 @@
 /** @file
   Head file for BDS Architectural Protocol implementation
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/ConnectConInEvent.h>
 #include <Guid/Performance.h>
 #include <Guid/StatusCodeDataTypeVariable.h>
+#include <Guid/EventGroup.h>
 
 #include <Protocol/Bds.h>
 #include <Protocol/LoadedImage.h>
 #include <Protocol/VariableLock.h>
+#include <Protocol/DeferredImageLoad.h>
 
 #include <Library/UefiDriverEntryPoint.h>  #include <Library/DebugLib.h> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
index e03cfde..a00b442 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
@@ -79,11 +79,13 @@ [Guids]
   gConnectConInEventGuid                        ## SOMETIMES_CONSUMES ## Event
   gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES ## GUID
   gPerformanceProtocolGuid                      ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" (The ACPI address of performance data)
+  gEfiEventReadyToBootGuid                      ## CONSUMES           ## Event
 
 [Protocols]
   gEfiBdsArchProtocolGuid                       ## PRODUCES
   gEfiSimpleTextInputExProtocolGuid             ## CONSUMES
   gEdkiiVariableLockProtocolGuid                ## CONSUMES
+  gEfiDeferredImageLoadProtocolGuid             ## CONSUMES
 
 [FeaturePcd]
   gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate    ## CONSUMES
diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
index aacc4a6..72adc51 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -86,6 +86,81 @@ BdsDxeOnConnectConInCallBack (
     DEBUG ((EFI_D_WARN, "[Bds] Connect ConIn failed - %r!!!\n", Status));
   }
 }
+/**
+  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This 
+is used to
+  check whether there is remaining deferred load images.
+
+  @param[in]  Event   The Event that is being processed.
+  @param[in]  Context The Event Context.
+
+**/
+VOID
+EFIAPI
+CheckDeferredLoadImageOnReadyToBoot (
+  IN EFI_EVENT        Event,
+  IN VOID             *Context
+  )
+{
+  EFI_STATUS                         Status;
+  EFI_DEFERRED_IMAGE_LOAD_PROTOCOL   *DeferredImage;
+  UINTN                              HandleCount;
+  EFI_HANDLE                         *Handles;
+  UINTN                              Index;
+  UINTN                              ImageIndex;
+  EFI_DEVICE_PATH_PROTOCOL           *ImageDevicePath;
+  VOID                               *Image;
+  UINTN                              ImageSize;
+  BOOLEAN                            BootOption;
+  CHAR16                             *DevicePathStr;
+
+  //
+  // Find all the deferred image load protocols.
+  //
+  HandleCount = 0;
+  Handles = NULL;
+  Status = gBS->LocateHandleBuffer (
+    ByProtocol,
+    &gEfiDeferredImageLoadProtocolGuid,
+    NULL,
+    &HandleCount,
+    &Handles
+  );
+  if (EFI_ERROR (Status)) {
+    return;
+  }
+
+  for (Index = 0; Index < HandleCount; Index++) {
+    Status = gBS->HandleProtocol (Handles[Index], &gEfiDeferredImageLoadProtocolGuid, (VOID **) &DeferredImage);
+    if (EFI_ERROR (Status)) {
+      continue;
+    }
+
+    for (ImageIndex = 0; ; ImageIndex++) {
+      //
+      // Load all the deferred images in this protocol instance.
+      //
+      Status = DeferredImage->GetImageInfo (
+        DeferredImage,
+        ImageIndex,
+        &ImageDevicePath,
+        (VOID **) &Image,
+        &ImageSize,
+        &BootOption
+      );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+      DevicePathStr = ConvertDevicePathToText (ImageDevicePath, FALSE, FALSE);
+      DEBUG ((DEBUG_LOAD, "[Bds] Image was deferred but not loaded: %s.\n", DevicePathStr));
+      if (DevicePathStr != NULL) {
+        FreePool (DevicePathStr);
+      }
+    }
+  }
+  if (Handles != NULL) {
+    FreePool (Handles);
+  }
+}
 
 /**
 
@@ -119,6 +194,21 @@ BdsInitialize (
                   );
   ASSERT_EFI_ERROR (Status);
 
+  DEBUG_CODE (
+    EFI_EVENT   Event;
+    //
+    // Register notify function to check deferred images on ReadyToBoot Event.
+    //
+    Status = gBS->CreateEventEx (
+                    EVT_NOTIFY_SIGNAL,
+                    TPL_CALLBACK,
+                    CheckDeferredLoadImageOnReadyToBoot,
+                    NULL,
+                    &gEfiEventReadyToBootGuid,
+                    &Event
+                    );
+    ASSERT_EFI_ERROR (Status);
+  );
   return Status;
 }
 
--
2.9.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

[-- Attachment #2: Type: message/rfc822, Size: 14173 bytes --]

From: "Ni, Ruiyu" <ruiyu.ni@intel.com>
To: "Wang, Sunny (HPS SW)" <sunnywang@hpe.com>
Cc: "Haskell, Darrell" <darrell.haskell@hpe.com>
Subject: RE: [edk2] [PATCH 3/4] MdeModulePkg/BdsDxe: Check deferred images before booting to OS
Date: Mon, 7 Nov 2016 02:35:11 +0000
Message-ID: <734D49CCEBEEF84792F5B80ED585239D58E56773@SHSMSX104.ccr.corp.intel.com>



Thanks/Ray

> -----Original Message-----
> From: Wang, Sunny (HPS SW) [mailto:sunnywang@hpe.com]
> Sent: Friday, November 4, 2016 7:34 PM
> To: Ni, Ruiyu <ruiyu.ni@intel.com>
> Cc: Wang, Sunny (HPS SW) <sunnywang@hpe.com>; Haskell, Darrell
> <darrell.haskell@hpe.com>
> Subject: RE: [edk2] [PATCH 3/4] MdeModulePkg/BdsDxe: Check deferred
> images before booting to OS
>
> Hi Ray,
> Remove others. Feel free to add some people back.
> CheckDeferredLoadImageOnReadyToBoot()  is almost the same as
> CheckDeferredImage() in Intel Central park reference code, so It looks good
> to me.
> However, I have a question and a suggestion below:
> Question:
>           - ReadyToBoot event is possibly signaled more than once during a boot.
> Why do we need to call CheckDeferredLoadImageOnReadyToBoot() more
> than once during a boot? If it is related to use cases of deferred image, could
> you give more information? I'm not familiar with the use cases of the
> deferred image, but I would like to know if it is worth for HPE sever to take
> little additional boot time to call CheckDeferredLoadImageOnReadyToBoot()
> more than once during a boot. Thanks in advance.

Yes I agree calling this more than once is unnecessary. I will change the patch
to call it only once.

>
> Suggestions:
>          - It looks like CheckDeferredLoadImageOnReadyToBoot() is only for
> printing DEBUG messages. Is there anything which I overlook?  If not, is it a
> good idea to add this CheckDeferredLoadImage() as a UefiBootManagerLib
> API instead of adding this as a Notify function in BdsDxe?  So that all the
> companies can decide whether/when they want to call
> CheckDeferredLoadImage() in BDS platform code instead of being forced
> calling it with ReadyToBoot event signaled in BDS core code.

I see your needs now. So how about I only register this callback in DEBUG
build, surrounding the code with DEBUG_CODE() macro?
Make this as an API requires platform manually register this callback, which
I think is not very convenient to platform.

>
> Regards,
> Sunny Wang
>
>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ruiyu Ni
> Sent: Friday, November 04, 2016 9:00 AM
> To: edk2-devel@lists.01.org
> Cc: Chao B Zhang <chao.b.zhang@intel.com>; Liming Gao
> <liming.gao@intel.com>
> Subject: [edk2] [PATCH 3/4] MdeModulePkg/BdsDxe: Check deferred
> images before booting to OS
>
> The patch adds check of deferred images before booting to OS.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Chao B Zhang <chao.b.zhang@intel.com>
> ---
>  MdeModulePkg/Universal/BdsDxe/Bds.h      |  4 +-
>  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  2 +
> MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 89
> ++++++++++++++++++++++++++++++++
>  3 files changed, 94 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Universal/BdsDxe/Bds.h
> b/MdeModulePkg/Universal/BdsDxe/Bds.h
> index d243932..1f8a192 100644
> --- a/MdeModulePkg/Universal/BdsDxe/Bds.h
> +++ b/MdeModulePkg/Universal/BdsDxe/Bds.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Head file for BDS Architectural Protocol implementation
>
> -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials  are licensed and made
> available under the terms and conditions of the BSD License  which
> accompanies this distribution.  The full text of the license may be found at
> @@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF
> ANY KIND, EITHER EXPRESS OR IMPLIED.
>  #include <Guid/ConnectConInEvent.h>
>  #include <Guid/Performance.h>
>  #include <Guid/StatusCodeDataTypeVariable.h>
> +#include <Guid/EventGroup.h>
>
>  #include <Protocol/Bds.h>
>  #include <Protocol/LoadedImage.h>
>  #include <Protocol/VariableLock.h>
> +#include <Protocol/DeferredImageLoad.h>
>
>  #include <Library/UefiDriverEntryPoint.h>  #include <Library/DebugLib.h>
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> index e03cfde..a00b442 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> @@ -79,11 +79,13 @@ [Guids]
>    gConnectConInEventGuid                        ## SOMETIMES_CONSUMES ## Event
>    gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES
> ## GUID
>    gPerformanceProtocolGuid                      ## SOMETIMES_PRODUCES ##
> Variable:L"PerfDataMemAddr" (The ACPI address of performance data)
> +  gEfiEventReadyToBootGuid                      ## CONSUMES           ## Event
>
>  [Protocols]
>    gEfiBdsArchProtocolGuid                       ## PRODUCES
>    gEfiSimpleTextInputExProtocolGuid             ## CONSUMES
>    gEdkiiVariableLockProtocolGuid                ## CONSUMES
> +  gEfiDeferredImageLoadProtocolGuid             ## CONSUMES
>
>  [FeaturePcd]
>    gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate    ##
> CONSUMES
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> index aacc4a6..ffa884a 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> @@ -86,7 +86,83 @@ BdsDxeOnConnectConInCallBack (
>      DEBUG ((EFI_D_WARN, "[Bds] Connect ConIn failed - %r!!!\n", Status));
>    }
>  }
> +/**
> +  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.
> This
> +is used to
> +  check whether there is remaining deferred load images.
> +
> +  @param[in]  Event   The Event that is being processed.
> +  @param[in]  Context The Event Context.
> +
> +**/
> +VOID
> +EFIAPI
> +CheckDeferredLoadImageOnReadyToBoot (
> +  IN EFI_EVENT        Event,
> +  IN VOID             *Context
> +  )
> +{
> +  EFI_STATUS                         Status;
> +  EFI_DEFERRED_IMAGE_LOAD_PROTOCOL   *DeferredImage;
> +  UINTN                              HandleCount;
> +  EFI_HANDLE                         *Handles;
> +  UINTN                              Index;
> +  UINTN                              ImageIndex;
> +  EFI_DEVICE_PATH_PROTOCOL           *ImageDevicePath;
> +  VOID                               *Image;
> +  UINTN                              ImageSize;
> +  BOOLEAN                            BootOption;
> +
> +  //
> +  // Find all the deferred image load protocols.
> +  //
> +  HandleCount = 0;
> +  Handles = NULL;
> +  Status = gBS->LocateHandleBuffer (
> +    ByProtocol,
> +    &gEfiDeferredImageLoadProtocolGuid,
> +    NULL,
> +    &HandleCount,
> +    &Handles
> +  );
> +  if (EFI_ERROR (Status)) {
> +    return;
> +  }
> +
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    Status = gBS->HandleProtocol (Handles[Index],
> &gEfiDeferredImageLoadProtocolGuid, (VOID **) &DeferredImage);
> +    if (EFI_ERROR (Status)) {
> +      continue;
> +    }
>
> +    for (ImageIndex = 0; ; ImageIndex++) {
> +      //
> +      // Load all the deferred images in this protocol instance.
> +      //
> +      Status = DeferredImage->GetImageInfo (
> +        DeferredImage,
> +        ImageIndex,
> +        &ImageDevicePath,
> +        (VOID **) &Image,
> +        &ImageSize,
> +        &BootOption
> +      );
> +      if (EFI_ERROR (Status)) {
> +        break;
> +      }
> +      DEBUG_CODE (
> +        CHAR16    *DevicePathStr;
> +        DevicePathStr = ConvertDevicePathToText (ImageDevicePath, FALSE,
> FALSE);
> +        DEBUG ((DEBUG_LOAD, "[Bds] Image was deferred but not
> loaded: %s.\n", DevicePathStr));
> +        if (DevicePathStr != NULL) {
> +          FreePool (DevicePathStr);
> +        }
> +        );
> +    }
> +  }
> +  if (Handles != NULL) {
> +    FreePool (Handles);
> +  }
> +}
>  /**
>
>    Install Boot Device Selection Protocol @@ -108,6 +184,7 @@ BdsInitialize (  {
>    EFI_STATUS  Status;
>    EFI_HANDLE  Handle;
> +  EFI_EVENT   Event;
>    //
>    // Install protocol interface
>    //
> @@ -119,6 +196,18 @@ BdsInitialize (
>                    );
>    ASSERT_EFI_ERROR (Status);
>
> +  //
> +  // Register notify function to check deferred images on ReadyToBoot
> Event.
> +  //
> +  Status = gBS->CreateEventEx (
> +                  EVT_NOTIFY_SIGNAL,
> +                  TPL_CALLBACK,
> +                  CheckDeferredLoadImageOnReadyToBoot,
> +                  NULL,
> +                  &gEfiEventReadyToBootGuid,
> +                  &Event
> +                  );
> +  ASSERT_EFI_ERROR (Status);
>    return Status;
>  }
>
> --
> 2.9.0.windows.1
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  parent reply	other threads:[~2016-11-10  5:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-08 12:29 [PATCH v2 0/9] Defer 3rd party images loading to after EndOfDxe Ruiyu Ni
2016-11-08 12:29 ` [PATCH v2 1/9] MdeModulePkg/SecurityStubDxe: Defer 3rd party image before EndOfDxe Ruiyu Ni
2016-11-10  7:24   ` Gao, Liming
2016-11-08 12:29 ` [PATCH v2 2/9] MdeModulePkg/UefiBootManager: Add EfiBootManagerDispatchDeferredImages Ruiyu Ni
2016-11-08 14:11   ` Zhang, Chao B
2016-11-10  5:52   ` Wang, Sunny (HPS SW)
2016-11-10  6:01   ` Gao, Liming
2016-11-08 12:29 ` [PATCH v2 3/9] MdeModulePkg/BdsDxe: Check deferred images before booting to OS Ruiyu Ni
2016-11-08 14:08   ` Zhang, Chao B
2016-11-10  5:50   ` Wang, Sunny (HPS SW) [this message]
2016-11-10  6:01   ` Gao, Liming
2016-11-08 12:29 ` [PATCH v2 4/9] MdeModulePkg/SecurityStubDxe: Report failure if image is load earlier Ruiyu Ni
2016-11-08 12:29 ` [PATCH v2 5/9] ArmVirPkg/PlatformBds: Dispatch deferred images after EndOfDxe Ruiyu Ni
2016-11-08 12:57   ` Laszlo Ersek
2016-11-08 12:29 ` [PATCH v2 6/9] OvmfPkg/PlatformBds: " Ruiyu Ni
2016-11-08 13:04   ` Laszlo Ersek
2016-11-11 11:16     ` Laszlo Ersek
2016-11-11 11:24       ` Ni, Ruiyu
2016-11-08 12:29 ` [PATCH v2 7/9] CorebootPayload/PlatformBds: " Ruiyu Ni
2016-11-09  0:13   ` Ma, Maurice
2016-11-08 12:29 ` [PATCH v2 8/9] QuarkPlatformPkg/PlatformBds: " Ruiyu Ni
2016-11-08 15:39   ` Kinney, Michael D
2016-11-08 12:29 ` [PATCH v2 9/9] Nt32Pkg/PlatformBds: " Ruiyu Ni
2016-11-09  6:55   ` Dong, Eric
2016-11-10  5:56 ` [PATCH v2 0/9] Defer 3rd party images loading to " Wang, Sunny (HPS SW)

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=CS1PR84MB02956EF3E303C604FE7BF697A8B80@CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.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