]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0009-KVM-SVM-obey-guest-PAT.patch
cc64a62fb722f69529859e763b4aba4aa63c3fd9
[pve-kernel.git] / patches / kernel / 0009-KVM-SVM-obey-guest-PAT.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Paolo Bonzini <pbonzini@redhat.com>
3 Date: Thu, 26 Oct 2017 09:13:27 +0200
4 Subject: [PATCH] KVM: SVM: obey guest PAT
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 For many years some users of assigned devices have reported worse
10 performance on AMD processors with NPT than on AMD without NPT,
11 Intel or bare metal.
12
13 The reason turned out to be that SVM is discarding the guest PAT
14 setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
15 PA3=UC). The guest might be using a different setting, and
16 especially might want write combining but isn't getting it
17 (instead getting slow UC or UC- accesses).
18
19 Thanks a lot to geoff@hostfission.com for noticing the relation
20 to the g_pat setting. The patch has been tested also by a bunch
21 of people on VFIO users forums.
22
23 Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
24 Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
25 Cc: stable@vger.kernel.org
26 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
27 Reviewed-by: David Hildenbrand <david@redhat.com>
28 Tested-by: Nick Sarnie <commendsarnex@gmail.com>
29 Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
30 (cherry picked from commit 15038e14724799b8c205beb5f20f9e54896013c3)
31 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
32 ---
33 arch/x86/kvm/svm.c | 7 +++++++
34 1 file changed, 7 insertions(+)
35
36 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
37 index a8c911fcd73f..e9d0f80fd83a 100644
38 --- a/arch/x86/kvm/svm.c
39 +++ b/arch/x86/kvm/svm.c
40 @@ -3650,6 +3650,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 --
55 2.14.2
56