Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 42c141f

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/bugs: Add 'spectre_bhi=vmexit' cmdline option
In cloud environments it can be useful to *only* enable the vmexit mitigation and leave syscalls vulnerable. Add that as an option. This is similar to the old spectre_bhi=auto option which was removed with the following commit: 36d4fe1 ("x86/bugs: Remove CONFIG_BHI_MITIGATION_AUTO and spectre_bhi=auto") with the main difference being that this has a more descriptive name and is disabled by default. Mitigation switch requested by Maksim Davydov <davydov-max@yandex-team.ru>. [ bp: Massage. ] Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Daniel Sneddon <daniel.sneddon@linux.intel.com> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Link: https://lore.kernel.org/r/2cbad706a6d5e1da2829e5e123d8d5c80330148c.1719381528.git.jpoimboe@kernel.org
1 parent 4586c93 commit 42c141f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6136,9 +6136,15 @@
61366136
deployment of the HW BHI control and the SW BHB
61376137
clearing sequence.
61386138

6139-
on - (default) Enable the HW or SW mitigation
6140-
as needed.
6141-
off - Disable the mitigation.
6139+
on - (default) Enable the HW or SW mitigation as
6140+
needed. This protects the kernel from
6141+
both syscalls and VMs.
6142+
vmexit - On systems which don't have the HW mitigation
6143+
available, enable the SW mitigation on vmexit
6144+
ONLY. On such systems, the host kernel is
6145+
protected from VM-originated BHI attacks, but
6146+
may still be vulnerable to syscall attacks.
6147+
off - Disable the mitigation.
61426148

61436149
spectre_v2= [X86,EARLY] Control mitigation of Spectre variant 2
61446150
(indirect branch speculation) vulnerability.

arch/x86/kernel/cpu/bugs.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ static bool __init spec_ctrl_bhi_dis(void)
16251625
enum bhi_mitigations {
16261626
BHI_MITIGATION_OFF,
16271627
BHI_MITIGATION_ON,
1628+
BHI_MITIGATION_VMEXIT_ONLY,
16281629
};
16291630

16301631
static enum bhi_mitigations bhi_mitigation __ro_after_init =
@@ -1639,6 +1640,8 @@ static int __init spectre_bhi_parse_cmdline(char *str)
16391640
bhi_mitigation = BHI_MITIGATION_OFF;
16401641
else if (!strcmp(str, "on"))
16411642
bhi_mitigation = BHI_MITIGATION_ON;
1643+
else if (!strcmp(str, "vmexit"))
1644+
bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
16421645
else
16431646
pr_err("Ignoring unknown spectre_bhi option (%s)", str);
16441647

@@ -1659,19 +1662,22 @@ static void __init bhi_select_mitigation(void)
16591662
return;
16601663
}
16611664

1665+
/* Mitigate in hardware if supported */
16621666
if (spec_ctrl_bhi_dis())
16631667
return;
16641668

16651669
if (!IS_ENABLED(CONFIG_X86_64))
16661670
return;
16671671

1668-
/* Mitigate KVM by default */
1669-
setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT);
1670-
pr_info("Spectre BHI mitigation: SW BHB clearing on vm exit\n");
1672+
if (bhi_mitigation == BHI_MITIGATION_VMEXIT_ONLY) {
1673+
pr_info("Spectre BHI mitigation: SW BHB clearing on VM exit only\n");
1674+
setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT);
1675+
return;
1676+
}
16711677

1672-
/* Mitigate syscalls when the mitigation is forced =on */
1678+
pr_info("Spectre BHI mitigation: SW BHB clearing on syscall and VM exit\n");
16731679
setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP);
1674-
pr_info("Spectre BHI mitigation: SW BHB clearing on syscall\n");
1680+
setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT);
16751681
}
16761682

16771683
static void __init spectre_v2_select_mitigation(void)

0 commit comments

Comments
 (0)