x86/microcode: Do the family check first

On CPUs like AMD's Geode, for example, we shouldn't even try to load
microcode because they do not support the modern microcode loading
interface.

However, we do the family check *after* the other checks whether the
loader has been disabled on the command line or whether we're running in
a guest.

So move the family checks first in order to exit early if we're being
loaded on an unsupported family.

Reported-and-tested-by: Sven Glodowski <glodi1@arcor.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org> # 4.11..
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://bugzilla.suse.com/show_bug.cgi?id=1061396
Link: http://lkml.kernel.org/r/20171012112316.977-1-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by Borislav Petkov and committed by Ingo Molnar 1f161f67 b956575b

Changed files
+18 -9
arch
x86
kernel
cpu
microcode
+18 -9
arch/x86/kernel/cpu/microcode/core.c
··· 122 122 bool *res = &dis_ucode_ldr; 123 123 #endif 124 124 125 - if (!have_cpuid_p()) 126 - return *res; 127 - 128 125 /* 129 126 * CPUID(1).ECX[31]: reserved for hypervisor use. This is still not 130 127 * completely accurate as xen pv guests don't see that CPUID bit set but ··· 163 166 void __init load_ucode_bsp(void) 164 167 { 165 168 unsigned int cpuid_1_eax; 169 + bool intel = true; 166 170 167 - if (check_loader_disabled_bsp()) 171 + if (!have_cpuid_p()) 168 172 return; 169 173 170 174 cpuid_1_eax = native_cpuid_eax(1); 171 175 172 176 switch (x86_cpuid_vendor()) { 173 177 case X86_VENDOR_INTEL: 174 - if (x86_family(cpuid_1_eax) >= 6) 175 - load_ucode_intel_bsp(); 178 + if (x86_family(cpuid_1_eax) < 6) 179 + return; 176 180 break; 181 + 177 182 case X86_VENDOR_AMD: 178 - if (x86_family(cpuid_1_eax) >= 0x10) 179 - load_ucode_amd_bsp(cpuid_1_eax); 183 + if (x86_family(cpuid_1_eax) < 0x10) 184 + return; 185 + intel = false; 180 186 break; 187 + 181 188 default: 182 - break; 189 + return; 183 190 } 191 + 192 + if (check_loader_disabled_bsp()) 193 + return; 194 + 195 + if (intel) 196 + load_ucode_intel_bsp(); 197 + else 198 + load_ucode_amd_bsp(cpuid_1_eax); 184 199 } 185 200 186 201 static bool check_loader_disabled_ap(void)