Commit c40e9cef authored by Henrik Riomar's avatar Henrik Riomar Committed by Leonardo Arena

main/grub: add xen pvh support

* Backport xen_pvh patches from grub master branch
* Adds grub-i386-xen_pvh.bin to the grub-xenhost package
parent 311f3a86
This diff is collapsed.
From b800b2b23ac56a5d0fb39b1acfcd9e3d4e0a93c0 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:30 +0100
Subject: [PATCH 02/20] loader/linux: Support passing RSDP address via boot
params
Xen PVH guests will have the RSDP at an arbitrary address. Support that
by passing the RSDP address via the boot parameters to Linux.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit d170be42f12b0b2ab91d8d943d7b0bf563c906dd)
---
grub-core/loader/i386/linux.c | 4 ++++
include/grub/i386/linux.h | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 083f9417c..7d6d5d499 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -551,6 +551,10 @@ grub_linux_boot (void)
}
}
+#ifdef GRUB_KERNEL_USE_RSDP_ADDR
+ linux_params.acpi_rsdp_addr = grub_le_to_cpu64 (grub_rsdp_addr);
+#endif
+
mmap_size = find_mmap_size ();
/* Make sure that each size is aligned to a page boundary. */
cl_offset = ALIGN_UP (mmap_size + sizeof (linux_params), 4096);
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
index da0ca3b83..ada068fa5 100644
--- a/include/grub/i386/linux.h
+++ b/include/grub/i386/linux.h
@@ -206,8 +206,9 @@ struct linux_kernel_params
grub_uint32_t ist_command; /* 64 */
grub_uint32_t ist_event; /* 68 */
grub_uint32_t ist_perf_level; /* 6c */
+ grub_uint64_t acpi_rsdp_addr; /* 70 */
- grub_uint8_t padding5[0x80 - 0x70];
+ grub_uint8_t padding5[0x80 - 0x78];
grub_uint8_t hd0_drive_info[0x10]; /* 80 */
grub_uint8_t hd1_drive_info[0x10]; /* 90 */
--
2.21.0
From 7c45df9ded4ca3201cf468de899bad28e4ac8c55 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:31 +0100
Subject: [PATCH 03/20] xen: Carve out grant tab initialization into dedicated
function
Initialize the grant tab in a dedicated function. This will enable
using it for PVH guests, too.
Call the new function from grub_machine_init() as this will later
be common between Xen PV and Xen PVH mode.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit c84927272cea59084ad5b0705c55547e8c85b28d)
---
grub-core/kern/xen/init.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
index 0559c033c..29f5bc23d 100644
--- a/grub-core/kern/xen/init.c
+++ b/grub-core/kern/xen/init.c
@@ -318,6 +318,25 @@ grub_xenstore_dir (const char *dir,
unsigned long gntframe = 0;
+static void
+grub_xen_setup_gnttab (void)
+{
+ struct gnttab_set_version gnttab_setver;
+ struct gnttab_setup_table gnttab_setup;
+
+ grub_memset (&gnttab_setver, 0, sizeof (gnttab_setver));
+
+ gnttab_setver.version = 1;
+ grub_xen_grant_table_op (GNTTABOP_set_version, &gnttab_setver, 1);
+
+ grub_memset (&gnttab_setup, 0, sizeof (gnttab_setup));
+ gnttab_setup.dom = DOMID_SELF;
+ gnttab_setup.nr_frames = 1;
+ gnttab_setup.frame_list.p = &gntframe;
+
+ grub_xen_grant_table_op (GNTTABOP_setup_table, &gnttab_setup, 1);
+}
+
#define MAX_N_UNUSABLE_PAGES 4
static int
@@ -357,26 +376,12 @@ map_all_pages (void)
(grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list;
grub_uint64_t *pg = (grub_uint64_t *) window;
grub_uint64_t oldpgstart, oldpgend;
- struct gnttab_setup_table gnttab_setup;
- struct gnttab_set_version gnttab_setver;
grub_size_t n_unusable_pages = 0;
struct mmu_update m2p_updates[2 * MAX_N_UNUSABLE_PAGES];
if (total_pages > MAX_TOTAL_PAGES - 4)
total_pages = MAX_TOTAL_PAGES - 4;
- grub_memset (&gnttab_setver, 0, sizeof (gnttab_setver));
-
- gnttab_setver.version = 1;
- grub_xen_grant_table_op (GNTTABOP_set_version, &gnttab_setver, 1);
-
- grub_memset (&gnttab_setup, 0, sizeof (gnttab_setup));
- gnttab_setup.dom = DOMID_SELF;
- gnttab_setup.nr_frames = 1;
- gnttab_setup.frame_list.p = &gntframe;
-
- grub_xen_grant_table_op (GNTTABOP_setup_table, &gnttab_setup, 1);
-
for (j = 0; j < total_pages - n_unusable_pages; j++)
while (!grub_xen_is_page_usable (mfn_list[j]))
{
@@ -537,6 +542,8 @@ grub_machine_init (void)
+ GRUB_KERNEL_MACHINE_MOD_GAP,
GRUB_KERNEL_MACHINE_MOD_ALIGN);
+ grub_xen_setup_gnttab ();
+
map_all_pages ();
grub_console_init ();
--
2.21.0
From 49a68b2a338cd55490c776d15b0b399303a08df5 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:32 +0100
Subject: [PATCH 04/20] xen: Prepare common code for Xen PVH support
Some common code needs to be special cased for Xen PVH mode. This hits
mostly Xen PV mode specific areas.
Split include/grub/i386/pc/int_types.h off from
include/grub/i386/pc/int.h to support including this file later from
xen_pvh code without the grub_bios_interrupt definition.
Move definition of struct grub_e820_mmap_entry from
grub-core/mmap/i386/pc/mmap.c to include/grub/i386/memory.h in order
to make it usable from xen_pvh code.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit fc9d47ead56365c3335bb42cf651008c9ac1f494)
---
grub-core/kern/i386/tsc.c | 2 +-
grub-core/mmap/i386/pc/mmap.c | 8 -----
include/grub/i386/memory.h | 7 ++++
include/grub/i386/pc/int.h | 36 +------------------
include/grub/i386/pc/int_types.h | 59 +++++++++++++++++++++++++++++++
include/grub/i386/tsc.h | 2 +-
include/grub/i386/xen/hypercall.h | 5 ++-
include/grub/kernel.h | 4 ++-
8 files changed, 76 insertions(+), 47 deletions(-)
create mode 100644 include/grub/i386/pc/int_types.h
diff --git a/grub-core/kern/i386/tsc.c b/grub-core/kern/i386/tsc.c
index 2e85289d8..b50831bfc 100644
--- a/grub-core/kern/i386/tsc.c
+++ b/grub-core/kern/i386/tsc.c
@@ -65,7 +65,7 @@ grub_tsc_init (void)
tsc_boot_time = grub_get_tsc ();
-#ifdef GRUB_MACHINE_XEN
+#if defined (GRUB_MACHINE_XEN) || defined (GRUB_MACHINE_XEN_PVH)
(void) (grub_tsc_calibrate_from_xen () || calibrate_tsc_hardcode());
#elif defined (GRUB_MACHINE_EFI)
(void) (grub_tsc_calibrate_from_pit () || grub_tsc_calibrate_from_pmtimer () || grub_tsc_calibrate_from_efi() || calibrate_tsc_hardcode());
diff --git a/grub-core/mmap/i386/pc/mmap.c b/grub-core/mmap/i386/pc/mmap.c
index 609994516..6ab4f6730 100644
--- a/grub-core/mmap/i386/pc/mmap.c
+++ b/grub-core/mmap/i386/pc/mmap.c
@@ -42,14 +42,6 @@ extern grub_uint16_t grub_machine_mmaphook_kblow;
extern grub_uint16_t grub_machine_mmaphook_kbin16mb;
extern grub_uint16_t grub_machine_mmaphook_64kbin4gb;
-struct grub_e820_mmap_entry
-{
- grub_uint64_t addr;
- grub_uint64_t len;
- grub_uint32_t type;
-} GRUB_PACKED;
-
-
/* Helper for preboot. */
static int fill_hook (grub_uint64_t addr, grub_uint64_t size,
grub_memory_type_t type, void *data)
diff --git a/include/grub/i386/memory.h b/include/grub/i386/memory.h
index 8bb6e1cbb..5cb607fb4 100644
--- a/include/grub/i386/memory.h
+++ b/include/grub/i386/memory.h
@@ -44,6 +44,13 @@
#include <grub/types.h>
+struct grub_e820_mmap_entry
+{
+ grub_uint64_t addr;
+ grub_uint64_t len;
+ grub_uint32_t type;
+} GRUB_PACKED;
+
grub_uint64_t grub_mmap_get_upper (void);
grub_uint64_t grub_mmap_get_lower (void);
grub_uint64_t grub_mmap_get_post64 (void);
diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h
index 16a53e4fe..a60104001 100644
--- a/include/grub/i386/pc/int.h
+++ b/include/grub/i386/pc/int.h
@@ -20,45 +20,11 @@
#define GRUB_INTERRUPT_MACHINE_HEADER 1
#include <grub/symbol.h>
-#include <grub/types.h>
-
-struct grub_bios_int_registers
-{
- grub_uint32_t eax;
- grub_uint16_t es;
- grub_uint16_t ds;
- grub_uint16_t flags;
- grub_uint16_t dummy;
- grub_uint32_t ebx;
- grub_uint32_t ecx;
- grub_uint32_t edi;
- grub_uint32_t esi;
- grub_uint32_t edx;
-};
-
-#define GRUB_CPU_INT_FLAGS_CARRY 0x1
-#define GRUB_CPU_INT_FLAGS_PARITY 0x4
-#define GRUB_CPU_INT_FLAGS_ADJUST 0x10
-#define GRUB_CPU_INT_FLAGS_ZERO 0x40
-#define GRUB_CPU_INT_FLAGS_SIGN 0x80
-#define GRUB_CPU_INT_FLAGS_TRAP 0x100
-#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200
-#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400
-#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800
-#ifdef GRUB_MACHINE_PCBIOS
-#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT
-#else
-#define GRUB_CPU_INT_FLAGS_DEFAULT 0
-#endif
+#include <grub/i386/pc/int_types.h>
void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno,
struct grub_bios_int_registers *regs)
__attribute__ ((regparm(3)));
-struct grub_i386_idt
-{
- grub_uint16_t limit;
- grub_uint32_t base;
-} GRUB_PACKED;
#ifdef GRUB_MACHINE_PCBIOS
extern struct grub_i386_idt *EXPORT_VAR(grub_realidt);
diff --git a/include/grub/i386/pc/int_types.h b/include/grub/i386/pc/int_types.h
new file mode 100644
index 000000000..2c5a69b63
--- /dev/null
+++ b/include/grub/i386/pc/int_types.h
@@ -0,0 +1,59 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_INTERRUPT_TYPES_MACHINE_HEADER
+#define GRUB_INTERRUPT_TYPES_MACHINE_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_CPU_INT_FLAGS_CARRY 0x1
+#define GRUB_CPU_INT_FLAGS_PARITY 0x4
+#define GRUB_CPU_INT_FLAGS_ADJUST 0x10
+#define GRUB_CPU_INT_FLAGS_ZERO 0x40
+#define GRUB_CPU_INT_FLAGS_SIGN 0x80
+#define GRUB_CPU_INT_FLAGS_TRAP 0x100
+#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200
+#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400
+#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800
+#ifdef GRUB_MACHINE_PCBIOS
+#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT
+#else
+#define GRUB_CPU_INT_FLAGS_DEFAULT 0
+#endif
+
+struct grub_bios_int_registers
+{
+ grub_uint32_t eax;
+ grub_uint16_t es;
+ grub_uint16_t ds;
+ grub_uint16_t flags;
+ grub_uint16_t dummy;
+ grub_uint32_t ebx;
+ grub_uint32_t ecx;
+ grub_uint32_t edi;
+ grub_uint32_t esi;
+ grub_uint32_t edx;
+};
+
+struct grub_i386_idt
+{
+ grub_uint16_t limit;
+ grub_uint32_t base;
+} GRUB_PACKED;
+
+#endif
diff --git a/include/grub/i386/tsc.h b/include/grub/i386/tsc.h
index a0aa2c573..324174ded 100644
--- a/include/grub/i386/tsc.h
+++ b/include/grub/i386/tsc.h
@@ -54,7 +54,7 @@ grub_get_tsc (void)
static __inline int
grub_cpu_is_tsc_supported (void)
{
-#ifndef GRUB_MACHINE_XEN
+#if !defined(GRUB_MACHINE_XEN) && !defined(GRUB_MACHINE_XEN_PVH)
grub_uint32_t a,b,c,d;
if (! grub_cpu_is_cpuid_supported ())
return 0;
diff --git a/include/grub/i386/xen/hypercall.h b/include/grub/i386/xen/hypercall.h
index 198ee94af..4e4c12a49 100644
--- a/include/grub/i386/xen/hypercall.h
+++ b/include/grub/i386/xen/hypercall.h
@@ -26,7 +26,10 @@ EXPORT_FUNC (grub_xen_hypercall) (grub_uint32_t callno, grub_uint32_t a0,
grub_uint32_t a1, grub_uint32_t a2,
grub_uint32_t a3, grub_uint32_t a4,
grub_uint32_t a5)
-__attribute__ ((regparm (3), cdecl));
+#ifdef GRUB_MACHINE_XEN
+ __attribute__ ((regparm (3), cdecl))
+#endif
+ ;
static inline int
grub_xen_sched_op (int cmd, void *arg)
diff --git a/include/grub/kernel.h b/include/grub/kernel.h
index 20ddf2da2..c17fc6e60 100644
--- a/include/grub/kernel.h
+++ b/include/grub/kernel.h
@@ -78,7 +78,9 @@ struct grub_module_info64
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) \
|| defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) \
|| defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_ARC) \
- || (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN)
+ || (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) \
+ || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN) \
+ || defined(GRUB_MACHINE_XEN_PVH)
/* FIXME: stack is between 2 heap regions. Move it. */
#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 1
#endif
--
2.21.0
From 02d764a4469d71a5bc78c1358b0bd62987e2dc8e Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:33 +0100
Subject: [PATCH 05/20] xen: Add some dummy headers for PVH mode
With Xen PVH mode adding a new machine type the machine related headers
need to be present for the build to succeed. Most of the headers just
need to include the related common i386 headers. Add those to the tree.
Note that xen_pvh/int.h needs to include pc/int_types.h instead of
pc/int.h in order to avoid the definition of grub_bios_interrupt().
xen_pvh/memory.h needs to include coreboot/memory.h (like some other
<machine>/memory.h do as well) as this contains just the needed stubs.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit 408de833bbd1ccad39ad439eaf3cddd528b039b5)
---
include/grub/i386/xen_pvh/boot.h | 1 +
include/grub/i386/xen_pvh/console.h | 1 +
include/grub/i386/xen_pvh/int.h | 1 +
include/grub/i386/xen_pvh/memory.h | 1 +
include/grub/i386/xen_pvh/time.h | 1 +
5 files changed, 5 insertions(+)
create mode 100644 include/grub/i386/xen_pvh/boot.h
create mode 100644 include/grub/i386/xen_pvh/console.h
create mode 100644 include/grub/i386/xen_pvh/int.h
create mode 100644 include/grub/i386/xen_pvh/memory.h
create mode 100644 include/grub/i386/xen_pvh/time.h
diff --git a/include/grub/i386/xen_pvh/boot.h b/include/grub/i386/xen_pvh/boot.h
new file mode 100644
index 000000000..6cd23aa83
--- /dev/null
+++ b/include/grub/i386/xen_pvh/boot.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/boot.h>
diff --git a/include/grub/i386/xen_pvh/console.h b/include/grub/i386/xen_pvh/console.h
new file mode 100644
index 000000000..305a46d8e
--- /dev/null
+++ b/include/grub/i386/xen_pvh/console.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/console.h>
diff --git a/include/grub/i386/xen_pvh/int.h b/include/grub/i386/xen_pvh/int.h
new file mode 100644
index 000000000..0f1f9ee62
--- /dev/null
+++ b/include/grub/i386/xen_pvh/int.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/int_types.h>
diff --git a/include/grub/i386/xen_pvh/memory.h b/include/grub/i386/xen_pvh/memory.h
new file mode 100644
index 000000000..8dd6f7c8c
--- /dev/null
+++ b/include/grub/i386/xen_pvh/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/memory.h>
diff --git a/include/grub/i386/xen_pvh/time.h b/include/grub/i386/xen_pvh/time.h
new file mode 100644
index 000000000..2298ee8f4
--- /dev/null
+++ b/include/grub/i386/xen_pvh/time.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/time.h>
--
2.21.0
From 56eb459603e458316d93cf5bdf16e4539dbb6a9d Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:34 +0100
Subject: [PATCH 06/20] xen: Rearrange xen/init.c to prepare it for Xen PVH
mode
Rearrange grub-core/kern/xen/init.c to prepare adding PVH mode support
to it. This includes putting some code under #ifdef GRUB_MACHINE_XEN
as it will not be used when running as PVH.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit bec9edf53f4d0b629a52a7d1145f38f88df8dd1d)
---
grub-core/kern/xen/init.c | 60 ++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 26 deletions(-)
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
index 29f5bc23d..10007b411 100644
--- a/grub-core/kern/xen/init.c
+++ b/grub-core/kern/xen/init.c
@@ -41,9 +41,11 @@ grub_size_t grub_xen_n_allocated_shared_pages;
static grub_xen_mfn_t
grub_xen_ptr2mfn (void *ptr)
{
+#ifdef GRUB_MACHINE_XEN
grub_xen_mfn_t *mfn_list =
(grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list;
return mfn_list[(grub_addr_t) ptr >> GRUB_XEN_LOG_PAGE_SIZE];
+#endif
}
void *
@@ -104,18 +106,6 @@ grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
{
}
-static grub_uint8_t window[GRUB_XEN_PAGE_SIZE]
- __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE)));
-
-#ifdef __x86_64__
-#define NUMBER_OF_LEVELS 4
-#else
-#define NUMBER_OF_LEVELS 3
-#endif
-
-#define LOG_POINTERS_PER_PAGE 9
-#define POINTERS_PER_PAGE (1 << LOG_POINTERS_PER_PAGE)
-
void
grub_xen_store_send (const void *buf_, grub_size_t len)
{
@@ -337,6 +327,19 @@ grub_xen_setup_gnttab (void)
grub_xen_grant_table_op (GNTTABOP_setup_table, &gnttab_setup, 1);
}
+#ifdef GRUB_MACHINE_XEN
+static grub_uint8_t window[GRUB_XEN_PAGE_SIZE]
+ __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE)));
+
+#ifdef __x86_64__
+#define NUMBER_OF_LEVELS 4
+#else
+#define NUMBER_OF_LEVELS 3
+#endif
+
+#define LOG_POINTERS_PER_PAGE 9
+#define POINTERS_PER_PAGE (1 << LOG_POINTERS_PER_PAGE)
+
#define MAX_N_UNUSABLE_PAGES 4
static int
@@ -529,13 +532,30 @@ map_all_pages (void)
grub_mm_init_region ((void *) heap_start, heap_end - heap_start);
}
+grub_err_t
+grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
+{
+ grub_uint64_t total_pages = grub_xen_start_page_addr->nr_pages;
+ grub_uint64_t usable_pages = grub_xen_start_page_addr->pt_base >> 12;
+ if (hook (0, page2offset (usable_pages), GRUB_MEMORY_AVAILABLE, hook_data))
+ return GRUB_ERR_NONE;
+
+ hook (page2offset (usable_pages), page2offset (total_pages - usable_pages),
+ GRUB_MEMORY_RESERVED, hook_data);
+
+ return GRUB_ERR_NONE;
+}
+#endif
+
extern char _end[];
void
grub_machine_init (void)
{
+#ifdef GRUB_MACHINE_XEN
#ifdef __i386__
grub_xen_vm_assist (VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3);
+#endif
#endif
grub_modbase = ALIGN_UP ((grub_addr_t) _end
@@ -544,7 +564,9 @@ grub_machine_init (void)
grub_xen_setup_gnttab ();
+#ifdef GRUB_MACHINE_XEN
map_all_pages ();
+#endif
grub_console_init ();
@@ -571,17 +593,3 @@ grub_machine_fini (int flags __attribute__ ((unused)))
grub_xendisk_fini ();
grub_boot_fini ();
}
-
-grub_err_t
-grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
-{
- grub_uint64_t total_pages = grub_xen_start_page_addr->nr_pages;
- grub_uint64_t usable_pages = grub_xen_start_page_addr->pt_base >> 12;
- if (hook (0, page2offset (usable_pages), GRUB_MEMORY_AVAILABLE, hook_data))
- return GRUB_ERR_NONE;
-
- hook (page2offset (usable_pages), page2offset (total_pages - usable_pages),
- GRUB_MEMORY_RESERVED, hook_data);
-
- return GRUB_ERR_NONE;
-}
--
2.21.0
From 9db97a1c63053bc376419e913a19f9f99a3f7b7d Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:35 +0100
Subject: [PATCH 07/20] xen: Modify grub_xen_ptr2mfn() for Xen PVH
grub_xen_ptr2mfn() returns the machine frame number for a given pointer
value. For Xen-PVH guests this is just the PFN. Add the PVH specific
variant.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit 3b8d09c7742a1890eadad6987852c82947ea5d4a)
---
grub-core/kern/xen/init.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
index 10007b411..a23dad633 100644
--- a/grub-core/kern/xen/init.c
+++ b/grub-core/kern/xen/init.c
@@ -45,6 +45,8 @@ grub_xen_ptr2mfn (void *ptr)
grub_xen_mfn_t *mfn_list =
(grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list;
return mfn_list[(grub_addr_t) ptr >> GRUB_XEN_LOG_PAGE_SIZE];
+#else
+ return (grub_addr_t) ptr >> GRUB_XEN_LOG_PAGE_SIZE;
#endif
}
--
2.21.0
From d0a9f803262b4702c0509d39820b2262d5bd916d Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:36 +0100
Subject: [PATCH 08/20] xen: Add PVH specific defines to offset.h
include/grub/offsets.h needs some defines for Xen PVH mode.
Add them. While at it line up the values in the surrounding lines to
start at the same column.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
(cherry picked from commit 53a92dea8b675afb3f46aed15c04528695d46d59)
---
include/grub/offsets.h | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/include/grub/offsets.h b/include/grub/offsets.h
index c88c86d4d..8c784a57d 100644
--- a/include/grub/offsets.h
+++ b/include/grub/offsets.h
@@ -36,9 +36,10 @@
#define GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE (0x9000-0x8200)
/* The segment where the kernel is loaded. */
-#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800
+#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800
-#define GRUB_KERNEL_I386_PC_LINK_ADDR 0x9000
+#define GRUB_KERNEL_I386_PC_LINK_ADDR 0x9000
+#define GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR 0x100000
/* The upper memory area (starting at 640 kiB). */
#define GRUB_MEMORY_I386_PC_UPPER 0xa0000
@@ -101,15 +102,17 @@
#define GRUB_KERNEL_I386_MULTIBOOT_MOD_ALIGN GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
#define GRUB_KERNEL_X86_64_XEN_MOD_ALIGN 0x8
-#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8
+#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8
+#define GRUB_KERNEL_I386_XEN_PVH_MOD_ALIGN 0x8
/* Non-zero value is only needed for PowerMacs. */
-#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0
-#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0
-#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0
-#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0
-#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0
-#define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0
+#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_XEN_PVH_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0
+#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0
+#define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0
#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000
#define GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN 3
--
2.21.0
From 6f19a6f001e182b9716ea850ce39bb2545c558cb Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:37 +0100
Subject: [PATCH 09/20] xen: Add basic hooks for PVH in current code
Add the hooks to current code needed for Xen PVH. They will be filled
with code later when the related functionality is being added.
loader/i386/linux.c needs to include machine/kernel.h now as it needs
to get GRUB_KERNEL_USE_RSDP_ADDR from there. This in turn requires to
add an empty kernel.h header for some i386 platforms (efi, coreboot,