1 From 4b703305d98bf7350d4b2953ee39a3aa2eeb1778 Mon Sep 17 00:00:00 2001
2 From: Borislav Petkov <bp@suse.de>
3 Date: Mon, 6 Jun 2016 17:10:43 +0200
4 Subject: x86/microcode: Fix suspend to RAM with builtin microcode
6 From: Borislav Petkov <bp@suse.de>
8 commit 4b703305d98bf7350d4b2953ee39a3aa2eeb1778 upstream.
10 Usually, after we have found the proper microcode blob for the current
11 machine, we stash it away for later use with save_microcode_in_initrd().
13 However, with builtin microcode which doesn't come from the initrd, we
14 don't call that function because CONFIG_BLK_DEV_INITRD=n and even if
15 set, we don't have a valid initrd.
17 In order to fix this, let's make save_microcode_in_initrd() an
18 fs_initcall which runs before rootfs_initcall() as this was the time it
19 was called previously through:
21 rootfs_initcall(populate_rootfs)
24 |-> save_microcode_in_initrd()
26 Also, we make it run independently from initrd functionality being
29 And since it is called in the microcode loader only now, we can also
32 Reported-and-tested-by: Jim Bos <jim876@xs4all.nl>
33 Signed-off-by: Borislav Petkov <bp@suse.de>
34 Cc: Andy Lutomirski <luto@amacapital.net>
35 Cc: Borislav Petkov <bp@alien8.de>
36 Cc: Brian Gerst <brgerst@gmail.com>
37 Cc: Denys Vlasenko <dvlasenk@redhat.com>
38 Cc: H. Peter Anvin <hpa@zytor.com>
39 Cc: Linus Torvalds <torvalds@linux-foundation.org>
40 Cc: Peter Zijlstra <peterz@infradead.org>
41 Cc: Thomas Gleixner <tglx@linutronix.de>
42 Link: http://lkml.kernel.org/r/1465225850-7352-3-git-send-email-bp@alien8.de
43 Signed-off-by: Ingo Molnar <mingo@kernel.org>
44 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47 arch/x86/include/asm/microcode.h | 2 --
48 arch/x86/kernel/cpu/microcode/core.c | 3 ++-
49 arch/x86/mm/init.c | 7 -------
50 3 files changed, 2 insertions(+), 10 deletions(-)
52 --- a/arch/x86/include/asm/microcode.h
53 +++ b/arch/x86/include/asm/microcode.h
54 @@ -133,13 +133,11 @@ static inline unsigned int x86_cpuid_fam
55 #ifdef CONFIG_MICROCODE
56 extern void __init load_ucode_bsp(void);
57 extern void load_ucode_ap(void);
58 -extern int __init save_microcode_in_initrd(void);
59 void reload_early_microcode(void);
60 extern bool get_builtin_firmware(struct cpio_data *cd, const char *name);
62 static inline void __init load_ucode_bsp(void) { }
63 static inline void load_ucode_ap(void) { }
64 -static inline int __init save_microcode_in_initrd(void) { return 0; }
65 static inline void reload_early_microcode(void) { }
67 get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; }
68 --- a/arch/x86/kernel/cpu/microcode/core.c
69 +++ b/arch/x86/kernel/cpu/microcode/core.c
70 @@ -175,7 +175,7 @@ void load_ucode_ap(void)
74 -int __init save_microcode_in_initrd(void)
75 +static int __init save_microcode_in_initrd(void)
77 struct cpuinfo_x86 *c = &boot_cpu_data;
79 @@ -691,4 +691,5 @@ int __init microcode_init(void)
83 +fs_initcall(save_microcode_in_initrd);
84 late_initcall(microcode_init);
85 --- a/arch/x86/mm/init.c
86 +++ b/arch/x86/mm/init.c
87 @@ -696,13 +696,6 @@ void free_initmem(void)
88 void __init free_initrd_mem(unsigned long start, unsigned long end)
91 - * Remember, initrd memory may contain microcode or other useful things.
92 - * Before we lose initrd mem, we need to find a place to hold them
93 - * now that normal virtual memory is enabled.
95 - save_microcode_in_initrd();
98 * end could be not aligned, and We can not align that,
99 * decompresser could be confused by aligned initrd_end
100 * We already reserve the end partial page before in