Skip to content

x86/microcode: Cleanup and late loading enhancements

Thomas Gleixner lkml 2 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. v2 Latest37 patches 11 repliesApplied
  2. v130 patches 22 repliesSuperseded

Changes in v2 from the cover letter

- Reordered the queue - Nikolay

- Fixed the bogus condition - Borislav

- Moved more structs and defines into the source - Arjan

- Consolidated the exported functions

- Cleaned up the core initialization

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/37x86/mm: Remove unused microcode.h includearch/x86/mm/init.c+0 -10 replies
2/37x86/microcode: Hide the config knobarch/x86/Kconfig arch/x86/include/asm/microcode.h arch/x86/include/asm/microcode_amd.h +2 more+8 -444 replies
3/37x86/microcode/intel: Move microcode functions out of cpu/intel.carch/x86/include/asm/microcode_intel.h arch/x86/kernel/cpu/intel.c arch/x86/kernel/cpu/microcode/intel.c+204 -2002 replies
4/37x86/microcode: Include vendor headers into microcode.harch/x86/include/asm/microcode.h arch/x86/include/asm/microcode_amd.h arch/x86/include/asm/microcode_intel.h +6 more+7 -120 replies
5/37x86/microcode: Make reload_early_microcode() staticarch/x86/include/asm/microcode.h arch/x86/kernel/cpu/microcode/core.c+1 -30 replies
6/37x86/microcode/intel: Rename get_datasize() since its used externallyarch/x86/include/asm/microcode_intel.h arch/x86/kernel/cpu/microcode/intel.c drivers/platform/x86/intel/ifs/load.c+11 -90 replies
7/37x86/microcode: Move core specific defines to local headerarch/x86/include/asm/microcode.h arch/x86/include/asm/microcode_amd.h arch/x86/include/asm/microcode_intel.h +4 more+223 -2270 replies
8/37x86/microcode/intel: Remove debug codearch/x86/kernel/cpu/microcode/intel.c+0 -750 replies
9/37x86/microcode/intel: Remove pointless mutexarch/x86/kernel/cpu/microcode/intel.c+2 -222 replies
10/37x86/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+36 -1210 replies
11/37x86/microcode/intel: Simplify scan_microcode()arch/x86/kernel/cpu/microcode/intel.c+7 -210 replies
12/37x86/microcode/intel: Simplify and rename generic_load_microcode()arch/x86/kernel/cpu/microcode/intel.c+17 -302 replies
13/37x86/microcode/intel: Cleanup code furtherarch/x86/kernel/cpu/microcode/intel.c+33 -490 replies
14/37x86/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+86 -1110 replies
15/37x86/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
16/37x86/microcode/intel: Switch to kvmalloc()arch/x86/kernel/cpu/microcode/intel.c+32 -230 replies
17/37x86/microcode/intel: Unify microcode apply() functionsarch/x86/kernel/cpu/microcode/intel.c+36 -700 replies
18/37x86/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+17 -340 replies
19/37x86/microcode/intel: Reuse intel_cpu_collect_info()arch/x86/kernel/cpu/microcode/intel.c+1 -150 replies
20/37x86/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
21/37x86/microcode/amd: Read revision from hardware in collect_cpu_info_amd()arch/x86/kernel/cpu/microcode/amd.c+2 -20 replies
22/37x86/microcode: Remove pointless apply() invocationarch/x86/kernel/cpu/microcode/core.c include/linux/cpuhotplug.h+6 -290 replies
23/37x86/microcode: Get rid of the schedule work indirectionarch/x86/kernel/cpu/microcode/core.c+9 -190 replies
24/37x86/microcode: Clean up mc_cpu_down_prep()arch/x86/kernel/cpu/microcode/core.c+1 -70 replies
25/37x86/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
26/37x86/microcode: Clarify the late load logicarch/x86/kernel/cpu/microcode/core.c+17 -221 reply
27/37x86/microcode: Sanitize __wait_for_cpus()arch/x86/kernel/cpu/microcode/core.c+17 -240 replies
28/37x86/microcode: Add per CPU result statearch/x86/kernel/cpu/microcode/core.c arch/x86/kernel/cpu/microcode/internal.h+65 -440 replies
29/37x86/microcode: Add per CPU control fieldarch/x86/kernel/cpu/microcode/core.c+18 -20 replies
30/37x86/microcode: Provide new control functionsarch/x86/kernel/cpu/microcode/core.c+86 -00 replies
31/37x86/microcode: Replace the all in one rendevouz handlerarch/x86/kernel/cpu/microcode/core.c+9 -420 replies
32/37x86/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
33/37x86/microcode: Protect against instrumentationarch/x86/kernel/cpu/microcode/core.c+84 -280 replies
34/37x86/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+17 -10 replies
35/37x86/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
36/37x86/microcode: Prepare for minimal revision checkDocumentation/admin-guide/kernel-parameters.txt arch/x86/Kconfig arch/x86/kernel/cpu/microcode/amd.c +3 more+58 -80 replies
37/37x86/microcode/intel: Add a minimum required revision for late-loadsarch/x86/include/asm/microcode.h arch/x86/kernel/cpu/microcode/intel.c+35 -50 replies

Reviews trailers per patch

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

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

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [patch V2 00/37] x86/microcode: Cleanup and late loading enhancements

This is a follow up on:

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

Late microcode loading is desired by enterprise users. Late loading is problematic as it requires detailed knowledge about the change and an analysis whether this change modifies something which is already in use by the kernel. Large enterprise customers have engineering teams and access to deep technical vendor support. The regular admin does not have such resources, so the kernel has always tainted the kernel after late loading.

Intel recently added a new previously reserved field to the microcode header which contains the minimal microcode revision which must be running on the CPU to make the load safe. This field is 0 in all older microcode revisions, which the kernel assumes to be unsafe. Minimal revision checking can be enforced via Kconfig or kernel command line. It then refuses to load an unsafe revision. The default loads unsafe revisions like before and taints the kernel. If a safe revision is loaded the kernel is not tainted.

But that does not solve all other known problems with late loading:

- Late loading on current Intel CPUs is unsafe vs. NMI when hyperthreading is enabled. If a NMI hits the secondary sibling while the primary loads the microcode, the machine can crash.

- Soft offline SMT siblings which are playing dead with MWAIT can cause damage too when the microcode update modifies MWAIT. That's a realistic scenario in the context of 'nosmt' mitigations. :(

Neither the core code nor the Intel specific code handles any of this at all.

While trying to implement this, I stumbled over disfunctional, horribly complex and redundant code, which I decided to clean up first so the new functionality can be added on a clean slate.

So the series has several sections:

1) Cleanup core code, header files and Kconfig

2) Cleanup of the Intel specific code

3) Implementation of proper core control logic to handle the NMI safe requirements

4) Support for minimal revision check in the core and the Intel specific parts.

Thanks to Borislav for discussing this with me and helping out with testing. Thanks also to Ashok who contributed a few patches and helped with testing on the Intel side especially with the new minimal revision mechanism.

Changes vs. V1:

- Reordered the queue - Nikolay

- Fixed the bogus condition - Borislav

- Moved more structs and defines into the source - Arjan

- Consolidated the exported functions

- Cleaned up the core initialization

The series applies on:

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

and is also available from git:

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

Thanks,

tglx

---
 arch/x86/include/asm/microcode_amd.h              |   56 -
 arch/x86/include/asm/microcode_intel.h            |   88 --
 b/Documentation/admin-guide/kernel-parameters.txt |    5 
 b/arch/x86/Kconfig                                |   63 -
 b/arch/x86/include/asm/apic.h                     |    5 
 b/arch/x86/include/asm/cpu.h                      |   20 
 b/arch/x86/include/asm/microcode.h                |  160 +---
 b/arch/x86/kernel/apic/apic_flat_64.c             |    2 
 b/arch/x86/kernel/apic/ipi.c                      |    9 
 b/arch/x86/kernel/apic/x2apic_cluster.c           |    1 
 b/arch/x86/kernel/apic/x2apic_phys.c              |    1 
 b/arch/x86/kernel/cpu/common.c                    |    1 
 b/arch/x86/kernel/cpu/intel.c                     |  176 ----
 b/arch/x86/kernel/cpu/microcode/Makefile          |    4 
 b/arch/x86/kernel/cpu/microcode/amd.c             |   68 +
 b/arch/x86/kernel/cpu/microcode/core.c            |  576 ++++++++++----
 b/arch/x86/kernel/cpu/microcode/intel.c           |  847 ++++++++++------------
 b/arch/x86/kernel/cpu/microcode/internal.h        |  125 +++
 b/arch/x86/kernel/nmi.c                           |    9 
 b/arch/x86/mm/init.c                              |    1 
 b/drivers/platform/x86/intel/ifs/load.c           |   15 
 b/include/linux/cpuhotplug.h                      |    1 
 22 files changed, 1124 insertions(+), 1109 deletions(-)