Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp862647ybz; Fri, 24 Apr 2020 10:29:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLeK5IiEl4lS1QV2WiiyltbMuOOMD4FXhc+9JIhWtV6VrA3R1TODAsldDrdAdnqhlBGe7+W X-Received: by 2002:a17:906:4dc8:: with SMTP id f8mr8180043ejw.23.1587749344369; Fri, 24 Apr 2020 10:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587749344; cv=none; d=google.com; s=arc-20160816; b=jA8InF8VFg1VV60iUsI9pyhUZmRBC741fRLyf7SYdiOtzMiX14xt9IlT6qKfkiNYlE h1A9oPx/PcMXMHu5SOJ1tRRNM6Z/wie7v88QZ5+JXiPu+Vs38ugtpG82ryG38+kJ+v5Q 8eU0MEYJJ8w5S1BPLxVA5/voHWdILhE3s8PsEneaxqEH4Fg7X1y/pUcLJEN/DCKJ3G6I TvuxgJ3Iz7H1ZWSGm/dGU1Ygo65p4Vdv3Y3zMbCBENgBxxUNTly+3zmdNBbxlD5DY81v pVBjrbDWKx7wg8g+cUO8rwpFwuLFzhBw8V4iiBd+wu3ADEqB1i7nyiXLyZdayen5jIPm 3nYQ== 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=UmAA9/+IHhfnv934e38JcU8oC7FPZN3AvIwnCiympQ4=; b=Ykf++t24sRcxuMDe49sQGpzOuFt51qQh/Xiy43A2TYmEGqoLSEispPR0YNg9uFBYrS bxDHwy1u62vjbSrNTRceYE+7IVK+yLsyZ9nTSAJEQIYPENnmXVRqPvdcdUmC/EdUjwS6 O9wTz0CBsVS+l5ABxl24MGqBHa7hKmzS2Tng1RtuM7+d/OazAWbbLM18oxH8GaxYowvC jLXVizDOlJxgAhYuNU/B4QQSd2A9qP832ogvczAFReT3XX1zPzAjPvwj4gyMAWHqgmRh nyvw0aEiyawL58xG3JG9LGr/5Z9I33YcTfS8QznVKbRFsItceUf4BtlmHlAooIceHJoW yGuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cue+9hPc; 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 g26si3531782ejr.99.2020.04.24.10.28.41; Fri, 24 Apr 2020 10:29:04 -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=Cue+9hPc; 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 S1729020AbgDXRY6 (ORCPT + 99 others); Fri, 24 Apr 2020 13:24:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:35726 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728850AbgDXRYk (ORCPT ); Fri, 24 Apr 2020 13:24:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587749078; 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=UmAA9/+IHhfnv934e38JcU8oC7FPZN3AvIwnCiympQ4=; b=Cue+9hPcQhEf9VbbR4SkWY0C+lyGe3mXiO8EQx2PoQhSKsxPBaTkrz/LIStZtd0Wh4GxTR MDGpZBMiVVT32f1bzWu/HO4Gk167WuuCUNPeiyPrhkyLVceXy4RgpmGt9XUNg67ZnxgX1P Vdfi+jpI9PJDmUYvYFi3Rd683keNXyA= 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-271-4DmxmMS2NQWsZlywIa1Pcg-1; Fri, 24 Apr 2020 13:24:34 -0400 X-MC-Unique: 4DmxmMS2NQWsZlywIa1Pcg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0383F18B641F; Fri, 24 Apr 2020 17:24:24 +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 0383625277; Fri, 24 Apr 2020 17:24:22 +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 , Peter Shier Subject: [PATCH v2 05/22] KVM: nVMX: Preserve exception priority irrespective of exiting behavior Date: Fri, 24 Apr 2020 13:23:59 -0400 Message-Id: <20200424172416.243870-6-pbonzini@redhat.com> In-Reply-To: <20200424172416.243870-1-pbonzini@redhat.com> References: <20200424172416.243870-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Short circuit vmx_check_nested_events() if an exception is pending and needs to be injected into L2, priority between coincident events is not dependent on exiting behavior. This fixes a bug where a single-step #DB that is not intercepted by L1 is incorrectly dropped due to servicing a VMX Preemption Timer VM-Exit. Injected exceptions also need to be blocked if nested VM-Enter is pending or an exception was already injected, otherwise injecting the exception could overwrite an existing event injection from L1. Technically, this scenario should be impossible, i.e. KVM shouldn't inject its own exception during nested VM-Enter. This will be addressed in a future patch. Note, event priority between SMI, NMI and INTR is incorrect for L2, e.g. SMI should take priority over VM-Exit on NMI/INTR, and NMI that is injected into L2 should take priority over VM-Exit INTR. This will also be addressed in a future patch. Fixes: b6b8a1451fc4 ("KVM: nVMX: Rework interception of IRQs and NMIs") Reported-by: Jim Mattson Cc: Oliver Upton Cc: Peter Shier Signed-off-by: Sean Christopherson Message-Id: <20200423022550.15113-2-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx/nested.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index b516c24494e3..490dba7d0504 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3716,11 +3716,11 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) /* * Process any exceptions that are not debug traps before MTF. */ - if (vcpu->arch.exception.pending && - !vmx_pending_dbg_trap(vcpu) && - nested_vmx_check_exception(vcpu, &exit_qual)) { + if (vcpu->arch.exception.pending && !vmx_pending_dbg_trap(vcpu)) { if (block_nested_events) return -EBUSY; + if (!nested_vmx_check_exception(vcpu, &exit_qual)) + goto no_vmexit; nested_vmx_inject_exception_vmexit(vcpu, exit_qual); return 0; } @@ -3733,10 +3733,11 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) return 0; } - if (vcpu->arch.exception.pending && - nested_vmx_check_exception(vcpu, &exit_qual)) { + if (vcpu->arch.exception.pending) { if (block_nested_events) return -EBUSY; + if (!nested_vmx_check_exception(vcpu, &exit_qual)) + goto no_vmexit; nested_vmx_inject_exception_vmexit(vcpu, exit_qual); return 0; } @@ -3771,6 +3772,7 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) return 0; } +no_vmexit: vmx_complete_nested_posted_interrupt(vcpu); return 0; } -- 2.18.2