Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 AC47B26F47C for ; Wed, 10 Jun 2026 00:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781052834; cv=none; b=lr012tc/SmYo+Vt74C9Sg5PON6IR96UObrPwJ4S9BShbqIBNeHSKfjbg+zcmjq/xPsoyv7d+xduBbvA20LZtIYxC241GFjWYvmVIwLpND+hQh2CSIjNAmb/VTufW3Ovwj6wAqxL+rb58utQNkxdus7Tqc72jtqXYbzzfHpPdZos= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781052834; c=relaxed/simple; bh=1R14fEOQLs6N966Zchktrti8uX0PorIg54QMlHvgk68=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Hwvopwn8rv9Xs/A9wgcuUzwDeo6f4di3Sukkufw4Pyo+2l8zeThNvPAPVsFugdqop6s5s3BSoZGp4D4eaPqcNaxRKwRQa1iew/XpgBaej3w6ctf20VCMLFLsd4OWRVYJTM7y5jBQNSm1RR3A6hTlxOZ+TU9grOaYBhnATpsxFrE= 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=wLIR/TXM; arc=none smtp.client-ip=209.85.214.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--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="wLIR/TXM" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2c0c1e08848so83268365ad.0 for ; Tue, 09 Jun 2026 17:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781052832; x=1781657632; 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=W9rLXq+5NYuHF5j+PqcJxTC4xDIIkyDtUExjWacEIvs=; b=wLIR/TXMMNk1vxVSyH+M9Sr00kTOSLLm8UR3Fd1rjNZCTxpP90HKMgzQcuupLBuNMs hXF7PMQ8q0KSJ6rhIAMjNAQDR22f5ryUSy3/5yPgrJf3QRh0e6UmqQLjBGVTUCOoVLSO Iu+Z0FGUNSh1PdDVEmVS/vwdbeS9TXqZJbF3dvao92NHYUxquI4X4xpqrQYbuEh9WOIA qHpyIvAFtVdH/UQhtdgQOoIcpBciI7ry3GZqeGjFqTTRvcISqhe1ABBxCgvLM7lVxivx Vh0xxO171Tzu1GfO11XioVIY1o1GhvklRkKnitadEVvnAmiMYPycYQi6yraejvmI6hc1 r9jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781052832; x=1781657632; 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=W9rLXq+5NYuHF5j+PqcJxTC4xDIIkyDtUExjWacEIvs=; b=aSNVWP4wIe+VHfoXjLb81wTP6YueKfR4Wb5Qtt3RnGwIV1MhXRYcbPOHEazgr0Vdb8 b9iWvIh4LV0QBhO/fV/E2jNIH5FcwYWK30L717VcdmEsV+SX6ZLkDOzQjr4TfAPf3dZn FTbJCXzXFbhlOljUCur92lODGPJOOhYccmkqYgiAK6iWOpiipWs51e6c3JqTZ++SFj9f C5wrGVVxR2/MyibtQBWFQIcKRS1IK924IjwjjpyDWbmW2m9xEvIn01Hj2zuVByFI86Y2 /dFHgTo2+mg4UKvqyGO0kGMZ1jRXC/NNqWSWihHMc9fvVRqTjwSyyJfVLpkvZDetCen9 IjPw== X-Forwarded-Encrypted: i=1; AFNElJ+RcFPnxp0pqXJYConlGdWMbc6eM7FjDVkz3yqbBq8yZXnPxt8ANp1tTeY3NuIdQF2UPlY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+SNj+8jy9fFvzor0XzLs9Cc2Xy8SpuSH8o81J1HXFEmueZziq XFfCG2ukL9ngX+9q2ZReemmi+R0g1xO87Ml83HtA2OsfhDPX8Zxoz9z0nnwbpsTeedWOt/Cj0vL ZAxNonA== X-Received: from plbbj2.prod.google.com ([2002:a17:902:8502:b0:2bf:2098:44f4]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ef50:b0:2bf:23c3:34ba with SMTP id d9443c01a7336-2c2a1c99a9bmr63318635ad.28.1781052831902; Tue, 09 Jun 2026 17:53:51 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Jun 2026 17:53:28 -0700 In-Reply-To: <20260610005338.2967132-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-9-seanjc@google.com> Subject: [PATCH v6 08/18] KVM: selftests: Add a helper to set proc IRQ affinity for 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: Josh Hilke Add a utility, proc_irq_set_smp_affinity(), to set the CPU affinity of a Linux host IRQ via the proc filesystem. Use smp_affinity_list instead of smp_affinity to avoid having to convert the single CPU to a bitmask. The helper will be used by the eventfd IRQ test to verify delivery of IRQs when the affinity is randomized/modified. Signed-off-by: Josh Hilke [sean: make the utility self-contained, drop "list", massage changelog] Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/proc_util.h | 2 ++ tools/testing/selftests/kvm/lib/proc_util.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/tools/testing/selftests/kvm/include/proc_util.h b/tools/testing/selftests/kvm/include/proc_util.h index 704839b6d7af..d1ddc967d11d 100644 --- a/tools/testing/selftests/kvm/include/proc_util.h +++ b/tools/testing/selftests/kvm/include/proc_util.h @@ -6,4 +6,6 @@ unsigned int vfio_msix_to_host_irq(const char *vfio_device_bdf, int msix); +void proc_irq_set_smp_affinity(unsigned int irq, int cpu); + #endif /* SELFTEST_KVM_PROC_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/proc_util.c b/tools/testing/selftests/kvm/lib/proc_util.c index 84d30f055a0a..3960b3841d63 100644 --- a/tools/testing/selftests/kvm/lib/proc_util.c +++ b/tools/testing/selftests/kvm/lib/proc_util.c @@ -38,3 +38,17 @@ unsigned int vfio_msix_to_host_irq(const char *device_bdf, int msix) return (unsigned int)irq; } +void proc_irq_set_smp_affinity(unsigned int irq, int cpu) +{ + char path[PATH_MAX]; + int r, fd; + + snprintf(path, sizeof(path), "/proc/irq/%u/smp_affinity_list", irq); + fd = open(path, O_RDWR); + TEST_ASSERT(fd >= 0, "Failed to open %s", path); + + r = dprintf(fd, "%d\n", cpu); + TEST_ASSERT(r > 0, "Failed to affinitize IRQ-%u to CPU %d", irq, cpu); + + kvm_close(fd); +} -- 2.54.0.1099.g489fc7bff1-goog