From patchwork Wed Sep 13 14:06:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladi Prosek X-Patchwork-Id: 9951459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A79060360 for ; Wed, 13 Sep 2017 14:07:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CE49223C6 for ; Wed, 13 Sep 2017 14:07:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51E0926E3A; Wed, 13 Sep 2017 14:07:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A6C226E74 for ; Wed, 13 Sep 2017 14:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751870AbdIMOGo (ORCPT ); Wed, 13 Sep 2017 10:06:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45130 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751846AbdIMOGl (ORCPT ); Wed, 13 Sep 2017 10:06:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07A9980F75 for ; Wed, 13 Sep 2017 14:06:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 07A9980F75 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lprosek@redhat.com Received: from dhcp-1-107.brq.redhat.com (ovpn-204-166.brq.redhat.com [10.40.204.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D32A614CF; Wed, 13 Sep 2017 14:06:39 +0000 (UTC) From: Ladi Prosek To: kvm@vger.kernel.org Cc: rkrcmar@redhat.com Subject: [PATCH 3/5] KVM: nVMX: save nested EPT information in SMRAM state save map Date: Wed, 13 Sep 2017 16:06:26 +0200 Message-Id: <20170913140628.7787-4-lprosek@redhat.com> In-Reply-To: <20170913140628.7787-1-lprosek@redhat.com> References: <20170913140628.7787-1-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 13 Sep 2017 14:06:41 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 26acdb3..6c89d4f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1440,4 +1440,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 4926df2..875c3ff 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11644,10 +11644,26 @@ static void vmx_setup_mce(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 21ade70..7af9ab8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6447,9 +6447,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;