Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11088758ybi; Thu, 25 Jul 2019 09:47:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYdYQNSb5AmQdNgki1qg8pH1Oyn0KxsWBS5uqToZY99AYK7gnb7Rx0W0QFaVhMwzmffHYy X-Received: by 2002:a17:90a:26ea:: with SMTP id m97mr93943903pje.59.1564073220134; Thu, 25 Jul 2019 09:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564073220; cv=none; d=google.com; s=arc-20160816; b=wUOlJU0EvylDq2mryupcUEAsGYBv8pWsT5bAeG8y6HXZrA0wm+xut68NEahxXYAvTK JQ1V1Kicj6xFO1VVmWbWuldh2y/d8M8U6LHkKM4UtfD85FKEZtxrwuxj/aGWiZ92sI2m 7TijrJhrE7JtSQb6pGv/w2GozhVt5VOxDdrk/PNkHPozlYaqCZqcu7kyJiZrQQxV4cNL 8mZnZ/F2jtf5gTfOj9xBzBgNOfBUY5NmDzOCPZ/KOq6J01914jAqHt2VkQJ7Bx3nZVAr 70E0NFv4F64kbriBCS3r/Neyq1ot2UFu+P0CD812infEFr0TEfUskF3kjx627R3xFkJo TEWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fP/uxcOzwVHr7L9oUh6zQGOUjqLibLxYvQKPmz0udDQ=; b=ouuqbBr7M1ujbFiWxBeZoLcCqsjTU2uBkir2yQnHgFtHuezTb1SlmRG1UI7eo9PCLD ohCMEiYMU5EDzqv8CQWY3rI1kw9dvofUF662fZdacUGin6jQo+kZbiFiCPfScojl3EiX aGVkZKsuzo5he+i02VHWC1MoTPMfInPGsMOYzKzYfejiOGvFumVBC7XuPwPpMiqRjR+g ztAaTTKxTGul57vHvWPYDvMOvHJxndROEbS/NkOAQeqKpj7zujh9jDzuI+7qr8Dv3y4a rkp7Z+cM2PVu5hJdIcDIqQryk11AEiw/GgU0Rkav1pqfeFq4XMuZ0x3QwblJ1SLOaWU1 mYbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u23si15742247pgb.503.2019.07.25.09.46.45; Thu, 25 Jul 2019 09:47:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728685AbfGYKqx (ORCPT + 99 others); Thu, 25 Jul 2019 06:46:53 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35822 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728376AbfGYKqu (ORCPT ); Thu, 25 Jul 2019 06:46:50 -0400 Received: by mail-wr1-f65.google.com with SMTP id y4so50263720wrm.2 for ; Thu, 25 Jul 2019 03:46:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fP/uxcOzwVHr7L9oUh6zQGOUjqLibLxYvQKPmz0udDQ=; b=jJObse833uuBhN+/fUnpi5pE3InvEvzGoARn1kFPqYkdFTE2ITp7Qy4c2exPNFsWKs W77dPVu/xeijzOeO9KFlkDBjpYWtQDHePY+plEbAsZ4xA0mbPDl5PPnlM28P4e8brW6x rMVJKCPCPVAz5l7FfhGKlbBXevZMlGVhmWOBf2YDdfortSyATfwMI6AdvU6u0jGoO1Df 95sQg6W+ibHJEXa0Hzq3xl0+fodQz9ReTB4RVooZTgt9/KcT4Wf5XgxpK0IJJDucNa+x oH/+TG4DOPKMWrsXHAYWUAYMFjSGt5AGCVGTaHWk/KaJKraW32aXy7JmaxnoEzAzyNCT ZWlg== X-Gm-Message-State: APjAAAXcdE4z9o5u6ktnwSGoZSH17jCOQamFbi7fgyN/EIZV6Xre+8Nx tMmlKiLmDSTd2tKLRE+5LDt4pg== X-Received: by 2002:adf:b1d1:: with SMTP id r17mr94675892wra.273.1564051608781; Thu, 25 Jul 2019 03:46:48 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id f204sm72042696wme.18.2019.07.25.03.46.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 03:46:48 -0700 (PDT) From: Vitaly Kuznetsov To: stable@vger.kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH stable-4.19 1/2] KVM: nVMX: do not use dangling shadow VMCS after guest reset Date: Thu, 25 Jul 2019 12:46:44 +0200 Message-Id: <20190725104645.30642-2-vkuznets@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725104645.30642-1-vkuznets@redhat.com> References: <20190725104645.30642-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini [ Upstream commit 88dddc11a8d6b09201b4db9d255b3394d9bc9e57 ] If a KVM guest is reset while running a nested guest, free_nested will disable the shadow VMCS execution control in the vmcs01. However, on the next KVM_RUN vmx_vcpu_run would nevertheless try to sync the VMCS12 to the shadow VMCS which has since been freed. This causes a vmptrld of a NULL pointer on my machime, but Jan reports the host to hang altogether. Let's see how much this trivial patch fixes. Reported-by: Jan Kiszka Cc: Liran Alon Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 73d6d585dd66..880bc36a0d5d 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -8457,6 +8457,7 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx) { vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_SHADOW_VMCS); vmcs_write64(VMCS_LINK_POINTER, -1ull); + vmx->nested.sync_shadow_vmcs = false; } static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) @@ -8468,7 +8469,6 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) /* copy to memory all shadowed fields in case they were modified */ copy_shadow_to_vmcs12(vmx); - vmx->nested.sync_shadow_vmcs = false; vmx_disable_shadow_vmcs(vmx); } vmx->nested.posted_intr_nv = -1; @@ -8668,6 +8668,9 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx) u64 field_value; struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs; + if (WARN_ON(!shadow_vmcs)) + return; + preempt_disable(); vmcs_load(shadow_vmcs); @@ -8706,6 +8709,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx) u64 field_value = 0; struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs; + if (WARN_ON(!shadow_vmcs)) + return; + vmcs_load(shadow_vmcs); for (q = 0; q < ARRAY_SIZE(fields); q++) { -- 2.20.1