All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Nicholas Dudar <main.kalliope@gmail.com>
Cc: stable@vger.kernel.org, pbonzini@redhat.com,
	gregkh@linuxfoundation.org,  kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, 0wn@theori.io,
	 mlevitsk@redhat.com, jmattson@google.com
Subject: Re: [PATCH v2 6.1.y 1/3] KVM: nVMX: Add a helper to get highest pending from Posted Interrupt vector
Date: Mon, 22 Jun 2026 19:01:56 -0700	[thread overview]
Message-ID: <ajnpFEwXcqw07XCm@google.com> (raw)
In-Reply-To: <20260619203107.2752678-2-main.kalliope@gmail.com>

On Fri, Jun 19, 2026, Nicholas Dudar wrote:
> From: Sean Christopherson <seanjc@google.com>
> 
> commit d83c36d822be44db4bad0c43bea99c8908f54117 upstream.
> 
> Add a helper to retrieve the highest pending vector given a Posted
> Interrupt descriptor.  While the actual operation is straightforward, it's
> surprisingly easy to mess up, e.g. if one tries to reuse lapic.c's
> find_highest_vector(), which doesn't work with PID.PIR due to the APIC's
> IRR and ISR component registers being physically discontiguous (they're
> 4-byte registers aligned at 16-byte intervals).
> 
> To make PIR handling more consistent with respect to IRR and ISR handling,
> return -1 to indicate "no interrupt pending".
> 
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/r/20240607172609.3205077-2-seanjc@google.com
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [ Nicholas Dudar: backport to 6.1.y. 6.1.y defines struct pi_desc in
>   posted_intr.h and predates the move to <asm/posted_intr.h>, so the helper
>   and the <linux/find.h> include go in posted_intr.h. ]

This is misleading.  The helper is in arch/x86/kvm/vmx/posted_intr.h, even in
upstream.  I don't know if I *intentionally* put the helper in KVM code, but for
for whatever reason, I did.

Commit 699f67512f04 caused a conflict that needed to be resolved in the 6.1
backport, but that didn't have anything to do with needing to re-home the helper.

That only matters because I was going to ask if we'd be better off backporting
asm/posted_intr.h so that the helper would live in it's "proper" location, but
the answer on that front is "no", because it's already there.

FWIW, I got the same conflict resolution, it's just the blurb that's confusing.

> Signed-off-by: Nicholas Dudar <main.kalliope@gmail.com>
> ---
>  arch/x86/kvm/vmx/nested.c      |  5 +++--
>  arch/x86/kvm/vmx/posted_intr.h | 10 ++++++++++
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index bdc462944..7d8e18dbe 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -12,6 +12,7 @@
>  #include "mmu.h"
>  #include "nested.h"
>  #include "pmu.h"
> +#include "posted_intr.h"
>  #include "sgx.h"
>  #include "trace.h"
>  #include "vmx.h"
> @@ -3818,8 +3819,8 @@ static int vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu)
>  	if (!pi_test_and_clear_on(vmx->nested.pi_desc))
>  		return 0;
>  
> -	max_irr = find_last_bit((unsigned long *)vmx->nested.pi_desc->pir, 256);
> -	if (max_irr != 256) {
> +	max_irr = pi_find_highest_vector(vmx->nested.pi_desc);
> +	if (max_irr > 0) {
>  		vapic_page = vmx->nested.virtual_apic_map.hva;
>  		if (!vapic_page)
>  			goto mmio_needed;
> diff --git a/arch/x86/kvm/vmx/posted_intr.h b/arch/x86/kvm/vmx/posted_intr.h
> index 269920765..88cea0dac 100644
> --- a/arch/x86/kvm/vmx/posted_intr.h
> +++ b/arch/x86/kvm/vmx/posted_intr.h
> @@ -2,6 +2,8 @@
>  #ifndef __KVM_X86_VMX_POSTED_INTR_H
>  #define __KVM_X86_VMX_POSTED_INTR_H
>  
> +#include <linux/find.h>
> +
>  #define POSTED_INTR_ON  0
>  #define POSTED_INTR_SN  1
>  
> @@ -103,4 +105,12 @@ int vmx_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
>  		       uint32_t guest_irq, bool set);
>  void vmx_pi_start_assignment(struct kvm *kvm);
>  
> +static inline int pi_find_highest_vector(struct pi_desc *pi_desc)
> +{
> +	int vec;
> +
> +	vec = find_last_bit((unsigned long *)pi_desc->pir, 256);
> +	return vec < 256 ? vec : -1;
> +}
> +
>  #endif /* __KVM_X86_VMX_POSTED_INTR_H */
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2026-06-23  2:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19 20:31 [PATCH v2 6.1.y 0/3] KVM: nVMX: backport virtual-APIC host NULL-deref fix Nicholas Dudar
2026-06-19 20:31 ` [PATCH v2 6.1.y 1/3] KVM: nVMX: Add a helper to get highest pending from Posted Interrupt vector Nicholas Dudar
2026-06-19 20:46   ` sashiko-bot
2026-06-23  1:47     ` Sean Christopherson
2026-06-23  2:01   ` Sean Christopherson [this message]
2026-06-23  3:03     ` Admin
2026-06-19 20:31 ` [PATCH v2 6.1.y 2/3] KVM: nVMX: Check for pending posted interrupts when looking for nested events Nicholas Dudar
2026-06-19 20:31 ` [PATCH v2 6.1.y 3/3] KVM: nVMX: Fold requested virtual interrupt check into has_nested_events() Nicholas Dudar
2026-06-21 13:47 ` [PATCH v2 6.1.y 0/3] KVM: nVMX: backport virtual-APIC host NULL-deref fix Sasha Levin
2026-06-23  2:07   ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ajnpFEwXcqw07XCm@google.com \
    --to=seanjc@google.com \
    --cc=0wn@theori.io \
    --cc=gregkh@linuxfoundation.org \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=main.kalliope@gmail.com \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.