From: Maxim Levitsky <mlevitsk@redhat.com>
To: kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
x86@kernel.org, Kees Cook <keescook@chromium.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Borislav Petkov <bp@alien8.de>, Joerg Roedel <joro@8bytes.org>,
Ingo Molnar <mingo@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
Maxim Levitsky <mlevitsk@redhat.com>
Subject: [PATCH v2 10/11] KVM: x86: SVM: use smram structs
Date: Tue, 21 Jun 2022 18:09:01 +0300 [thread overview]
Message-ID: <20220621150902.46126-11-mlevitsk@redhat.com> (raw)
In-Reply-To: <20220621150902.46126-1-mlevitsk@redhat.com>
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>
---
arch/x86/include/asm/kvm_host.h | 6 ------
arch/x86/kvm/svm/svm.c | 28 +++++++++++++++++-----------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 1038ccb7056a39..9e8467be96b4e6 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2057,12 +2057,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 136298cfb3fb57..8dcbbe839bef36 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4399,6 +4399,7 @@ static int svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
static int svm_enter_smm(struct kvm_vcpu *vcpu, char *smstate)
{
+ struct kvm_smram_state_64 *smram = (struct kvm_smram_state_64 *)smstate;
struct vcpu_svm *svm = to_svm(vcpu);
struct kvm_host_map map_save;
int ret;
@@ -4406,10 +4407,17 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, char *smstate)
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);
+ /*
+ * 32 bit SMRAM format doesn't preserve EFER and SVM state.
+ * SVM should not be enabled by the userspace without marking
+ * the CPU as at least long mode capable.
+ */
+
+ if (!guest_cpuid_has(vcpu, X86_FEATURE_SVM))
+ return 1;
+
+ smram->svm_guest_flag = 1;
+ smram->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];
@@ -4446,9 +4454,9 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, char *smstate)
static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
{
+ struct kvm_smram_state_64 *smram = (struct kvm_smram_state_64 *)smstate;
struct vcpu_svm *svm = to_svm(vcpu);
struct kvm_host_map map, map_save;
- u64 saved_efer, vmcb12_gpa;
struct vmcb *vmcb12;
int ret;
@@ -4456,18 +4464,16 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
return 0;
/* Non-zero if SMI arrived while vCPU was in guest mode. */
- if (!GET_SMSTATE(u64, smstate, 0x7ed8))
+ if (!smram->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->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->svm_guest_vmcb_gpa), &map) == -EINVAL)
return 1;
ret = 1;
@@ -4493,7 +4499,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
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->svm_guest_vmcb_gpa, vmcb12, false);
if (ret)
goto unmap_save;
--
2.26.3
next prev parent reply other threads:[~2022-06-21 15:10 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 15:08 [PATCH v2 00/11] SMM emulation and interrupt shadow fixes Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 01/11] KVM: x86: emulator: em_sysexit should update ctxt->mode Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 02/11] KVM: x86: emulator: introduce update_emulation_mode Maxim Levitsky
2022-07-20 23:44 ` Sean Christopherson
2022-07-21 11:52 ` Maxim Levitsky
2022-07-21 14:23 ` Sean Christopherson
2022-06-21 15:08 ` [PATCH v2 03/11] KVM: x86: emulator: remove assign_eip_near/far Maxim Levitsky
2022-07-20 23:51 ` Sean Christopherson
2022-07-21 11:52 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 04/11] KVM: x86: emulator: update the emulation mode after rsm Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 05/11] KVM: x86: emulator: update the emulation mode after CR0 write Maxim Levitsky
2022-07-20 23:50 ` Sean Christopherson
2022-07-21 11:53 ` Maxim Levitsky
2022-07-21 14:11 ` Sean Christopherson
2022-07-21 14:57 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 06/11] KVM: x86: emulator/smm: number of GPRs in the SMRAM image depends on the image format Maxim Levitsky
2022-07-21 0:06 ` Sean Christopherson
2022-07-21 0:09 ` Sean Christopherson
2022-06-21 15:08 ` [PATCH v2 07/11] KVM: x86: emulator/smm: add structs for KVM's smram layout Maxim Levitsky
2022-07-21 0:40 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 08/11] KVM: x86: emulator/smm: use smram struct for 32 bit smram load/restore Maxim Levitsky
2022-06-21 15:09 ` [PATCH v2 09/11] KVM: x86: emulator/smm: use smram struct for 64 " Maxim Levitsky
2022-07-21 0:38 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:09 ` Maxim Levitsky [this message]
2022-07-21 0:18 ` [PATCH v2 10/11] KVM: x86: SVM: use smram structs Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-07-21 0:39 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:09 ` [PATCH v2 11/11] KVM: x86: emulator/smm: preserve interrupt shadow in SMRAM Maxim Levitsky
2022-06-29 16:31 ` Jim Mattson
2022-06-30 6:00 ` Maxim Levitsky
2022-06-30 16:00 ` Jim Mattson
2022-07-05 13:38 ` Maxim Levitsky
2022-07-05 13:40 ` Maxim Levitsky
2022-07-05 13:51 ` Maxim Levitsky
2022-07-06 18:13 ` Jim Mattson
2022-07-06 20:00 ` Maxim Levitsky
2022-07-06 20:38 ` Jim Mattson
2022-07-10 16:05 ` Maxim Levitsky
2022-06-29 7:21 ` [PATCH v2 00/11] SMM emulation and interrupt shadow fixes Maxim Levitsky
2022-07-14 11:06 ` Maxim Levitsky
2022-07-20 8:47 ` Maxim Levitsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220621150902.46126-11-mlevitsk@redhat.com \
--to=mlevitsk@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox