]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0013-KVM-x86-SVM-use-smram-structs.patch
update submodule and patches to 6.1.14
[pve-kernel.git] / patches / kernel / 0013-KVM-x86-SVM-use-smram-structs.patch
CommitLineData
54ebe3cb
TL
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Maxim Levitsky <mlevitsk@redhat.com>
4fc427d9 3Date: Wed, 3 Aug 2022 18:50:09 +0300
54ebe3cb 4Subject: [PATCH] KVM: x86: SVM: use smram structs
826eb0ff
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
54ebe3cb
TL
8
9This removes the last user of put_smstate/GET_SMSTATE so
10remove these functions as well.
11
12Also add a sanity check that we don't attempt to enter the SMM
13on non long mode capable guest CPU with a running nested guest.
14
15Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
16Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
826eb0ff 17Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
54ebe3cb
TL
18---
19 arch/x86/include/asm/kvm_host.h | 6 ------
4fc427d9
TL
20 arch/x86/kvm/svm/svm.c | 21 ++++++---------------
21 2 files changed, 6 insertions(+), 21 deletions(-)
54ebe3cb
TL
22
23diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
12247ad0 24index 6885f3839e25..f5b82b6f4f84 100644
54ebe3cb
TL
25--- a/arch/x86/include/asm/kvm_host.h
26+++ b/arch/x86/include/asm/kvm_host.h
12247ad0 27@@ -2090,12 +2090,6 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
54ebe3cb
TL
28 #endif
29 }
30
31-#define put_smstate(type, buf, offset, val) \
32- *(type *)((buf) + (offset) - 0x7e00) = val
33-
34-#define GET_SMSTATE(type, buf, offset) \
35- (*(type *)((buf) + (offset) - 0x7e00))
36-
37 int kvm_cpu_dirty_log_size(void);
38
39 int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);
40diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
fc2b61b1 41index feb48828124e..023b6507a539 100644
54ebe3cb
TL
42--- a/arch/x86/kvm/svm/svm.c
43+++ b/arch/x86/kvm/svm/svm.c
fc2b61b1 44@@ -4397,15 +4397,11 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram)
54ebe3cb
TL
45 struct kvm_host_map map_save;
46 int ret;
4fc427d9
TL
47
48- char *smstate = (char *)smram;
49-
54ebe3cb
TL
50 if (!is_guest_mode(vcpu))
51 return 0;
52
53- /* FED8h - SVM Guest */
54- put_smstate(u64, smstate, 0x7ed8, 1);
55- /* FEE0h - SVM Guest VMCB Physical Address */
56- put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb12_gpa);
4fc427d9
TL
57+ smram->smram64.svm_guest_flag = 1;
58+ smram->smram64.svm_guest_vmcb_gpa = svm->nested.vmcb12_gpa;
54ebe3cb
TL
59
60 svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX];
61 svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP];
fc2b61b1 62@@ -4444,28 +4440,23 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
54ebe3cb 63 {
54ebe3cb
TL
64 struct vcpu_svm *svm = to_svm(vcpu);
65 struct kvm_host_map map, map_save;
66- u64 saved_efer, vmcb12_gpa;
67 struct vmcb *vmcb12;
68 int ret;
69
4fc427d9
TL
70- const char *smstate = (const char *)smram;
71-
72 if (!guest_cpuid_has(vcpu, X86_FEATURE_LM))
54ebe3cb
TL
73 return 0;
74
75 /* Non-zero if SMI arrived while vCPU was in guest mode. */
76- if (!GET_SMSTATE(u64, smstate, 0x7ed8))
4fc427d9 77+ if (!smram->smram64.svm_guest_flag)
54ebe3cb
TL
78 return 0;
79
80 if (!guest_cpuid_has(vcpu, X86_FEATURE_SVM))
81 return 1;
82
83- saved_efer = GET_SMSTATE(u64, smstate, 0x7ed0);
84- if (!(saved_efer & EFER_SVME))
4fc427d9 85+ if (!(smram->smram64.efer & EFER_SVME))
54ebe3cb
TL
86 return 1;
87
88- vmcb12_gpa = GET_SMSTATE(u64, smstate, 0x7ee0);
89- if (kvm_vcpu_map(vcpu, gpa_to_gfn(vmcb12_gpa), &map) == -EINVAL)
4fc427d9 90+ if (kvm_vcpu_map(vcpu, gpa_to_gfn(smram->smram64.svm_guest_vmcb_gpa), &map) == -EINVAL)
54ebe3cb
TL
91 return 1;
92
93 ret = 1;
fc2b61b1 94@@ -4491,7 +4482,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
54ebe3cb
TL
95 vmcb12 = map.hva;
96 nested_copy_vmcb_control_to_cache(svm, &vmcb12->control);
97 nested_copy_vmcb_save_to_cache(svm, &vmcb12->save);
98- ret = enter_svm_guest_mode(vcpu, vmcb12_gpa, vmcb12, false);
4fc427d9 99+ ret = enter_svm_guest_mode(vcpu, smram->smram64.svm_guest_vmcb_gpa, vmcb12, false);
54ebe3cb
TL
100
101 if (ret)
102 goto unmap_save;