diff mbox series

[2/2] x86/video: do not assume a video mode to be unconditionally present

Message ID 20240328153523.4155-3-roger.pau@citrix.com (mailing list archive)
State New
Headers show
Series x86/video: improve early video detection | expand

Commit Message

Roger Pau Monne March 28, 2024, 3:35 p.m. UTC
There's no reason to assume VGA text mode 3 to be unconditionally available.
With the addition of booting Xen itself in PVH mode there's a boot path that
explicitly short-circuits all the real-mode logic, including the VGA detection.

Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
not populate boot_vid_info with any default settings.  It will either be
populated by the real-mode video detection code, or left zeroed in case
real-mode code is skipped.

Note that only PVH skips the real-mode portion of the boot trampoline,
otherwise the only way to skip it is to set `no-real-mode` on the command line,
and the description for the option already notes that VGA would be disabled as
a result of skipping real-mode bootstrap.

This fixes Xen incorrectly reporting:

(XEN) Video information:
(XEN)  VGA is text mode 80x25, font 8x16

When booted as a PVH guest.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/boot/video.S | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Andrew Cooper March 28, 2024, 7:58 p.m. UTC | #1
On 28/03/2024 3:35 pm, Roger Pau Monne wrote:
> There's no reason to assume VGA text mode 3 to be unconditionally available.
> With the addition of booting Xen itself in PVH mode there's a boot path that
> explicitly short-circuits all the real-mode logic, including the VGA detection.
>
> Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
> not populate boot_vid_info with any default settings.  It will either be
> populated by the real-mode video detection code, or left zeroed in case
> real-mode code is skipped.
>
> Note that only PVH skips the real-mode portion of the boot trampoline,
> otherwise the only way to skip it is to set `no-real-mode` on the command line,
> and the description for the option already notes that VGA would be disabled as
> a result of skipping real-mode bootstrap.

IIRC, Grub defaults to using no-real-mode for xen.efi.  It's definitely
a common option to find used in practice.

>
> This fixes Xen incorrectly reporting:
>
> (XEN) Video information:
> (XEN)  VGA is text mode 80x25, font 8x16
>
> When booted as a PVH guest.
>
> Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Reivewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Jan Beulich April 2, 2024, 9:49 a.m. UTC | #2
On 28.03.2024 16:35, Roger Pau Monne wrote:
> There's no reason to assume VGA text mode 3 to be unconditionally available.
> With the addition of booting Xen itself in PVH mode there's a boot path that
> explicitly short-circuits all the real-mode logic, including the VGA detection.
> 
> Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
> not populate boot_vid_info with any default settings.  It will either be
> populated by the real-mode video detection code, or left zeroed in case
> real-mode code is skipped.
> 
> Note that only PVH skips the real-mode portion of the boot trampoline,
> otherwise the only way to skip it is to set `no-real-mode` on the command line,
> and the description for the option already notes that VGA would be disabled as
> a result of skipping real-mode bootstrap.
> 
> This fixes Xen incorrectly reporting:
> 
> (XEN) Video information:
> (XEN)  VGA is text mode 80x25, font 8x16
> 
> When booted as a PVH guest.

And what effect does this have on a bare-metal boot with no-real-mode in use?
The default on x86 hardware still is that in the absence of other information,
a VGA of some kind can be assumed to be there. Yes, there are headless
systems, but better assume VGA is there when there's not than the other way
around.

What I would have expected is for the PVH boot path to clear boot_vid_info.

Jan
Jan Beulich April 2, 2024, 9:54 a.m. UTC | #3
On 28.03.2024 20:58, Andrew Cooper wrote:
> On 28/03/2024 3:35 pm, Roger Pau Monne wrote:
>> There's no reason to assume VGA text mode 3 to be unconditionally available.
>> With the addition of booting Xen itself in PVH mode there's a boot path that
>> explicitly short-circuits all the real-mode logic, including the VGA detection.
>>
>> Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
>> not populate boot_vid_info with any default settings.  It will either be
>> populated by the real-mode video detection code, or left zeroed in case
>> real-mode code is skipped.
>>
>> Note that only PVH skips the real-mode portion of the boot trampoline,
>> otherwise the only way to skip it is to set `no-real-mode` on the command line,
>> and the description for the option already notes that VGA would be disabled as
>> a result of skipping real-mode bootstrap.
> 
> IIRC, Grub defaults to using no-real-mode for xen.efi.

That's our MB2 entry path which forces skip_realmode to 1. The xen.efi boot
path doesn't, but similarly skips entering real mode (retrieving desired
data via EFI protocols instead). Imo if to be retained, the above paragraph
would want extending some, to cover all the cases.

Jan
Andrew Cooper April 2, 2024, 10:06 a.m. UTC | #4
On 02/04/2024 10:54 am, Jan Beulich wrote:
> On 28.03.2024 20:58, Andrew Cooper wrote:
>> On 28/03/2024 3:35 pm, Roger Pau Monne wrote:
>>> There's no reason to assume VGA text mode 3 to be unconditionally available.
>>> With the addition of booting Xen itself in PVH mode there's a boot path that
>>> explicitly short-circuits all the real-mode logic, including the VGA detection.
>>>
>>> Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
>>> not populate boot_vid_info with any default settings.  It will either be
>>> populated by the real-mode video detection code, or left zeroed in case
>>> real-mode code is skipped.
>>>
>>> Note that only PVH skips the real-mode portion of the boot trampoline,
>>> otherwise the only way to skip it is to set `no-real-mode` on the command line,
>>> and the description for the option already notes that VGA would be disabled as
>>> a result of skipping real-mode bootstrap.
>> IIRC, Grub defaults to using no-real-mode for xen.efi.
> That's our MB2 entry path which forces skip_realmode to 1. The xen.efi boot
> path doesn't, but similarly skips entering real mode (retrieving desired
> data via EFI protocols instead). Imo if to be retained, the above paragraph
> would want extending some, to cover all the cases.

What I mean is that Grub's 20_linux_xen script writes a stanza which
includes "no-real-mode edd=off" for any non-PC platform, which includes EFI.

~Andrew
Roger Pau Monne April 19, 2024, 7:42 a.m. UTC | #5
On Tue, Apr 02, 2024 at 11:49:20AM +0200, Jan Beulich wrote:
> On 28.03.2024 16:35, Roger Pau Monne wrote:
> > There's no reason to assume VGA text mode 3 to be unconditionally available.
> > With the addition of booting Xen itself in PVH mode there's a boot path that
> > explicitly short-circuits all the real-mode logic, including the VGA detection.
> > 
> > Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
> > not populate boot_vid_info with any default settings.  It will either be
> > populated by the real-mode video detection code, or left zeroed in case
> > real-mode code is skipped.
> > 
> > Note that only PVH skips the real-mode portion of the boot trampoline,
> > otherwise the only way to skip it is to set `no-real-mode` on the command line,
> > and the description for the option already notes that VGA would be disabled as
> > a result of skipping real-mode bootstrap.
> > 
> > This fixes Xen incorrectly reporting:
> > 
> > (XEN) Video information:
> > (XEN)  VGA is text mode 80x25, font 8x16
> > 
> > When booted as a PVH guest.
> 
> And what effect does this have on a bare-metal boot with no-real-mode in use?
> The default on x86 hardware still is that in the absence of other information,
> a VGA of some kind can be assumed to be there. Yes, there are headless
> systems, but better assume VGA is there when there's not than the other way
> around.

But that contradicts the text of the 'no-real-mode' option, which
explicitly notes:

"Do not execute real-mode bootstrap code when booting Xen. This option
should not be used except for debugging. It will effectively disable
the vga option, which relies on real mode to set the video mode."

> What I would have expected is for the PVH boot path to clear boot_vid_info.

Well, my intention was to fix both PVH and also make the
implementation of the 'no-real-mode' option consistent with the
documentation.

Thanks, Roger.
Jan Beulich April 19, 2024, 9:26 a.m. UTC | #6
On 19.04.2024 09:42, Roger Pau Monné wrote:
> On Tue, Apr 02, 2024 at 11:49:20AM +0200, Jan Beulich wrote:
>> On 28.03.2024 16:35, Roger Pau Monne wrote:
>>> There's no reason to assume VGA text mode 3 to be unconditionally available.
>>> With the addition of booting Xen itself in PVH mode there's a boot path that
>>> explicitly short-circuits all the real-mode logic, including the VGA detection.
>>>
>>> Leave the default user selected mode as text mode 3 in boot_vid_mode, but do
>>> not populate boot_vid_info with any default settings.  It will either be
>>> populated by the real-mode video detection code, or left zeroed in case
>>> real-mode code is skipped.
>>>
>>> Note that only PVH skips the real-mode portion of the boot trampoline,
>>> otherwise the only way to skip it is to set `no-real-mode` on the command line,
>>> and the description for the option already notes that VGA would be disabled as
>>> a result of skipping real-mode bootstrap.
>>>
>>> This fixes Xen incorrectly reporting:
>>>
>>> (XEN) Video information:
>>> (XEN)  VGA is text mode 80x25, font 8x16
>>>
>>> When booted as a PVH guest.
>>
>> And what effect does this have on a bare-metal boot with no-real-mode in use?
>> The default on x86 hardware still is that in the absence of other information,
>> a VGA of some kind can be assumed to be there. Yes, there are headless
>> systems, but better assume VGA is there when there's not than the other way
>> around.
> 
> But that contradicts the text of the 'no-real-mode' option, which
> explicitly notes:
> 
> "Do not execute real-mode bootstrap code when booting Xen. This option
> should not be used except for debugging. It will effectively disable
> the vga option, which relies on real mode to set the video mode."

Well. Even without setting a video mode, _some_ mode is set (by firmware) as
long as there is a VGA. In the absence of a "vga=" option iirc we'd retrieve
that setting, unless we're not allowed to by "no-real-mode". In which case,
as indicated, we may still be better off guessing a basic mode than kind of
suggesting the absence of any VGA.

Besides, when booting from EFI vga= is respected despite not going through
real mode. So the quoted text isn't quite right anyway.

Jan

>> What I would have expected is for the PVH boot path to clear boot_vid_info.
> 
> Well, my intention was to fix both PVH and also make the
> implementation of the 'no-real-mode' option consistent with the
> documentation.
> 
> Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/arch/x86/boot/video.S b/xen/arch/x86/boot/video.S
index a4b25a3b34d1..a51de04a024e 100644
--- a/xen/arch/x86/boot/video.S
+++ b/xen/arch/x86/boot/video.S
@@ -994,12 +994,7 @@  name_bann:      .asciz  "Video adapter: "
 force_size:     .word   0       # Use this size instead of the one in BIOS vars
 
 GLOBAL(boot_vid_info)
-        .byte   0, 0    /* orig_x, orig_y */
-        .byte   3       /* text mode 3    */
-        .byte   80, 25  /* 80x25          */
-        .byte   1       /* isVGA          */
-        .word   16      /* 8x16 font      */
-        .space  BVI_size - BVI_capabilities
+        .space  BVI_size
 GLOBAL(boot_edid_info)
         .fill   128,1,0x13
 GLOBAL(boot_edid_caps)