Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Image loader for kexec_file_load system call.
4 *
5 * Copyright IBM Corp. 2018
6 *
7 * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
8 */
9
10#include <linux/errno.h>
11#include <linux/kernel.h>
12#include <linux/kexec.h>
13#include <asm/setup.h>
14
15static int kexec_file_add_image_kernel(struct kimage *image,
16 struct s390_load_data *data,
17 char *kernel, unsigned long kernel_len)
18{
19 struct kexec_buf buf;
20 int ret;
21
22 buf.image = image;
23
24 buf.buffer = kernel + STARTUP_NORMAL_OFFSET;
25 buf.bufsz = kernel_len - STARTUP_NORMAL_OFFSET;
26
27 buf.mem = STARTUP_NORMAL_OFFSET;
28 if (image->type == KEXEC_TYPE_CRASH)
29 buf.mem += crashk_res.start;
30 buf.memsz = buf.bufsz;
31
32 ret = kexec_add_buffer(&buf);
33
34 data->kernel_buf = kernel;
35 data->memsz += buf.memsz + STARTUP_NORMAL_OFFSET;
36
37 return ret;
38}
39
40static void *s390_image_load(struct kimage *image,
41 char *kernel, unsigned long kernel_len,
42 char *initrd, unsigned long initrd_len,
43 char *cmdline, unsigned long cmdline_len)
44{
45 struct s390_load_data data = {0};
46 int ret;
47
48 ret = kexec_file_add_image_kernel(image, &data, kernel, kernel_len);
49 if (ret)
50 return ERR_PTR(ret);
51
52 if (initrd) {
53 ret = kexec_file_add_initrd(image, &data, initrd, initrd_len);
54 if (ret)
55 return ERR_PTR(ret);
56 }
57
58 ret = kexec_file_add_purgatory(image, &data);
59 if (ret)
60 return ERR_PTR(ret);
61
62 return kexec_file_update_kernel(image, &data);
63}
64
65static int s390_image_probe(const char *buf, unsigned long len)
66{
67 /* Can't reliably tell if an image is valid. Therefore give the
68 * user whatever he wants.
69 */
70 return 0;
71}
72
73const struct kexec_file_ops s390_kexec_image_ops = {
74 .probe = s390_image_probe,
75 .load = s390_image_load,
76};
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Image loader for kexec_file_load system call.
4 *
5 * Copyright IBM Corp. 2018
6 *
7 * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
8 */
9
10#include <linux/errno.h>
11#include <linux/kernel.h>
12#include <linux/kexec.h>
13#include <asm/ipl.h>
14#include <asm/setup.h>
15
16static int kexec_file_add_kernel_image(struct kimage *image,
17 struct s390_load_data *data)
18{
19 struct kexec_buf buf;
20
21 buf.image = image;
22
23 buf.buffer = image->kernel_buf;
24 buf.bufsz = image->kernel_buf_len;
25
26 buf.mem = 0;
27#ifdef CONFIG_CRASH_DUMP
28 if (image->type == KEXEC_TYPE_CRASH)
29 buf.mem += crashk_res.start;
30#endif
31 buf.memsz = buf.bufsz;
32
33 data->kernel_buf = image->kernel_buf;
34 data->kernel_mem = buf.mem;
35 data->parm = image->kernel_buf + PARMAREA;
36 data->memsz += buf.memsz;
37
38 ipl_report_add_component(data->report, &buf,
39 IPL_RB_COMPONENT_FLAG_SIGNED |
40 IPL_RB_COMPONENT_FLAG_VERIFIED,
41 IPL_RB_CERT_UNKNOWN);
42 return kexec_add_buffer(&buf);
43}
44
45static void *s390_image_load(struct kimage *image,
46 char *kernel, unsigned long kernel_len,
47 char *initrd, unsigned long initrd_len,
48 char *cmdline, unsigned long cmdline_len)
49{
50 return kexec_file_add_components(image, kexec_file_add_kernel_image);
51}
52
53static int s390_image_probe(const char *buf, unsigned long len)
54{
55 /* Can't reliably tell if an image is valid. Therefore give the
56 * user whatever he wants.
57 */
58 return 0;
59}
60
61const struct kexec_file_ops s390_kexec_image_ops = {
62 .probe = s390_image_probe,
63 .load = s390_image_load,
64#ifdef CONFIG_KEXEC_SIG
65 .verify_sig = s390_verify_sig,
66#endif /* CONFIG_KEXEC_SIG */
67};