Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1147973lqd; Thu, 25 Apr 2024 07:19:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1w8D+fyGUDn8BOmy+yEZvWPR3+Yapj4+1pAsfnrWUEKgD7GfjryP7/BH3rILRl9pzuytQkGXKP7toZQvP0Yqa52xO2DJGsvbJKO2rXg== X-Google-Smtp-Source: AGHT+IGNapd5aVTk4lCXSMukNcvIIdFH0IAiWijwPcIlYD2DJPbHvcRhDfKoK5FVELnNo8Gue+ds X-Received: by 2002:a17:90b:350f:b0:2ae:5b9b:8636 with SMTP id ls15-20020a17090b350f00b002ae5b9b8636mr5363436pjb.3.1714054749473; Thu, 25 Apr 2024 07:19:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714054749; cv=pass; d=google.com; s=arc-20160816; b=GLDHKVHJwbDeky84VbKqhf4dcnubfgR/zrEJjpNE9Ju4KLXRAqkLLMped6lFY5J/Wg F4XfC0u85tVpqrNj6PdBJ1nyyA7NNnL2ZdB59IxtNobpzU9JqCX/YIOGr58r3zHzx8nG RD92hAY86FrAiKSX16ZgDhsF41l4SEFQeYYJU9wwZtvg5G96kujiJ5dpxYPRt1CICoUP ZKhriTyvB6ylLB4uRsf/0Q+5fDJVrvqb5Ids8QVS2QJ4ETcv4+OxMDktiSosbO1ETX2i RBnKbHdzdtIk6huThNdJxRdm/Se5W0dNyq8BuLcPSfvVJxbRTp1/8P3mdxFf/uxEe4cC 1VRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=ERpiYyy6VKUTYmVo9nuH623n9EpUv9W8nfTL91rChmw=; fh=N10kKTs1o6SvPzoZdiHfmp6oJZDLJJXdsVWfwzQu84I=; b=FZUR9+mhdXxxxvqqUqeLhPT/LNpzs2QZofs6b3mFjmDhVb+tDX5TD9Zk7jQIHtfHu2 GorLtVLcZunl3FKsdWwRCEiuBV167oT+Uvd1ZQk22qT/l76QMiLYr1BfaEizX8fYEMvh DDhhUyJKk3T76Afe2Gw+5Ej6UR+HnoF5036WzCJ99OTH3J/0rpZgcpkld6qqSyC2b2EO AZRiHQEUp0ROAsy9RyD81vOoKm9beO1zXovU48ClXdkLVyn19zR2PYibHFfywg/o/ebD xFSDm4Lw4eONz+252dq343T02mXWeIPDS/pK55oauBrQlAQ9ZV3ZYFXQGYvIE+3NEo4i 4T9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ENbR9AJ7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-158675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q9-20020a17090a304900b002ac214dea57si12343417pjl.19.2024.04.25.07.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 07:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ENbR9AJ7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-158675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1B1F32848FA for ; Thu, 25 Apr 2024 14:18:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A84F14A09B; Thu, 25 Apr 2024 14:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ENbR9AJ7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="geuelfvO" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3941149C67; Thu, 25 Apr 2024 14:18:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714054689; cv=none; b=H6nupZiCMBMJkjB2g4oZ9HkjCQrN3WHUQWaPkQxkVcvG1A53mtKxG5m6mXcbXFpbud3U/tRirHDZ84X2dORL3uLoxlPDC9XuqloH9+xuoDM/In1GeTO/+3oBzHdCJkZKcZoLu8IkxN8lB7RwXV9Pyb4lGnCFiCphBF2fV80Xj4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714054689; c=relaxed/simple; bh=ngxmY1opm52+AJqMx4m1GyiFhCMC+7ATWYtg3YsNcUk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=f8Cfwz3FhhIKnWiZRmQESX/dhzF+WCd9+jyDU8z7ibXc9TeVREeKJ6inOl4IqXvOVEt1hw9TsySYj1m/MOKNOAN/6oc8iT6LQqhOqXACcOcECFNkCg/2WP7KaU0d7uOk8gwE6UB8OF/zBUFPQSVZk3/W5j3U9lMTX9S7KvSTmR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ENbR9AJ7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=geuelfvO; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 25 Apr 2024 14:18:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1714054686; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERpiYyy6VKUTYmVo9nuH623n9EpUv9W8nfTL91rChmw=; b=ENbR9AJ7x5bFMnl2kRXcoqnTE5P07kK4Nagb8V5BHz2yeFKsd26WanTL/GWgxcea1HzNs/ Dbo+qL4n5W2fUuJWdI40fsPs98qydcQgf4RlHMH++JTeCNeUGgNXF1h8LT8dks6qWYQ704 BWhV/pFITq20YpJ24QrwyJLMtCTQNQrSXyyl2bfLdeDglHusdnhG8A8Z9lbLFYcQVbbigE 1Q1hyzcD3u3wZViA26O1h6XJGDxuUi7UlafjZX1VrajByLXfMQXn0vzrfcbDrVxnwXXaF3 BvfvtGbtQJhgV05o2k97giUEF9kBkI/TUbMhaUCoOpu7ZmpIFo5mQkrPp8uXlQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714054686; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERpiYyy6VKUTYmVo9nuH623n9EpUv9W8nfTL91rChmw=; b=geuelfvO0HXQ3t4kMSjWOZJXWSWo/IG1fG06AFpjxNNYWPcbVjagkz+8jyiis0PhNGecdb wUv0bxo0m/A1CHDQ== From: "tip-bot2 for Sean Christopherson" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] cpu: Ignore "mitigations" kernel parameter if CPU_MITIGATIONS=n Cc: Sean Christopherson , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240420000556.2645001-3-seanjc@google.com> References: <20240420000556.2645001-3-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171405468558.10875.5701614476992826261.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/urgent branch of tip: Commit-ID: ce0abef6a1d540acef85068e0e82bdf1fbeeb0e9 Gitweb: https://git.kernel.org/tip/ce0abef6a1d540acef85068e0e82bdf1fbeeb0e9 Author: Sean Christopherson AuthorDate: Fri, 19 Apr 2024 17:05:55 -07:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 25 Apr 2024 15:47:39 +02:00 cpu: Ignore "mitigations" kernel parameter if CPU_MITIGATIONS=n Explicitly disallow enabling mitigations at runtime for kernels that were built with CONFIG_CPU_MITIGATIONS=n, as some architectures may omit code entirely if mitigations are disabled at compile time. E.g. on x86, a large pile of Kconfigs are buried behind CPU_MITIGATIONS, and trying to provide sane behavior for retroactively enabling mitigations is extremely difficult, bordering on impossible. E.g. page table isolation and call depth tracking require build-time support, BHI mitigations will still be off without additional kernel parameters, etc. [ bp: Touchups. ] Signed-off-by: Sean Christopherson Signed-off-by: Borislav Petkov (AMD) Acked-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20240420000556.2645001-3-seanjc@google.com --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/Kconfig | 8 ++++++-- include/linux/cpu.h | 11 +++++++++++ kernel/cpu.c | 14 ++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 902ecd9..213d071 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3423,6 +3423,9 @@ arch-independent options, each of which is an aggregation of existing arch-specific options. + Note, "mitigations" is supported if and only if the + kernel was built with CPU_MITIGATIONS=y. + off Disable all optional CPU mitigations. This improves system performance, but it may also diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 619a04d..928820e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2495,9 +2495,13 @@ menuconfig CPU_MITIGATIONS help Say Y here to enable options which enable mitigations for hardware vulnerabilities (usually related to speculative execution). + Mitigations can be disabled or restricted to SMT systems at runtime + via the "mitigations" kernel parameter. - If you say N, all mitigations will be disabled. You really - should know what you are doing to say so. + If you say N, all mitigations will be disabled. This CANNOT be + overridden at runtime. + + Say 'Y', unless you really know what you are doing. if CPU_MITIGATIONS diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 272e4e7..861c3bf 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -221,7 +221,18 @@ void cpuhp_report_idle_dead(void); static inline void cpuhp_report_idle_dead(void) { } #endif /* #ifdef CONFIG_HOTPLUG_CPU */ +#ifdef CONFIG_CPU_MITIGATIONS extern bool cpu_mitigations_off(void); extern bool cpu_mitigations_auto_nosmt(void); +#else +static inline bool cpu_mitigations_off(void) +{ + return true; +} +static inline bool cpu_mitigations_auto_nosmt(void) +{ + return false; +} +#endif #endif /* _LINUX_CPU_H_ */ diff --git a/kernel/cpu.c b/kernel/cpu.c index bb0ff27..63447eb 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -3196,6 +3196,7 @@ void __init boot_cpu_hotplug_init(void) this_cpu_write(cpuhp_state.target, CPUHP_ONLINE); } +#ifdef CONFIG_CPU_MITIGATIONS /* * These are used for a global "mitigations=" cmdline option for toggling * optional CPU mitigations. @@ -3206,9 +3207,7 @@ enum cpu_mitigations { CPU_MITIGATIONS_AUTO_NOSMT, }; -static enum cpu_mitigations cpu_mitigations __ro_after_init = - IS_ENABLED(CONFIG_CPU_MITIGATIONS) ? CPU_MITIGATIONS_AUTO : - CPU_MITIGATIONS_OFF; +static enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO; static int __init mitigations_parse_cmdline(char *arg) { @@ -3224,7 +3223,6 @@ static int __init mitigations_parse_cmdline(char *arg) return 0; } -early_param("mitigations", mitigations_parse_cmdline); /* mitigations=off */ bool cpu_mitigations_off(void) @@ -3239,3 +3237,11 @@ bool cpu_mitigations_auto_nosmt(void) return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT; } EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt); +#else +static int __init mitigations_parse_cmdline(char *arg) +{ + pr_crit("Kernel compiled without mitigations, ignoring 'mitigations'; system may still be vulnerable\n"); + return 0; +} +#endif +early_param("mitigations", mitigations_parse_cmdline);