Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2418681lqt; Mon, 22 Apr 2024 10:05:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTZQZf5CyEoGp+hDVzyOnV5Tt0pBdht9/fwLUO3kpqP9276Tw05Yy+Kx/gQaM032Mvxoyab5BHSD4qL+49FlxhfbMASAFxw17VYKWOmg== X-Google-Smtp-Source: AGHT+IEsX3ucXrubAaGOgXK5SDXQL53SWCHxhJLiKHclc/LV7Y/png1XMuklBmaBtKLX2Gv8y4RK X-Received: by 2002:a05:6a20:9708:b0:1ad:3d93:b71e with SMTP id hr8-20020a056a20970800b001ad3d93b71emr1925842pzc.59.1713805501970; Mon, 22 Apr 2024 10:05:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713805501; cv=pass; d=google.com; s=arc-20160816; b=muC72b43ECMYwAaqlNMQe2Ys/fsoToTu8JPnNRP8oUiPQCVJHy/x/e8pUd/d0NGfeU t/oAvOf5rESGuir7BpYDawRlZMghDG3WJSda2H5Xi81u9nmzLxGlW1mAJexqcAxaLiE0 hO+2er4qHYyBooGEqaozhC+1Z65yfP+ObtIgh5rctJ4m/aJu5nkzdKyV2QXt+dcKojKG 6pC6Cmg7MpPffSW2m0U2I79AhSTZxT3C39bsExdtvFvIa+P6squcE78UnT0u08KyFj+4 LQV5C4RTdmuGD1DCTPxVVzR7u95AawBnAoKDvRWTxGekd6WwHx9k+JJ0rH4QUvMQEL5J YsKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=aQodkT2pk00x6+Ui5xe7sWS/8qfrbWhleMy31J9gQDg=; fh=5XJJypkQeI5s73nZGmyRskmPdYeXtfodQOf0GbSr5UU=; b=ZX0CqoH1/0mgho83XafpX7Dkj4gHqUsen6cbuXgQKM7VrXfiI88de4CxZv7R2g4u6z 5+olB8gqLl2s3fJvAy3vGIrDhesdplw2Pb65vQUXAVY49h5JLVJQqeisrLYaD4eT43LU HRkRXQzDXhFCZN7IjoZgYyCHGmEeCy4GrjYJ1XvunyP+lRZU3de0t/NEpoiQld2dR/Fm 4j+RaKmXIPShDiB7B97d3kKe/119dw8KfrEzn3UEvgM/DazznLvS0yQe9fsAb/y7oRbi RSWlvlfyPPP3IUN736cxieLcDAowtghxfyaXzCPKsWEk6gPyXK5dwuIggrpRLAFJjoiC e4ow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-153774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153774-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d1-20020a656b81000000b005ce021f4418si8355522pgw.524.2024.04.22.10.05.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 10:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153774-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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-153774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153774-linux.lists.archive=gmail.com@vger.kernel.org" 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 1C6E92880CB for ; Mon, 22 Apr 2024 17:01:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 333A31553B0; Mon, 22 Apr 2024 16:59:08 +0000 (UTC) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E556E155314 for ; Mon, 22 Apr 2024 16:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713805147; cv=none; b=E+qSZLXOwx90tM3j/9g43np6p/mae2psccxOT5wmb0uwP/KdwHhM3Dl8YeeSQBloI1cC01Hndv7Xftbha0yaB6sA+dqw8C5niLx50kIC2laDeUPJS9cOMj6GyXiMfwCX7dYA4MA7rW1am6AZ+4EAG//pn6ZrCDO+fOJEintF8kI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713805147; c=relaxed/simple; bh=CEW6djjENnK8i4xnr2gyr3zOyZhyU7VSWHKtmWEbZvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AGGGqLNKlp8Gi1QjWB90vwRYdW9Zckt9HNfE2y9ZOEnjDj1GrkeeYme8fPEhxxPnH1wut35UscHNVDOoQMBNLPoi4J+zG70dhcEXy2+H3jMsUosS6pcXiI4zF7K9uJVINUD9rFOYKgbNSkxH0LqXqSCv1ak7P2m8A4k8e05qSNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-41a72f3a20dso7210535e9.0 for ; Mon, 22 Apr 2024 09:59:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713805144; x=1714409944; 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=aQodkT2pk00x6+Ui5xe7sWS/8qfrbWhleMy31J9gQDg=; b=bAkkqK5mUF1qCld1RU8/9CETxjZF7VoVO2YsyLW1DDXpe7/D2WX543K1NtyJwbsKeo XRMgpNxYde5jqAMabS4jNjS4kL45XBEEkAj+ukD2+UBRsSNyUG7h4M3xbuc4YljUw6Hi UjP97MsAMhmh9qNGkEkT7CaQGVlIvcxrtiKjnw2QVSyOID7s+12D2kKAJV7uOBKv/2+3 bPwyIPk0+yxM3y73D2gZ7Hr8KpSNMRq7XGkrCNsMLMm7CPtgegYouvZUr+ily/jOIsha 6MZouBV5SPiFthV1DnoOxPwkvoHYW0tNZEGoXzK5GTdP1cj90e5gYfXZ0gzZ/eLp4F4N LqLA== X-Gm-Message-State: AOJu0YwjRajjNud3NyIw/yuzUqaSMVA8XGv4zCq9zRhSqS3QF8BjqENz FASsO1YkD6fYyTY2ZCnD1XlBWp9WXZwTSXjAlq7U0dTsZZLikzhU X-Received: by 2002:a05:6000:22d:b0:348:4519:15b8 with SMTP id l13-20020a056000022d00b00348451915b8mr6885572wrz.40.1713805144348; Mon, 22 Apr 2024 09:59:04 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id qq22-20020a17090720d600b00a554f6fbb25sm5923437ejb.138.2024.04.22.09.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:59:03 -0700 (PDT) From: Breno Leitao To: jpoimboe@kernel.org, mingo@redhat.com, Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Pawan Gupta Cc: linux-kernel@vger.kernel.org Subject: [PATCH v3 09/10] x86/bugs: Add a separate config for Spectre V2 Date: Mon, 22 Apr 2024 09:58:23 -0700 Message-ID: <20240422165830.2142904-10-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422165830.2142904-1-leitao@debian.org> References: <20240422165830.2142904-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, the CONFIG_SPECULATION_MITIGATIONS is halfway populated, where some mitigations have entries in Kconfig, and they could be modified, while others mitigations do not have Kconfig entries, and could not be controlled at build time. Create an entry for the Spectre V2 CPU mitigation under CONFIG_SPECULATION_MITIGATIONS. This allow users to enable or disable it at compilation time. Signed-off-by: Breno Leitao Acked-by: Josh Poimboeuf --- arch/x86/Kconfig | 12 ++++++++++++ arch/x86/kernel/cpu/bugs.c | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index fdf1c894fcb8..4f69a7f5f675 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2719,6 +2719,18 @@ config MITIGATION_SPECTRE_V1 memory access bounds check. See also +config MITIGATION_SPECTRE_V2 + bool "Mitigate SPECTRE V2 hardware bug" + default y + help + Enable mitigation for Spectre V2 (Branch Target Injection). Spectre + V2 is a class of side channel attacks that takes advantage of + indirect branch predictors inside the processor. In Spectre variant 2 + attacks, the attacker can steer speculative indirect branches in the + victim to gadget code by poisoning the branch target buffer of a CPU + used for predicting indirect branch addresses. + See also + config MITIGATION_SRBDS bool "Mitigate Special Register Buffer Data Sampling (SRBDS) hardware bug" depends on CPU_SUP_INTEL diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 49b60c0e2eb4..5628a77281fe 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1457,17 +1457,18 @@ static void __init spec_v2_print_cond(const char *reason, bool secure) static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) { - enum spectre_v2_mitigation_cmd cmd = SPECTRE_V2_CMD_AUTO; + enum spectre_v2_mitigation_cmd cmd; char arg[20]; int ret, i; + cmd = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ? SPECTRE_V2_CMD_AUTO : SPECTRE_V2_CMD_NONE; if (cmdline_find_option_bool(boot_command_line, "nospectre_v2") || cpu_mitigations_off()) return SPECTRE_V2_CMD_NONE; ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg)); if (ret < 0) - return SPECTRE_V2_CMD_AUTO; + return cmd; for (i = 0; i < ARRAY_SIZE(mitigation_options); i++) { if (!match_option(arg, ret, mitigation_options[i].option)) @@ -1477,8 +1478,8 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) } if (i >= ARRAY_SIZE(mitigation_options)) { - pr_err("unknown option (%s). Switching to AUTO select\n", arg); - return SPECTRE_V2_CMD_AUTO; + pr_err("unknown option (%s). Switching to default mode\n", arg); + return cmd; } if ((cmd == SPECTRE_V2_CMD_RETPOLINE || -- 2.43.0