From patchwork Mon Dec 16 09:32:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3352541 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4230E9F44E for ; Mon, 16 Dec 2013 09:33:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1AD052034D for ; Mon, 16 Dec 2013 09:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE64720382 for ; Mon, 16 Dec 2013 09:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753184Ab3LPJcp (ORCPT ); Mon, 16 Dec 2013 04:32:45 -0500 Received: from goliath.siemens.de ([192.35.17.28]:18684 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751848Ab3LPJco (ORCPT ); Mon, 16 Dec 2013 04:32:44 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id rBG9WZ7J027324; Mon, 16 Dec 2013 10:32:35 +0100 Received: from mchn199C.mchp.siemens.de ([146.254.78.38]) by mail1.siemens.de (8.14.3/8.14.3) with SMTP id rBG9WYYN001545; Mon, 16 Dec 2013 10:32:34 +0100 Message-ID: <52AEC8B2.7010602@siemens.com> Date: Mon, 16 Dec 2013 10:32:34 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Gleb Natapov , Paolo Bonzini CC: kvm Subject: [RFC][PATCH] KVM: nVMX: Leave VMX mode on apparent CPU reset Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As long as we do not expose all the VMX related states to user space, there is no way to properly reset a VCPU when VMX is enabled. Emulate this for now by catching host-side clearings of the feature control MSR. This allows to reboot a VM while it is running some hypervisor code. Signed-off-by: Jan Kiszka --- Better ideas? Or continue to leave it as it is? arch/x86/kvm/vmx.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index f90320b..da04247 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2455,6 +2455,8 @@ static int vmx_get_vmx_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) return 1; } +static void vmx_reset_nested(struct kvm_vcpu *vcpu); + static int vmx_set_vmx_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { u32 msr_index = msr_info->index; @@ -2470,6 +2472,12 @@ static int vmx_set_vmx_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) & FEATURE_CONTROL_LOCKED) return 0; to_vmx(vcpu)->nested.msr_ia32_feature_control = data; + /* + * Detect reset and allow to leave VMX mode this way until we + * expose all related states to user space. + */ + if (host_initialized && data == 0) + vmx_reset_nested(vcpu); return 1; } @@ -8487,6 +8495,33 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu) vmx->nested.sync_shadow_vmcs = true; } +static void vmx_reset_nested(struct kvm_vcpu *vcpu) +{ + struct vmcs12 *vmcs12 = get_vmcs12(vcpu); + struct vcpu_vmx *vmx = to_vmx(vcpu); + + if (!vmx->nested.vmxon) + return; + + if (is_guest_mode(vcpu)) { + vmcs12->host_cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET; + vmcs12->host_cr3 = 0; + vmcs12->host_cr4 = 0; + vmcs12->host_rsp = 0; + vmcs12->vm_exit_controls = 0; + nested_vmx_vmexit(vcpu); + } + + free_nested(vmx); + + /* + * If we were in guest mode, the reset state user space wrote so far + * is now inconsistent. If we were in host mode, some state update may + * have been rejected. So simply repeat the reset her. + */ + vmx_vcpu_reset(vcpu); +} + /* * L1's failure to enter L2 is a subset of a normal exit, as explained in * 23.7 "VM-entry failures during or after loading guest state" (this also