gfx: improvements when using multiboot2 and EFI
v2 cover gfx: improvements when using multiboot2 and EFI
Hello,
The following series contains some fixes and improvements related to graphics usage when booting Xen.
Proposed patches fix some shortcomings when using multiboot2, mostly the ignoring of the console=vga (or lack of) and the vga=gfx- parameters. It also switches default Xen behaviour from trying to reuse the currently set GOP mode instead of attempting to set the maximum supported resolution.
Thanks, Roger.
Roger Pau Monne (3):
efi: try to use the currently set GOP mode
multiboot2: parse console= and vga= options when setting GOP mode
multiboot2: do not set StdOut mode unconditionally
xen/arch/x86/boot/head.S | 13 ++++- xen/arch/x86/efi/efi-boot.h | 95 ++++++++++++++++++++++++++++--- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/common/efi/boot.c | 21 +++++++ 4 files changed, 120 insertions(+), 10 deletions(-)
Signature · 1 line
2.40.0
PATCH v2 1/3 efi: try to use the currently set GOP mode
Modify efi_find_gop_mode() so that passing cols or rows as 0 is interpreted as a request to attempt to keep the currently set mode, and do so if the mode query for information is successful and the depth is supported.
---
Changes since v1:
- Only update cols or rows if the value is 0.
- Leave depth alone.
--- xen/common/efi/boot.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
xen/common/efi/boot.c +21 -0
@@ -930,6 +930,27 @@ static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode = ~0 , info_size, size;unsigned int i; +if ( (!cols || !rows) && gop->Mode->Mode < gop->Mode->MaxMode ) + { +/* If no (valid) resolution suggested, try to use the current mode. */ + status = gop->QueryMode (gop, gop->Mode->Mode, &info_size, &mode_info); +if (EFI_ERROR (status) ) +PrintErr (L"Invalid current graphics mode\r\n" ); +else if ( mode_info->PixelFormat < PixelBltOnly ) +return gop->Mode->Mode; +else + { +/* +* Try to find a mode with the same resolution and a valid pixel +* format. +*/ +if ( !cols ) + cols = mode_info->HorizontalResolution; +if ( !rows ) + rows = mode_info->VerticalResolution; + } + } +for ( i = size =0 ; i < gop->Mode->MaxMode; ++i ) {unsigned int bpp =0 ;
Signature · 1 line
2.40.0
Re: [PATCH v2 1/3] efi: try to use the currently set GOP mode
Quoted 5 lines · Roger Pau Monne
Modify
efi_find_gop_mode()so that passing cols or rows as 0 is interpreted as a request to attempt to keep the currently set mode, and do so if the mode query for information is successful and the depth is supported.
Quoted 8 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v1:
- Only update cols or rows if the value is 0.
- Leave depth alone.--- xen/common/efi/boot.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
While I realize that docs/misc/efi.pandoc currently doesn't describe what rows/cols being zero means, I think that file needs updating in the course of what you're doing. Irrespective of this I'm uncertain about the change in behavior: Presently both values being 0 means "find biggest resolution mode", in an attempt to have as much info on the screen at a time as possible (in particular in case of problems). I certainly appreciate the desire to have a way to say "keep the current mode", but I don't think this should alter behavior of what's presently considered valid config settings.
Quoted 4 lines
xen/common/efi/boot.c +0
-0@@ -930,6 +930,27 @@ static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode = ~0 , info_size, size;
xen/common/efi/boot.c static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, · line 940
Quoted 10 lines
xen/common/efi/boot.c +8
-0unsigned int i; +if ( (!cols || !rows) && gop->Mode->Mode < gop->Mode->MaxMode ) + { +/* If no (valid) resolution suggested, try to use the current mode. */ + status = gop->QueryMode (gop, gop->Mode->Mode, &info_size, &mode_info); +if (EFI_ERROR (status) ) +PrintErr (L"Invalid current graphics mode\r\n" ); +else if ( mode_info->PixelFormat < PixelBltOnly ) +return gop->Mode->Mode;
What if one of cols/rows was non-zero? You then wouldn't fulfill the request. "depth", if non-zero, is also entirely ignored. (We don't fulfill such a request right now either, but not doing so becomes more odd now imo. In fact right now in this case we leave the screen alone, if I'm not mistaken, so there already looks to be a way to achieve what you're after.)
xen/common/efi/boot.c static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, · line 946
Quoted 6 lines
xen/common/efi/boot.c +6
-0+else + { +/* +* Try to find a mode with the same resolution and a valid pixel +* format. +*/
Is "valid" the right word here? I think you mean "usable for us" or some such?
xen/common/efi/boot.c static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, · line 952
Quoted 6 lines
xen/common/efi/boot.c +6
-0+if ( !cols ) + cols = mode_info->HorizontalResolution; +if ( !rows ) + rows = mode_info->VerticalResolution; + } + }
Overall with the resulting behavior I'm not sure the title really describes what's being done. You "try" only in certain cases.
Jan
PATCH v2 2/3 multiboot2: parse console= and vga= options when setting GOP mode
In reply to Roger Pau MonneOnly set the GOP mode if vga is selected in the console option, otherwise just fetch the information from the current mode in order to make it available to dom0.
Introduce support for passing the command line to the efi_multiboot2() helper, and parse the console= and vga= options if present.
Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
---
Changes since v1:
- Do not return the last occurrence of a command line.
- Rearrange the code for assembly processing of the cmdline and use lea.
- Merge patches handling console= and vga= together.
--- xen/arch/x86/boot/head.S | 13 ++++- xen/arch/x86/efi/efi-boot.h | 80 ++++++++++++++++++++++++++++++- xen/arch/x86/x86_64/asm-offsets.c | 1 + 3 files changed, 90 insertions(+), 4 deletions(-)
xen/arch/x86/boot/head.S +11 -2
@@ -221,9 +221,10 @@ __efi64_mb2_start: jmp x86_32_switch .Lefi_multiboot2_proto: - /* Zero EFI SystemTable and EFI ImageHandle addresses. */ + /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ xor %esi,%esi xor %edi,%edi + xor %edx,%edx /* Skip Multiboot2 information fixed part. */ lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx
@@ -261,6 +262,13 @@ __efi64_mb2_start: cmove MB2_efi64_ih(%rcx),%rdi je .Lefi_mb2_next_tag + /* Get command line from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_CMDLINE,MB2_tag_type(%rcx) + jne .Lno_cmdline + lea MB2_tag_string(%rcx),%rdx + jmp .Lefi_mb2_next_tag +.Lno_cmdline: + /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je .Lrun_bs
@@ -324,7 +332,8 @@ __efi64_mb2_start: /* * efi_multiboot2() is called according to System V AMD64 ABI: - * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. + * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable, + * %rdx - MB2 cmdline */ call efi_multiboot2
xen/arch/x86/efi/efi-boot.h +78 -2
92 lines not on this page · raw message
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -175,6 +175,7 @@ void __dummy__(void)OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);OFFSET (MB2_efi64_st, multiboot2_tag_efi64_t, pointer);OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer); +OFFSET (MB2_tag_string, multiboot2_tag_string_t, string);BLANK (); OFFSET(DOMAIN_vm_assist, struct domain, vm_assist);
Signature · 1 line
2.40.0
Re: [PATCH v2 2/3] multiboot2: parse console= and vga= options when setting GOP mode
Quoted 1 line · Roger Pau Monne
Only set the GOP mode if vga is selected in the console option,
This particular aspect of the behavior is inconsistent with legacy boot behavior: There "vga=" isn't qualified by what "console=" has.
Quoted 15 lines
otherwise just fetch the information from the current mode in order to make it available to dom0.
Introduce support for passing the command line to the
efi_multiboot2()helper, and parse the console= and vga= options if present.Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
Signed-off-by Roger Pau Monné <[email protected]>[...]
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 794
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +6
-1@@ -786,7 +786,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { } -void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return the next occurrence of opt in cmd. */ +static const char __init *get_option (const char *cmd,const char *opt) +{ +const char *s = cmd, *o =NULL ; + +if ( !cmd || !opt )
I can see why you need to check "cmd", but there's no need to check "opt" I would say.
Quoted 8 lines
xen/arch/x86/efi/efi-boot.h +3
-1@@ -807,7 +830,60 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *opt =NULL , *last = cmdline; +/* Default console selection is "com1,vga". */ +bool vga = true;
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 845
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ +/* For the console option the last occurrence is the enforced one. */ +while ( (last =get_option (last,"console=" )) !=NULL ) + opt = last; + +if ( opt ) + { +const char *s =strstr (opt,"vga" ); + +if ( !s || s >strpbrk (opt," " ) )
Why strpbrk() and not the simpler strchr()? Or did you mean to also look for tabs, but then didn't include \t here (and in get_option())? (Legacy boot code also takes \r and \n as separators, btw, but I'm unconvinced of the need.)
Also aiui this is UB when the function returns NULL, as relational operators (excluding equality ones) may only be applied when both addresses refer to the same object (or to the end of an involved array).
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 855
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ vga = false; + } + +if ( vga ) + { +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + + last = cmdline; +while ( (last =get_option (last,"vga=" )) !=NULL )
It's yet different for "vga=", I'm afraid: Early boot code (boot/cmdline.c) finds the first instance only. Normal command line handling respects the last instance only. So while "vga=gfx-... vga=keep" will have the expected effect, "vga=keep vga=gfx-..." won't (I think). It is certainly fine to be less inflexible here, but I think this then wants accompanying by an update to the command line doc, no matter that presently it doesn't really describe these peculiarities. Otoh it would end up being slightly cheaper to only look for the first instance here as well. In particular ...
Quoted 14 lines
xen/arch/x86/efi/efi-boot.h +14
-0+ { +if ( !strncmp (last,"gfx-" ,4 ) ) + { + width =simple_strtoul (last +4 , &last,10 ); +if ( *last =='x' ) + height =simple_strtoul (last +1 , &last,10 ); +if ( *last =='x' ) + depth =simple_strtoul (last +1 , &last,10 ); +/* Allow depth to be 0 or unset. */ +if ( !width || !height ) + width = height = depth =0 ; + keep_current = false; + } +else if ( !strncmp (last,"current" ,7 ) )
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 879
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ keep_current = true; + else if ( !strncmp(last, "keep", 4) ) + { +/* Ignore. */ + } + else + { +/* Fallback to defaults if unimplemented. */ + width = height = depth =0 ; + keep_current = false;
... this zapping of what was successfully parsed before would then not be needed in any event (else I would question why this is necessary).
Jan
Re: [PATCH v2 2/3] multiboot2: parse console= and vga= options when setting GOP mode
Quoted 5 lines · Jan Beulich
Quoted 1 line · Roger Pau Monne
Only set the GOP mode if vga is selected in the console option,
This particular aspect of the behavior is inconsistent with legacy boot behavior: There "vga=" isn't qualified by what "console=" has.
Hm, I find this very odd, why would we fiddle with the VGA (or the GOP here) if we don't intend to use it for output?
Quoted 18 lines
Quoted 18 lines
otherwise just fetch the information from the current mode in order to make it available to dom0.
Introduce support for passing the command line to the
efi_multiboot2()helper, and parse the console= and vga= options if present.Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
Signed-off-by Roger Pau Monné <[email protected]>[...]xen/arch/x86/efi/efi-boot.h +0
-0@@ -786,7 +786,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { }
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 794
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +6
-1-void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return the next occurrence of opt in cmd. */ +static const char __init *get_option (const char *cmd,const char *opt) +{ +const char *s = cmd, *o =NULL ; + +if ( !cmd || !opt )I can see why you need to check "cmd", but there's no need to check "opt" I would say.
Given this is executed without a page-fault handler in place I thought it was best to be safe rather than sorry, and avoid any pointer dereferences.
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/efi-boot.h +10
-1@@ -807,7 +830,60 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *opt =NULL , *last = cmdline; +/* Default console selection is "com1,vga". */ +bool vga = true; + +/* For the console option the last occurrence is the enforced one. */ +while ( (last =get_option (last,"console=" )) !=NULL ) + opt = last; + +if ( opt ) + {
Quoted 8 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 845
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h +3
-0+const char *s =strstr (opt,"vga" ); + +if ( !s || s >strpbrk (opt," " ) )Why
strpbrk()and not the simplerstrchr()? Or did you mean to also look for tabs, but then didn't include \t here (and inget_option())? (Legacy boot code also takes \r and \n as separators, btw, but I'm unconvinced of the need.)
I was originally checking for more characters here and didn't switch when removing those. I will add \t.
Quoted 3 lines
Also aiui this is UB when the function returns NULL, as relational operators (excluding equality ones) may only be applied when both addresses refer to the same object (or to the end of an involved array).
Hm, I see, thanks for spotting. So I would need to do:
s > (strpbrk(opt, " ") ?: s)
So that we don't compare against NULL.
Also the original code was wrong AFAICT, as strpbrk() returning NULL should result in vga=true (as it would imply console= is the last option on the command line).
Quoted 11 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 855
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ vga = false; + } + +if ( vga ) + { +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + + last = cmdline; +while ( (last =get_option (last,"vga=" )) !=NULL )
Quoted 7 lines
It's yet different for "vga=", I'm afraid: Early boot code (
boot/cmdline.c) finds the first instance only. Normal command line handling respects the last instance only. So while "vga=gfx-... vga=keep" will have the expected effect, "vga=keep vga=gfx-..." won't (I think). It is certainly fine to be less inflexible here, but I think this then wants accompanying by an update to the command line doc, no matter that presently it doesn't really describe these peculiarities.
But if we then describe this behavior in the documentation people could rely on it. Right now this is just an implementation detail (or a bug I would say), and that would justify fixing boot/cmdline.c to also respect the last instance only.
Quoted 28 lines
Otoh it would end up being slightly cheaper
to only look for the first instance here as well. In particular ...Quoted 14 lines
xen/arch/x86/efi/efi-boot.h +14
-0+ { +if ( !strncmp (last,"gfx-" ,4 ) ) + { + width =simple_strtoul (last +4 , &last,10 ); +if ( *last =='x' ) + height =simple_strtoul (last +1 , &last,10 ); +if ( *last =='x' ) + depth =simple_strtoul (last +1 , &last,10 ); +/* Allow depth to be 0 or unset. */ +if ( !width || !height ) + width = height = depth =0 ; + keep_current = false; + } +else if ( !strncmp (last,"current" ,7 ) )xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 879
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ keep_current = true; + else if ( !strncmp(last, "keep", 4) ) + { +/* Ignore. */ + } + else + { +/* Fallback to defaults if unimplemented. */ + width = height = depth =0 ; + keep_current = false;
Quoted 2 lines
... this zapping of what was successfully parsed before would then not be needed in any event (else I would question why this is necessary).
Hm, I don't have a strong opinion, the expected behavior I have of command line options is that the last one is the one that takes effect, but it would simplify the change if we only cared about the first one, albeit that's an odd behavior.
My preference would be to leave the code here respecting the last instance only, and attempt to fix boot/cmdline.c so it does the same.
Thanks, Roger.
Re: [PATCH v2 2/3] multiboot2: parse console= and vga= options when setting GOP mode
Quoted 9 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 1 line · Roger Pau Monne
Only set the GOP mode if vga is selected in the console option,
This particular aspect of the behavior is inconsistent with legacy boot behavior: There "vga=" isn't qualified by what "console=" has.
Hm, I find this very odd, why would we fiddle with the VGA (or the GOP here) if we don't intend to use it for output?
Because we also need to arrange for what Dom0 possibly wants to use. It has no way of setting the mode the low-level (BIOS or EFI) way.
Quoted 29 lines
Quoted 18 lines
Quoted 18 lines
otherwise just fetch the information from the current mode in order to make it available to dom0.
Introduce support for passing the command line to the
efi_multiboot2()helper, and parse the console= and vga= options if present.Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
Signed-off-by Roger Pau Monné <[email protected]>[...]xen/arch/x86/efi/efi-boot.h +0
-0@@ -786,7 +786,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { }Quoted 10 lines
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 794
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +6
-1-void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return the next occurrence of opt in cmd. */ +static const char __init *get_option (const char *cmd,const char *opt) +{ +const char *s = cmd, *o =NULL ; + +if ( !cmd || !opt )I can see why you need to check "cmd", but there's no need to check "opt" I would say.
Quoted 3 lines
Given this is executed without a page-fault handler in place I thought it was best to be safe rather than sorry, and avoid any pointer dereferences.
Hmm, I see. We don't do so elsewhere, though, I think.
Quoted 33 lines
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/efi-boot.h +10
-1@@ -807,7 +830,60 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *opt =NULL , *last = cmdline; +/* Default console selection is "com1,vga". */ +bool vga = true; + +/* For the console option the last occurrence is the enforced one. */ +while ( (last =get_option (last,"console=" )) !=NULL ) + opt = last; + +if ( opt ) + {Quoted 8 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 845
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h +3
-0+const char *s =strstr (opt,"vga" ); + +if ( !s || s >strpbrk (opt," " ) )Why
strpbrk()and not the simplerstrchr()? Or did you mean to also look for tabs, but then didn't include \t here (and inget_option())? (Legacy boot code also takes \r and \n as separators, btw, but I'm unconvinced of the need.)I was originally checking for more characters here and didn't switch when removing those. I will add \t.
Quoted 3 lines
Also aiui this is UB when the function returns NULL, as relational operators (excluding equality ones) may only be applied when both addresses refer to the same object (or to the end of an involved array).
Hm, I see, thanks for spotting. So I would need to do:
Quoted 7 lines
s > (
strpbrk(opt, " ")?: s)So that we don't compare against NULL.
Also the original code was wrong AFAICT, as
strpbrk()returning NULL should result in vga=true (as it would imply console= is the last option on the command line).
I'm afraid I'm in trouble what "original code" you're referring to here. Iirc you really only add code to the function. And boot/cmdline.c has no use of strpbrk() afaics.
Quoted 19 lines
Quoted 11 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 855
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ vga = false; + } + +if ( vga ) + { +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + + last = cmdline; +while ( (last =get_option (last,"vga=" )) !=NULL )Quoted 7 lines
It's yet different for "vga=", I'm afraid: Early boot code (
boot/cmdline.c) finds the first instance only. Normal command line handling respects the last instance only. So while "vga=gfx-... vga=keep" will have the expected effect, "vga=keep vga=gfx-..." won't (I think). It is certainly fine to be less inflexible here, but I think this then wants accompanying by an update to the command line doc, no matter that presently it doesn't really describe these peculiarities.
Quoted 4 lines
But if we then describe this behavior in the documentation people could rely on it. Right now this is just an implementation detail (or a bug I would say), and that would justify fixing
boot/cmdline.cto also respect the last instance only.
Yes, fixing the non-EFI code is certainly an option (and then describing the hopefully consistent result in the doc).
Jan
Quoted 40 lines
Quoted 28 lines
Otoh it would end up being slightly cheaper
to only look for the first instance here as well. In particular ...Quoted 14 lines
xen/arch/x86/efi/efi-boot.h +14
-0+ { +if ( !strncmp (last,"gfx-" ,4 ) ) + { + width =simple_strtoul (last +4 , &last,10 ); +if ( *last =='x' ) + height =simple_strtoul (last +1 , &last,10 ); +if ( *last =='x' ) + depth =simple_strtoul (last +1 , &last,10 ); +/* Allow depth to be 0 or unset. */ +if ( !width || !height ) + width = height = depth =0 ; + keep_current = false; + } +else if ( !strncmp (last,"current" ,7 ) )xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 879
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ keep_current = true; + else if ( !strncmp(last, "keep", 4) ) + { +/* Ignore. */ + } + else + { +/* Fallback to defaults if unimplemented. */ + width = height = depth =0 ; + keep_current = false;Quoted 2 lines
... this zapping of what was successfully parsed before would then not be needed in any event (else I would question why this is necessary).
Hm, I don't have a strong opinion, the expected behavior I have of command line options is that the last one is the one that takes effect, but it would simplify the change if we only cared about the first one, albeit that's an odd behavior.
My preference would be to leave the code here respecting the last instance only, and attempt to fix
boot/cmdline.cso it does the same.Thanks, Roger.
Re: [PATCH v2 2/3] multiboot2: parse console= and vga= options when setting GOP mode
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 3 lines · Jan Beulich
Quoted 1 line · Roger Pau Monne
Only set the GOP mode if vga is selected in the console option,
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This particular aspect of the behavior is inconsistent with legacy boot behavior: There "vga=" isn't qualified by what "console=" has.
Hm, I find this very odd, why would we fiddle with the VGA (or the GOP here) if we don't intend to use it for output?
Because we also need to arrange for what Dom0 possibly wants to use. It has no way of setting the mode the low-level (BIOS or EFI) way.
I understand this might be needed when Xen is booted as an EFI application, but otherwise it should be the bootloader that takes care of setting such mode, as (most?) OSes are normally loaded with boot services already exited.
I've removed the parsing of the console= option and unconditionally parse vga= now. We can always adjust later.
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
otherwise just fetch the information from the current mode in order to make it available to dom0.
Introduce support for passing the command line to the
efi_multiboot2()helper, and parse the console= and vga= options if present.Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
Signed-off-by Roger Pau Monné <[email protected]>[...]xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 794
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +6
-1@@ -786,7 +786,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { } -void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return the next occurrence of opt in cmd. */ +static const char __init *get_option (const char *cmd,const char *opt) +{ +const char *s = cmd, *o =NULL ; + +if ( !cmd || !opt )I can see why you need to check "cmd", but there's no need to check "opt" I would say.
Quoted 5 lines
Quoted 3 lines
Given this is executed without a page-fault handler in place I thought it was best to be safe rather than sorry, and avoid any pointer dereferences.
Hmm, I see. We don't do so elsewhere, though, I think.
If you insist I can remove it, otherwise I will just leave as-is.
Quoted 38 lines
Quoted 38 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/efi/efi-boot.h +10
-1@@ -807,7 +830,60 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *opt =NULL , *last = cmdline; +/* Default console selection is "com1,vga". */ +bool vga = true; + +/* For the console option the last occurrence is the enforced one. */ +while ( (last =get_option (last,"console=" )) !=NULL ) + opt = last; + +if ( opt ) + {Quoted 8 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 845
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h +3
-0+const char *s =strstr (opt,"vga" ); + +if ( !s || s >strpbrk (opt," " ) )Why
strpbrk()and not the simplerstrchr()? Or did you mean to also look for tabs, but then didn't include \t here (and inget_option())? (Legacy boot code also takes \r and \n as separators, btw, but I'm unconvinced of the need.)I was originally checking for more characters here and didn't switch when removing those. I will add \t.
Quoted 3 lines
Also aiui this is UB when the function returns NULL, as relational operators (excluding equality ones) may only be applied when both addresses refer to the same object (or to the end of an involved array).
Hm, I see, thanks for spotting. So I would need to do:
s > (
strpbrk(opt, " ")?: s)So that we don't compare against NULL.
Quoted 7 lines
Quoted 3 lines
Also the original code was wrong AFAICT, as
strpbrk()returning NULL should result in vga=true (as it would imply console= is the last option on the command line).I'm afraid I'm in trouble what "original code" you're referring to here. Iirc you really only add code to the function. And
boot/cmdline.chas no use ofstrpbrk()afaics.
Original code in the patch, anyway this is now gone because I no longer parse console=.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 855
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ vga = false; + } + +if ( vga ) + { +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + + last = cmdline; +while ( (last =get_option (last,"vga=" )) !=NULL )It's yet different for "vga=", I'm afraid: Early boot code (
boot/cmdline.c) finds the first instance only. Normal command line handling respects the last instance only. So while "vga=gfx-... vga=keep" will have the expected effect, "vga=keep vga=gfx-..." won't (I think). It is certainly fine to be less inflexible here, but I think this then wants accompanying by an update to the command line doc, no matter that presently it doesn't really describe these peculiarities.
Quoted 7 lines
Quoted 4 lines
But if we then describe this behavior in the documentation people could rely on it. Right now this is just an implementation detail (or a bug I would say), and that would justify fixing
boot/cmdline.cto also respect the last instance only.Yes, fixing the non-EFI code is certainly an option (and then describing the hopefully consistent result in the doc).
OK, let me take a look, I expect that should be fairly trivial.
Thanks, Roger.
Re: [PATCH v2 2/3] multiboot2: parse console= and vga= options when setting GOP mode
Quoted 12 lines · Roger Pau Monné
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 1 line · Roger Pau Monne
Only set the GOP mode if vga is selected in the console option,
This particular aspect of the behavior is inconsistent with legacy boot behavior: There "vga=" isn't qualified by what "console=" has.
Hm, I find this very odd, why would we fiddle with the VGA (or the GOP here) if we don't intend to use it for output?
Quoted 7 lines
Quoted 2 lines
Because we also need to arrange for what Dom0 possibly wants to use. It has no way of setting the mode the low-level (BIOS or EFI) way.
I understand this might be needed when Xen is booted as an EFI application, but otherwise it should be the bootloader that takes care of setting such mode, as (most?) OSes are normally loaded with boot services already exited.
The bootloader doing this is a quirk imo. In the Linux case this implies knowing the inner structure of the binary to be booted, to communicate the necessary information, plus peeking into the kernel's command line.
Furthermore I wasn't referring to the EFI-with-bootloader case, but the legacy BIOS one plus the (mentioned by you) EFI-application one. Even the MB2 protocol allows the bootloader to hand over with boot services not exited yet, iirc, so even in that case Xen would be in the position of using boot service functions (from efi_multiboot2()).
Jan
PATCH v2 3/3 multiboot2: do not set StdOut mode unconditionally
In reply to Roger Pau MonneOnly initialize StdOut if there's no GOP available. This avoids forcefully switching StdOut to the maximum supported resolution, and thus very likely changing the GOP mode without having first parsed the command line options.
---
Changes since v1:
- New in this version.
--- xen/arch/x86/efi/efi-boot.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
xen/arch/x86/efi/efi-boot.h +9 -6
@@ -820,12 +820,6 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_init (ImageHandle, SystemTable); -efi_console_set_mode (); - -if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, - &cols, &rows) ==EFI_SUCCESS ) -efi_arch_console_init (cols, rows); - gop =efi_get_gop (&gop_handle);if ( gop )
@@ -887,6 +881,15 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_arch_edid (gop_handle); } +else + { +/* If no GOP, init ConOut (StdOut) to the max supported size. */ +efi_console_set_mode (); + +if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, + &cols, &rows) ==EFI_SUCCESS ) +efi_arch_console_init (cols, rows); + }efi_arch_edd ();efi_arch_cpu ();
Signature · 1 line
2.40.0
Re: [PATCH v2 3/3] multiboot2: do not set StdOut mode unconditionally
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 892
Quoted 13 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +9
-0@@ -887,6 +881,15 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_arch_edid (gop_handle); } +else + { +/* If no GOP, init ConOut (StdOut) to the max supported size. */ +efi_console_set_mode (); + +if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, + &cols, &rows) ==EFI_SUCCESS ) +efi_arch_console_init (cols, rows); + }
Instead of making this an "else", wouldn't you better check that a valid gop_mode was found? efi_find_gop_mode() can return ~0 after all.
Furthermore, what if the active mode doesn't support text output? (I consider the spec unclear in regard to whether this is possible, but maybe I simply didn't find the right place stating it.)
Finally I think efi_arch_console_init() wants calling nevertheless.
So altogether maybe
if ( gop_mode == ~0 ||
StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
&cols, &rows) != EFI_SUCCESS )
/* If no usable GOP mode, init ConOut (StdOut) to the max supported size. */
efi_console_set_mode();
if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
&cols, &rows) == EFI_SUCCESS )
efi_arch_console_init(cols, rows);?
Jan
Re: [PATCH v2 3/3] multiboot2: do not set StdOut mode unconditionally
Quoted 17 lines · Jan Beulich
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 892
Quoted 13 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +9
-0@@ -887,6 +881,15 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_arch_edid (gop_handle); } +else + { +/* If no GOP, init ConOut (StdOut) to the max supported size. */ +efi_console_set_mode (); + +if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, + &cols, &rows) ==EFI_SUCCESS ) +efi_arch_console_init (cols, rows); + }Instead of making this an "else", wouldn't you better check that a valid
gop_modewas found?efi_find_gop_mode()can return ~0 after all.
When using vga=current gop_mode would also be ~0, in order for efi_set_gop_mode() to not change the current mode, I was trying to avoid exposing keep_current or similar extra variable to signal this.
Quoted 11 lines
Furthermore, what if the active mode doesn't support text output? (I consider the spec unclear in regard to whether this is possible, but maybe I simply didn't find the right place stating it.)
Finally I think
efi_arch_console_init()wants calling nevertheless.So altogether maybe
if ( gop_mode == ~0 || StdOut->QueryMode(StdOut, StdOut->Mode->Mode, &cols, &rows) != EFI_SUCCESS )
I think it would make more sense to call efi_console_set_mode() only if the current StdOut mode is not valid, as anything different from vga=current will already force a GOP mode change.
Thanks, Roger.
Re: [PATCH v2 3/3] multiboot2: do not set StdOut mode unconditionally
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 892
Quoted 13 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +9
-0@@ -887,6 +881,15 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_arch_edid (gop_handle); } +else + { +/* If no GOP, init ConOut (StdOut) to the max supported size. */ +efi_console_set_mode (); + +if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, + &cols, &rows) ==EFI_SUCCESS ) +efi_arch_console_init (cols, rows); + }Instead of making this an "else", wouldn't you better check that a valid
gop_modewas found?efi_find_gop_mode()can return ~0 after all.
Quoted 2 lines
When using vga=current
gop_modewould also be ~0, in order forefi_set_gop_mode()to not change the current mode,
And then we'd skip efi_console_set_mode() here as well, which I think is what we want with "vga=current"?
Quoted 11 lines
I was trying to
avoid exposingkeep_currentor similar extra variable to signal this.Quoted 8 lines
Furthermore, what if the active mode doesn't support text output? (I consider the spec unclear in regard to whether this is possible, but maybe I simply didn't find the right place stating it.)
Finally I think
efi_arch_console_init()wants calling nevertheless.So altogether maybe
Quoted 7 lines
Quoted 3 lines
if ( gop_mode == ~0 || StdOut->QueryMode(StdOut, StdOut->Mode->Mode, &cols, &rows) != EFI_SUCCESS )I think it would make more sense to call
efi_console_set_mode()only if the current StdOut mode is not valid, as anything different from vga=current will already force a GOP mode change.
Hmm, this may also make sense. I guess I'd like to see the combined result to be better able to judge.
Jan