Re: [PATCH v5 14/21] KVM: selftests: Verify non-postable IRQ remapping in IRQ test
From: Sean Christopherson
Date: Thu Jun 04 2026 - 13:30:51 EST
On Thu, Jun 04, 2026, Josh Hilke wrote:
> From: David Matlack <dmatlack@xxxxxxxxxx>
>
> Add the -n flag to tools/testing/selftests/kvm/irq_test.c to route a
> portion of device interrupts as NMIs (Non-Maskable Interrupts) into the
> guest using an alternating pattern of 4 NMIs followed by 4 regular
> interrupts.
>
> While this adds coverage for NMI injection, the primary goal is to
> validate KVM's handling of non-postable interrupt delivery.
> Specifically, the transitions between posted and remapped modes. NMIs
> are used for this purpose because they are a reliable, architectural way
> to force these code paths.
>
> Co-developed-by: Josh Hilke <jrhilke@xxxxxxxxxx>
> Signed-off-by: Josh Hilke <jrhilke@xxxxxxxxxx>
> Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
> ---
> tools/testing/selftests/kvm/irq_test.c | 44 ++++++++++++++++++++------
> 1 file changed, 35 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c
> index de8c29baa2b0..ed48562318bf 100644
> --- a/tools/testing/selftests/kvm/irq_test.c
> +++ b/tools/testing/selftests/kvm/irq_test.c
> @@ -17,12 +17,15 @@
> static u64 timeout_ns = 2ULL * 1000 * 1000 * 1000;
> static bool guest_ready_for_irqs[KVM_MAX_VCPUS];
> static bool guest_received_irq[KVM_MAX_VCPUS];
> +static bool guest_received_nmi[KVM_MAX_VCPUS];
> static bool irq_affinity;
> static bool block_vcpus;
> static bool done;
>
> #define GUEST_RECEIVED_IRQ(__vcpu) \
> SYNC_FROM_GUEST_AND_READ((__vcpu)->vm, guest_received_irq[(__vcpu)->id])
> +#define GUEST_RECEIVED_NMI(__vcpu) \
> + SYNC_FROM_GUEST_AND_READ((__vcpu)->vm, guest_received_nmi[(__vcpu)->id])
Add a wrapper macro to simplify/consolidate the core logic:
#define GUEST_RECEIVED_INTERRUPT(__vcpu, __nmi) \
((__nmi) ? GUEST_RECEIVED_NMI(__vcpu) : GUEST_RECEIVED_IRQ(__vcpu))