Commit adfffc93 authored by Colin Watson's avatar Colin Watson

Backport Xen PVH guest support from upstream

Closes: #776450
parents e4e7c3fa 0e3e215f
......@@ -151,6 +151,7 @@ case "$target_cpu"-"$platform" in
i386-efi) ;;
x86_64-efi) ;;
i386-xen) ;;
i386-xen_pvh) ;;
x86_64-xen) ;;
i386-pc) ;;
i386-multiboot) ;;
......@@ -217,6 +218,7 @@ case "$platform" in
multiboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
efi) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
xen) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
xen_pvh) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN_PVH=1" ;;
ieee1275) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
uboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
......@@ -1936,6 +1938,7 @@ AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform =
AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh])
AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips])
......
# see git-dpm(1) from git-dpm package
2a8298a27e1313af552c049e35ec8c8c82197285
2a8298a27e1313af552c049e35ec8c8c82197285
0e3e215f58cbacbd623a19c5283da412d729cc65
0e3e215f58cbacbd623a19c5283da412d729cc65
59aeb1cfaa3d5bfd7bbeeee0f0d37f6d9eed51fe
59aeb1cfaa3d5bfd7bbeeee0f0d37f6d9eed51fe
grub2_2.02+dfsg1.orig.tar.xz
......
......@@ -10,6 +10,7 @@ grub2 (2.02+dfsg1-10) UNRELEASED; urgency=medium
can't figure this out for itself since we apply debconf-based
customisations on top of the template configuration file (closes:
#812574, LP: #564853).
* Backport Xen PVH guest support from upstream (closes: #776450).
-- Colin Watson <cjwatson@debian.org> Fri, 21 Dec 2018 21:20:48 +0000
......
......@@ -100,3 +100,23 @@ linuxefi-update-to-new-interfaces.patch
gcc-8-packed-not-aligned.patch
linuxefi-skip-validation-without-secure-boot.patch
efi-fdt-do-not-copy-random-memory.patch
xen-pvh-add-headers.patch
xen-pvh-rsdp-boot-params.patch
xen-pvh-refactor-grant-tab-init.patch
xen-pvh-prepare-common-code.patch
xen-pvh-add-dummy-headers.patch
xen-pvh-rearrange-init.patch
xen-pvh-ptr2mfn.patch
xen-pvh-offsets.patch
xen-pvh-basic-hooks.patch
xen-pvh-boot-entry.patch
xen-pvh-setup-hypercall-page.patch
xen-pvh-get-memory-map.patch
xen-pvh-setup-data.patch
xen-pvh-init-memory-regions.patch
xen-pvh-build.patch
xen-pvh-module-verifier.patch
xen-pvh-elfnote-defines.patch
xen-pvh-mkimage.patch
xen-pvh-install.patch
xen-pvh-configure.patch
From c5e44c9c6dd64d4447eae7ceebd8437e63a8d0bf Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:33 +0100
Subject: 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>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=408de833bbd1ccad39ad439eaf3cddd528b039b5
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-add-dummy-headers.patch
---
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>
This diff is collapsed.
This diff is collapsed.
From 6c3df9cf4e8e965f7c18b10afba8d311e87b381d Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:38 +0100
Subject: xen: Add PVH boot entry code
Add the code for the Xen PVH mode boot entry.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=1a4d83af2fc1eb0a0951775a2b86860ab074c699
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-boot-entry.patch
---
grub-core/kern/i386/xen/startup_pvh.S | 52 +++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/grub-core/kern/i386/xen/startup_pvh.S b/grub-core/kern/i386/xen/startup_pvh.S
index 69b8fdcca..363c31858 100644
--- a/grub-core/kern/i386/xen/startup_pvh.S
+++ b/grub-core/kern/i386/xen/startup_pvh.S
@@ -19,11 +19,63 @@
#include <config.h>
#include <grub/symbol.h>
+#include <grub/machine/memory.h>
.file "startup_pvh.S"
.text
+ .globl start, _start
+ .code32
+start:
+_start:
+ cld
+ lgdt gdtdesc
+ ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f
+1:
+ movl $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %eax
+ mov %eax, %ds
+ mov %eax, %es
+ mov %eax, %fs
+ mov %eax, %gs
+ mov %eax, %ss
+ leal LOCAL(stack_end), %esp
+
+ /* Save address of start info structure. */
+ mov %ebx, pvh_start_info
+ call EXT_C(grub_main)
+ /* Doesn't return. */
+
+ .p2align 3
+gdt:
+ .word 0, 0
+ .byte 0, 0, 0, 0
+
+ /* -- code segment --
+ * base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present
+ * type = 32bit code execute/read, DPL = 0
+ */
+ .word 0xFFFF, 0
+ .byte 0, 0x9A, 0xCF, 0
+
+ /* -- data segment --
+ * base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present
+ * type = 32 bit data read/write, DPL = 0
+ */
+ .word 0xFFFF, 0
+ .byte 0, 0x92, 0xCF, 0
+
+ .p2align 3
+/* this is the GDT descriptor */
+gdtdesc:
+ .word 0x17 /* limit */
+ .long gdt /* addr */
+
+ .p2align 2
/* Saved pointer to start info structure. */
.globl pvh_start_info
pvh_start_info:
.long 0
+
+ .bss
+ .space GRUB_MEMORY_MACHINE_PROT_STACK_SIZE
+LOCAL(stack_end):
From fdb322ca3c1d64f93e7d81a64899773c62eb18f0 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:43 +0100
Subject: xen_pvh: Add build runes for grub-core
Add the modifications to the build system needed to build a xen_pvh
grub.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=9c062ad42c32a42b677da4b066cb33debf1dfe30
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-build.patch
---
gentpl.py | 4 ++--
grub-core/Makefile.am | 12 ++++++++++++
grub-core/Makefile.core.def | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/gentpl.py b/gentpl.py
index f08bcc404..24d890895 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -28,7 +28,7 @@ import re
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
- "i386_xen", "x86_64_xen",
+ "i386_xen", "x86_64_xen", "i386_xen_pvh",
"mips_loongson", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ]
@@ -69,7 +69,7 @@ GROUPS["videomodules"] = GRUB_PLATFORMS[:];
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
# Similar for terminfo
-GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"];
+GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips", "i386_xen_pvh" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"];
GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index cc884e379..95e9817ca 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -101,6 +101,18 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
+if COND_i386_xen_pvh
+KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
+KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
+endif
+
if COND_i386_efi
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index b6cb87c94..94a15f8c7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -79,6 +79,8 @@ kernel = {
i386_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0';
x86_64_xen_ldflags = '$(TARGET_IMG_LDFLAGS)';
x86_64_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0';
+ i386_xen_pvh_ldflags = '$(TARGET_IMG_LDFLAGS)';
+ i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000';
mips_loongson_ldflags = '-Wl,-Ttext,0x80200000';
powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
@@ -98,6 +100,7 @@ kernel = {
x86_64_efi_startup = kern/x86_64/efi/startup.S;
i386_xen_startup = kern/i386/xen/startup.S;
x86_64_xen_startup = kern/x86_64/xen/startup.S;
+ i386_xen_pvh_startup = kern/i386/xen/startup_pvh.S;
i386_qemu_startup = kern/i386/qemu/startup.S;
i386_ieee1275_startup = kern/i386/ieee1275/startup.S;
i386_coreboot_startup = kern/i386/coreboot/startup.S;
@@ -159,6 +162,7 @@ kernel = {
i386 = kern/i386/dl.c;
i386_xen = kern/i386/dl.c;
+ i386_xen_pvh = kern/i386/dl.c;
i386_coreboot = kern/i386/coreboot/init.c;
i386_multiboot = kern/i386/coreboot/init.c;
@@ -204,6 +208,14 @@ kernel = {
xen = disk/xen/xendisk.c;
xen = commands/boot.c;
+ i386_xen_pvh = commands/boot.c;
+ i386_xen_pvh = disk/xen/xendisk.c;
+ i386_xen_pvh = kern/i386/tsc.c;
+ i386_xen_pvh = kern/i386/xen/tsc.c;
+ i386_xen_pvh = kern/i386/xen/pvh.c;
+ i386_xen_pvh = kern/xen/init.c;
+ i386_xen_pvh = term/xen/console.c;
+
ia64_efi = kern/ia64/efi/startup.S;
ia64_efi = kern/ia64/efi/init.c;
ia64_efi = kern/ia64/dl.c;
@@ -775,6 +787,7 @@ module = {
name = cpuid;
common = commands/i386/cpuid.c;
enable = x86;
+ enable = i386_xen_pvh;
enable = i386_xen;
enable = x86_64_xen;
};
@@ -834,6 +847,7 @@ module = {
i386_coreboot = lib/i386/halt.c;
i386_qemu = lib/i386/halt.c;
xen = lib/xen/halt.c;
+ i386_xen_pvh = lib/xen/halt.c;
efi = lib/efi/halt.c;
ieee1275 = lib/ieee1275/halt.c;
emu = lib/emu/halt.c;
@@ -854,6 +868,7 @@ module = {
mips_loongson = lib/mips/loongson/reboot.c;
mips_qemu_mips = lib/mips/qemu_mips/reboot.c;
xen = lib/xen/reboot.c;
+ i386_xen_pvh = lib/xen/reboot.c;
uboot = lib/uboot/reboot.c;
common = commands/reboot.c;
};
@@ -1526,12 +1541,18 @@ module = {
x86 = lib/i386/relocator16.S;
x86 = lib/i386/relocator32.S;
x86 = lib/i386/relocator64.S;
+ i386_xen_pvh = lib/i386/relocator16.S;
+ i386_xen_pvh = lib/i386/relocator32.S;
+ i386_xen_pvh = lib/i386/relocator64.S;
i386 = lib/i386/relocator_asm.S;
+ i386_xen_pvh = lib/i386/relocator_asm.S;
x86_64 = lib/x86_64/relocator_asm.S;
i386_xen = lib/i386/relocator_asm.S;
x86_64_xen = lib/x86_64/relocator_asm.S;
x86 = lib/i386/relocator.c;
x86 = lib/i386/relocator_common_c.c;
+ i386_xen_pvh = lib/i386/relocator.c;
+ i386_xen_pvh = lib/i386/relocator_common_c.c;
ieee1275 = lib/ieee1275/relocator.c;
efi = lib/efi/relocator.c;
mips = lib/mips/relocator_asm.S;
@@ -1550,6 +1571,7 @@ module = {
enable = mips;
enable = powerpc;
enable = x86;
+ enable = i386_xen_pvh;
enable = xen;
};
@@ -1563,6 +1585,7 @@ module = {
sparc64_ieee1275 = lib/ieee1275/cmos.c;
powerpc_ieee1275 = lib/ieee1275/cmos.c;
xen = lib/xen/datetime.c;
+ i386_xen_pvh = lib/xen/datetime.c;
mips_arc = lib/arc/datetime.c;
enable = noemu;
@@ -1649,6 +1672,7 @@ module = {
common = lib/cmdline.c;
common = loader/multiboot_mbi2.c;
enable = x86;
+ enable = i386_xen_pvh;
enable = mips;
};
@@ -1657,8 +1681,10 @@ module = {
common = loader/multiboot.c;
common = lib/cmdline.c;
x86 = loader/i386/multiboot_mbi.c;
+ i386_xen_pvh = loader/i386/multiboot_mbi.c;
extra_dist = loader/multiboot_elfxx.c;
enable = x86;
+ enable = i386_xen_pvh;
};
module = {
@@ -1671,8 +1697,10 @@ module = {
module = {
name = linux;
x86 = loader/i386/linux.c;
+ i386_xen_pvh = loader/i386/linux.c;
xen = loader/i386/xen.c;
i386_pc = lib/i386/pc/vesa_modes_table.c;
+ i386_xen_pvh = lib/i386/pc/vesa_modes_table.c;
mips = loader/mips/linux.c;
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
@@ -1768,6 +1796,8 @@ module = {
common = mmap/mmap.c;
x86 = mmap/i386/uppermem.c;
x86 = mmap/i386/mmap.c;
+ i386_xen_pvh = mmap/i386/uppermem.c;
+ i386_xen_pvh = mmap/i386/mmap.c;
i386_pc = mmap/i386/pc/mmap.c;
i386_pc = mmap/i386/pc/mmap_helper.S;
@@ -1777,6 +1807,7 @@ module = {
mips = mmap/mips/uppermem.c;
enable = x86;
+ enable = i386_xen_pvh;
enable = ia64_efi;
enable = arm_efi;
enable = arm64_efi;
@@ -2010,6 +2041,7 @@ module = {
name = legacy_password_test;
common = tests/legacy_password_test.c;
enable = i386_pc;
+ enable = i386_xen_pvh;
enable = i386_efi;
enable = x86_64_efi;
enable = emu;
@@ -2208,6 +2240,7 @@ module = {
xen = lib/i386/pc/vesa_modes_table.c;
enable = i386_pc;
+ enable = i386_xen_pvh;
enable = i386_efi;
enable = x86_64_efi;
enable = emu;
@@ -2251,10 +2284,12 @@ module = {
module = {
name = backtrace;
x86 = lib/i386/backtrace.c;
+ i386_xen_pvh = lib/i386/backtrace.c;
i386_xen = lib/i386/backtrace.c;
x86_64_xen = lib/i386/backtrace.c;
common = lib/backtrace.c;
enable = x86;
+ enable = i386_xen_pvh;
enable = i386_xen;
enable = x86_64_xen;
};
From 0e3e215f58cbacbd623a19c5283da412d729cc65 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:48 +0100
Subject: xen_pvh: Add support to configure
Support platform i386/xen_pvh in configure.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=d789e70e26340bd35b36d595a948dbc399b9ffba
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-configure.patch
---
configure.ac | 3 +++
1 file changed, 3 insertions(+)
diff --git a/configure.ac b/configure.ac
index f102b7024..5b7423be3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -151,6 +151,7 @@ case "$target_cpu"-"$platform" in
i386-efi) ;;
x86_64-efi) ;;
i386-xen) ;;
+ i386-xen_pvh) ;;
x86_64-xen) ;;
i386-pc) ;;
i386-multiboot) ;;
@@ -217,6 +218,7 @@ case "$platform" in
multiboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
efi) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
xen) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
+ xen_pvh) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN_PVH=1" ;;
ieee1275) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
uboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
@@ -1936,6 +1938,7 @@ AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform =
AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
+AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh])
AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips])
From 7d890df3ad1eb733da162b8d7d3f3de41be368e6 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:45 +0100
Subject: xen: Use elfnote defines instead of plain numbers
In order to avoid using plain integers for the ELF notes use the
available Xen include instead.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=9bce25213a44553c71527776f65fabc3b729c2f3
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-elfnote-defines.patch
---
util/grub-mkimagexx.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index f20255a28..4ac9c8470 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -48,6 +48,8 @@
#include <grub/util/install.h>
#include <grub/util/mkimage.h>
+#include <xen/elfnote.h>
+
#pragma GCC diagnostic ignored "-Wcast-align"
/* These structures are defined according to the CHRP binding to IEEE1275,
@@ -312,7 +314,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (sizeof (PACKAGE_NAME));
- note_ptr->n_type = grub_host_to_target32 (6);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_GUEST_OS);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
@@ -323,7 +325,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (sizeof ("generic"));
- note_ptr->n_type = grub_host_to_target32 (8);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_LOADER);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
@@ -334,7 +336,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (sizeof ("xen-3.0"));
- note_ptr->n_type = grub_host_to_target32 (5);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_XEN_VERSION);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
@@ -345,7 +347,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (image_target->voidp_sizeof);
- note_ptr->n_type = grub_host_to_target32 (1);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_ENTRY);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
@@ -356,7 +358,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (image_target->voidp_sizeof);
- note_ptr->n_type = grub_host_to_target32 (3);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_VIRT_BASE);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
@@ -369,7 +371,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
note_ptr = (Elf_Nhdr *) ptr;
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME));
note_ptr->n_descsz = grub_host_to_target32 (sizeof ("yes,bimodal"));
- note_ptr->n_type = grub_host_to_target32 (9);
+ note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_PAE_MODE);
ptr += sizeof (Elf_Nhdr);
memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME));
ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4);
From 9cbe74c503f40832d02ef407e6452fda638f7589 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 7 Dec 2018 13:11:40 +0100
Subject: xen: Get memory map from hypervisor for PVH
Retrieve the memory map from the hypervisor and normalize it to contain
no overlapping entries and to be sorted by address.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Hans van Kranenburg <hans@knorrie.org>
Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=2b7a21afd319b829941a928f5763e017d1cc2951
Bug-Debian: https://bugs.debian.org/776450
Last-Update: 2019-01-07
Patch-Name: xen-pvh-get-memory-map.patch
---
grub-core/kern/i386/xen/pvh.c | 94 +++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/grub-core/kern/i386/xen/pvh.c b/grub-core/kern/i386/xen/pvh.c
index a2554fb1d..2b68ac333 100644
--- a/grub-core/kern/i386/xen/pvh.c
+++ b/grub-core/kern/i386/xen/pvh.c
@@ -24,7 +24,12 @@
#include <grub/i386/io.h>
#include <grub/xen.h>
#include <xen/hvm/start_info.h>
+#include <grub/i386/linux.h>
#include <grub/machine/kernel.h>
+#include <grub/machine/memory.h>
+#include <xen/memory.h>
+
+#define XEN_MEMORY_MAP_SIZE 128
grub_uint64_t grub_rsdp_addr;
@@ -32,6 +37,8 @@ static char hypercall_page[GRUB_XEN_PAGE_SIZE]
__attribute__ ((aligned (GRUB_XEN_PAGE_SIZE)));
static grub_uint32_t xen_cpuid_base;
+static struct grub_e820_mmap_entry map[XEN_MEMORY_MAP_SIZE];
+static unsigned int nr_map_entries;
static void
grub_xen_cons_msg (const char *msg)
@@ -104,11 +111,98 @@ grub_xen_hypercall (grub_uint32_t callno, grub_uint32_t a0,
return res;
}
+static void
+grub_xen_sort_mmap (void)
+{
+ grub_uint64_t from, to;
+ unsigned int i;
+ struct grub_e820_mmap_entry tmp;
+
+ /* Align map entries to page boundaries. */
+ for (i = 0; i < nr_map_entries; i++)
+ {
+ from = map[i].addr;
+ to = from + map[i].len;
+ if (map[i].type == GRUB_MEMORY_AVAILABLE)
+ {
+ from = ALIGN_UP (from, GRUB_XEN_PAGE_SIZE);
+ to = ALIGN_DOWN (to, GRUB_XEN_PAGE_SIZE);
+ }
+ else
+ {
+ from = ALIGN_DOWN (from, GRUB_XEN_PAGE_SIZE);
+ to = ALIGN_UP (to, GRUB_XEN_PAGE_SIZE);
+ }
+ map[i].addr = from;
+ map[i].len = to - from;
+ }
+
+ again:
+ /* Sort entries by start address. */
+ for (i = 1; i < nr_map_entries; i++)
+ {
+ if (map[i].addr >= map[i - 1].addr)
+ continue;
+ tmp = map[i];
+ map[i] = map[i - 1];
+ map[i - 1] = tmp;
+ i = 0;
+ }
+
+ /* Detect overlapping areas. */
+ for (i = 1; i < nr_map_entries; i++)
+ {
+ if (map[i].addr >= map[i - 1].addr + map[i - 1].len)
+ continue;
+ tmp = map[i - 1];
+ map[i - 1].len = map[i].addr - map[i - 1].addr;
+ if (map[i].addr + map[i].len >= tmp.addr + tmp.len)
+ continue;
+ if (nr_map_entries < ARRAY_SIZE (map))
+ {
+ map[nr_map_entries].addr = map[i].addr + map[i].len;
+ map[nr_map_entries].len = tmp.addr + tmp.len - map[nr_map_entries].addr;
+ map[nr_map_entries].type = tmp.type;
+ nr_map_entries++;
+ goto again;
+ }
+ }
+
+ /* Merge adjacent entries. */
+ for (i = 1; i < nr_map_entries; i++)
+ {
+ if (map[i].type == map[i - 1].type &&
+ map[i].addr == map[i - 1].addr + map[i - 1].len)
+ {
+ map[i - 1].len += map[i].len;
+ map[i] = map[nr_map_entries - 1];