From patchwork Thu Jul 25 11:49:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 11058717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 246A1138D for ; Thu, 25 Jul 2019 11:50:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1114428722 for ; Thu, 25 Jul 2019 11:50:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F338128970; Thu, 25 Jul 2019 11:50:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 969E028722 for ; Thu, 25 Jul 2019 11:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404325AbfGYLtn (ORCPT ); Thu, 25 Jul 2019 07:49:43 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38340 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404292AbfGYLtn (ORCPT ); Thu, 25 Jul 2019 07:49:43 -0400 Received: by mail-wm1-f66.google.com with SMTP id s15so23102757wmj.3 for ; Thu, 25 Jul 2019 04:49:42 -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=ahpb6xPK075Z6njHxQUERLqrZnJthEhBDnChxsDJ0yI=; b=Qx9lGeub0o7AUamHE34nZWPZ4DFbSzRlMur5WPEokKCvVpH9ekx2vrfXXgybx+rEkR rLGbFYaUVqH3nnN5vlnzit17iOUXrRMGyKEBeGL42QxMk8TVAPfXMqjJwmm32YKlf48m j8Yb5kXfXJZxr+H4OKpBbDPLTFzJX7yoSdjuxFrDCiBMpd/UZnc+OP3RH1hJLr9dxEW7 OCakhF0UsPKj2veMS2/MNEyzy46c5rTkuxtWCUK3eL4/3wM7rmrBZ0S21DB4e4LKW5sB e1RuZFUW/EsCysL2sGfn+AVlsBBJrgguh75ciwfrzmKieQ7MCak2c1QxxaKxP+SX13mw 26bg== X-Gm-Message-State: APjAAAUE9VKyMDhUg3/LAF87V4yARrkv2v4V3QHzzuguTpkAdEWMX8EW iq4msjjtQbRbdgi5O6UYIzvj8w== X-Google-Smtp-Source: APXvYqysh53Nn7YpCuVhrX6td5G/bTjwKnhelBX4YvIb8Js+9A/cGM/O1IBBsQ19J2X8WwmSCryqSg== X-Received: by 2002:a7b:cf0b:: with SMTP id l11mr83901119wmg.143.1564055381570; Thu, 25 Jul 2019 04:49:41 -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 t140sm44784683wmt.0.2019.07.25.04.49.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 04:49:41 -0700 (PDT) From: Vitaly Kuznetsov To: stable@vger.kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Subject: [PATCH stable-5.1 1/3] KVM: nVMX: do not use dangling shadow VMCS after guest reset Date: Thu, 25 Jul 2019 13:49:36 +0200 Message-Id: <20190725114938.3976-2-vkuznets@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725114938.3976-1-vkuznets@redhat.com> References: <20190725114938.3976-1-vkuznets@redhat.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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/nested.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 4ca834d22169..3f48006a43ec 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -184,6 +184,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.need_vmcs12_sync = false; } static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) @@ -1328,6 +1329,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); @@ -1366,6 +1370,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++) { @@ -4340,7 +4347,6 @@ static inline void nested_release_vmcs12(struct kvm_vcpu *vcpu) /* copy to memory all shadowed fields in case they were modified */ copy_shadow_to_vmcs12(vmx); - vmx->nested.need_vmcs12_sync = false; vmx_disable_shadow_vmcs(vmx); } vmx->nested.posted_intr_nv = -1; From patchwork Thu Jul 25 11:49:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 11058715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AE30912 for ; Thu, 25 Jul 2019 11:49:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4901D28722 for ; Thu, 25 Jul 2019 11:49:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CF0A28970; Thu, 25 Jul 2019 11:49:54 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AC88128722 for ; Thu, 25 Jul 2019 11:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404342AbfGYLtp (ORCPT ); Thu, 25 Jul 2019 07:49:45 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36995 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404314AbfGYLto (ORCPT ); Thu, 25 Jul 2019 07:49:44 -0400 Received: by mail-wm1-f68.google.com with SMTP id f17so44442773wme.2 for ; Thu, 25 Jul 2019 04:49:43 -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=Z59Fx3FchhtcYpGTAy6/0+pqXBGTFpbIQm7SLJs066s=; b=hPB+y1n3DGhqwTejfhuunmAh0if7stGpUKgZVwqDHxfa3apC6KOINiewBj7cUxVrHt +mikQR3U55aMPaxp1ZeucSZsvp6RcG2e8V8dcwrYnba7iRw8lMPIWeTPXmaZySHHL2HF QmwYkdNuHz2jpYzO3U4SQSKJ1Q23D2CyxF9VKCUXVvSfDd0tl0ufatjw/EJ/io+HyKd0 bEfj5sw5E49jR8vejzv9u0jVhsOOTWnIMmVAz+65WnnuMpD8meZAST0MgzaTRWXs67Gj nMZoHr2d6WG3u4+MIjhQ1AwpwqLEfStWExG8q56pCiiOLOexT8CXR2F9UFr16ZbMZeMb cFAQ== X-Gm-Message-State: APjAAAWZt84c+1mEKJJw4fxJZ58XA9cRdULMyDRGpt7b+uWDiIUSHeEW dVygOqd9p65G+Q6cRVto7nX/cg== X-Google-Smtp-Source: APXvYqxRX1Odd/FqOub1CpfyIe42j8zssRTmGESC5RT9PX9QN36ChMZZssuNdKvI3JcnDGwivfGf1A== X-Received: by 2002:a7b:c0c6:: with SMTP id s6mr3698651wmh.115.1564055382411; Thu, 25 Jul 2019 04:49:42 -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 t140sm44784683wmt.0.2019.07.25.04.49.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 04:49:41 -0700 (PDT) From: Vitaly Kuznetsov To: stable@vger.kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Subject: [PATCH stable-5.1 2/3] KVM: nVMX: Clear pending KVM_REQ_GET_VMCS12_PAGES when leaving nested Date: Thu, 25 Jul 2019 13:49:37 +0200 Message-Id: <20190725114938.3976-3-vkuznets@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725114938.3976-1-vkuznets@redhat.com> References: <20190725114938.3976-1-vkuznets@redhat.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Kiszka [ Upstream commit cf64527bb33f6cec2ed50f89182fc4688d0056b6 ] Letting this pend may cause nested_get_vmcs12_pages to run against an invalid state, corrupting the effective vmcs of L1. This was triggerable in QEMU after a guest corruption in L2, followed by a L1 reset. Signed-off-by: Jan Kiszka Reviewed-by: Liran Alon Cc: stable@vger.kernel.org Fixes: 7f7f1ba33cf2 ("KVM: x86: do not load vmcs12 pages while still in SMM") Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx/nested.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 3f48006a43ec..f78975d4a7fa 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -212,6 +212,8 @@ static void free_nested(struct kvm_vcpu *vcpu) if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon) return; + kvm_clear_request(KVM_REQ_GET_VMCS12_PAGES, vcpu); + vmx->nested.vmxon = false; vmx->nested.smm.vmxon = false; free_vpid(vmx->nested.vpid02); From patchwork Thu Jul 25 11:49:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 11058713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1608E912 for ; Thu, 25 Jul 2019 11:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0101128722 for ; Thu, 25 Jul 2019 11:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E60AD28970; Thu, 25 Jul 2019 11:49:51 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 87A3328722 for ; Thu, 25 Jul 2019 11:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404355AbfGYLtr (ORCPT ); Thu, 25 Jul 2019 07:49:47 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33858 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404328AbfGYLtq (ORCPT ); Thu, 25 Jul 2019 07:49:46 -0400 Received: by mail-wr1-f67.google.com with SMTP id 31so50493096wrm.1 for ; Thu, 25 Jul 2019 04:49:44 -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=5eFHQcAJJ1arMcU18ItSiGCK+xpQYpQYRWNTnt4Sl8M=; b=puERPxaQgYv1+uDM1AN0+zE1UpMMNhSlyhu8BFDOwKdk4ds7DAWCowwKXY1gf4Z4jG FPosGS/4vvzlH8A/1Zr1coVgWZwmjZbtb5koN1KB+cn8HfN4yznYIFHP+1LKHQY0Y6Gg wQ/l5lOzAhjq438lkFSUCjr5NP6nlSjzBjopfd4zgu8sYeemBpZiMRrBcuYOhmnrALE6 +tXGtNiqnQ4I4fNIWGl0sY2Df4QEevahtKdga/7Xt83RRyb6X7txNd9hu/6Pg/bwriQt QakzE85fmILYg/snH7EmbUPzBFDMIORvBJj2uc2vyomodV54PNq7NFND/uALVuEZ9n7q 7M2Q== X-Gm-Message-State: APjAAAU9F02G4eRGILWgqiWcnh7yYIRoVl5c3hiRTekMjZDJgHlyK7sd tdbCjN9DUwkrDm0oXKNDSZnruUD1Zzs= X-Google-Smtp-Source: APXvYqwHF+F+rdSQWjhG31Xnxl9xMrRVHiLRHocchVFoV1vta3opzCIwlmlEKq6AN3HyyfnnQNNydw== X-Received: by 2002:a05:6000:1189:: with SMTP id g9mr57465609wrx.51.1564055383632; Thu, 25 Jul 2019 04:49:43 -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 t140sm44784683wmt.0.2019.07.25.04.49.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 04:49:42 -0700 (PDT) From: Vitaly Kuznetsov To: stable@vger.kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Subject: [PATCH stable-5.1 3/3] Revert "kvm: x86: Use task structs fpu field for user" Date: Thu, 25 Jul 2019 13:49:38 +0200 Message-Id: <20190725114938.3976-4-vkuznets@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725114938.3976-1-vkuznets@redhat.com> References: <20190725114938.3976-1-vkuznets@redhat.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini [ Upstream commit ec269475cba7bcdd1eb8fdf8e87f4c6c81a376fe ] This reverts commit 240c35a3783ab9b3a0afaba0dde7291295680a6b ("kvm: x86: Use task structs fpu field for user", 2018-11-06). The commit is broken and causes QEMU's FPU state to be destroyed when KVM_RUN is preempted. Fixes: 240c35a3783a ("kvm: x86: Use task structs fpu field for user") Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 7 ++++--- arch/x86/kvm/x86.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c79abe7ca093..564729a4a25c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -609,15 +609,16 @@ struct kvm_vcpu_arch { /* * QEMU userspace and the guest each have their own FPU state. - * In vcpu_run, we switch between the user, maintained in the - * task_struct struct, and guest FPU contexts. While running a VCPU, - * the VCPU thread will have the guest FPU context. + * In vcpu_run, we switch between the user and guest FPU contexts. + * While running a VCPU, the VCPU thread will have the guest FPU + * context. * * Note that while the PKRU state lives inside the fpu registers, * it is switched out separately at VMENTER and VMEXIT time. The * "guest_fpu" state here contains the guest FPU context, with the * host PRKU bits. */ + struct fpu user_fpu; struct fpu *guest_fpu; u64 xcr0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 37028ea85d4c..aede8fa2ea9a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8172,7 +8172,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu) static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) { preempt_disable(); - copy_fpregs_to_fpstate(¤t->thread.fpu); + copy_fpregs_to_fpstate(&vcpu->arch.user_fpu); /* PKRU is separately restored in kvm_x86_ops->run. */ __copy_kernel_to_fpregs(&vcpu->arch.guest_fpu->state, ~XFEATURE_MASK_PKRU); @@ -8185,7 +8185,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) { preempt_disable(); copy_fpregs_to_fpstate(vcpu->arch.guest_fpu); - copy_kernel_to_fpregs(¤t->thread.fpu.state); + copy_kernel_to_fpregs(&vcpu->arch.user_fpu.state); preempt_enable(); ++vcpu->stat.fpu_reload; trace_kvm_fpu(0);