From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 50F7C35B646 for ; Tue, 21 Apr 2026 23:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776813383; cv=none; b=YjtIN6jUwUaCMzDOTyxeL9no6p5N9Ddhsy+yiQo8lMdENzKhuPbnX5Ii+b8r+n3kjX7nhJLbvUtnSLMQd471x8AbIUa3rsTvZFljsM+JiOakh1AHH0LGz8N/uazBN0JGg9aKs6fGZAVBbpxRlAL/BshJ3xb2vsl37Cn6uJ7Q4BE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776813383; c=relaxed/simple; bh=Fa5Z2b3AFmLW659rMLC6e+YsFIKYNkhhbhmajGAg4nY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SMyFbzHZlmN0c6YxScOJHcBkjhmDuN4ceJ4ioT3KgTq3MAaFQDIt4bjXrwaNY9Am+oRWdKi9j2IqcLCruOf6OnubOholJeT9tvpYGQbwEFSy4EKSOWZvqpybvuUnPz3G0i6EqfLLZeWnXnBUWqH3Ft62AoYMLIKjscnu9Jw5iwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZHYNlmGf; arc=none smtp.client-ip=209.85.215.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--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZHYNlmGf" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c7993b17335so814704a12.0 for ; Tue, 21 Apr 2026 16:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776813381; x=1777418181; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rO/sEyq9fOmOK5M/bH4lLglok4DGILopTeBk6BkE89o=; b=ZHYNlmGfs1PK0moVxNWay4BoBLIqs8pBf05EnL5kLM4O9JZvToe7JtHXqEgxlVycTP FdIExshnNp6LH39qoUtSgEXx6dPZ+1Lc/ZiTDuZMeMBFiURsQCKQbLHfKFha4FGAFnzU g9CgTF9ntkUjCn2MQF8N9hEVsKSmgxv70+VQNEG955NX5EN68taOmsEDMP4DVOdGG84Q XppYKtdOPMus6yfqLQ6O90OgX0FlutuU/tFQF9MZSdkLipXB/lXd5nSzft7lqqydDHJm 4Jbuy2S7xoXJCPxYjAKmGAPsguUXDMToBq/szd5AG06u18rg7W+uENHKilqdjOirbsKP b89g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776813381; x=1777418181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rO/sEyq9fOmOK5M/bH4lLglok4DGILopTeBk6BkE89o=; b=iljZeD3I7XGRoF45JQjkBahqYQGQJXl7xJ+6OUlCRvNWmakmzwyv8b5uLGYsEQG6Tc kOJSqse2v4gJy57pRJvcCocsoQOPoeMMBuEZuUKMPyVBYF1NlTkPf8poYiGsR4eymqIt uVJAmyEXAs5367rUF5jRa68ZGfZ6cZIkxEaqra976pg9jQs9ZPouRKo2wQWdqbpLQADU EXrwDXJwyicNnzjFIV2dImZikxzYTYssb1zJIGBjFH3ZJ37+8nkfMqbmBvn4azYHiZa/ m/DIanhq+x7dAsilKldfDx/xPPqBBsJOigaVMLM+pTr3Tx+SODv0YJH84q8K6UWsp4wT f6Ig== X-Forwarded-Encrypted: i=1; AFNElJ9lgly9hzR8lwDrXLexNRhetOnw+m7HvJ+5Eohxatl388swtWcIiK8FngYLXqMvg7pgRpAbWYSB2jySP2A=@vger.kernel.org X-Gm-Message-State: AOJu0YxGrMHstP/+Vrv1Skgz4jyyBj8SRRHxUOEACpH3Y2pk87Q2dGa0 IcE2FVcCNX75C1yr4nxUYyoSUrhzoAHbPDG9qD/NuYqEb/wehaTvFqz0jwuDfT+dKQse2lmioeC e6ndUnGb4 X-Received: from pfkm16.prod.google.com ([2002:a05:6a00:810:b0:82f:acfe:350b]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1a0b:b0:82f:b519:a5cb with SMTP id d2e1a72fcca58-82fb519a73emr8945998b3a.37.1776813381347; Tue, 21 Apr 2026 16:16:21 -0700 (PDT) Date: Tue, 21 Apr 2026 23:15:43 +0000 In-Reply-To: <20260421231557.1254270-1-jrhilke@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260421231557.1254270-1-jrhilke@google.com> X-Mailer: git-send-email 2.54.0.rc2.533.g4f5dca5207-goog Message-ID: <20260421231557.1254270-3-jrhilke@google.com> Subject: [PATCH v3 02/16] KVM: selftests: Add /proc/interrupts parsing helpers From: Josh Hilke To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Alex Williamson , Josh Hilke Content-Type: text/plain; charset="UTF-8" From: David Matlack Introduce utility functions to parse /proc/interrupts and extract the host IRQ number for a given VFIO device and MSI vector. These helpers lay the groundwork for subsequent patches that will use real VFIO devices to trigger hardware interrupts. Specifically, they are needed to allow the test to log the exact IRQ number being used for better debugging. Suggested-by: Sean Christopherson Co-developed-by: Josh Hilke Signed-off-by: Josh Hilke Signed-off-by: David Matlack --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/include/proc_util.h | 9 ++++ tools/testing/selftests/kvm/lib/proc_util.c | 42 +++++++++++++++++++ 3 files changed, 52 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 b3e223f45575..d944b81cad7d 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..7c465e8584e2 --- /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 + +int get_proc_vfio_irq_number(const char *vfio_device_bdf, int msi); + +#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..ad1c54a81869 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/proc_util.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "kvm_util.h" +#include "test_util.h" +#include "proc_util.h" + +#include + +static FILE *open_proc_interrupts(void) +{ + FILE *fp; + + fp = fopen("/proc/interrupts", "r"); + TEST_ASSERT(fp, "fopen(/proc/interrupts) failed"); + + return fp; +} + +int get_proc_vfio_irq_number(const char *device_bdf, int msi) +{ + 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]", msi); + + 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 irq; +} + -- 2.54.0.rc2.533.g4f5dca5207-goog