From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 91DB43BB135 for ; Fri, 26 Jun 2026 21:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509751; cv=none; b=l4TYTKB0kyWEocTriQ1yt9bl4RTdG7Woxu3z6YYRfr6OaRvzIUGu+Q+T/Lbb6BMzj6VOemlohI1KE3yM1BrganBA15HzvgZEVWhOcdy8dod6nxvM+NOiZ69FVe4BiMxonERHs6E4ygUJM3c5zCoKQEYiFlFFXGeL13VPsn1vZ3E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782509751; c=relaxed/simple; bh=SROkhbh6/bZDK8vpbuJbeyr6/QiF+pI9lfh9kvOCqug=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NaqgmyFXs8d3eTMqevl1cwD+RTkSmr9F7rv+sFTWXSANtLbOVxX3Af7By9WOhEMQKEos5K+ms0Cf19Zt6je2FH3nQAoawfI4lnnNzRg47DvvEQozBlI2NnfQ/z1hTRapU9RCHEVKfTnODUEVOins7ILty0YULBpT2OBF2dnJ+2k= 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=G+Thz3Y5; arc=none smtp.client-ip=209.85.210.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="G+Thz3Y5" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-845b97ebc72so1052290b3a.3 for ; Fri, 26 Jun 2026 14:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782509746; x=1783114546; 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=pnTbJ0qzupqs+OdQTBbFmTptoXz92YWWt6sTMLKlVlM=; b=G+Thz3Y5BV8uSy6t6rG6LYo78LZi1vALC/Kh7P3VkqXtC/t2NLZQOkKJUJvBK+/xdT NW6IEPw1+cNTueb4G1gZHVSRzjS6yyHWoIbtMO50Y8SolDAY1NEX9r2ZjpEC7yNGpsjD 0N3JsgC7L5BN5gXJy5Bd7QKVc/fCkFzMaCw0xl0xzA1X2ysgyKLpQrJbFZAXfB8kyYYd zKH8afbP8pOv0Dz9B1lhNLG4bn6Z0uepea1sWlmxCP1j0tlb92gSsk1AdOmSXqB7TXFD sIpRKmYQUru+G6gKHEd2RoU3JOJShLQeIPieyQQSWjuFXdBHb3tOkdRRBVOq7bVXLaWs Rvdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782509746; x=1783114546; 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=pnTbJ0qzupqs+OdQTBbFmTptoXz92YWWt6sTMLKlVlM=; b=DAFjMX3IbrpoRzJIip6oPQrFpOPrR3BXgj3Kzb4/hELdcpKbbzRtn3KOjWbg5BPPit mTBaIfxinWz9Nr0048+ZF5EpDbzE1fVw12BAPAuf7jr9/MJIvfzEtTzW7snLPWUPAOE4 tRr3DJOG+3VgKpivYdYlRfhbq+JsP5PX95xwtG7b6bapXfHqVLOoXbQe0cyz/gZqbrVu SscZqL14x+g5NrprwhbwblGOp25f6AbLBQLNm0qMr5JLx/sQ8iBXN95Y7YiAZqseGE9N QoZzBFcJkMS57kD0EYj8pYop+rd1vZ+VlxuXvSabqdPB3TxsCdDniub4xstiCwwfJ6yL UjeA== X-Forwarded-Encrypted: i=1; AHgh+RqjRxbaBggAGz51pPRrbLV0Omq/U0wFKw5/X8Qr141fWnl8sJ7L6ocXTkr1w3/xXeHMMgefcp8dYK1opbk=@vger.kernel.org X-Gm-Message-State: AOJu0YzoxcatZD8n4xoC0Y1DeMaZMoejCwZh+rWa5VpaRTByyp9GPXP0 U9B+kN5H51kJTZTX102vRRlJyo62x7z+6QXdX23nbmEOrLShg+NpmeFnxqh7j4YS1tGf5lD1MQs 8O4gRvg== X-Received: from pfbhx20.prod.google.com ([2002:a05:6a00:8994:b0:842:7548:51e8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:66c6:b0:845:ba0d:3e5c with SMTP id d2e1a72fcca58-845ba0d45cfmr6880920b3a.42.1782509746265; Fri, 26 Jun 2026 14:35:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 26 Jun 2026 14:35:21 -0700 In-Reply-To: <20260626213534.3866178-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: <20260626213534.3866178-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260626213534.3866178-9-seanjc@google.com> Subject: [PATCH v8 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 a24875fada03..88c6c8046dde 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.55.0.rc0.799.gd6f94ed593-goog