From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A2F33BF66B for ; Fri, 19 Jun 2026 20:32:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781901123; cv=none; b=MVJJXvgb6L80IFAQuUjIFn7ztXYmmxOu6roHldCGELRJbGyMq7H7wx5JpuJZlYMnwlLbtfVnn11q2UTjsxgMhb7gGxtaBKAui2ArR4bT5VlKSigsi/6S9KTm0ytzXJKILNcVkBk6LmQ1QcEIMfeobglQmtOQ3bCzhTnJeQXo2To= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781901123; c=relaxed/simple; bh=KEHvri2C+4rwq4Wz41q+2TtCvRVzvXyvnlqX/inZMjo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nNrJUzmI6opGDpMJJ5FTW1YjjO7Ouh/Q8RWvDggJy+NH2WT3tuWK3ZBPvKpGzTitiZOu4d0ici2jUboRK7rhDZIULYVUyz8YD1UWkBxwcQ/Oqme/bFoEN2NTyvkF7zSLMtjU4w1ek7IsCsc8fpF/va13KcU0sQfUJT1XVRt1FwA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dM+3r2rK; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dM+3r2rK" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-7e86d46b02dso30202847b3.3 for ; Fri, 19 Jun 2026 13:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781901119; x=1782505919; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vyiYsQofQELQbzMq1inRUoCbXJl9QmJD7EW7nh7MVlI=; b=dM+3r2rKuRCj0AnZ9/5CQhVuFolFYblR7SpHBPcUtb13HrEvFqStkAfm5RFq9bNSWo w2hoNu6kx5hcLSLqyKaFUb8WSKB7WuBH211yA9YoTqvlZ9m6Sak+Jb/dyJH3Kw24RL+v EgndwFVFsQpKkdXNbOrU27zx9ATF2QhRmV1aVzYDBlJvbfpZu/XobsP2YffdYivwJfc4 N63tHNbzhkjz4OT7z0tDEOkleCd35ZOV0/9mlKWL5Q9wfcOcUbuantLJrM0tRCjM4wPl QHPErmRW3XDOgdeAxm2hRAfELi/r4uVsx4ycPJLhTUUJivTQZS1jiqMdtuk3eXRSydbj 1vHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781901119; x=1782505919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vyiYsQofQELQbzMq1inRUoCbXJl9QmJD7EW7nh7MVlI=; b=nKX82CPSoBtt1tm2eML+vDHcY+5FHfvEihhhNX1CkOPNlAcjFq56uAMxPZp4LkO5JE Z8sMIyWwNFzWJMX8SJr2PI1oSos7rMrzEfA0I+ArThryqtydev9bRTcefYD69SyBbE/6 qnoG8ksLL0sEyg913UQkW4ZwNNatkwbdwHO1rcJI3y5MswUJkObjuXeJKN7//MeQnxHN uwFC150uhfrRmGXwUO/Pf6iPLxnZKd86AxZIihoBxGi4tYC5wh1NRAbON2wIq2qktWpe pJ1Hd4kaBHnRkjQrdJ3lviWDABr1NKjioMFQr28LWLifr0POJ9KrBCLfG1TVesg9Z+jR k5Dw== X-Forwarded-Encrypted: i=1; AFNElJ9PSoWPHCfcuuodGTsWl374MF59Qe9Zh20Y7YA8oGu7xDFwtPa2lzteHCN/vSHA9X+9Qw4D04D8XKa11wI=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ/9AkD70xfmiVlm59Du245t4VfsDgfkv+x+T6fjM/34U33YFT jXRuLzOvjrHeyEqF5NbKSV6S/R9jSSv2LYZFFC7K0KB9W5iSVe36mB5y X-Gm-Gg: AfdE7ckt8GHsjSvKkINW430UvbKHxYE3km+33Lpw5tFVtJEpjNM8Da/66K4tX6q+/MH tNDJV9Ypn+9yhhYONUurv8yGsnipFvkSQFyDA2Fp1F1LzjVEYpbKGZYlATYe29GoH5VECPA3VqA wDchnET/N7zav6RvoMresbaC5s6mBP9cHlSzjLQwBRMzSs4HMtpBkTQROc/+ZSldwgU//Lac2dm 7U72hIc1mAabF+7BGVC4WEnVV9kAAOCyMwNxHn7ZrMLjSOabGBWn7NSrDaPiD0Itpd5oTO4RaBy TyFNJnv5z3kgMvcMx3OwWOvHvbakCc3oyN3g9xR+Ic3yhh7B4Mu3Dt1rjyb/ii1uufmCoa2TnQR GoFplOTu96aFirjK13nKzIX/qETiVTiTLe2M8oK8OZayYvqwHMaRQNIiYvIBz8TsRl14wYYQ8fQ u1CVTvArWrCiqwl88= X-Received: by 2002:a05:690c:6c8e:b0:7fe:1333:c745 with SMTP id 00721157ae682-80134c78770mr57757507b3.27.1781901119103; Fri, 19 Jun 2026 13:31:59 -0700 (PDT) Received: from TurinLinux.. ([37.19.212.13]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8df7f015805sm11106986d6.1.2026.06.19.13.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 13:31:58 -0700 (PDT) From: Nicholas Dudar To: stable@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, gregkh@linuxfoundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, 0wn@theori.io, mlevitsk@redhat.com, jmattson@google.com, Nicholas Dudar Subject: [PATCH v2 6.1.y 3/3] KVM: nVMX: Fold requested virtual interrupt check into has_nested_events() Date: Fri, 19 Jun 2026 16:31:07 -0400 Message-Id: <20260619203107.2752678-4-main.kalliope@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260619203107.2752678-1-main.kalliope@gmail.com> References: <20260619203107.2752678-1-main.kalliope@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sean Christopherson commit 321ef62b0c5f6f57bb8500a2ca5986052675abbf upstream. Check for a Requested Virtual Interrupt, i.e. a virtual interrupt that is pending delivery, in vmx_has_nested_events() and drop the one-off kvm_x86_ops.guest_apic_has_interrupt() hook. In addition to dropping a superfluous hook, this fixes a bug where KVM would incorrectly treat virtual interrupts _for L2_ as always enabled due to kvm_arch_interrupt_allowed(), by way of vmx_interrupt_blocked(), treating IRQs as enabled if L2 is active and vmcs12 is configured to exit on IRQs, i.e. KVM would treat a virtual interrupt for L2 as a valid wake event based on L1's IRQ blocking status. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240607172609.3205077-6-seanjc@google.com Signed-off-by: Sean Christopherson [ Nicholas Dudar: backport to 6.1.y. 6.1.y predates the vmx main.c / x86_ops.h split, so drop .guest_apic_has_interrupt from vmx_x86_ops in vmx.c rather than vt_x86_ops in main.c. The function is static in vmx.c, so upstream's x86_ops.h prototype removal does not apply. 6.1.y keeps the current hwapic_isr_update signature. ] Signed-off-by: Nicholas Dudar --- arch/x86/include/asm/kvm-x86-ops.h | 1 - arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/vmx/nested.c | 4 ++++ arch/x86/kvm/vmx/vmx.c | 21 --------------------- arch/x86/kvm/x86.c | 10 +--------- 5 files changed, 5 insertions(+), 32 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index c068565fe..1cfe83263 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -81,7 +81,6 @@ KVM_X86_OP(check_apicv_inhibit_reasons) KVM_X86_OP(refresh_apicv_exec_ctrl) KVM_X86_OP_OPTIONAL(hwapic_irr_update) KVM_X86_OP_OPTIONAL(hwapic_isr_update) -KVM_X86_OP_OPTIONAL_RET0(guest_apic_has_interrupt) KVM_X86_OP_OPTIONAL(load_eoi_exitmap) KVM_X86_OP_OPTIONAL(set_virtual_apic_mode) KVM_X86_OP_OPTIONAL(set_apic_access_page_addr) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fe5c0f86a..31395c434 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1549,7 +1549,6 @@ struct kvm_x86_ops { void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu); void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr); void (*hwapic_isr_update)(struct kvm_vcpu *vcpu, int isr); - bool (*guest_apic_has_interrupt)(struct kvm_vcpu *vcpu); void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap); void (*set_virtual_apic_mode)(struct kvm_vcpu *vcpu); void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index ad07e83d2..f7a790a28 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3979,6 +3979,10 @@ static bool vmx_has_nested_events(struct kvm_vcpu *vcpu, bool for_injection) vppr = *((u32 *)(vapic + APIC_PROCPRI)); + max_irr = vmx_get_rvi(); + if ((max_irr & 0xf0) > (vppr & 0xf0)) + return true; + if (vmx->nested.pi_pending && vmx->nested.pi_desc && pi_test_on(vmx->nested.pi_desc)) { max_irr = pi_find_highest_vector(vmx->nested.pi_desc); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e5d162e97..2e6454e4c 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4063,26 +4063,6 @@ void pt_update_intercept_for_msr(struct kvm_vcpu *vcpu) } } -static bool vmx_guest_apic_has_interrupt(struct kvm_vcpu *vcpu) -{ - struct vcpu_vmx *vmx = to_vmx(vcpu); - void *vapic_page; - u32 vppr; - int rvi; - - if (WARN_ON_ONCE(!is_guest_mode(vcpu)) || - !nested_cpu_has_vid(get_vmcs12(vcpu)) || - WARN_ON_ONCE(!vmx->nested.virtual_apic_map.gfn)) - return false; - - rvi = vmx_get_rvi(); - - vapic_page = vmx->nested.virtual_apic_map.hva; - vppr = *((u32 *)(vapic_page + APIC_PROCPRI)); - - return ((rvi & 0xf0) > (vppr & 0xf0)); -} - static void vmx_msr_filter_changed(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -8266,7 +8246,6 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .check_apicv_inhibit_reasons = vmx_check_apicv_inhibit_reasons, .hwapic_irr_update = vmx_hwapic_irr_update, .hwapic_isr_update = vmx_hwapic_isr_update, - .guest_apic_has_interrupt = vmx_guest_apic_has_interrupt, .sync_pir_to_irr = vmx_sync_pir_to_irr, .deliver_interrupt = vmx_deliver_interrupt, .dy_apicv_has_pending_interrupt = pi_has_pending_interrupt, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 10ef8a435..208a713d7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13046,12 +13046,6 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm, kvm_page_track_flush_slot(kvm, slot); } -static inline bool kvm_guest_apic_has_interrupt(struct kvm_vcpu *vcpu) -{ - return (is_guest_mode(vcpu) && - static_call(kvm_x86_guest_apic_has_interrupt)(vcpu)); -} - static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) { if (!list_empty_careful(&vcpu->async_pf.done)) @@ -13077,9 +13071,7 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) static_call(kvm_x86_smi_allowed)(vcpu, false))) return true; - if (kvm_arch_interrupt_allowed(vcpu) && - (kvm_cpu_has_interrupt(vcpu) || - kvm_guest_apic_has_interrupt(vcpu))) + if (kvm_arch_interrupt_allowed(vcpu) && kvm_cpu_has_interrupt(vcpu)) return true; if (kvm_hv_has_stimer_pending(vcpu)) -- 2.34.1