Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp582776rdg; Thu, 10 Aug 2023 12:11:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmKRhZJba1Rljs9O7hcUctRAkm9I0ccyDBJjBVfNeVgVxqID6DzR0b6AhL1GnA6ATb6Gyv X-Received: by 2002:a17:903:1211:b0:1b9:e913:b585 with SMTP id l17-20020a170903121100b001b9e913b585mr3646146plh.13.1691694705702; Thu, 10 Aug 2023 12:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691694705; cv=none; d=google.com; s=arc-20160816; b=wDKm/fX5koM5PKuQX0fvyqm/PGqO+AbJYPAcfxsLQKYKDikJ2OYvsxBWlNJDK9Qkr9 2bJAUTyBHmHoBfJsOIpqmI94tta7SokP3Mx52cMQThhp+qJV7zt+BSNzoEbMhPo39lAF gE/LNcCaSPbn7TPxnq6/Wuo6nCXuYcyw+40SiJmHw/cQGx9bPqNthDJUVpzjkNnjq8Nz UbSHSypbH+qMLe1KnDBlka6PIA9heAhqf8f4RIk1odDVoP12xHB8VtxUz9eNpbehwWrX Xs6r0LkKnV9aifX1aMCAdRN03/fZXTfpZU6G6LIpWZA8SttoMCoSFtdoXgLeZ50MIDcA FTAw== 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=UokI+w5bD9vUcMSFnaXSpgjbgC5/EVsUA75GVMUW0B8=; fh=Vp72a/EEov1VOHpGPkCjAnDQEmhhYrQPa+PSfT8H2jQ=; b=0u7m6VHbMOsBpBFrhe60M/4Wsz0LVvlrKf6ccU1UphhTjxtRWQTWevC7HuSa/vL9eX +0ey+k8lv2ZMg5/npv/O+oX7OChe6WDnZR9nR9zmiAGUtJa3fMObp/kacbl8pNUIGlda /++6EO6+DPoZzqlAh5eO4Mz6+CqMPSRSIIq9lyGVWSI3nsQEXCP1/a/Q57S9WEXDi4W1 3cVpb6nK4Lj36ud+s+lwrNa220nTXPLRVnsA/zhEtjXvraekhFlZ4PA7nAzBAC3eauQ6 1hn4HP5whuI4yJLoQSNKaCJlhgp3Cp6sYHWu3JeYgTheiFg8dvQ29bSLNQXa6hIXsU/I TWjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RMvHAUry; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7zQNNfI6; 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 o17-20020a170903301100b001bbcddc33dasi1838066pla.180.2023.08.10.12.11.33; Thu, 10 Aug 2023 12:11:45 -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=RMvHAUry; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7zQNNfI6; 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 S235462AbjHJSha (ORCPT + 99 others); Thu, 10 Aug 2023 14:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbjHJSh3 (ORCPT ); Thu, 10 Aug 2023 14:37:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB3B426BC for ; Thu, 10 Aug 2023 11:37:28 -0700 (PDT) Message-ID: <20230810153317.850017756@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691692646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=UokI+w5bD9vUcMSFnaXSpgjbgC5/EVsUA75GVMUW0B8=; b=RMvHAUryYhy9kk1EU0Sen3r+3dzOUKpfyznSvzd8W4eJUZhOeQC7U//xhvOywGq2hDvi39 hBYXZiK77mDXdwu5l93l6TQDZP5xNlENccyVbGIGr4WF9FjGQjVrqo6J6VgxDIgtuknmM2 C0EjsowMCRmbWDvCaPe/zGmNUK44KujMxEGFyUVAfO7m4spml0DYAI+0dxiGz99zSIWZlL kQZQ9h7kx1BXWA67ZAYXXVPxGoyF0dtTVwbw2DYqJvs8rU7GNiVclMCaThctFj1aY27igs UUKSgzC2AhvvSGxBCTELQD44pTqcw6lZ9hvG7wbKBAb97BpdmzM1QNhFUyWysA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691692646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=UokI+w5bD9vUcMSFnaXSpgjbgC5/EVsUA75GVMUW0B8=; b=7zQNNfI6ADnT1jQLLzmF3j0FcY/eJNWccLjD0XZvbbCvTMbiV7Ypo/iKY+D8Q810FPt1iA nPzIgfMbvY8aspBQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , Ashok Raj , Arjan van de Ven Subject: [patch 00/30] x86/microcode: Cleanup and late loading enhancements Date: Thu, 10 Aug 2023 20:37:26 +0200 (CEST) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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! 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. 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-v1 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/microcode.h | 162 +--- 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 | 25 b/arch/x86/kernel/cpu/microcode/core.c | 518 +++++++++++--- b/arch/x86/kernel/cpu/microcode/intel.c | 807 ++++++++++------------ b/arch/x86/kernel/cpu/microcode/internal.h | 190 +++++ b/arch/x86/kernel/nmi.c | 9 b/arch/x86/mm/init.c | 1 b/drivers/platform/x86/intel/ifs/load.c | 4 20 files changed, 1109 insertions(+), 1018 deletions(-)