summaryrefslogtreecommitdiffstats
path: root/kernel/kexec_file.c
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2018-04-13 18:35:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-13 20:10:27 -0400
commit9ec4ecef0af7790551109283ca039a7c52de343c (patch)
tree449f1e0764c03e53bd22c97a911695a118905d62 /kernel/kexec_file.c
parentb799a09f639beeda105fe8a9ab440d80fdabd3b3 (diff)
kexec_file,x86,powerpc: factor out kexec_file_ops functions
As arch_kexec_kernel_image_{probe,load}(), arch_kimage_file_post_load_cleanup() and arch_kexec_kernel_verify_sig() are almost duplicated among architectures, they can be commonalized with an architecture-defined kexec_file_ops array. So let's factor them out. Link: http://lkml.kernel.org/r/20180306102303.9063-3-takahiro.akashi@linaro.org Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Acked-by: Dave Young <dyoung@redhat.com> Tested-by: Dave Young <dyoung@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Baoquan He <bhe@redhat.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/kexec_file.c')
-rw-r--r--kernel/kexec_file.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index ab1dced677fd..332c4fd12cb1 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -28,28 +28,80 @@
28 28
29static int kexec_calculate_store_digests(struct kimage *image); 29static int kexec_calculate_store_digests(struct kimage *image);
30 30
31/*
32 * Currently this is the only default function that is exported as some
33 * architectures need it to do additional handlings.
34 * In the future, other default functions may be exported too if required.
35 */
36int kexec_image_probe_default(struct kimage *image, void *buf,
37 unsigned long buf_len)
38{
39 const struct kexec_file_ops * const *fops;
40 int ret = -ENOEXEC;
41
42 for (fops = &kexec_file_loaders[0]; *fops && (*fops)->probe; ++fops) {
43 ret = (*fops)->probe(buf, buf_len);
44 if (!ret) {
45 image->fops = *fops;
46 return ret;
47 }
48 }
49
50 return ret;
51}
52
31/* Architectures can provide this probe function */ 53/* Architectures can provide this probe function */
32int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, 54int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
33 unsigned long buf_len) 55 unsigned long buf_len)
34{ 56{
35 return -ENOEXEC; 57 return kexec_image_probe_default(image, buf, buf_len);
58}
59
60static void *kexec_image_load_default(struct kimage *image)
61{
62 if (!image->fops || !image->fops->load)
63 return ERR_PTR(-ENOEXEC);
64
65 return image->fops->load(image, image->kernel_buf,
66 image->kernel_buf_len, image->initrd_buf,
67 image->initrd_buf_len, image->cmdline_buf,
68 image->cmdline_buf_len);
36} 69}
37 70
38void * __weak arch_kexec_kernel_image_load(struct kimage *image) 71void * __weak arch_kexec_kernel_image_load(struct kimage *image)
39{ 72{
40 return ERR_PTR(-ENOEXEC); 73 return kexec_image_load_default(image);
74}
75
76static int kexec_image_post_load_cleanup_default(struct kimage *image)
77{
78 if (!image->fops || !image->fops->cleanup)
79 return 0;
80
81 return image->fops->cleanup(image->image_loader_data);
41} 82}
42 83
43int __weak arch_kimage_file_post_load_cleanup(struct kimage *image) 84int __weak arch_kimage_file_post_load_cleanup(struct kimage *image)
44{ 85{
45 return -EINVAL; 86 return kexec_image_post_load_cleanup_default(image);
46} 87}
47 88
48#ifdef CONFIG_KEXEC_VERIFY_SIG 89#ifdef CONFIG_KEXEC_VERIFY_SIG
90static int kexec_image_verify_sig_default(struct kimage *image, void *buf,
91 unsigned long buf_len)
92{
93 if (!image->fops || !image->fops->verify_sig) {
94 pr_debug("kernel loader does not support signature verification.\n");
95 return -EKEYREJECTED;
96 }
97
98 return image->fops->verify_sig(buf, buf_len);
99}
100
49int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, 101int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
50 unsigned long buf_len) 102 unsigned long buf_len)
51{ 103{
52 return -EKEYREJECTED; 104 return kexec_image_verify_sig_default(image, buf, buf_len);
53} 105}
54#endif 106#endif
55 107