From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 A00C14503B for ; Sat, 30 May 2026 00:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780100578; cv=none; b=BlwXXS/m9RBjv46y/UMnILY5OXd+AE7BuYeDyvkds+qfqmm6zZpvxG+Fqo25ctJPqxQ/dNN+o+VFYdfWc84ncNi0SZgAxKZnZBflqtTyHvoFqzHijxbFgQSf3m8IAw33BaR2+VuTQtwQykWLdM0USvViC0JsSicHpr6MUSn/wog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780100578; c=relaxed/simple; bh=XDY/e6y/pqWNJvfEwKI1E9W2gkWol5Z1CfB+B7PBiXk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=oX9LRa+q+BgIKjOOeNH8qpEkAesv7I2gYrxZoF4vEAqpOy8H/D6MmXSEk8WNEL6xSfpg1E1IIqjJceMr/FuCvy2CKvcxi5FNUvlnNI2JjF8wYjPZ1wxFGAzGCCrStzIqctzfpJPUQQtxOKUU2lgYJQwwOCk2CNhX4BPjwrhGcdw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nEqeYwFu; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nEqeYwFu" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c85759a8f33so751406a12.0 for ; Fri, 29 May 2026 17:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780100577; x=1780705377; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AgTu89yTYwkieiKYURPcExxeCVTfHh00EXFY4PAaEro=; b=nEqeYwFus/OfbRDcJ9o2meu43a52ZZ8PPovOKGF4Chl4VolQLaexq1ayZvkl7w8vub Cj4nWFVDyTdH/9h1eAoMj4IICub+ZBbLwBlL7pPKX1Kir2x41ZG9OmLim5aI/PFWHU1+ NoHJjEdzO3zmdfCDi0IcEGI0MwmJplOkiO1n+LoXS0aHt8JbUmzdYxho7D9N4ElcB4fK noQ1VryDkU3+DcNB2Ndh58axvM+mmMlRTF+NrMZChI3718W0WB7CYpiYRCkEdXxUNDfi 5YsYukHxrnsTt1AZMn+Cqc1OSAgF2dLlAybXRRXlkucXAJnLh2a+htDsvTX6xw87CM4t 5R4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780100577; x=1780705377; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AgTu89yTYwkieiKYURPcExxeCVTfHh00EXFY4PAaEro=; b=PmUpmp5AkXpYPuTcQ48euOuul2KIWx26uq8JHxEq4n/aH1v0BSLGu7VVjmrQel6sSH 6LZVhPWjgfajHakZKiU0x6ic+br/DrLtc4rt6DkDKj3QUs3StDkFIQ/vhmWCC3jiti9g 3xs0ChC0Hn0QfnbApqoGjZuyXoF3hnBDe1PEKDh1otHkfyxQZBw7Zub0UPj8i55Nlzua gqPVByO7crGq7I160mBD0gXB2X6a0hQkkFtO51Y6SJAVW6LbCC8G87kYEPWI9ZXWnxfd IlkQmoVFoMHVx92OB2X+ZmMvCCCc2Zc1IPXwbin5Mg82HwWy7+lzESavy9Tv+IV9Wm4J 2tAA== X-Forwarded-Encrypted: i=1; AFNElJ9ZJ/W6MtdrAkWhKcZNCc6i8h4nLTJdLPQ3wGAik3ziBPLCFEgoe9K+cjzL/QviLoFvxNw2+zSn+j2YbfQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxOYh73KYBT1UhoKe9fUSEAdu/XmvXbM8TZJs1R7BaT9H58Bulc o7bMhEQC0yDgHng9YQn9HQvu1+v4qnyRzn+D2Dzes4ZcVtPTy1s9Xg3Qwa8br46iCqUqN5XOSAz SML7pGimq X-Received: from pjtl13.prod.google.com ([2002:a17:90a:c58d:b0:36a:b898:125a]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:33c5:b0:36b:97b4:df7 with SMTP id 98e67ed59e1d1-36beb578668mr1262912a91.9.1780100576662; Fri, 29 May 2026 17:22:56 -0700 (PDT) Date: Sat, 30 May 2026 00:21:15 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260530002134.558837-1-jrhilke@google.com> Subject: [PATCH v4 00/19] KVM: selftests: Link with VFIO selftests lib From: Josh Hilke To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Alex Williamson , Josh Hilke Content-Type: text/plain; charset="UTF-8" This is v4 of a series which introduces tools/testing/selftests/kvm/irq_test.c in KVM selftests. This test exercises the delivery of interrupts (both emulated via eventfd and real from a VFIO device) to guest vCPUs. Beyond basic injection, the series adds coverage for several complex scenarios, including: - Dynamic updates to KVM's GSI routing table while interrupts are active. - Waking up halted vCPUs via interrupts. - Stressing interrupt delivery during random host IRQ affinity changes. - Stressing interrupt delivery during random vCPU thread migration across physical CPUs. - Testing non-postable interrupt remapping (using NMIs to force transitions). - Supporting both xAPIC and x2APIC modes in the guest. The series also links the VFIO selftests library into KVM selftests to enable testing of VFIO-KVM interactions. The test can optionally use a PCI device bound to vfio-pci to test physical device interrupts. If using a device, it can be invoked by passing the BDF to the VFIO selftests setup script, and then running the test with the device BDF passed via the -d option: $ ./tools/testing/selftests/vfio/scripts/setup.sh 0000:6a:01.0 $ tools/testing/selftests/kvm/irq_test -d 0000:6a:01.0 This test only supports x86. Testing physical device interrupts (-d argument) requires a device with a supported VFIO selftest driver. Currently supported devices include: - Intel DSA (Data Streaming Accelerator), 8086:0b25 - Intel IOAT (I/O Acceleration Technology), 8086:2021 The test can be run with following command-line arguments allow for broad coverage of the interrupt delivery path: -a: Random IRQ Affinity. Randomly affinitizes the device IRQ to different host CPUs to verify stable delivery during interrupt steering changes. -b: Block vCPUs. Causes vCPUs to HLT instead of spinning, verifying that Posted-interrupt wakeup (PIW) correctly kicks blocked vCPUs. -c: Clear GSI Routes. Periodically destroys/recreates KVM's GSI routing table to verify handling of dynamic IRQ updates. -d: Device MSI Triggers. Uses the physical device to trigger MSIs instead of eventfd emulation (requires a supported device driver). -i: IRQ Count. Sets the number of interrupts to generate (default 1000). -m: vCPU Migration. Migrates vCPUs to random physical CPUs to verify that posted interrupts follow the vCPU across host cores. -n: NMI Delivery. Routes interrupts as NMIs into the guest to verify the VFIO-NMI delivery path. -v: vCPU Count. Distributes interrupts across multiple vCPUs via round-robin routing. -x: xAPIC Mode. Forces legacy xAPIC mode to verify compatibility. --- Changelog v3 -> v4 - Add context to short logs specifying if the change relates specifically to the IRQ test (Sean) - Format code correctly (Sean) - Fix compilation errors for gettid() wrapper (Sean) - Add macros for GUEST_RECEIVED_NMI and GUEST_RECEIVED_IRQ (Sean) - Split helper functions into separate patches (Sean) David Matlack (12): KVM: selftests: Build and link selftests/vfio/lib into KVM selftests KVM: selftests: Add /proc/interrupts parsing helpers for IRQ test KVM: selftests: Add guest read/write macros KVM: selftests: Add IRQ injection test KVM: selftests: Verify IRQ bypass works in IRQ test KVM: selftests: Verify interrupts are received when IRQ affinity changes in IRQ test KVM: selftests: Verify IRQs wake up halted vCPUs in IRQ test KVM: selftests: Verify interrupts are received after modifying IRQ routes in IRQ test KVM: selftests: Make number of IRQs configurable in IRQ test KVM: selftests: Verify non-postable IRQ remapping in IRQ test KVM: selftests: Make number of vCPUs configurable in IRQ test KVM: selftests: Add xAPIC support in IRQ test Josh Hilke (7): KVM: selftests: Rename guest_rng to kvm_rng KVM: selftests: Add helper to generate random u64 in range [min,max] KVM: selftests: Add kvm_gettid() wrapper and convert users KVM: selftests: Add kvm_sched_getaffinity() wrapper and convert users KVM: selftests: Add pin_task_to_random_cpu() helper function KVM: selftests: Verify vCPU migration during IRQ delivery in IRQ test KVM: selftests: Print vCPU affinity on timeout during IRQ test tools/testing/selftests/kvm/Makefile.kvm | 8 +- tools/testing/selftests/kvm/arch_timer.c | 2 +- .../kvm/arm64/arch_timer_edge_cases.c | 2 +- .../selftests/kvm/demand_paging_test.c | 2 +- .../selftests/kvm/dirty_log_perf_test.c | 4 +- tools/testing/selftests/kvm/dirty_log_test.c | 8 +- .../selftests/kvm/include/kvm_syscalls.h | 6 + .../testing/selftests/kvm/include/kvm_util.h | 13 + .../testing/selftests/kvm/include/proc_util.h | 28 ++ .../testing/selftests/kvm/include/test_util.h | 25 +- .../selftests/kvm/include/x86/kvm_util_arch.h | 4 +- tools/testing/selftests/kvm/irq_test.c | 370 ++++++++++++++++++ tools/testing/selftests/kvm/lib/assert.c | 8 +- tools/testing/selftests/kvm/lib/kvm_util.c | 95 ++++- tools/testing/selftests/kvm/lib/memstress.c | 8 +- tools/testing/selftests/kvm/lib/proc_util.c | 62 +++ tools/testing/selftests/kvm/lib/test_util.c | 27 +- tools/testing/selftests/kvm/mmu_stress_test.c | 15 +- tools/testing/selftests/kvm/rseq_test.c | 6 +- tools/testing/selftests/kvm/steal_time.c | 22 +- 20 files changed, 635 insertions(+), 80 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/proc_util.h create mode 100644 tools/testing/selftests/kvm/irq_test.c create mode 100644 tools/testing/selftests/kvm/lib/proc_util.c -- 2.54.0.929.g9b7fa37559-goog