xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Luca Fancellu <luca.fancellu@arm.com>
Cc: bertrand.marquis@arm.com, wei.chen@arm.com, iwj@xenproject.org,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH-4.16 v2] xen/efi: Fix Grub2 boot on arm64
Date: Thu, 4 Nov 2021 17:36:09 +0100	[thread overview]
Message-ID: <81685961-501e-7a41-6f6f-bc4491645264@suse.com> (raw)
In-Reply-To: <20211104141206.25153-1-luca.fancellu@arm.com>

On 04.11.2021 15:12, Luca Fancellu wrote:
> --- a/xen/common/efi/boot.c
> +++ b/xen/common/efi/boot.c
> @@ -449,6 +449,15 @@ static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
>      CHAR16 *pathend, *ptr;
>      EFI_STATUS ret;
>  
> +    /*
> +     * Grub2 running on top of EDK2 has been observed to supply a NULL
> +     * DeviceHandle. We can't use that to gain access to the filesystem.
> +     * However the system can still boot if it doesn’t require access to the
> +     * filesystem.
> +     */
> +    if ( !loaded_image->DeviceHandle )
> +        return NULL;
> +
>      do {
>          EFI_FILE_IO_INTERFACE *fio;
>  
> @@ -581,6 +590,8 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
>      EFI_STATUS ret;
>      const CHAR16 *what = NULL;
>  
> +    if ( !dir_handle )
> +        blexit(L"Error: No access to the filesystem");
>      if ( !name )
>          PrintErrMesg(L"No filename", EFI_OUT_OF_RESOURCES);
>      ret = dir_handle->Open(dir_handle, &FileHandle, name,
> @@ -1333,8 +1344,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>              EFI_FILE_HANDLE handle = get_parent_handle(loaded_image,
>                                                         &file_name);
>  
> -            handle->Close(handle);
> -            *argv = file_name;
> +            if ( !handle )
> +            {
> +                PrintErr(L"Error retrieving image name: no filesystem access."
> +                         L" Setting default to xen.efi");
> +                PrintErr(newline);
> +                *argv = L"xen.efi";
> +            }
> +            else
> +            {
> +                handle->Close(handle);
> +                *argv = file_name;
> +            }
>          }
>  
>          name.s = get_value(&cfg, section.s, "options");
> @@ -1369,7 +1390,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      /* Get the number of boot modules specified on the DT or an error (<0) */
>      dt_modules_found = efi_check_dt_boot(dir_handle);
>  
> -    dir_handle->Close(dir_handle);
> +    if ( dir_handle )
> +        dir_handle->Close(dir_handle);
>  
>      if ( dt_modules_found < 0 )
>          /* efi_check_dt_boot throws some error */
> 

I'm sorry, but I think we need to take a step back here and revisit
the earlier change. If that hadn't moved obtaining dir_handle out by
one level of scope, nothing bad would have happened to the case that
you're now trying to fix, I understand? So perhaps that part wants
undoing, with efi_check_dt_boot() instead getting passed loaded_image.
That way, down the call tree the needed handle can be obtained via
another call to get_parent_handle(), and quite likely in the scenario
you're trying to fix here execution wouldn't even make it there. This
then wouldn't be much different to the image name retrieval calling
get_parent_handle() a 2nd time, rather than trying to re-use
dir_handle.

Net effect being that I think get_parent_handle() would then again
only be called when the returned handle is actually needed, and hence
when failure of HandleProtocol() (for DeviceHandle being NULL just
like for any other reason) is indeed an error that needs reporting.

Jan



  parent reply	other threads:[~2021-11-04 16:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 14:12 [PATCH-4.16 v2] xen/efi: Fix Grub2 boot on arm64 Luca Fancellu
2021-11-04 14:33 ` Bertrand Marquis
2021-11-04 14:44   ` Ian Jackson
2021-11-04 16:36 ` Jan Beulich [this message]
2021-11-04 20:56   ` Stefano Stabellini
2021-11-04 21:07     ` Luca Fancellu
2021-11-04 21:35       ` Stefano Stabellini
2021-11-04 21:43         ` Luca Fancellu
2021-11-04 21:50           ` Stefano Stabellini
2021-11-05  7:35             ` Jan Beulich
2021-11-05 15:33               ` Stefano Stabellini
2021-11-08  7:25                 ` Jan Beulich
2021-11-09  2:11                   ` Stefano Stabellini
2021-11-09  9:23                     ` Luca Fancellu
2021-11-09 11:01                       ` Jan Beulich
2021-11-09 11:00                     ` Jan Beulich
2021-11-09 21:52                       ` Stefano Stabellini
2021-11-09 22:31                         ` Julien Grall
2021-11-10  7:40                         ` Jan Beulich
2021-11-10 13:05                         ` Luca Fancellu
2021-11-10 13:36                           ` Julien Grall
2021-11-10 14:02                             ` Luca Fancellu
2021-11-15 18:57                               ` Julien Grall
2021-11-15 22:00                                 ` Stefano Stabellini
2021-11-16  8:36                                   ` Luca Fancellu
2021-11-16 15:08                                     ` Ian Jackson
2021-11-16 16:11                                       ` Jan Beulich
2021-11-16 16:23                                       ` Julien Grall
2021-11-05  7:32           ` Jan Beulich
2021-11-05  7:27     ` Jan Beulich
2021-11-04 20:51 ` Stefano Stabellini

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-all 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=81685961-501e-7a41-6f6f-bc4491645264@suse.com \
    --to=jbeulich@suse.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=iwj@xenproject.org \
    --cc=julien@xen.org \
    --cc=luca.fancellu@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=wei.chen@arm.com \
    --cc=xen-devel@lists.xenproject.org \
    /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;
as well as URLs for NNTP newsgroup(s).