]>
Commit | Line | Data |
---|---|---|
54ebe3cb TL |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Maxim Levitsky <mlevitsk@redhat.com> | |
4fc427d9 | 3 | Date: Wed, 3 Aug 2022 18:50:09 +0300 |
54ebe3cb TL |
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 ------ | |
4fc427d9 TL |
16 | arch/x86/kvm/svm/svm.c | 21 ++++++--------------- |
17 | 2 files changed, 6 insertions(+), 21 deletions(-) | |
54ebe3cb TL |
18 | |
19 | diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h | |
12247ad0 | 20 | index 6885f3839e25..f5b82b6f4f84 100644 |
54ebe3cb TL |
21 | --- a/arch/x86/include/asm/kvm_host.h |
22 | +++ b/arch/x86/include/asm/kvm_host.h | |
12247ad0 | 23 | @@ -2090,12 +2090,6 @@ static inline int kvm_cpu_get_apicid(int mps_cpu) |
54ebe3cb TL |
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 | |
12247ad0 | 37 | index 45c4def86cd3..bfacbef667d7 100644 |
54ebe3cb TL |
38 | --- a/arch/x86/kvm/svm/svm.c |
39 | +++ b/arch/x86/kvm/svm/svm.c | |
12247ad0 | 40 | @@ -4391,15 +4391,11 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram) |
54ebe3cb TL |
41 | struct kvm_host_map map_save; |
42 | int ret; | |
4fc427d9 TL |
43 | |
44 | - char *smstate = (char *)smram; | |
45 | - | |
54ebe3cb TL |
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); | |
4fc427d9 TL |
53 | + smram->smram64.svm_guest_flag = 1; |
54 | + smram->smram64.svm_guest_vmcb_gpa = svm->nested.vmcb12_gpa; | |
54ebe3cb TL |
55 | |
56 | svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX]; | |
57 | svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP]; | |
12247ad0 | 58 | @@ -4438,28 +4434,23 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram) |
54ebe3cb | 59 | { |
54ebe3cb TL |
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 | ||
4fc427d9 TL |
66 | - const char *smstate = (const char *)smram; |
67 | - | |
68 | if (!guest_cpuid_has(vcpu, X86_FEATURE_LM)) | |
54ebe3cb TL |
69 | return 0; |
70 | ||
71 | /* Non-zero if SMI arrived while vCPU was in guest mode. */ | |
72 | - if (!GET_SMSTATE(u64, smstate, 0x7ed8)) | |
4fc427d9 | 73 | + if (!smram->smram64.svm_guest_flag) |
54ebe3cb TL |
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)) | |
4fc427d9 | 81 | + if (!(smram->smram64.efer & EFER_SVME)) |
54ebe3cb TL |
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) | |
4fc427d9 | 86 | + if (kvm_vcpu_map(vcpu, gpa_to_gfn(smram->smram64.svm_guest_vmcb_gpa), &map) == -EINVAL) |
54ebe3cb TL |
87 | return 1; |
88 | ||
89 | ret = 1; | |
12247ad0 | 90 | @@ -4485,7 +4476,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram) |
54ebe3cb TL |
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); | |
4fc427d9 | 95 | + ret = enter_svm_guest_mode(vcpu, smram->smram64.svm_guest_vmcb_gpa, vmcb12, false); |
54ebe3cb TL |
96 | |
97 | if (ret) | |
98 | goto unmap_save; |