[edk2] [Patch] MdeModulePkg/Core/Dxe: Remove extra connects for UEFI Applications

Michael D Kinney posted 1 patch 6 years, 5 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Core/Dxe/Image/Image.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
[edk2] [Patch] MdeModulePkg/Core/Dxe: Remove extra connects for UEFI Applications
Posted by Michael D Kinney 6 years, 5 months ago
https://bugzilla.tianocore.org/show_bug.cgi?id=765

The UEFI Specification Boot Services chapter, StartImage() service,
EFF 1.10 Extension requires extra calls to ConnectController()
if a UEFI Driver produces handles. The DXE Core is performing these
extra calls to ConnectController() without evaluating the ImageType.

A filter is added to not make extra calls to ConnectController()
if the ImageType is EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION.

Without this filter, extra calls to ConnectController() may be
performed by UEFI Applications or a UEFI Shell Applications that
also call ConnectController().

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 4e22aa6dc7..c6b8ff44b9 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -1703,9 +1703,17 @@ CoreStartImage (
   mCurrentImage = LastImage;
 
   //
-  // Go connect any handles that were created or modified while the image executed.
+  // UEFI Specification - StartImage() - EFI 1.10 Extension
+  // To maintain compatibility with UEFI drivers that are written to the EFI
+  // 1.02 Specification, StartImage() must monitor the handle database before
+  // and after each image is started. If any handles are created or modified
+  // when an image is started, then EFI_BOOT_SERVICES.ConnectController() must
+  // be called with the Recursive parameter set to TRUE for each of the newly
+  // created or modified handles before StartImage() returns.
   //
-  CoreConnectHandlesByKey (HandleDatabaseKey);
+  if (Image->ImageContext.ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
+    CoreConnectHandlesByKey (HandleDatabaseKey);
+  }
 
   //
   // Handle the image's returned ExitData
-- 
2.14.2.windows.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg/Core/Dxe: Remove extra connects for UEFI Applications
Posted by Zeng, Star 6 years, 5 months ago
Reviewed-by: Star Zeng <star.zeng@intel.com>

BTW: I see the code is using Image->ImageContext.ImageType at some places and Image->Type at other place, it seems a little inconsistent.

Thanks,
Star
-----Original Message-----
From: Kinney, Michael D 
Sent: Thursday, November 9, 2017 1:55 AM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>
Subject: [Patch] MdeModulePkg/Core/Dxe: Remove extra connects for UEFI Applications

https://bugzilla.tianocore.org/show_bug.cgi?id=765

The UEFI Specification Boot Services chapter, StartImage() service,
EFF 1.10 Extension requires extra calls to ConnectController()
if a UEFI Driver produces handles. The DXE Core is performing these
extra calls to ConnectController() without evaluating the ImageType.

A filter is added to not make extra calls to ConnectController()
if the ImageType is EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION.

Without this filter, extra calls to ConnectController() may be
performed by UEFI Applications or a UEFI Shell Applications that
also call ConnectController().

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 4e22aa6dc7..c6b8ff44b9 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -1703,9 +1703,17 @@ CoreStartImage (
   mCurrentImage = LastImage;
 
   //
-  // Go connect any handles that were created or modified while the image executed.
+  // UEFI Specification - StartImage() - EFI 1.10 Extension
+  // To maintain compatibility with UEFI drivers that are written to the EFI
+  // 1.02 Specification, StartImage() must monitor the handle database before
+  // and after each image is started. If any handles are created or modified
+  // when an image is started, then EFI_BOOT_SERVICES.ConnectController() must
+  // be called with the Recursive parameter set to TRUE for each of the newly
+  // created or modified handles before StartImage() returns.
   //
-  CoreConnectHandlesByKey (HandleDatabaseKey);
+  if (Image->ImageContext.ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
+    CoreConnectHandlesByKey (HandleDatabaseKey);
+  }
 
   //
   // Handle the image's returned ExitData
-- 
2.14.2.windows.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg/Core/Dxe: Remove extra connects for UEFI Applications
Posted by Kinney, Michael D 6 years, 5 months ago
Star,

Thanks for noticing the inconsistency.

I agree that Image->Type is a better choice.

Mike

> -----Original Message-----
> From: Zeng, Star
> Sent: Thursday, November 9, 2017 5:10 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Zeng, Star
> <star.zeng@intel.com>
> Subject: RE: [Patch] MdeModulePkg/Core/Dxe: Remove
> extra connects for UEFI Applications
> 
> Reviewed-by: Star Zeng <star.zeng@intel.com>
> 
> BTW: I see the code is using Image-
> >ImageContext.ImageType at some places and Image->Type
> at other place, it seems a little inconsistent.
> 
> Thanks,
> Star
> -----Original Message-----
> From: Kinney, Michael D
> Sent: Thursday, November 9, 2017 1:55 AM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric
> <eric.dong@intel.com>
> Subject: [Patch] MdeModulePkg/Core/Dxe: Remove extra
> connects for UEFI Applications
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=765
> 
> The UEFI Specification Boot Services chapter,
> StartImage() service,
> EFF 1.10 Extension requires extra calls to
> ConnectController()
> if a UEFI Driver produces handles. The DXE Core is
> performing these
> extra calls to ConnectController() without evaluating
> the ImageType.
> 
> A filter is added to not make extra calls to
> ConnectController()
> if the ImageType is
> EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION.
> 
> Without this filter, extra calls to ConnectController()
> may be
> performed by UEFI Applications or a UEFI Shell
> Applications that
> also call ConnectController().
> 
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Michael D Kinney
> <michael.d.kinney@intel.com>
> ---
>  MdeModulePkg/Core/Dxe/Image/Image.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c
> b/MdeModulePkg/Core/Dxe/Image/Image.c
> index 4e22aa6dc7..c6b8ff44b9 100644
> --- a/MdeModulePkg/Core/Dxe/Image/Image.c
> +++ b/MdeModulePkg/Core/Dxe/Image/Image.c
> @@ -1703,9 +1703,17 @@ CoreStartImage (
>    mCurrentImage = LastImage;
> 
>    //
> -  // Go connect any handles that were created or
> modified while the image executed.
> +  // UEFI Specification - StartImage() - EFI 1.10
> Extension
> +  // To maintain compatibility with UEFI drivers that
> are written to the EFI
> +  // 1.02 Specification, StartImage() must monitor the
> handle database before
> +  // and after each image is started. If any handles
> are created or modified
> +  // when an image is started, then
> EFI_BOOT_SERVICES.ConnectController() must
> +  // be called with the Recursive parameter set to
> TRUE for each of the newly
> +  // created or modified handles before StartImage()
> returns.
>    //
> -  CoreConnectHandlesByKey (HandleDatabaseKey);
> +  if (Image->ImageContext.ImageType !=
> EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
> +    CoreConnectHandlesByKey (HandleDatabaseKey);
> +  }
> 
>    //
>    // Handle the image's returned ExitData
> --
> 2.14.2.windows.3

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