Skip to content

Commit 584aeda

Browse files
committed
KVM: x86: Move MSR_IA32_PRED_CMD WRMSR emulation to common code
Dedup the handling of MSR_IA32_PRED_CMD across VMX and SVM by moving the logic to kvm_set_msr_common(). Now that the MSR interception toggling is handled as part of setting guest CPUID, the VMX and SVM paths are identical. Opportunistically massage the code to make it a wee bit denser. Link: https://lore.kernel.org/r/20230322011440.2195485-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 5ac641d commit 584aeda

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,20 +2942,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
29422942
*/
29432943
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SPEC_CTRL, 1, 1);
29442944
break;
2945-
case MSR_IA32_PRED_CMD:
2946-
if (!msr->host_initiated &&
2947-
!guest_has_pred_cmd_msr(vcpu))
2948-
return 1;
2949-
2950-
if (data & ~PRED_CMD_IBPB)
2951-
return 1;
2952-
if (!boot_cpu_has(X86_FEATURE_IBPB))
2953-
return 1;
2954-
if (!data)
2955-
break;
2956-
2957-
wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB);
2958-
break;
29592945
case MSR_AMD64_VIRT_SPEC_CTRL:
29602946
if (!msr->host_initiated &&
29612947
!guest_cpuid_has(vcpu, X86_FEATURE_VIRT_SSBD))

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,20 +2285,6 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22852285
if (data & ~(TSX_CTRL_RTM_DISABLE | TSX_CTRL_CPUID_CLEAR))
22862286
return 1;
22872287
goto find_uret_msr;
2288-
case MSR_IA32_PRED_CMD:
2289-
if (!msr_info->host_initiated &&
2290-
!guest_has_pred_cmd_msr(vcpu))
2291-
return 1;
2292-
2293-
if (data & ~PRED_CMD_IBPB)
2294-
return 1;
2295-
if (!boot_cpu_has(X86_FEATURE_IBPB))
2296-
return 1;
2297-
if (!data)
2298-
break;
2299-
2300-
wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB);
2301-
break;
23022288
case MSR_IA32_CR_PAT:
23032289
if (!kvm_pat_valid(data))
23042290
return 1;

arch/x86/kvm/x86.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
36173617
vcpu->arch.perf_capabilities = data;
36183618
kvm_pmu_refresh(vcpu);
36193619
return 0;
3620+
case MSR_IA32_PRED_CMD:
3621+
if (!msr_info->host_initiated && !guest_has_pred_cmd_msr(vcpu))
3622+
return 1;
3623+
3624+
if (!boot_cpu_has(X86_FEATURE_IBPB) || (data & ~PRED_CMD_IBPB))
3625+
return 1;
3626+
if (!data)
3627+
break;
3628+
3629+
wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB);
3630+
break;
36203631
case MSR_EFER:
36213632
return set_efer(vcpu, msr_info);
36223633
case MSR_K7_HWCR:

0 commit comments

Comments
 (0)