public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner" <abner.chang@amd.com>
To: Minh Nguyen <minhnguyen1@os.amperecomputing.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "patches@amperecomputing.com" <patches@amperecomputing.com>,
	"nicklew@nvidia.com" <nicklew@nvidia.com>,
	"igork@ami.com" <igork@ami.com>,
	"nhi@os.amperecomputing.com" <nhi@os.amperecomputing.com>,
	Vu Nguyen <vunguyen@os.amperecomputing.com>,
	Nick Ramirez <nramirez@nvidia.com>
Subject: Re: [PATCH V2 3/5] RedfishPkg: Create RestEx child on selected interface
Date: Thu, 4 May 2023 08:00:19 +0000	[thread overview]
Message-ID: <MN2PR12MB3966A08C0F8291D7C93A7A53EA6D9@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20230504041945.1377457-4-minhnguyen1@os.amperecomputing.com>

[AMD Official Use Only - General]

Hi Minh, please check my comment inline,

> -----Original Message-----
> From: Minh Nguyen <minhnguyen1@os.amperecomputing.com>
> Sent: Thursday, May 4, 2023 12:20 PM
> To: devel@edk2.groups.io
> Cc: patches@amperecomputing.com; Chang, Abner
> <Abner.Chang@amd.com>; nicklew@nvidia.com; igork@ami.com;
> nhi@os.amperecomputing.com; Vu Nguyen
> <vunguyen@os.amperecomputing.com>; Minh Nguyen
> <minhnguyen1@os.amperecomputing.com>; Nick Ramirez
> <nramirez@nvidia.com>
> Subject: [PATCH V2 3/5] RedfishPkg: Create RestEx child on selected
> interface
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> From: Vu Nguyen <vunguyen@os.amperecomputing.com>
> 
> When a MAC address matching interface is found, a RestEx child will be
> created to provide the Redfish communication on that interface.
> Currently, It will try to locate all RestEx binding services and choose the first
> satisfied instance without taking care about current selected interface. This
> might raise an issue on the system with multiple network devices that the
> RestEx child was installed on wrong interface.
> 
> Signed-off-by: Minh Nguyen <minhnguyen1@os.amperecomputing.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  RedfishPkg/Include/Library/RestExLib.h             |   3 +
>  RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c     | 153 ++++++++----------
> --
>  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c |   1 +
>  3 files changed, 63 insertions(+), 94 deletions(-)
> 
> diff --git a/RedfishPkg/Include/Library/RestExLib.h
> b/RedfishPkg/Include/Library/RestExLib.h
> index bc4e4ca6caa7..2c32c3684cf4 100644
> --- a/RedfishPkg/Include/Library/RestExLib.h
> +++ b/RedfishPkg/Include/Library/RestExLib.h
> @@ -2,6 +2,7 @@
>    This library provides help functions for REST EX Protocol.
> 
>    (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -20,6 +21,7 @@
>    This function allows the caller to create child handle for specific
>    REST server.
> 
> +  @param[in]  Controller           The controller handle used of selected
> interface.
>    @param[in]  Image                The image handle used to open service.
>    @param[in]  AccessMode           Access mode of REST server.
>    @param[in]  ConfigType           Underlying configuration to communicate
> with REST server.
> @@ -32,6 +34,7 @@
>  **/
>  EFI_STATUS
>  RestExLibCreateChild (
> +  IN EFI_HANDLE                       Controller,
>    IN EFI_HANDLE                       Image,
>    IN EFI_REST_EX_SERVICE_ACCESS_MODE  AccessMode,
>    IN EFI_REST_EX_CONFIG_TYPE          ConfigType,
> diff --git a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c
> b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c
> index d9acad24dec1..6002be93c54e 100644
> --- a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c
> +++ b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c
> @@ -2,6 +2,7 @@
>    This library provides help functions for REST EX Protocol.
> 
>    (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -9,6 +10,7 @@
> 
>  #include <Uefi.h>
>  #include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
>  #include <Library/MemoryAllocationLib.h>  #include <Library/NetLib.h>
> #include <Library/UefiBootServicesTableLib.h>
> @@ -21,6 +23,7 @@
>    This function allows the caller to create child handle for specific
>    REST server.
> 
> +  @param[in]  Controller           The controller handle used of selected
> interface.
>    @param[in]  Image                The image handle used to open service.
>    @param[in]  AccessMode           Access mode of REST server.
>    @param[in]  ConfigType           Underlying configuration to communicate
> with REST server.
> @@ -33,6 +36,7 @@
>  **/
>  EFI_STATUS
>  RestExLibCreateChild (
> +  IN EFI_HANDLE                       Controller,
>    IN EFI_HANDLE                       Image,
>    IN EFI_REST_EX_SERVICE_ACCESS_MODE  AccessMode,
>    IN EFI_REST_EX_CONFIG_TYPE          ConfigType,
> @@ -41,8 +45,6 @@ RestExLibCreateChild (
>    )
>  {
>    EFI_STATUS                Status;
> -  UINTN                     NoBuffer;
> -  EFI_HANDLE                *Handle;
>    EFI_HANDLE                ChildHandle;
>    EFI_REST_EX_PROTOCOL      *RestEx;
>    EFI_REST_EX_SERVICE_INFO  *RestExServiceInfo; @@ -59,116 +61,79 @@
> RestExLibCreateChild (
>    }
> 
>    *ChildInstanceHandle = NULL;
> -  //
> -  // Locate all REST EX binding service.
> -  //
> -  Handle   = NULL;
> -  NoBuffer = 0;
> -  Status   = gBS->LocateHandleBuffer (
> -                    ByProtocol,
> -                    &gEfiRestExServiceBindingProtocolGuid,
> -                    NULL,
> -                    &NoBuffer,
> -                    &Handle
> -                    );
> -  if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
> +
> +  ChildHandle = NULL;
> +  Status = NetLibCreateServiceChild (
> +             Controller,
> +             Image,
> +             &gEfiRestExServiceBindingProtocolGuid,
> +             &ChildHandle
> +             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: Failed to create service child - %r \n",
> +      __FUNCTION__,
The latest PatchCheck throws error for "__FUNCTION__", we should use "__func__" otherwise it wont it pass PatchCheck and edk2 CI. 

I have no problem with this code in generally. Just would like to confirm with you if you use RedfishConfigHandlerDriver on your system and does it work fine with the change in this patch?

Thanks
Abner


> +      Status
> +      ));
>      return Status;
>    }
> -
> -  Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof (EFI_HANDLE) *
> NoBuffer);
> -  if (Handle == NULL) {
> -    return EFI_OUT_OF_RESOURCES;
> -  }
> -
> -  Status = gBS->LocateHandleBuffer (
> -                  ByProtocol,
> -                  &gEfiRestExServiceBindingProtocolGuid,
> +  Status = gBS->OpenProtocol (
> +                  ChildHandle,
> +                  &gEfiRestExProtocolGuid,
> +                  (VOID **)&RestEx,
> +                  Image,
>                    NULL,
> -                  &NoBuffer,
> -                  &Handle
> +                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
>                    );
>    if (EFI_ERROR (Status)) {
> -    FreePool (Handle);
> -    return Status;
> +    goto ON_ERROR;
>    }
> 
>    //
> -  // Search for the proper REST EX instance.
> +  // Get the information of REST service provided by this EFI REST EX
> + driver
>    //
> -  while (NoBuffer != 0) {
> -    ChildHandle = NULL;
> -    Status      = NetLibCreateServiceChild (
> -                    *(Handle + (NoBuffer - 1)),
> -                    Image,
> -                    &gEfiRestExServiceBindingProtocolGuid,
> -                    &ChildHandle
> -                    );
> -    if (!EFI_ERROR (Status)) {
> -      Status = gBS->OpenProtocol (
> -                      ChildHandle,
> -                      &gEfiRestExProtocolGuid,
> -                      (VOID **)&RestEx,
> -                      Image,
> -                      NULL,
> -                      EFI_OPEN_PROTOCOL_GET_PROTOCOL
> -                      );
> -      if (EFI_ERROR (Status)) {
> -        goto ON_ERROR;
> -      }
> -
> -      //
> -      // Get the information of REST service provided by this EFI REST EX driver
> -      //
> -      Status = RestEx->GetService (
> -                         RestEx,
> -                         &RestExServiceInfo
> -                         );
> -      if (EFI_ERROR (Status)) {
> -        goto ON_ERROR;
> -      }
> -
> -      //
> -      // Check REST EX property.
> -      //
> -      switch (ConfigType) {
> -        case EfiRestExConfigHttp:
> -          LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
> -          break;
> -
> -        case EfiRestExConfigUnspecific:
> -          LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;
> -          break;
> +  Status = RestEx->GetService (
> +                     RestEx,
> +                     &RestExServiceInfo
> +                     );
> +  if (EFI_ERROR (Status)) {
> +    goto ON_ERROR;
> +  }
> +  //
> +  // Check REST EX property.
> +  //
> +  switch (ConfigType) {
> +  case EfiRestExConfigHttp:
> +    LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
> +    break;
> 
> -        default:
> -          goto ON_ERROR;
> -      }
> +  case EfiRestExConfigUnspecific:
> +    LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;
> +    break;
> 
> -      if ((RestExServiceInfo-
> >EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||
> -          (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType !=
> ServiceType) ||
> -          (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType !=
> ConfigType) ||
> -          ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) &&
> (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength !=
> LenOfConfig)))
> -      {
> -        goto ON_ERROR;
> -      }
> -    }
> +  default:
> +    goto ON_ERROR;
> +  }
> +  if (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode !=
> AccessMode ||
> +      RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType !=
> ServiceType ||
> +      RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType !=
> ConfigType ||
> +      ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) &&
> (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength !=
> LenOfConfig))) {
> +    goto ON_ERROR;
> +  }
> 
> -    //
> -    // This is proper REST EX instance.
> -    //
> -    *ChildInstanceHandle = ChildHandle;
> -    FreePool (Handle);
> -    return EFI_SUCCESS;
> +  //
> +  // This is proper REST EX instance.
> +  //
> +  *ChildInstanceHandle = ChildHandle;
> +  return EFI_SUCCESS;
> 
>  ON_ERROR:;
>      NetLibDestroyServiceChild (
> -      *(Handle + (NoBuffer - 1)),
> +      Controller,
>        Image,
>        &gEfiRestExServiceBindingProtocolGuid,
>        ChildHandle
>        );
> -    NoBuffer--;
> -  }
> -
> -  FreePool (Handle);
>    return EFI_NOT_FOUND;
>  }
> diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> index a247bfed9e34..dd5bdbb377e9 100644
> --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> @@ -87,6 +87,7 @@ CreateRestExInstance (
>    EFI_STATUS  Status;
> 
>    Status = RestExLibCreateChild (
> +             Instance->NetworkInterface->OpenDriverControllerHandle,
>               Instance->Owner,
>               FixedPcdGetBool (PcdRedfishDiscoverAccessModeInBand) ?
> EfiRestExServiceInBandAccess : EfiRestExServiceOutOfBandAccess,
>               EfiRestExConfigHttp,
> --
> 2.39.0

  reply	other threads:[~2023-05-04  8:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  4:19 [PATCH V2 0/5] Adding necessary changes for RedfishPkg Minh Nguyen
2023-05-04  4:19 ` [PATCH V2 1/5] RedfishPkg: Correct variable type to prevent memory corruption Minh Nguyen
2023-05-04  4:19 ` [PATCH V2 2/5] RedfishPkg: Fix condition checking of error status Minh Nguyen
2023-05-04  7:00   ` Nickle Wang
2023-05-04  4:19 ` [PATCH V2 3/5] RedfishPkg: Create RestEx child on selected interface Minh Nguyen
2023-05-04  8:00   ` Chang, Abner [this message]
2023-05-04  8:26     ` Minh Nguyen
2023-05-05  3:59       ` Minh Nguyen
2023-05-05  4:03         ` Chang, Abner
2023-05-04  4:19 ` [PATCH V2 4/5] RedfishPkg: Add missing newline character Minh Nguyen
2023-05-04  4:19 ` [PATCH V2 5/5] RedfishPkg: Fix compile issue on Linux Minh Nguyen

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=MN2PR12MB3966A08C0F8291D7C93A7A53EA6D9@MN2PR12MB3966.namprd12.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