From: David Woodhouse <dwmw(a)amazon.co.uk>
When running under Xen, hvmloader places a table at 0x1000 with the e820
information and BIOS tables. If this isn't present, SeaBIOS will
currently panic.
We now have support for running Xen guests natively in QEMU/KVM, which
boots SeaBIOS directly instead of via hvmloader, and does not provide
the same structure.
As it happens, this doesn't matter on first boot. because although we
set PlatformRunningOn to PF_QEMU|PF_XEN, reading it back again still
gives zero. Presumably because in true Xen, this is all already RAM. But
in QEMU with a faithfully-emulated PAM config in the host bridge, it's
still in ROM mode at this point so we don't see what we've just written.
On reboot, however, the region *is* set to RAM mode and we do see the
updated value of PlatformRunningOn, do manage to remember that we've
detected Xen in CPUID, and hit the panic.
It's not trivial to detect QEMU vs. real Xen at the time xen_preinit()
runs, because it's so early. We can't even make a XENVER_extraversion
hypercall to look for hints, because we haven't set up the hypercall
page (and don't have an allocator to give us a page in which to do so).
So just make Xen detection contingent on the info structure being
present. If it wasn't, we were going to panic anyway. That leaves us
taking the standard QEMU init path for Xen guests in native QEMU,
which is just fine.
Untested on actual Xen but ObviouslyCorrect™.
Signed-off-by: David Woodhouse <dwmw(a)amazon.co.uk>
---
src/fw/xen.c | 45 ++++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/src/fw/xen.c b/src/fw/xen.c
index a215b9e..00e4b0c 100644
--- a/src/fw/xen.c
+++ b/src/fw/xen.c
@@ -40,16 +40,25 @@ struct xen_seabios_info {
u32 e820_nr;
} PACKED;
-static void validate_info(struct xen_seabios_info *t)
+static struct xen_seabios_info *validate_info(void)
{
- if ( memcmp(t->signature, "XenHVMSeaBIOS", 14) )
- panic("Bad Xen info signature\n");
+ struct xen_seabios_info *t = (void *)INFO_PHYSICAL_ADDRESS;
- if ( t->length < sizeof(struct xen_seabios_info) )
- panic("Bad Xen info length\n");
+ if ( memcmp(t->signature, "XenHVMSeaBIOS", 14) ) {
+ dprintf(1, "Bad Xen info signature\n");
+ return NULL;
+ }
+
+ if ( t->length < sizeof(struct xen_seabios_info) ) {
+ dprintf(1, "Bad Xen info length\n");
+ return NULL;
+ }
- if (checksum(t, t->length) != 0)
- panic("Bad Xen info checksum\n");
+ if (checksum(t, t->length) != 0) {
+ dprintf(1, "Bad Xen info checksum\n");
+ return NULL;
+ }
+ return t;
}
void xen_preinit(void)
@@ -86,7 +95,10 @@ void xen_preinit(void)
dprintf(1, "No Xen hypervisor found.\n");
return;
}
- PlatformRunningOn = PF_QEMU|PF_XEN;
+ if (validate_info())
+ PlatformRunningOn = PF_QEMU|PF_XEN;
+ else
+ dprintf(1, "Not enabling Xen support due to lack of Xen info\n");
}
static int hypercall_xen_version( int cmd, void *arg)
@@ -122,10 +134,14 @@ void xen_hypercall_setup(void)
void xen_biostable_setup(void)
{
- struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
- void **tables = (void*)info->tables;
+ struct xen_seabios_info *info = validate_info();
+ void **tables;
int i;
+ if (!info)
+ panic("Xen info corrupted\n");
+
+ tables = (void*)info->tables;
dprintf(1, "xen: copy BIOS tables...\n");
for (i=0; i<info->tables_nr; i++)
copy_table(tables[i]);
@@ -136,12 +152,15 @@ void xen_biostable_setup(void)
void xen_ramsize_preinit(void)
{
int i;
- struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
- struct e820entry *e820 = (struct e820entry *)info->e820;
- validate_info(info);
+ struct xen_seabios_info *info = validate_info();
+ struct e820entry *e820;
+
+ if (!info)
+ panic("Xen info corrupted\n");
dprintf(1, "xen: copy e820...\n");
+ e820 = (struct e820entry *)info->e820;
for (i = 0; i < info->e820_nr; i++) {
struct e820entry *e = &e820[i];
e820_add(e->start, e->size, e->type);
--
2.34.1