Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp242999pxx; Wed, 28 Oct 2020 03:55:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycOSK41G+0ZHRmbGkfo1oikx0X+Z225RuaSMgvsg1F2NA3bDt8w1qheVRTxzQfA6Rnz68h X-Received: by 2002:a17:906:a40b:: with SMTP id l11mr3694244ejz.25.1603882525423; Wed, 28 Oct 2020 03:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882525; cv=none; d=google.com; s=arc-20160816; b=dnOEle3J1W7tmKvKAfuCUHEeV8nBDs2SyNXFpdusCN8S9iywX4kLjhk67Iu9QHWMbE CQUwfGrY18/HedZPfw32hy3/ELIFrh0LulDT/iepaw9h6jeipbJMJRUUkn9x1QiYddFy us5fUsrUm5s0TrOmHrybzS4SxwN+rE43+k5zlZ3WYqWIJ1cQL/b0hYAA8mBsGdvVQ1s9 uSois/Y87f3L5pBWH3XWFrVOWUUf2OfbEyzvk7XVsu6Y1PeBCf92pyHT5CZEc7eQ7eOV oMxqZBAJ2CPF9WIrEQnwurAa1YpXDOqUBuDzfB0V135tXy+7L7VUy+saKCycs9RYJBXV X4uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pVael4MDBM9a3pDK+Tw3L3AbdKoNIhNRkrlIk+cBsAA=; b=zxYKWWjnAKzyTZLLkpBvELlQWtZW+WFbIP+6i8IowekcyUSNKYUwaqifulnXLuISCa x4ThLYTe02fjxNyB7ZP4eG7hBaUZyFCFIxnHaL/JuEJImsaw4OJUmo1rHSDIicI5u1BK 6Ai/wPdgS5gMtXH2v+2/8YdRHLlKAjmGMwt8QuOs+3xaWx1P9ZJG63JmpoAIdegULGVw B9xUEVtMAzbahZID4ylV+Grw602POZvP44iCStBPYRsv7c/ej7KJiDEThlBqFj0yh8Pu eYquq8pyX3vMR8B4F+nVdm88AWTzweeAh4PMeEJd+HmT3HVY0XkVeqFiHcIw0x4RgBoz U5xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y2dQNUSy; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si2654785ede.591.2020.10.28.03.55.03; Wed, 28 Oct 2020 03:55:25 -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=@kernel.org header.s=default header.b=y2dQNUSy; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752716AbgJ0O4S (ORCPT + 99 others); Tue, 27 Oct 2020 10:56:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:50270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1772943AbgJ0Ouk (ORCPT ); Tue, 27 Oct 2020 10:50:40 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DF34621556; Tue, 27 Oct 2020 14:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810239; bh=m/T5nyzCStNhmcQrq3oiuc4IfQVKpD5kfOWhEGogN9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2dQNUSy/PiowbeMm5hsn5Lw2BAKypeh12YP/YW3YGfQuvHHqgzgXQmYHeIORLDkM pwqLztRVPjsPWbiQAtPtkXdNVKzUjOxBwdyw1GNJB/mblBhqg0dvdCGPza6FffUYdt yYre8clEVGopd3TGu/HDzjM35VZANs3/djEbTht8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liran Alon , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.8 069/633] KVM: nVMX: Morph notification vector IRQ on nested VM-Enter to pending PI Date: Tue, 27 Oct 2020 14:46:52 +0100 Message-Id: <20201027135525.938108275@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 25bb2cf97139f81e3bb8910d26016a529019528e upstream. On successful nested VM-Enter, check for pending interrupts and convert the highest priority interrupt to a pending posted interrupt if it matches L2's notification vector. If the vCPU receives a notification interrupt before nested VM-Enter (assuming L1 disables IRQs before doing VM-Enter), the pending interrupt (for L1) should be recognized and processed as a posted interrupt when interrupts become unblocked after VM-Enter to L2. This fixes a bug where L1/L2 will get stuck in an infinite loop if L1 is trying to inject an interrupt into L2 by setting the appropriate bit in L2's PIR and sending a self-IPI prior to VM-Enter (as opposed to KVM's method of manually moving the vector from PIR->vIRR/RVI). KVM will observe the IPI while the vCPU is in L1 context and so won't immediately morph it to a posted interrupt for L2. The pending interrupt will be seen by vmx_check_nested_events(), cause KVM to force an immediate exit after nested VM-Enter, and eventually be reflected to L1 as a VM-Exit. After handling the VM-Exit, L1 will see that L2 has a pending interrupt in PIR, send another IPI, and repeat until L2 is killed. Note, posted interrupts require virtual interrupt deliveriy, and virtual interrupt delivery requires exit-on-interrupt, ergo interrupts will be unconditionally unmasked on VM-Enter if posted interrupts are enabled. Fixes: 705699a13994 ("KVM: nVMX: Enable nested posted interrupt processing") Cc: stable@vger.kernel.org Cc: Liran Alon Signed-off-by: Sean Christopherson Message-Id: <20200812175129.12172-1-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 7 +++++++ arch/x86/kvm/lapic.h | 1 + arch/x86/kvm/vmx/nested.c | 8 ++++++++ 3 files changed, 16 insertions(+) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -490,6 +490,12 @@ static inline void apic_clear_irr(int ve } } +void kvm_apic_clear_irr(struct kvm_vcpu *vcpu, int vec) +{ + apic_clear_irr(vec, vcpu->arch.apic); +} +EXPORT_SYMBOL_GPL(kvm_apic_clear_irr); + static inline void apic_set_isr(int vec, struct kvm_lapic *apic) { struct kvm_vcpu *vcpu; @@ -2462,6 +2468,7 @@ int kvm_apic_has_interrupt(struct kvm_vc __apic_update_ppr(apic, &ppr); return apic_has_interrupt_for_ppr(apic, ppr); } +EXPORT_SYMBOL_GPL(kvm_apic_has_interrupt); int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu) { --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -89,6 +89,7 @@ int kvm_lapic_reg_read(struct kvm_lapic bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, int shorthand, unsigned int dest, int dest_mode); int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); +void kvm_apic_clear_irr(struct kvm_vcpu *vcpu, int vec); bool __kvm_apic_update_irr(u32 *pir, void *regs, int *max_irr); bool kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir, int *max_irr); void kvm_apic_update_ppr(struct kvm_vcpu *vcpu); --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3480,6 +3480,14 @@ static int nested_vmx_run(struct kvm_vcp if (unlikely(status != NVMX_VMENTRY_SUCCESS)) goto vmentry_failed; + /* Emulate processing of posted interrupts on VM-Enter. */ + if (nested_cpu_has_posted_intr(vmcs12) && + kvm_apic_has_interrupt(vcpu) == vmx->nested.posted_intr_nv) { + vmx->nested.pi_pending = true; + kvm_make_request(KVM_REQ_EVENT, vcpu); + kvm_apic_clear_irr(vcpu, vmx->nested.posted_intr_nv); + } + /* Hide L1D cache contents from the nested guest. */ vmx->vcpu.arch.l1tf_flush_l1d = true;