Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1388625rwd; Thu, 15 Jun 2023 09:51:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rGNV+zw8+PTS5mS6J88diz1tssi9oWAQzrDUvhaC16mA5WbnAv8B5hX3RV3cH/tzz1dno X-Received: by 2002:a17:903:22ce:b0:1b1:1168:656b with SMTP id y14-20020a17090322ce00b001b11168656bmr7883273plg.26.1686847900065; Thu, 15 Jun 2023 09:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686847900; cv=none; d=google.com; s=arc-20160816; b=GVYx17Csge9qBTHKbl0O5U6PWliUWal/wJunq3VPPPDAxrOuefTtHVP8zvratCCIIP Ra70my7TEbeeeEmNNHe13C++LqUEPvK7zPLP4mgCGWe2vl0HG1cic+K55fozbd3ExO2Q Pl8BzT3k46TPuGrZD2dxilPkGr8sX9wGlY79vyI4Lcgqelk6dHL/ecuCxnOZyYJGJLLG GNvXzZV/pI7Sb6efpMnWNtF2A/9DgYH18Xo6B0tKLdTVcEs7b4BkcvY1B5Vh4WxPn+35 tvjtA25wbKdi4r4gd7d5Cj1T9jr4UK2Kr7wcjpmBgC5P0Dr1+qNlfL9i5sIPgdSJJNz8 i35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=h/iaRHbMZknbdlPyOxZE8eGdzil5wkV0A7XuLO8jEos=; b=SPHE7iOHnJCPYrJTWClKK3okR+aICHUudk/vV2TF1WhxEdDjlSRNB67ix+Ui1MYcaR f4ERTbwKf/b8VEQY6xV1U4ijoky4Ji9PFCKxnEx2MTIiLvFkbTcLOd7Rh8q6HJbwmmvn WT1Wq8fjgmMOcvl3lBOx60X8mo3Vkiu9NYFG6tlcAMNP/w38Vhk76j7T/hWIpdmlZspo joCLk4nZc649ckXAARSJLslv+Fn0QvESl9fOo3Gvm6kWpApMO8BuaNTicpyNUMHWa7/7 +4TuAYx27OabXXdEbkb6gpd11W6dmvD+w7M09GjJRNWFG+3Gz7HcRKqj5II9VqC1PZaq DYdQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n11-20020a1709026a8b00b001b049682a8dsi12844888plk.458.2023.06.15.09.51.28; Thu, 15 Jun 2023 09:51:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235592AbjFOQpS (ORCPT + 99 others); Thu, 15 Jun 2023 12:45:18 -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 ); 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 ; Thu, 15 Jun 2023 09:44:28 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-30e412a852dso6024947f8f.0 for ; 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-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 To: pawan.kumar.gupta@linux.intel.com, jpoimboe@kernel.org, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" 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 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 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 --- 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