s390/kexec_file: Add image loader
Add an image loader for kexec_file_load. For simplicity first skip crash support. The functions defined in machine_kexec_file will later be shared with the ELF loader. Signed-off-by: Philipp Rudo <prudo@linux.vnet.ibm.com> Reviewed-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
parent
71406883fd
commit
e49bb0a27f
|
@ -46,4 +46,26 @@
|
|||
static inline void crash_setup_regs(struct pt_regs *newregs,
|
||||
struct pt_regs *oldregs) { }
|
||||
|
||||
struct kimage;
|
||||
struct s390_load_data {
|
||||
/* Pointer to the kernel buffer. Used to register cmdline etc.. */
|
||||
void *kernel_buf;
|
||||
|
||||
/* Total size of loaded segments in memory. Used as an offset. */
|
||||
size_t memsz;
|
||||
|
||||
/* Load address of initrd. Used to register INITRD_START in kernel. */
|
||||
unsigned long initrd_load_addr;
|
||||
};
|
||||
|
||||
int kexec_file_add_purgatory(struct kimage *image,
|
||||
struct s390_load_data *data);
|
||||
int kexec_file_add_initrd(struct kimage *image,
|
||||
struct s390_load_data *data,
|
||||
char *initrd, unsigned long initrd_len);
|
||||
int *kexec_file_update_kernel(struct kimage *iamge,
|
||||
struct s390_load_data *data);
|
||||
|
||||
extern const struct kexec_file_ops s390_kexec_image_ops;
|
||||
|
||||
#endif /*_S390_KEXEC_H */
|
||||
|
|
|
@ -82,7 +82,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o
|
|||
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
|
||||
obj-$(CONFIG_UPROBES) += uprobes.o
|
||||
|
||||
obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o
|
||||
obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o
|
||||
|
||||
obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_cpum_cf.o perf_cpum_sf.o
|
||||
obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Image loader for kexec_file_load system call.
|
||||
*
|
||||
* Copyright IBM Corp. 2018
|
||||
*
|
||||
* Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
|
||||
*/
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kexec.h>
|
||||
#include <asm/setup.h>
|
||||
|
||||
static int kexec_file_add_image_kernel(struct kimage *image,
|
||||
struct s390_load_data *data,
|
||||
char *kernel, unsigned long kernel_len)
|
||||
{
|
||||
struct kexec_buf buf;
|
||||
int ret;
|
||||
|
||||
buf.image = image;
|
||||
|
||||
buf.buffer = kernel + STARTUP_NORMAL_OFFSET;
|
||||
buf.bufsz = kernel_len - STARTUP_NORMAL_OFFSET;
|
||||
|
||||
buf.mem = STARTUP_NORMAL_OFFSET;
|
||||
buf.memsz = buf.bufsz;
|
||||
|
||||
ret = kexec_add_buffer(&buf);
|
||||
|
||||
data->kernel_buf = kernel;
|
||||
data->memsz += buf.memsz + STARTUP_NORMAL_OFFSET;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *s390_image_load(struct kimage *image,
|
||||
char *kernel, unsigned long kernel_len,
|
||||
char *initrd, unsigned long initrd_len,
|
||||
char *cmdline, unsigned long cmdline_len)
|
||||
{
|
||||
struct s390_load_data data = {0};
|
||||
int ret;
|
||||
|
||||
/* We don't support crash kernels yet. */
|
||||
if (image->type == KEXEC_TYPE_CRASH)
|
||||
return ERR_PTR(-ENOTSUPP);
|
||||
|
||||
ret = kexec_file_add_image_kernel(image, &data, kernel, kernel_len);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
if (initrd) {
|
||||
ret = kexec_file_add_initrd(image, &data, initrd, initrd_len);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
ret = kexec_file_add_purgatory(image, &data);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
return kexec_file_update_kernel(image, &data);
|
||||
}
|
||||
|
||||
static int s390_image_probe(const char *buf, unsigned long len)
|
||||
{
|
||||
/* Can't reliably tell if an image is valid. Therefore give the
|
||||
* user whatever he wants.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct kexec_file_ops s390_kexec_image_ops = {
|
||||
.probe = s390_image_probe,
|
||||
.load = s390_image_load,
|
||||
};
|
|
@ -12,9 +12,84 @@
|
|||
#include <asm/setup.h>
|
||||
|
||||
const struct kexec_file_ops * const kexec_file_loaders[] = {
|
||||
&s390_kexec_image_ops,
|
||||
NULL,
|
||||
};
|
||||
|
||||
int *kexec_file_update_kernel(struct kimage *image,
|
||||
struct s390_load_data *data)
|
||||
{
|
||||
unsigned long *loc;
|
||||
|
||||
if (image->cmdline_buf_len >= ARCH_COMMAND_LINE_SIZE)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (image->cmdline_buf_len)
|
||||
memcpy(data->kernel_buf + COMMAND_LINE_OFFSET,
|
||||
image->cmdline_buf, image->cmdline_buf_len);
|
||||
|
||||
if (image->initrd_buf) {
|
||||
loc = (unsigned long *)(data->kernel_buf + INITRD_START_OFFSET);
|
||||
*loc = data->initrd_load_addr;
|
||||
|
||||
loc = (unsigned long *)(data->kernel_buf + INITRD_SIZE_OFFSET);
|
||||
*loc = image->initrd_buf_len;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int kexec_file_update_purgatory(struct kimage *image)
|
||||
{
|
||||
u64 entry, type;
|
||||
int ret;
|
||||
|
||||
entry = STARTUP_NORMAL_OFFSET;
|
||||
ret = kexec_purgatory_get_set_symbol(image, "kernel_entry", &entry,
|
||||
sizeof(entry), false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int kexec_file_add_purgatory(struct kimage *image, struct s390_load_data *data)
|
||||
{
|
||||
struct kexec_buf buf;
|
||||
int ret;
|
||||
|
||||
buf.image = image;
|
||||
|
||||
data->memsz = ALIGN(data->memsz, PAGE_SIZE);
|
||||
buf.mem = data->memsz;
|
||||
|
||||
ret = kexec_load_purgatory(image, &buf);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = kexec_file_update_purgatory(image);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data,
|
||||
char *initrd, unsigned long initrd_len)
|
||||
{
|
||||
struct kexec_buf buf;
|
||||
int ret;
|
||||
|
||||
buf.image = image;
|
||||
|
||||
buf.buffer = initrd;
|
||||
buf.bufsz = initrd_len;
|
||||
|
||||
data->memsz = ALIGN(data->memsz, PAGE_SIZE);
|
||||
buf.mem = data->memsz;
|
||||
buf.memsz = buf.bufsz;
|
||||
|
||||
data->initrd_load_addr = buf.mem;
|
||||
data->memsz += buf.memsz;
|
||||
|
||||
ret = kexec_add_buffer(&buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole
|
||||
* and provide kbuf->mem by hand.
|
||||
|
|
Loading…
Reference in New Issue