From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) by mx.groups.io with SMTP id smtpd.web09.4930.1631247783797447376 for ; Thu, 09 Sep 2021 21:23:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qi+OLZ7U; spf=pass (domain: gmail.com, ip: 209.85.222.46, mailfrom: pedro.falcato@gmail.com) Received: by mail-ua1-f46.google.com with SMTP id j31so417290uad.10 for ; Thu, 09 Sep 2021 21:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IxyrbdOLSwpI5uXZw/LAr245Q8CK0DI0zq+huNAT+Ps=; b=qi+OLZ7UNgq8sz4LXS0xgJW4YvmRt2IzVC8VuEX6X4slGmBsJ37nLX6/aZ9S4E3HeH XSItzwzetacnt0vTXofr4s1IZEmzxF95RiFDZNI0ZVfSIXHTiPlrJNXQnwXQDU+Y7goT uM+RGTKGb21lutahfOaIxZrba/LfKbbG/0d3w825ZZDWzcYHZT9qL0pDp8dqQAXXIr/0 Big6vXphpnMG2Utag9FQ57q4x7XhcsSLNLE0SXK6eIZI7RePcyp5StcxRn6oDYGJ/XKI jBlP2RQMFSjk5+JtVCINENfUmSPf5h9HEeUbdhPSVsOroPNgsNuS9a/sGP0gysL4Tuot I8bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IxyrbdOLSwpI5uXZw/LAr245Q8CK0DI0zq+huNAT+Ps=; b=SX7FKBuDoqRIyi+Ykt0Gsb8F0EwkFnvIaI0v46Sn3ZHhzxFOdHRsUm53aFpI+AR/Ic yHjUvszlrze2txbOd55ho6MJhv/YGiD7TdaWqU4v/tHMcKqYW3Mwmm0TUrABq8PU2/47 RnUZmOdXweF3bMgi8OtmYCszDBgSWYjIf/1POUZXQ3tmneZJM7nWcVOJgtu5tnTYErZ8 PlLVfYKrUEJFNp7pMeXl0iUVE9GoGoHmT1UFACC6YxpUNT1K5eTYBcy9mhgwhHtQGqil cl4XKpDa0fQw767Ub7nHAnhr3ZJ1EvXwWhonf+N/a6tanipqgtYjInsXzejvnvOCmOAJ r//w== X-Gm-Message-State: AOAM531+hNxRP7R6E9uHVCuajnw/df5hHXYF+mpEY9WLbrcT7sleFyUg MYoXxW/pcHNtS/2aQXMn3x3KR+pqJ3SOIJZspGx60AvIn6/0Mw== X-Google-Smtp-Source: ABdhPJxVsdVwvgNGiWGBCai2V4Oi/NUiY8EPbl1/xPr/WZWNiW3YxzpkuKJaYQ+g7spQxk/RtmZ67ZKEY2SjgLf7yvo= X-Received: by 2002:ab0:780a:: with SMTP id x10mr2135633uaq.24.1631247782851; Thu, 09 Sep 2021 21:23:02 -0700 (PDT) MIME-Version: 1.0 References: <9c6ac428e55f3584295bd490502532ba456b4d3f.1631219610.git.jbrasen@nvidia.com> In-Reply-To: <9c6ac428e55f3584295bd490502532ba456b4d3f.1631219610.git.jbrasen@nvidia.com> From: "Pedro Falcato" Date: Fri, 10 Sep 2021 05:22:51 +0100 Message-ID: Subject: Re: [PATCH 1/2] Ext4Pkg: Improve Binding support behavior To: Jeff Brasen Cc: edk2-devel-groups-io Content-Type: text/plain; charset="UTF-8" Hi Jeff, Comments below. The patch itself looks good. Nitpick on the commit message: I'd reword the commit message to something like "Improve Ext4IsBindingSupported() behavior" or "Improve IsBindingSupported behavior", since this patch doesn't change Ext4Bind(), which does the actual bind. On Thu, Sep 9, 2021 at 9:41 PM Jeff Brasen wrote: > > A couple improvements to improve performance. > Add check to return ACCESS_DENIED if already connected > Add check to verify superblock magic during supported to deduce start calls > > Signed-off-by: Jeff Brasen > --- > Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 14 +++++++ > Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c | 57 +++++++++++++++++++++------ > Features/Ext4Pkg/Ext4Dxe/Superblock.c | 34 ++++++++++++++++ > 3 files changed, 92 insertions(+), 13 deletions(-) > > diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > index 64eab455db..9a3938e671 100644 > --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > @@ -1117,4 +1117,18 @@ Ext4GetVolumeName ( > OUT UINTN *VolNameLen > ); > > +/** > + Checks only superblock magic value. > + > + @param[in] DiskIo Pointer to the DiskIo. > + @param[in] BlockIo Pointer to the BlockIo. > + > + @return TRUE if a valid ext4 superblock, else FALSE. > +**/ > +BOOLEAN > +Ext4SuperblockCheckMagic ( > + IN EFI_DISK_IO_PROTOCOL *DiskIo, > + IN EFI_BLOCK_IO_PROTOCOL *BlockIo > + ); I'd reword the first part of the comment into something like "Checks the superblock's magic value.". Aligning the two "Pointer to the ...Io" would be neat :) Types and parameter names need to be separated by at least two columns. So, something like: IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_BLOCK_IO_PROTOCOL *BlockIo The feedback above also applies to the function's definition below, in Superblock.c. > + > #endif > diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c > index ea2e048d77..cb1e6d532a 100644 > --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c > +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c > @@ -631,7 +631,6 @@ Ext4Unload ( > @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and > RemainingDevicePath is already being managed by a different > driver or an application that requires exclusive access. > - Currently not implemented. > @retval EFI_UNSUPPORTED The device specified by ControllerHandle and > RemainingDevicePath is not supported by the driver specified by This. > **/ > @@ -643,32 +642,64 @@ Ext4IsBindingSupported ( > IN EFI_DEVICE_PATH *RemainingDevicePath OPTIONAL > ) > { > - // Note to self: EFI_OPEN_PROTOCOL_TEST_PROTOCOL lets us not close the > - // protocol and ignore the output argument entirely > - > - EFI_STATUS Status; > + EFI_STATUS Status; > + EFI_DISK_IO_PROTOCOL *DiskIo = NULL; > + EFI_BLOCK_IO_PROTOCOL *BlockIo = NULL; > Initialization of variables are always separate from the declaration. Example: EFI_DISK_IO_PROTOCOL *DiskIo; ... DiskIo = NULL; > + // > + // Open the IO Abstraction(s) needed to perform the supported test > + // > Status = gBS->OpenProtocol ( > ControllerHandle, > &gEfiDiskIoProtocolGuid, > - NULL, > - BindingProtocol->ImageHandle, > + (VOID **) &DiskIo, > + BindingProtocol->DriverBindingHandle, > ControllerHandle, > - EFI_OPEN_PROTOCOL_TEST_PROTOCOL > + EFI_OPEN_PROTOCOL_BY_DRIVER > ); > > if (EFI_ERROR (Status)) { > - return Status; > + goto Exit; > } > - > + // > + // Open the IO Abstraction(s) needed to perform the supported test > + // > Status = gBS->OpenProtocol ( > ControllerHandle, > &gEfiBlockIoProtocolGuid, > - NULL, > - BindingProtocol->ImageHandle, > + (VOID **) &BlockIo, > + BindingProtocol->DriverBindingHandle, > ControllerHandle, > - EFI_OPEN_PROTOCOL_TEST_PROTOCOL > + EFI_OPEN_PROTOCOL_GET_PROTOCOL > ); > + if (EFI_ERROR (Status)) { > + goto Exit; > + } > + > + if (!Ext4SuperblockCheckMagic (DiskIo, BlockIo)) { > + Status = EFI_UNSUPPORTED; > + } > + > +Exit: > + // > + // Close the I/O Abstraction(s) used to perform the supported test > + // > + if (DiskIo != NULL) { > + gBS->CloseProtocol ( > + ControllerHandle, > + &gEfiDiskIoProtocolGuid, > + BindingProtocol->DriverBindingHandle, > + ControllerHandle > + ); > + } > + if (BlockIo != NULL) { > + gBS->CloseProtocol ( > + ControllerHandle, > + &gEfiBlockIoProtocolGuid, > + BindingProtocol->DriverBindingHandle, > + ControllerHandle > + ); > + } > return Status; > } > > diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4Dxe/Superblock.c > index c321d8c3d8..1f8cdd3705 100644 > --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c > +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c > @@ -34,6 +34,40 @@ STATIC CONST UINT32 gSupportedIncompatFeat = > // this is desired, it's fairly trivial to look for EFI_VOLUME_CORRUPTED > // references and add some Ext4SignalCorruption function + function call. > > +/** > + Checks only superblock magic value. > + > + @param[in] DiskIo Pointer to the DiskIo. > + @param[in] BlockIo Pointer to the BlockIo. > + > + @return TRUE if a valid ext4 superblock, else FALSE. > +**/ > +BOOLEAN > +Ext4SuperblockCheckMagic ( > + IN EFI_DISK_IO_PROTOCOL *DiskIo, > + IN EFI_BLOCK_IO_PROTOCOL *BlockIo > + ) Same as above. > +{ > + UINT16 Magic; > + EFI_STATUS Status; > + > + Status = DiskIo->ReadDisk (DiskIo, > + BlockIo->Media->MediaId, > + EXT4_SUPERBLOCK_OFFSET + OFFSET_OF (EXT4_SUPERBLOCK, s_magic), > + sizeof (Magic), > + &Magic > + ); Splitting a function call in multiple lines should be done like in https://edk2-docs.gitbook.io/edk-ii-c-coding-standards-specification/5_source_files/52_spacing#5-2-2-4-subsequent-lines-of-multi-line-function-calls-should-line-up-two-spaces-from-the-beginning-of-the-function-name. > + if (EFI_ERROR (Status)) { > + return FALSE; > + } > + > + if (Magic != EXT4_SIGNATURE) { > + return FALSE; > + } > + > + return TRUE; > +} > + > /** > Does brief validation of the ext4 superblock. > > -- > 2.17.1 > -- Pedro Falcato