From patchwork Tue Jun 13 23:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 13279284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88B56C001B1 for ; Tue, 13 Jun 2023 23:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240192AbjFMXj2 (ORCPT ); Tue, 13 Jun 2023 19:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238613AbjFMXj0 (ORCPT ); Tue, 13 Jun 2023 19:39:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B9D21989; Tue, 13 Jun 2023 16:39:24 -0700 (PDT) Message-ID: <20230613223827.532680283@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686699562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=zGcwSkjRu8UFPTZ5Hk2Js/azQZ9pUpsGsLPKi5+wHk4=; b=1vl6UXgCAJSEGSzD8t6gUcoJc5169AwVrpA21nUOBZK5joseTFTf4tOCJuSxYeH8jjiG5a jEyyQE8u/hzl94Ysm1rJG2YnzoQg/tcACXTl7p0VwWp1Hg5BBJMua3yUhYob6t9+1w2mee 490vMvkq9U3+kLEoOiWcYf6hGufEEl+RY32dXE3KaUMRZAu87C+A2xK5wy++4GlmwK3EZB Z5VXWqjjyIYWILTQXObbl4QE63VzmXuPdS4shWyoeGuVxCCmwUXoumayy+XcSsFxFG+bU7 NlI/LWfvrG5jqcCo56KbCsG3Df/lECSRqYeR0pyPUxwGWLhUnEuZlGh+hhMUzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686699562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=zGcwSkjRu8UFPTZ5Hk2Js/azQZ9pUpsGsLPKi5+wHk4=; b=c2klUM1ewA5e7Mdg+k2IbCC4Vl2VvLKpWjP1RVCx9kwxZJ2Q99tmqHfyKPV09o7em5evQ2 Pbn7SMSiRq5L4VBA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Nikolay Borisov , "Ahmed S. Darwish" , Arnd Bergmann , Russell King , linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org, Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Richard Henderson , "James E.J. Bottomley" , Michael Ellerman , Chris Zankel , Tom Lendacky Subject: [patch 00/17] init, treewide, x86: Cleanup check_bugs() and start sanitizing the x86 boot process Date: Wed, 14 Jun 2023 01:39:21 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org 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(-)