Skip to content

Commit d893832

Browse files
committed
x86/srso: Add IBPB on VMEXIT
Add the option to flush IBPB only on VMEXIT in order to protect from malicious guests but one otherwise trusts the software that runs on the hypervisor. Signed-off-by: Borislav Petkov (AMD) <[email protected]>
1 parent 233d6f6 commit d893832

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311

312312
#define X86_FEATURE_SRSO (11*32+24) /* "" AMD BTB untrain RETs */
313313
#define X86_FEATURE_SRSO_ALIAS (11*32+25) /* "" AMD BTB untrain RETs through aliasing */
314+
#define X86_FEATURE_IBPB_ON_VMEXIT (11*32+26) /* "" Issue an IBPB only on VMEXIT */
314315

315316
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
316317
#define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */

arch/x86/kernel/cpu/bugs.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,20 +2198,23 @@ enum srso_mitigation {
21982198
SRSO_MITIGATION_MICROCODE,
21992199
SRSO_MITIGATION_SAFE_RET,
22002200
SRSO_MITIGATION_IBPB,
2201+
SRSO_MITIGATION_IBPB_ON_VMEXIT,
22012202
};
22022203

22032204
enum srso_mitigation_cmd {
22042205
SRSO_CMD_OFF,
22052206
SRSO_CMD_MICROCODE,
22062207
SRSO_CMD_SAFE_RET,
22072208
SRSO_CMD_IBPB,
2209+
SRSO_CMD_IBPB_ON_VMEXIT,
22082210
};
22092211

22102212
static const char * const srso_strings[] = {
22112213
[SRSO_MITIGATION_NONE] = "Vulnerable",
22122214
[SRSO_MITIGATION_MICROCODE] = "Mitigation: microcode",
22132215
[SRSO_MITIGATION_SAFE_RET] = "Mitigation: safe RET",
22142216
[SRSO_MITIGATION_IBPB] = "Mitigation: IBPB",
2217+
[SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only"
22152218
};
22162219

22172220
static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE;
@@ -2230,6 +2233,8 @@ static int __init srso_parse_cmdline(char *str)
22302233
srso_cmd = SRSO_CMD_SAFE_RET;
22312234
else if (!strcmp(str, "ibpb"))
22322235
srso_cmd = SRSO_CMD_IBPB;
2236+
else if (!strcmp(str, "ibpb-vmexit"))
2237+
srso_cmd = SRSO_CMD_IBPB_ON_VMEXIT;
22332238
else
22342239
pr_err("Ignoring unknown SRSO option (%s).", str);
22352240

@@ -2313,6 +2318,20 @@ static void __init srso_select_mitigation(void)
23132318
pr_err("WARNING: kernel not compiled with CPU_IBPB_ENTRY.\n");
23142319
goto pred_cmd;
23152320
}
2321+
break;
2322+
2323+
case SRSO_CMD_IBPB_ON_VMEXIT:
2324+
if (IS_ENABLED(CONFIG_CPU_SRSO)) {
2325+
if (!boot_cpu_has(X86_FEATURE_ENTRY_IBPB) && has_microcode) {
2326+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
2327+
srso_mitigation = SRSO_MITIGATION_IBPB_ON_VMEXIT;
2328+
}
2329+
} else {
2330+
pr_err("WARNING: kernel not compiled with CPU_SRSO.\n");
2331+
goto pred_cmd;
2332+
}
2333+
break;
2334+
23162335
default:
23172336
break;
23182337
}

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,9 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
14981498

14991499
if (sd->current_vmcb != svm->vmcb) {
15001500
sd->current_vmcb = svm->vmcb;
1501-
indirect_branch_prediction_barrier();
1501+
1502+
if (!cpu_feature_enabled(X86_FEATURE_IBPB_ON_VMEXIT))
1503+
indirect_branch_prediction_barrier();
15021504
}
15031505
if (kvm_vcpu_apicv_active(vcpu))
15041506
avic_vcpu_load(vcpu, cpu);

arch/x86/kvm/svm/vmenter.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ SYM_FUNC_START(__svm_vcpu_run)
224224
*/
225225
UNTRAIN_RET
226226

227+
/* SRSO */
228+
ALTERNATIVE "", "call entry_ibpb", X86_FEATURE_IBPB_ON_VMEXIT
229+
227230
/*
228231
* Clear all general purpose registers except RSP and RAX to prevent
229232
* speculative use of the guest's values, even those that are reloaded

0 commit comments

Comments
 (0)