kexec: extend kexec hypercall for use with pv-ops kernels
v6 cover kexec: 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.
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.
Patch 9 adds a link time check for the size of the relocate code.
Patch 10 adds myself as the maintainer for kexec in Xen.
The required patch series for kexec-tools have previously been posted and this series has been rebased on the latest kexec-tools and is available from the xen-v3 branch of:
http://xenbits.xen.org/gitweb/?p=people/dvrabel/kexec-tools.git;a=summary
Changes since v5:
- 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 since v4 (v5 was 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 since v3:
- 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 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
PATCH v6 1/10 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
@@ -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
@@ -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
PATCH v6 2/10 xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
In reply to David VrabelFrom: 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 restriction so they may be used by any new structures.
There is a minimal cost for 32-bit guests on 64-but hypervisors as set_xen_guest_handle() needs to zero 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
@@ -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
@@ -858,9 +858,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
@@ -875,8 +880,6 @@ struct xenctl_bitmap { };#endif -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ -#endif /* __XEN_PUBLIC_XEN_H__ */ /*
Signature · 1 line
1.7.2.5
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 14 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/arch-x86/xen-x86_32.h +1
-2@@ -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; } \
xen/include/public/arch-x86/xen-x86_32.h line 106
Quoted 1 line
xen/include/public/arch-x86/xen-x86_32.h +0
-0@@ -107,7 +106,6 @@#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
This line is the reason why such a change is not acceptable: We require the headers to not use gcc extensions outside of regions guarded by dependencies on __XEN__ and/or __XEN_TOOLS__ (which we know/require will always be built by gcc compatible tool chains).
xen/include/public/arch-x86/xen-x86_32.h line 110
Quoted 5 lines
xen/include/public/arch-x86/xen-x86_32.h +0
-1#define __XEN_GUEST_HANDLE_64 (name) __guest_handle_64_ ## name#define XEN_GUEST_HANDLE_64 (name) __XEN_GUEST_HANDLE_64(name) -#endif #ifndef __ASSEMBLY__
I'm afraid you'll need to find a way to do what you want in the kexec interface with the traditional manual padding approach.
Jan
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/arch-x86/xen-x86_32.h +0
-0@@ -91,8 +91,7 @@#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)#endif
Quoted 13 lines
xen/include/public/arch-x86/xen-x86_32.h line 106
Quoted 8 lines
xen/include/public/arch-x86/xen-x86_32.h +1
-2-/* 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)))This line is the reason why such a change is not acceptable: We require the headers to not use gcc extensions outside of regions guarded by dependencies on
__XEN__and/or__XEN_TOOLS__(which we know/require will always be built by gcc compatible tool chains).
I did this because this is identical to what ARM is doing.
I think we do what a guest handle type that is always 64 bits long. For x86, perhaps something like (but with a better name):
#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
typedef struct { type *p; } \
__guest_handle_ ## name; \
#if defined(__XEN__) || (__XEN_TOOLS__)
typedef struct { union { type *p; uint64_aligned_t q; }; } \
__guest_handle_64_ ## name \
#endif
typedef struct { union { type *p; uint64_t q; }; } \
__guest_handle_new_ ## name
#undef set_xen_guest_handle_raw
#define set_xen_guest_handle_raw(hnd, val) \
do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \
(hnd).p = val; \
} while ( 0 )#if defined(__XEN__) || (__XEN_TOOLS__)
#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
#define __XEN_GUEST_HANDLE_NEW(name) __guest_handle_new_ ## name /* This must be aligned to 8 bytes with padding if necessary. */ #define XEN_GUEST_HANDLE_NEW(name) __XEN_GUEST_HANDLE_NEW(name)
Quoted 8 lines
xen/include/public/arch-x86/xen-x86_32.h line 110
Quoted 5 lines
xen/include/public/arch-x86/xen-x86_32.h +0
-1#define __XEN_GUEST_HANDLE_64 (name) __guest_handle_64_ ## name#define XEN_GUEST_HANDLE_64 (name) __XEN_GUEST_HANDLE_64(name) -#endif #ifndef __ASSEMBLY__I'm afraid you'll need to find a way to do what you want in the kexec interface with the traditional manual padding approach.
This is fine. The kexec interface has the necessary padding and doesn't need the the aligned attribute.
David
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 15 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel
#define
uint64_aligned_tuint64_t__attribute__((aligned(8)))This line is the reason why such a change is not acceptable: We require the headers to not use gcc extensions outside of regions guarded by dependencies on
__XEN__and/or__XEN_TOOLS__(which we know/require will always be built by gcc compatible tool chains).I did this because this is identical to what ARM is doing.
I think we do what a guest handle type that is always 64 bits long. For x86, perhaps something like (but with a better name):
Quoted 9 lines
#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
typedef struct { type *p; } \
__guest_handle_ ## name; \
#if defined(__XEN__) || (__XEN_TOOLS__)
typedef struct { union { type *p; uint64_aligned_t q; }; } \
__guest_handle_64_ ## name \
#endif
typedef struct { union { type *p; uint64_t q; }; } \
__guest_handle_new_ ## nameThe uint64_t here ...
Quoted 12 lines
#undef
set_xen_guest_handle_raw#define set_xen_guest_handle_raw(hnd, val) \ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ (hnd).p = val; \ } while ( 0 )#if
defined(__XEN__)|| (__XEN_TOOLS__)
#defineuint64_aligned_tuint64_t__attribute__((aligned(8))) #define__XEN_GUEST_HANDLE_64(name)__guest_handle_64_## name #defineXEN_GUEST_HANDLE_64(name)__XEN_GUEST_HANDLE_64(name)#endif
Quoted 3 lines
#define
__XEN_GUEST_HANDLE_NEW(name)__guest_handle_new_## name /* This must be aligned to 8 bytes with padding if necessary. */ #defineXEN_GUEST_HANDLE_NEW(name)__XEN_GUEST_HANDLE_NEW(name)
... does in no way satisfy the comment here, so what's the point?
Quoted 5 lines
Quoted 2 lines
I'm afraid you'll need to find a way to do what you want in the kexec interface with the traditional manual padding approach.
This is fine. The kexec interface has the necessary padding and doesn't need the the aligned attribute.
Not afaict, unless you meant if substituting XEN_GUEST_HANDLE_NEW() (rather than XEN_GUEST_HANDLE()) for XEN_GUEST_HANDLE_64().
Jan
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 39 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel
#define
uint64_aligned_tuint64_t__attribute__((aligned(8)))This line is the reason why such a change is not acceptable: We require the headers to not use gcc extensions outside of regions guarded by dependencies on
__XEN__and/or__XEN_TOOLS__(which we know/require will always be built by gcc compatible tool chains).I did this because this is identical to what ARM is doing.
I think we do what a guest handle type that is always 64 bits long. For x86, perhaps something like (but with a better name):
Quoted 9 lines
#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ typedef struct { type *p; } \ __guest_handle_ ## name; \ #if defined(__XEN__) || (__XEN_TOOLS__) typedef struct { union { type *p; uint64_aligned_t q; }; } \ __guest_handle_64_ ## name \ #endif typedef struct { union { type *p; uint64_t q; }; } \ __guest_handle_new_ ## nameThe
uint64_there ...Quoted 12 lines
#undef
set_xen_guest_handle_raw#define set_xen_guest_handle_raw(hnd, val) \ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ (hnd).p = val; \ } while ( 0 )#if
defined(__XEN__)|| (__XEN_TOOLS__)
#defineuint64_aligned_tuint64_t__attribute__((aligned(8))) #define__XEN_GUEST_HANDLE_64(name)__guest_handle_64_## name #defineXEN_GUEST_HANDLE_64(name)__XEN_GUEST_HANDLE_64(name)#endif
Quoted 5 lines
Quoted 3 lines
#define
__XEN_GUEST_HANDLE_NEW(name)__guest_handle_new_## name /* This must be aligned to 8 bytes with padding if necessary. */ #defineXEN_GUEST_HANDLE_NEW(name)__XEN_GUEST_HANDLE_NEW(name)... does in no way satisfy the comment here, so what's the point?
The comment is unclear, sorry.
/* A structure containing this type of guest handle must align the
field to 8 bytes, using padding fields as necessary. */
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I'm afraid you'll need to find a way to do what you want in the kexec interface with the traditional manual padding approach.
This is fine. The kexec interface has the necessary padding and doesn't need the the aligned attribute.
Not afaict, unless you meant if substituting
XEN_GUEST_HANDLE_NEW()(rather thanXEN_GUEST_HANDLE()) forXEN_GUEST_HANDLE_64().
Yes.
David
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 24 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 22 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel
typedef struct { union { type *p; uint64_t q; }; } \ __guest_handle_new_ ## nameThe
uint64_there ...Quoted 15 lines
#undef
set_xen_guest_handle_raw#define set_xen_guest_handle_raw(hnd, val) \ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ (hnd).p = val; \ } while ( 0 )#if
defined(__XEN__)|| (__XEN_TOOLS__)
#defineuint64_aligned_tuint64_t__attribute__((aligned(8))) #define__XEN_GUEST_HANDLE_64(name)__guest_handle_64_## name #defineXEN_GUEST_HANDLE_64(name)__XEN_GUEST_HANDLE_64(name)#endif#define
__XEN_GUEST_HANDLE_NEW(name)__guest_handle_new_## name /* This must be aligned to 8 bytes with padding if necessary. */ #defineXEN_GUEST_HANDLE_NEW(name)__XEN_GUEST_HANDLE_NEW(name)
Quoted 6 lines
Quoted 1 line
... does in no way satisfy the comment here, so what's the point?
The comment is unclear, sorry.
/* A structure containing this type of guest handle must align the
field to 8 bytes, using padding fields as necessary. */
Okay, now I understand your intention at least. However, I still don't see a point in doing what you try to do - the consumer still has to add stuff along with the (oddly named) new handle type, so why not having it take care of padding _and_ sizing?
Jan
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 18 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel
typedef struct { union { type *p; uint64_t q; }; } \ __guest_handle_new_ ## nameThe
uint64_there ...Quoted 12 lines
#undef
set_xen_guest_handle_raw#define set_xen_guest_handle_raw(hnd, val) \ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ (hnd).p = val; \ } while ( 0 )#if
defined(__XEN__)|| (__XEN_TOOLS__)
#defineuint64_aligned_tuint64_t__attribute__((aligned(8))) #define__XEN_GUEST_HANDLE_64(name)__guest_handle_64_## name #defineXEN_GUEST_HANDLE_64(name)__XEN_GUEST_HANDLE_64(name)#endifQuoted 5 lines
Quoted 3 lines
#define
__XEN_GUEST_HANDLE_NEW(name)__guest_handle_new_## name /* This must be aligned to 8 bytes with padding if necessary. */ #defineXEN_GUEST_HANDLE_NEW(name)__XEN_GUEST_HANDLE_NEW(name)... does in no way satisfy the comment here, so what's the point?
The comment is unclear, sorry.
Quoted 7 lines
Quoted 2 lines
/* A structure containing this type of guest handle must align the
field to 8 bytes, using padding fields as necessary. */Okay, now I understand your intention at least. However, I still don't see a point in doing what you try to do - the consumer still has to add stuff along with the (oddly named) new handle type, so why not having it take care of padding _and_ sizing?
I want the structure to be identical for 32-bit and 64-bit guests so compat code is not required in the hypervisor.
Without a macro like XEN_GUEST_HANDLE_64() how do you suggest the structure is defined so the field is sized correctly (i.e., 8 bytes)?
Are you suggesting something like?
typedef struct xen_kexec_load {
uint8_t type; /* One of KEXEC_TYPE_* */
uint8_t _pad;
uint16_t arch; /* ELF machine type (EM_*). */
uint32_t nr_segments;
union {
XEN_GUEST_HANDLE(xen_kexec_segment_t) segments;
uint64_t _qword;
} u;
uint64_t entry_maddr; /* image entry point machine address. */
} xen_kexec_load_t;David
Re: [PATCH 02/10] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere
Quoted 9 lines
Quoted 1 line
Quoted 1 line · David Vrabel
I want the structure to be identical for 32-bit and 64-bit guests so compat code is not required in the hypervisor.
Without a macro like
XEN_GUEST_HANDLE_64()how do you suggest the structure is defined so the field is sized correctly (i.e., 8 bytes)?Are you suggesting something like?
Quoted 11 lines
typedef struct xen_kexec_load {
uint8_t type; /* One of KEXEC_TYPE_* */
uint8_t _pad;
uint16_t arch; /* ELF machine type (EM_*). */
uint32_t nr_segments;
union {
XEN_GUEST_HANDLE(xen_kexec_segment_t) segments;
uint64_t _qword;
} u;
uint64_t entry_maddr; /* image entry point machine address. */
} xen_kexec_load_t;Yes - there are already other cases similar to this in the public headers, for example struct vcpu_register_runstate_memory_area and struct vcpu_register_time_memory_area.
Jan
PATCH v6 3/10 kexec: add public interface for improved load/unload sub-ops
In reply to David VrabelFrom: 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 | 66 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 10 deletions(-)
xen/common/kexec.c +6 -6
@@ -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 +62 -4
80 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 03/10] kexec: add public interface for improved load/unload sub-ops
xen/include/public/kexec.h typedef struct xen_kexec_range { · line 155
Quoted 6 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +1
-0@@ -152,6 +152,64 @@ typedef struct xen_kexec_range {unsigned long start; } xen_kexec_range_t; +#if __XEN_INTERFACE_VERSION__ >=0x00040300
... >= 0x00040400
Jan
Quoted 60 lines
xen/include/public/kexec.h +57
-0+/* +* 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; +}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. +* +* 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_* */ +uint8_t _pad; +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 ; +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 ; + +#endif +#endif /* _XEN_PUBLIC_KEXEC_H */ /*
Re: [PATCH 03/10] kexec: add public interface for improved load/unload sub-ops
Quoted 8 lines · Jan Beulich
xen/include/public/kexec.h typedef struct xen_kexec_range { · line 155
Quoted 6 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/kexec.h +1
-0@@ -152,6 +152,64 @@ typedef struct xen_kexec_range {unsigned long start; } xen_kexec_range_t; +#if __XEN_INTERFACE_VERSION__ >=0x00040300 ... >=
0x00040400
Yes, as soon as Xen's version becomes 4.4, but for now it's still 4.3.
David
Re: [PATCH 03/10] kexec: add public interface for improved load/unload sub-ops
Quoted 7 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,64 @@ typedef struct xen_kexec_range {unsigned long start; } xen_kexec_range_t;
Quoted 5 lines
Quoted 3 lines
xen/include/public/kexec.h typedef struct xen_kexec_range { · line 155
Quoted 1 line
xen/include/public/kexec.h +1
-0+#if __XEN_INTERFACE_VERSION__ >=0x00040300 ... >=
0x00040400Yes, as soon as Xen's version becomes 4.4, but for now it's still 4.3.
Not exactly - if no patch before yours bumps the interface version, your one will need to.
Jan
PATCH v6 4/10 kexec: add infrastructure for handling kexec images
In reply to David VrabelFrom: 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 | 823 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/kimage.h | 59 ++++ 3 files changed, 883 insertions(+), 0 deletions(-) create mode 100644 xen/common/kimage.c create mode 100644 xen/include/xen/kimage.h
xen/common/Makefile +1 -0
@@ -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 +823 -0
823 lines not on this page · raw message
xen/include/xen/kimage.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 04/10] kexec: add infrastructure for handling kexec images
xen/common/kimage.c line 81
Quoted 7 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/kimage.c new file +6
-0+static struct page_info *kimage_alloc_zeroed_page (unsigned memflags) +{ +struct page_info *page; + + page =alloc_domheap_page (NULL , memflags); +if ( page ==NULL )
Please be consistent - either always use "== NULL", ...
Quoted 9 lines
xen/common/kimage.c new file +9
-0+return NULL ; + +clear_domain_page (page_to_mfn (page)); + +return page; +} + +static int do_kimage_alloc(struct kexec_image **rimage, paddr_t entry, + unsigned long nr_segments,
xen/common/kimage.c line 100
Quoted 10 lines
xen/common/kimage.c new file +10
-0+ xen_kexec_segment_t *segments, uint8_t type) +{ +struct kexec_image *image; +unsigned long i; +int result; + +/* Allocate a controlling structure */ + result = -ENOMEM ; + image =xzalloc (typeof (*image)); +if ( !image )
... or (preferably afaic) always use "!".
xen/common/kimage.c line 103
Quoted 3 lines
xen/common/kimage.c new file +3
-0+ goto out; + + image->control_page = ~0 ;/* By default this does not apply */
Use a recognizable #define instead?
Quoted 20 lines
xen/common/kimage.c new file +20
-0+ image->entry_maddr = entry; + image->type = type; + image->nr_segments = nr_segments; + image->segments = segments; + +INIT_PAGE_LIST_HEAD (&image->control_pages); +INIT_PAGE_LIST_HEAD (&image->dest_pages); +INIT_PAGE_LIST_HEAD (&image->unusable_pages); + +/* +* Verify we have good destination addresses. The caller is +* responsible for making certain we don't attempt to load +* the new image into invalid or reserved areas of RAM. This +* just verifies it is an address we can use. +* +* Since the kernel does everything in page size chunks ensure +* the destination addresses are page aligned. Too many +* special cases crop of when we don't do this. The most +* insidious is getting overlapping destination addresses +* simply because addresses are changed to page size
xen/common/kimage.c line 133
Quoted 10 lines
xen/common/kimage.c new file +10
-0+* granularity. +*/ + result = -EADDRNOTAVAIL ; +for ( i =0 ; i < nr_segments; i++ ) + { +paddr_t mstart, mend; + + mstart = image->segments[i].dest_maddr; + mend = mstart + image->segments[i].dest_size; +if ( (mstart & ~PAGE_MASK ) || (mend & ~PAGE_MASK ) )
Expressions like this can be abbreviated to
if ( (mstart | mend) & ~PAGE_MASK )
xen/common/kimage.c line 137
Quoted 4 lines
xen/common/kimage.c new file +4
-0+ goto out; + } + +/* Verify our destination addresses do not overlap.
Coding style (the comment immediately above is done correctly). There are more of these further down...
There are also a few cases of bogus blank lines - while the coding style document doesn't say anything in that regard, excessive amounts of blank lines increase the risk of future patches getting applied incorrectly due to the patch context becoming less meaningful.
Jan
Re: [PATCH 04/10] kexec: add infrastructure for handling kexec images
Quoted 7 lines · Jan Beulich
xen/common/kimage.c line 103
Quoted 5 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/kimage.c new file +3
-0+ goto out; + + image->control_page = ~0 ;/* By default this does not apply */ Use a recognizable #define instead?
This assignment serves no purpose so I'll leaved it zeroed.
Quoted 7 lines
xen/common/kimage.c line 133
Quoted 3 lines
xen/common/kimage.c new file +3
-0+ mstart = image->segments[i].dest_maddr; + mend = mstart + image->segments[i].dest_size; +if ( (mstart & ~PAGE_MASK ) || (mend & ~PAGE_MASK ) )Expressions like this can be abbreviated to
if ( (mstart | mend) & ~PAGE_MASK )
I think the original more clearly reflects the intent.
David
PATCH v6 5/10 kexec: extend hypercall with improved load/unload ops
In reply to David VrabelFrom: 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 | 211 +++++++++++++++++++ xen/common/kexec.c | 393 +++++++++++++++++++++++++++++------ xen/common/kimage.c | 103 +++++++++ xen/include/asm-x86/fixmap.h | 3 - xen/include/asm-x86/machine_kexec.h | 16 ++ xen/include/xen/kexec.h | 14 +- xen/include/xen/kimage.h | 6 + 10 files changed, 885 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
@@ -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 ); + +while ( (addr < last_addr) && (addr < end_addr) ) + { +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 ; +} + +/* +* 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 ; +} + +/* +* 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; +} -for ( k =0 ; k <KEXEC_XEN_NO_PAGES ; k++ ) + +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 ) { -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); + + ret =build_reloc_page_table (image); +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 +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). -*/ - asmvolatile ("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
@@ -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 +211 -0
211 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 +103 -0
109 lines not on this page · raw message
xen/include/asm-x86/fixmap.h +0 -3
@@ -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 +16 -0
@@ -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 long kexec_reloc_size; + +#endif + +#endif /* __X86_MACHINE_KEXEC_H__ */
xen/include/xen/kexec.h +5 -9
@@ -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
@@ -46,6 +46,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
Re: [PATCH 05/10] kexec: extend hypercall with improved load/unload ops
xen/arch/x86/machine_kexec.c line 31
Quoted 7 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/arch/x86/machine_kexec.c +6
-0+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 );
For one, with the code below, this can't be right: "addr" is getting only page aligned, but the rest of the code assumes it is suitable as a super-page.
Further, you're risking mapping non-memory here, as the caller doesn't pass the true end of the memory block to be mapped.
And then the expression is odd - why not just
end_addr = addr + (L2_PAGETABLE_ENTRIES << L2_PAGETABLE_SHIFT);
Quoted 11 lines
xen/arch/x86/machine_kexec.c +11
-0+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) ) + {
xen/arch/x86/machine_kexec.c line 95
Quoted 10 lines
xen/arch/x86/machine_kexec.c +10
-0+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)
Coding style.
Quoted 26 lines
xen/arch/x86/machine_kexec.c +26
-0+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);
xen/arch/x86/machine_kexec.c line 150
Quoted 10 lines
xen/arch/x86/machine_kexec.c +10
-0+ 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);
Afaict you're done using "l3" here, so you should unmap it in order to reduce the pressure on the domain page mapping resources.
xen/arch/x86/machine_kexec.c line 162
Quoted 12 lines
xen/arch/x86/machine_kexec.c +12
-0+ + 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);
Same for "l2" at this point.
xen/arch/x86/machine_kexec.c line 191
Quoted 12 lines
xen/arch/x86/machine_kexec.c +12
-0+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 );
What about holes in the physical address space - not just the MMIO hole below 4Gb is a problem here, but also discontiguous physical memory.
Quoted 53 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +50
-0@@ -0,0 +1,211 @@ +/* + * 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> + + .text + .align PAGE_SIZE + .code64 + +ENTRY(kexec_reloc) + /* %rdi - code page maddr */ + /* %rsi - page table maddr */ + /* %rdx - indirection page maddr */ + /* %rcx - entry maddr */ + /* %r8 - flags */ + + movq %rdx, %rbx + + /* Setup stack. */ + leaq (reloc_stack - kexec_reloc)(%rdi), %rsp + + /* Load reloc page table. */ + movq %rsi, %cr3 + + /* Jump to identity mapped code. */ + leaq (identity_mapped - kexec_reloc)(%rdi), %rax + jmpq *%rax + +identity_mapped: + pushq %rcx + pushq %rbx + pushq %rsi + pushq %rdi + + /* + * Set cr0 to a known state:
xen/arch/x86/x86_64/kexec_reloc.S line 60
Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10
-0+ * - 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
Either "andq" and "orq" or "andl" and "orl".
xen/arch/x86/x86_64/kexec_reloc.S line 67
Quoted 7 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +7
-0+ movq %rax, %cr0 + + /* + * Set cr4 to a known state: + * - physical address extension enabled + */ + movq $X86_CR4_PAE, %rax
"movl" suffices here.
Quoted 24 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +24
-0+ 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 + +call_64_bit: + /* Call the image entry point. This should never return. */ + call *%rcx + ud2 + +call_32_bit: + /* Setup IDT. */ + lidt compat_mode_idt(%rip) + + /* Load compat GDT. */
xen/arch/x86/x86_64/kexec_reloc.S line 101
Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10
-0+ 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)
As you're elsewhere using mnemonic suffixes elsewhere even when not strictly needed, for consistency I'd recommend using one on this instruction (and perhaps also on the lidt/lgdt above) too.
xen/arch/x86/x86_64/kexec_reloc.S line 108
Quoted 7 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +7
-0+ +relocate_pages: + /* %rdi - indirection page maddr */ + cld + movq %rdi, %rcx + xorq %rdi, %rdi + xorq %rsi, %rsi
I guess performance and code size aren't of highest importance here, but "xorl" would suffice in both of the above lines.
xen/arch/x86/x86_64/kexec_reloc.S line 116
Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8
-0+ jmp 1f + +0: /* top, read another word for the indirection page */ + + movq (%rbx), %rcx + addq $8, %rbx +1: + testq $0x1, %rcx /* is it a destination page? */
And "testl" (or even "testb") would be sufficient here. There are more pointless uses of the "q" suffix further down.
In any event the 0x1 here and the other flags tested for below will want to become manifest constants.
xen/arch/x86/x86_64/kexec_reloc.S line 119
Quoted 3 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +3
-0+ jz 2f + movq %rcx, %rdi + andq $0xfffffffffffff000, %rdi
The number of "f"-s here being correct can't be seen without actually counting them - either use a manifest constant like PAGE_MASK, or at least write "$~0xfff".
xen/arch/x86/x86_64/kexec_reloc.S line 130
Quoted 11 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +11
-0+ jmp 0b +2: + testq $0x2, %rcx /* is it an indirection page? */ + jz 2f + movq %rcx, %rbx + andq $0xfffffffffffff000, %rbx + jmp 0b +2: + testq $0x4, %rcx /* is it the done indicator? */ + jz 2f + jmp 3f
Just a single (inverse) conditional branch please.
And there are too many "2:" labels here in close succession.
xen/arch/x86/x86_64/kexec_reloc.S line 134
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4
-0+2: + testq $0x8, %rcx /* is it the source indicator? */ + jz 2f + movq %rcx, %rsi /* For ever source page do a copy */
"every"?
Quoted 30 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +30
-0+ andq $0xfffffffffffff000, %rsi + movq $512, %rcx + rep movsq + jmp 0b +2: + testq $0x10, %rcx /* is it the zero indicator? */ + jz 0b /* Ignore it otherwise */ + movq $512, %rcx /* Zero the destination page. */ + xorq %rax, %rax + rep stosq + jmp 0b +3: + 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
xen/arch/x86/x86_64/kexec_reloc.S line 174
Quoted 10 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +10
-0+ movl %eax, %cr0 + + /* Disable long mode */ + movl $MSR_EFER, %ecx + rdmsr + andl $~EFER_LME, %eax + wrmsr + + /* Clear cr4 to disable PAE. */ + movl $0, %eax
xorl %eax, %eax
xen/arch/x86/x86_64/kexec_reloc.S line 181
Quoted 7 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +7
-0+ movl %eax, %cr4 + + /* Call the image entry point. This should never return. */ + call *%ebp + ud2 + + .align 16
Why? 4 is all you need.
xen/arch/x86/x86_64/kexec_reloc.S line 186
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+compatibility_mode_far: + .long 0x00000000 /* set in call_32_bit above */ + .word 0x0010 + + .align 16
Even more so here. If you care for alignment, you want 2 mod 8 here.
xen/arch/x86/x86_64/kexec_reloc.S line 191
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+compat_mode_gdt_desc: + .word (3*8)-1 + .quad 0x0000000000000000 /* set in call_32_bit above */ + + .align 16
And just 8 here.
xen/arch/x86/x86_64/kexec_reloc.S line 197
Quoted 6 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +6
-0+compat_mode_gdt: + .quad 0x0000000000000000 /* null */ + .quad 0x00cf92000000ffff /* 0x0008 ring 0 data */ + .quad 0x00cf9a000000ffff /* 0x0010 ring 0 code, compatibility */ + +compat_mode_idt:
compat_mode_idt_desc:
And if you care for alignment, 2 mod 8 again.
xen/arch/x86/x86_64/kexec_reloc.S line 205
Quoted 8 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +8
-0+ .word 0 /* limit */ + .long 0 /* base */ + + /* + * 16 words of stack are more than enough. + */ + .fill 16,8,0 +reloc_stack:
And now you don't care for the stack being mis-aligned?
Jan
Re: [PATCH 05/10] kexec: extend hypercall with improved load/unload ops
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel
+static int
init_transition_pgtable(struct kexec_image *image, l4_pgentry_t *l4)
[...]
Quoted 12 lines
xen/arch/x86/machine_kexec.c line 150
Quoted 11 lines
xen/arch/x86/machine_kexec.c +11
-0+ 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);
Quoted 2 lines
Afaict you're done using "l3" here, so you should unmap it in order to reduce the pressure on the domain page mapping resources.
The unmaps are grouped at the end to make the error paths simpler and I would prefer to keep it like this. This is only using 4 entries. Are we really that short?
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/machine_kexec.c +8
-0+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 )
Quoted 8 lines
xen/arch/x86/machine_kexec.c line 191
Quoted 4 lines
xen/arch/x86/machine_kexec.c +4
-0+return -ENOMEM ; + l4 =__map_domain_page (l4_page); + + result =init_level4_page (image, l4,0 , max_page <<PAGE_SHIFT );What about holes in the physical address space - not just the MMIO hole below 4Gb is a problem here, but also discontiguous physical memory.
I don't see a problem with creating mappings for non-RAM regions.
The discontiguous physical memory is a problem though. I think I'll solve this by specifying that images are only executed with the first 4 GiB of physical address space linearly mapped.
If this turns out not to be enough then the mappings can be extended without breaking existing tools or images.
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +0
-0
[...]
Quoted 1 line
And just 8 here.
I seem to recall reading that some processors needed 16 byte alignment for the GDT. I may be misremembering or this was for an older processor that Xen no longer supports.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4
-0+compat_mode_gdt: + .quad 0x0000000000000000 /* null */ + .quad 0x00cf92000000ffff /* 0x0008 ring 0 data */ + .quad 0x00cf9a000000ffff /* 0x0010 ring 0 code, compatibility */
[...]
Quoted 7 lines
xen/arch/x86/x86_64/kexec_reloc.S line 205
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+ /* + * 16 words of stack are more than enough. + */ + .fill 16,8,0 +reloc_stack:And now you don't care for the stack being mis-aligned?
I do find the way you make some review comments as a question like this rather ambiguous. I guess I don't care? But now I'm not sure if I should.
David
Re: [PATCH 05/10] kexec: extend hypercall with improved load/unload ops
Quoted 18 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · David Vrabel
+static int
init_transition_pgtable(struct kexec_image *image, l4_pgentry_t *l4)[...]
Quoted 12 lines
Quoted 11 lines
xen/arch/x86/machine_kexec.c +11
-0+ 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);
Quoted 6 lines
Quoted 2 lines
Afaict you're done using "l3" here, so you should unmap it in order to reduce the pressure on the domain page mapping resources.
The unmaps are grouped at the end to make the error paths simpler and I would prefer to keep it like this. This is only using 4 entries. Are we really that short?
4 entries are fine as long as calling code doesn't also (now or in the future) want to keep stuff mapped around calling this.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/machine_kexec.c +8
-0+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 )Quoted 8 lines
xen/arch/x86/machine_kexec.c line 191
Quoted 4 lines
xen/arch/x86/machine_kexec.c +4
-0+return -ENOMEM ; + l4 =__map_domain_page (l4_page); + + result =init_level4_page (image, l4,0 , max_page <<PAGE_SHIFT );What about holes in the physical address space - not just the MMIO hole below 4Gb is a problem here, but also discontiguous physical memory.
Quoted 1 line
I don't see a problem with creating mappings for non-RAM regions.
You absolutely must not map regions you don't know anything about with WB attribute, or else side effects of prefetches can create very hard to debug issues.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +0
-0[...]
Quoted 1 line
And just 8 here.
I seem to recall reading that some processors needed 16 byte alignment for the GDT. I may be misremembering or this was for an older processor that Xen no longer supports.
I'm unaware of such, and e.g. trampoline_gdt is currently not even 8-byte aligned. But if you can point to documentation saying so, I certainly won't abject playing by their rules.
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +4
-0+compat_mode_gdt: + .quad 0x0000000000000000 /* null */ + .quad 0x00cf92000000ffff /* 0x0008 ring 0 data */ + .quad 0x00cf9a000000ffff /* 0x0010 ring 0 code, compatibility */[...]
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+ /* + * 16 words of stack are more than enough. + */ + .fill 16,8,0 +reloc_stack:
Quoted 4 lines
Quoted 1 line
And now you don't care for the stack being mis-aligned?
I do find the way you make some review comments as a question like this rather ambiguous. I guess I don't care? But now I'm not sure if I should.
I was just puzzled by the earlier over-aligning and the complete lack of alignment here.
Jan
Re: [PATCH 05/10] kexec: extend hypercall with improved load/unload ops
In reply to David VrabelQuoted 34 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_loadandKEXEC_CMD_kexec_unloadops 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_loadsystem 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., anEM_386image on anEM_X86_64hypervisor).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_v1andKEXEC_CMD_unload_v1) and are implemented on top of the new infrastructure.Signed-off-by David Vrabel <[email protected]>Reviewed-by Daniel Kiper <[email protected]>Tested-by Daniel Kiper <[email protected]>
[...]
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +0
-0
[...]
xen/arch/x86/x86_64/kexec_reloc.S line 211
Quoted 5 lines
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+ .globl __kexec_reloc_size + .set __kexec_reloc_size, . - kexec_reloc + .globl kexec_reloc_size +kexec_reloc_size: + .quad __kexec_reloc_size
Why do you define two variables to store the same value? Why quad not long? I think that you could do that:
.globl kexec_reloc_size /* Personaly I prefer do this at the beginning of S file. */kexec_reloc_size:
.long . - xen_relocate_kernel
It should work for C files and linker script.
Daniel
Re: [PATCH 05/10] kexec: extend hypercall with improved load/unload ops
Quoted 8 lines · Daniel Kiper
xen/arch/x86/x86_64/kexec_reloc.S line 211
Quoted 6 lines · David Vrabel
xen/arch/x86/x86_64/kexec_reloc.S new file +5
-0+ .globl __kexec_reloc_size + .set __kexec_reloc_size, . - kexec_reloc + .globl kexec_reloc_size +kexec_reloc_size: + .quad __kexec_reloc_size
Quoted 7 lines
Why do you define two variables to store the same value?
.globl
kexec_reloc_size/* Personaly I prefer do this at the beginning of S file. */kexec_reloc_size:
.long . -xen_relocate_kernelIt should work for C files and linker script.
This doesn't work, to the linker the value of kexec_reloc_size is its address.
David
PATCH v6 6/10 xen: kexec crash image when dom0 crashes
In reply to David VrabelFrom: 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
@@ -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
@@ -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
PATCH v6 7/10 libxc: add hypercall buffer arrays
In reply to David VrabelFrom: 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
@@ -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
@@ -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
PATCH v6 8/10 libxc: add API for kexec hypercall
In reply to David VrabelFrom: 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
@@ -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
PATCH v6 9/10 x86: check kexec relocation code fits in a page
In reply to David VrabelFrom: 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 | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
xen/arch/x86/xen.lds.S +4 -0
@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large") +#endif
Signature · 1 line
1.7.2.5
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
xen/arch/x86/xen.lds.S SECTIONS · line 192
Quoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/arch/x86/xen.lds.S +4
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large") +#endif
I don't recall having seen a mechanism to disable CONFIG_KEXEC, so why the conditional?
Jan
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
Quoted 14 lines · Jan Beulich
xen/arch/x86/xen.lds.S SECTIONS · line 192
Quoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/arch/x86/xen.lds.S +4
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large") +#endifI don't recall having seen a mechanism to disable
CONFIG_KEXEC, so why the conditional?
Quoted 1 line
Jan
CONFIG_KEXEC exists in include/asm-x86/config.h, but it turns out not to compile if you disable it.
I for one would not mind in the slightest if CONFIG_KEXEC disappeared.
~Andrew
Quoted 6 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
Quoted 16 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 13 lines · Jan Beulich
xen/arch/x86/xen.lds.S SECTIONS · line 192
Quoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/arch/x86/xen.lds.S +4
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large") +#endifI don't recall having seen a mechanism to disable
CONFIG_KEXEC, so why the conditional?
Quoted 2 lines
CONFIG_KEXECexists ininclude/asm-x86/config.h, but it turns out not to compile if you disable it.
This is more of an announcement than a knob for disabling (such that e.g. generic code can exclude respective pieces from getting built).
Quoted 1 line
I for one would not mind in the slightest if
CONFIG_KEXECdisappeared.
We should keep it at least as long as ARM doesn't support it, and perhaps even after to be prepared for new ports that (initially) don't have the necessary support bits.
Jan
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 13 lines · Jan Beulich
xen/arch/x86/xen.lds.S SECTIONS · line 192
Quoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/arch/x86/xen.lds.S +4
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large") +#endifI don't recall having seen a mechanism to disable
CONFIG_KEXEC, so why the conditional?
Quoted 6 lines
Quoted 2 lines
CONFIG_KEXECexists ininclude/asm-x86/config.h, but it turns out not to compile if you disable it.This is more of an announcement than a knob for disabling (such that e.g. generic code can exclude respective pieces from getting built).
It would have been better to call these things HAVE_FOO rather than CONFIG_FOO to avoid the implication of configurability, but that horse is long gone...
Quoted 14 lines
Quoted 2 lines
I for one would not mind in the slightest if
CONFIG_KEXECdisappeared.We should keep it at least as long as ARM doesn't support it, and perhaps even after to be prepared for new ports that (initially) don't have the necessary support bits.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
In reply to David VrabelQuoted 15 lines · 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.
Signed-off-by David Vrabel <[email protected]>--- xen/arch/x86/xen.lds.S | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)xen/arch/x86/xen.lds.S +0
-0
xen/arch/x86/xen.lds.S SECTIONS · line 191
Quoted 6 lines
xen/arch/x86/xen.lds.S +3
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large")
ASSERT(kexec_reloc_size <= KEXEC_CONTROL_PAGE_SIZE, "kexec control code is too large")
Daniel
Re: [PATCH 09/10] x86: check kexec relocation code fits in a page
Quoted 11 lines · Daniel Kiper
Quoted 10 lines · 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.
Signed-off-by David Vrabel <[email protected]>--- xen/arch/x86/xen.lds.S | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Quoted 13 lines
xen/arch/x86/xen.lds.S SECTIONS · line 191
Quoted 11 lines
xen/arch/x86/xen.lds.S +3
-0@@ -186,3 +186,7 @@ SECTIONS .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } } + +#ifdef CONFIG_KEXEC +ASSERT(__kexec_reloc_size <= PAGE_SIZE, "kexec control code is too large")
ASSERT(kexec_reloc_size <= KEXEC_CONTROL_PAGE_SIZE, "kexec control code is too large")
Huh. I thought I'd removed KEXEC_CONTROL_PAGE_SIZE but I see the #define is still there.
David
PATCH v6 10/10 MAINTAINERS: Add KEXEC maintainer
In reply to David VrabelFrom: David Vrabel <[email protected]>
--- MAINTAINERS | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
@@ -190,6 +190,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
Quoted 27 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.
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_v1sub-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_crashby 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.
Patch 9 adds a link time check for the size of the relocate code.
Quoted 7 lines
Patch 10 adds myself as the maintainer for kexec in Xen.
The required patch series for kexec-tools have previously been posted and this series has been rebased on the latest kexec-tools and is available from the xen-v3 branch of:
http://xenbits.xen.org/gitweb/?p=people/dvrabel/kexec-tools.git;a=summary
As you have picked up my one bugfix from the patch queue, please consider the entire series:
~Andrew
Quoted 37 lines
Changes since v5:
- Fix double free in
KEXEC_load_v1failure path.
- Only copy the relocation code and not the whole page.
- Add myself as the kexec maintainer.Changes since v4 (v5 was not posted to the list):
-
_rsvd->_padin 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 since v3:
- Use
paddr_tandpage_to_maddr()etc. for portability.
- Add explicit padding to hypercall structures where required.
- Minor cleanup of thekexec_relocassembly.
- 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 since v2:
- Provide old struct
xen_kexec_loadif__XEN_INTERFACE_VERSION__< 4.3
- Adjust new structxen_kexec_loadto avoid unnecessary padding.
- Use domheap pages for the image and control pages.
- Remove theDBG()macros from the reloc code.David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
On Mon, Jun 24, 2013 at 06:42:11PM +0100, David Vrabel wrote:
[...]
Quoted 5 lines
Changes since v4 (v5 was not posted to the list):
-
_rsvd->_padin 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.
Why? I do not see why trailing pages must be zeroed. I am afraid that this way you are only masking bug in kexec-tools. I think it is better to do bisect on it and find out which patch introduces a bug.
In general this series is OK but as I can see Jan has some comments this time. I think that it is worth to take most of them into account.
Please prepare next version of these patches and repost with kexec-tools patches. They are integral part of new Xen kexec implementation and it is worth to review both patch series together.
Daniel
PS I will be on holiday next week and I would not be able to do reviews.
Quoted 6 lines · Daniel Kiper
On Mon, Jun 24, 2013 at 06:42:11PM +0100, David Vrabel wrote:
[...]
Quoted 2 lines
Changes since v4 (v5 was not posted to the list):
Quoted 7 lines
Quoted 3 lines
-
_rsvd->_padin 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.Why? I do not see why trailing pages must be zeroed. I am afraid that this way you are only masking bug in kexec-tools. I think it is better to do bisect on it and find out which patch introduces a bug.
The load sub-ob is defined such that the range (dest_maddr + buf_size, dest_maddr + dest_size] is zeroed. If the caller asks for lots of trailing zeros then we should do this (regardless of how pointless this is). I do note that this is not very well documented and I will improve this.
kexec-tools calculates the checksum of the image including the trailing zeroed region which is why the exec would fail.
If you want to improve kexec-tools to load fewer zeroed pages, be my guest.
Quoted 3 lines
Please prepare next version of these patches and repost with kexec-tools patches. They are integral part of new Xen kexec implementation and it is worth to review both patch series together.
The kexec-tools patches haven't changed and I don't see any merit in reposting them until the Xen patches are applied.
David
Quoted 8 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 3 lines · Daniel Kiper
Please prepare next version of these patches and repost with kexec-tools patches. They are integral part of new Xen kexec implementation and it is worth to review both patch series together.
The kexec-tools patches haven't changed and I don't see any merit in reposting them until the Xen patches are applied.
So what if we apply the Xen patches, and then you're asked to do changes to the tools ones, requiring adjustments to the interface? Or if the tools side patches get rejected altogether? There certainly ought to be some mutual agreement that both will get applied in a certain (final) shape...
Jan