aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2018-04-13 18:35:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-13 20:10:27 -0400
commitb799a09f639beeda105fe8a9ab440d80fdabd3b3 (patch)
tree16528f3af3ad7e1dff4805083391cc4e9c28826f
parent1da4d377f943fe4194ffb9fb9c26cc58fad4dd24 (diff)
kexec_file: make use of purgatory optional
Patch series "kexec_file, x86, powerpc: refactoring for other architecutres", v2. This is a preparatory patchset for adding kexec_file support on arm64. It was originally included in a arm64 patch set[1], but Philipp is also working on their kexec_file support on s390[2] and some changes are now conflicting. So these common parts were extracted and put into a separate patch set for better integration. What's more, my original patch#4 was split into a few small chunks for easier review after Dave's comment. As such, the resulting code is basically identical with my original, and the only *visible* differences are: - renaming of _kexec_kernel_image_probe() and _kimage_file_post_load_cleanup() - change one of types of arguments at prepare_elf64_headers() Those, unfortunately, require a couple of trivial changes on the rest (#1, #6 to #13) of my arm64 kexec_file patch set[1]. Patch #1 allows making a use of purgatory optional, particularly useful for arm64. Patch #2 commonalizes arch_kexec_kernel_{image_probe, image_load, verify_sig}() and arch_kimage_file_post_load_cleanup() across architectures. Patches #3-#7 are also intended to generalize parse_elf64_headers(), along with exclude_mem_range(), to be made best re-use of. [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-February/561182.html [2] http://lkml.iu.edu//hypermail/linux/kernel/1802.1/02596.html This patch (of 7): On arm64, crash dump kernel's usable memory is protected by *unmapping* it from kernel virtual space unlike other architectures where the region is just made read-only. It is highly unlikely that the region is accidentally corrupted and this observation rationalizes that digest check code can also be dropped from purgatory. The resulting code is so simple as it doesn't require a bit ugly re-linking/relocation stuff, i.e. arch_kexec_apply_relocations_add(). Please see: http://lists.infradead.org/pipermail/linux-arm-kernel/2017-December/545428.html All that the purgatory does is to shuffle arguments and jump into a new kernel, while we still need to have some space for a hash value (purgatory_sha256_digest) which is never checked against. As such, it doesn't make sense to have trampline code between old kernel and new kernel on arm64. This patch introduces a new configuration, ARCH_HAS_KEXEC_PURGATORY, and allows related code to be compiled in only if necessary. [takahiro.akashi@linaro.org: fix trivial screwup] Link: http://lkml.kernel.org/r/20180309093346.GF25863@linaro.org Link: http://lkml.kernel.org/r/20180306102303.9063-2-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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/powerpc/Kconfig3
-rw-r--r--arch/x86/Kconfig3
-rw-r--r--kernel/kexec_file.c5
3 files changed, 11 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 73ce5dd07642..c32a181a7cbb 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -552,6 +552,9 @@ config KEXEC_FILE
552 for kernel and initramfs as opposed to a list of segments as is the 552 for kernel and initramfs as opposed to a list of segments as is the
553 case for the older kexec call. 553 case for the older kexec call.
554 554
555config ARCH_HAS_KEXEC_PURGATORY
556 def_bool KEXEC_FILE
557
555config RELOCATABLE 558config RELOCATABLE
556 bool "Build a relocatable kernel" 559 bool "Build a relocatable kernel"
557 depends on PPC64 || (FLATMEM && (44x || FSL_BOOKE)) 560 depends on PPC64 || (FLATMEM && (44x || FSL_BOOKE))
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index d234cca296db..7fe107f5990b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2008,6 +2008,9 @@ config KEXEC_FILE
2008 for kernel and initramfs as opposed to list of segments as 2008 for kernel and initramfs as opposed to list of segments as
2009 accepted by previous system call. 2009 accepted by previous system call.
2010 2010
2011config ARCH_HAS_KEXEC_PURGATORY
2012 def_bool KEXEC_FILE
2013
2011config KEXEC_VERIFY_SIG 2014config KEXEC_VERIFY_SIG
2012 bool "Verify kernel signature during kexec_file_load() syscall" 2015 bool "Verify kernel signature during kexec_file_load() syscall"
2013 depends on KEXEC_FILE 2016 depends on KEXEC_FILE
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index e5bcd94c1efb..ab1dced677fd 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -532,6 +532,9 @@ static int kexec_calculate_store_digests(struct kimage *image)
532 struct kexec_sha_region *sha_regions; 532 struct kexec_sha_region *sha_regions;
533 struct purgatory_info *pi = &image->purgatory_info; 533 struct purgatory_info *pi = &image->purgatory_info;
534 534
535 if (!IS_ENABLED(CONFIG_ARCH_HAS_KEXEC_PURGATORY))
536 return 0;
537
535 zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT); 538 zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
536 zero_buf_sz = PAGE_SIZE; 539 zero_buf_sz = PAGE_SIZE;
537 540
@@ -633,6 +636,7 @@ out:
633 return ret; 636 return ret;
634} 637}
635 638
639#ifdef CONFIG_ARCH_HAS_KEXEC_PURGATORY
636/* Actually load purgatory. Lot of code taken from kexec-tools */ 640/* Actually load purgatory. Lot of code taken from kexec-tools */
637static int __kexec_load_purgatory(struct kimage *image, unsigned long min, 641static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
638 unsigned long max, int top_down) 642 unsigned long max, int top_down)
@@ -1022,3 +1026,4 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
1022 1026
1023 return 0; 1027 return 0;
1024} 1028}
1029#endif /* CONFIG_ARCH_HAS_KEXEC_PURGATORY */