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