Commit dee32197 authored by Sean Christopherson's avatar Sean Christopherson

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: default avatarKai Huang <kai.huang@intel.com>
Reviewed-by: default avatarKai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20230511233351.635053-9-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 3a5f4907
...@@ -2939,9 +2939,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) ...@@ -2939,9 +2939,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
break; break;
case MSR_IA32_CR_PAT: case MSR_IA32_CR_PAT:
if (!kvm_pat_valid(data)) ret = kvm_set_msr_common(vcpu, msr);
return 1; if (ret)
vcpu->arch.pat = data; break;
svm->vmcb01.ptr->save.g_pat = data; svm->vmcb01.ptr->save.g_pat = data;
if (is_guest_mode(vcpu)) if (is_guest_mode(vcpu))
nested_vmcb02_compute_g_pat(svm); nested_vmcb02_compute_g_pat(svm);
......
...@@ -2287,10 +2287,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2287,10 +2287,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
return 1; return 1;
goto find_uret_msr; goto find_uret_msr;
case MSR_IA32_CR_PAT: case MSR_IA32_CR_PAT:
if (!kvm_pat_valid(data)) ret = kvm_set_msr_common(vcpu, msr_info);
return 1; if (ret)
break;
vcpu->arch.pat = data;
if (is_guest_mode(vcpu) && if (is_guest_mode(vcpu) &&
get_vmcs12(vcpu)->vm_exit_controls & VM_EXIT_SAVE_IA32_PAT) get_vmcs12(vcpu)->vm_exit_controls & VM_EXIT_SAVE_IA32_PAT)
......
...@@ -3703,12 +3703,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -3703,12 +3703,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
} }
break; break;
case MSR_IA32_CR_PAT: case MSR_IA32_CR_PAT:
/*
* Writes to PAT should be handled by vendor code as both SVM
* and VMX track the guest's PAT in the VMCB/VMCS.
*/
WARN_ON_ONCE(1);
if (!kvm_pat_valid(data)) if (!kvm_pat_valid(data))
return 1; return 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment