Skip to contentSkip to conversation

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

PATCH Superseded David Vrabel 3 participants 34 messages Apr 8, 2013 – Apr 16, 2013

Subsystems (2)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

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

The series 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.

The second patch allows hypercall structures to be ABI compatible between 32- and 64-bit guests (by reusing stuff present for domctls and sysctls). This seems better than having to keep adding compat handling for new hypercalls etc.

Patch 3 introduces the new ABI.

Patch 4 and 5 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 6 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 7 and 8 add the libxc API for the kexec calls. These have been acked-by Ian Campbell already.

The required patch series for kexec-tools will be posted shortly.

Changes since v2:

- 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 v3 1/8 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 97ab5d3..f13ba93 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 d026d78..2eefcf4 100644
@@ -71,6 +71,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

Re: [PATCH 1/8] x86: give FIX_EFI_MPF its own fixmap entry

Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel

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

To be honest, no matter how small the wastage, I'd prefer reusing another entry over creating a new one. FIX_TBOOT_MAP_ADDRESS seems like a reasonable fit (which we also don't have to expect to go away, unless tboot support would get ripped out altogether). This is not the least because sane UEFI systems aren't expected to have MPS tables anyway (i.e. the entry, if separate, would likely _never_ be used in reality), it's just that the specification allows for it.

Jan

#3 lore raw

Re: [Xen-devel] [PATCH 1/8] x86: give FIX_EFI_MPF its own fixmap entry

In reply to David Vrabel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel

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

To be honest, no matter how small the wastage, I'd prefer reusing another entry over creating a new one. FIX_TBOOT_MAP_ADDRESS seems like a reasonable fit (which we also don't have to expect to go away, unless tboot support would get ripped out altogether). This is not the least because sane UEFI systems aren't expected to have MPS tables anyway (i.e. the entry, if separate, would likely _never_ be used in reality), it's just that the specification allows for it.

Jan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

Re: [PATCH 1/8] x86: give FIX_EFI_MPF its own fixmap entry

Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel

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

Quoted 8 lines

To be honest, no matter how small the wastage, I'd prefer reusing another entry over creating a new one. FIX_TBOOT_MAP_ADDRESS seems like a reasonable fit (which we also don't have to expect to go away, unless tboot support would get ripped out altogether). This is not the least because sane UEFI systems aren't expected to have MPS tables anyway (i.e. the entry, if separate, would likely _never_ be used in reality), it's just that the specification allows for it.

This patch added one entry and patch 5 removes 68 entries so this series is a big gain as is. It doesn't seem productive to further improve this at this time.

David

#5 lore raw

Re: [Xen-devel] [PATCH 1/8] x86: give FIX_EFI_MPF its own fixmap entry

In reply to Jan Beulich
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel

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

Quoted 8 lines

To be honest, no matter how small the wastage, I'd prefer reusing another entry over creating a new one. FIX_TBOOT_MAP_ADDRESS seems like a reasonable fit (which we also don't have to expect to go away, unless tboot support would get ripped out altogether). This is not the least because sane UEFI systems aren't expected to have MPS tables anyway (i.e. the entry, if separate, would likely _never_ be used in reality), it's just that the specification allows for it.

This patch added one entry and patch 5 removes 68 entries so this series is a big gain as is. It doesn't seem productive to further improve this at this time.

David

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

PATCH v3 2/8 xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere

In reply to David Vrabel

From: David Vrabel <[email protected]>

GUEST_HANDLE_64() and uint64_aligned_t allow hypercall ABI structures to be identical (binary compatible) for 32 and 64-bit guests. They are currently limited to only being available for use in sysctls and domctls. Relax this limit so it may be used by any new structures.

There is a minimal cost for 32-bit guests on 64-but hypervisors as set_guest_handle() needs to 0 the whole field on GUEST_HANDLE_64() handles, but this is expected to be less than the overhead of having to translate compat structures.

---
 xen/include/public/arch-x86/xen-x86_32.h |    4 +---
 xen/include/public/xen.h                 |   13 ++++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)
xen/include/public/arch-x86/xen-x86_32.h +1 -3
index 1504191..f6b4f49 100644
@@ -91,8 +91,7 @@
 #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
 #endif
 
-/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
-#if defined(__XEN__) || defined(__XEN_TOOLS__)
+/* 32-/64-bit invariability. */
 #undef ___DEFINE_XEN_GUEST_HANDLE
 #define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
     typedef struct { type *p; }                                 \
@@ -107,7 +106,6 @@
 #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
 #define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
 #define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
-#endif
 
 #ifndef __ASSEMBLY__
 
xen/include/public/xen.h +8 -5
index e9431e2..af421a2 100644
@@ -840,9 +840,14 @@ __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
 
 #endif /* !__ASSEMBLY__ */
 
-/* Default definitions for macros used by domctl/sysctl. */
-#if defined(__XEN__) || defined(__XEN_TOOLS__)
-
+/*
+ * Default definitions for 32/64-bit invariant macros.
+ *
+ * Use these in ABI structures that should be identical for 32 and
+ * 64-bit guests. There is some (very small) overhead in using
+ * XEN_GUEST_HANDLE_64() instead of XEN_GUEST_HANDLE() so avoid for
+ * very hot paths.
+ */
 #ifndef uint64_aligned_t
 #define uint64_aligned_t uint64_t
 #endif
@@ -857,8 +862,6 @@ struct xenctl_cpumap {
 };
 #endif
 
-#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
-
 #endif /* __XEN_PUBLIC_XEN_H__ */
 
 /*
Signature · 1 line
1.7.2.5
#7 lore raw

PATCH v3 3/8 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.

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

---
 xen/common/kexec.c         |   12 ++++----
 xen/include/public/kexec.h |   65 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 67 insertions(+), 10 deletions(-)
xen/common/kexec.c +6 -6
index 7b04c1c..f2bda59 100644
@@ -733,7 +733,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;
@@ -780,7 +780,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;
@@ -792,8 +792,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;
@@ -865,8 +865,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 +61 -4

79 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#8 lore raw

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

Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

Quoted 8 lines
xen/include/public/kexec.h +8 -0
+} xen_kexec_segment_t;
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_segment_t);
+
+/*
+ * Load a kexec image into memory.
+ *
+ * For KEXEC_TYPE_DEFAULT images, the segments may be anywhere in RAM.
+ * The image is relocated prior to being executed.

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 182

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+ *
+ * For KEXEC_TYPE_CRASH images, each segment of the image must reside
+ * in the memory region reserved for kexec (KEXEC_RANGE_MA_CRASH) and
+ * the entry point must be within the image. The caller is responsible
+ * for ensuring that multiple images do not overlap.
+ */
+
+#define KEXEC_CMD_kexec_load 4
+typedef struct xen_kexec_load {
+    uint8_t  type;        /* One of KEXEC_TYPE_* */

Explicit padding please.

Quoted 16 lines
xen/include/public/kexec.h +16 -0
+    uint16_t arch;        /* ELF machine type (EM_*). */
+    uint32_t nr_segments;
+    XEN_GUEST_HANDLE_64(xen_kexec_segment_t) segments;
+    uint64_t entry_maddr; /* image entry point machine address. */
+} xen_kexec_load_t;
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_load_t);
+
+/*
+ * Unload a kexec image.
+ *
+ * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
+ */
+#define KEXEC_CMD_kexec_unload 5
+typedef struct xen_kexec_unload {
+    uint8_t type;
+} xen_kexec_unload_t;

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 208

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t);
+
+#else /* __XEN_INTERFACE_VERSION__ < 0x00040300 */
+
+#define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1
+#define KEXEC_CMD_kexec_unload KEXEC_CMD_kexec_unload_v1
+typedef struct xen_kexec_load {
+    int type;
+    xen_kexec_image_t image;
+} xen_kexec_load_t;

I don't really like this duplication, but I admit that the alternatives I can think of aren't much better either.

Jan

#9 lore raw

Re: [Xen-devel] [PATCH 3/8] kexec: add public interface for improved load/unload sub-ops

In reply to David Vrabel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

Quoted 8 lines
xen/include/public/kexec.h +8 -0
+} xen_kexec_segment_t;
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_segment_t);
+
+/*
+ * Load a kexec image into memory.
+ *
+ * For KEXEC_TYPE_DEFAULT images, the segments may be anywhere in RAM.
+ * The image is relocated prior to being executed.

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 182

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+ *
+ * For KEXEC_TYPE_CRASH images, each segment of the image must reside
+ * in the memory region reserved for kexec (KEXEC_RANGE_MA_CRASH) and
+ * the entry point must be within the image. The caller is responsible
+ * for ensuring that multiple images do not overlap.
+ */
+
+#define KEXEC_CMD_kexec_load 4
+typedef struct xen_kexec_load {
+    uint8_t  type;        /* One of KEXEC_TYPE_* */

Explicit padding please.

Quoted 16 lines
xen/include/public/kexec.h +16 -0
+    uint16_t arch;        /* ELF machine type (EM_*). */
+    uint32_t nr_segments;
+    XEN_GUEST_HANDLE_64(xen_kexec_segment_t) segments;
+    uint64_t entry_maddr; /* image entry point machine address. */
+} xen_kexec_load_t;
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_load_t);
+
+/*
+ * Unload a kexec image.
+ *
+ * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
+ */
+#define KEXEC_CMD_kexec_unload 5
+typedef struct xen_kexec_unload {
+    uint8_t type;
+} xen_kexec_unload_t;

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 208

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t);
+
+#else /* __XEN_INTERFACE_VERSION__ < 0x00040300 */
+
+#define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1
+#define KEXEC_CMD_kexec_unload KEXEC_CMD_kexec_unload_v1
+typedef struct xen_kexec_load {
+    int type;
+    xen_kexec_image_t image;
+} xen_kexec_load_t;

I don't really like this duplication, but I admit that the alternatives I can think of aren't much better either.

Jan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#10 lore raw

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

Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 
Quoted 13 lines

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

It's not needed here. Should I use uint64_aligned_t anyway?

It was easier to make both XEN_GUEST_HANDLE_64() and uint64_aligned_t available than to make only one.

David

#11 lore raw

Re: [Xen-devel] [PATCH 3/8] kexec: add public interface for improved load/unload sub-ops

In reply to Jan Beulich
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 
Quoted 13 lines

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

It's not needed here. Should I use uint64_aligned_t anyway?

It was easier to make both XEN_GUEST_HANDLE_64() and uint64_aligned_t available than to make only one.

David

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#12 lore raw

Re: [Xen-devel] [PATCH 3/8] kexec: add public interface for improved load/unload sub-ops

Quoted 21 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 
Quoted 13 lines

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

Quoted 4 lines

It's not needed here. Should I use uint64_aligned_t anyway?

It was easier to make both XEN_GUEST_HANDLE_64() and uint64_aligned_t available than to make only one.

Ah, okay. And now that I think about it again, perhaps the less extensions we need to use, the better. So I guess it's fine to keep things the way they are in this regard.

Jan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#13 lore raw

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

In reply to David Vrabel
Quoted 21 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +0 -0
@@ -152,6 +152,63 @@ typedef struct xen_kexec_range {
     unsigned long start;
 } xen_kexec_range_t;
 
Quoted 13 lines

xen/include/public/kexec.h typedef struct xen_kexec_range { · line 164

Quoted 10 lines
xen/include/public/kexec.h +10 -0
+#if __XEN_INTERFACE_VERSION__ >= 0x00040300
+/*
+ * A contiguous chunk of a kexec image and it's destination machine
+ * address.
+ */
+typedef struct xen_kexec_segment {
+    XEN_GUEST_HANDLE_64(const_void) buf;
+    uint64_t buf_size;
+    uint64_t dest_maddr;
+    uint64_t dest_size;

So you made uint64_aligned_t available in the previous patch, but now you don't use it?

Quoted 4 lines

It's not needed here. Should I use uint64_aligned_t anyway?

It was easier to make both XEN_GUEST_HANDLE_64() and uint64_aligned_t available than to make only one.

Ah, okay. And now that I think about it again, perhaps the less extensions we need to use, the better. So I guess it's fine to keep things the way they are in this regard.

Jan

#14 lore raw

PATCH v3 4/8 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      |  842 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/kimage.h |   63 ++++
 3 files changed, 906 insertions(+), 0 deletions(-)
 create mode 100644 xen/common/kimage.c
 create mode 100644 xen/include/xen/kimage.h
xen/common/Makefile +1 -0
index 8a0c506..1d12775 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 +842 -0

842 lines not on this page · raw message

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

63 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#15 lore raw

Re: [PATCH 4/8] kexec: add infrastructure for handling kexec images

Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

Quoted 1 line

+ struct page_list_head unuseable_pages;

unusable_pages.

Also there appear to be a few hard tabs here and there.

Jan

#16 lore raw

Re: [Xen-devel] [PATCH 4/8] kexec: add infrastructure for handling kexec images

In reply to David Vrabel
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

Quoted 1 line

+ struct page_list_head unuseable_pages;

unusable_pages.

Also there appear to be a few hard tabs here and there.

Jan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#17 lore raw

Re: [PATCH 4/8] kexec: add infrastructure for handling kexec images

Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

I will make this change but it isn't clear to me why this isn't portable.

David

#18 lore raw

Re: [Xen-devel] [PATCH 4/8] kexec: add infrastructure for handling kexec images

In reply to Jan Beulich
Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

I will make this change but it isn't clear to me why this isn't portable.

David

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#19 lore raw

Re: [PATCH 4/8] kexec: add infrastructure for handling kexec images

Quoted 10 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

I will make this change but it isn't clear to me why this isn't portable.

Because left shifting an unsigned long may shift out significant bits, namely on 32-bit architectures (and the code here is - iirc - living under xen/common/).

Jan

#20 lore raw

Re: [Xen-devel] [PATCH 4/8] kexec: add infrastructure for handling kexec images

In reply to David Vrabel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 6 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ ret = kimage_add_page(image, page_to_mfn(page) << PAGE_SHIFT);

Constructs like this aren't portable. You ought to use page_to_maddr(), and have the called function have paddr_t instead of unsigned long as the respective parameter.

I will make this change but it isn't clear to me why this isn't portable.

Because left shifting an unsigned long may shift out significant bits, namely on 32-bit architectures (and the code here is - iirc - living under xen/common/).

Jan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#21 lore raw

PATCH v3 5/8 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        |  282 +++++++++++++++++++------
 xen/arch/x86/x86_64/Makefile        |    2 +-
 xen/arch/x86/x86_64/compat_kexec.S  |  187 ----------------
 xen/arch/x86/x86_64/kexec_reloc.S   |  215 +++++++++++++++++++
 xen/common/kexec.c                  |  397 +++++++++++++++++++++++++++++------
 xen/common/kimage.c                 |   78 +++++++
 xen/include/asm-x86/fixmap.h        |    3 -
 xen/include/asm-x86/machine_kexec.h |   14 ++
 xen/include/xen/kexec.h             |   14 +-
 xen/include/xen/kimage.h            |    6 +
 10 files changed, 866 insertions(+), 332 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 +212 -70
index 68b9705..e6c34c5 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,216 @@
 #include <xen/guest_access.h>
 #include <asm/fixmap.h>
 #include <asm/hpet.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+static void init_level2_page(l2_pgentry_t *l2, unsigned long addr)
+{
+    unsigned long end_addr;
+
+    addr &= PAGE_MASK;
+    end_addr = addr + L2_PAGETABLE_ENTRIES * (1ul << L2_PAGETABLE_SHIFT);
 
-typedef void (*relocate_new_kernel_t)(
-                unsigned long indirection_page,
-                unsigned long *page_list,
-                unsigned long start_address,
-                unsigned int preserve_context);
+    while ( addr < end_addr )
+    {
+        l2e_write(l2++, l2e_from_paddr(addr, __PAGE_HYPERVISOR | _PAGE_PSE));
 
-int machine_kexec_load(int type, int slot, xen_kexec_image_t *image)
+        addr += 1ul << L2_PAGETABLE_SHIFT;
+    }
+}
+
+static int init_level3_page(struct kexec_image *image, l3_pgentry_t *l3,
+                            unsigned long addr, unsigned long last_addr)
 {
-    unsigned long prev_ma = 0;
-    int fix_base = FIX_KEXEC_BASE_0 + (slot * (KEXEC_XEN_NO_PAGES >> 1));
-    int k;
+    unsigned long end_addr;
 
-    /* setup fixmap to point to our pages and record the virtual address
-     * in every odd index in page_list[].
-     */
+    addr &= PAGE_MASK;
+    end_addr = addr + L3_PAGETABLE_ENTRIES * (1ul << L3_PAGETABLE_SHIFT);
 
-    for ( k = 0; k < KEXEC_XEN_NO_PAGES; k++ )
+    while( (addr < last_addr) && (addr < end_addr) )
     {
-        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));
-            }
-        }
+        struct page_info *l2_page;
+        l2_pgentry_t *l2;
+
+        l2_page = kimage_alloc_control_page(image, 0);
+        if ( !l2_page )
+            return -ENOMEM;
+        l2 = __map_domain_page(l2_page);
+        init_level2_page(l2, addr);
+        unmap_domain_page(l2);
+
+        l3e_write(l3++, l3e_from_page(l2_page, __PAGE_HYPERVISOR));
+
+        addr += 1ul << L3_PAGETABLE_SHIFT;
     }
 
     return 0;
 }
 
-void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image)
+/*
+ * Build a complete page table to identity map [addr, last_addr).
+ *
+ * Control pages are used so they do not overlap with the image source
+ * or destination.
+ */
+static int init_level4_page(struct kexec_image *image, l4_pgentry_t *l4,
+                            unsigned long addr, unsigned long last_addr)
 {
+    unsigned long end_addr;
+    int result;
+
+    addr &= PAGE_MASK;
+    end_addr = addr + L4_PAGETABLE_ENTRIES * (1ul << L4_PAGETABLE_SHIFT);
+
+    while ( (addr < last_addr) && (addr < end_addr) )
+    {
+        struct page_info *l3_page;
+        l3_pgentry_t *l3;
+
+        l3_page = kimage_alloc_control_page(image, 0);
+        if ( !l3_page )
+            return -ENOMEM;
+        l3 = __map_domain_page(l3_page);
+        result = init_level3_page(image, l3, addr, last_addr);
+        unmap_domain_page(l3);
+        if (result)
+            return result;
+
+        l4e_write(l4++, l4e_from_page(l3_page, __PAGE_HYPERVISOR));
+
+        addr += 1ul << L4_PAGETABLE_SHIFT;
+    }
+
+    return 0;
 }
 
-void machine_reboot_kexec(xen_kexec_image_t *image)
+/*
+ * 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.
+ * 
+ * We don't really need to allocate control pages here as these
+ * entries won't be used while the kexec image is being copied, but it
+ * makes clean-up easier.
+ */
+static int init_transition_pgtable(struct kexec_image *image, l4_pgentry_t *l4)
+{
+    struct page_info *l3_page;
+    struct page_info *l2_page;
+    struct page_info *l1_page;
+    unsigned long vaddr, paddr;
+    l3_pgentry_t *l3 = NULL;
+    l2_pgentry_t *l2 = NULL;
+    l1_pgentry_t *l1 = NULL;
+    int ret = -ENOMEM;
+
+    vaddr = (unsigned long)kexec_reloc;
+    paddr = page_to_maddr(image->control_code_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(paddr >> 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);
+    return ret;
+}
+
+
+static int build_reloc_page_table(struct kexec_image *image)
+{
+    struct page_info *l4_page;
+    l4_pgentry_t *l4;
+    int result;
+
+    l4_page = kimage_alloc_control_page(image, 0);
+    if ( !l4_page )
+        return -ENOMEM;
+    l4 = __map_domain_page(l4_page);
+
+    result = init_level4_page(image, l4, 0, max_page << PAGE_SHIFT);
+    if ( result == 0)
+        result = init_transition_pgtable(image, l4);
+    unmap_domain_page(l4);
+    if ( result )
+        return result;
+
+    image->aux_page = l4_page;
+    return 0;
+}
+
+int machine_kexec_load(struct kexec_image *image)
+{
+    void *code_page;
+    int ret;
+
+    switch ( image->arch )
+    {
+    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, PAGE_SIZE);
+    unmap_domain_page(code_page);
+
+    ret = build_reloc_page_table(image);
+    if ( ret < 0 )
+        return ret;
+
+    return 0;
+}
+
+void machine_kexec_unload(struct kexec_image *image)
+{
+    /* no-op. kimage_free() frees all control pages. */
+}
+
+void machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
@@ -75,13 +237,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 +268,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 +215 -0

215 lines not on this page · raw message

xen/common/kexec.c +335 -62

494 lines not on this page · raw message

xen/common/kimage.c +78 -0

84 lines not on this page · raw message

xen/include/asm-x86/fixmap.h +0 -3
index 2eefcf4..1695228 100644
@@ -57,9 +57,6 @@ enum fixed_addresses {
     FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
     FIX_HPET_BASE,
     FIX_CYCLONE_TIMER,
-    FIX_KEXEC_BASE_0,
-    FIX_KEXEC_BASE_END = FIX_KEXEC_BASE_0 \
-      + ((KEXEC_XEN_NO_PAGES >> 1) * KEXEC_IMAGE_NR) - 1,
     FIX_IOMMU_REGS_BASE_0,
     FIX_IOMMU_REGS_END = FIX_IOMMU_REGS_BASE_0 + MAX_IOMMUS-1,
     FIX_IOMMU_MMIO_BASE_0,
xen/include/asm-x86/machine_kexec.h new file +14 -0
new file mode 100644
index 0000000..ec41099
@@ -0,0 +1,14 @@
+#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);
+
+#endif
+
+#endif /* __X86_MACHINE_KEXEC_H__ */
xen/include/xen/kexec.h +5 -9
index 1a5dda1..7bb9213 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,11 @@ 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_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 +53,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 9a785a1..7628e0a 100644
@@ -50,6 +50,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 /* __XEN_KIMAGE_H__ */
 
 /*
Signature · 1 line
1.7.2.5
#22 lore raw

Re: [PATCH 5/8] 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 34 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +28 -0
new file mode 100644
index 0000000..9d09c35
@@ -0,0 +1,215 @@
+/*
+ * 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 <asm/asm_defns.h>
+#include <asm/msr.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+/* The unrelocated physical address of a symbol. */
+#define SYM_PHYS(sym)          ((sym) - __XEN_VIRT_START)
+
+/* Load physical address of symbol into register and relocate it. */
+#define RELOCATE_SYM(sym,reg)  mov $SYM_PHYS(sym), reg ; \
+                               add xen_phys_start(%rip), reg
+
+        .text
+        .align PAGE_SIZE

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

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 */
+
+        mov %rdx, %rbx

movq?

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

Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+
+        /* Setup stack. */
+        RELOCATE_SYM(reloc_stack, %rax)
+        mov %rax, %rsp

Ditto?

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

Quoted 3 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +3 -0
+
+        /* Load reloc page table. */
+        movq %rsi, %cr3

...because at least you use movq here...
...etc...

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

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

Quoted 39 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +39 -0
+
+identity_mapped:
+        pushq %rcx
+        pushq %rbx
+        pushq %rsi
+        pushq %rdi
+
+        /*
+         * 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
+        andq    $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %rax
+        orl     $(X86_CR0_PG | X86_CR0_PE), %eax
+        movq    %rax, %cr0
+
+        /*
+         * Set cr4 to a known state:
+         *  - physical address extension enabled
+         */
+        movq    $X86_CR4_PAE, %rax
+        movq    %rax, %cr4
+
+        movq %rbx, %rdi
+        call relocate_pages
+
+        popq %rdi
+        popq %rsi
+        popq %rbx
+        popq %rcx
+
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit

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

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */
+        call *%rcx
+        ud2
+
+call_32_bit:
+        /* Relocate compatibility mode entry point address. */
+        movl %edi, %eax
+        addl $(compatibility_mode - kexec_reloc), %eax

leal (compatibility_mode - kexec_reloc)(%edi), %eax

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

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+        movl %eax, compatibility_mode_far(%rip)
+
+        /* setup idt */
+        lidt compat_mode_idt(%rip)
+
+        /* Load compat GDT. */
+        movq %rdi, %rax
+        addq $(compat_mode_gdt - kexec_reloc), %rax

leaq (compat_mode_gdt - kexec_reloc)(%rdi), %rax

[...]

Quoted 1 line
xen/common/kexec.c +0 -0

[...]

Quoted 7 lines
xen/common/kexec.c +1 -2
-static int kexec_load_unload_compat(unsigned long op,
-                                    XEN_GUEST_HANDLE_PARAM(void) uarg)
+static int kexec_load_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
 #ifdef CONFIG_COMPAT
     compat_kexec_load_v1_t compat_load;

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1015

Quoted 7 lines
xen/common/kexec.c +2 -2
@@ -808,49 +1011,113 @@ static int kexec_load_unload_compat(unsigned long op,
     load.type = compat_load.type;
     XLAT_kexec_image(&load.image, &compat_load.image);
 
-    return kexec_load_unload_internal(op, &load);
-#else /* CONFIG_COMPAT */
+    return kexec_do_load_v1(&load, 1);
+#else

Why did you removed comment?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1016

Quoted 1 line
xen/common/kexec.c +0 -0
     return 0;

Why not -ENOSYS?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1017

Quoted 2 lines
xen/common/kexec.c +1 -1
-#endif /* CONFIG_COMPAT */
+#endif

Why did you removed comment?

[...]

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1103

Quoted 13 lines
xen/common/kexec.c +13 -0
+static int kexec_unload_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
+{
+#ifdef CONFIG_COMPAT
+    compat_kexec_load_v1_t compat_load;
+    xen_kexec_unload_t unload;
+
+    if ( copy_from_guest(&compat_load, uarg, 1) )
+        return -EFAULT;
+
+    unload.type = compat_load.type;
+    return kexec_do_unload(&unload);
+#else
+    return 0;

Why not -ENOSYS?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1032

Quoted 2 lines
xen/common/kexec.c +2 -0
+#endif
+}

Please check other similar places too.

Daniel

#23 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

In reply to David Vrabel
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 34 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +28 -0
new file mode 100644
index 0000000..9d09c35
@@ -0,0 +1,215 @@
+/*
+ * 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 <asm/asm_defns.h>
+#include <asm/msr.h>
+#include <asm/page.h>
+#include <asm/machine_kexec.h>
+
+/* The unrelocated physical address of a symbol. */
+#define SYM_PHYS(sym)          ((sym) - __XEN_VIRT_START)
+
+/* Load physical address of symbol into register and relocate it. */
+#define RELOCATE_SYM(sym,reg)  mov $SYM_PHYS(sym), reg ; \
+                               add xen_phys_start(%rip), reg
+
+        .text
+        .align PAGE_SIZE

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

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 */
+
+        mov %rdx, %rbx

movq?

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

Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4 -0
+
+        /* Setup stack. */
+        RELOCATE_SYM(reloc_stack, %rax)
+        mov %rax, %rsp

Ditto?

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

Quoted 3 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +3 -0
+
+        /* Load reloc page table. */
+        movq %rsi, %cr3

...because at least you use movq here...
...etc...

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

Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

Quoted 39 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +39 -0
+
+identity_mapped:
+        pushq %rcx
+        pushq %rbx
+        pushq %rsi
+        pushq %rdi
+
+        /*
+         * 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
+        andq    $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %rax
+        orl     $(X86_CR0_PG | X86_CR0_PE), %eax
+        movq    %rax, %cr0
+
+        /*
+         * Set cr4 to a known state:
+         *  - physical address extension enabled
+         */
+        movq    $X86_CR4_PAE, %rax
+        movq    %rax, %cr4
+
+        movq %rbx, %rdi
+        call relocate_pages
+
+        popq %rdi
+        popq %rsi
+        popq %rbx
+        popq %rcx
+
+        /* Need to switch to 32-bit mode? */
+        testq $KEXEC_RELOC_FLAG_COMPAT, %r8
+        jnz call_32_bit

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

Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10 -0
+
+call_64_bit:
+        /* Call the image entry point.  This should never return. */
+        call *%rcx
+        ud2
+
+call_32_bit:
+        /* Relocate compatibility mode entry point address. */
+        movl %edi, %eax
+        addl $(compatibility_mode - kexec_reloc), %eax

leal (compatibility_mode - kexec_reloc)(%edi), %eax

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

Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8 -0
+        movl %eax, compatibility_mode_far(%rip)
+
+        /* setup idt */
+        lidt compat_mode_idt(%rip)
+
+        /* Load compat GDT. */
+        movq %rdi, %rax
+        addq $(compat_mode_gdt - kexec_reloc), %rax

leaq (compat_mode_gdt - kexec_reloc)(%rdi), %rax

[...]

Quoted 1 line
xen/common/kexec.c +0 -0

[...]

Quoted 7 lines
xen/common/kexec.c +1 -2
-static int kexec_load_unload_compat(unsigned long op,
-                                    XEN_GUEST_HANDLE_PARAM(void) uarg)
+static int kexec_load_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
 #ifdef CONFIG_COMPAT
     compat_kexec_load_v1_t compat_load;

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1015

Quoted 7 lines
xen/common/kexec.c +2 -2
@@ -808,49 +1011,113 @@ static int kexec_load_unload_compat(unsigned long op,
     load.type = compat_load.type;
     XLAT_kexec_image(&load.image, &compat_load.image);
 
-    return kexec_load_unload_internal(op, &load);
-#else /* CONFIG_COMPAT */
+    return kexec_do_load_v1(&load, 1);
+#else

Why did you removed comment?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1016

Quoted 1 line
xen/common/kexec.c +0 -0
     return 0;

Why not -ENOSYS?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1017

Quoted 2 lines
xen/common/kexec.c +1 -1
-#endif /* CONFIG_COMPAT */
+#endif

Why did you removed comment?

[...]

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1103

Quoted 13 lines
xen/common/kexec.c +13 -0
+static int kexec_unload_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
+{
+#ifdef CONFIG_COMPAT
+    compat_kexec_load_v1_t compat_load;
+    xen_kexec_unload_t unload;
+
+    if ( copy_from_guest(&compat_load, uarg, 1) )
+        return -EFAULT;
+
+    unload.type = compat_load.type;
+    return kexec_do_unload(&unload);
+#else
+    return 0;

Why not -ENOSYS?

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1032

Quoted 2 lines
xen/common/kexec.c +2 -0
+#endif
+}

Please check other similar places too.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#24 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

Quoted 10 lines · Daniel Kiper

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

Quoted 7 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

This isn't equivalent. It loads the value at the specified memory location and jumps to that address.

leaq (identity_mapped - kexec_reloc)(%rdi), %rax jmpq *%rax

Does the right thing.

David

#25 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

In reply to Daniel Kiper
Quoted 10 lines · Daniel Kiper

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

Quoted 7 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

This isn't equivalent. It loads the value at the specified memory location and jumps to that address.

leaq (identity_mapped - kexec_reloc)(%rdi), %rax jmpq *%rax

Does the right thing.

David

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#26 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

Quoted 12 lines · David Vrabel
Quoted 10 lines · Daniel Kiper

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

Quoted 7 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

Quoted 7 lines

This isn't equivalent. It loads the value at the specified memory location and jumps to that address.

leaq (identity_mapped - kexec_reloc)(%rdi), %rax jmpq *%rax

Does the right thing.

You are right. Sorry for confusion.

Daniel

#27 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

In reply to David Vrabel
Quoted 12 lines · David Vrabel
Quoted 10 lines · Daniel Kiper

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

Quoted 7 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +6 -0
+
+        /* Jump to identity mapped code. */
+        movq %rdi, %r9
+        addq $(identity_mapped - kexec_reloc), %r9
+
+        jmp *%r9

jmpq *(identity_mapped - kexec_reloc)(%rdi)

Quoted 7 lines

This isn't equivalent. It loads the value at the specified memory location and jumps to that address.

leaq (identity_mapped - kexec_reloc)(%rdi), %rax jmpq *%rax

Does the right thing.

You are right. Sorry for confusion.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#28 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

In reply to Daniel Kiper
Quoted 12 lines · Daniel Kiper
Quoted 11 lines · David Vrabel
xen/common/kexec.c +1 -2
-static int kexec_load_unload_compat(unsigned long op,
-                                    XEN_GUEST_HANDLE_PARAM(void) uarg)
+static int kexec_load_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
 #ifdef CONFIG_COMPAT
     compat_kexec_load_v1_t compat_load;
@@ -808,49 +1011,113 @@ static int kexec_load_unload_compat(unsigned long op,
     load.type = compat_load.type;
     XLAT_kexec_image(&load.image, &compat_load.image);
 
Quoted 6 lines

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1015

Quoted 4 lines
xen/common/kexec.c +2 -2
-    return kexec_load_unload_internal(op, &load);
-#else /* CONFIG_COMPAT */
+    return kexec_do_load_v1(&load, 1);
+#else

Why did you removed comment?

It's unhelpful clutter when the #if/#else/#endif are close together.

Quoted 3 lines

Review static int kexec_load_unload_compat(unsigned long op, · line 1016

Quoted 1 line
(quoted diff) +0 -0
     return 0;

Why not -ENOSYS?

It's unreachable code so it doesn't matter.

David

#29 lore raw

Re: [PATCH 5/8] kexec: extend hypercall with improved load/unload ops

In reply to Daniel Kiper
Quoted 12 lines · Daniel Kiper
Quoted 11 lines · David Vrabel
xen/common/kexec.c +1 -2
-static int kexec_load_unload_compat(unsigned long op,
-                                    XEN_GUEST_HANDLE_PARAM(void) uarg)
+static int kexec_load_v1_compat(XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
 #ifdef CONFIG_COMPAT
     compat_kexec_load_v1_t compat_load;
@@ -808,49 +1011,113 @@ static int kexec_load_unload_compat(unsigned long op,
     load.type = compat_load.type;
     XLAT_kexec_image(&load.image, &compat_load.image);
 
Quoted 6 lines

xen/common/kexec.c static int kexec_load_unload_compat(unsigned long op, · line 1015

Quoted 4 lines
xen/common/kexec.c +2 -2
-    return kexec_load_unload_internal(op, &load);
-#else /* CONFIG_COMPAT */
+    return kexec_do_load_v1(&load, 1);
+#else

Why did you removed comment?

It's unhelpful clutter when the #if/#else/#endif are close together.

Quoted 3 lines

Review static int kexec_load_unload_compat(unsigned long op, · line 1016

Quoted 1 line
(quoted diff) +0 -0
     return 0;

Why not -ENOSYS?

It's unreachable code so it doesn't matter.

David

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#30 lore raw

PATCH v3 6/8 xen: kexec crash image when dom0 crashes

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/shutdown.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
xen/common/shutdown.c +3 -0
index 73a7d7b..b676a03 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
#31 lore raw

Re: [PATCH 6/8] xen: kexec crash image when dom0 crashes

Quoted 12 lines · David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/shutdown.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
xen/common/shutdown.c +0 -0
index 73a7d7b..b676a03 100644

xen/common/shutdown.c void dom0_shutdown(u8 reason) · line 49

Quoted 3 lines
xen/common/shutdown.c +0 -0
@@ -47,6 +47,9 @@ void dom0_shutdown(u8 reason)
     {
         debugger_trap_immediate();
         printk("Domain 0 crashed: ");

Maybe printk("Domain 0 crashed...\n") because kexec_crash() does not print any message and current version looks a bit strange i.e. it suggest that something should be printed but something has failed... If yes then messages which could be printed immediately after "Domain 0 crashed...\n" should start from "..." e.g. "...rebooting...".

xen/common/shutdown.c void dom0_shutdown(u8 reason) · line 55

Quoted 6 lines
xen/common/shutdown.c +3 -0
+#ifdef CONFIG_KEXEC
+        kexec_crash();
+#endif
         maybe_reboot();
         break; /* not reached */
     }

Daniel

#32 lore raw

PATCH v3 7/8 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 32122fd..c3b2c28 100644
@@ -317,6 +317,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
#33 lore raw

PATCH v3 8/8 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 d44abf9..39badf9 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