From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ladi Prosek Subject: [PATCH v3 0/6] KVM: nested virt SMM fixes Date: Mon, 25 Sep 2017 10:08:58 +0200 Message-ID: <20170925080904.24850-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]:46398 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932117AbdIYIJN (ORCPT ); Mon, 25 Sep 2017 04:09:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CEA3981DFE for ; Mon, 25 Sep 2017 08:09:13 +0000 (UTC) Sender: kvm-owner@vger.kernel.org List-ID: Windows Server 2016 with Hyper-V enabled fails to boot on OVMF with SMM (OVMF_CODE-need-smm.fd). Turns out that the SMM emulation code in KVM does not handle nested virtualization very well, leading to a whole bunch of issues. For example, Hyper-V uses descriptor table exiting (SECONDARY_EXEC_DESC) so when the SMM handler tries to switch from real mode a VM exit occurs and is forwarded to a clueless L1. This series fixes it by switching the vcpu to !guest_mode, i.e. to the L1 state, before entering SMM and then switching back to L2 after the RSM instruction is emulated. Patches 1 and 2 are common for both Intel and AMD, patch 3 fixes Intel, and patches 5-6 AMD. Patch 4 prevents CR4.VMXE from being set in SMM on Intel. It is however not required to make Windows work. v1->v2: * Moved left_smm detection to emulator_set_hflags (couldn't quite get rid of the field despite my original claim) (Paolo) * Moved the kvm_x86_ops->post_leave_smm() call a few statements down so it really runs after all state has been synced. * Added the smi_allowed callback (new patch 2) to avoid running into WARN_ON_ONCE(vmx->nested.nested_run_pending) on Intel. v2->v3: * Ommitted patch 4 ("KVM: nVMX: save nested EPT information in SMRAM state save map") and replaced it with ("treat CR4.VMXE as reserved in SMM") (Paolo) * Implemented smi_allowed on AMD to support SMI interception. Turns out Windows needs this when running on >1 vCPU. * Eliminated internal SMM state on AMD and switched to using the SMM state save area in guest memory instead (Paolo) Ladi Prosek (6): KVM: x86: introduce ISA specific SMM entry/exit callbacks KVM: x86: introduce ISA specific smi_allowed callback KVM: nVMX: fix SMI injection in guest mode KVM: nVMX: treat CR4.VMXE as reserved in SMM KVM: nSVM: refactor nested_svm_vmrun KVM: nSVM: fix SMI injection in guest mode arch/x86/include/asm/kvm_emulate.h | 2 + arch/x86/include/asm/kvm_host.h | 7 ++ arch/x86/kvm/emulate.c | 18 +++- arch/x86/kvm/svm.c | 205 +++++++++++++++++++++++++------------ arch/x86/kvm/vmx.c | 79 ++++++++++++-- arch/x86/kvm/x86.c | 18 +++- 6 files changed, 249 insertions(+), 80 deletions(-)