]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
s390/kexec_file: Add image loader
authorPhilipp Rudo <prudo@linux.vnet.ibm.com>
Wed, 30 Aug 2017 12:03:38 +0000 (14:03 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 16 Apr 2018 07:10:22 +0000 (09:10 +0200)
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>
arch/s390/include/asm/kexec.h
arch/s390/kernel/Makefile
arch/s390/kernel/kexec_image.c [new file with mode: 0644]
arch/s390/kernel/machine_kexec_file.c

index 1d708a419326eaf8e400e8be3e430301c3e0035e..4c9da9974cf4c3cf5453778d002e827a10a553fa 100644 (file)
 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 */
index 35bec1ab84e387d39f595cfe9b84801ef8a9d28f..a84e9611c5c749c2419ff88a2e18bc66ed989ffc 100644 (file)
@@ -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
diff --git a/arch/s390/kernel/kexec_image.c b/arch/s390/kernel/kexec_image.c
new file mode 100644 (file)
index 0000000..7f5021e
--- /dev/null
@@ -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,
+};
index d9b4f9d23e9ff6a9deb2c222a409a413b31aafac..2a2ceece77b0637742d2b09d4e3db364ba5247a5 100644 (file)
 #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.