From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Roger Pau Monne <roger.pau@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>
Subject: [PATCH 1/2] x86/head: check base address alignment
Date: Tue, 2 May 2023 11:22:23 +0200 [thread overview]
Message-ID: <20230502092224.52265-2-roger.pau@citrix.com> (raw)
In-Reply-To: <20230502092224.52265-1-roger.pau@citrix.com>
Ensure that the base address is 2M aligned, or else the page table
entries created would be corrupt as reserved bits on the PDE end up
set.
We have found a broken firmware where the loader would end up loading
Xen at a non 2M aligned region, and that caused a very difficult to
debug triple fault.
If the alignment is not as required by the page tables print an error
message and stop the boot.
The check could be performed earlier, but so far the alignment is
required by the page tables, and hence feels more natural that the
check lives near to the piece of code that requires it.
Note that when booted as an EFI application from the PE entry point
the alignment check is already performed by
efi_arch_load_addr_check(), and hence there's no need to add another
check at the point where page tables get built in
efi_arch_memory_setup().
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
xen/arch/x86/boot/head.S | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 0fb7dd3029f2..ff73c1d274c4 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -121,6 +121,7 @@ multiboot2_header:
.Lbad_ldr_nst: .asciz "ERR: EFI SystemTable is not provided by bootloader!"
.Lbad_ldr_nih: .asciz "ERR: EFI ImageHandle is not provided by bootloader!"
.Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!"
+.Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
.section .init.data, "aw", @progbits
.align 4
@@ -146,6 +147,9 @@ bad_cpu:
not_multiboot:
add $sym_offs(.Lbad_ldr_msg),%esi # Error message
jmp .Lget_vtb
+not_aligned:
+ add $sym_offs(.Lbag_alg_msg),%esi # Error message
+ jmp .Lget_vtb
.Lmb2_no_st:
/*
* Here we are on EFI platform. vga_text_buffer was zapped earlier
@@ -670,6 +674,11 @@ trampoline_setup:
cmp %edi, %eax
jb 1b
+ /* Check that the image base is aligned. */
+ lea sym_esi(_start), %eax
+ and $(1 << L2_PAGETABLE_SHIFT) - 1, %eax
+ jnz not_aligned
+
/* Map Xen into the higher mappings using 2M superpages. */
lea _PAGE_PSE + PAGE_HYPERVISOR_RWX + sym_esi(_start), %eax
mov $sym_offs(_start), %ecx /* %eax = PTE to write ^ */
--
2.40.0
next prev parent reply other threads:[~2023-05-02 9:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-02 9:22 [PATCH 0/2] x86: init improvements Roger Pau Monne
2023-05-02 9:22 ` Roger Pau Monne [this message]
2023-05-02 9:54 ` [PATCH 1/2] x86/head: check base address alignment Andrew Cooper
2023-05-02 10:28 ` Jan Beulich
2023-05-02 10:51 ` Roger Pau Monné
2023-05-02 11:05 ` Jan Beulich
2023-05-02 11:11 ` Jan Beulich
2023-05-02 13:02 ` Roger Pau Monné
2023-05-02 13:27 ` Jan Beulich
2023-05-02 10:28 ` Roger Pau Monné
2023-05-02 10:34 ` Jan Beulich
2023-05-02 10:35 ` Andrew Cooper
2023-05-02 9:22 ` [PATCH 2/2] x86/trampoline: load the GDT located in the trampoline page Roger Pau Monne
2023-05-02 9:43 ` Andrew Cooper
2023-05-02 10:34 ` Roger Pau Monné
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=20230502092224.52265-2-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=wl@xen.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.