Skip to content

Commit aba7de6

Browse files
pa1guptasean-jc
authored andcommitted
x86/bugs: Use VM_CLEAR_CPU_BUFFERS in VMX as well
TSA mitigation: d8010d4 ("x86/bugs: Add a Transient Scheduler Attacks mitigation") introduced VM_CLEAR_CPU_BUFFERS for guests on AMD CPUs. Currently on Intel CLEAR_CPU_BUFFERS is being used for guests which has a much broader scope (kernel->user also). Make mitigations on Intel consistent with TSA. This would help handling the guest-only mitigations better in future. Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> [sean: make CLEAR_CPU_BUF_VM mutually exclusive with the MMIO mitigation] Acked-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Brendan Jackman <jackmanb@google.com> Link: https://patch.msgid.link/20251113233746.1703361-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 844afc1 commit aba7de6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
194194

195195
/*
196196
* Controls CPU Fill buffer clear before VMenter. This is a subset of
197-
* X86_FEATURE_CLEAR_CPU_BUF, and should only be enabled when KVM-only
197+
* X86_FEATURE_CLEAR_CPU_BUF_VM, and should only be enabled when KVM-only
198198
* mitigation is required.
199199
*/
200200
DEFINE_STATIC_KEY_FALSE(cpu_buf_vm_clear);
@@ -489,8 +489,8 @@ static enum rfds_mitigations rfds_mitigation __ro_after_init =
489489
IS_ENABLED(CONFIG_MITIGATION_RFDS) ? RFDS_MITIGATION_AUTO : RFDS_MITIGATION_OFF;
490490

491491
/*
492-
* Set if any of MDS/TAA/MMIO/RFDS are going to enable VERW clearing
493-
* through X86_FEATURE_CLEAR_CPU_BUF on kernel and guest entry.
492+
* Set if any of MDS/TAA/MMIO/RFDS are going to enable VERW clearing on exit to
493+
* userspace *and* on entry to KVM guests.
494494
*/
495495
static bool verw_clear_cpu_buf_mitigation_selected __ro_after_init;
496496

@@ -536,6 +536,7 @@ static void __init mds_apply_mitigation(void)
536536
if (mds_mitigation == MDS_MITIGATION_FULL ||
537537
mds_mitigation == MDS_MITIGATION_VMWERV) {
538538
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF);
539+
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM);
539540
if (!boot_cpu_has(X86_BUG_MSBDS_ONLY) &&
540541
(mds_nosmt || smt_mitigations == SMT_MITIGATIONS_ON))
541542
cpu_smt_disable(false);
@@ -647,6 +648,7 @@ static void __init taa_apply_mitigation(void)
647648
* present on host, enable the mitigation for UCODE_NEEDED as well.
648649
*/
649650
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF);
651+
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM);
650652

651653
if (taa_nosmt || smt_mitigations == SMT_MITIGATIONS_ON)
652654
cpu_smt_disable(false);
@@ -748,6 +750,7 @@ static void __init mmio_apply_mitigation(void)
748750
*/
749751
if (verw_clear_cpu_buf_mitigation_selected) {
750752
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF);
753+
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM);
751754
static_branch_disable(&cpu_buf_vm_clear);
752755
} else {
753756
static_branch_enable(&cpu_buf_vm_clear);
@@ -839,8 +842,10 @@ static void __init rfds_update_mitigation(void)
839842

840843
static void __init rfds_apply_mitigation(void)
841844
{
842-
if (rfds_mitigation == RFDS_MITIGATION_VERW)
845+
if (rfds_mitigation == RFDS_MITIGATION_VERW) {
843846
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF);
847+
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM);
848+
}
844849
}
845850

846851
static __init int rfds_parse_cmdline(char *str)

arch/x86/kvm/vmx/vmenter.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ SYM_FUNC_START(__vmx_vcpu_run)
155155
mov VCPU_RAX(%_ASM_AX), %_ASM_AX
156156

157157
/* Clobbers EFLAGS.ZF */
158-
CLEAR_CPU_BUFFERS
158+
VM_CLEAR_CPU_BUFFERS
159159

160160
/* Check @flags to see if VMLAUNCH or VMRESUME is needed. */
161161
testl $VMX_RUN_VMRESUME, WORD_SIZE(%_ASM_SP)

0 commit comments

Comments
 (0)