[PATCH 5/5] kexec/xen: directly load images images into Xen

Daniel Kiper daniel.kiper at oracle.com
Tue Apr 9 17:20:36 EDT 2013


On Mon, Apr 08, 2013 at 08:06:54PM +0100, David Vrabel wrote:
> From: David Vrabel <david.vrabel at citrix.com>
>
> Xen 4.3 has an improvided kexec hypercall ABI that allows images to be
> loaded and executed without any kernel involvement.  Use the API
> provided by libxc to load images when running in a Xen guest.
>
> Support for loading images via the kexec_load syscall in non-upstream
> ("classic") Xen kernels is no longer supported.
>
> Signed-off-by: David Vrabel <david.vrabel at citrix.com>

[...]

> diff --git a/kexec/kexec-xen.c b/kexec/kexec-xen.c

[...]

> +int xen_kexec_load(uint64_t entry,
> +		   uint32_t nr_segments, struct kexec_segment *segments,
> +		   uint64_t kexec_flags)
> +{
> +	xc_interface *xch;
> +	xc_hypercall_buffer_array_t *array = NULL;
> +	uint8_t type;
> +	uint8_t arch;
> +	xen_kexec_segment_t *xen_segs;
> +	int s;
> +	int ret = -1;
> +
> +	xch = xc_interface_open(NULL, NULL, 0);
> +	if (!xch)
> +		return -1;
> +
> +	xen_segs = calloc(nr_segments, sizeof(*xen_segs));
> +	if (!xen_segs)
> +		goto out;
> +
> +	array = xc_hypercall_buffer_array_create(xch, nr_segments);
> +	if (array == NULL)
> +		goto out;
> +
> +	for (s = 0; s < nr_segments; s++) {
> +		DECLARE_HYPERCALL_BUFFER(void, seg_buf);
> +
> +		seg_buf = xc_hypercall_buffer_array_alloc(xch, array, s,
> +							  seg_buf, segments[s].bufsz);
> +		if (seg_buf == NULL)
> +			goto out;
> +		memcpy(seg_buf, segments[s].buf, segments[s].bufsz);
> +
> +		set_xen_guest_handle(xen_segs[s].buf, seg_buf);
> +		xen_segs[s].buf_size = segments[s].bufsz;
> +		xen_segs[s].dest_maddr = (uint64_t)segments[s].mem;
> +		xen_segs[s].dest_size = segments[s].memsz;
> +	}
> +
> +	type = kexec_flags & KEXEC_TYPE_CRASH;
> +	arch = (kexec_flags >> 16) & 0xffff;

arch = (kexec_flags & KEXEC_ARCH_MASK) >> 16;

Daniel



More information about the kexec mailing list