KVM: selftests: Add a helper to set proc IRQ affinity for IRQ test

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 <jrhilke@google.com>
[sean: make the utility self-contained, drop "list", massage changelog]
Link: https://patch.msgid.link/20260626213534.3866178-11-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
Josh Hilke 2026-06-26 14:35:23 -07:00 committed by Sean Christopherson
parent 3902e8b02d
commit 380b0e5e0e
2 changed files with 16 additions and 0 deletions

View File

@ -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 */

View File

@ -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);
}