Commit 74ca317c26a3f8543203b61d262c0ab2e30c384e

Authored by Vivek Goyal
Committed by Linus Torvalds
1 parent b38af4721f

kexec: create a new config option CONFIG_KEXEC_FILE for new syscall

Currently new system call kexec_file_load() and all the associated code
compiles if CONFIG_KEXEC=y.  But new syscall also compiles purgatory
code which currently uses gcc option -mcmodel=large.  This option seems
to be available only gcc 4.4 onwards.

Hiding new functionality behind a new config option will not break
existing users of old gcc.  Those who wish to enable new functionality
will require new gcc.  Having said that, I am trying to figure out how
can I move away from using -mcmodel=large but that can take a while.

I think there are other advantages of introducing this new config
option.  As this option will be enabled only on x86_64, other arches
don't have to compile generic kexec code which will never be used.  This
new code selects CRYPTO=y and CRYPTO_SHA256=y.  And all other arches had
to do this for CONFIG_KEXEC.  Now with introduction of new config
option, we can remove crypto dependency from other arches.

Now CONFIG_KEXEC_FILE is available only on x86_64.  So whereever I had
CONFIG_X86_64 defined, I got rid of that.

For CONFIG_KEXEC_FILE, instead of doing select CRYPTO=y, I changed it to
"depends on CRYPTO=y".  This should be safer as "select" is not
recursive.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Tested-by: Shaun Ruffell <sruffell@digium.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 8 changed files with 42 additions and 20 deletions Side-by-side Diff

... ... @@ -17,7 +17,5 @@
17 17 obj-y += platform/
18 18 obj-y += net/
19 19  
20   -ifeq ($(CONFIG_X86_64),y)
21   -obj-$(CONFIG_KEXEC) += purgatory/
22   -endif
  20 +obj-$(CONFIG_KEXEC_FILE) += purgatory/
... ... @@ -1585,9 +1585,6 @@
1585 1585  
1586 1586 config KEXEC
1587 1587 bool "kexec system call"
1588   - select BUILD_BIN2C
1589   - select CRYPTO
1590   - select CRYPTO_SHA256
1591 1588 ---help---
1592 1589 kexec is a system call that implements the ability to shutdown your
1593 1590 current kernel, and to start another kernel. It is like a reboot
1594 1591  
... ... @@ -1602,9 +1599,22 @@
1602 1599 interface is strongly in flux, so no good recommendation can be
1603 1600 made.
1604 1601  
  1602 +config KEXEC_FILE
  1603 + bool "kexec file based system call"
  1604 + select BUILD_BIN2C
  1605 + depends on KEXEC
  1606 + depends on X86_64
  1607 + depends on CRYPTO=y
  1608 + depends on CRYPTO_SHA256=y
  1609 + ---help---
  1610 + This is new version of kexec system call. This system call is
  1611 + file based and takes file descriptors as system call argument
  1612 + for kernel and initramfs as opposed to list of segments as
  1613 + accepted by previous system call.
  1614 +
1605 1615 config KEXEC_VERIFY_SIG
1606 1616 bool "Verify kernel signature during kexec_file_load() syscall"
1607   - depends on KEXEC
  1617 + depends on KEXEC_FILE
1608 1618 ---help---
1609 1619 This option makes kernel signature verification mandatory for
1610 1620 kexec_file_load() syscall. If kernel is signature can not be
... ... @@ -184,11 +184,8 @@
184 184 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
185 185  
186 186 archprepare:
187   -ifeq ($(CONFIG_KEXEC),y)
188   -# Build only for 64bit. No loaders for 32bit yet.
189   - ifeq ($(CONFIG_X86_64),y)
  187 +ifeq ($(CONFIG_KEXEC_FILE),y)
190 188 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
191   - endif
192 189 endif
193 190  
194 191 ###
arch/x86/kernel/Makefile
... ... @@ -71,6 +71,7 @@
71 71 obj-$(CONFIG_X86_TSC) += trace_clock.o
72 72 obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o
73 73 obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o
  74 +obj-$(CONFIG_KEXEC_FILE) += kexec-bzimage64.o
74 75 obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o
75 76 obj-y += kprobes/
76 77 obj-$(CONFIG_MODULES) += module.o
... ... @@ -118,6 +119,5 @@
118 119  
119 120 obj-$(CONFIG_PCI_MMCONFIG) += mmconf-fam10h_64.o
120 121 obj-y += vsmp_64.o
121   - obj-$(CONFIG_KEXEC) += kexec-bzimage64.o
122 122 endif
arch/x86/kernel/crash.c
... ... @@ -182,8 +182,7 @@
182 182 crash_save_cpu(regs, safe_smp_processor_id());
183 183 }
184 184  
185   -#ifdef CONFIG_X86_64
186   -
  185 +#ifdef CONFIG_KEXEC_FILE
187 186 static int get_nr_ram_ranges_callback(unsigned long start_pfn,
188 187 unsigned long nr_pfn, void *arg)
189 188 {
... ... @@ -696,6 +695,5 @@
696 695  
697 696 return ret;
698 697 }
699   -
700   -#endif /* CONFIG_X86_64 */
  698 +#endif /* CONFIG_KEXEC_FILE */
arch/x86/kernel/machine_kexec_64.c
... ... @@ -25,9 +25,11 @@
25 25 #include <asm/debugreg.h>
26 26 #include <asm/kexec-bzimage64.h>
27 27  
  28 +#ifdef CONFIG_KEXEC_FILE
28 29 static struct kexec_file_ops *kexec_file_loaders[] = {
29 30 &kexec_bzImage64_ops,
30 31 };
  32 +#endif
31 33  
32 34 static void free_transition_pgtable(struct kimage *image)
33 35 {
... ... @@ -178,6 +180,7 @@
178 180 );
179 181 }
180 182  
  183 +#ifdef CONFIG_KEXEC_FILE
181 184 /* Update purgatory as needed after various image segments have been prepared */
182 185 static int arch_update_purgatory(struct kimage *image)
183 186 {
... ... @@ -209,6 +212,12 @@
209 212  
210 213 return ret;
211 214 }
  215 +#else /* !CONFIG_KEXEC_FILE */
  216 +static inline int arch_update_purgatory(struct kimage *image)
  217 +{
  218 + return 0;
  219 +}
  220 +#endif /* CONFIG_KEXEC_FILE */
212 221  
213 222 int machine_kexec_prepare(struct kimage *image)
214 223 {
... ... @@ -329,6 +338,7 @@
329 338  
330 339 /* arch-dependent functionality related to kexec file-based syscall */
331 340  
  341 +#ifdef CONFIG_KEXEC_FILE
332 342 int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
333 343 unsigned long buf_len)
334 344 {
... ... @@ -522,4 +532,5 @@
522 532 (int)ELF64_R_TYPE(rel[i].r_info), value);
523 533 return -ENOEXEC;
524 534 }
  535 +#endif /* CONFIG_KEXEC_FILE */
arch/x86/purgatory/Makefile
... ... @@ -24,8 +24,5 @@
24 24 $(call if_changed,bin2c)
25 25  
26 26  
27   -# No loaders for 32bits yet.
28   -ifeq ($(CONFIG_X86_64),y)
29   - obj-$(CONFIG_KEXEC) += kexec-purgatory.o
30   -endif
  27 +obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.o
... ... @@ -64,7 +64,9 @@
64 64 char __weak kexec_purgatory[0];
65 65 size_t __weak kexec_purgatory_size = 0;
66 66  
  67 +#ifdef CONFIG_KEXEC_FILE
67 68 static int kexec_calculate_store_digests(struct kimage *image);
  69 +#endif
68 70  
69 71 /* Location of the reserved area for the crash kernel */
70 72 struct resource crashk_res = {
... ... @@ -341,6 +343,7 @@
341 343 return ret;
342 344 }
343 345  
  346 +#ifdef CONFIG_KEXEC_FILE
344 347 static int copy_file_from_fd(int fd, void **buf, unsigned long *buf_len)
345 348 {
346 349 struct fd f = fdget(fd);
... ... @@ -612,6 +615,9 @@
612 615 kfree(image);
613 616 return ret;
614 617 }
  618 +#else /* CONFIG_KEXEC_FILE */
  619 +static inline void kimage_file_post_load_cleanup(struct kimage *image) { }
  620 +#endif /* CONFIG_KEXEC_FILE */
615 621  
616 622 static int kimage_is_destination_range(struct kimage *image,
617 623 unsigned long start,
... ... @@ -1375,6 +1381,7 @@
1375 1381 }
1376 1382 #endif
1377 1383  
  1384 +#ifdef CONFIG_KEXEC_FILE
1378 1385 SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
1379 1386 unsigned long, cmdline_len, const char __user *, cmdline_ptr,
1380 1387 unsigned long, flags)
... ... @@ -1451,6 +1458,8 @@
1451 1458 return ret;
1452 1459 }
1453 1460  
  1461 +#endif /* CONFIG_KEXEC_FILE */
  1462 +
1454 1463 void crash_kexec(struct pt_regs *regs)
1455 1464 {
1456 1465 /* Take the kexec_mutex here to prevent sys_kexec_load
... ... @@ -2006,6 +2015,7 @@
2006 2015  
2007 2016 subsys_initcall(crash_save_vmcoreinfo_init);
2008 2017  
  2018 +#ifdef CONFIG_KEXEC_FILE
2009 2019 static int __kexec_add_segment(struct kimage *image, char *buf,
2010 2020 unsigned long bufsz, unsigned long mem,
2011 2021 unsigned long memsz)
... ... @@ -2682,6 +2692,7 @@
2682 2692  
2683 2693 return 0;
2684 2694 }
  2695 +#endif /* CONFIG_KEXEC_FILE */
2685 2696  
2686 2697 /*
2687 2698 * Move into place and start executing a preloaded standalone