Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1356834ybz; Wed, 22 Apr 2020 19:27:32 -0700 (PDT) X-Google-Smtp-Source: APiQypJf29+lRBrPNJLURUrdSkxpuY+tztqt5AAMQkTZqPb5sz3AzapovTzbLsGQgqtIsvFQIW/6 X-Received: by 2002:a17:907:40f2:: with SMTP id no2mr946733ejb.41.1587608852171; Wed, 22 Apr 2020 19:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587608852; cv=none; d=google.com; s=arc-20160816; b=kzZGuKY04kQc0A/Naht3YQLqq7khpIDRySgjU6lGAGE6P8flZF0z/Nbkm/6AmumIgM 890I8o2Qe3K/FiGIRMqphrpe2P/YRr9ICBwMUnd8hVREfMpMGqvApWY43/XtbKT6uWo6 2JqZupmw/Gdv7whzapUPuS9DHgy1rrqiCiYFGbuzbXHyZbSb4f8DhPRGR/TNj0xkDcRi 0RxPfA2rm/XWhsbcGZZvz2HlNDPR1PH3ClJunRqkvdhzs1aZOjLhO+o061V8qwEIcXF+ 9lslUmO14QpqU9t0D4ilteu8xrelfG0fyc/TOhgQNzu2GpZfYwVVJifbVbejhC7JnymF 4fTA== 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 :ironport-sdr:ironport-sdr; bh=mV+J9TaMhM571na0Nn1XEhPflH7k58/HzZ4+YPkkLUg=; b=dyDyZTJgNSGBqV4fEuVeT3sSFDc+z3p3dq3KFxobKnTgWWadTQ9hng7fEFKje2Pfuv pTxRyC3l88ZPLKHBHyfnirDNBkeceSRy4UfC6a4w/Wcvfj+RHTp/aIKMNRLPcFTfSGVc CMGr7Lf+UT5GGDB6BoRF224x0A7Y07P9exWViHdycYknhk2riZRqVtyR75jC/4pOyTHX oZ8OmS3wmJYGIrEOOh8KfagYqO3xahl2lRSn/siygi7PsRdsWuGNJkCMLsw4J1P00yjt J1nIpYoL0TBXw4MTsmmQaYGEdztNwReMvuPMJL1gmagL5kGvISkT/+Xwbi1pf9/xDYVs ON2Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn23si530305ejb.331.2020.04.22.19.27.09; Wed, 22 Apr 2020 19:27:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbgDWC0C (ORCPT + 99 others); Wed, 22 Apr 2020 22:26:02 -0400 Received: from mga06.intel.com ([134.134.136.31]:33065 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726581AbgDWCZ7 (ORCPT ); Wed, 22 Apr 2020 22:25:59 -0400 IronPort-SDR: REO5yVs0shxwcwZlDnWQB6Bc3qxgbwrXiDpp5iIFTtearGmtFxPBo3fH5I40+cpdQHb7hVyocw vhT8E0xUwH3Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 19:25:55 -0700 IronPort-SDR: 2Z/0fy1Rj0mpp5HFgJpPAkSaA7HUQoMV89zmGJqKByl/vjrCA/CzdXYCq+JEjbLy8gSDNGasTb 0NBw3t7FIu0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,305,1583222400"; d="scan'208";a="259273964" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by orsmga006.jf.intel.com with ESMTP; 22 Apr 2020 19:25:54 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Upton , Peter Shier Subject: [PATCH 11/13] KVM: VMX: Use vmx_interrupt_blocked() directly from vmx_handle_exit() Date: Wed, 22 Apr 2020 19:25:48 -0700 Message-Id: <20200423022550.15113-12-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200423022550.15113-1-sean.j.christopherson@intel.com> References: <20200423022550.15113-1-sean.j.christopherson@intel.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 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 --- 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 50c726a21feb..2f8cacb3aa9b 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.26.0