Skip to content

Commit a694b1f

Browse files
bonzinigregkh
authored andcommitted
KVM: SVM: obey guest PAT
commit 15038e14724799b8c205beb5f20f9e54896013c3 upstream. For many years some users of assigned devices have reported worse performance on AMD processors with NPT than on AMD without NPT, Intel or bare metal. The reason turned out to be that SVM is discarding the guest PAT setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-, PA3=UC). The guest might be using a different setting, and especially might want write combining but isn't getting it (instead getting slow UC or UC- accesses). Thanks a lot to geoff@hostfission.com for noticing the relation to the g_pat setting. The patch has been tested also by a bunch of people on VFIO users forums. Fixes: 709ddeb Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: David Hildenbrand <david@redhat.com> Tested-by: Nick Sarnie <commendsarnex@gmail.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8293dc7 commit a694b1f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

arch/x86/kvm/svm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
31143114
u32 ecx = msr->index;
31153115
u64 data = msr->data;
31163116
switch (ecx) {
3117+
case MSR_IA32_CR_PAT:
3118+
if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
3119+
return 1;
3120+
vcpu->arch.pat = data;
3121+
svm->vmcb->save.g_pat = data;
3122+
mark_dirty(svm->vmcb, VMCB_NPT);
3123+
break;
31173124
case MSR_IA32_TSC:
31183125
kvm_write_tsc(vcpu, msr);
31193126
break;

0 commit comments

Comments
 (0)