Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp599863ybz; Sat, 25 Apr 2020 00:04:35 -0700 (PDT) X-Google-Smtp-Source: APiQypLAT2sn3BgJ+2zZJIwLnHiTPJpRG0+5ENoo6U18GKOBPole1mjN5uqSUNxI/oTNMKyBodBQ X-Received: by 2002:a05:6402:3121:: with SMTP id dd1mr10726307edb.168.1587798275195; Sat, 25 Apr 2020 00:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587798275; cv=none; d=google.com; s=arc-20160816; b=ULyK8HMhohtKoYmCDROoZxM5bGFgtHGuCNxSQfRaq0aBBEhF5QEux3jYQhvg1eudLd PoPaWa6V0EG7dYgCAvaLmastACaPhgFnj00y8bzUH8hPRf2vx/kIZW2HlNC2fhWRp64k NoXFUqkohtR8r7cjkOji4iV1O9AooV5ZQ0ylJlwnWUwCH1WbdPsjvuNNbuJ2zaO0kZxx MJN3/XSvUlYzNS0+AxRqmGMDLqvTlWqblcHzn3PBPK8b3SM39r79PWIn28srtRVy5Ug6 zNIrPGcpNTYYZW+WJaUU2+G4N39vubOrTC1AheMLQDqq+SVSw5o4KBQs53UiB9rlvvXO 9Upg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=F5d2hZyoWLkLFhOgbvoh0l9Xmnu5vZ/wvjbqCedo71Y=; b=VLMKuxBVVRMHhInQhQ6Ln4Cntl9Xobhf9ylRFv1H7l2csPo/64t1/eIGXy0xn00aWE FoeYKb1HKKI52hh/f7Eg7rGVz3MjjEKMHu5jSIm2jkikjMfTDo+uNgQ+TjN5EAcp4RhW q5Qx4ThKeTkAk36nvbYeEjqDD0lGxeMCNd5R0hUo8IW3yCqbuHnyZ7pzEzh8Hjp+Hou6 otoVQmW2k8wB+hz0JwdvYiePrgzOKJmGHBLZXfS6Tl6ugDqHLnD3nL69wMBb36/sa2yS 2QB0wh7pAnCOEnGjVspSePu5IR1XzTIO8HBLPYJjNVqKWA0++Bv2fYMMFvauXWhk9RNb YtCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K2Me8a22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si4777832edf.277.2020.04.25.00.04.12; Sat, 25 Apr 2020 00:04:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K2Me8a22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbgDYHCY (ORCPT + 99 others); Sat, 25 Apr 2020 03:02:24 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:56442 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726348AbgDYHCV (ORCPT ); Sat, 25 Apr 2020 03:02:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587798140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=F5d2hZyoWLkLFhOgbvoh0l9Xmnu5vZ/wvjbqCedo71Y=; b=K2Me8a22s14h/7eo3M7XthuKq5ROVLbpMaBTNiqWD4EwOubzNGmpVnYOOWhaC6tIpfJqUW Tc58XynmNDBggrL0Xk7cBOmLZ5aew9hNB2DL2oqR6jS/p4wVsL8jjUc6JyPK8ViZSTos0p nRG81JpIVY9mvVEyxZLXIYAkO9b5PJk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-hhz45wqyOoOewXgRnfFx9g-1; Sat, 25 Apr 2020 03:02:17 -0400 X-MC-Unique: hhz45wqyOoOewXgRnfFx9g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1E3C462; Sat, 25 Apr 2020 07:02:16 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3918600E8; Sat, 25 Apr 2020 07:02:15 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: wei.huang2@amd.com, cavery@redhat.com, vkuznets@redhat.com, Sean Christopherson , Oliver Upton , Jim Mattson Subject: [PATCH v2 20/22] KVM: VMX: Use vmx_interrupt_blocked() directly from vmx_handle_exit() Date: Sat, 25 Apr 2020 03:02:13 -0400 Message-Id: <20200425070215.251397-1-pbonzini@redhat.com> In-Reply-To: <20200424172416.243870-1-pbonzini@redhat.com> References: <20200424172416.243870-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Use vmx_interrupt_blocked() instead of bouncing through vmx_interrupt_allowed() when handling edge cases in vmx_handle_exit(). The nested_run_pending check in vmx_interrupt_allowed() should never evaluate true in the VM-Exit path. Hoist the WARN in handle_invalid_guest_state() up to vmx_handle_exit() to enforce the above assumption for the !enable_vnmi case, and to detect any other potential bugs with nested VM-Enter. Signed-off-by: Sean Christopherson Message-Id: <20200423022550.15113-12-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx/vmx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 7fb7dcb3d94d..0e5eacd6f911 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5268,18 +5268,11 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) bool intr_window_requested; unsigned count = 130; - /* - * We should never reach the point where we are emulating L2 - * due to invalid guest state as that means we incorrectly - * allowed a nested VMEntry with an invalid vmcs12. - */ - WARN_ON_ONCE(vmx->emulation_required && vmx->nested.nested_run_pending); - intr_window_requested = exec_controls_get(vmx) & CPU_BASED_INTR_WINDOW_EXITING; while (vmx->emulation_required && count-- != 0) { - if (intr_window_requested && vmx_interrupt_allowed(vcpu)) + if (intr_window_requested && !vmx_interrupt_blocked(vcpu)) return handle_interrupt_window(&vmx->vcpu); if (kvm_test_request(KVM_REQ_EVENT, vcpu)) @@ -5896,6 +5889,14 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, if (enable_pml) vmx_flush_pml_buffer(vcpu); + /* + * We should never reach this point with a pending nested VM-Enter, and + * more specifically emulation of L2 due to invalid guest state (see + * below) should never happen as that means we incorrectly allowed a + * nested VM-Enter with an invalid vmcs12. + */ + WARN_ON_ONCE(vmx->nested.nested_run_pending); + /* If guest state is invalid, start emulating */ if (vmx->emulation_required) return handle_invalid_guest_state(vcpu); @@ -5962,7 +5963,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, if (unlikely(!enable_vnmi && vmx->loaded_vmcs->soft_vnmi_blocked)) { - if (vmx_interrupt_allowed(vcpu)) { + if (!vmx_interrupt_blocked(vcpu)) { vmx->loaded_vmcs->soft_vnmi_blocked = 0; } else if (vmx->loaded_vmcs->vnmi_blocked_time > 1000000000LL && vcpu->arch.nmi_pending) { -- 2.18.2