Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1357725ybz; Wed, 22 Apr 2020 19:29:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJk/Vzl98efo2nm87V32W6ULeqB2biny7cTtFKlJOYi1UVPUoTOzk6QQ16Tb2i8LNF19sVA X-Received: by 2002:a17:906:b2c4:: with SMTP id cf4mr971867ejb.340.1587608946101; Wed, 22 Apr 2020 19:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587608946; cv=none; d=google.com; s=arc-20160816; b=aWWRRsHvnke15hkh/ZwRAoQMz/c+WbfTszVMDIreMKDvF93ujyS/fksUqu39IKJ8f0 0DeOdnJCmaRrU3sYWtyGYG65+bqt3aDi5IusH2glqglg0CzgcXAWJzYpb+WlhMvO3/S+ yyN44GqXT/QkvHe0glhwWlLsd2ZT2wnjjVfJQh8pdgGOp1lqHuRHd7fQyysBX9c6nWCg KFWMkvoowNjJe5E2kArd/WhaSal2Kxxvqet/M+LGg7inahNuEykzYfnIhKwgfFLYmRtL 1pJDNKUGGgvZgCncGJR0jseGt6MZWHwXA4cFoRPjVQ1Nes88Cg+sJfcrJm8Fk7QG3YmQ PyNw== 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=2SJELvGHbyogOL0fOCbo5/F9K9OQW3UP1hQO36wT5qE=; b=k1hz8EMWcQDRx+TIdaJcSc7TklHghQStupzvzObwH1V+BuTb7ny0mbf/G0JrJeqecy o1/PfCxD8TGdJ+c5DaNZyhiy2oYCJqb7BnQTZ5tvWFmBACZBGPGZ6AvDpQCSbUBOYL7m 5zE4387jYkc2JNLB2KxxtyKppRy5FXWbnpaYfHEBv7C1XJzFiv+ZwFLZhRQgxN3MFUa1 sH3M0ehjqs+0GWs2VXYhgPiRHzd+M1bEbyz1YWY6SycYHatT3yMGDE8nQH4h1ZtJq3Dr +mCuUGT+WMn8rrMpC+7Ji3sZV8TgDLMa2UOulr3VDlnHk7qRpiuOcToSribrQrLDtf8p MONg== 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 g5si533299ejs.290.2020.04.22.19.28.43; Wed, 22 Apr 2020 19:29:06 -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 S1726552AbgDWCZ5 (ORCPT + 99 others); Wed, 22 Apr 2020 22:25:57 -0400 Received: from mga05.intel.com ([192.55.52.43]:43420 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgDWCZz (ORCPT ); Wed, 22 Apr 2020 22:25:55 -0400 IronPort-SDR: PBtXlPbCYjHb5PWE2+UKniXZQP0fwMd80Rn55KecCtOjSdBBCa8ZXnNNgYGdavfMRW0ZhWKMLX bka5aVbcKS9Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 19:25:54 -0700 IronPort-SDR: d4SYGUjyFo0ArnHT9KsSbY4ttXZC48ZmHxFFgQYMg8axD1qCJoGlYChMUaQ/JOlTOtM4X7m7rr kg2WlQY4qTCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,305,1583222400"; d="scan'208";a="259273932" 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 01/13] KVM: nVMX: Preserve exception priority irrespective of exiting behavior Date: Wed, 22 Apr 2020 19:25:38 -0700 Message-Id: <20200423022550.15113-2-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 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 --- 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 f228339cd0a0..dc7315b31fee 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.26.0