From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>
Cc: xen-devel@lists.xenproject.org,
Anthony PERARD <anthony.perard@vates.tech>,
Michal Orzel <michal.orzel@amd.com>,
Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH 6/7] x86/vga: fix mapping of the VGA text buffer
Date: Fri, 14 Mar 2025 11:39:15 +0100 [thread overview]
Message-ID: <Z9QHU-KozrXR95sL@macbook.local> (raw)
In-Reply-To: <8ce7caae-8bf6-4ba2-8705-399129a411b6@citrix.com>
(resending because I seem to have inadvertently corrupted the Cc field)
On Thu, Mar 13, 2025 at 07:39:58PM +0000, Andrew Cooper wrote:
> On 13/03/2025 3:30 pm, Roger Pau Monne wrote:
> > The call to ioremap_wc() in video_init() will always fail, because
> > video_init() is called ahead of vm_init_type(), and so the underlying
> > __vmap() call will fail to allocate the linear address space.
> >
> > Fix by reverting to the previous behavior and using the directmap entries
> > in the low 1MB. Note the VGA text buffer directmap entries are also
> > adjusted to map the VGA text buffer as WC instead of UC-.
> >
> > Fixes: 81d195c6c0e2 ('x86: introduce ioremap_wc()')
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > ---
> > xen/arch/x86/boot/x86_64.S | 10 +++++++---
> > xen/arch/x86/include/asm/config.h | 5 +++++
> > xen/drivers/video/vga.c | 11 ++++++++---
> > 3 files changed, 20 insertions(+), 6 deletions(-)
> >
> > diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S
> > index 26b9d1c2df9a..07f4bdf46e31 100644
> > --- a/xen/arch/x86/boot/x86_64.S
> > +++ b/xen/arch/x86/boot/x86_64.S
> > @@ -84,15 +84,19 @@ ENTRY(__high_start)
> > /*
> > * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings
> > * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
> > - * of physical memory. In any case the VGA hole should be mapped with type UC.
> > + * of physical memory. VGA hole should be mapped with type UC, with the
> > + * exception of the text buffer that uses WC.
> > * Uses 1x 4k page.
> > */
> > l1_directmap:
> > pfn = 0
> > .rept L1_PAGETABLE_ENTRIES
> > - /* VGA hole (0xa0000-0xc0000) should be mapped UC-. */
> > - .if pfn >= 0xa0 && pfn < 0xc0
> > + /* VGA hole (0xa0000-0xb8000) should be mapped UC-. */
> > + .if pfn >= 0xa0 && pfn < 0xb8
> > .quad (pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR_UCMINUS | _PAGE_GLOBAL | MAP_SMALL_PAGES
> > + /* VGA text buffer (0xb80000-0xc0000) should be mapped WC. */
> > + .elseif pfn >= 0xb8 && pfn < 0xc0
> > + .quad (pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR_WC | _PAGE_GLOBAL | MAP_SMALL_PAGES
> > .else
> > .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR_RWX | MAP_SMALL_PAGES
> > .endif
>
> We have to be careful doing this.
>
> It probably is safe to use WC in the pagetables. We don't start using
> the pagetables until after we're sure we're on a 64bit CPU, which means
> WC is available.
>
> However, doing so now means that we need explicit SFENCE's when using
> this, even in places like early_error. The IN/OUT instructions do flush
> WC buffers, but the UART is written to before the screen, so there's a
> chance that you'll lose the final character of the message on the screen.
I don't think early_error will ever use this mapping.
`vga_text_buffer` contains the address 0xb8000, and AFAICT it's
exclusively used with paging disabled (as the multiboot2 efi path
explicitly sets vga_text_buffer = 0). The WC mapping created above is
on the directmap, so va > DIRECTMAP_VIRT_START.
vga_text_puts() might need such SFENCE, but arguably that should be a
different patch IMO. Might be best to ask Jan whether this is on
purpose?
My hypothesis is that the SFENCE might only be needed in
video_endboot() and before reboot if Xen crashed ahead of
relinquishing the VGA console.
Thanks, Roger.
next prev parent reply other threads:[~2025-03-14 10:39 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 15:30 [PATCH 0/7] x86/ubsan: fix ubsan on clang + code fixes Roger Pau Monne
2025-03-13 15:30 ` [PATCH 1/7] xen/ubsan: provide helper for clang's -fsanitize=function Roger Pau Monne
2025-03-13 17:18 ` Andrew Cooper
2025-03-13 15:30 ` [PATCH 2/7] x86/wait: prevent duplicated assembly labels Roger Pau Monne
2025-03-13 19:07 ` Andrew Cooper
2025-03-14 8:24 ` Jan Beulich
2025-03-14 8:30 ` Roger Pau Monné
2025-03-14 8:44 ` Jan Beulich
2025-03-14 9:05 ` Andrew Cooper
2025-03-14 9:13 ` Jan Beulich
2025-03-14 10:12 ` Roger Pau Monné
2025-03-14 11:17 ` Jan Beulich
2025-03-14 11:20 ` Andrew Cooper
2025-03-14 9:06 ` Roger Pau Monné
2025-03-14 9:15 ` Jan Beulich
2025-03-13 15:30 ` [PATCH 3/7] x86/dom0: placate GCC 12 compile-time errors with UBSAN and PVH_GUEST Roger Pau Monne
2025-03-13 19:35 ` Andrew Cooper
2025-03-14 8:10 ` Jan Beulich
2025-03-14 8:27 ` Roger Pau Monné
2025-03-14 8:33 ` Jan Beulich
2025-03-14 9:10 ` Roger Pau Monné
2025-03-13 15:30 ` [PATCH 4/7] xen/ubsan: expand pointer overflow message printing Roger Pau Monne
2025-03-13 17:22 ` Andrew Cooper
2025-03-13 15:30 ` [PATCH 5/7] x86/ioremap: prevent additions against the NULL pointer Roger Pau Monne
2025-03-13 17:21 ` Andrew Cooper
2025-03-14 8:43 ` Roger Pau Monné
2025-03-14 11:25 ` Andrew Cooper
2025-03-13 15:30 ` [PATCH 6/7] x86/vga: fix mapping of the VGA text buffer Roger Pau Monne
2025-03-13 19:39 ` Andrew Cooper
2025-03-14 10:39 ` Roger Pau Monné [this message]
2025-03-14 11:23 ` Jan Beulich
2025-03-14 11:58 ` Roger Pau Monné
2025-03-13 15:30 ` [PATCH 7/7] kconfig/randconfig: enable UBSAN for randconfig Roger Pau Monne
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=Z9QHU-KozrXR95sL@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.