From patchwork Thu Jul 17 04:56:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 4572671 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 5086A9F3B4 for ; Thu, 17 Jul 2014 04:58:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 813E320148 for ; Thu, 17 Jul 2014 04:58:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2223200ED for ; Thu, 17 Jul 2014 04:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753831AbaGQE5m (ORCPT ); Thu, 17 Jul 2014 00:57:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:51947 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbaGQE5j (ORCPT ); Thu, 17 Jul 2014 00:57:39 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 16 Jul 2014 21:57:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,675,1400050800"; d="scan'208";a="544579435" Received: from wanpengl-mobl.ccr.corp.intel.com (HELO localhost) ([10.238.130.27]) by orsmga001.jf.intel.com with ESMTP; 16 Jul 2014 21:57:34 -0700 From: Wanpeng Li To: Paolo Bonzini , Jan Kiszka Cc: Marcelo Tosatti , Gleb Natapov , Bandan Das , Zhang Yang , Hu Robert , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH 3/3] KVM: nVMX: Fix vmptrld fail and vmwrite error when L1 goes down Date: Thu, 17 Jul 2014 12:56:51 +0800 Message-Id: <1405573011-41330-3-git-send-email-wanpeng.li@linux.intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1405573011-41330-1-git-send-email-wanpeng.li@linux.intel.com> References: <1405573011-41330-1-git-send-email-wanpeng.li@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 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 This bug can be trigger by L1 goes down directly w/ enable_shadow_vmcs. [ 6413.158950] kvm: vmptrld (null)/780000000000 failed [ 6413.158954] vmwrite error: reg 401e value 4 (err 1) [ 6413.158957] CPU: 0 PID: 4840 Comm: qemu-system-x86 Tainted: G OE 3.16.0kvm+ #2 [ 6413.158958] Hardware name: Dell Inc. OptiPlex 9020/0DNKMN, BIOS A05 12/05/2013 [ 6413.158959] 0000000000000003 ffff880210c9fb58 ffffffff81741de9 ffff8800d7433f80 [ 6413.158960] ffff880210c9fb68 ffffffffa059fa08 ffff880210c9fb78 ffffffffa05938bf [ 6413.158962] ffff880210c9fba8 ffffffffa059a97f ffff8800d7433f80 0000000000000003 [ 6413.158963] Call Trace: [ 6413.158968] [] dump_stack+0x45/0x56 [ 6413.158972] [] vmwrite_error+0x2c/0x2e [kvm_intel] [ 6413.158974] [] vmcs_writel+0x1f/0x30 [kvm_intel] [ 6413.158976] [] free_nested.part.73+0x5f/0x170 [kvm_intel] [ 6413.158978] [] vmx_free_vcpu+0x33/0x70 [kvm_intel] [ 6413.158991] [] kvm_arch_vcpu_free+0x44/0x50 [kvm] [ 6413.158998] [] kvm_arch_destroy_vm+0xf2/0x1f0 [kvm] Commit 26a865 (KVM: VMX: fix use after free of vmx->loaded_vmcs) fix the use after free bug by move free_loaded_vmcs() before free_nested(), however, this lead to free loaded_vmcs->vmcs premature and vmptrld load a NULL pointer during sync shadow vmcs to vmcs12. In addition, vmwrite which used to disable shadow vmcs and reset VMCS_LINK_POINTER failed since there is no valid current-VMCS. This patch fix it by skipping sync shadow vmcs and reset vmcs field for L1 destroy since they will be reinitialized after L1 recreate. Signed-off-by: Wanpeng Li --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index fbce89e..2b28da7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6113,9 +6113,9 @@ static void free_nested(struct vcpu_vmx *vmx) return; vmx->nested.vmxon = false; if (vmx->nested.current_vmptr != -1ull) { - nested_release_vmcs12(vmx); vmx->nested.current_vmptr = -1ull; vmx->nested.current_vmcs12 = NULL; + nested_release_vmcs12(vmx); } if (enable_shadow_vmcs) free_vmcs(vmx->nested.current_shadow_vmcs);