Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1934277rwd; Tue, 13 Jun 2023 17:05:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4T+7nyVoMkO1aPqXtLacrkF6oybg2aewKWShsKg8xBltB+9XWwTcuD6idPxluC1XlACoHp X-Received: by 2002:a05:6402:3496:b0:516:41ed:fd40 with SMTP id v22-20020a056402349600b0051641edfd40mr51567edc.12.1686701146456; Tue, 13 Jun 2023 17:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686701146; cv=none; d=google.com; s=arc-20160816; b=z4IqRIpUoWjk415GmL+bXP8kgOgtwX47KiEIQh+ZyuEULuDz6OTe2wu5GtFB/VcoQ9 Bav+vwKLcbmxgaLNeR/ozb3fvtcq5gS08eFLKoLKTW/4X109+TPJTkIbJD26cD4D5aad dQsCVNFOr3t4W/Bt7fV2hoNXlFmI8AzzrxhPUZLYDz3R94H3+xtZmNgGGMgUGFtGT5Dz LKU69CYyTbjPl7OjKpUt/NEDWmoyEbsOkLui65zbzW/DoBtjck9gt2afekx/AjAhAPa7 +4M96J57F32M6qjn+9QbwIQr9jlK/S0HZKfB/dvofH4Rd7Qa6A0Njfjyapjpqz/MtkHE EBhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=zGcwSkjRu8UFPTZ5Hk2Js/azQZ9pUpsGsLPKi5+wHk4=; b=BPOz0kA4iTPf/3ScI0GcPLa/KDSQNj1Hk446rwap2KRcA6O66VHOJ0zqhPruTIkLV2 LJSuGBdRyCh/4QQiFUXSkQEs+YyRPBF5v8HkEQ+DNx6DN0OQ2Fj4l+k0JCvKEjZNSSCS Bud/VbwA4f0ToBz0Pr/FRVoc8DXjBTTxTIlMvQpEPvI3WtXcGhxWvE9gr9o2yT6kgAh7 MSsG9DF3E8epIyft10lFo8WQKdzrAXa1gJ/DVNXEaw8MTnuyjwvxL3x2RhEZefjsJBSu r3aD1dxUaemCIfLcwUO9cISZXOP81C3MjBNssas7sJ0lOrTS/MBYrIzLC6xXYvNhmS44 7z5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1vl6UXgC; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y25-20020aa7c259000000b0050bc1ed0727si7845583edo.286.2023.06.13.17.05.10; Tue, 13 Jun 2023 17:05:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1vl6UXgC; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240627AbjFMXjc (ORCPT + 99 others); Tue, 13 Jun 2023 19:39:32 -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) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-)