From: "Marvin Häuser" <mhaeuser@posteo.de>
To: devel@edk2.groups.io, jbrasen@nvidia.com
Cc: pedro.falcato@gmail.com
Subject: Re: [edk2-devel] [PATCH 1/2] Ext4Pkg: Improve Binding support behavior
Date: Fri, 10 Sep 2021 16:24:57 +0000 [thread overview]
Message-ID: <c7956a5c-a5e7-b0c8-200f-e5eaa1e922db@posteo.de> (raw)
In-Reply-To: <9c6ac428e55f3584295bd490502532ba456b4d3f.1631219610.git.jbrasen@nvidia.com>
Good day,
On 09/09/2021 22:41, Jeff Brasen via groups.io wrote:
> A couple improvements to improve performance.
> Add check to return ACCESS_DENIED if already connected
This "performance improvement" actually aligns the load behaviour with
the UEFI spec, maybe it should be mentioned?
> Add check to verify superblock magic during supported to deduce start calls
>
> Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
> ---
> 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
> + );
> +
> #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;
>
> + //
> + // 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;
This change is not required as nothing was opened on failure; see below.
> }
> -
> + //
> + // 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
Why do the open modes mismatch if both protocols are equally stored in
the private partition data? Is the owner of Block I/O a different one
than the one of Disk I/O?
> );
> + if (EFI_ERROR (Status)) {
> + goto Exit;
> + }
> +
> + if (!Ext4SuperblockCheckMagic (DiskIo, BlockIo)) {
> + Status = EFI_UNSUPPORTED;
> + }
This can easily be rewritten to not require "goto":
if (!EFI_ERROR (Status) && !Ext4SuperblockCheckMagic (DiskIo, BlockIo)) {
Status = EFI_UNSUPPORTED;
}
With the change above this allows to drop the label and any "goto" code.
> +
> +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
> + );
> + }
Protocols retrieved by GET_PROTOCOL are not closed.
> 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.
Whether it "only" checks the magic is more of a functional detail than
an actual description.
> +
> + @param[in] DiskIo Pointer to the DiskIo.
> + @param[in] BlockIo Pointer to the BlockIo.
> +
> + @return TRUE if a valid ext4 superblock, else FALSE.
Maybe use "@returns Whether the partition has a valid EXT4 superblock
magic" for readability?
Best regards,
Marvin
> +**/
> +BOOLEAN
> +Ext4SuperblockCheckMagic (
> + IN EFI_DISK_IO_PROTOCOL *DiskIo,
> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo
> + )
> +{
> + UINT16 Magic;
> + EFI_STATUS Status;
> +
> + Status = DiskIo->ReadDisk (DiskIo,
> + BlockIo->Media->MediaId,
> + EXT4_SUPERBLOCK_OFFSET + OFFSET_OF (EXT4_SUPERBLOCK, s_magic),
> + sizeof (Magic),
> + &Magic
> + );
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> +
> + if (Magic != EXT4_SIGNATURE) {
> + return FALSE;
> + }
> +
> + return TRUE;
> +}
> +
> /**
> Does brief validation of the ext4 superblock.
>
next prev parent reply other threads:[~2021-09-10 16:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 20:40 [PATCH 0/2] ExtPkg Updates Jeff Brasen
2021-09-09 20:41 ` [PATCH 1/2] Ext4Pkg: Improve Binding support behavior Jeff Brasen
2021-09-10 4:22 ` Pedro Falcato
2021-09-10 4:34 ` Jeff Brasen
2021-09-10 16:24 ` Marvin Häuser [this message]
2021-09-09 20:41 ` [PATCH 2/2] Ext4Pkg: Support non-cleanlty unmounted filesystems Jeff Brasen
2021-09-10 4:35 ` Pedro Falcato
2021-09-10 4:40 ` [PATCH 0/2] ExtPkg Updates Pedro Falcato
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=c7956a5c-a5e7-b0c8-200f-e5eaa1e922db@posteo.de \
--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