aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2016-05-02 18:51:00 -0400
committerIngo Molnar <mingo@kernel.org>2016-05-03 02:15:58 -0400
commitdc425a6e140bca99bdb4823e9909c9d9b8ba36b6 (patch)
treeb8d0da2590a05c1afe45492277bfb5bb729e0e65 /arch/x86/boot
parent4abf061bf87bbd856c8d60199b2fba8b8f9b9fd6 (diff)
x86/boot: Extract error reporting functions
Currently to use warn(), a caller would need to include misc.h. However, this means they would get the (unavailable during compressed boot) gcc built-in memcpy family of functions. But since string.c is defining these memcpy functions for use by misc.c, we end up in a weird circular dependency. To break this loop, move the error reporting functions outside of misc.c with their own header so that they can be independently included by other sources. Since the screen-writing routines use memmove(), keep the low-level *_putstr() functions in misc.c. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Lasse Collin <lasse.collin@tukaani.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Yinghai Lu <yinghai@kernel.org> Link: http://lkml.kernel.org/r/1462229461-3370-2-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/compressed/Makefile2
-rw-r--r--arch/x86/boot/compressed/error.c22
-rw-r--r--arch/x86/boot/compressed/error.h7
-rw-r--r--arch/x86/boot/compressed/kaslr.c1
-rw-r--r--arch/x86/boot/compressed/misc.c18
-rw-r--r--arch/x86/boot/compressed/misc.h1
-rw-r--r--arch/x86/boot/compressed/string.c2
7 files changed, 34 insertions, 19 deletions
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 75f2233b8414..77ce3a04d46e 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -70,7 +70,7 @@ $(obj)/../voffset.h: vmlinux FORCE
70$(obj)/misc.o: $(obj)/../voffset.h 70$(obj)/misc.o: $(obj)/../voffset.h
71 71
72vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ 72vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
73 $(obj)/string.o $(obj)/cmdline.o \ 73 $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
74 $(obj)/piggy.o $(obj)/cpuflags.o 74 $(obj)/piggy.o $(obj)/cpuflags.o
75 75
76vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o 76vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
diff --git a/arch/x86/boot/compressed/error.c b/arch/x86/boot/compressed/error.c
new file mode 100644
index 000000000000..6248740b68b5
--- /dev/null
+++ b/arch/x86/boot/compressed/error.c
@@ -0,0 +1,22 @@
1/*
2 * Callers outside of misc.c need access to the error reporting routines,
3 * but the *_putstr() functions need to stay in misc.c because of how
4 * memcpy() and memmove() are defined for the compressed boot environment.
5 */
6#include "misc.h"
7
8void warn(char *m)
9{
10 error_putstr("\n\n");
11 error_putstr(m);
12 error_putstr("\n\n");
13}
14
15void error(char *m)
16{
17 warn(m);
18 error_putstr(" -- System halted");
19
20 while (1)
21 asm("hlt");
22}
diff --git a/arch/x86/boot/compressed/error.h b/arch/x86/boot/compressed/error.h
new file mode 100644
index 000000000000..2e59dac07f9e
--- /dev/null
+++ b/arch/x86/boot/compressed/error.h
@@ -0,0 +1,7 @@
1#ifndef BOOT_COMPRESSED_ERROR_H
2#define BOOT_COMPRESSED_ERROR_H
3
4void warn(char *m);
5void error(char *m);
6
7#endif /* BOOT_COMPRESSED_ERROR_H */
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8741a6d83bfe..f1818d95d726 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -10,6 +10,7 @@
10 * 10 *
11 */ 11 */
12#include "misc.h" 12#include "misc.h"
13#include "error.h"
13 14
14#include <asm/msr.h> 15#include <asm/msr.h>
15#include <asm/archrandom.h> 16#include <asm/archrandom.h>
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 8f0253d8c7ff..9536d778149e 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include "misc.h" 14#include "misc.h"
15#include "error.h"
15#include "../string.h" 16#include "../string.h"
16#include "../voffset.h" 17#include "../voffset.h"
17 18
@@ -36,7 +37,6 @@
36#define memmove memmove 37#define memmove memmove
37 38
38/* Functions used by the included decompressor code below. */ 39/* Functions used by the included decompressor code below. */
39static void error(char *m);
40void *memmove(void *dest, const void *src, size_t n); 40void *memmove(void *dest, const void *src, size_t n);
41 41
42/* 42/*
@@ -169,22 +169,6 @@ void __puthex(unsigned long value)
169 } 169 }
170} 170}
171 171
172void warn(char *m)
173{
174 error_putstr("\n\n");
175 error_putstr(m);
176 error_putstr("\n\n");
177}
178
179static void error(char *m)
180{
181 warn(m);
182 error_putstr(" -- System halted");
183
184 while (1)
185 asm("hlt");
186}
187
188#if CONFIG_X86_NEED_RELOCS 172#if CONFIG_X86_NEED_RELOCS
189static void handle_relocations(void *output, unsigned long output_len) 173static void handle_relocations(void *output, unsigned long output_len)
190{ 174{
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index e75f6cf9caaf..9887e0d4aaeb 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -35,7 +35,6 @@ extern memptr free_mem_end_ptr;
35extern struct boot_params *boot_params; 35extern struct boot_params *boot_params;
36void __putstr(const char *s); 36void __putstr(const char *s);
37void __puthex(unsigned long value); 37void __puthex(unsigned long value);
38void warn(char *m);
39#define error_putstr(__x) __putstr(__x) 38#define error_putstr(__x) __putstr(__x)
40#define error_puthex(__x) __puthex(__x) 39#define error_puthex(__x) __puthex(__x)
41 40
diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c
index 2befeca1aada..faa4dc7dc66b 100644
--- a/arch/x86/boot/compressed/string.c
+++ b/arch/x86/boot/compressed/string.c
@@ -5,6 +5,8 @@
5 * trust the gcc built-in implementations as they may do unexpected things 5 * trust the gcc built-in implementations as they may do unexpected things
6 * (e.g. FPU ops) in the minimal decompression stub execution environment. 6 * (e.g. FPU ops) in the minimal decompression stub execution environment.
7 */ 7 */
8#include "error.h"
9
8#include "../string.c" 10#include "../string.c"
9 11
10#ifdef CONFIG_X86_32 12#ifdef CONFIG_X86_32