Skip to content

Commit dee3219

Browse files
committed
KVM: x86: Move common handling of PAT MSR writes to kvm_set_msr_common()
Move the common check-and-set handling of PAT MSR writes out of vendor code and into kvm_set_msr_common(). This aligns writes with reads, which are already handled in common code, i.e. makes the handling of reads and writes symmetrical in common code. Alternatively, the common handling in kvm_get_msr_common() could be moved to vendor code, but duplicating code is generally undesirable (even though the duplicatated code is trivial in this case), and guest writes to PAT should be rare, i.e. the overhead of the extra function call is a non-issue in practice. Suggested-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://lore.kernel.org/r/20230511233351.635053-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3a5f490 commit dee3219

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,9 +2939,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
29392939

29402940
break;
29412941
case MSR_IA32_CR_PAT:
2942-
if (!kvm_pat_valid(data))
2943-
return 1;
2944-
vcpu->arch.pat = data;
2942+
ret = kvm_set_msr_common(vcpu, msr);
2943+
if (ret)
2944+
break;
2945+
29452946
svm->vmcb01.ptr->save.g_pat = data;
29462947
if (is_guest_mode(vcpu))
29472948
nested_vmcb02_compute_g_pat(svm);

arch/x86/kvm/vmx/vmx.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,10 +2287,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22872287
return 1;
22882288
goto find_uret_msr;
22892289
case MSR_IA32_CR_PAT:
2290-
if (!kvm_pat_valid(data))
2291-
return 1;
2292-
2293-
vcpu->arch.pat = data;
2290+
ret = kvm_set_msr_common(vcpu, msr_info);
2291+
if (ret)
2292+
break;
22942293

22952294
if (is_guest_mode(vcpu) &&
22962295
get_vmcs12(vcpu)->vm_exit_controls & VM_EXIT_SAVE_IA32_PAT)

arch/x86/kvm/x86.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,12 +3703,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
37033703
}
37043704
break;
37053705
case MSR_IA32_CR_PAT:
3706-
/*
3707-
* Writes to PAT should be handled by vendor code as both SVM
3708-
* and VMX track the guest's PAT in the VMCB/VMCS.
3709-
*/
3710-
WARN_ON_ONCE(1);
3711-
37123706
if (!kvm_pat_valid(data))
37133707
return 1;
37143708

0 commit comments

Comments
 (0)