From: Ladi Prosek Subject: [PATCH v2 4/6] KVM: nVMX: save nested EPT information in SMRAM state save map Date: Tue, 19 Sep 2017 17:37:06 +0200 Message-ID: <20170919153708.9019-5-lprosek@redhat.com> References: <20170919153708.9019-1-lprosek@redhat.com> Cc: rkrcmar@redhat.com, pbonzini@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37632 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbdISPhT (ORCPT ); Tue, 19 Sep 2017 11:37:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F66C4A70A for ; Tue, 19 Sep 2017 15:37:19 +0000 (UTC) In-Reply-To: <20170919153708.9019-1-lprosek@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: According to Intel SDM 34.14.1 "Default Treatment of SMI Delivery", if the cpu is in VMX non-root operation and EPT is enabled at the time of an SMI, this fact is recorded in the SMRAM state save area. Signed-off-by: Ladi Prosek --- arch/x86/include/asm/kvm_host.h | 5 +++++ arch/x86/kvm/vmx.c | 18 +++++++++++++++++- arch/x86/kvm/x86.c | 3 --- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9719347da965..414d362d9fe9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1441,4 +1441,9 @@ static inline int kvm_cpu_get_apicid(int mps_cpu) #endif } +#define get_smstate(type, buf, offset) \ + *(type *)((buf) + (offset) - 0x7e00) +#define put_smstate(type, buf, offset, val) \ + *(type *)((buf) + (offset) - 0x7e00) = val + #endif /* _ASM_X86_KVM_HOST_H */ diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index f37514f1d9cb..6d1c8ffc02ee 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11652,10 +11652,26 @@ static int vmx_smi_allowed(struct kvm_vcpu *vcpu) static int vmx_prep_enter_smm(struct kvm_vcpu *vcpu, char *smstate) { struct vcpu_vmx *vmx = to_vmx(vcpu); + struct vmcs12 *vmcs12; vmx->nested.smm.guest_mode = is_guest_mode(vcpu); - if (vmx->nested.smm.guest_mode) + if (vmx->nested.smm.guest_mode) { + vmcs12 = get_vmcs12(vcpu); + if (nested_cpu_has_ept(vmcs12)) { + /* + * 34.14.1 Default Treatment of SMI Delivery + * Bit 0 of the 32-bit field at offset SMBASE + 8000H + 7EE0H + * indicates whether the cpu was in VMX non-root operation with + * EPT enabled. + * The 64-bit field at offset SMBASE + 8000H + 7ED8H holds the + * value of the EPT pointer. + */ + put_smstate(u32, smstate, 0x7ee0, + get_smstate(u32, smstate, 0x7ee0) | 1); + put_smstate(u64, smstate, 0x7ed8, vmcs12->ept_pointer); + } nested_vmx_vmexit(vcpu, -1, 0, 0); + } vmx->nested.smm.vmxon = vmx->nested.vmxon; vmx->nested.vmxon = false; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index dad293ed2868..99cd41f1b1ee 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6451,9 +6451,6 @@ static void process_nmi(struct kvm_vcpu *vcpu) kvm_make_request(KVM_REQ_EVENT, vcpu); } -#define put_smstate(type, buf, offset, val) \ - *(type *)((buf) + (offset) - 0x7e00) = val - static u32 enter_smm_get_segment_flags(struct kvm_segment *seg) { u32 flags = 0; -- 2.13.5