Skip to contentSkip to conversation

Xen: extend kexec hypercall for use with pv-ops kernels

PATCH Superseded David Vrabel 4 participants 24 messages Sep 20, 2013 – Oct 7, 2013

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v8 cover Xen: extend kexec hypercall for use with pv-ops kernels

The series (for Xen 4.4) improves the kexec hypercall by making Xen responsible for loading and relocating the image. This allows kexec to be usable by pv-ops kernels and should allow kexec to be usable from a HVM or PVH privileged domain.

The first patch is a simple clean-up.

Patch 2 introduces the new ABI.

Patch 3 and 4 nearly completely reimplement the kexec load, unload and exec sub-ops. The old load_v1 sub-op is then implemented on top of the new code.

Patch 5 calls the kexec image when dom0 crashes. This avoids having to alter dom0 kernels to do a exec sub-op call on crash -- a SHUTDOWN_crash by dom0 will trigger the kexec.

Patches 6 and 7 add the libxc API for the kexec calls. These have been acked-by Ian Campbell already.

Patch 8 adds a link time check for the size of the relocate code.

Patch 9 adds myself as the maintainer for kexec in Xen.

The required patch series for kexec-tools will be posted shortly and are available from the xen-v5 branch of:

http://xenbits.xen.org/gitweb/?p=people/dvrabel/kexec-tools.git;a=summary

Changes in v8:

- Use #defines for compat ABI structures.
- Tweak link time check for kexec_reloc.

Changes in v7:

- No longer use GUEST_HANDLE_64(), get a uniform ABI by using unions and explicit padding.
- Only map the segments and not all of RAM.
- Add a mechanism to create mappings for use by the exec'd image (a segment with a NULL buf handle).
- Fix a bug where a crash image's code page would by placed at machine address 0 (instead of inside the crash region).

Changes in v6:

- Fix double free in KEXEC_load_v1 failure path.
- Only copy the relocation code and not the whole page.
- Add myself as the kexec maintainer.

Changes in v5 (not posted to the list):

- _rsvd -> _pad in one of the public ABI structures.
- Fix bug where trailing pages were not zeroed. This fixes loading a 64-bit Linux kernel using a more recent version of kexec-tools.
- Check the relocation code fits into a page at link time.

Changes in v4:

- Use paddr_t and page_to_maddr() etc. for portability.
- Add explicit padding to hypercall structures where required.
- Minor cleanup of the kexec_reloc assembly.
- Print a message before exec'ing a crash image.
- Style fixes (tabs, trailing whitespace) and typos.
- Fix a bug where using the V1 interface and unloading a image may crash.

Changes in v3:

- Provide old struct xen_kexec_load if __XEN_INTERFACE_VERSION__ < 4.3
- Adjust new struct xen_kexec_load to avoid unnecessary padding.
- Use domheap pages for the image and control pages.
- Remove the DBG() macros from the reloc code.

David

#1 lore raw

PATCH v8 1/9 x86: give FIX_EFI_MPF its own fixmap entry

From: David Vrabel <[email protected]>

FIX_EFI_MPF was the same as FIX_KEXEC_BASE_0 which is going away. So add its own entry.

---
 xen/arch/x86/mpparse.c       |    2 --
 xen/include/asm-x86/fixmap.h |    1 +
 2 files changed, 1 insertions(+), 2 deletions(-)
xen/arch/x86/mpparse.c +0 -2
index 97d34bc..3753704 100644
@@ -538,8 +538,6 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 	}
 }
 
-#define FIX_EFI_MPF FIX_KEXEC_BASE_0
-
 static __init void efi_unmap_mpf(void)
 {
 	if (efi_enabled)
xen/include/asm-x86/fixmap.h +1 -0
index d850be4..8b4266d 100644
@@ -66,6 +66,7 @@ enum fixed_addresses {
     FIX_APEI_RANGE_BASE,
     FIX_APEI_RANGE_END = FIX_APEI_RANGE_BASE + FIX_APEI_RANGE_MAX -1,
     FIX_IGD_MMIO,
+    FIX_EFI_MPF,
     __end_of_fixed_addresses
 };
 
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH v8 2/9 kexec: add public interface for improved load/unload sub-ops

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add replacement KEXEC_CMD_load and KEXEC_CMD_unload sub-ops to the kexec hypercall. These new sub-ops allow a priviledged guest to provide the image data to be loaded into Xen memory or the crash region instead of guests loading the image data themselves and providing the relocation code and metadata.

The old interface is provided to guests requesting an interface version prior to 4.3.

Bump __XEN_LATEST_INTERFACE_VERSION__ to 0x00040400.

Signed-off: David Vrabel <[email protected]>

---
 xen/common/kexec.c              |   12 +++---
 xen/include/public/kexec.h      |   78 +++++++++++++++++++++++++++++++++++++--
 xen/include/public/xen-compat.h |    2 +-
 3 files changed, 81 insertions(+), 11 deletions(-)
xen/common/kexec.c +6 -6
index 7cd151f..7b23df0 100644
@@ -734,7 +734,7 @@ static void crash_save_vmcoreinfo(void)
 #endif
 }
 
-static int kexec_load_unload_internal(unsigned long op, xen_kexec_load_t *load)
+static int kexec_load_unload_internal(unsigned long op, xen_kexec_load_v1_t *load)
 {
     xen_kexec_image_t *image;
     int base, bit, pos;
@@ -781,7 +781,7 @@ static int kexec_load_unload_internal(unsigned long op, xen_kexec_load_t *load)
 
 static int kexec_load_unload(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
-    xen_kexec_load_t load;
+    xen_kexec_load_v1_t load;
 
     if ( unlikely(copy_from_guest(&load, uarg, 1)) )
         return -EFAULT;
@@ -793,8 +793,8 @@ static int kexec_load_unload_compat(unsigned long op,
                                     XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
 #ifdef CONFIG_COMPAT
-    compat_kexec_load_t compat_load;
-    xen_kexec_load_t load;
+    compat_kexec_load_v1_t compat_load;
+    xen_kexec_load_v1_t load;
 
     if ( unlikely(copy_from_guest(&compat_load, uarg, 1)) )
         return -EFAULT;
@@ -866,8 +866,8 @@ static int do_kexec_op_internal(unsigned long op,
         else
                 ret = kexec_get_range(uarg);
         break;
-    case KEXEC_CMD_kexec_load:
-    case KEXEC_CMD_kexec_unload:
+    case KEXEC_CMD_kexec_load_v1:
+    case KEXEC_CMD_kexec_unload_v1:
         spin_lock_irqsave(&kexec_lock, flags);
         if (!test_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags))
         {
xen/include/public/kexec.h +74 -4

92 lines not on this page · raw message

xen/include/public/xen-compat.h +1 -1
index 69141c4..3eb80a0 100644
@@ -27,7 +27,7 @@
 #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
 #define __XEN_PUBLIC_XEN_COMPAT_H__
 
-#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040300
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040400
 
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 /* Xen is built with matching headers and implements the latest interface. */
Signature · 1 line
1.7.2.5
#3 lore raw

Re: [PATCH 2/9] kexec: add public interface for improved load/unload sub-ops

Quoted 9 lines
Quoted 1 line
Quoted 1 line · David Vrabel

From: David Vrabel <[email protected]>

Add replacement KEXEC_CMD_load and KEXEC_CMD_unload sub-ops to the kexec hypercall. These new sub-ops allow a priviledged guest to provide the image data to be loaded into Xen memory or the crash region instead of guests loading the image data themselves and providing the relocation code and metadata.

Quoted 4 lines

The old interface is provided to guests requesting an interface version prior to 4.3.

Bump __XEN_LATEST_INTERFACE_VERSION__ to 0x00040400.

The paragraph directly preceding this sentence is inconsistent with this.

xen/include/public/kexec.h typedef struct xen_kexec_exec { · line 120

Quoted 11 lines
xen/include/public/kexec.h +2 -3
@@ -116,12 +116,12 @@ typedef struct xen_kexec_exec {
  * type  == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
  * image == relocation information for kexec (ignored for unload) [in]
  */
-#define KEXEC_CMD_kexec_load            1
-#define KEXEC_CMD_kexec_unload          2
-typedef struct xen_kexec_load {
+#define KEXEC_CMD_kexec_load_v1         1 /* obsolete since 0x00040300 */
+#define KEXEC_CMD_kexec_unload_v1       2 /* obsolete since 0x00040300 */

And so are these comments.

Jan

#4 lore raw

PATCH v8 3/9 kexec: add infrastructure for handling kexec images

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add the code needed to handle and load kexec images into Xen memory or into the crash region. This is needed for the new KEXEC_CMD_load and KEXEC_CMD_unload hypercall sub-ops.

Much of this code is derived from the Linux kernel.

---
 xen/common/Makefile      |    1 +
 xen/common/kimage.c      |  817 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/kimage.h |   62 ++++
 3 files changed, 880 insertions(+), 0 deletions(-)
 create mode 100644 xen/common/kimage.c
 create mode 100644 xen/include/xen/kimage.h
xen/common/Makefile +1 -0
index 5486140..3cb456a 100644
@@ -11,6 +11,7 @@ obj-y += irq.o
 obj-y += kernel.o
 obj-y += keyhandler.o
 obj-$(HAS_KEXEC) += kexec.o
+obj-$(HAS_KEXEC) += kimage.o
 obj-y += lib.o
 obj-y += memory.o
 obj-y += multicall.o
xen/common/kimage.c new file +817 -0

817 lines not on this page · raw message

xen/include/xen/kimage.h new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#5 lore raw

PATCH v8 4/9 kexec: extend hypercall with improved load/unload ops

In reply to David Vrabel

From: David Vrabel <[email protected]>

In the existing kexec hypercall, the load and unload ops depend on internals of the Linux kernel (the page list and code page provided by the kernel). The code page is used to transition between Xen context and the image so using kernel code doesn't make sense and will not work for PVH guests.

Add replacement KEXEC_CMD_kexec_load and KEXEC_CMD_kexec_unload ops that no longer require a code page to be provided by the guest -- Xen now provides the code for calling the image directly.

The new load op looks similar to the Linux kexec_load system call and allows the guest to provide the image data to be loaded. The guest specifies the architecture of the image which may be a 32-bit subarch of the hypervisor's architecture (i.e., an EM_386 image on an EM_X86_64 hypervisor).

The toolstack can now load images without kernel involvement. This is required for supporting kexec when using a dom0 with an upstream kernel.

Crash images are copied directly into the crash region on load. Default images are copied into domheap pages and a list of source and destination machine addresses is created. This is list is used in kexec_reloc() to relocate the image to its destination.

The old load and unload sub-ops are still available (as KEXEC_CMD_load_v1 and KEXEC_CMD_unload_v1) and are implemented on top of the new infrastructure.

---
 xen/arch/x86/machine_kexec.c        |  192 +++++++++++-------
 xen/arch/x86/x86_64/Makefile        |    2 +-
 xen/arch/x86/x86_64/compat_kexec.S  |  187 -----------------
 xen/arch/x86/x86_64/kexec_reloc.S   |  208 ++++++++++++++++++
 xen/common/kexec.c                  |  393 +++++++++++++++++++++++++++++------
 xen/common/kimage.c                 |  123 +++++++++++-
 xen/include/asm-x86/fixmap.h        |    3 -
 xen/include/asm-x86/machine_kexec.h |   16 ++
 xen/include/xen/kexec.h             |   16 +-
 xen/include/xen/kimage.h            |    6 +
 10 files changed, 811 insertions(+), 335 deletions(-)
 delete mode 100644 xen/arch/x86/x86_64/compat_kexec.S
 create mode 100644 xen/arch/x86/x86_64/kexec_reloc.S
 create mode 100644 xen/include/asm-x86/machine_kexec.h
xen/arch/x86/machine_kexec.c +121 -71
index 68b9705..b70d5a6 100644
@@ -1,9 +1,18 @@
 /******************************************************************************
  * machine_kexec.c
  *
+ * Copyright (C) 2013 Citrix Systems R&D Ltd.
+ *
+ * Portions derived from Linux's arch/x86/kernel/machine_kexec_64.c.
+ *
+ *   Copyright (C) 2002-2005 Eric Biederman  <[email protected]>
+ *
  * Xen port written by:
  * - Simon 'Horms' Horman <[email protected]>
  * - Magnus Damm <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
  */
 
 #include <xen/types.h>
@@ -11,63 +20,124 @@
 #include <xen/guest_access.h>
 #include <asm/fixmap.h>
 #include <asm/hpet.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
 
-typedef void (*relocate_new_kernel_t)(
-                unsigned long indirection_page,
-                unsigned long *page_list,
-                unsigned long start_address,
-                unsigned int preserve_context);
-
-int machine_kexec_load(int type, int slot, xen_kexec_image_t *image)
+/*
+ * Add a mapping for a page to the page tables used during kexec.
+ */
+int machine_kexec_add_page(struct kexec_image *image, unsigned long vaddr,
+                           unsigned long maddr)
 {
-    unsigned long prev_ma = 0;
-    int fix_base = FIX_KEXEC_BASE_0 + (slot * (KEXEC_XEN_NO_PAGES >> 1));
-    int k;
+    struct page_info *l4_page;
+    struct page_info *l3_page;
+    struct page_info *l2_page;
+    struct page_info *l1_page;
+    l4_pgentry_t *l4 = NULL;
+    l3_pgentry_t *l3 = NULL;
+    l2_pgentry_t *l2 = NULL;
+    l1_pgentry_t *l1 = NULL;
+    int ret = -ENOMEM;
+
+    l4_page = image->aux_page;
+    if ( !l4_page )
+    {
+        l4_page = kimage_alloc_control_page(image, 0);
+        if ( !l4_page )
+            goto out;
+        image->aux_page = l4_page;
+    }
 
-    /* setup fixmap to point to our pages and record the virtual address
-     * in every odd index in page_list[].
-     */
+    l4 = __map_domain_page(l4_page);
+    l4 += l4_table_offset(vaddr);
+    if ( !(l4e_get_flags(*l4) & _PAGE_PRESENT) )
+    {
+        l3_page = kimage_alloc_control_page(image, 0);
+        if ( !l3_page )
+            goto out;
+        l4e_write(l4, l4e_from_page(l3_page, __PAGE_HYPERVISOR));
+    }
+    else
+        l3_page = l4e_get_page(*l4);
+
+    l3 = __map_domain_page(l3_page);
+    l3 += l3_table_offset(vaddr);
+    if ( !(l3e_get_flags(*l3) & _PAGE_PRESENT) )
+    {
+        l2_page = kimage_alloc_control_page(image, 0);
+        if ( !l2_page )
+            goto out;
+        l3e_write(l3, l3e_from_page(l2_page, __PAGE_HYPERVISOR));
+    }
+    else
+        l2_page = l3e_get_page(*l3);
+
+    l2 = __map_domain_page(l2_page);
+    l2 += l2_table_offset(vaddr);
+    if ( !(l2e_get_flags(*l2) & _PAGE_PRESENT) )
+    {
+        l1_page = kimage_alloc_control_page(image, 0);
+        if ( !l1_page )
+            goto out;
+        l2e_write(l2, l2e_from_page(l1_page, __PAGE_HYPERVISOR));
+    }
+    else
+        l1_page = l2e_get_page(*l2);
+
+    l1 = __map_domain_page(l1_page);
+    l1 += l1_table_offset(vaddr);
+    l1e_write(l1, l1e_from_pfn(maddr >> PAGE_SHIFT, __PAGE_HYPERVISOR));
+
+    ret = 0;
+out:
+    if ( l1 )
+        unmap_domain_page(l1);
+    if ( l2 )
+        unmap_domain_page(l2);
+    if ( l3 )
+        unmap_domain_page(l3);
+    if ( l4 )
+        unmap_domain_page(l4);
+    return ret;
+}
 
-    for ( k = 0; k < KEXEC_XEN_NO_PAGES; k++ )
+int machine_kexec_load(struct kexec_image *image)
+{
+    void *code_page;
+    int ret;
+
+    switch ( image->arch )
     {
-        if ( (k & 1) == 0 )
-        {
-            /* Even pages: machine address. */
-            prev_ma = image->page_list[k];
-        }
-        else
-        {
-            /* Odd pages: va for previous ma. */
-            if ( is_pv_32on64_domain(dom0) )
-            {
-                /*
-                 * The compatability bounce code sets up a page table
-                 * with a 1-1 mapping of the first 1G of memory so
-                 * VA==PA here.
-                 *
-                 * This Linux purgatory code still sets up separate
-                 * high and low mappings on the control page (entries
-                 * 0 and 1) but it is harmless if they are equal since
-                 * that PT is not live at the time.
-                 */
-                image->page_list[k] = prev_ma;
-            }
-            else
-            {
-                set_fixmap(fix_base + (k >> 1), prev_ma);
-                image->page_list[k] = fix_to_virt(fix_base + (k >> 1));
-            }
-        }
+    case EM_386:
+    case EM_X86_64:
+        break;
+    default:
+        return -EINVAL;
     }
 
+    code_page = __map_domain_page(image->control_code_page);
+    memcpy(code_page, kexec_reloc, kexec_reloc_size);
+    unmap_domain_page(code_page);
+
+    /*
+     * Add a mapping for the control code page to the same virtual
+     * address as kexec_reloc.  This allows us to keep running after
+     * these page tables are loaded in kexec_reloc.
+     */
+    ret = machine_kexec_add_page(image, (unsigned long)kexec_reloc,
+                                 page_to_maddr(image->control_code_page));
+    if ( ret < 0 )
+        return ret;
+
     return 0;
 }
 
-void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image)
+void machine_kexec_unload(struct kexec_image *image)
 {
+    /* no-op. kimage_free() frees all control pages. */
 }
 
-void machine_reboot_kexec(xen_kexec_image_t *image)
+void machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
@@ -75,13 +145,10 @@ void machine_reboot_kexec(xen_kexec_image_t *image)
     BUG();
 }
 
-void machine_kexec(xen_kexec_image_t *image)
+void machine_kexec(struct kexec_image *image)
 {
-    struct desc_ptr gdt_desc = {
-        .base = (unsigned long)(boot_cpu_gdt_table - FIRST_RESERVED_GDT_ENTRY),
-        .limit = LAST_RESERVED_GDT_BYTE
-    };
     int i;
+    unsigned long reloc_flags = 0;
 
     /* We are about to permenantly jump out of the Xen context into the kexec
      * purgatory code.  We really dont want to be still servicing interupts.
@@ -109,29 +176,12 @@ void machine_kexec(xen_kexec_image_t *image)
      * not like running with NMIs disabled. */
     enable_nmis();
 
-    /*
-     * compat_machine_kexec() returns to idle pagetables, which requires us
-     * to be running on a static GDT mapping (idle pagetables have no GDT
-     * mappings in their per-domain mapping area).
-     */
-    asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
+    if ( image->arch == EM_386 )
+        reloc_flags |= KEXEC_RELOC_FLAG_COMPAT;
 
-    if ( is_pv_32on64_domain(dom0) )
-    {
-        compat_machine_kexec(image->page_list[1],
-                             image->indirection_page,
-                             image->page_list,
-                             image->start_address);
-    }
-    else
-    {
-        relocate_new_kernel_t rnk;
-
-        rnk = (relocate_new_kernel_t) image->page_list[1];
-        (*rnk)(image->indirection_page, image->page_list,
-               image->start_address,
-               0 /* preserve_context */);
-    }
+    kexec_reloc(page_to_maddr(image->control_code_page),
+                page_to_maddr(image->aux_page),
+                image->head, image->entry_maddr, reloc_flags);
 }
 
 int machine_kexec_get(xen_kexec_range_t *range)
xen/arch/x86/x86_64/Makefile +1 -1
index d56e12d..7f8fb3d 100644
@@ -11,11 +11,11 @@ obj-y += mmconf-fam10h.o
 obj-y += mmconfig_64.o
 obj-y += mmconfig-shared.o
 obj-y += compat.o
-obj-bin-y += compat_kexec.o
 obj-y += domain.o
 obj-y += physdev.o
 obj-y += platform_hypercall.o
 obj-y += cpu_idle.o
 obj-y += cpufreq.o
+obj-bin-y += kexec_reloc.o
 
 obj-$(crash_debug)   += gdbstub.o
xen/arch/x86/x86_64/compat_kexec.S deleted +0 -187

187 lines not on this page · raw message

xen/arch/x86/x86_64/kexec_reloc.S new file +208 -0

208 lines not on this page · raw message

xen/common/kexec.c +331 -62

490 lines not on this page · raw message

xen/common/kimage.c +121 -2

166 lines not on this page · raw message

xen/include/asm-x86/fixmap.h +0 -3
index 8b4266d..48c5676 100644
@@ -56,9 +56,6 @@ enum fixed_addresses {
     FIX_ACPI_BEGIN,
     FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
     FIX_HPET_BASE,
-    FIX_KEXEC_BASE_0,
-    FIX_KEXEC_BASE_END = FIX_KEXEC_BASE_0 \
-      + ((KEXEC_XEN_NO_PAGES >> 1) * KEXEC_IMAGE_NR) - 1,
     FIX_TBOOT_SHARED_BASE,
     FIX_MSIX_IO_RESERV_BASE,
     FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGES -1,
xen/include/asm-x86/machine_kexec.h new file +16 -0
new file mode 100644
index 0000000..ba0d469
@@ -0,0 +1,16 @@
+#ifndef __X86_MACHINE_KEXEC_H__
+#define __X86_MACHINE_KEXEC_H__
+
+#define KEXEC_RELOC_FLAG_COMPAT 0x1 /* 32-bit image */
+
+#ifndef __ASSEMBLY__
+
+extern void kexec_reloc(unsigned long reloc_code, unsigned long reloc_pt,
+                        unsigned long ind_maddr, unsigned long entry_maddr,
+                        unsigned long flags);
+
+extern unsigned int kexec_reloc_size;
+
+#endif
+
+#endif /* __X86_MACHINE_KEXEC_H__ */
xen/include/xen/kexec.h +7 -9
index 1a5dda1..bd17747 100644
@@ -6,6 +6,7 @@
 #include <public/kexec.h>
 #include <asm/percpu.h>
 #include <xen/elfcore.h>
+#include <xen/kimage.h>
 
 typedef struct xen_kexec_reserve {
     unsigned long size;
@@ -40,11 +41,13 @@ extern enum low_crashinfo low_crashinfo_mode;
 extern paddr_t crashinfo_maxaddr_bits;
 void kexec_early_calculations(void);
 
-int machine_kexec_load(int type, int slot, xen_kexec_image_t *image);
-void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image);
+int machine_kexec_add_page(struct kexec_image *image, unsigned long vaddr,
+                           unsigned long maddr);
+int machine_kexec_load(struct kexec_image *image);
+void machine_kexec_unload(struct kexec_image *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
-void machine_reboot_kexec(xen_kexec_image_t *image);
-void machine_kexec(xen_kexec_image_t *image);
+void machine_reboot_kexec(struct kexec_image *image);
+void machine_kexec(struct kexec_image *image);
 void kexec_crash(void);
 void kexec_crash_save_cpu(void);
 crash_xen_info_t *kexec_crash_save_info(void);
@@ -52,11 +55,6 @@ void machine_crash_shutdown(void);
 int machine_kexec_get(xen_kexec_range_t *range);
 int machine_kexec_get_xen(xen_kexec_range_t *range);
 
-void compat_machine_kexec(unsigned long rnk,
-                          unsigned long indirection_page,
-                          unsigned long *page_list,
-                          unsigned long start_address);
-
 /* vmcoreinfo stuff */
 #define VMCOREINFO_BYTES           (4096)
 #define VMCOREINFO_NOTE_NAME       "VMCOREINFO_XEN"
xen/include/xen/kimage.h +6 -0
index 0ebd37a..d10ebf7 100644
@@ -47,6 +47,12 @@ int kimage_load_segments(struct kexec_image *image);
 struct page_info *kimage_alloc_control_page(struct kexec_image *image,
                                             unsigned memflags);
 
+kimage_entry_t *kimage_entry_next(kimage_entry_t *entry, bool_t compat);
+unsigned long kimage_entry_mfn(kimage_entry_t *entry, bool_t compat);
+unsigned long kimage_entry_ind(kimage_entry_t *entry, bool_t compat);
+int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn,
+                     bool_t compat);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __XEN_KIMAGE_H__ */
Signature · 1 line
1.7.2.5
#6 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 32 lines · David Vrabel

From: David Vrabel <[email protected]>

In the existing kexec hypercall, the load and unload ops depend on internals of the Linux kernel (the page list and code page provided by the kernel). The code page is used to transition between Xen context and the image so using kernel code doesn't make sense and will not work for PVH guests.

Add replacement KEXEC_CMD_kexec_load and KEXEC_CMD_kexec_unload ops that no longer require a code page to be provided by the guest -- Xen now provides the code for calling the image directly.

The new load op looks similar to the Linux kexec_load system call and allows the guest to provide the image data to be loaded. The guest specifies the architecture of the image which may be a 32-bit subarch of the hypervisor's architecture (i.e., an EM_386 image on an EM_X86_64 hypervisor).

The toolstack can now load images without kernel involvement. This is required for supporting kexec when using a dom0 with an upstream kernel.

Crash images are copied directly into the crash region on load. Default images are copied into domheap pages and a list of source and destination machine addresses is created. This is list is used in kexec_reloc() to relocate the image to its destination.

The old load and unload sub-ops are still available (as KEXEC_CMD_load_v1 and KEXEC_CMD_unload_v1) and are implemented on top of the new infrastructure.

[...]

Quoted 28 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +22 -0
new file mode 100644
index 0000000..41dd27b
@@ -0,0 +1,208 @@
+/*
+ * Relocate a kexec_image to its destination and call it.
+ *
+ * Copyright (C) 2013 Citrix Systems R&D Ltd.
+ *
+ * Portions derived from Linux's arch/x86/kernel/relocate_kernel_64.S.
+ *
+ *   Copyright (C) 2002-2005 Eric Biederman  <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+#include <xen/config.h>
+#include <xen/kimage.h>
+
+#include <asm/asm_defns.h>
+#include <asm/msr.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+        .text
+        .align PAGE_SIZE

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        .code64
+
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5 -0
+        /* Setup stack. */
+        leaq (reloc_stack - kexec_reloc)(%rdi), %rsp
+
+        /* Load reloc page table. */
+        movq %rsi, %cr3

xen/arch/x86/x86_64/kexec_reloc.S line 48

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+
+        /* Jump to identity mapped code. */
+        leaq (identity_mapped - kexec_reloc)(%rdi), %rax
+        jmpq *%rax
+
+identity_mapped:
+        pushq %rcx
+        pushq %rbx
+        pushq %rsi
+        pushq %rdi

Delete pushq %rbx, pushq %rsi, pushq %rdi

Quoted 12 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +12 -0
+        /*
+         * Set cr0 to a known state:
+         *  - Paging enabled
+         *  - Alignment check disabled
+         *  - Write protect disabled
+         *  - No task switch
+         *  - Don't do FP software emulation.
+         *  - Proctected mode enabled
+         */
+        movq    %cr0, %rax
+        andl    $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
+        orl     $(X86_CR0_PG | X86_CR0_PE), %eax

xen/arch/x86/x86_64/kexec_reloc.S line 71

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        movq    %rax, %cr0
+
+        /*
+         * Set cr4 to a known state:
+         *  - physical address extension enabled
+         */
+        movl    $X86_CR4_PAE, %eax
+        movq    %rax, %cr4
+
+        movq %rbx, %rdi

movq %rdx, %rdi

xen/arch/x86/x86_64/kexec_reloc.S line 77

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        call relocate_pages
+
+        popq %rdi
+        popq %rsi
+        popq %rbx
+        popq %rcx

Delete popq %rdi, popq %rsi, popq %rbx

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

xen/arch/x86/x86_64/kexec_reloc.S line 85

Quoted 1 line
xen/arch/x86/x86_64/kexec_reloc.S new file +1 -0
+        callq *%rcx

Maybe we should use retq to jump into image entry point. If not I think that we should store image entry point address in %rax (just to the order).

Quoted 82 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +82 -0
+        ud2
+
+call_32_bit:
+        /* Setup IDT. */
+        lidt compat_mode_idt(%rip)
+
+        /* Load compat GDT. */
+        leaq (compat_mode_gdt - kexec_reloc)(%rdi), %rax
+        movq %rax, (compat_mode_gdt_desc + 2)(%rip)
+        lgdt compat_mode_gdt_desc(%rip)
+
+        /* Relocate compatibility mode entry point address. */
+        leal (compatibility_mode - kexec_reloc)(%edi), %eax
+        movl %eax, compatibility_mode_far(%rip)
+
+        /* Enter compatibility mode. */
+        ljmp *compatibility_mode_far(%rip)
+
+relocate_pages:
+        /* %rdi - indirection page maddr */
+        cld
+        movq    %rdi, %rcx
+        xorl    %edi, %edi
+        xorl    %esi, %esi
+        jmp     is_dest
+
+next_entry: /* top, read another word for the indirection page */
+
+        movq    (%rbx), %rcx
+        addq    $8, %rbx
+is_dest:
+        testb   $IND_DESTINATION, %cl
+        jz      is_ind
+        movq    %rcx, %rdi
+        andq    $PAGE_MASK, %rdi
+        jmp     next_entry
+is_ind:
+        testb   $IND_INDIRECTION, %cl
+        jz      is_done
+        movq    %rcx, %rbx
+        andq    $PAGE_MASK, %rbx
+        jmp     next_entry
+is_done:
+        testb   $IND_DONE, %cl
+        jnz     done
+is_source:
+        testb   $IND_SOURCE, %cl
+        jz      is_zero
+        movq    %rcx, %rsi      /* For every source page do a copy */
+        andq    $PAGE_MASK, %rsi
+        movl    $(PAGE_SIZE / 8), %ecx
+        rep movsq
+        jmp     next_entry
+is_zero:
+        testb   $IND_ZERO, %cl
+        jz      next_entry
+        movl    $(PAGE_SIZE / 8), %ecx  /* Zero the destination page. */
+        xorl    %eax, %eax
+        rep stosq
+        jmp     next_entry
+done:
+        ret
+
+        .code32
+
+compatibility_mode:
+        /* Setup some sane segments. */
+        movl $0x0008, %eax
+        movl %eax, %ds
+        movl %eax, %es
+        movl %eax, %fs
+        movl %eax, %gs
+        movl %eax, %ss
+
+        movl %ecx, %ebp
+
+        /* Disable paging and therefore leave 64 bit mode. */
+        movl %cr0, %eax
+        andl $~X86_CR0_PG, %eax
+        movl %eax, %cr0
+
+        /* Disable long mode */

xen/arch/x86/x86_64/kexec_reloc.S line 177

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        movl    $MSR_EFER, %ecx
+        rdmsr
+        andl    $~EFER_LME, %eax
+        wrmsr
+
+        /* Clear cr4 to disable PAE. */
+        xorl    %eax, %eax
+        movl    %eax, %cr4
+
+        /* Call the image entry point.  This should never return. */

Ditto.

xen/arch/x86/x86_64/kexec_reloc.S line 178

Quoted 1 line
xen/arch/x86/x86_64/kexec_reloc.S new file +1 -0
+        call *%ebp

Ditto.

Daniel

#7 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 124 lines · Daniel Kiper
Quoted 32 lines · David Vrabel

From: David Vrabel <[email protected]>

In the existing kexec hypercall, the load and unload ops depend on internals of the Linux kernel (the page list and code page provided by the kernel). The code page is used to transition between Xen context and the image so using kernel code doesn't make sense and will not work for PVH guests.

Add replacement KEXEC_CMD_kexec_load and KEXEC_CMD_kexec_unload ops that no longer require a code page to be provided by the guest -- Xen now provides the code for calling the image directly.

The new load op looks similar to the Linux kexec_load system call and allows the guest to provide the image data to be loaded. The guest specifies the architecture of the image which may be a 32-bit subarch of the hypervisor's architecture (i.e., an EM_386 image on an EM_X86_64 hypervisor).

The toolstack can now load images without kernel involvement. This is required for supporting kexec when using a dom0 with an upstream kernel.

Crash images are copied directly into the crash region on load. Default images are copied into domheap pages and a list of source and destination machine addresses is created. This is list is used in kexec_reloc() to relocate the image to its destination.

The old load and unload sub-ops are still available (as KEXEC_CMD_load_v1 and KEXEC_CMD_unload_v1) and are implemented on top of the new infrastructure.

[...]

Quoted 28 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +22 -0
new file mode 100644
index 0000000..41dd27b
@@ -0,0 +1,208 @@
+/*
+ * Relocate a kexec_image to its destination and call it.
+ *
+ * Copyright (C) 2013 Citrix Systems R&D Ltd.
+ *
+ * Portions derived from Linux's arch/x86/kernel/relocate_kernel_64.S.
+ *
+ *   Copyright (C) 2002-2005 Eric Biederman  <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+#include <xen/config.h>
+#include <xen/kimage.h>
+
+#include <asm/asm_defns.h>
+#include <asm/msr.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+        .text
+        .align PAGE_SIZE

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        .code64
+
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5 -0
+        /* Setup stack. */
+        leaq (reloc_stack - kexec_reloc)(%rdi), %rsp
+
+        /* Load reloc page table. */
+        movq %rsi, %cr3

xen/arch/x86/x86_64/kexec_reloc.S line 48

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+
+        /* Jump to identity mapped code. */
+        leaq (identity_mapped - kexec_reloc)(%rdi), %rax
+        jmpq *%rax
+
+identity_mapped:
+        pushq %rcx
+        pushq %rbx
+        pushq %rsi
+        pushq %rdi

Delete pushq %rbx, pushq %rsi, pushq %rdi

Quoted 12 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +12 -0
+        /*
+         * Set cr0 to a known state:
+         *  - Paging enabled
+         *  - Alignment check disabled
+         *  - Write protect disabled
+         *  - No task switch
+         *  - Don't do FP software emulation.
+         *  - Proctected mode enabled
+         */
+        movq    %cr0, %rax
+        andl    $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
+        orl     $(X86_CR0_PG | X86_CR0_PE), %eax

xen/arch/x86/x86_64/kexec_reloc.S line 71

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        movq    %rax, %cr0
+
+        /*
+         * Set cr4 to a known state:
+         *  - physical address extension enabled
+         */
+        movl    $X86_CR4_PAE, %eax
+        movq    %rax, %cr4
+
+        movq %rbx, %rdi

movq %rdx, %rdi

xen/arch/x86/x86_64/kexec_reloc.S line 77

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        call relocate_pages
+
+        popq %rdi
+        popq %rsi
+        popq %rbx
+        popq %rcx

Delete popq %rdi, popq %rsi, popq %rbx

Quoted 11 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

In the kexec case, we are specifically trying to leak the state of the entire system outside of the crash area so something can investigate.

Zeroing the registers for the sake of it is pointless. Any author of kexec image expecting all GPRs to be 0 on entry deserves the debugging problems they are asking for.

Quoted 5 lines

xen/arch/x86/x86_64/kexec_reloc.S line 85

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +1 -0
+        callq *%rcx

Maybe we should use retq to jump into image entry point. If not I think that we should store image entry point address in %rax (just to the order).

retq with a zeroed %rsp ?

This code was derived from the linux code which allows a kexec image to pass parameters (which is also why the registers are pushed/poped above) and return back to the originator. (Although I have to admit to being curious to how someone would go about trying to justify using this feature in a real usecase.)

It might be reasonable to replace "callq *%rcx; ud2" with "jmp *%rcx", but all of this does feel like nitpicking on a codepath which (hopefully) will never be executed.

If we decide here and now that Xen shall never support passing arguments to the kexec image, and never support the kexec image returning back to us then perhaps we can go ahead and change things, although I would argue that consistency with the other implementation is more important.

~Andrew

#8 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 137 lines · Andrew Cooper
Quoted 124 lines · Daniel Kiper
Quoted 32 lines · David Vrabel

From: David Vrabel <[email protected]>

In the existing kexec hypercall, the load and unload ops depend on internals of the Linux kernel (the page list and code page provided by the kernel). The code page is used to transition between Xen context and the image so using kernel code doesn't make sense and will not work for PVH guests.

Add replacement KEXEC_CMD_kexec_load and KEXEC_CMD_kexec_unload ops that no longer require a code page to be provided by the guest -- Xen now provides the code for calling the image directly.

The new load op looks similar to the Linux kexec_load system call and allows the guest to provide the image data to be loaded. The guest specifies the architecture of the image which may be a 32-bit subarch of the hypervisor's architecture (i.e., an EM_386 image on an EM_X86_64 hypervisor).

The toolstack can now load images without kernel involvement. This is required for supporting kexec when using a dom0 with an upstream kernel.

Crash images are copied directly into the crash region on load. Default images are copied into domheap pages and a list of source and destination machine addresses is created. This is list is used in kexec_reloc() to relocate the image to its destination.

The old load and unload sub-ops are still available (as KEXEC_CMD_load_v1 and KEXEC_CMD_unload_v1) and are implemented on top of the new infrastructure.

[...]

Quoted 28 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +22 -0
new file mode 100644
index 0000000..41dd27b
@@ -0,0 +1,208 @@
+/*
+ * Relocate a kexec_image to its destination and call it.
+ *
+ * Copyright (C) 2013 Citrix Systems R&D Ltd.
+ *
+ * Portions derived from Linux's arch/x86/kernel/relocate_kernel_64.S.
+ *
+ *   Copyright (C) 2002-2005 Eric Biederman  <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+#include <xen/config.h>
+#include <xen/kimage.h>
+
+#include <asm/asm_defns.h>
+#include <asm/msr.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+        .text
+        .align PAGE_SIZE

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        .code64
+
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5 -0
+        /* Setup stack. */
+        leaq (reloc_stack - kexec_reloc)(%rdi), %rsp
+
+        /* Load reloc page table. */
+        movq %rsi, %cr3

xen/arch/x86/x86_64/kexec_reloc.S line 48

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+
+        /* Jump to identity mapped code. */
+        leaq (identity_mapped - kexec_reloc)(%rdi), %rax
+        jmpq *%rax
+
+identity_mapped:
+        pushq %rcx
+        pushq %rbx
+        pushq %rsi
+        pushq %rdi

Delete pushq %rbx, pushq %rsi, pushq %rdi

Quoted 12 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +12 -0
+        /*
+         * Set cr0 to a known state:
+         *  - Paging enabled
+         *  - Alignment check disabled
+         *  - Write protect disabled
+         *  - No task switch
+         *  - Don't do FP software emulation.
+         *  - Proctected mode enabled
+         */
+        movq    %cr0, %rax
+        andl    $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
+        orl     $(X86_CR0_PG | X86_CR0_PE), %eax

xen/arch/x86/x86_64/kexec_reloc.S line 71

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+        movq    %rax, %cr0
+
+        /*
+         * Set cr4 to a known state:
+         *  - physical address extension enabled
+         */
+        movl    $X86_CR4_PAE, %eax
+        movq    %rax, %cr4
+
+        movq %rbx, %rdi

movq %rdx, %rdi

xen/arch/x86/x86_64/kexec_reloc.S line 77

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        call relocate_pages
+
+        popq %rdi
+        popq %rsi
+        popq %rbx
+        popq %rcx

Delete popq %rdi, popq %rsi, popq %rbx

Quoted 11 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Quoted 2 lines

In the kexec case, we are specifically trying to leak the state of the entire system outside of the crash area so something can investigate.

You think about kdump which is different thing than kexec.

Quoted 3 lines

Zeroing the registers for the sake of it is pointless. Any author of kexec image expecting all GPRs to be 0 on entry deserves the debugging problems they are asking for.

I agree that anybody should not assume that any given register contains specific value in this case. However, we should not leak data (especially in kexec not kdump case) if we could wipe it at almost no cost. I know that memory contains more data but why we would like to make bad guys life easier?

Quoted 6 lines
Quoted 4 lines

xen/arch/x86/x86_64/kexec_reloc.S line 85

Quoted 1 line
xen/arch/x86/x86_64/kexec_reloc.S new file +1 -0
+        callq *%rcx

Maybe we should use retq to jump into image entry point. If not I think that we should store image entry point address in %rax (just to the order).

retq with a zeroed %rsp ?

I hope that you are joking here. I assume that everybody on this list knows which register should be set in each case.

Quoted 5 lines

This code was derived from the linux code which allows a kexec image to pass parameters (which is also why the registers are pushed/poped above) and return back to the originator. (Although I have to admit to being curious to how someone would go about trying to justify using this feature in a real usecase.)

Original Linux code uses ret not call.

Quoted 8 lines

It might be reasonable to replace "callq *%rcx; ud2" with "jmp *%rcx", but all of this does feel like nitpicking on a codepath which (hopefully) will never be executed.

If we decide here and now that Xen shall never support passing arguments to the kexec image, and never support the kexec image returning back to us then perhaps we can go ahead and change things, although I would argue that consistency with the other implementation is more important.

Right, so should we use ret? I do not insist on that. More important thing for me is zeroing of registers. Later stuff is also done in Linux Kernel.

Daniel

#9 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

We avoid using %rdx in case we need to re-add the UART debugging.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
Quoted 8 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +2 -0
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

Quoted 5 lines
Quoted 1 line

+ callq *%rcx

Maybe we should use retq to jump into image entry point. If not I think that we should store image entry point address in %rax (just to the order).

With call if an image does try to return it will fault at a well defined point (the following ud2) making the failure a bit easier to diagnose. With your suggestion it will fault somewhere random.

Linux uses call.

David

#10 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 17 lines · David Vrabel
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 1 line

We avoid using %rdx in case we need to re-add the UART debugging.

Does not make sens for me. We could re-add it also if we remove this movq. Now it is not clear why it is here. I think that it should be removed.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
Quoted 8 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +2 -0
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Quoted 2 lines

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Anybody who does this asks for problems. This is not our issue.

Quoted 2 lines

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

I am aware that this does not solve all security issues but it could make simple attacks more difficult. I think that it costs nothing. Linux does this. Why we could not do that?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

+ callq *%rcx

Maybe we should use retq to jump into image entry point. If not I think that we should store image entry point address in %rax (just to the order).

With call if an image does try to return it will fault at a well defined point (the following ud2) making the failure a bit easier to diagnose. With your suggestion it will fault somewhere random.

As I said I do not insist on changing that. I know why that you did this in that way. ret is just an option to consider. That is all.

Quoted 1 line

Linux uses call.

OK, to be precise in almost all cases it uses ret. It uses call if preserve context is enabled. However, I do not know who is using that feature (once someone considered even removal of this feature). So ret is main path to go to the new system image. Please check the sources.

Daniel

#11 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 18 lines · Daniel Kiper
Quoted 17 lines · David Vrabel
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 4 lines
Quoted 1 line

We avoid using %rdx in case we need to re-add the UART debugging.

Does not make sens for me. We could re-add it also if we remove this movq. Now it is not clear why it is here. I think that it should be removed.

outb uses %rdx so avoiding using %rdx means any UART debugging macros are trivial (since they don't have to save/restore the value in %rdx).

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Quoted 4 lines
Quoted 2 lines

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Anybody who does this asks for problems. This is not our issue.

Zeroing the registers makes that part of the ABI for calling images, which means it can never be changed. If the ABI is the register values are undefined then this can be changes in the future to something that is defined.

Quoted 5 lines
Quoted 2 lines

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

I am aware that this does not solve all security issues but it could make simple attacks more difficult.

What attacks? What security issues is zero-ing a tiny amount of state going to prevent when the exec'd image has full control over the whole host?

Your reasoning is completely bogus.

Quoted 6 lines
Quoted 1 line

Linux uses call.

OK, to be precise in almost all cases it uses ret. It uses call if preserve context is enabled. However, I do not know who is using that feature (once someone considered even removal of this feature). So ret is main path to go to the new system image. Please check the sources.

I missed that which means I've definitely not changing this from the obvious call.

David

#12 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 19 lines · David Vrabel
Quoted 18 lines · Daniel Kiper
Quoted 17 lines · David Vrabel
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

We avoid using %rdx in case we need to re-add the UART debugging.

Does not make sens for me. We could re-add it also if we remove this movq. Now it is not clear why it is here. I think that it should be removed.

outb uses %rdx so avoiding using %rdx means any UART debugging macros are trivial (since they don't have to save/restore the value in %rdx).

Once again, there is no UART code so there is no sens for this movq. Any smart developer (we have a dozens of them here) knows how to write relevant code. Now this movq only obfuscates things.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
Quoted 8 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +2 -0
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Quoted 6 lines
Quoted 1 line

Anybody who does this asks for problems. This is not our issue.

Zeroing the registers makes that part of the ABI for calling images, which means it can never be changed. If the ABI is the register values are undefined then this can be changes in the future to something that is defined.

I have never ever tried to define any ABI here. I have never ever said that the caller must pass this and the callee must expect that. There is no such definition in current Linux Kernel implementation too. Even purgatory expects nothing special in registers. I am just saying that it is worth to wipe data from GPRs. No more no less. If you would like to use any register to pass argument later you could do that. My proposal does not impose any limits.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

I am aware that this does not solve all security issues but it could make simple attacks more difficult.

What attacks? What security issues is zero-ing a tiny amount of state going to prevent when the exec'd image has full control over the whole host?

I said "more difficult" not "prevent" and it makes difference.

Daniel

#13 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 25 lines · Daniel Kiper
Quoted 24 lines · David Vrabel
Quoted 22 lines · Daniel Kiper
Quoted 17 lines · David Vrabel
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S line 32

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 1 line

We avoid using %rdx in case we need to re-add the UART debugging.

Does not make sens for me. We could re-add it also if we remove this movq. Now it is not clear why it is here. I think that it should be removed.

Quoted 6 lines
Quoted 2 lines

outb uses %rdx so avoiding using %rdx means any UART debugging macros are trivial (since they don't have to save/restore the value in %rdx).

Once again, there is no UART code so there is no sens for this movq. Any smart developer (we have a dozens of them here) knows how to write relevant code. Now this movq only obfuscates things.

As a smart engineer I know I would much prefer to drop in debugging code with minimal (risky) changes to existing code.

That said, I now have access to an ICE so I don't much care about debugging with a UART so I'll make the suggested change.

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
Quoted 8 lines

xen/arch/x86/x86_64/kexec_reloc.S line 84

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +2 -0
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Quoted 6 lines
Quoted 1 line

Anybody who does this asks for problems. This is not our issue.

Zeroing the registers makes that part of the ABI for calling images, which means it can never be changed. If the ABI is the register values are undefined then this can be changes in the future to something that is defined.

Quoted 6 lines

I have never ever tried to define any ABI here. I have never ever said that the caller must pass this and the callee must expect that. There is no such definition in current Linux Kernel implementation too. Even purgatory expects nothing special in registers. I am just saying that it is worth to wipe data from GPRs. No more no less. If you would like to use any register to pass argument later you could do that. My proposal does not impose any limits.

There's an explicit ABI and an implicit one based on the implementation.
In the absence of a formal test suite and certification program,
implicit ABI are often just as fixed and constraining as explicit ones.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

I am aware that this does not solve all security issues but it could make simple attacks more difficult.

What attacks? What security issues is zero-ing a tiny amount of state going to prevent when the exec'd image has full control over the whole host?

I said "more difficult" not "prevent" and it makes difference.

You didn't actually answer my question. What security issue do you think zeroing registers will mitigate? Given that the exec'd image has full control over the host, access to all memory and all devices.

Lipstick on one pig in a whole herd of pigs comes to mind...

David

#14 lore raw

Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops

Quoted 33 lines · David Vrabel
Quoted 25 lines · Daniel Kiper
Quoted 24 lines · David Vrabel
Quoted 22 lines · Daniel Kiper
Quoted 17 lines · David Vrabel
Quoted 4 lines · Daniel Kiper
Quoted 3 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +0 -0
@@ -0,0 +1,208 @@

[...]

Quoted 10 lines

xen/arch/x86/x86_64/kexec_reloc.S

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+ENTRY(kexec_reloc)
+        /* %rdi - code page maddr */
+        /* %rsi - page table maddr */
+        /* %rdx - indirection page maddr */
+        /* %rcx - entry maddr */
+        /* %r8 - flags */
+
+        movq %rdx, %rbx

Delete movq %rdx, %rbx

Quoted 1 line

We avoid using %rdx in case we need to re-add the UART debugging.

Does not make sens for me. We could re-add it also if we remove this movq. Now it is not clear why it is here. I think that it should be removed.

Quoted 6 lines
Quoted 2 lines

outb uses %rdx so avoiding using %rdx means any UART debugging macros are trivial (since they don't have to save/restore the value in %rdx).

Once again, there is no UART code so there is no sens for this movq. Any smart developer (we have a dozens of them here) knows how to write relevant code. Now this movq only obfuscates things.

Quoted 5 lines

As a smart engineer I know I would much prefer to drop in debugging code with minimal (risky) changes to existing code.

That said, I now have access to an ICE so I don't much care about debugging with a UART so I'll make the suggested change.

Still I am not convinced. This way you could add similar redundant stuff in every piece of code, just in case, and finaly make it unreadable. Does not make sens for me. Please remove this redundant movq or add UART code or add relevant comment which explains why do you do that this way. 1 and 2 makes sens for me. 3 much less or at all.

Quoted 30 lines
Quoted 23 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit
+
Quoted 8 lines

xen/arch/x86/x86_64/kexec_reloc.S

Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +2 -0
+call_64_bit:
+        /* Call the image entry point.  This should never return. */

I think that all general purpose registers (including %rsi, %rdi, %rbp and %rsp) should be zeroed here. We should leave as little as possible info about previous system. Especially in kexec case. Just in case. Please look into linux/arch/x86/kernel/relocate_kernel_64.S for more details.

Not initializing the registers is a deliberate design decision so exec'd images cannot mistakenly rely on the register values.

Quoted 6 lines
Quoted 1 line

Anybody who does this asks for problems. This is not our issue.

Zeroing the registers makes that part of the ABI for calling images, which means it can never be changed. If the ABI is the register values are undefined then this can be changes in the future to something that is defined.

Quoted 6 lines

I have never ever tried to define any ABI here. I have never ever said that the caller must pass this and the callee must expect that. There is no such definition in current Linux Kernel implementation too. Even purgatory expects nothing special in registers. I am just saying that it is worth to wipe data from GPRs. No more no less. If you would like to use any register to pass argument later you could do that. My proposal does not impose any limits.

Quoted 3 lines

There's an explicit ABI and an implicit one based on the implementation.
In the absence of a formal test suite and certification program,
implicit ABI are often just as fixed and constraining as explicit ones.

Could you tell me where do you see an ABI here?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Clearing a handful of words when all of host memory is accessible by the exec'd image does nothing for security (as you suggest in a later email).

I am aware that this does not solve all security issues but it could make simple attacks more difficult.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What attacks? What security issues is zero-ing a tiny amount of state going to prevent when the exec'd image has full control over the whole host?

I said "more difficult" not "prevent" and it makes difference.

You didn't actually answer my question. What security issue do you think zeroing registers will mitigate? Given that the exec'd image has full control over the host, access to all memory and all devices.

I am able to imagine a situation in which some registers values could tell you how to put all interesting pieces together from somewhere. Without them it could be difficult or even impossible in some cases. It is difficult to point out a specific example now due to complexity of Xen itself and other involved stuff. However, I belive that there are smart guys in the wild with sufficient time and money to find some (sooner or later). Why we would like to make their live easier? Few extra instructions cost us nothing. For them this could be or not to be.

Quoted 1 line

Lipstick on one pig in a whole herd of pigs comes to mind...

I have never stated that this solve all security issues. However, this way maybe we could avoid some problems in the future.

Daniel

#15 lore raw

PATCH v8 5/9 xen: kexec crash image when dom0 crashes

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/kexec.c    |    2 ++
 xen/common/shutdown.c |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
xen/common/kexec.c +2 -0
index 5548c37..fe0424e 100644
@@ -307,6 +307,8 @@ void kexec_crash(void)
     if ( !test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
         return;
 
+    printk("Executing crash image\n");
+
     kexecing = TRUE;
 
     kexec_common_shutdown();
xen/common/shutdown.c +3 -0
index 20f04b0..9bccd34 100644
@@ -47,6 +47,9 @@ void dom0_shutdown(u8 reason)
     {
         debugger_trap_immediate();
         printk("Domain 0 crashed: ");
+#ifdef CONFIG_KEXEC
+        kexec_crash();
+#endif
         maybe_reboot();
         break; /* not reached */
     }
Signature · 1 line
1.7.2.5
#16 lore raw

PATCH v8 6/9 libxc: add hypercall buffer arrays

In reply to David Vrabel

From: David Vrabel <[email protected]>

Hypercall buffer arrays are used when a hypercall takes a variable length array of buffers.

---
 tools/libxc/xc_hcall_buf.c |   73 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h      |   27 ++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
tools/libxc/xc_hcall_buf.c +73 -0
index c354677..e762a93 100644
@@ -228,6 +228,79 @@ void xc__hypercall_bounce_post(xc_interface *xch, xc_hypercall_buffer_t *b)
     xc__hypercall_buffer_free(xch, b);
 }
 
+struct xc_hypercall_buffer_array {
+    unsigned max_bufs;
+    xc_hypercall_buffer_t *bufs;
+};
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch,
+                                                              unsigned n)
+{
+    xc_hypercall_buffer_array_t *array;
+    xc_hypercall_buffer_t *bufs = NULL;
+
+    array = malloc(sizeof(*array));
+    if ( array == NULL )
+        goto error;
+
+    bufs = calloc(n, sizeof(*bufs));
+    if ( bufs == NULL )
+        goto error;
+
+    array->max_bufs = n;
+    array->bufs     = bufs;
+
+    return array;
+
+error:
+    free(bufs);
+    free(array);
+    return NULL;
+}
+
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch,
+                                       xc_hypercall_buffer_array_t *array,
+                                       unsigned index,
+                                       xc_hypercall_buffer_t *hbuf,
+                                       size_t size)
+{
+    void *buf;
+
+    if ( index >= array->max_bufs || array->bufs[index].hbuf )
+        abort();
+
+    buf = xc__hypercall_buffer_alloc(xch, hbuf, size);
+    if ( buf )
+        array->bufs[index] = *hbuf;
+    return buf;
+}
+
+void *xc__hypercall_buffer_array_get(xc_interface *xch,
+                                     xc_hypercall_buffer_array_t *array,
+                                     unsigned index,
+                                     xc_hypercall_buffer_t *hbuf)
+{
+    if ( index >= array->max_bufs || array->bufs[index].hbuf == NULL )
+        abort();
+
+    *hbuf = array->bufs[index];
+    return array->bufs[index].hbuf;
+}
+
+void xc_hypercall_buffer_array_destroy(xc_interface *xc,
+                                       xc_hypercall_buffer_array_t *array)
+{
+    unsigned i;
+
+    if ( array == NULL )
+        return;
+
+    for (i = 0; i < array->max_bufs; i++ )
+        xc__hypercall_buffer_free(xc, &array->bufs[i]);
+    free(array->bufs);
+    free(array);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +27 -0
index 58d51f3..1119943 100644
@@ -321,6 +321,33 @@ void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b
 #define xc_hypercall_buffer_free_pages(_xch, _name, _nr) xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name), _nr)
 
 /*
+ * Array of hypercall buffers.
+ *
+ * Create an array with xc_hypercall_buffer_array_create() and
+ * populate it by declaring one hypercall buffer in a loop and
+ * allocating the buffer with xc_hypercall_buffer_array_alloc().
+ *
+ * To access a previously allocated buffers, declare a new hypercall
+ * buffer and call xc_hypercall_buffer_array_get().
+ *
+ * Destroy the array with xc_hypercall_buffer_array_destroy() to free
+ * the array and all its alocated hypercall buffers.
+ */
+struct xc_hypercall_buffer_array;
+typedef struct xc_hypercall_buffer_array xc_hypercall_buffer_array_t;
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch, unsigned n);
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                       unsigned index, xc_hypercall_buffer_t *hbuf, size_t size);
+#define xc_hypercall_buffer_array_alloc(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_alloc(_xch, _array, _index, HYPERCALL_BUFFER(_name), _size)
+void *xc__hypercall_buffer_array_get(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                     unsigned index, xc_hypercall_buffer_t *hbuf);
+#define xc_hypercall_buffer_array_get(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_get(_xch, _array, _index, HYPERCALL_BUFFER(_name))
+void xc_hypercall_buffer_array_destroy(xc_interface *xc, xc_hypercall_buffer_array_t *array);
+
+/*
  * CPUMAP handling
  */
 typedef uint8_t *xc_cpumap_t;
Signature · 1 line
1.7.2.5
#17 lore raw

PATCH v8 7/9 libxc: add API for kexec hypercall

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add xc_kexec_exec(), xc_kexec_get_ranges(), xc_kexec_load(), and xc_kexec_unload(). The load and unload calls require the v2 load and unload ops.

---
 tools/libxc/Makefile   |    1 +
 tools/libxc/xc_kexec.c |  140 ++++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h  |   55 +++++++++++++++++++
 3 files changed, 196 insertions(+), 0 deletions(-)
 create mode 100644 tools/libxc/xc_kexec.c
tools/libxc/Makefile +1 -0
index 512a994..528198e 100644
@@ -31,6 +31,7 @@ CTRL_SRCS-y       += xc_mem_access.c
 CTRL_SRCS-y       += xc_memshr.c
 CTRL_SRCS-y       += xc_hcall_buf.c
 CTRL_SRCS-y       += xc_foreign_memory.c
+CTRL_SRCS-y       += xc_kexec.c
 CTRL_SRCS-y       += xtl_core.c
 CTRL_SRCS-y       += xtl_logger_stdio.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
tools/libxc/xc_kexec.c new file +140 -0

140 lines not on this page · raw message

tools/libxc/xenctrl.h +55 -0

65 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#18 lore raw

PATCH v8 8/9 x86: check kexec relocation code fits in a page

In reply to David Vrabel

From: David Vrabel <[email protected]>

The kexec relocation (control) code must fit in a single page so add a link time check for this.

---
 xen/arch/x86/xen.lds.S |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
xen/arch/x86/xen.lds.S +2 -0
index 9600cdf..17db361 100644
@@ -198,3 +198,5 @@ SECTIONS
   .stab.indexstr 0 : { *(.stab.indexstr) }
   .comment 0 : { *(.comment) }
 }
+
+ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large")
Signature · 1 line
1.7.2.5
#19 lore raw

PATCH v8 9/9 MAINTAINERS: Add KEXEC maintainer

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 MAINTAINERS |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
index adacac2..4aac28c 100644
@@ -197,6 +197,14 @@ X:	xen/drivers/passthrough/amd/
 X:	xen/drivers/passthrough/vtd/
 F:	xen/include/xen/iommu.h
 
+KEXEC
+M:      David Vrabel <[email protected]>
+S:      Supported
+F:      xen/common/{kexec,kimage}.c
+F:      xen/include/{kexec,kimage}.h
+F:      xen/arch/x86/machine_kexec.c
+F:      xen/arch/x86/x86_64/kexec_reloc.S
+
 LINUX (PV_OPS)
 M:	Konrad Rzeszutek Wilk <[email protected]>
 S:	Supported
Signature · 1 line
1.7.2.5
#20 lore raw
In reply to David Vrabel
Quoted 4 lines · David Vrabel

The series (for Xen 4.4) improves the kexec hypercall by making Xen responsible for loading and relocating the image. This allows kexec to be usable by pv-ops kernels and should allow kexec to be usable from a HVM or PVH privileged domain.

Currently I am on holiday. I will do final review
and test at the beginning of October.

Daniel

#21 lore raw
Quoted 8 lines · Daniel Kiper
Quoted 4 lines · David Vrabel

The series (for Xen 4.4) improves the kexec hypercall by making Xen responsible for loading and relocating the image. This allows kexec to be usable by pv-ops kernels and should allow kexec to be usable from a HVM or PVH privileged domain.

Currently I am on holiday. I will do final review
and test at the beginning of October.

Ping?

David

#22 lore raw
In reply to David Vrabel
Quoted 4 lines · David Vrabel

The series (for Xen 4.4) improves the kexec hypercall by making Xen responsible for loading and relocating the image. This allows kexec to be usable by pv-ops kernels and should allow kexec to be usable from a HVM or PVH privileged domain.

Please repost both patch series because kexec list address is incorrect. It should be [email protected].

Daniel

#23 lore raw
In reply to David Vrabel
Quoted 4 lines · David Vrabel

The series (for Xen 4.4) improves the kexec hypercall by making Xen responsible for loading and relocating the image. This allows kexec to be usable by pv-ops kernels and should allow kexec to be usable from a HVM or PVH privileged domain.

[...]

I am back. I have reviewed latest patch series. There are some minor issues which should be fixed before patches will be applied to Xen unstable. Please take also into account Jan's and Konrad's comments. Do not forget to respost to correct kexec list address ([email protected]).

You could add Reviewed-by: Daniel Kiper <[email protected]> to kexec-tools patch series.

Daniel