Skip to content

Commit bbb69e8

Browse files
jpoimboesuryasaimadhu
authored andcommitted
x86/speculation: Use cached host SPEC_CTRL value for guest entry/exit
There's no need to recalculate the host value for every entry/exit. Just use the cached value in spec_ctrl_current(). Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]>
1 parent 56aa4d2 commit bbb69e8

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void __init check_bugs(void)
208208
void
209209
x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
210210
{
211-
u64 msrval, guestval, hostval = x86_spec_ctrl_base;
211+
u64 msrval, guestval, hostval = spec_ctrl_current();
212212
struct thread_info *ti = current_thread_info();
213213

214214
/* Is MSR_SPEC_CTRL implemented ? */
@@ -221,15 +221,6 @@ x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
221221
guestval = hostval & ~x86_spec_ctrl_mask;
222222
guestval |= guest_spec_ctrl & x86_spec_ctrl_mask;
223223

224-
/* SSBD controlled in MSR_SPEC_CTRL */
225-
if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
226-
static_cpu_has(X86_FEATURE_AMD_SSBD))
227-
hostval |= ssbd_tif_to_spec_ctrl(ti->flags);
228-
229-
/* Conditional STIBP enabled? */
230-
if (static_branch_unlikely(&switch_to_cond_stibp))
231-
hostval |= stibp_tif_to_spec_ctrl(ti->flags);
232-
233224
if (hostval != guestval) {
234225
msrval = setguest ? guestval : hostval;
235226
wrmsrl(MSR_IA32_SPEC_CTRL, msrval);
@@ -1397,7 +1388,6 @@ static void __init spectre_v2_select_mitigation(void)
13971388
pr_err(SPECTRE_V2_EIBRS_EBPF_MSG);
13981389

13991390
if (spectre_v2_in_ibrs_mode(mode)) {
1400-
/* Force it so VMEXIT will restore correctly */
14011391
x86_spec_ctrl_base |= SPEC_CTRL_IBRS;
14021392
write_spec_ctrl_current(x86_spec_ctrl_base, true);
14031393
}

0 commit comments

Comments
 (0)