From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
Ingo Molnar <mingo@kernel.org>, Amit Shah <amit.shah@amd.com>,
Nikolay Borisov <nik.borisov@suse.com>,
Sasha Levin <sashal@kernel.org>,
tglx@linutronix.de, bp@alien8.de, peterz@infradead.org,
mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org,
luto@kernel.org
Subject: [PATCH AUTOSEL 6.1 13/17] x86/bugs: Don't fill RSB on context switch with eIBRS
Date: Mon, 14 Apr 2025 09:30:44 -0400 [thread overview]
Message-ID: <20250414133048.680608-13-sashal@kernel.org> (raw)
In-Reply-To: <20250414133048.680608-1-sashal@kernel.org>
From: Josh Poimboeuf <jpoimboe@kernel.org>
[ Upstream commit 27ce8299bc1ec6df8306073785ff82b30b3cc5ee ]
User->user Spectre v2 attacks (including RSB) across context switches
are already mitigated by IBPB in cond_mitigation(), if enabled globally
or if either the prev or the next task has opted in to protection. RSB
filling without IBPB serves no purpose for protecting user space, as
indirect branches are still vulnerable.
User->kernel RSB attacks are mitigated by eIBRS. In which case the RSB
filling on context switch isn't needed, so remove it.
Suggested-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Amit Shah <amit.shah@amd.com>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Link: https://lore.kernel.org/r/98cdefe42180358efebf78e3b80752850c7a3e1b.1744148254.git.jpoimboe@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kernel/cpu/bugs.c | 24 ++++++++++++------------
arch/x86/mm/tlb.c | 6 +++---
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index f0f184afa44f3..0be0edb07a2a9 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -1553,7 +1553,7 @@ static void __init spec_ctrl_disable_kernel_rrsba(void)
rrsba_disabled = true;
}
-static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_mitigation mode)
+static void __init spectre_v2_select_rsb_mitigation(enum spectre_v2_mitigation mode)
{
/*
* Similar to context switches, there are two types of RSB attacks
@@ -1577,7 +1577,7 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_
*/
switch (mode) {
case SPECTRE_V2_NONE:
- return;
+ break;
case SPECTRE_V2_EIBRS:
case SPECTRE_V2_EIBRS_LFENCE:
@@ -1586,18 +1586,21 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_
pr_info("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n");
setup_force_cpu_cap(X86_FEATURE_RSB_VMEXIT_LITE);
}
- return;
+ break;
case SPECTRE_V2_RETPOLINE:
case SPECTRE_V2_LFENCE:
case SPECTRE_V2_IBRS:
- pr_info("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n");
+ pr_info("Spectre v2 / SpectreRSB: Filling RSB on context switch and VMEXIT\n");
+ setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
setup_force_cpu_cap(X86_FEATURE_RSB_VMEXIT);
- return;
- }
+ break;
- pr_warn_once("Unknown Spectre v2 mode, disabling RSB mitigation at VM exit");
- dump_stack();
+ default:
+ pr_warn_once("Unknown Spectre v2 mode, disabling RSB mitigation\n");
+ dump_stack();
+ break;
+ }
}
/*
@@ -1822,10 +1825,7 @@ static void __init spectre_v2_select_mitigation(void)
*
* FIXME: Is this pointless for retbleed-affected AMD?
*/
- setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
- pr_info("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n");
-
- spectre_v2_determine_rsb_fill_type_at_vmexit(mode);
+ spectre_v2_select_rsb_mitigation(mode);
/*
* Retpoline protects the kernel, but doesn't protect firmware. IBRS
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index b07e2167fcebf..8d46b9c0e9204 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -385,9 +385,9 @@ static void cond_mitigation(struct task_struct *next)
prev_mm = this_cpu_read(cpu_tlbstate.last_user_mm_spec);
/*
- * Avoid user/user BTB poisoning by flushing the branch predictor
- * when switching between processes. This stops one process from
- * doing Spectre-v2 attacks on another.
+ * Avoid user->user BTB/RSB poisoning by flushing them when switching
+ * between processes. This stops one process from doing Spectre-v2
+ * attacks on another.
*
* Both, the conditional and the always IBPB mode use the mm
* pointer to avoid the IBPB when switching between tasks of the
--
2.39.5
next prev parent reply other threads:[~2025-04-14 13:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 13:30 [PATCH AUTOSEL 6.1 01/17] KVM: s390: Don't use %pK through tracepoints Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 02/17] udmabuf: fix a buf size overflow issue during udmabuf creation Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 03/17] selftests: ublk: fix test_stripe_04 Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 04/17] xen: Change xen-acpi-processor dom0 dependency Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 05/17] nvme: requeue namespace scan on missed AENs Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 06/17] ACPI: EC: Set ec_no_wakeup for Lenovo Go S Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 07/17] ACPI PPTT: Fix coding mistakes in a couple of sizeof() calls Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 08/17] nvme: re-read ANA log page after ns scan completes Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 09/17] objtool: Stop UNRET validation on UD2 Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 10/17] selftests/mincore: Allow read-ahead pages to reach the end of the file Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 11/17] x86/bugs: Use SBPB in write_ibpb() if applicable Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 12/17] x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline Sasha Levin
2025-04-14 13:30 ` Sasha Levin [this message]
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 14/17] nvmet-fc: take tgtport reference only once Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 15/17] nvmet-fc: put ref when assoc->del_work is already scheduled Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 16/17] net_sched: sch_sfq: use a temporary work area for validating configuration Sasha Levin
2025-04-14 13:30 ` [PATCH AUTOSEL 6.1 17/17] ext4: make block validity check resistent to sb bh corruption Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250414133048.680608-13-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=amit.shah@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox