Skip to content

init, treewide, x86: Cleanup check_bugs() and start sanitizing the x86 boot process

Thomas Gleixner linux-arm-kernel linux-ia64 linux-m68k linux-mips linux-sh linux-um lkml loongarch sparclinux 1 version Applied

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

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest17 patches 27 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/17init: Provide arch_cpu_finalize_init()arch/Kconfig include/linux/cpu.h init/main.c+13 -01 reply
2/17x86/cpu: Switch to arch_cpu_finalize_init()arch/x86/Kconfig arch/x86/include/asm/bugs.h arch/x86/kernel/cpu/bugs.c +2 more+56 -522 replies
3/17ARM: cpu: Switch to arch_cpu_finalize_init()arch/arm/Kconfig arch/arm/include/asm/bugs.h arch/arm/kernel/bugs.c+3 -51 reply
4/17ia64/cpu: Switch to arch_cpu_finalize_init()arch/ia64/Kconfig arch/ia64/include/asm/bugs.h arch/ia64/kernel/setup.c+2 -221 reply
5/17loongarch/cpu: Switch to arch_cpu_finalize_init()arch/loongarch/Kconfig arch/loongarch/include/asm/bugs.h arch/loongarch/kernel/setup.c+3 -171 reply
6/17m68k/cpu: Switch to arch_cpu_finalize_init()arch/m68k/Kconfig arch/m68k/include/asm/bugs.h arch/m68k/kernel/setup_mm.c+3 -221 reply
7/17mips/cpu: Switch to arch_cpu_finalize_init()arch/mips/Kconfig arch/mips/include/asm/bugs.h arch/mips/kernel/setup.c+14 -171 reply
8/17sh/cpu: Switch to arch_cpu_finalize_init()arch/sh/Kconfig arch/sh/include/asm/bugs.h arch/sh/include/asm/processor.h +2 more+59 -742 replies
9/17sparc/cpu: Switch to arch_cpu_finalize_init()arch/sparc/Kconfig arch/sparc/include/asm/bugs.h arch/sparc/kernel/setup_32.c+8 -182 replies
10/17um/cpu: Switch to arch_cpu_finalize_init()arch/um/Kconfig arch/um/include/asm/bugs.h arch/um/kernel/um_arch.c+3 -82 replies
11/17init: Remove check_bugs() leftoversarch/alpha/include/asm/bugs.h arch/parisc/include/asm/bugs.h arch/powerpc/include/asm/bugs.h +3 more+0 -892 replies
12/17init: Invoke arch_cpu_finalize_init() earlierinit/main.c+2 -22 replies
13/17init, x86: Move mem_encrypt_init() into arch_cpu_finalize_init()arch/x86/include/asm/mem_encrypt.h arch/x86/kernel/cpu/common.c init/main.c+15 -161 reply
14/17x86/init: Initialize signal frame size latearch/x86/include/asm/sigframe.h arch/x86/kernel/cpu/common.c arch/x86/kernel/signal.c+3 -60 replies
15/17x86/fpu: Remove cpuinfo argument from init functionsarch/x86/include/asm/fpu/api.h arch/x86/kernel/cpu/common.c arch/x86/kernel/fpu/init.c+5 -50 replies
16/17x86/fpu: Mark init functions __initarch/x86/kernel/fpu/init.c+2 -20 replies
17/17x86/fpu: Move FPU initialization into arch_cpu_finalize_init()arch/x86/kernel/cpu/common.c+8 -47 replies

Reviews trailers per patch

12 of 17 patches have a Reviewed-by or Acked-by.

PatchRichard HendersonRichard WeinbergerGeert UytterhoevenBorislav Petkov (AMD)Sam RavnborgRick EdgecombeTom LendackyPhilippe Mathieu-DaudéJohn Paul Adrian Glaubitz
1/17
2/17R-b
3/17R-b
4/17R-b
5/17R-b
6/17A-b
7/17R-b
8/17R-b A-b
9/17R-b R-b
10/17A-b R-b
11/17R-b R-b
12/17R-b
13/17R-b
14/17
15/17
16/17
17/17

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

Read the v1 thread

Cover letter [patch 00/17] init, treewide, x86: Cleanup check_bugs() and start sanitizing the x86 boot process

Hi!

My team and myself are working on sanitizing the x86 boot process, especially the complete horror show of CPUID evaluation, which is constructed with hay-wire circuits, duct tape and superglue.

A related goal is to move the initialization of infrastructure which is not required during early boot out into a later phase of the boot process. Early boot is fragile and convoluted enough already, so anything which can move into a later phase is a win.

X86 FPU initialization is one of the obvious parts which has zero justification to be done early. The only requirement is that it happens before alternative patching. Doing it early also requires custom command line parsing which can be obviously avoided when the initialization happens later.

Alternative patching happens from check_bugs() which is invoked late in start_kernel(). Moving FPU initialization into that is too late because check_bugs() is invoked after fork_init(), but fork_init() requires that the FPU is initialized on X86 as on X86 the size of task_struct depends on the FPU register buffer size.

In order to avoid another magic function we set out to move check_bugs() earlier and inspected all incarnations whether there is any reason to do that so late. It turned out there is none (famous last words), but it also revealed that check_bugs() is a gross misnomer.

check_bugs() has become a dump ground for finalizing the CPU initialization before running the rest of the init code.

Most implementations are empty, a few do actual bug checks, some do alternative patching and one cobbles a CPU advertisment string together...

As a consequence we decided to rename it to arch_cpu_finalize_init(). The purely mechanical 's/check_bugs/arch_cpu_finalize_init/' would have been trivial, but having stared at the actual implementations of check_bugs() had triggered the scavenger reflex already. So I got the mop out and cleaned it up completely.

The resulting series consists therefore of three parts:

1) Patches 1-11

Rename and mop up check_bugs() which removes a solid amount of redundant historical copy & pasta crud:

39 files changed, 161 insertions(+), 321 deletions(-)

11 out of the 39 changed files are removed completely.

2) Patches 12-13

Move the invocation of arch_cpu_finalize_init() earlier in start_kernel() and move the x86'ism mem_encrypt_init() into the x86 space.

3) Patches 14-17

Implement the late FPU initialization for X86 on top. Removal of the custom early command line parsing is subject to separate x86 specific changes. This part #3 is to illustrate the use case for #2.

The series applies on Linus tree and is also available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git init

Thanks,

tglx

---
 a/arch/alpha/include/asm/bugs.h     |   20 ---------
 a/arch/ia64/include/asm/bugs.h      |   20 ---------
 a/arch/loongarch/include/asm/bugs.h |   15 ------
 a/arch/m68k/include/asm/bugs.h      |   21 ---------
 a/arch/parisc/include/asm/bugs.h    |   20 ---------
 a/arch/powerpc/include/asm/bugs.h   |   15 ------
 a/arch/sh/include/asm/bugs.h        |   74 ---------------------------------
 a/arch/sparc/include/asm/bugs.h     |   18 --------
 a/arch/um/include/asm/bugs.h        |    7 ---
 a/arch/xtensa/include/asm/bugs.h    |   18 --------
 a/include/asm-generic/bugs.h        |   11 -----
 arch/Kconfig                        |    3 +
 arch/arm/Kconfig                    |    1 
 arch/arm/include/asm/bugs.h         |    4 -
 arch/arm/kernel/bugs.c              |    3 -
 arch/ia64/Kconfig                   |    1 
 arch/ia64/kernel/setup.c            |    3 -
 arch/loongarch/Kconfig              |    1 
 arch/loongarch/kernel/setup.c       |    4 -
 arch/m68k/Kconfig                   |    1 
 arch/m68k/kernel/setup_mm.c         |    3 -
 arch/mips/Kconfig                   |    1 
 arch/mips/include/asm/bugs.h        |   17 -------
 arch/mips/kernel/setup.c            |   13 +++++
 arch/sh/Kconfig                     |    1 
 arch/sh/include/asm/processor.h     |    2 
 arch/sh/kernel/idle.c               |    1 
 arch/sh/kernel/setup.c              |   55 +++++++++++++++++++++++++
 arch/sparc/Kconfig                  |    1 
 arch/sparc/kernel/setup_32.c        |    7 +++
 arch/um/Kconfig                     |    1 
 arch/um/kernel/um_arch.c            |    3 -
 arch/x86/Kconfig                    |    1 
 arch/x86/include/asm/bugs.h         |    2 
 arch/x86/include/asm/fpu/api.h      |    2 
 arch/x86/include/asm/mem_encrypt.h  |    7 +--
 arch/x86/include/asm/sigframe.h     |    2 
 arch/x86/kernel/cpu/bugs.c          |   51 -----------------------
 arch/x86/kernel/cpu/common.c        |   79 ++++++++++++++++++++++++++++++++----
 arch/x86/kernel/cpu/cpu.h           |    1 
 arch/x86/kernel/fpu/init.c          |    8 +--
 arch/x86/kernel/signal.c            |    4 +
 include/linux/cpu.h                 |    6 ++
 init/main.c                         |   16 -------
 44 files changed, 192 insertions(+), 352 deletions(-)