Skip to content

x86/microcode: Cleanup and late loading enhancements

Thomas Gleixner lkml 5 versions – Applied

Status from this message: The following commit has been merged into the x86/microcode branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest39 patches 3 repliesApplied
  2. v430 patches 7 repliesApplied
  3. v330 patches 39 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v21 of 2 patches0 repliesSuperseded
v12 patches3 repliesSuperseded

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/39x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32()arch/x86/kernel/Makefile arch/x86/kernel/head32.c+3 -10 replies
2/39x86/boot: Use __pa_nodebug() in mk_early_pgtbl_32()arch/x86/kernel/head32.c+6 -100 replies
3/39x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()arch/x86/kernel/head32.c+21 -173 replies
4/39x86/boot/32: Restructure mk_early_pgtbl_32()arch/x86/kernel/head32.c+23 -190 replies
5/39x86/microcode: Provide CONFIG_MICROCODE_INITRD32arch/x86/Kconfig+4 -00 replies
6/39x86/boot/32: Temporarily map initrd for microcode loadingarch/x86/include/asm/microcode.h arch/x86/kernel/head32.c+54 -20 replies
7/39x86/microcode/32: Move early loading after paging enablearch/x86/include/asm/microcode.h arch/x86/kernel/cpu/common.c arch/x86/kernel/cpu/microcode/amd.c +6 more+71 -2700 replies
8/39x86/microcode/intel: Rip out mixed stepping support for Intel CPUsarch/x86/kernel/cpu/microcode/amd.c arch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/intel.c +1 more+35 -1200 replies
9/39x86/microcode/intel: Simplify scan_microcode()arch/x86/kernel/cpu/microcode/intel.c+7 -210 replies
10/39x86/microcode/intel: Simplify and rename generic_load_microcode()arch/x86/kernel/cpu/microcode/intel.c+17 -300 replies
11/39x86/microcode/intel: Cleanup code furtherarch/x86/kernel/cpu/microcode/intel.c+32 -440 replies
12/39x86/microcode/intel: Simplify early loadingarch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/intel.c arch/x86/kernel/cpu/microcode/internal.h+63 -950 replies
13/39x86/microcode/intel: Save the microcode only after a successful late-loadarch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/intel.c arch/x86/kernel/cpu/microcode/internal.h+20 -150 replies
14/39x86/microcode/intel: Switch to kvmalloc()arch/x86/kernel/cpu/microcode/intel.c+25 -230 replies
15/39x86/microcode/intel: Unify microcode apply() functionsarch/x86/kernel/cpu/microcode/intel.c+37 -690 replies
16/39x86/microcode/intel: Rework intel_cpu_collect_info()arch/x86/include/asm/cpu.h arch/x86/kernel/cpu/microcode/intel.c drivers/platform/x86/intel/ifs/load.c+14 -310 replies
17/39x86/microcode/intel: Reuse intel_cpu_collect_info()arch/x86/kernel/cpu/microcode/intel.c+1 -150 replies
18/39x86/microcode/intel: Rework intel_find_matching_signature()arch/x86/include/asm/cpu.h arch/x86/kernel/cpu/microcode/intel.c drivers/platform/x86/intel/ifs/load.c+21 -280 replies
19/39x86/microcode: Remove pointless apply() invocationarch/x86/kernel/cpu/microcode/core.c+6 -170 replies
20/39x86/microcode/amd: Use correct per CPU ucode_cpu_infoarch/x86/kernel/cpu/microcode/amd.c+3 -30 replies
21/39x86/microcode/amd: Cache builtin microcode tooarch/x86/kernel/cpu/microcode/amd.c+1 -10 replies
22/39x86/microcode/amd: Cache builtin/initrd microcode earlyarch/x86/kernel/cpu/microcode/amd.c arch/x86/kernel/cpu/microcode/core.c+11 -170 replies
23/39x86/microcode/amd: Use cached microcode for AP loadarch/x86/kernel/cpu/microcode/amd.c arch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/internal.h+13 -240 replies
24/39x86/microcode: Mop up early loading leftoversarch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/internal.h+1 -170 replies
25/39x86/microcode: Get rid of the schedule work indirectionarch/x86/kernel/cpu/microcode/core.c+10 -190 replies
26/39x86/microcode: Clean up mc_cpu_down_prep()arch/x86/kernel/cpu/microcode/core.c+1 -70 replies
27/39x86/microcode: Handle "nosmt" correctlyarch/x86/Kconfig arch/x86/kernel/cpu/microcode/amd.c arch/x86/kernel/cpu/microcode/core.c +1 more+44 -310 replies
28/39x86/microcode: Clarify the late load logicarch/x86/kernel/cpu/microcode/core.c+19 -220 replies
29/39x86/microcode: Sanitize __wait_for_cpus()arch/x86/kernel/cpu/microcode/core.c+17 -220 replies
30/39x86/microcode: Add per CPU result statearch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/internal.h+67 -460 replies
31/39x86/microcode: Add per CPU control fieldarch/x86/kernel/cpu/microcode/core.c+18 -20 replies
32/39x86/microcode: Provide new control functionsarch/x86/kernel/cpu/microcode/core.c+84 -00 replies
33/39x86/microcode: Replace the all-in-one rendevous handlerarch/x86/kernel/cpu/microcode/core.c+9 -420 replies
34/39x86/microcode: Rendezvous and load in NMIarch/x86/include/asm/microcode.h arch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/intel.c +2 more+57 -50 replies
35/39x86/microcode: Protect against instrumentationarch/x86/kernel/cpu/microcode/core.c+83 -280 replies
36/39x86/apic: Provide apic_force_nmi_on_cpu()arch/x86/include/asm/apic.h arch/x86/kernel/apic/apic_flat_64.c arch/x86/kernel/apic/ipi.c +2 more+16 -10 replies
37/39x86/microcode: Handle "offline" CPUs correctlyarch/x86/include/asm/microcode.h arch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/internal.h +1 more+113 -60 replies
38/39x86/microcode: Prepare for minimal revision checkDocumentation/admin-guide/kernel-parameters.txt arch/x86/Kconfig arch/x86/kernel/cpu/microcode/amd.c +3 more+49 -60 replies
39/39x86/microcode/intel: Add a minimum required revision for late loadingarch/x86/include/asm/microcode.h arch/x86/kernel/cpu/microcode/intel.c+35 -50 replies

Reviews trailers per patch

1 of 39 patches has a Reviewed-by or Acked-by.

PatchThomas GleixnerNikolay Borisov
1/39
2/39
3/39
4/39
5/39
6/39
7/39
8/39Originally-by
9/39
10/39
11/39
12/39
13/39
14/39
15/39
16/39
17/39
18/39
19/39
20/39
21/39
22/39
23/39
24/39
25/39
26/39
27/39
28/39R-b
29/39
30/39
31/39
32/39
33/39
34/39
35/39
36/39
37/39
38/39
39/39

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [patch V5 00/39] x86/microcode: Cleanup and late loading enhancements

This is is a refresh of the microcode overhaul series V4:

https://lore.kernel.org/all/[email protected]/

combined with the follow up series for AMD:

https://lore.kernel.org/all/[email protected]

This refresh turned out to be necessary as the original series which had been applied to

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/microcode

turned out to have a serious flaw.

Moving the 32bit early loading after paging enable is broken due to a combination of a naive brainfart on my side, a test setup failure and the utter lack of general 32-bit test coverage.

Borislav noticed it by chance end of last week and I was able to cure it with a series on top, but we deciced to rebase the whole lot for the sake of bisectability and use the opportunity to fold the fixes and reshuffle the series so that the AMD cleanups are in front of the late loading changes.

The problem is simply that contrary to 64-bit, 32-bit cannot establish a initrd mapping via the early page fault handler and therefore initrd is not accessible after paging is enabled, especially not if the initrd is placed outside of the low-mem physical address space.

Bringing the pre paging early load mechanics back was not really an option as this prevents quite some major cleanups in the microcode loader and brings back all the undebuggable horrors in the affected code paths.

After debating and exploring some options it turned out that the final solution is pretty straight forward.

32-bit sets up the initial page tables from physical address 0 up to the end of the kernel image, which has the .brk section at the end, plus some extra margin to cover a complete low-mem direct page table. The end of this mapping space is saved in _brk_end, which is used by the subsequent initialization code to reserve memory. _brk_end is PMD/PGD (3/2 level) aligned. Anything after _brk_end is reused as regular memory space.

This part and the _brk_end mechanics are left unmodified. After that the initial page table setup code establishes a temporary mapping for the initrd right after _brk_end and stores the resulting virtual address for the early BSP microcode loader. After the loader completes, the mapping is zapped by invalidating the related PMD/PGD (3/2 level paging) entries in the initial page tables. As the actual PTE entries are located past _brk_end, they are just discarded and therefore is no memory wasted. As this happens right at the beginning of i386_start_kernel() which is the transition from ASM to C, the temporarily utilized PTE memory space and the resulting virtual addresses are not interfering with anything.

This also requires to undo the Intel specific optimization of saving the microcode blob address for later use in save_builtin_microcode().o That's required because initrd can be relocated, especially on 32-bit.

The series is also available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git ucode-v5

The delta patch against

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/microcode

is below. The head32.c changes in that delta patch are slightly hard to read, but the actual commits which rework that inital map code are fine granular and review friendly.

Though the delta shows nicely that the rest of the code, except for the initrd rescan in save_builtin_microcode() is not affected by these changes. The rescan change is harmless and has been tested extensively.

Thanks to Borislav for discussing this with me over the weekend and for his extensive testing on 32-bit (!PAE/PAE) in the past two days!

Thanks,

tglx
---

arch/x86/Kconfig +4 -0
index d8ff206e503f..cadea3f3161e 100644
@@ -1313,6 +1313,10 @@ config MICROCODE
 	def_bool y
 	depends on CPU_SUP_AMD || CPU_SUP_INTEL
 
+config MICROCODE_INITRD32
+	def_bool y
+	depends on MICROCODE && X86_32 && BLK_DEV_INITRD
+
 config MICROCODE_LATE_LOADING
 	bool "Late microcode loading (DANGEROUS)"
 	default n
arch/x86/include/asm/microcode.h +2 -0
index 7811efe53b5e..695e569159c1 100644
@@ -23,6 +23,8 @@ static inline void load_ucode_ap(void) { }
 static inline void microcode_bsp_resume(void) { }
 #endif
 
+extern unsigned long initrd_start_early;
+
 #ifdef CONFIG_CPU_SUP_INTEL
 /* Intel specific microcode defines. Public for IFS */
 struct microcode_header_intel {
arch/x86/kernel/cpu/microcode/amd.c +1 -1
index 8baa8cebc0b8..07f8ddd9209b 100644
@@ -530,7 +530,7 @@ static int __init save_microcode_in_initrd(void)
 	enum ucode_state ret;
 	struct cpio_data cp;
 
-	if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
+	if (dis_ucode_ldr || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
 		return 0;
 
 	find_blobs_in_containers(cpuid_1_eax, &cp);
arch/x86/kernel/cpu/microcode/core.c +3 -6
index 18e0cdd4f569..666d25bbc5ad 100644
@@ -44,7 +44,7 @@
 #define DRIVER_VERSION	"2.2"
 
 static struct microcode_ops	*microcode_ops;
-static bool dis_ucode_ldr = true;
+bool dis_ucode_ldr = true;
 
 bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV);
 module_param(force_minrev, bool, S_IRUSR | S_IWUSR);
@@ -191,12 +191,9 @@ struct cpio_data __init find_microcode_in_initrd(const char *path)
 
 #ifdef CONFIG_X86_32
 	size = boot_params.hdr.ramdisk_size;
-	/*
-	 * Set start only if we have an initrd image. We cannot use initrd_start
-	 * because it is not set that early yet.
-	 */
+	/* Early load on BSP has a temporary mapping. */
 	if (size)
-		start = boot_params.hdr.ramdisk_image;
+		start = initrd_start_early;
 
 #else /* CONFIG_X86_64 */
 	size  = (unsigned long)boot_params.ext_ramdisk_size << 32;
arch/x86/kernel/cpu/microcode/intel.c +7 -14
index d6311f0273fa..e99f129708da 100644
@@ -375,8 +375,6 @@ static __init struct microcode_intel *get_microcode_blob(struct ucode_cpu_info *
 	return scan_microcode(cp.data, cp.size, uci);
 }
 
-static struct microcode_intel *ucode_early_pa __initdata;
-
 /*
  * Invoked from an early init call to save the microcode blob which was
  * selected during early boot when mm was not usable. The microcode must be
@@ -386,13 +384,14 @@ static struct microcode_intel *ucode_early_pa __initdata;
  */
 static int __init save_builtin_microcode(void)
 {
-	struct microcode_intel *mc;
+	struct ucode_cpu_info uci;
 
-	if (!ucode_early_pa)
+	if (dis_ucode_ldr || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
 		return 0;
 
-	mc = __va((void *)ucode_early_pa);
-	save_microcode_patch(mc);
+	uci.mc = get_microcode_blob(&uci);
+	if (uci.mc)
+		save_microcode_patch(uci.mc);
 	return 0;
 }
 early_initcall(save_builtin_microcode);
@@ -403,14 +402,8 @@ void __init load_ucode_intel_bsp(void)
 	struct ucode_cpu_info uci;
 
 	uci.mc = get_microcode_blob(&uci);
-	if (!uci.mc)
-		return;
-
-	if (apply_microcode_early(&uci) != UCODE_UPDATED)
-		return;
-
-	/* Store the physical address as KASLR happens after this. */
-	ucode_early_pa = (struct microcode_intel *)__pa_nodebug(uci.mc);
+	if (uci.mc)
+		apply_microcode_early(&uci);
 }
 
 void load_ucode_intel_ap(void)
arch/x86/kernel/cpu/microcode/internal.h +3 -2
index fc03a7b39f18..f8047b12329a 100644
@@ -37,8 +37,6 @@ struct microcode_ops {
 				use_nmi		: 1;
 };
 
-extern bool force_minrev;
-
 extern struct ucode_cpu_info ucode_cpu_info[];
 struct cpio_data find_microcode_in_initrd(const char *path);
 
@@ -90,6 +88,9 @@ static inline unsigned int x86_cpuid_family(void)
 	return x86_family(eax);
 }
 
+extern bool dis_ucode_ldr;
+extern bool force_minrev;
+
 #ifdef CONFIG_CPU_SUP_AMD
 void load_ucode_amd_bsp(unsigned int family);
 void load_ucode_amd_ap(unsigned int family);
arch/x86/kernel/head32.c +84 -32

147 lines not on this page · raw message