From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 07C883CD8D3 for ; Fri, 26 Jun 2026 21:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509763; cv=none; b=s+/L45znJ6oXGAAEIAzSggRjgtiCGbJ23aCkOCDKQZCriZTrf9i0ek0s23ZhoDY+ZfORxLzLh6csW1valoMyco2E6ugvKEevXlbzjtNeTI6Kc0QKzEI9hS75OA4RF6WUBFt88jxHCwkQlykbSNTZmFyCxqxeVoyEbZlAenWmXsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509763; c=relaxed/simple; bh=7417aI7o8+VY0zFgJhxw12Swg3ymzFrCld14qvLBip0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hqKBDS95sWD3s/zVuwT1wOWbXJoU7MOEaPFVKpJGE5KorBzc9bRiHxGgc4g5nBbKsjWVSdjkBnAmjhS8qGS7eaFYV5CxWcXt3Zbd8Tw+HNLchV0Nn1ZPSnjoix5cOTJvpa3Eu9LhF996BlaOvi9TLhXCu85wjfr88R3ecp3DE7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UuyO7NxZ; arc=none smtp.client-ip=209.85.216.74 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UuyO7NxZ" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-37cc07f3e36so1588972a91.2 for ; Fri, 26 Jun 2026 14:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782509758; x=1783114558; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=37AjqTPC3Cofz5c5D7lHCWd7gT64KCMX7KZ8N6F2Usg=; b=UuyO7NxZ9XJ5uvgj2f3gvueo0otRYNCHzgCJc8KgXPc42VOeHDLwxmJ4Fv7sT5Z380 gjCk1L8/5WoKVVE2KCvEHPrRk7wrmhSofDhel09EHRZCgbvkvbVxulj5cYSziS2f/45P vFf8TV3NZ5sXx0zK2+dGF6vjMOWgCbVxjQSNVUrEjwjwjldM3+o07xaKJ5auy/zyaa5M MASnxP+eWgBAA+khVzQUVgFOqgU4XDJbR6/3g2WBttjJEMHLNxFTCiJLMVRJXIY3PEPv wu7nsjNpk/D4b11hJRQGTVUXvDJHJ1Gg3MCn/SwCashj7YAciya6H2QQluz0TuVdYSN6 gcfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782509758; x=1783114558; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=37AjqTPC3Cofz5c5D7lHCWd7gT64KCMX7KZ8N6F2Usg=; b=m2DVX4ltI1BbJFyQdcZsZaroxy9jz1z+DaOr0Q42fzQ+50TLZvZOwlUnlY1SZA1X3r SUV659UKM7cVMM0mXhpLo050iUElttH0Z2i0rt8UnhyOL/zR3yG2u/bJk4Ggx0t9ZUPI 050Jr3H3zg2uwZ2BAVb8m1E0D01tY6Ta9zck7TUIPer4OA2Y0T5SM5mm6sOauq5vJLU7 2Jb3sMHco+1+oi2sfmc7WgxlvS+3hTUUaHpTH+Ru2jyk65FhoRyazkuhzlxfnAivIjWc el8vp1qDr8+4kvxvtdnvB7Qx8kqddKNV2DIlnn8EurI2gXHxzH1aZ8qC3+mEm5LLwo6o /6Ug== X-Forwarded-Encrypted: i=1; AHgh+RqHKHrcRSaiR7eRTH3ofpV5P6c9d18ErWgnV/IpufUzMTI/SLGw3obelfUajsFhCzQ2n2s7nhWSDPXQQ3g=@vger.kernel.org X-Gm-Message-State: AOJu0YxkwzNt2ZZ3Va8iOKPZf9AcuhPZ7ecss0tywmhiTgH9HmlPbUN3 N0U76/nglAEqiFtjgSsfSinDCmQbyyt5XzACxmadXcR6KsJxV0HmtN4h6o8uh4a4COtS/8WDOSv 4FKA/BA== X-Received: from pjyl13.prod.google.com ([2002:a17:90a:ec0d:b0:37d:f8a4:accb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4cd0:b0:36b:9daf:1504 with SMTP id 98e67ed59e1d1-37dfa250f22mr8077365a91.14.1782509758025; Fri, 26 Jun 2026 14:35:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 26 Jun 2026 14:35:31 -0700 In-Reply-To: <20260626213534.3866178-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260626213534.3866178-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260626213534.3866178-19-seanjc@google.com> Subject: [PATCH v8 18/20] KVM: selftests: Verify vCPU migration during IRQ delivery in IRQ test From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Sean Christopherson Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, David Matlack , Josh Hilke Content-Type: text/plain; charset="UTF-8" From: David Matlack Extend the eventfd IRQ test with a '-m' flag to have the test migrate the target vCPU to a random physical CPU before triggering its interrupt, e.g. to validate KVM's ability to update device posted IRQ routing. Signed-off-by: David Matlack Co-developed-by: Josh Hilke Signed-off-by: Josh Hilke [sean: pin one vCPU at a time to simplify things, use main()'s affinity] Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/irq_test.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c index 48520c6dea69..c0ff6e60b167 100644 --- a/tools/testing/selftests/kvm/irq_test.c +++ b/tools/testing/selftests/kvm/irq_test.c @@ -157,13 +157,14 @@ static const char *probe_iommu_type(void) static void help(const char *name) { - printf("Usage: %s [-a] [-d ] [-e] [-h] [-i nr_irqs] [-n] [-t iommu_type]\n", name); + printf("Usage: %s [-a] [-d ] [-e] [-h] [-i nr_irqs] [-m] [-n] [-t iommu_type]\n", name); printf("\n"); printf("Tests KVM interrupt routing and delivery via irqfd.\n"); printf("-a Affine the device's host IRQ to a random physical CPU\n"); printf("-d Use a VFIO device to send MSI-X interrupts instead of manually signaling the eventfd\n"); printf("-e Set empty GSI routing in-between some interrupts\n"); printf("-i The number of IRQs to generate during the test\n"); + printf("-m Pin target vCPU to random physical CPU before triggering interrupt\n"); printf("-n Deliver 50 percent of IRQs as non-maskable interrupts\n"); printf("-t Override the IOMMU type to use (vfio_type1_iommu or iommufd)\n"); printf("\n"); @@ -195,12 +196,14 @@ int main(int argc, char **argv) const char *device_bdf = NULL; const char *iommu_type = NULL; int i, j, c, msix, eventfd; + bool migrate_vcpus = false; + cpu_set_t available_cpus; bool use_nmi = false; struct iommu *iommu; struct kvm_vm *vm; int irq, irq_cpu; - while ((c = getopt(argc, argv, "ad:ehi:nt:")) != -1) { + while ((c = getopt(argc, argv, "ad:ehi:mnt:")) != -1) { switch (c) { case 'a': irq_affinity = true; @@ -214,6 +217,9 @@ int main(int argc, char **argv) case 'i': nr_irqs = atoi_positive("Number of IRQs", optarg); break; + case 'm': + migrate_vcpus = true; + break; case 'n': use_nmi = true; break; @@ -248,7 +254,6 @@ int main(int argc, char **argv) eventfd = kvm_new_eventfd(); irq = -1; - irq_cpu = -1; } pr_info("Injecting interrupts for GSI %d (guest vector 0x%x) %d times\n", @@ -256,6 +261,9 @@ int main(int argc, char **argv) kvm_assign_irqfd(vm, gsi, eventfd); + if (migrate_vcpus) + kvm_sched_getaffinity(0, sizeof(available_cpus), &available_cpus); + for (i = 0; i < nr_vcpus; i++) pthread_create(&vcpu_threads[i], NULL, vcpu_thread_main, vcpus[i]); @@ -266,6 +274,8 @@ int main(int argc, char **argv) continue; } + irq_cpu = -1; + for (i = 0; i < nr_irqs; i++) { const bool do_set_empty_routing = set_empty_routing && (i & BIT(3)); const bool do_use_nmi = use_nmi && (i & BIT(2)); @@ -282,6 +292,9 @@ int main(int argc, char **argv) proc_irq_set_smp_affinity(irq, irq_cpu); } + if (migrate_vcpus) + pin_task_to_random_cpu(vcpu_threads[i % nr_vcpus], &available_cpus); + for (j = 0; j < nr_vcpus; j++) { TEST_ASSERT(!GUEST_RECEIVED_IRQ(vcpus[j]), "IRQ flag for vCPU %d not clear prior to test", -- 2.55.0.rc0.799.gd6f94ed593-goog