From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 53C123191C8 for ; Wed, 10 Jun 2026 00:54:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781052848; cv=none; b=UPiD1bQUhO7ZglT1wFP+JNKv0AW5A3b4IzdsNEW+j40AWSZWjHpQSA/iNydu1J2IxXFrLY84b4MLqc9T3kxV1CZk3faK1rc3sV3fFAgp63TR8UzVqirNGn532gNgkJKqidFGvpkThTWDDWEcy3gXFJaLpgJizw09wEA2YCrqrbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781052848; c=relaxed/simple; bh=M1SdOxQSqUB+H9HERaK00A5DaRRJ8hWJ3nSlC9W7AKk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eXMlZtBc2N4GHycxovE+8yT0Ap2rJThJpAlSr71/Om9kMMy35IEwBR8+WANc94nUaWjpT5s9gdBU7GPzH3hj0PhxLtjvy5CaPwcUC9/y/dhBtU6rtbpEQ5mfCSMMNwahBfSVdxHGeZl4MVT1tJn/3NQGvAzzXMNfozSOIhGwZVQ= 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=jTHksrFC; arc=none smtp.client-ip=209.85.216.73 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="jTHksrFC" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-36b934a336eso4472550a91.2 for ; Tue, 09 Jun 2026 17:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781052845; x=1781657645; 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=6cKvUgF9aEo/LoEwdPMR+iUYk9h9pBrQbVTXEbhkSEo=; b=jTHksrFCpiRDNXAToBPewfdozhRIQo/Ho8S1Jmir4Ljd7o7kPcwEHTr7JLUlEQuZL4 G1FRS9BMzKjfZiGb+9ZbeB7Fq00CVqFEJj9j39YaHTeWJ5qRRO6G7B5pIHyY8gTVEnU0 K6NreFzvGLHXZAxFEIDU4GGp97jjIEzVSvYkdNw7o1tqs9/x4RLoFobwo54CeGMEGr1+ XnbRhOQj32SHVxOJVJwDb8QJrtQrjhWdsYTD58FVNOpG8x1HwDiO5P23accIHnkOMQ51 E35wSVW0IqqD8T1HcKRWoWD252wBv1CjhnbK0wGlpt8/qGdzzW9aA9pSZWIBEHIRIfqc Yq8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781052845; x=1781657645; 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=6cKvUgF9aEo/LoEwdPMR+iUYk9h9pBrQbVTXEbhkSEo=; b=cw/TF/scJJvRvhoT2ymUm4VCMdkwkHssCPTqviTMc+EFb0nM08CBAh7ErsipBrUYke YKMXmqt10/dq2ZLEIc3HnKE2UZ01Zr/jZa3del0BsS/enZ5CZw+9k7YWRho/hsNf3P+Z LAk4h4viZT1KWsnxzr4ikZIowtG38ggRyprmM+s+u6vQgDjkmrxgmTwVEdd5DvWcsNjC icZvw5MS4oA6sMJhvkigWRAnUIQ7n5NsBtFOTDYkqI9AOV0Kd5e7SoztIMPpP2MaaHAV JCUXzt49gUmUlaWz3SBpDyVmlYynuCKX+SXyh87et4uGGBd4dijtjG0pFgvT2VFGUK0p Gr7A== X-Forwarded-Encrypted: i=1; AFNElJ94noSpUfpjZIkhcNrQuztr1XPds1QRqdYTGYyA66mZI/chZFj1dalgWn7nsadbKCWMFZciPnUSNbUekKI=@vger.kernel.org X-Gm-Message-State: AOJu0YwIg4Z4eN7GC7X+9Keu79aLoGRiSGAD9ElDAKDtBq4+eF13SCLo tgLXqB2kBomL01WjcY1HXs6KzV21SJfqxMsVYbGytfXhgXMpvKa7XJ1AhtRCc37gMTQxxFGKXMa ghRLu7Q== X-Received: from plbkx6.prod.google.com ([2002:a17:902:f946:b0:2bd:99a8:49c9]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:540c:b0:36d:b680:3036 with SMTP id 98e67ed59e1d1-370ee447882mr23877534a91.4.1781052845496; Tue, 09 Jun 2026 17:54:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Jun 2026 17:53:37 -0700 In-Reply-To: <20260610005338.2967132-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: <20260610005338.2967132-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.1099.g489fc7bff1-goog Message-ID: <20260610005338.2967132-18-seanjc@google.com> Subject: [PATCH v6 17/18] KVM: selftests: Make number of vCPUs configurable 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 '-v' flag to allow the user to configure the number of vCPUs to create and run (versus only ever using a single vCPU). Update the routing logic to play nice with 32 bit IDs, enable x2APIC format in KVM (to enable 32-bit ID routing), and disable KVM's x2APIC broadcast quirk so that targeting vCPU 255 doesn't blast the interrupt to all vCPUs when in x2APIC mode. Signed-off-by: David Matlack Co-developed-by: Josh Hilke Signed-off-by: Josh Hilke Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/irq_test.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/irq_test.c b/tools/testing/selftests/kvm/irq_test.c index aeede7937147..7d64fd29ea8b 100644 --- a/tools/testing/selftests/kvm/irq_test.c +++ b/tools/testing/selftests/kvm/irq_test.c @@ -112,7 +112,8 @@ static void kvm_route_msi(struct kvm_vm *vm, u32 gsi, struct kvm_vcpu *vcpu, .entry = { .gsi = gsi, .type = KVM_IRQ_ROUTING_MSI, - .u.msi.address_lo = 0xFEE00000 | (vcpu->id << 12), + .u.msi.address_lo = 0xFEE00000 | (vcpu->id & GENMASK(7, 0)) << 12, + .u.msi.address_hi = vcpu->id & GENMASK(31, 8), .u.msi.data = use_nmi ? NMI_VECTOR | (4 << 8) : vector, }, }; @@ -145,7 +146,7 @@ static const char *probe_iommu_type(void) static void help(const char *name) { - printf("Usage: %s [-a] [-d ] [-e] [-h] [-i nr_irqs] [-m] [-n] [-t iommu_type]\n", name); + printf("Usage: %s [-a] [-d ] [-e] [-h] [-i nr_irqs] [-m] [-n] [-t iommu_type] [-v nr_vcpus]\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"); @@ -155,6 +156,7 @@ static void help(const char *name) 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("-v Number of vCPUS to run\n"); printf("\n"); exit(KSFT_FAIL); } @@ -191,7 +193,7 @@ int main(int argc, char **argv) struct kvm_vm *vm; int irq, irq_cpu; - while ((c = getopt(argc, argv, "ad:ehi:mnt:")) != -1) { + while ((c = getopt(argc, argv, "ad:ehi:mnt:v:")) != -1) { switch (c) { case 'a': irq_affinity = true; @@ -214,6 +216,11 @@ int main(int argc, char **argv) case 't': iommu_type = optarg; break; + case 'v': + nr_vcpus = atoi_positive("Number of vCPUS", optarg); + TEST_ASSERT(nr_vcpus <= KVM_MAX_VCPUS, + "KVM selftests support at most %u vCPUs", KVM_MAX_VCPUS); + break; case 'h': default: help(argv[0]); @@ -223,6 +230,9 @@ int main(int argc, char **argv) TEST_REQUIRE(kvm_arch_has_default_irqchip()); vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus); + vm_enable_cap(vm, KVM_CAP_X2APIC_API, KVM_X2APIC_API_USE_32BIT_IDS | + KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK); + vm_install_exception_handler(vm, vector, guest_irq_handler); vm_install_exception_handler(vm, NMI_VECTOR, guest_nmi_handler); -- 2.54.0.1099.g489fc7bff1-goog