public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig
@ 2022-08-18 19:58 Dimitrije Pavlov
  2022-09-05 12:01 ` Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: Dimitrije Pavlov @ 2022-08-18 19:58 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Liming Gao, Sunny Wang,
	Jeff Booher-Kaeding, Samer El-Haj-Mahmoud

Per the UEFI specification, if the Request argument in
EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig() is NULL or does not contain
any request elements, the implementation should return all of the settings
being abstracted for the particular ConfigHdr reference.

The current implementation returns EFI_INVALID_PARAMETER if Request is
NULL or does not contain any request elements. Instead, construct
a new ConfigRequest to handle these cases per the specification.

In addition, per the UEFI specification, if the Configuration argument in
EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig() has a ConfigHdr that
specifies a non-existing target, the implementation should return
EFI_NOT_FOUND.

The current implementation returns EFI_INVALID_PARAMETER if Configuration
has a non-existing target in ConfigHdr. Instead, perform a check and
return EFI_NOT_FOUND in this case.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Sunny Wang <Sunny.Wang@arm.com>
Cc: Jeff Booher-Kaeding <Jeff.Booher-Kaeding@arm.com>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>

Signed-off-by: Dimitrije Pavlov <Dimitrije.Pavlov@arm.com>
---
 OvmfPkg/PlatformDxe/PlatformConfig.h |   2 +
 OvmfPkg/PlatformDxe/Platform.c       | 115 +++++++++++++++++++-
 OvmfPkg/PlatformDxe/PlatformConfig.c |   2 +-
 3 files changed, 116 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.h b/OvmfPkg/PlatformDxe/PlatformConfig.h
index 902c9b2ce043..5d9b457b1b4b 100644
--- a/OvmfPkg/PlatformDxe/PlatformConfig.h
+++ b/OvmfPkg/PlatformDxe/PlatformConfig.h
@@ -50,4 +50,6 @@ PlatformConfigLoad (
 #define PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION  BIT0
 #define PLATFORM_CONFIG_F_DOWNGRADE            BIT63
 
+extern CHAR16  mVariableName[];
+
 #endif // _PLATFORM_CONFIG_H_
diff --git a/OvmfPkg/PlatformDxe/Platform.c b/OvmfPkg/PlatformDxe/Platform.c
index a6d459f3dfd7..0e32c6e76037 100644
--- a/OvmfPkg/PlatformDxe/Platform.c
+++ b/OvmfPkg/PlatformDxe/Platform.c
@@ -108,6 +108,11 @@ STATIC EFI_EVENT  mGopEvent;
 //
 STATIC VOID  *mGopTracker;
 
+//
+// The driver image handle, used to obtain the device path for <ConfigHdr>.
+//
+STATIC EFI_HANDLE  mImageHandle;
+
 //
 // Cache the resolutions we get from the GOP.
 //
@@ -229,6 +234,10 @@ ExtractConfig (
 {
   MAIN_FORM_STATE  MainFormState;
   EFI_STATUS       Status;
+  EFI_STRING       ConfigRequestHdr;
+  EFI_STRING       ConfigRequest;
+  UINTN            Size;
+  BOOLEAN          AllocatedRequest;
 
   DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));
 
@@ -236,18 +245,73 @@ ExtractConfig (
     return EFI_INVALID_PARAMETER;
   }
 
+  ConfigRequestHdr = NULL;
+  ConfigRequest    = NULL;
+  Size             = 0;
+  AllocatedRequest = FALSE;
+
+  //
+  // Check if <ConfigHdr> matches the GUID and name
+  //
+  *Progress = Request;
+  if ((Request != NULL) &&
+      !HiiIsConfigHdrMatch (
+         Request,
+         &gOvmfPlatformConfigGuid,
+         mVariableName
+         )
+      )
+  {
+    return EFI_NOT_FOUND;
+  }
+
   Status = PlatformConfigToFormState (&MainFormState);
   if (EFI_ERROR (Status)) {
-    *Progress = Request;
     return Status;
   }
 
+  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
+    //
+    // Request has no <RequestElement>, so construct full request string.
+    // Allocate and fill a buffer large enough to hold <ConfigHdr>
+    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a
+    // null terminator.
+    //
+    ConfigRequestHdr = HiiConstructConfigHdr (
+                         &gOvmfPlatformConfigGuid,
+                         mVariableName,
+                         mImageHandle
+                         );
+    if (ConfigRequestHdr == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    Size             = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+    ConfigRequest    = AllocateZeroPool (Size);
+    AllocatedRequest = TRUE;
+    if (ConfigRequest == NULL) {
+      FreePool (ConfigRequestHdr);
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    UnicodeSPrint (
+      ConfigRequest,
+      Size,
+      L"%s&OFFSET=0&WIDTH=%016LX",
+      ConfigRequestHdr,
+      sizeof MainFormState
+      );
+    FreePool (ConfigRequestHdr);
+  } else {
+    ConfigRequest = Request;
+  }
+
   //
   // Answer the textual request keying off the binary form state.
   //
   Status = gHiiConfigRouting->BlockToConfig (
                                 gHiiConfigRouting,
-                                Request,
+                                ConfigRequest,
                                 (VOID *)&MainFormState,
                                 sizeof MainFormState,
                                 Results,
@@ -265,6 +329,33 @@ ExtractConfig (
     DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));
   }
 
+  //
+  // If we used a newly allocated ConfigRequest, update Progress to point to
+  // original Request instead of ConfigRequest.
+  //
+  if (Request == NULL) {
+    *Progress = NULL;
+  } else if (StrStr (Request, L"OFFSET") == NULL) {
+    if (EFI_ERROR (Status)) {
+      //
+      // Since we constructed ConfigRequest, failure can only occur if there
+      // is not enough memory. In this case, we point Progress to the first
+      // character of Request.
+      //
+      *Progress = Request;
+    } else {
+      //
+      // In case of success, we point Progress to the null terminator of
+      // Request.
+      //
+      *Progress = Request + StrLen (Request);
+    }
+  }
+
+  if (AllocatedRequest) {
+    FreePool (ConfigRequest);
+  }
+
   return Status;
 }
 
@@ -348,6 +439,21 @@ RouteConfig (
     return EFI_INVALID_PARAMETER;
   }
 
+  //
+  // Check if <ConfigHdr> matches the GUID and name
+  //
+  *Progress = Configuration;
+  if ((Configuration != NULL) &&
+      !HiiIsConfigHdrMatch (
+         Configuration,
+         &gOvmfPlatformConfigGuid,
+         mVariableName
+         )
+      )
+  {
+    return EFI_NOT_FOUND;
+  }
+
   //
   // the "read" step in RMW
   //
@@ -866,6 +972,11 @@ PlatformInit (
     return Status;
   }
 
+  //
+  // Save the driver image handle.
+  //
+  mImageHandle = ImageHandle;
+
   //
   // Publish the HII package list to HII Database.
   //
diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.c b/OvmfPkg/PlatformDxe/PlatformConfig.c
index e202ac5b4798..f5ac2d0609ff 100644
--- a/OvmfPkg/PlatformDxe/PlatformConfig.c
+++ b/OvmfPkg/PlatformDxe/PlatformConfig.c
@@ -21,7 +21,7 @@
 //
 // Name of the UEFI variable that we use for persistent storage.
 //
-STATIC CHAR16  mVariableName[] = L"PlatformConfig";
+CHAR16  mVariableName[] = L"PlatformConfig";
 
 /**
   Serialize and persistently save platform configuration.
-- 
2.37.2


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

* Re: [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig
  2022-08-18 19:58 [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig Dimitrije Pavlov
@ 2022-09-05 12:01 ` Ard Biesheuvel
  2022-09-05 12:11   ` Samer El-Haj-Mahmoud
  0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2022-09-05 12:01 UTC (permalink / raw)
  To: Dimitrije Pavlov
  Cc: devel, Ard Biesheuvel, Jiewen Yao, Liming Gao, Sunny Wang,
	Jeff Booher-Kaeding, Samer El-Haj-Mahmoud

On Thu, 18 Aug 2022 at 21:58, Dimitrije Pavlov <dimitrije.pavlov@arm.com> wrote:
>
> Per the UEFI specification, if the Request argument in
> EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig() is NULL or does not contain
> any request elements, the implementation should return all of the settings
> being abstracted for the particular ConfigHdr reference.
>
> The current implementation returns EFI_INVALID_PARAMETER if Request is
> NULL or does not contain any request elements. Instead, construct
> a new ConfigRequest to handle these cases per the specification.
>
> In addition, per the UEFI specification, if the Configuration argument in
> EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig() has a ConfigHdr that
> specifies a non-existing target, the implementation should return
> EFI_NOT_FOUND.
>
> The current implementation returns EFI_INVALID_PARAMETER if Configuration
> has a non-existing target in ConfigHdr. Instead, perform a check and
> return EFI_NOT_FOUND in this case.
>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Sunny Wang <Sunny.Wang@arm.com>
> Cc: Jeff Booher-Kaeding <Jeff.Booher-Kaeding@arm.com>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
>
> Signed-off-by: Dimitrije Pavlov <Dimitrije.Pavlov@arm.com>

Was this issue caught in some kind of testing/validation?

> ---
>  OvmfPkg/PlatformDxe/PlatformConfig.h |   2 +
>  OvmfPkg/PlatformDxe/Platform.c       | 115 +++++++++++++++++++-
>  OvmfPkg/PlatformDxe/PlatformConfig.c |   2 +-
>  3 files changed, 116 insertions(+), 3 deletions(-)
>
> diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.h b/OvmfPkg/PlatformDxe/PlatformConfig.h
> index 902c9b2ce043..5d9b457b1b4b 100644
> --- a/OvmfPkg/PlatformDxe/PlatformConfig.h
> +++ b/OvmfPkg/PlatformDxe/PlatformConfig.h
> @@ -50,4 +50,6 @@ PlatformConfigLoad (
>  #define PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION  BIT0
>  #define PLATFORM_CONFIG_F_DOWNGRADE            BIT63
>
> +extern CHAR16  mVariableName[];
> +
>  #endif // _PLATFORM_CONFIG_H_
> diff --git a/OvmfPkg/PlatformDxe/Platform.c b/OvmfPkg/PlatformDxe/Platform.c
> index a6d459f3dfd7..0e32c6e76037 100644
> --- a/OvmfPkg/PlatformDxe/Platform.c
> +++ b/OvmfPkg/PlatformDxe/Platform.c
> @@ -108,6 +108,11 @@ STATIC EFI_EVENT  mGopEvent;
>  //
>  STATIC VOID  *mGopTracker;
>
> +//
> +// The driver image handle, used to obtain the device path for <ConfigHdr>.
> +//
> +STATIC EFI_HANDLE  mImageHandle;
> +
>  //
>  // Cache the resolutions we get from the GOP.
>  //
> @@ -229,6 +234,10 @@ ExtractConfig (
>  {
>    MAIN_FORM_STATE  MainFormState;
>    EFI_STATUS       Status;
> +  EFI_STRING       ConfigRequestHdr;
> +  EFI_STRING       ConfigRequest;
> +  UINTN            Size;
> +  BOOLEAN          AllocatedRequest;
>
>    DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));
>
> @@ -236,18 +245,73 @@ ExtractConfig (
>      return EFI_INVALID_PARAMETER;
>    }
>
> +  ConfigRequestHdr = NULL;
> +  ConfigRequest    = NULL;
> +  Size             = 0;
> +  AllocatedRequest = FALSE;
> +
> +  //
> +  // Check if <ConfigHdr> matches the GUID and name
> +  //
> +  *Progress = Request;
> +  if ((Request != NULL) &&
> +      !HiiIsConfigHdrMatch (
> +         Request,
> +         &gOvmfPlatformConfigGuid,
> +         mVariableName
> +         )
> +      )
> +  {
> +    return EFI_NOT_FOUND;
> +  }
> +
>    Status = PlatformConfigToFormState (&MainFormState);
>    if (EFI_ERROR (Status)) {
> -    *Progress = Request;
>      return Status;
>    }
>
> +  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
> +    //
> +    // Request has no <RequestElement>, so construct full request string.
> +    // Allocate and fill a buffer large enough to hold <ConfigHdr>
> +    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a
> +    // null terminator.
> +    //
> +    ConfigRequestHdr = HiiConstructConfigHdr (
> +                         &gOvmfPlatformConfigGuid,
> +                         mVariableName,
> +                         mImageHandle
> +                         );
> +    if (ConfigRequestHdr == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    Size             = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
> +    ConfigRequest    = AllocateZeroPool (Size);
> +    AllocatedRequest = TRUE;
> +    if (ConfigRequest == NULL) {
> +      FreePool (ConfigRequestHdr);
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    UnicodeSPrint (
> +      ConfigRequest,
> +      Size,
> +      L"%s&OFFSET=0&WIDTH=%016LX",
> +      ConfigRequestHdr,
> +      sizeof MainFormState
> +      );
> +    FreePool (ConfigRequestHdr);
> +  } else {
> +    ConfigRequest = Request;
> +  }
> +
>    //
>    // Answer the textual request keying off the binary form state.
>    //
>    Status = gHiiConfigRouting->BlockToConfig (
>                                  gHiiConfigRouting,
> -                                Request,
> +                                ConfigRequest,
>                                  (VOID *)&MainFormState,
>                                  sizeof MainFormState,
>                                  Results,
> @@ -265,6 +329,33 @@ ExtractConfig (
>      DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));
>    }
>
> +  //
> +  // If we used a newly allocated ConfigRequest, update Progress to point to
> +  // original Request instead of ConfigRequest.
> +  //
> +  if (Request == NULL) {
> +    *Progress = NULL;
> +  } else if (StrStr (Request, L"OFFSET") == NULL) {
> +    if (EFI_ERROR (Status)) {
> +      //
> +      // Since we constructed ConfigRequest, failure can only occur if there
> +      // is not enough memory. In this case, we point Progress to the first
> +      // character of Request.
> +      //
> +      *Progress = Request;
> +    } else {
> +      //
> +      // In case of success, we point Progress to the null terminator of
> +      // Request.
> +      //
> +      *Progress = Request + StrLen (Request);
> +    }
> +  }
> +
> +  if (AllocatedRequest) {
> +    FreePool (ConfigRequest);
> +  }
> +
>    return Status;
>  }
>
> @@ -348,6 +439,21 @@ RouteConfig (
>      return EFI_INVALID_PARAMETER;
>    }
>
> +  //
> +  // Check if <ConfigHdr> matches the GUID and name
> +  //
> +  *Progress = Configuration;
> +  if ((Configuration != NULL) &&
> +      !HiiIsConfigHdrMatch (
> +         Configuration,
> +         &gOvmfPlatformConfigGuid,
> +         mVariableName
> +         )
> +      )
> +  {
> +    return EFI_NOT_FOUND;
> +  }
> +
>    //
>    // the "read" step in RMW
>    //
> @@ -866,6 +972,11 @@ PlatformInit (
>      return Status;
>    }
>
> +  //
> +  // Save the driver image handle.
> +  //
> +  mImageHandle = ImageHandle;
> +
>    //
>    // Publish the HII package list to HII Database.
>    //
> diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.c b/OvmfPkg/PlatformDxe/PlatformConfig.c
> index e202ac5b4798..f5ac2d0609ff 100644
> --- a/OvmfPkg/PlatformDxe/PlatformConfig.c
> +++ b/OvmfPkg/PlatformDxe/PlatformConfig.c
> @@ -21,7 +21,7 @@
>  //
>  // Name of the UEFI variable that we use for persistent storage.
>  //
> -STATIC CHAR16  mVariableName[] = L"PlatformConfig";
> +CHAR16  mVariableName[] = L"PlatformConfig";
>
>  /**
>    Serialize and persistently save platform configuration.
> --
> 2.37.2
>

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

* Re: [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig
  2022-09-05 12:01 ` Ard Biesheuvel
@ 2022-09-05 12:11   ` Samer El-Haj-Mahmoud
  2022-09-05 13:53     ` [edk2-devel] " Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: Samer El-Haj-Mahmoud @ 2022-09-05 12:11 UTC (permalink / raw)
  To: Ard Biesheuvel, Dimitrije Pavlov
  Cc: devel@edk2.groups.io, Ard Biesheuvel, Jiewen Yao, Liming Gao,
	Sunny Wang, Jeff Booher-Kaeding, Samer El-Haj-Mahmoud, nd

Hi Ard,

Yes, this was found during SCT testing:

HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig- ExtractConfig() returns EFI_SUCCESS or EFI_NOT_FOUND with Request been NULL . -- FAILURE
603E52F0-2CE3-4E7A-A72E-DF8CA3FDB20D
/home/dpavlov/qemu-cert/custom-testing/arm-systemready/SR/scripts/edk2-test/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/HIIConfigAccess/BlackBoxTest/HIIConfigAccessBBTestFunction.c:448: Status - Invalid Parameter

Thanks,
--Samer



> -----Original Message-----
> From: Ard Biesheuvel <ardb@kernel.org>
> Sent: Monday, September 5, 2022 8:01 AM
> To: Dimitrije Pavlov <Dimitrije.Pavlov@arm.com>
> Cc: devel@edk2.groups.io; Ard Biesheuvel <ardb+tianocore@kernel.org>;
> Jiewen Yao <jiewen.yao@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Sunny Wang <Sunny.Wang@arm.com>; Jeff Booher-Kaeding <Jeff.Booher-
> Kaeding@arm.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-
> Mahmoud@arm.com>
> Subject: Re: [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in
> ExtractConfig and RouteConfig
> 
> On Thu, 18 Aug 2022 at 21:58, Dimitrije Pavlov <dimitrije.pavlov@arm.com>
> wrote:
> >
> > Per the UEFI specification, if the Request argument in
> > EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig() is NULL or does not
> contain
> > any request elements, the implementation should return all of the settings
> > being abstracted for the particular ConfigHdr reference.
> >
> > The current implementation returns EFI_INVALID_PARAMETER if Request is
> > NULL or does not contain any request elements. Instead, construct
> > a new ConfigRequest to handle these cases per the specification.
> >
> > In addition, per the UEFI specification, if the Configuration argument in
> > EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig() has a ConfigHdr that
> > specifies a non-existing target, the implementation should return
> > EFI_NOT_FOUND.
> >
> > The current implementation returns EFI_INVALID_PARAMETER if Configuration
> > has a non-existing target in ConfigHdr. Instead, perform a check and
> > return EFI_NOT_FOUND in this case.
> >
> > Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> > Cc: Jiewen Yao <jiewen.yao@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Sunny Wang <Sunny.Wang@arm.com>
> > Cc: Jeff Booher-Kaeding <Jeff.Booher-Kaeding@arm.com>
> > Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> >
> > Signed-off-by: Dimitrije Pavlov <Dimitrije.Pavlov@arm.com>
> 
> Was this issue caught in some kind of testing/validation?
> 
> > ---
> >  OvmfPkg/PlatformDxe/PlatformConfig.h |   2 +
> >  OvmfPkg/PlatformDxe/Platform.c       | 115 +++++++++++++++++++-
> >  OvmfPkg/PlatformDxe/PlatformConfig.c |   2 +-
> >  3 files changed, 116 insertions(+), 3 deletions(-)
> >
> > diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.h
> b/OvmfPkg/PlatformDxe/PlatformConfig.h
> > index 902c9b2ce043..5d9b457b1b4b 100644
> > --- a/OvmfPkg/PlatformDxe/PlatformConfig.h
> > +++ b/OvmfPkg/PlatformDxe/PlatformConfig.h
> > @@ -50,4 +50,6 @@ PlatformConfigLoad (
> >  #define PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION  BIT0
> >  #define PLATFORM_CONFIG_F_DOWNGRADE            BIT63
> >
> > +extern CHAR16  mVariableName[];
> > +
> >  #endif // _PLATFORM_CONFIG_H_
> > diff --git a/OvmfPkg/PlatformDxe/Platform.c
> b/OvmfPkg/PlatformDxe/Platform.c
> > index a6d459f3dfd7..0e32c6e76037 100644
> > --- a/OvmfPkg/PlatformDxe/Platform.c
> > +++ b/OvmfPkg/PlatformDxe/Platform.c
> > @@ -108,6 +108,11 @@ STATIC EFI_EVENT  mGopEvent;
> >  //
> >  STATIC VOID  *mGopTracker;
> >
> > +//
> > +// The driver image handle, used to obtain the device path for <ConfigHdr>.
> > +//
> > +STATIC EFI_HANDLE  mImageHandle;
> > +
> >  //
> >  // Cache the resolutions we get from the GOP.
> >  //
> > @@ -229,6 +234,10 @@ ExtractConfig (
> >  {
> >    MAIN_FORM_STATE  MainFormState;
> >    EFI_STATUS       Status;
> > +  EFI_STRING       ConfigRequestHdr;
> > +  EFI_STRING       ConfigRequest;
> > +  UINTN            Size;
> > +  BOOLEAN          AllocatedRequest;
> >
> >    DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__,
> Request));
> >
> > @@ -236,18 +245,73 @@ ExtractConfig (
> >      return EFI_INVALID_PARAMETER;
> >    }
> >
> > +  ConfigRequestHdr = NULL;
> > +  ConfigRequest    = NULL;
> > +  Size             = 0;
> > +  AllocatedRequest = FALSE;
> > +
> > +  //
> > +  // Check if <ConfigHdr> matches the GUID and name
> > +  //
> > +  *Progress = Request;
> > +  if ((Request != NULL) &&
> > +      !HiiIsConfigHdrMatch (
> > +         Request,
> > +         &gOvmfPlatformConfigGuid,
> > +         mVariableName
> > +         )
> > +      )
> > +  {
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> >    Status = PlatformConfigToFormState (&MainFormState);
> >    if (EFI_ERROR (Status)) {
> > -    *Progress = Request;
> >      return Status;
> >    }
> >
> > +  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
> > +    //
> > +    // Request has no <RequestElement>, so construct full request string.
> > +    // Allocate and fill a buffer large enough to hold <ConfigHdr>
> > +    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW"
> followed by a
> > +    // null terminator.
> > +    //
> > +    ConfigRequestHdr = HiiConstructConfigHdr (
> > +                         &gOvmfPlatformConfigGuid,
> > +                         mVariableName,
> > +                         mImageHandle
> > +                         );
> > +    if (ConfigRequestHdr == NULL) {
> > +      return EFI_OUT_OF_RESOURCES;
> > +    }
> > +
> > +    Size             = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
> > +    ConfigRequest    = AllocateZeroPool (Size);
> > +    AllocatedRequest = TRUE;
> > +    if (ConfigRequest == NULL) {
> > +      FreePool (ConfigRequestHdr);
> > +      return EFI_OUT_OF_RESOURCES;
> > +    }
> > +
> > +    UnicodeSPrint (
> > +      ConfigRequest,
> > +      Size,
> > +      L"%s&OFFSET=0&WIDTH=%016LX",
> > +      ConfigRequestHdr,
> > +      sizeof MainFormState
> > +      );
> > +    FreePool (ConfigRequestHdr);
> > +  } else {
> > +    ConfigRequest = Request;
> > +  }
> > +
> >    //
> >    // Answer the textual request keying off the binary form state.
> >    //
> >    Status = gHiiConfigRouting->BlockToConfig (
> >                                  gHiiConfigRouting,
> > -                                Request,
> > +                                ConfigRequest,
> >                                  (VOID *)&MainFormState,
> >                                  sizeof MainFormState,
> >                                  Results,
> > @@ -265,6 +329,33 @@ ExtractConfig (
> >      DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__,
> *Results));
> >    }
> >
> > +  //
> > +  // If we used a newly allocated ConfigRequest, update Progress to point to
> > +  // original Request instead of ConfigRequest.
> > +  //
> > +  if (Request == NULL) {
> > +    *Progress = NULL;
> > +  } else if (StrStr (Request, L"OFFSET") == NULL) {
> > +    if (EFI_ERROR (Status)) {
> > +      //
> > +      // Since we constructed ConfigRequest, failure can only occur if there
> > +      // is not enough memory. In this case, we point Progress to the first
> > +      // character of Request.
> > +      //
> > +      *Progress = Request;
> > +    } else {
> > +      //
> > +      // In case of success, we point Progress to the null terminator of
> > +      // Request.
> > +      //
> > +      *Progress = Request + StrLen (Request);
> > +    }
> > +  }
> > +
> > +  if (AllocatedRequest) {
> > +    FreePool (ConfigRequest);
> > +  }
> > +
> >    return Status;
> >  }
> >
> > @@ -348,6 +439,21 @@ RouteConfig (
> >      return EFI_INVALID_PARAMETER;
> >    }
> >
> > +  //
> > +  // Check if <ConfigHdr> matches the GUID and name
> > +  //
> > +  *Progress = Configuration;
> > +  if ((Configuration != NULL) &&
> > +      !HiiIsConfigHdrMatch (
> > +         Configuration,
> > +         &gOvmfPlatformConfigGuid,
> > +         mVariableName
> > +         )
> > +      )
> > +  {
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> >    //
> >    // the "read" step in RMW
> >    //
> > @@ -866,6 +972,11 @@ PlatformInit (
> >      return Status;
> >    }
> >
> > +  //
> > +  // Save the driver image handle.
> > +  //
> > +  mImageHandle = ImageHandle;
> > +
> >    //
> >    // Publish the HII package list to HII Database.
> >    //
> > diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.c
> b/OvmfPkg/PlatformDxe/PlatformConfig.c
> > index e202ac5b4798..f5ac2d0609ff 100644
> > --- a/OvmfPkg/PlatformDxe/PlatformConfig.c
> > +++ b/OvmfPkg/PlatformDxe/PlatformConfig.c
> > @@ -21,7 +21,7 @@
> >  //
> >  // Name of the UEFI variable that we use for persistent storage.
> >  //
> > -STATIC CHAR16  mVariableName[] = L"PlatformConfig";
> > +CHAR16  mVariableName[] = L"PlatformConfig";
> >
> >  /**
> >    Serialize and persistently save platform configuration.
> > --
> > 2.37.2
> >

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

* Re: [edk2-devel] [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig
  2022-09-05 12:11   ` Samer El-Haj-Mahmoud
@ 2022-09-05 13:53     ` Ard Biesheuvel
  0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2022-09-05 13:53 UTC (permalink / raw)
  To: devel, samer.el-haj-mahmoud
  Cc: Dimitrije Pavlov, Ard Biesheuvel, Jiewen Yao, Liming Gao,
	Sunny Wang, Jeff Booher-Kaeding, nd

On Mon, 5 Sept 2022 at 14:11, Samer El-Haj-Mahmoud
<samer.el-haj-mahmoud@arm.com> wrote:
>
> Hi Ard,
>
> Yes, this was found during SCT testing:
>
> HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig- ExtractConfig() returns EFI_SUCCESS or EFI_NOT_FOUND with Request been NULL . -- FAILURE
> 603E52F0-2CE3-4E7A-A72E-DF8CA3FDB20D
> /home/dpavlov/qemu-cert/custom-testing/arm-systemready/SR/scripts/edk2-test/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/HIIConfigAccess/BlackBoxTest/HIIConfigAccessBBTestFunction.c:448: Status - Invalid Parameter
>


Merged as #3287

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

end of thread, other threads:[~2022-09-05 13:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-18 19:58 [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig Dimitrije Pavlov
2022-09-05 12:01 ` Ard Biesheuvel
2022-09-05 12:11   ` Samer El-Haj-Mahmoud
2022-09-05 13:53     ` [edk2-devel] " Ard Biesheuvel

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