From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 523ABEB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:18 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S235141AbjFOQpQ (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:16 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43506 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S235592AbjFOQod (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:33 -0400
Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F0C42D68
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:27 -0700 (PDT)
Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-4f764e9295dso3560527e87.0
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:27 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847465; x=1689439465;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=ZKrXpTuTUilsXuTU2ZCSebU2HevXpno2wTvArxmiD/I=;
        b=LcO9jiu05ylVTSZzr4SU4EZgahdLYPBHHgeZTetrC4fDUqTA7NAf80UFCBdrM4ZME6
         wohdzicshdhWcqZQOHaM4W4S5IkhVS9gcJGxnl49s2DrGH8WdF35bX/yP7RQWFRuASfN
         ENlP8IkX2JnwDto3haQPfvQ6ClW0WXsf3LsMsp05NQJTuS+ue+nMqU4gV9jE/0bjGUCB
         qLFsZoaUs23gb6fICZGxz225UiEiswUgpYc5v+7BmR3A9U6Yp4bxN4usqgulaiDz41y9
         4a9KN6/MYT5mWSlY6h1nFrBzwyVnwVGHU7fs2hgN90RGamUlAkdctOCDU9cD4gEiNKWo
         vBgg==
X-Gm-Message-State: AC+VfDxMawcGudHlCS7BI6BH94x/xtHEZWEvZelulSNV1YsoKyBDrQqc
        JFPlHp2dtEkCdn9ZFIIjiBM=
X-Google-Smtp-Source: ACHHUZ7Ej3e+4lEdxGSsJ/iaN/wwADaHZ1JD3PLw1zeo3YQ8ZJe+I3Cv3xKG4vBLE3ACixNIFMkPfA==
X-Received: by 2002:a19:7b14:0:b0:4f8:83f:babe with SMTP id w20-20020a197b14000000b004f8083fbabemr1970034lfc.62.1686847465120;
        Thu, 15 Jun 2023 09:44:25 -0700 (PDT)
Received: from localhost (fwdproxy-cln-007.fbsv.net. [2a03:2880:31ff:7::face:b00c])
        by smtp.gmail.com with ESMTPSA id l16-20020a1c7910000000b003f8d770e935sm6143947wme.0.2023.06.15.09.44.24
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:24 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de
Cc:     leit@fb.com, hpa@zytor.com, x86@kernel.org, mingo@redhat.com,
        dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] x86/bugs: Break down mitigations configurations
Date:   Thu, 15 Jun 2023 09:44:11 -0700
Message-Id: <20230615164417.3588162-1-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to compile a kernel today with some of the speculative
mitigations disabled. Even if the kernel has
CONFIG_SPECULATION_MITIGATIONS=n, some Intel mitigations, such as MDS, TAA,
MMIO are still enabled and can only be disabled using a kernel parameter.

This patchset creates a way to choose what to enable or disable, and,
get the mitigations disable if CONFIG_SPECULATION_MITIGATIONS is not
set, as the rest of other mitigations.

Also, we want to print a warning message letting users know that these
mitigations are disabled.

This is a follow up to this discussion: https://lkml.org/lkml/2023/6/12/798

Breno Leitao (3):
  x86/bugs: Create an option to disable MDS
  x86/bugs: Create an option to disable TAA
  x86/bugs: Create an option to disable MMIO vulnerability

 arch/x86/Kconfig           | 31 +++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/bugs.c | 23 +++++++++++++++++++----
 2 files changed, 50 insertions(+), 4 deletions(-)

-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 1E5BFEB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:24 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S236145AbjFOQpV (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:21 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43594 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S236130AbjFOQog (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:36 -0400
Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F4130C6
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:28 -0700 (PDT)
Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-30e412a852dso6024947f8f.0
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:28 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847467; x=1689439467;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=h/iaRHbMZknbdlPyOxZE8eGdzil5wkV0A7XuLO8jEos=;
        b=e19iUv80fm9DHni/on1OhVwGrsi36TWIKh3BdUodXdtJRIqR5uTOVColyzZw23E46l
         H7vZyfteDVCh4PWoRIN6GB6F8gjWV+3xkJbJLJHVORYyTGi+RjJpRkCfTl2L346U+eWB
         jBFNHt3Yl1NyiyRO6ULLe6DfS3fQAH3ZNxgLcmJejJK3KRqEpwH2IPFDSI3PN0NQTCNG
         xAGsyZJA3keMYoGZbzn3p9f9uAQI55ROds5KXT7GrYateTi4huXWXdWwuBVK30U4ycYD
         mz7cO7323IgsxAAwBlg5SyNxfU2qC5sCyeB2P6Y1TqN/shhZucokHwZFRMtEzTkx3dh8
         QrtA==
X-Gm-Message-State: AC+VfDyHJvMPeRqw+x5gpIGUfNKvb7kGBW2j21U0zLfM8cx/MpNS3vhR
        3CotD+L9fVemd1Nfwe9NRdN7GAIyMWs=
X-Google-Smtp-Source: ACHHUZ4Tf3U78NbDvBaXcy6pNpUoCEg1zhXEIHFBt0r8wCtMdvb9HiNSl0VLtsWo59p+6m3X7D1VUw==
X-Received: by 2002:a5d:4cc1:0:b0:30f:c142:5330 with SMTP id c1-20020a5d4cc1000000b0030fc1425330mr7815963wrt.27.1686847467003;
        Thu, 15 Jun 2023 09:44:27 -0700 (PDT)
Received: from localhost (fwdproxy-cln-020.fbsv.net. [2a03:2880:31ff:14::face:b00c])
        by smtp.gmail.com with ESMTPSA id a8-20020a5d5088000000b0030f9c3219aasm19257509wrt.47.2023.06.15.09.44.26
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:26 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>
Cc:     leit@fb.com, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] x86/bugs: Create an option to disable MDS
Date:   Thu, 15 Jun 2023 09:44:12 -0700
Message-Id: <20230615164417.3588162-2-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to disable MDS mitigation today at compilation time. MDS
is enabled even if CONFIG_SPECULATION_MITIGATIONS is unset.

Create a new KCONFIG option that allow MDS mitigations to be disabled in
compilation time.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/x86/Kconfig           | 11 +++++++++++
 arch/x86/kernel/cpu/bugs.c |  9 ++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 53bab123a8ee..d25132b2d54f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2649,6 +2649,17 @@ config SLS
 	  against straight line speculation. The kernel image might be slightly
 	  larger.
 
+config MITIGATE_MDS
+	bool "Mitigate Microarchitectural Data Sampling (MDS) hardware bug"
+	depends on CPU_SUP_INTEL && X86_64
+	default y
+	help
+	  Enable mitigation for Microarchitectural Data Sampling (MDS). MDS is
+	  a hardware vulnerability which allows unprivileged speculative access
+	  to data which is available in various CPU internal buffer. Deeper
+	  technical information is available in the MDS specific x86 architecture
+	  section: Documentation/arch/x86/mds.rst.
+
 endif
 
 config ARCH_HAS_ADD_PAGES
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 182af64387d0..50f12829dce9 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -269,6 +269,7 @@ static void x86_amd_ssb_disable(void)
 /* Default mitigation for MDS-affected CPUs */
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
 static bool mds_nosmt __ro_after_init = false;
+#define MDS_WARN_MSG "WARNING: Microarchitectural Data Sampling (MDS) speculative mitigation disabled!\n"
 
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",
@@ -278,11 +279,17 @@ static const char * const mds_strings[] = {
 
 static void __init mds_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_MDS)) {
 		mds_mitigation = MDS_MITIGATION_OFF;
 		return;
 	}
 
+	if (cpu_mitigations_off() || !IS_ENABLED(CONFIG_MITIGATE_MDS)) {
+		mds_mitigation = MDS_MITIGATION_OFF;
+		pr_err(MDS_WARN_MSG);
+		return;
+	}
+
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
 		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
 			mds_mitigation = MDS_MITIGATION_VMWERV;
-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 6C0F3EB64DA
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:29 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S236787AbjFOQp2 (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:28 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42796 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S236242AbjFOQoo (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:44 -0400
Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B60C42D75
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:30 -0700 (PDT)
Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-30fc90f359fso3238477f8f.3
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:30 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847469; x=1689439469;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=yDJSQzuktanU2Jg2xVD0F/r0980umpPsJ0j0RWDQ1rg=;
        b=ZqnggpNQElkv8Bi/QjIOp18QIt0ami4HaITF+tfhLAR+5n6Gs6Vi8mFIUsypSpJOge
         uASjsFw3S9D9E8TR1v+lXftx6F+q/bDqFKcIBoHLesIJ73I8NclCbWht2uLm/xCXbENC
         UEwIXQXbyheEtoHD/oJQ35gQzbbrNALWaE4PZnXmjcC0nhpHCX+7ALXvokERcVcp8RnD
         DZToMahPtCi72n50cwxGjfbaq07VCu0oh6JQilwZaKDlm6APRFfoWmpt5g8h7/czFbIF
         QUG3MMq9xys9UgtT4rp5PX2j2Tclqvcd5iCpRbqD5NNrhjavBMo2UQrVphB82CPgHebl
         jzCQ==
X-Gm-Message-State: AC+VfDzrgjyCu2YwULkvoGsfuJAlvb/IwASvdkVJ6uKdR14s7O+KjVNA
        QSDv/PmPg/ZHRpAZsRhZlE8=
X-Google-Smtp-Source: ACHHUZ6MTnd9tDwMGRx7ahXOqi0IkgjY8BrdmE322JxFQy4hyHZc6iJBneVWxvJcemvZc7PGVZNSbg==
X-Received: by 2002:a05:6000:1:b0:30f:bbf1:d195 with SMTP id h1-20020a056000000100b0030fbbf1d195mr9842573wrx.36.1686847468817;
        Thu, 15 Jun 2023 09:44:28 -0700 (PDT)
Received: from localhost (fwdproxy-cln-116.fbsv.net. [2a03:2880:31ff:74::face:b00c])
        by smtp.gmail.com with ESMTPSA id d17-20020a5d6dd1000000b003095bd71159sm21615015wrz.7.2023.06.15.09.44.28
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:28 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>
Cc:     leit@fb.com, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] x86/bugs: Create an option to disable TAA
Date:   Thu, 15 Jun 2023 09:44:13 -0700
Message-Id: <20230615164417.3588162-3-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to disable TAA mitigation today at compilation time. TAA
is enabled even if CONFIG_SPECULATION_MITIGATIONS is unset.

Create a new KCONFIG option that allow TAA mitigation to be disabled in
compilation time.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/x86/Kconfig           | 10 ++++++++++
 arch/x86/kernel/cpu/bugs.c |  4 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index d25132b2d54f..140af3b30c45 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2660,6 +2660,16 @@ config MITIGATE_MDS
 	  technical information is available in the MDS specific x86 architecture
 	  section: Documentation/arch/x86/mds.rst.
 
+config MITIGATE_TAA
+	bool "Mitigate TSX Asynchronous Abort (TAA) hardware bug"
+	depends on CPU_SUP_INTEL && X86_64
+	default y
+	help
+	  Enable mitigation for TSX Asynchronous Abort (TAA). TAA is a hardware
+	  vulnerability that allows unprivileged speculative access to data
+	  which is available in various CPU internal buffers by using
+	  asynchronous aborts within an Intel TSX transactional region.
+
 endif
 
 config ARCH_HAS_ADD_PAGES
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 50f12829dce9..3615bda9573f 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -336,6 +336,7 @@ enum taa_mitigations {
 /* Default mitigation for TAA-affected CPUs */
 static enum taa_mitigations taa_mitigation __ro_after_init = TAA_MITIGATION_VERW;
 static bool taa_nosmt __ro_after_init;
+#define TAA_WARN_MSG "WARNING: TSX Asynchronous Abort (TAA) speculative mitigation disabled!\n"
 
 static const char * const taa_strings[] = {
 	[TAA_MITIGATION_OFF]		= "Vulnerable",
@@ -359,8 +360,9 @@ static void __init taa_select_mitigation(void)
 		return;
 	}
 
-	if (cpu_mitigations_off()) {
+	if (cpu_mitigations_off() || !IS_ENABLED(CONFIG_MITIGATE_TAA)) {
 		taa_mitigation = TAA_MITIGATION_OFF;
+		pr_err(TAA_WARN_MSG);
 		return;
 	}
 
-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 45999EB64DA
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:32 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S236909AbjFOQpb (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:31 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43754 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S232053AbjFOQoq (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:46 -0400
Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F6F830D6
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:32 -0700 (PDT)
Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-3f8cec6641bso22528605e9.1
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:32 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847471; x=1689439471;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=cnu101MlL/lBc9D51wfUyU127xq92KgSEDJgVIsZ6RU=;
        b=h8T/2GAVKqteALxJJb5540KEV/alCgtQntkyvSBDcvSa3xa5Rg4rmBbLAxqtO3pQjI
         lpGyOnZ7y+78365TIet/IfQSUFd5EvYPiivvc47gvuYWDQkTpi3VIq6Oxn4QbkN7aTo0
         Fv7XTGWtgp7ihZ0RC4qg3cp8brgTFLXVRJsvjinPRUPc7VjcsVu4G+kSOOdwia9rHylk
         6GGHz2tJyVzkSa0Q8ErmoQ0yYF1FAFkItR5bEcS8liPPSVartfCqoHP7vikJExHcKKRH
         sbKmRXAq+QIrpvrlicVaa8P3fFqZGY1/IZEUPkca9z3P6o3z1br3HkmUamAx992mMBPt
         CqlA==
X-Gm-Message-State: AC+VfDxMYpjatdQeHEXNV+gH5mUqy0uJ8ncF5EI0zZgB/0EjKgYCWTAk
        uQlSoa6qKrHYV1bGcb4efL0=
X-Google-Smtp-Source: ACHHUZ6tjv3xr59m+gYz8OVXnm1xmB74cCrv0sXwMg/z6UFWTLrHE2IEMmOXvM6S6QfjlV+oyShcwQ==
X-Received: by 2002:a05:600c:295:b0:3f6:af2:8471 with SMTP id 21-20020a05600c029500b003f60af28471mr14466195wmk.26.1686847470651;
        Thu, 15 Jun 2023 09:44:30 -0700 (PDT)
Received: from localhost (fwdproxy-cln-017.fbsv.net. [2a03:2880:31ff:11::face:b00c])
        by smtp.gmail.com with ESMTPSA id u2-20020a5d4342000000b0030e5c8d55f2sm21453538wrr.6.2023.06.15.09.44.29
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:29 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>
Cc:     leit@fb.com, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] x86/bugs: Create an option to disable MMIO vulnerability
Date:   Thu, 15 Jun 2023 09:44:14 -0700
Message-Id: <20230615164417.3588162-4-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to disable MMIO Stale data mitigation today at
compilation time. These mitigations are enabled even if
CONFIG_SPECULATION_MITIGATIONS is unset.

Create a new KCONFIG option that allow MMIO mitigation to be disabled in
compilation time.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/x86/Kconfig           | 10 ++++++++++
 arch/x86/kernel/cpu/bugs.c | 10 ++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 140af3b30c45..ba64f7c9b08d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2670,6 +2670,16 @@ config MITIGATE_TAA
 	  which is available in various CPU internal buffers by using
 	  asynchronous aborts within an Intel TSX transactional region.
 
+config MITIGATE_MMIO_STALE_DATA
+	bool "Mitigate MMIO Stale Data hardware bug"
+	depends on CPU_SUP_INTEL && X86_64
+	default y
+	help
+	  Enable mitigation for MMIO Stale Data hardware bugs.  Processor MMIO
+	  Stale Data Vulnerabilities are a class of memory-mapped I/O (MMIO)
+	  vulnerabilities that can expose data. The vulnerabilities require the
+	  attacker to have access to MMIO.
+
 endif
 
 config ARCH_HAS_ADD_PAGES
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 3615bda9573f..b5c171feb05e 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -439,6 +439,7 @@ enum mmio_mitigations {
 /* Default mitigation for Processor MMIO Stale Data vulnerabilities */
 static enum mmio_mitigations mmio_mitigation __ro_after_init = MMIO_MITIGATION_VERW;
 static bool mmio_nosmt __ro_after_init = false;
+#define MMIO_WARN_MSG "WARNING: MMIO Stale Data speculative mitigation disabled!\n"
 
 static const char * const mmio_strings[] = {
 	[MMIO_MITIGATION_OFF]		= "Vulnerable",
@@ -451,12 +452,17 @@ static void __init mmio_select_mitigation(void)
 	u64 ia32_cap;
 
 	if (!boot_cpu_has_bug(X86_BUG_MMIO_STALE_DATA) ||
-	     boot_cpu_has_bug(X86_BUG_MMIO_UNKNOWN) ||
-	     cpu_mitigations_off()) {
+	     boot_cpu_has_bug(X86_BUG_MMIO_UNKNOWN)) {
 		mmio_mitigation = MMIO_MITIGATION_OFF;
 		return;
 	}
 
+	if (cpu_mitigations_off() || !IS_ENABLED(CONFIG_MITIGATE_MDS)) {
+		mmio_mitigation = MMIO_MITIGATION_OFF;
+		pr_err(MMIO_WARN_MSG);
+		return;
+	}
+
 	if (mmio_mitigation == MMIO_MITIGATION_OFF)
 		return;
 
-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 3B1B3EB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:36 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S236967AbjFOQpf (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:35 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42858 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S233787AbjFOQot (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:49 -0400
Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0E2A30E7
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:33 -0700 (PDT)
Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3111547c8f9so837102f8f.1
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:33 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847472; x=1689439472;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=9Egc4fmm7smvfOFVQ5s3mS2mzKk6KiuOWVMSMxPPdik=;
        b=VpXK5YNXS/HtX+hVmjlJhE8f5WiWEsHho/TjZuL1Joqxv/i5Oesln8761YBsGu6pw9
         Z/HvRtryCldkj8L9em3gyoTosLU+3XiKceQbt3bgfjDkzFb7PJzewe7+zQUsu+fU/Uul
         Nvjie7ZdurubDMNygzgWlszSM9wTgVfWGiMuINKbiXZ7sDbC/jaOQW5IEk86RPCA8pYv
         cqZMENuL9/hAV28bfTIuZArVWLiixOo1pm6qiStJNAJTYeNYNN9g+tjAE5M1Gxa7QdZY
         Yq0BRbzAMshi7UWL964mV2+0/07wg+0TK5YHKF3Szhv4Hnhv9DopENutwN3Nsy3o+rGz
         fzVg==
X-Gm-Message-State: AC+VfDwack0fWX5w282iUKWGrNvXSHErT6fRE+ia0NJ508Dq+cQXk4my
        nzbtKtIPOzZ/UyjPEm3P5WI=
X-Google-Smtp-Source: ACHHUZ6zhzYN6oAaFFfvbT3Be6zWySwMH+fDayw3K3IJRZC489llcfGrPebhYUtFhg6qnFKS2qYeDw==
X-Received: by 2002:a05:6000:1b0c:b0:311:1a9a:90e4 with SMTP id f12-20020a0560001b0c00b003111a9a90e4mr841266wrz.57.1686847472206;
        Thu, 15 Jun 2023 09:44:32 -0700 (PDT)
Received: from localhost (fwdproxy-cln-019.fbsv.net. [2a03:2880:31ff:13::face:b00c])
        by smtp.gmail.com with ESMTPSA id c2-20020a5d5282000000b002fae7408544sm21515912wrv.108.2023.06.15.09.44.31
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:31 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de
Cc:     leit@fb.com, hpa@zytor.com, x86@kernel.org, mingo@redhat.com,
        dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] x86/bugs: Break down mitigations configurations
Date:   Thu, 15 Jun 2023 09:44:15 -0700
Message-Id: <20230615164417.3588162-5-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to compile a kernel today with some of the speculative
mitigations disabled. Even if the kernel has
CONFIG_SPECULATION_MITIGATIONS=n, some Intel mitigations, such as MDS, TAA,
MMIO are still enabled and can only be disabled using a kernel parameter.

This patchset creates a way to choose what to enable or disable, and,
get the mitigations disable if CONFIG_SPECULATION_MITIGATIONS is not
set, as the rest of other mitigations.

Also, we want to print a warning message letting users know that these
mitigations are disabled.

Breno Leitao (2):
  x86/speculation: Disable mitigations if CONFIG says so
  x86/speculation: Print error when mitigations are disabled

 arch/x86/kernel/cpu/bugs.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 2BCCCEB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:40 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S237057AbjFOQph (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:37 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42974 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S237015AbjFOQo5 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:44:57 -0400
Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE7030FA
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:35 -0700 (PDT)
Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-3f8d2bfec9bso22127965e9.0
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:35 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847474; x=1689439474;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=C7eq1USby5ztEf/7JC2Lke/melezYmsYGTiWNlQ9QdE=;
        b=IV6LxR5o3aMYTfUtYytMr644MIV6Oiajfl225yCbT6QpDlJ4T+ohDQrmkDuIAkaSJ9
         W9zACqMgQpXStIhSHZoUCLNPFszhOcFqzUMKIaAtAUfe4C1ImyeazH5XOgv8CpFoUW7y
         NqUazOoJliX5PyvjE6BS3LBvnScaocmURFhqXFbtaVAu/9JeZ1gpnCm5WCIH/R2KGSXO
         +vuM4TabZLT6Ae5bh1wXr6CrxvcqYzA7TZyiuRGYRbVKkob8rllzzuUPSNoHtOKxo0U/
         jtSZq9FhUF+Yrhh4JAFU1WnHjagbInW11r7UvPF9HmR+Q+p0HinUazCY3MAei7y2v9fi
         P8Bw==
X-Gm-Message-State: AC+VfDzQgbNSB8iIBKhR/clsLUsbq+4vzkSQqIj3RC74GuhfMoUul8lj
        rzXX56ZEEEZQqmZvzkdlDc4=
X-Google-Smtp-Source: ACHHUZ5vMzpzcEwea8p6zmZXyM0paKmFlSUyMnQ4eN2gvbq1e5scVMSPYhTePZDDNsVHDD4QsZ9Bkw==
X-Received: by 2002:a1c:ed06:0:b0:3f7:f584:5796 with SMTP id l6-20020a1ced06000000b003f7f5845796mr15079346wmh.2.1686847473943;
        Thu, 15 Jun 2023 09:44:33 -0700 (PDT)
Received: from localhost (fwdproxy-cln-012.fbsv.net. [2a03:2880:31ff:c::face:b00c])
        by smtp.gmail.com with ESMTPSA id h4-20020a05600c314400b003f1978bbcd6sm4683036wmo.3.2023.06.15.09.44.33
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:33 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>
Cc:     leit@fb.com, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] x86/speculation: Disable mitigations if CONFIG says so
Date:   Thu, 15 Jun 2023 09:44:16 -0700
Message-Id: <20230615164417.3588162-6-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

There is no way to disable certain mitigations(MDS, TAA, MMIO) today.
They are enabled even when the kernel has
CONFIG_SPECULATION_MITIGATIONS=n.

Create a function that says if the speculative mitigations are enabled
or not. They should use CONFIG_SPECULATION_MITIGATIONS as one source of
information.

Just enable MDS, TAA, MMIO mitigations if speculative mitigations are
enabled.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/x86/kernel/cpu/bugs.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 182af64387d0..703649a29181 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -87,6 +87,12 @@ void update_spec_ctrl_cond(u64 val)
 		wrmsrl(MSR_IA32_SPEC_CTRL, val);
 }
 
+static inline bool cpu_speculative_mitigations_off(void)
+{
+	return cpu_mitigations_off() ||
+		!IS_ENABLED(CONFIG_SPECULATION_MITIGATIONS);
+}
+
 noinstr u64 spec_ctrl_current(void)
 {
 	return this_cpu_read(x86_spec_ctrl_current);
@@ -278,7 +284,7 @@ static const char * const mds_strings[] = {
 
 static void __init mds_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_speculative_mitigations_off()) {
 		mds_mitigation = MDS_MITIGATION_OFF;
 		return;
 	}
@@ -352,7 +358,7 @@ static void __init taa_select_mitigation(void)
 		return;
 	}
 
-	if (cpu_mitigations_off()) {
+	if (cpu_speculative_mitigations_off()) {
 		taa_mitigation = TAA_MITIGATION_OFF;
 		return;
 	}
@@ -443,7 +449,7 @@ static void __init mmio_select_mitigation(void)
 
 	if (!boot_cpu_has_bug(X86_BUG_MMIO_STALE_DATA) ||
 	     boot_cpu_has_bug(X86_BUG_MMIO_UNKNOWN) ||
-	     cpu_mitigations_off()) {
+	     cpu_speculative_mitigations_off()) {
 		mmio_mitigation = MMIO_MITIGATION_OFF;
 		return;
 	}
@@ -516,7 +522,7 @@ early_param("mmio_stale_data", mmio_stale_data_parse_cmdline);
 
 static void __init md_clear_update_mitigation(void)
 {
-	if (cpu_mitigations_off())
+	if (cpu_speculative_mitigations_off())
 		return;
 
 	if (!static_key_enabled(&mds_user_clear))
-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 7CF47EB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 16:45:44 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S237103AbjFOQpn (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 12:45:43 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43774 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S237188AbjFOQpA (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 12:45:00 -0400
Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC8F53590
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:37 -0700 (PDT)
Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2b4470e1500so12167911fa.1
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 09:44:37 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686847476; x=1689439476;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=0LSIDuAzGUjwULNEFFLWoff2MIu4uiigVl6eBKjinCo=;
        b=CPAnbxpwtfqlBayL9sHpYGgnC+f7w+Vj7Q3286vJdWis0ZeWkObFo9tgWBlFKuwblV
         M8IiwwkPQBcPXwJ3LZElvpco29ASkJo5om5TT+VMJwOqpAmPkzwvzRN8miLFRFmbAEdi
         dpowGxLm6i/fBrxA3b9M9s6g8t1AWuCGWXjyjyO85jCz8qRJwOpj1IlREFcB3lc0gM36
         Grzt3+6Dtcv8e2dPKOHDFYMSZouR/T0zU0h+S1VYi4cid+kiA0MszqszJG038nkR2nWg
         S5aARFN/Lm52iK81dLRUAqb9B8siWMaMbBdmK0QVDksbPXUdoRBJjMIQYORbNEImCXIz
         ng6A==
X-Gm-Message-State: AC+VfDwMBzfrFOp7PQOCOatctZHDpaU/MXT4W4mPxHJEziSGIZ9qLq/5
        Upzp5S+9u1GKCWa+pI0WwSY=
X-Google-Smtp-Source: ACHHUZ4pR9WDwMlm3g3HwOYKuBIeEK8y7RWOY4bSgnAnd5UNBpuROzozma91VhwiCiN8B79aBFE6yg==
X-Received: by 2002:a2e:90cd:0:b0:2ac:8261:5f4b with SMTP id o13-20020a2e90cd000000b002ac82615f4bmr5658ljg.28.1686847476025;
        Thu, 15 Jun 2023 09:44:36 -0700 (PDT)
Received: from localhost (fwdproxy-cln-011.fbsv.net. [2a03:2880:31ff:b::face:b00c])
        by smtp.gmail.com with ESMTPSA id m1-20020a5d4a01000000b003062ad45243sm21533276wrq.14.2023.06.15.09.44.34
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 15 Jun 2023 09:44:35 -0700 (PDT)
From:   Breno Leitao <leitao@debian.org>
To:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>
Cc:     leit@fb.com, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] x86/speculation: Print error when mitigations are disabled
Date:   Thu, 15 Jun 2023 09:44:17 -0700
Message-Id: <20230615164417.3588162-7-leitao@debian.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org>
References: <20230615164417.3588162-1-leitao@debian.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

If mitigations are disabled for MDS, TAA, MMIO we want to let users
aware. This is either disabled by "mitigations=off" kernel argument, or,
by CONFIG_SPECULATION_MITIGATIONS=n

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/x86/kernel/cpu/bugs.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 703649a29181..b678cdd95dc1 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -275,6 +275,7 @@ static void x86_amd_ssb_disable(void)
 /* Default mitigation for MDS-affected CPUs */
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
 static bool mds_nosmt __ro_after_init = false;
+#define MDS_WARN_MSG "WARNING: Microarchitectural Data Sampling (MDS) speculative mitigation disabled!\n"
 
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",
@@ -284,11 +285,16 @@ static const char * const mds_strings[] = {
 
 static void __init mds_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_speculative_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_MDS)) {
 		mds_mitigation = MDS_MITIGATION_OFF;
 		return;
 	}
 
+	if (cpu_speculative_mitigations_off()) {
+		pr_err(MDS_WARN_MSG);
+		mds_mitigation = MDS_MITIGATION_OFF;
+	}
+
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
 		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
 			mds_mitigation = MDS_MITIGATION_VMWERV;
@@ -335,6 +341,7 @@ enum taa_mitigations {
 /* Default mitigation for TAA-affected CPUs */
 static enum taa_mitigations taa_mitigation __ro_after_init = TAA_MITIGATION_VERW;
 static bool taa_nosmt __ro_after_init;
+#define TAA_WARN_MSG "WARNING: TSX Asynchronous Abort (TAA) speculative mitigation disabled!\n"
 
 static const char * const taa_strings[] = {
 	[TAA_MITIGATION_OFF]		= "Vulnerable",
@@ -359,6 +366,7 @@ static void __init taa_select_mitigation(void)
 	}
 
 	if (cpu_speculative_mitigations_off()) {
+		pr_err(TAA_WARN_MSG);
 		taa_mitigation = TAA_MITIGATION_OFF;
 		return;
 	}
@@ -436,6 +444,7 @@ enum mmio_mitigations {
 /* Default mitigation for Processor MMIO Stale Data vulnerabilities */
 static enum mmio_mitigations mmio_mitigation __ro_after_init = MMIO_MITIGATION_VERW;
 static bool mmio_nosmt __ro_after_init = false;
+#define MMIO_WARN_MSG "WARNING: MMIO Stale Data speculative mitigation disabled!\n"
 
 static const char * const mmio_strings[] = {
 	[MMIO_MITIGATION_OFF]		= "Vulnerable",
@@ -448,12 +457,16 @@ static void __init mmio_select_mitigation(void)
 	u64 ia32_cap;
 
 	if (!boot_cpu_has_bug(X86_BUG_MMIO_STALE_DATA) ||
-	     boot_cpu_has_bug(X86_BUG_MMIO_UNKNOWN) ||
-	     cpu_speculative_mitigations_off()) {
+	     boot_cpu_has_bug(X86_BUG_MMIO_UNKNOWN)) {
 		mmio_mitigation = MMIO_MITIGATION_OFF;
 		return;
 	}
 
+	if (cpu_speculative_mitigations_off()) {
+		pr_err(MMIO_WARN_MSG);
+		mmio_mitigation = MMIO_MITIGATION_OFF;
+	}
+
 	if (mmio_mitigation == MMIO_MITIGATION_OFF)
 		return;
 
-- 
2.34.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 4AD9AEB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 17:32:35 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S236706AbjFORcd (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 13:32:33 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S230167AbjFORc2 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 13:32:28 -0400
Received: from mga03.intel.com (mga03.intel.com [134.134.136.65])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559101FDD
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 10:32:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1686850347; x=1718386347;
  h=from:to:cc:subject:references:date:in-reply-to:
   message-id:mime-version;
  bh=gj1PE8jgcTAjvU5QpELZ2BVDX+vgouCIrJw6XJgXAGI=;
  b=GqFT9P00Zbh0a2/lpaNRpar0aXHALKvhhx6hveRRBeOtrL+PVeEfWY1B
   M5cCX1UPlUJLQF6uJuMiL3AoGgIlMuSmDVVE3RZ1gCGMyOQNNV5Y75GfQ
   t+vn3olJLL8c8zJL2VATcnmK8JTTme5VPaPWNE6/sAdXgexC4pm6fNRx3
   B5s+B/LhkXb8MzpgGyLE4PeIWawGUEvx+xjIXia4Mjp1qv7LSulf4OHcd
   9HS+7fgptj7b8Cnq+Quh6iM52qu39UyFbSohXy8fKpPw3tMgdrYigRiXZ
   SOkmEozxPP78Npv3AZBVgQ9h9crlIr/uyZONw8rse2TOvYEhciDsbibEI
   g==;
X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="362402750"
X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; 
   d="scan'208";a="362402750"
Received: from orsmga007.jf.intel.com ([10.7.209.58])
  by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 10:21:55 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="706764961"
X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; 
   d="scan'208";a="706764961"
Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.54.38.190])
  by orsmga007.jf.intel.com with ESMTP; 15 Jun 2023 10:21:55 -0700
Received: by tassilo.localdomain (Postfix, from userid 1000)
        id 86E65302A4D; Thu, 15 Jun 2023 10:21:55 -0700 (PDT)
From:   Andi Kleen <ak@linux.intel.com>
To:     Breno Leitao <leitao@debian.org>
Cc:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        leit@fb.com, hpa@zytor.com, x86@kernel.org, mingo@redhat.com,
        dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] x86/bugs: Break down mitigations configurations
References: <20230615164417.3588162-1-leitao@debian.org>
Date:   Thu, 15 Jun 2023 10:21:55 -0700
In-Reply-To: <20230615164417.3588162-1-leitao@debian.org> (Breno Leitao's
        message of "Thu, 15 Jun 2023 09:44:11 -0700")
Message-ID: <87352shc98.fsf@linux.intel.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Breno Leitao <leitao@debian.org> writes:

> There is no way to compile a kernel today with some of the speculative
> mitigations disabled. Even if the kernel has
> CONFIG_SPECULATION_MITIGATIONS=n, some Intel mitigations, such as MDS, TAA,
> MMIO are still enabled and can only be disabled using a kernel parameter.
>
> This patchset creates a way to choose what to enable or disable, and,
> get the mitigations disable if CONFIG_SPECULATION_MITIGATIONS is not
> set, as the rest of other mitigations.
>
> Also, we want to print a warning message letting users know that these
> mitigations are disabled.
>
> This is a follow up to this discussion: https://lkml.org/lkml/2023/6/12/798
>

Isn't this all roughly equivalent to CONFIG_CMDLINE="mitigations=..." ?

-Andi

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 04D4EEB64D9
	for <linux-kernel@archiver.kernel.org>; Thu, 15 Jun 2023 22:14:31 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S237463AbjFOWO2 (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 15 Jun 2023 18:14:28 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54660 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S232199AbjFOWOW (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 15 Jun 2023 18:14:22 -0400
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAEA5296C
        for <linux-kernel@vger.kernel.org>; Thu, 15 Jun 2023 15:14:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1686867256; x=1718403256;
  h=date:from:to:cc:subject:message-id:references:
   mime-version:in-reply-to;
  bh=o6CzlnOxUp7Pn23UIx3PBDccZCaI5gkIID8mocI167g=;
  b=daDlw3z6GB+u8bYWoMsRpr9l5SJkJxLkcakFIUr6iPpZJzvUwnzWvHB8
   B3Y/b9+IhcvdvN8+TAzA7QnLDq2x93sAAAXDRzo41e4qgLE1TEfNOIgJj
   1k8cWSW/VmcytjlMWZLyZJQdcJKv1Ipikh4GhyNLboSS/rrYAY/IOMoKi
   JbXlRFdhnyjNzEwdAEw5ldMCISMvJT1vX/KSpqQcBzRo8p0MM3i92Lo1T
   FpVf2bGSqVIyf8epeMtVVQoIg1NH0nVj+D5JPuGIQAVv2LvnJ/i9HthED
   /ESeus24kqF4DfUIcZKyOdOORkaOXjLjgdOBjM1v6R6RSy6BGXC7H5wdD
   A==;
X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="356543710"
X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; 
   d="scan'208";a="356543710"
Received: from orsmga001.jf.intel.com ([10.7.209.18])
  by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:13:54 -0700
X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="745846573"
X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; 
   d="scan'208";a="745846573"
Received: from ckale-mobl1.amr.corp.intel.com (HELO desk) ([10.212.176.170])
  by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:13:54 -0700
Date:   Thu, 15 Jun 2023 15:13:47 -0700
From:   Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
To:     Breno Leitao <leitao@debian.org>
Cc:     jpoimboe@kernel.org, peterz@infradead.org, tglx@linutronix.de,
        bp@alien8.de, Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>, leit@fb.com,
        linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] x86/bugs: Create an option to disable MDS
Message-ID: <20230615221347.6ghb4d33tituxht4@desk>
References: <20230615164417.3588162-1-leitao@debian.org>
 <20230615164417.3588162-2-leitao@debian.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20230615164417.3588162-2-leitao@debian.org>
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Thu, Jun 15, 2023 at 09:44:12AM -0700, Breno Leitao wrote:
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 182af64387d0..50f12829dce9 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -269,6 +269,7 @@ static void x86_amd_ssb_disable(void)
>  /* Default mitigation for MDS-affected CPUs */
>  static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
>  static bool mds_nosmt __ro_after_init = false;
> +#define MDS_WARN_MSG "WARNING: Microarchitectural Data Sampling (MDS) speculative mitigation disabled!\n"
>  
>  static const char * const mds_strings[] = {
>  	[MDS_MITIGATION_OFF]	= "Vulnerable",
> @@ -278,11 +279,17 @@ static const char * const mds_strings[] = {
>  
>  static void __init mds_select_mitigation(void)
>  {
> -	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off()) {
> +	if (!boot_cpu_has_bug(X86_BUG_MDS)) {
>  		mds_mitigation = MDS_MITIGATION_OFF;
>  		return;
>  	}
>  
> +	if (cpu_mitigations_off() || !IS_ENABLED(CONFIG_MITIGATE_MDS)) {
> +		mds_mitigation = MDS_MITIGATION_OFF;
> +		pr_err(MDS_WARN_MSG);
> +		return;

Why does compile time config needs to be so restrictive that it does not
allow runtime override with mds= cmdline?

I believe Kconfig should only be setting the mitigation default,
allowing users to select mitigation at runtime:

---
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 182af64387d0..50e1ca4ea68b 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -267,7 +267,11 @@ static void x86_amd_ssb_disable(void)
 #define pr_fmt(fmt)	"MDS: " fmt
 
 /* Default mitigation for MDS-affected CPUs */
+#if IS_ENABLED(CONFIG_MITIGATE_MDS)
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
+#else
+static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_OFF;
+#endif
 static bool mds_nosmt __ro_after_init = false;
 
 static const char * const mds_strings[] = {

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 698A8EB64D7
	for <linux-kernel@archiver.kernel.org>; Fri, 16 Jun 2023 08:39:34 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S244545AbjFPIjc (ORCPT <rfc822;linux-kernel@archiver.kernel.org>);
        Fri, 16 Jun 2023 04:39:32 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39824 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S244439AbjFPIja (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Fri, 16 Jun 2023 04:39:30 -0400
Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F11A2D4D
        for <linux-kernel@vger.kernel.org>; Fri, 16 Jun 2023 01:39:29 -0700 (PDT)
Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4f6195d2b3fso494017e87.1
        for <linux-kernel@vger.kernel.org>; Fri, 16 Jun 2023 01:39:29 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686904767; x=1689496767;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=q+F5ipwxxMtT+ZL+axMsUdKjWgaE9QxBGsYhfSmi3Bo=;
        b=W/C/45Y/3zhiTtPpvcG+oQBZwfZ5g7rTr+QbB1r+SLIlE6ZA5yzpTnwAs1234kmUjM
         0Pbg41l0I+bW91cv5Ke2rocSgpb/vLiO8Tza3NibWrRH+iuH915PNep92HYcPX8LM2tl
         s1Esmikag74ZNvT2VKGiZEw431GwLo/IFPGLtwi5Kr5NnZX7eCcF9wKco/Wg1kg6/gl1
         fGkQX4wM2gzQzGrb8F6P15QtbZ0/syUgyuEu5+2JypX/0DkUHmDoMkBJ9cojdGNOP9JY
         D4c1xi6lz2+sKX6afDjUnC0c2i4CSXjZaHA1xLP2biB7LeDtQO6S56rxdTLRYcYyEIcX
         /jtg==
X-Gm-Message-State: AC+VfDzbiIBzBIMuOC14LSj07fqp6BOMvXpdBSZsh5I0xwFSiC0YRdNr
        Pvbb8SGxxRr+Y4m83bm0kE0=
X-Google-Smtp-Source: ACHHUZ4wb3vV9bVpaq4EyteKZUjh1t5PzqDgHPgzJy/mkbkoTBbQo0YxVo6f+ujNPpztmE5ggVE90w==
X-Received: by 2002:a19:5017:0:b0:4f6:266c:22fa with SMTP id e23-20020a195017000000b004f6266c22famr785310lfb.49.1686904767100;
        Fri, 16 Jun 2023 01:39:27 -0700 (PDT)
Received: from gmail.com (fwdproxy-cln-022.fbsv.net. [2a03:2880:31ff:16::face:b00c])
        by smtp.gmail.com with ESMTPSA id s14-20020adfeb0e000000b0030ae53550f5sm23042511wrn.51.2023.06.16.01.39.26
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 16 Jun 2023 01:39:26 -0700 (PDT)
Date:   Fri, 16 Jun 2023 01:39:22 -0700
From:   Breno Leitao <leitao@debian.org>
To:     Andi Kleen <ak@linux.intel.com>
Cc:     pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org,
        peterz@infradead.org, tglx@linutronix.de, bp@alien8.de,
        leit@fb.com, hpa@zytor.com, x86@kernel.org, mingo@redhat.com,
        dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] x86/bugs: Break down mitigations configurations
Message-ID: <ZIwfuvaRFNqZyCC7@gmail.com>
References: <20230615164417.3588162-1-leitao@debian.org>
 <87352shc98.fsf@linux.intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87352shc98.fsf@linux.intel.com>
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Thu, Jun 15, 2023 at 10:21:55AM -0700, Andi Kleen wrote:
> Breno Leitao <leitao@debian.org> writes:
> 
> > There is no way to compile a kernel today with some of the speculative
> > mitigations disabled. Even if the kernel has
> > CONFIG_SPECULATION_MITIGATIONS=n, some Intel mitigations, such as MDS, TAA,
> > MMIO are still enabled and can only be disabled using a kernel parameter.
> >
> > This patchset creates a way to choose what to enable or disable, and,
> > get the mitigations disable if CONFIG_SPECULATION_MITIGATIONS is not
> > set, as the rest of other mitigations.
> >
> > Also, we want to print a warning message letting users know that these
> > mitigations are disabled.
> >
> > This is a follow up to this discussion: https://lkml.org/lkml/2023/6/12/798
> >
> 
> Isn't this all roughly equivalent to CONFIG_CMDLINE="mitigations=..." ?

It is, indeed. But, the main motivation for this patchset it to solve a
consistency problem on our Kconfig. The user would image that all
speculative mitigations would be disabled if he passes
CONFIG_SPECULATION_MITIGATIONS=n, but that is not true. The user needs
something else, such as CONFIG_CMDLINE="mitigations=off" or "mds=off".

This patchset give more consistency to our Kconfig options, and the user
doesn't need to read between the lines.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
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 50400EB64D7
	for <linux-kernel@archiver.kernel.org>; Fri, 16 Jun 2023 11:47:13 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1343958AbjFPLrM (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Fri, 16 Jun 2023 07:47:12 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34446 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S241426AbjFPLrI (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Fri, 16 Jun 2023 07:47:08 -0400
Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561C22944
        for <linux-kernel@vger.kernel.org>; Fri, 16 Jun 2023 04:47:07 -0700 (PDT)
Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-3f7378a75c0so4479305e9.3
        for <linux-kernel@vger.kernel.org>; Fri, 16 Jun 2023 04:47:07 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1686916026; x=1689508026;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=zqnO9DvolFFI8feND6ugT07HkB5AUpc6lt0eNZnKtgY=;
        b=JPpjaQ+J1IpLmEztSRAoQm2iAGvPOWh6eSkW9ueJX0gAQM6VHbBv5LU2RaOwYtzDHJ
         h7XjXs0UmbHETID29NHQyP5rXEQKoxw2k0dNeEzFLis7MingaN3DHZby6M4Z36Q61bHY
         Z443M/zFkpkGJKKs63uJeQ7klsmYHreFXLlWsyyIAlBl58KThAaIZy7ppljrEVjhsV63
         AfovxBTECY6KhpKAVyocxKlt62IXoJntuSPnM94KB1Tcpfazdb+zVUiCyuMc3A72keI9
         a8wh/sO83k0sUNyBzIt7gZxHgvaC8LgLA8HUGa9uUvWo4QFogm4xGVisBONG2X8kzwm3
         qwGA==
X-Gm-Message-State: AC+VfDwHgxEyQ/jbuw0wMAKKTay6maL8l+/hLfux9Ge3sC40DqMY5WHy
        /tjkenTfFgoS3iuWfvvE7jk=
X-Google-Smtp-Source: ACHHUZ4xVJ2wecBCqmofNyTNY/0sRy0IBb1byhodmQO8Ofxup9qLMGH7CDRsPvqSSQfPMRMxIc263A==
X-Received: by 2002:a05:600c:3782:b0:3f8:d66f:db3b with SMTP id o2-20020a05600c378200b003f8d66fdb3bmr1555902wmr.30.1686916025541;
        Fri, 16 Jun 2023 04:47:05 -0700 (PDT)
Received: from gmail.com (fwdproxy-cln-019.fbsv.net. [2a03:2880:31ff:13::face:b00c])
        by smtp.gmail.com with ESMTPSA id o25-20020a1c7519000000b003f427687ba7sm1961517wmc.41.2023.06.16.04.47.04
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 16 Jun 2023 04:47:05 -0700 (PDT)
Date:   Fri, 16 Jun 2023 04:47:03 -0700
From:   Breno Leitao <leitao@debian.org>
To:     Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Cc:     jpoimboe@kernel.org, peterz@infradead.org, tglx@linutronix.de,
        bp@alien8.de, Ingo Molnar <mingo@redhat.com>,
        Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
        "H. Peter Anvin" <hpa@zytor.com>, leit@fb.com,
        linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] x86/bugs: Create an option to disable MDS
Message-ID: <ZIxLt3/vWyoB/UIK@gmail.com>
References: <20230615164417.3588162-1-leitao@debian.org>
 <20230615164417.3588162-2-leitao@debian.org>
 <20230615221347.6ghb4d33tituxht4@desk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20230615221347.6ghb4d33tituxht4@desk>
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Thu, Jun 15, 2023 at 03:13:47PM -0700, Pawan Gupta wrote:
> On Thu, Jun 15, 2023 at 09:44:12AM -0700, Breno Leitao wrote:
> > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> > index 182af64387d0..50f12829dce9 100644
> > --- a/arch/x86/kernel/cpu/bugs.c
> > +++ b/arch/x86/kernel/cpu/bugs.c
> > @@ -269,6 +269,7 @@ static void x86_amd_ssb_disable(void)
> >  /* Default mitigation for MDS-affected CPUs */
> >  static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
> >  static bool mds_nosmt __ro_after_init = false;
> > +#define MDS_WARN_MSG "WARNING: Microarchitectural Data Sampling (MDS) speculative mitigation disabled!\n"
> >  
> >  static const char * const mds_strings[] = {
> >  	[MDS_MITIGATION_OFF]	= "Vulnerable",
> > @@ -278,11 +279,17 @@ static const char * const mds_strings[] = {
> >  
> >  static void __init mds_select_mitigation(void)
> >  {
> > -	if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off()) {
> > +	if (!boot_cpu_has_bug(X86_BUG_MDS)) {
> >  		mds_mitigation = MDS_MITIGATION_OFF;
> >  		return;
> >  	}
> >  
> > +	if (cpu_mitigations_off() || !IS_ENABLED(CONFIG_MITIGATE_MDS)) {
> > +		mds_mitigation = MDS_MITIGATION_OFF;
> > +		pr_err(MDS_WARN_MSG);
> > +		return;
> 
> Why does compile time config needs to be so restrictive that it does not
> allow runtime override with mds= cmdline?
> 
> I believe Kconfig should only be setting the mitigation default,
> allowing users to select mitigation at runtime:

Sure, that is doable as well. If no one has any opposition to it, I will
implemented as suggested.

