]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0010-KVM-SVM-obey-guest-PAT.patch
fix #1537: cherry-pick AMD NPT / IOMMU fix
[pve-kernel.git] / patches / kernel / 0010-KVM-SVM-obey-guest-PAT.patch
CommitLineData
9e94988c
FG
1From 08d71587b34c95d5461a6bdd946dc1dd46888bf3 Mon Sep 17 00:00:00 2001
2From: Paolo Bonzini <pbonzini@redhat.com>
3Date: Thu, 26 Oct 2017 09:13:27 +0200
4Subject: [PATCH 10/10] KVM: SVM: obey guest PAT
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9For many years some users of assigned devices have reported worse
10performance on AMD processors with NPT than on AMD without NPT,
11Intel or bare metal.
12
13The reason turned out to be that SVM is discarding the guest PAT
14setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
15PA3=UC). The guest might be using a different setting, and
16especially might want write combining but isn't getting it
17(instead getting slow UC or UC- accesses).
18
19Thanks a lot to geoff@hostfission.com for noticing the relation
20to the g_pat setting. The patch has been tested also by a bunch
21of people on VFIO users forums.
22
23Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
24Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
25Cc: stable@vger.kernel.org
26Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
27Reviewed-by: David Hildenbrand <david@redhat.com>
28Tested-by: Nick Sarnie <commendsarnex@gmail.com>
29Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
30(cherry picked from commit 15038e14724799b8c205beb5f20f9e54896013c3)
31Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
32---
33 arch/x86/kvm/svm.c | 7 +++++++
34 1 file changed, 7 insertions(+)
35
36diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
37index af256b786a70..af09baa3d736 100644
38--- a/arch/x86/kvm/svm.c
39+++ b/arch/x86/kvm/svm.c
40@@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
41 u32 ecx = msr->index;
42 u64 data = msr->data;
43 switch (ecx) {
44+ case MSR_IA32_CR_PAT:
45+ if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
46+ return 1;
47+ vcpu->arch.pat = data;
48+ svm->vmcb->save.g_pat = data;
49+ mark_dirty(svm->vmcb, VMCB_NPT);
50+ break;
51 case MSR_IA32_TSC:
52 kvm_write_tsc(vcpu, msr);
53 break;
54--
552.14.2
56