Commit 29a5c67e7a78815fda0567a867adce467f6e6e5a

Authored by maximilian attems
Committed by Linus Torvalds
1 parent e4cc2f873a

kexec: export kexec.h to user space

Add userspace definitions, guard all relevant kernel structures.  While at
it document stuff and remove now useless userspace hint.

It is easy to add the relevant system call to respective libc's, but it
seems pointless to have to duplicate the data structures.

This is based on the kexec-tools headers, with the exception of just using
int on return (succes or failure) and using size_t instead of 'unsigned
long int' for the number of segments argument of kexec_load().

Signed-off-by: maximilian attems <max@stro.at>
Cc: Simon Horman <horms@verge.net.au>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Haren Myneni <hbabu@us.ibm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 54 additions and 22 deletions Side-by-side Diff

include/linux/Kbuild
... ... @@ -226,6 +226,7 @@
226 226 header-y += kernel.h
227 227 header-y += kernelcapi.h
228 228 header-y += kernel-page-flags.h
  229 +header-y += kexec.h
229 230 header-y += keyboard.h
230 231 header-y += keyctl.h
231 232 header-y += l2tp.h
include/linux/kexec.h
1 1 #ifndef LINUX_KEXEC_H
2 2 #define LINUX_KEXEC_H
3 3  
4   -#ifdef CONFIG_KEXEC
  4 +/* kexec system call - It loads the new kernel to boot into.
  5 + * kexec does not sync, or unmount filesystems so if you need
  6 + * that to happen you need to do that yourself.
  7 + */
  8 +
5 9 #include <linux/types.h>
  10 +
  11 +/* kexec flags for different usage scenarios */
  12 +#define KEXEC_ON_CRASH 0x00000001
  13 +#define KEXEC_PRESERVE_CONTEXT 0x00000002
  14 +#define KEXEC_ARCH_MASK 0xffff0000
  15 +
  16 +/* These values match the ELF architecture values.
  17 + * Unless there is a good reason that should continue to be the case.
  18 + */
  19 +#define KEXEC_ARCH_DEFAULT ( 0 << 16)
  20 +#define KEXEC_ARCH_386 ( 3 << 16)
  21 +#define KEXEC_ARCH_X86_64 (62 << 16)
  22 +#define KEXEC_ARCH_PPC (20 << 16)
  23 +#define KEXEC_ARCH_PPC64 (21 << 16)
  24 +#define KEXEC_ARCH_IA_64 (50 << 16)
  25 +#define KEXEC_ARCH_ARM (40 << 16)
  26 +#define KEXEC_ARCH_S390 (22 << 16)
  27 +#define KEXEC_ARCH_SH (42 << 16)
  28 +#define KEXEC_ARCH_MIPS_LE (10 << 16)
  29 +#define KEXEC_ARCH_MIPS ( 8 << 16)
  30 +
  31 +/* The artificial cap on the number of segments passed to kexec_load. */
  32 +#define KEXEC_SEGMENT_MAX 16
  33 +
  34 +#ifndef __KERNEL__
  35 +/*
  36 + * This structure is used to hold the arguments that are used when
  37 + * loading kernel binaries.
  38 + */
  39 +struct kexec_segment {
  40 + const void *buf;
  41 + size_t bufsz;
  42 + const void *mem;
  43 + size_t memsz;
  44 +};
  45 +
  46 +/* Load a new kernel image as described by the kexec_segment array
  47 + * consisting of passed number of segments at the entry-point address.
  48 + * The flags allow different useage types.
  49 + */
  50 +extern int kexec_load(void *, size_t, struct kexec_segment *,
  51 + unsigned long int);
  52 +#endif /* __KERNEL__ */
  53 +
  54 +#ifdef __KERNEL__
  55 +#ifdef CONFIG_KEXEC
6 56 #include <linux/list.h>
7 57 #include <linux/linkage.h>
8 58 #include <linux/compat.h>
9 59  
... ... @@ -67,11 +117,10 @@
67 117 #define IND_DONE 0x4
68 118 #define IND_SOURCE 0x8
69 119  
70   -#define KEXEC_SEGMENT_MAX 16
71 120 struct kexec_segment {
72 121 void __user *buf;
73 122 size_t bufsz;
74   - unsigned long mem; /* User space sees this as a (void *) ... */
  123 + unsigned long mem;
75 124 size_t memsz;
76 125 };
77 126  
... ... @@ -175,25 +224,6 @@
175 224 #define kexec_flush_icache_page(page)
176 225 #endif
177 226  
178   -#define KEXEC_ON_CRASH 0x00000001
179   -#define KEXEC_PRESERVE_CONTEXT 0x00000002
180   -#define KEXEC_ARCH_MASK 0xffff0000
181   -
182   -/* These values match the ELF architecture values.
183   - * Unless there is a good reason that should continue to be the case.
184   - */
185   -#define KEXEC_ARCH_DEFAULT ( 0 << 16)
186   -#define KEXEC_ARCH_386 ( 3 << 16)
187   -#define KEXEC_ARCH_X86_64 (62 << 16)
188   -#define KEXEC_ARCH_PPC (20 << 16)
189   -#define KEXEC_ARCH_PPC64 (21 << 16)
190   -#define KEXEC_ARCH_IA_64 (50 << 16)
191   -#define KEXEC_ARCH_ARM (40 << 16)
192   -#define KEXEC_ARCH_S390 (22 << 16)
193   -#define KEXEC_ARCH_SH (42 << 16)
194   -#define KEXEC_ARCH_MIPS_LE (10 << 16)
195   -#define KEXEC_ARCH_MIPS ( 8 << 16)
196   -
197 227 /* List of defined/legal kexec flags */
198 228 #ifndef CONFIG_KEXEC_JUMP
199 229 #define KEXEC_FLAGS KEXEC_ON_CRASH
... ... @@ -228,5 +258,6 @@
228 258 static inline void crash_kexec(struct pt_regs *regs) { }
229 259 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
230 260 #endif /* CONFIG_KEXEC */
  261 +#endif /* __KERNEL__ */
231 262 #endif /* LINUX_KEXEC_H */