x86/microcode: Cleanup and late loading enhancements
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
- v5 Latest39 patches 3 repliesApplied
- v430 patches 7 repliesApplied
- v330 patches 39 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 1 of 2 patches | 0 replies | Superseded | |
| v1 | 2 patches | 3 replies | Superseded |
Patches in v5 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/39 | x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32()arch/ arch/ | +3 | 0 replies | |
| 2/39 | x86/boot: Use __pa_nodebug() in mk_early_pgtbl_32()arch/ | +6 | 0 replies | |
| 3/39 | x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()arch/ | +21 | 3 replies | |
| 4/39 | x86/boot/32: Restructure mk_early_pgtbl_32()arch/ | +23 | 0 replies | |
| 5/39 | x86/microcode: Provide CONFIG_MICROCODE_INITRD32arch/ | +4 | 0 replies | |
| 6/39 | x86/boot/32: Temporarily map initrd for microcode loadingarch/ arch/ | +54 | 0 replies | |
| 7/39 | x86/microcode/32: Move early loading after paging enablearch/ arch/ arch/ +6 more | +71 | 0 replies | |
| 8/39 | x86/microcode/intel: Rip out mixed stepping support for Intel CPUsarch/ arch/ arch/ +1 more | +35 | 0 replies | |
| 9/39 | x86/microcode/intel: Simplify scan_microcode()arch/ | +7 | 0 replies | |
| 10/39 | x86/microcode/intel: Simplify and rename generic_load_microcode()arch/ | +17 | 0 replies | |
| 11/39 | x86/microcode/intel: Cleanup code furtherarch/ | +32 | 0 replies | |
| 12/39 | x86/microcode/intel: Simplify early loadingarch/ arch/ arch/ | +63 | 0 replies | |
| 13/39 | x86/microcode/intel: Save the microcode only after a successful late-loadarch/ arch/ arch/ | +20 | 0 replies | |
| 14/39 | x86/microcode/intel: Switch to kvmalloc()arch/ | +25 | 0 replies | |
| 15/39 | x86/microcode/intel: Unify microcode apply() functionsarch/ | +37 | 0 replies | |
| 16/39 | x86/microcode/intel: Rework intel_cpu_collect_info()arch/ arch/ drivers/ | +14 | 0 replies | |
| 17/39 | x86/microcode/intel: Reuse intel_cpu_collect_info()arch/ | +1 | 0 replies | |
| 18/39 | x86/microcode/intel: Rework intel_find_matching_signature()arch/ arch/ drivers/ | +21 | 0 replies | |
| 19/39 | x86/microcode: Remove pointless apply() invocationarch/ | +6 | 0 replies | |
| 20/39 | x86/microcode/amd: Use correct per CPU ucode_cpu_infoarch/ | +3 | 0 replies | |
| 21/39 | x86/microcode/amd: Cache builtin microcode tooarch/ | +1 | 0 replies | |
| 22/39 | x86/microcode/amd: Cache builtin/initrd microcode earlyarch/ arch/ | +11 | 0 replies | |
| 23/39 | x86/microcode/amd: Use cached microcode for AP loadarch/ arch/ arch/ | +13 | 0 replies | |
| 24/39 | x86/microcode: Mop up early loading leftoversarch/ arch/ | +1 | 0 replies | |
| 25/39 | x86/microcode: Get rid of the schedule work indirectionarch/ | +10 | 0 replies | |
| 26/39 | x86/microcode: Clean up mc_cpu_down_prep()arch/ | +1 | 0 replies | |
| 27/39 | x86/microcode: Handle "nosmt" correctlyarch/ arch/ arch/ +1 more | +44 | 0 replies | |
| 28/39 | x86/microcode: Clarify the late load logicarch/ | +19 | 0 replies | |
| 29/39 | x86/microcode: Sanitize __wait_for_cpus()arch/ | +17 | 0 replies | |
| 30/39 | x86/microcode: Add per CPU result statearch/ arch/ | +67 | 0 replies | |
| 31/39 | x86/microcode: Add per CPU control fieldarch/ | +18 | 0 replies | |
| 32/39 | x86/microcode: Provide new control functionsarch/ | +84 | 0 replies | |
| 33/39 | x86/microcode: Replace the all-in-one rendevous handlerarch/ | +9 | 0 replies | |
| 34/39 | x86/microcode: Rendezvous and load in NMIarch/ arch/ arch/ +2 more | +57 | 0 replies | |
| 35/39 | x86/microcode: Protect against instrumentationarch/ | +83 | 0 replies | |
| 36/39 | x86/apic: Provide apic_force_nmi_on_cpu()arch/ arch/ arch/ +2 more | +16 | 0 replies | |
| 37/39 | x86/microcode: Handle "offline" CPUs correctlyarch/ arch/ arch/ +1 more | +113 | 0 replies | |
| 38/39 | x86/microcode: Prepare for minimal revision checkDocumentation/ arch/ arch/ +3 more | +49 | 0 replies | |
| 39/39 | x86/microcode/intel: Add a minimum required revision for late loadingarch/ arch/ | +35 | 0 replies |
Reviews trailers per patch
1 of 39 patches has a Reviewed-by or Acked-by.
| Patch | Thomas Gleixner | Nikolay Borisov |
|---|---|---|
| 1/39 | ||
| 2/39 | ||
| 3/39 | ||
| 4/39 | ||
| 5/39 | ||
| 6/39 | ||
| 7/39 | ||
| 8/39 | Originally-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/39 | R-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.
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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