mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 17:42:03 +02:00
KVM: selftests: Add helper to get host IRQ from device MSI-X for IRQ bypass test
Introduce proc_util.c and proc_util.h to house utility functions for interacting with the proc filesystem. Add vfio_msix_to_host_irq(), which parses /proc/interrupts, to get the host Linux IRQ for a given VFIO device BDF and MSI-X vector. This helper will be used by the eventfd IRQ test to print the host IRQ number when triggering IRQs via VFIO device, e.g. to aid in debugging if the test fails. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: David Matlack <dmatlack@google.com> Co-developed-by: Josh Hilke <jrhilke@google.com> Signed-off-by: Josh Hilke <jrhilke@google.com> [sean: massage changelog] Link: https://patch.msgid.link/20260626213534.3866178-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
3ceab37ac9
commit
362cc00162
|
|
@ -11,6 +11,7 @@ LIBKVM += lib/kvm_util.c
|
|||
LIBKVM += lib/lru_gen_util.c
|
||||
LIBKVM += lib/memstress.c
|
||||
LIBKVM += lib/guest_sprintf.c
|
||||
LIBKVM += lib/proc_util.c
|
||||
LIBKVM += lib/rbtree.c
|
||||
LIBKVM += lib/sparsebit.c
|
||||
LIBKVM += lib/test_util.c
|
||||
|
|
|
|||
9
tools/testing/selftests/kvm/include/proc_util.h
Normal file
9
tools/testing/selftests/kvm/include/proc_util.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef SELFTEST_KVM_PROC_UTIL_H
|
||||
#define SELFTEST_KVM_PROC_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
unsigned int vfio_msix_to_host_irq(const char *vfio_device_bdf, int msix);
|
||||
|
||||
#endif /* SELFTEST_KVM_PROC_UTIL_H */
|
||||
40
tools/testing/selftests/kvm/lib/proc_util.c
Normal file
40
tools/testing/selftests/kvm/lib/proc_util.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "kvm_util.h"
|
||||
#include "test_util.h"
|
||||
#include "proc_util.h"
|
||||
|
||||
static FILE *open_proc_interrupts(void)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("/proc/interrupts", "r");
|
||||
TEST_ASSERT(fp, "fopen(/proc/interrupts) failed");
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
unsigned int vfio_msix_to_host_irq(const char *device_bdf, int msix)
|
||||
{
|
||||
char search_string[64];
|
||||
char line[4096];
|
||||
int irq = -1;
|
||||
FILE *fp;
|
||||
|
||||
fp = open_proc_interrupts();
|
||||
|
||||
snprintf(search_string, sizeof(search_string), "vfio-msix[%d]", msix);
|
||||
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (strstr(line, device_bdf) && strstr(line, search_string)) {
|
||||
TEST_ASSERT_EQ(1, sscanf(line, "%d:", &irq));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
TEST_ASSERT(irq != -1, "Failed to locate IRQ for %s %s", device_bdf,
|
||||
search_string);
|
||||
return (unsigned int)irq;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user