Misc EFI boot fixes
cover Misc EFI boot fixes
Fixes for a couple of annoyances when booting Xen using the native EFI entry point.
Ross Lagerwall (2):
efi: Call FreePages only if needed
efi: Stop using StdErr
xen/common/efi/boot.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/2 efi: Call FreePages only if needed
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls FreePages() on the address.
Xen may also call FreePages() with a zero address if blexit() is called after this point since cfg.need_to_free is not set to false.
The UEFI specification does not say whether calling FreePages() with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.
--- xen/common/efi/boot.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
xen/common/efi/boot.c +5 -2
@@ -1534,8 +1534,11 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle,efi_arch_cfg_file_late (loaded_image, dir_handle, section.s); - efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); - cfg.addr =0 ; +if ( cfg.need_to_free ) + { + efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); + cfg.need_to_free = false; + }if ( dir_handle ) dir_handle->Close (dir_handle);
Signature · 1 line
2.50.1
Re: [PATCH 1/2] efi: Call FreePages only if needed
Quoted 11 lines · Ross Lagerwall
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls
FreePages()on the address.Xen may also call
FreePages()with a zero address ifblexit()is called after this point since cfg.need_to_free is not set to false.The UEFI specification does not say whether calling
FreePages()with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.Signed-off-by Ross Lagerwall <[email protected]>
Re: [PATCH 1/2] efi: Call FreePages only if needed
In reply to Ross LagerwallQuoted 9 lines · Ross Lagerwall
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls
FreePages()on the address.Xen may also call
FreePages()with a zero address ifblexit()is called after this point since cfg.need_to_free is not set to false.The UEFI specification does not say whether calling
FreePages()with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.
Well, no, this paragraph makes no sense. Of course this is allowed, but not as no-op behavior (like free(NULL) would be), but to free memory starting at 0.
Quoted 1 line
Signed-off-by Ross Lagerwall <[email protected]>
This pretty clearly wants a Fixes: tag, or maybe it even needs to be two. I've checked the original code in 4.2, and things were consistent there, afaics. So breakage was introduced perhaps in one or two of the many re-works.
Jan
Re: [PATCH 1/2] efi: Call FreePages only if needed
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls
FreePages()on the address.Xen may also call
FreePages()with a zero address ifblexit()is called after this point since cfg.need_to_free is not set to false.
Quoted 7 lines
Quoted 3 lines
The UEFI specification does not say whether calling
FreePages()with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.Well, no, this paragraph makes no sense. Of course this is allowed, but not as no-op behavior (like free(NULL) would be), but to free memory starting at 0.
Fair enough. This paragraph could simply be dropped then.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Ross Lagerwall <[email protected]>This pretty clearly wants a Fixes: tag, or maybe it even needs to be two. I've checked the original code in 4.2, and things were consistent there, afaics. So breakage was introduced perhaps in one or two of the many re-works.
hypervisor/kernel/initrd images")
Do you want an updated patch or can these tweaks be done while committing?
Thanks,
Ross
Re: [PATCH 1/2] efi: Call FreePages only if needed
Quoted 28 lines · Ross Lagerwall
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls
FreePages()on the address.Xen may also call
FreePages()with a zero address ifblexit()is called after this point since cfg.need_to_free is not set to false.Quoted 7 lines
Quoted 3 lines
The UEFI specification does not say whether calling
FreePages()with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.Well, no, this paragraph makes no sense. Of course this is allowed, but not as no-op behavior (like free(NULL) would be), but to free memory starting at 0.
Fair enough. This paragraph could simply be dropped then.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Ross Lagerwall <[email protected]>This pretty clearly wants a Fixes: tag, or maybe it even needs to be two. I've checked the original code in 4.2, and things were consistent there, afaics. So breakage was introduced perhaps in one or two of the many re-works.
Quoted 5 lines
Fixes 8a71d50ed40b ("efi: Enable booting unifiedhypervisor/kernel/initrd images")
Fixes 04be2c3a0678 ("efi/boot.c: add file.need_to_free")Do you want an updated patch or can these tweaks be done while committing?
If the maintainers have no other requests that require a v2, I'm sure this can be done while committing.
Jan
Re: [PATCH 1/2] efi: Call FreePages only if needed
In reply to Ross LagerwallQuoted 23 lines · Ross Lagerwall
If the config file is builtin, cfg.addr will be zero but Xen unconditionally calls
FreePages()on the address.Xen may also call
FreePages()with a zero address ifblexit()is called after this point since cfg.need_to_free is not set to false.The UEFI specification does not say whether calling
FreePages()with a zero address is allowed so let's be cautious and use cfg.need_to_free properly.Signed-off-by Ross Lagerwall <[email protected]>--- xen/common/efi/boot.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)xen/common/efi/boot.c +0
-0@@ -1534,8 +1534,11 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle,efi_arch_cfg_file_late (loaded_image, dir_handle, section.s);
xen/common/efi/boot.c void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle, · line 1544
Quoted 10 lines
xen/common/efi/boot.c +5
-2- efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); - cfg.addr =0 ; +if ( cfg.need_to_free ) + { + efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); + cfg.need_to_free = false; + }if ( dir_handle ) dir_handle->Close (dir_handle);
Acked-by Daniel P. Smith <[email protected]>
PATCH 2/2 efi: Stop using StdErr
In reply to Ross LagerwallXen's use of StdErr is inconsistent. Some boot errors are reported using PrintErr() which uses StdErr and some are reported using blexit() which uses StdOut.
On my test system using OVMF, StdErr is not displayed on the emulated screen. Looking at other EFI applications, StdErr is just used for debug messages if at all.
Therefore, switch all boot output to use StdOut.
--- xen/common/efi/boot.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
xen/common/efi/boot.c +1 -8
@@ -153,7 +153,6 @@ static UINT32 __initdata efi_bs_revision;static EFI_HANDLE __initdata efi_ih;static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; -static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;static UINT32 __initdata mdesc_ver;static bool __initdata map_bs;
@@ -168,11 +167,7 @@ static void __init PrintStr(const CHAR16 *s) { StdOut->OutputString (StdOut, (CHAR16 *)s ); } - -static void __init PrintErr (const CHAR16 *s) -{ - StdErr->OutputString (StdErr, (CHAR16 *)s ); -} +#define PrintErr PrintStrstatic CHAR16 *__init FormatDec (UINT64 Val,CHAR16 *Buffer) {
@@ -287,7 +282,6 @@ static bool __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)/* generic routine for printing error messages */ static void __init noreturnPrintErrMesg (const CHAR16 *mesg,EFI_STATUS ErrCode) { - StdOut = StdErr;PrintErr (mesg);PrintErr (L": " );
@@ -914,7 +908,6 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl efi_fw_revision = SystemTable->FirmwareRevision; StdOut = SystemTable->ConOut; - StdErr = SystemTable->StdErr ?: StdOut; }static void __init efi_console_set_mode (void )
Signature · 1 line
2.50.1
Re: [PATCH 2/2] efi: Stop using StdErr
Quoted 3 lines · Ross Lagerwall
Xen's use of StdErr is inconsistent. Some boot errors are reported using
PrintErr()which uses StdErr and some are reported usingblexit()which uses StdOut.
... with PrintErrMesg() having
StdOut = StdErr;
apparently to address at least some of the inconsistencies. Perhaps blexit(), when not passed NULL, should similarly override StdOut.
Quoted 3 lines
On my test system using OVMF, StdErr is not displayed on the emulated screen. Looking at other EFI applications, StdErr is just used for debug messages if at all.
That's hardly how StdErr was meant to be used. And at the risk of being flamed for saying so, looking at other EFI applications (without saying of what prominence or origin they are) can hardly serve as a justification. If OVMF doesn't set up StdErr correctly (despite being configured / set up correctly), and if that can't be fixed there, imo what you want as a workaround is a command line option to override StdErr by StdOut even when SystemTable->StdErr is non-NULL.
Along the lines of the comment further up, inconsistencies in the use of StdErr vs StdOut may want addressing (separately).
But of course, not being EFI maintainer anymore, all of what I said above may be deemed entirely meaningless by the new maintainers.
Jan
Re: [PATCH 2/2] efi: Stop using StdErr
Quoted 25 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall
Xen's use of StdErr is inconsistent. Some boot errors are reported using
PrintErr()which uses StdErr and some are reported usingblexit()which uses StdOut.... with
PrintErrMesg()havingStdOut = StdErr;apparently to address at least some of the inconsistencies. Perhaps
blexit(), when not passed NULL, should similarly override StdOut.Quoted 3 lines
On my test system using OVMF, StdErr is not displayed on the emulated screen. Looking at other EFI applications, StdErr is just used for debug messages if at all.
That's hardly how StdErr was meant to be used. And at the risk of being flamed for saying so, looking at other EFI applications (without saying of what prominence or origin they are) can hardly serve as a justification. If OVMF doesn't set up StdErr correctly (despite being configured / set up correctly), and if that can't be fixed there, imo what you want as a workaround is a command line option to override StdErr by StdOut even when
SystemTable->StdErris non-NULL.
Quoted 3 lines
Along the lines of the comment further up, inconsistencies in the use of StdErr vs StdOut may want addressing (separately).
I tried to reproduce this on a few physical hosts and was unable to so for now I'll chalk it up as an OVMF bug / configuration issue and retract this patch. And yes, the StdErr vs StdOut issue should probably be addressed separately.
Thanks,
Ross