From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 2670723EAB4 for ; Sat, 13 Jun 2026 00:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781310046; cv=none; b=n65a558gCjXXvTabv2GTEec+aDjJa9jMYniJk6H2cIkx73y8xg+ZVRNkPsLGyVm1ib5FdwPA4ZnxhelrV2mU/jSrNLL0S61NzLcf4xAWmw9t05zGnjSy2VatQK2qDubeLILbvnu+y2LDfbjf//pj0Yu4LJaGoaeUcfreIic7d4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781310046; c=relaxed/simple; bh=V+fai80fvGy6xNbMhzBzclZirnMI9czJqjJ8MXI2MX4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b9o7I4CkhRf4JbELVshD0CeU6p6FE6uLd1oJqFlkzATNLeMCs7ORR/M6p5m0CHgCecYW306EJHb4AxNf2GI+6jS8AONKKf8ehzZ8EIOmaOW6TWoKjxaJWsgcYPn2/AhKRlCn35U7gNpDtdwgAuMLVOprf/riRAoL/ZL/WSBbAIU= 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=X5/Ciz5B; arc=none smtp.client-ip=209.85.214.201 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="X5/Ciz5B" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2c0d0516ad7so15482745ad.0 for ; Fri, 12 Jun 2026 17:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781310044; x=1781914844; 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=3qRbqYxE/FHHRGIPHLP62KGhWo8UkYosmytEIIXQZ9U=; b=X5/Ciz5B9czGyvHpFAgYYMSyz6ctkGJi3MiVMsiZzkd5GCIObI6f+IVjtnas8x/12b 344eqynQISMLQYKI34c3JFyqnIRASaP1JThmR63qaqKA3v0BGeniwGqR24ETv+9hGrL1 0nQVpuqEMArcpEVqKy00f/kjdn1/lugcPThoURq8jWx9hacr5OaeIqlFV05TOVTPJmk5 Ut6uBQ5dePEbTIM0uzB7utec1uLMptcxg7jfCsJ2A46nZY0MCuELvhTWVudt8/6U2Z62 3fWzsAsTI5k4/DtPf9TGMZGkGdkHiQUuuzLYClmnWQ9n2S2aYcYz/5dObziwNcilXbWF M1ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781310044; x=1781914844; 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=3qRbqYxE/FHHRGIPHLP62KGhWo8UkYosmytEIIXQZ9U=; b=eJuPqi5ewAKVoh3AJV9Q4AMRWZbvCqxfZEDKkPeSSHxBw34m5rsYap4u6jpwVWiPAR xJD5eJzOAHmebOL3AKkRBjZcKBHW+OQmYsfe7dneT8s/1z5w1oU4b1FKND1SqotVEMHM LcMOE7Ee/c8iNeoGL1ttvw6BzbLocJshLaIiLZDxYbYcra/3kDF6Prtu3q7ZIV+/CFnj zydHt15Fp9qnlmb3TzwNLLgDSe3J1l6BbZX7iiKswm0CQmzanHx3fmnpZenbhuo5xB8g vKsv7V2PJYk92xcS0TLsW8kC0Pisa/0RjMpWL7nIRBv4c+U9b1cB4ymXk2a6MX8Rbm/4 kyyg== X-Forwarded-Encrypted: i=1; AFNElJ/xYXmLcVeMAGpGfucI7WF3vYRw3E71nGMEf9ORKjkAXZsUi+ydslZtNDw2HTPJutvjLApl5ZDgigdvbbI=@vger.kernel.org X-Gm-Message-State: AOJu0YwXlgSth1i6j48B1Gp5olwIcv9UF573z6YFaaxBwbdc9BfMyeto 899QNLVNUIIECGBq4PwN6BPXFsuWRNHQixg2PtTteGZAE92Mg80WHvYRRZJNysTZhwOYUm5w9kb Kh83qnA== X-Received: from plrx19.prod.google.com ([2002:a17:902:b413:b0:2bd:3dba:a4c5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:acb:b0:2c0:a746:7b16 with SMTP id d9443c01a7336-2c6641e3058mr18450205ad.22.1781310044254; Fri, 12 Jun 2026 17:20:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Jun 2026 17:20:19 -0700 In-Reply-To: <20260613002031.745413-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: <20260613002031.745413-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260613002031.745413-9-seanjc@google.com> Subject: [PATCH v7 08/20] KVM: selftests: Add helper to get host IRQ from device MSI-X for IRQ bypass 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 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 Signed-off-by: David Matlack Co-developed-by: Josh Hilke Signed-off-by: Josh Hilke [sean: massage changelog] Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/include/proc_util.h | 9 +++++ tools/testing/selftests/kvm/lib/proc_util.c | 40 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/proc_util.h create mode 100644 tools/testing/selftests/kvm/lib/proc_util.c diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm index de5f6e91203b..c112cedd3a2a 100644 --- a/tools/testing/selftests/kvm/Makefile.kvm +++ b/tools/testing/selftests/kvm/Makefile.kvm @@ -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 diff --git a/tools/testing/selftests/kvm/include/proc_util.h b/tools/testing/selftests/kvm/include/proc_util.h new file mode 100644 index 000000000000..704839b6d7af --- /dev/null +++ b/tools/testing/selftests/kvm/include/proc_util.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_PROC_UTIL_H +#define SELFTEST_KVM_PROC_UTIL_H + +#include + +unsigned int vfio_msix_to_host_irq(const char *vfio_device_bdf, int msix); + +#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 new file mode 100644 index 000000000000..84d30f055a0a --- /dev/null +++ b/tools/testing/selftests/kvm/lib/proc_util.c @@ -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; +} + -- 2.54.0.1136.gdb2ca164c4-goog