826eb0ff89
but allow discarding BTF information when loading modules, so that upgrades which are otherwise ABI compatible still work. this allows using BTF information when matching and available, while degrading gracefully if the currently running kernel is not identical to the one that module was built for. in case of a mismatch, the kernel will log a warning when loading the module, for example: Jan 30 13:57:58 test kernel: BPF: type_id=184 bits_offset=4096 Jan 30 13:57:58 test kernel: BPF: Jan 30 13:57:58 test kernel: BPF: Invalid name Jan 30 13:57:58 test kernel: BPF: Jan 30 13:57:58 test kernel: failed to validate module [bonding] BTF: -22 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
103 lines
3.5 KiB
Diff
103 lines
3.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Maxim Levitsky <mlevitsk@redhat.com>
|
|
Date: Wed, 3 Aug 2022 18:50:09 +0300
|
|
Subject: [PATCH] KVM: x86: SVM: use smram structs
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
This removes the last user of put_smstate/GET_SMSTATE so
|
|
remove these functions as well.
|
|
|
|
Also add a sanity check that we don't attempt to enter the SMM
|
|
on non long mode capable guest CPU with a running nested guest.
|
|
|
|
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
|
|
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
|
|
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
|
|
---
|
|
arch/x86/include/asm/kvm_host.h | 6 ------
|
|
arch/x86/kvm/svm/svm.c | 21 ++++++---------------
|
|
2 files changed, 6 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
|
|
index 6885f3839e25..f5b82b6f4f84 100644
|
|
--- a/arch/x86/include/asm/kvm_host.h
|
|
+++ b/arch/x86/include/asm/kvm_host.h
|
|
@@ -2090,12 +2090,6 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
|
|
#endif
|
|
}
|
|
|
|
-#define put_smstate(type, buf, offset, val) \
|
|
- *(type *)((buf) + (offset) - 0x7e00) = val
|
|
-
|
|
-#define GET_SMSTATE(type, buf, offset) \
|
|
- (*(type *)((buf) + (offset) - 0x7e00))
|
|
-
|
|
int kvm_cpu_dirty_log_size(void);
|
|
|
|
int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);
|
|
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
|
|
index 45c4def86cd3..bfacbef667d7 100644
|
|
--- a/arch/x86/kvm/svm/svm.c
|
|
+++ b/arch/x86/kvm/svm/svm.c
|
|
@@ -4391,15 +4391,11 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram)
|
|
struct kvm_host_map map_save;
|
|
int ret;
|
|
|
|
- char *smstate = (char *)smram;
|
|
-
|
|
if (!is_guest_mode(vcpu))
|
|
return 0;
|
|
|
|
- /* FED8h - SVM Guest */
|
|
- put_smstate(u64, smstate, 0x7ed8, 1);
|
|
- /* FEE0h - SVM Guest VMCB Physical Address */
|
|
- put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb12_gpa);
|
|
+ smram->smram64.svm_guest_flag = 1;
|
|
+ smram->smram64.svm_guest_vmcb_gpa = svm->nested.vmcb12_gpa;
|
|
|
|
svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX];
|
|
svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP];
|
|
@@ -4438,28 +4434,23 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
|
|
{
|
|
struct vcpu_svm *svm = to_svm(vcpu);
|
|
struct kvm_host_map map, map_save;
|
|
- u64 saved_efer, vmcb12_gpa;
|
|
struct vmcb *vmcb12;
|
|
int ret;
|
|
|
|
- const char *smstate = (const char *)smram;
|
|
-
|
|
if (!guest_cpuid_has(vcpu, X86_FEATURE_LM))
|
|
return 0;
|
|
|
|
/* Non-zero if SMI arrived while vCPU was in guest mode. */
|
|
- if (!GET_SMSTATE(u64, smstate, 0x7ed8))
|
|
+ if (!smram->smram64.svm_guest_flag)
|
|
return 0;
|
|
|
|
if (!guest_cpuid_has(vcpu, X86_FEATURE_SVM))
|
|
return 1;
|
|
|
|
- saved_efer = GET_SMSTATE(u64, smstate, 0x7ed0);
|
|
- if (!(saved_efer & EFER_SVME))
|
|
+ if (!(smram->smram64.efer & EFER_SVME))
|
|
return 1;
|
|
|
|
- vmcb12_gpa = GET_SMSTATE(u64, smstate, 0x7ee0);
|
|
- if (kvm_vcpu_map(vcpu, gpa_to_gfn(vmcb12_gpa), &map) == -EINVAL)
|
|
+ if (kvm_vcpu_map(vcpu, gpa_to_gfn(smram->smram64.svm_guest_vmcb_gpa), &map) == -EINVAL)
|
|
return 1;
|
|
|
|
ret = 1;
|
|
@@ -4485,7 +4476,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
|
|
vmcb12 = map.hva;
|
|
nested_copy_vmcb_control_to_cache(svm, &vmcb12->control);
|
|
nested_copy_vmcb_save_to_cache(svm, &vmcb12->save);
|
|
- ret = enter_svm_guest_mode(vcpu, vmcb12_gpa, vmcb12, false);
|
|
+ ret = enter_svm_guest_mode(vcpu, smram->smram64.svm_guest_vmcb_gpa, vmcb12, false);
|
|
|
|
if (ret)
|
|
goto unmap_save;
|