From: David Matlack <dmatlack@google.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, stable@vger.kernel.org
Cc: Abhishek Sahu <abhsahu@nvidia.com>,
Alex Williamson <alex@shazbot.org>,
David Matlack <dmatlack@google.com>,
Raghavendra Rao Ananta <rananta@google.com>,
Shuah Khan <shuah@kernel.org>
Subject: [PATCH 4/5] vfio: selftests: Add sysfs_kernel_warn_count_get()
Date: Thu, 29 Oct 2026 20:33:23 +0000 [thread overview]
Message-ID: <20261029203324.1637772-5-dmatlack@google.com> (raw)
In-Reply-To: <20261029203324.1637772-1-dmatlack@google.com>
Add a helper to read /sys/kernel/warn_count, which counts the number of
warnings (e.g. WARN(), KASAN, and UBSAN reports) the kernel has
encountered since boot. Return a negative value if the file does not
exist, e.g. on kernels that predate it.
Factor the code to read an integer from a sysfs file out of
sysfs_val_get_int() so that it can be shared by both helpers.
This will be used in a subsequent commit to detect kernel warnings
triggered by tests.
Signed-off-by: David Matlack <dmatlack@google.com>
---
.../vfio/lib/include/libvfio/sysfs.h | 7 +++++++
tools/testing/selftests/vfio/lib/sysfs.c | 19 +++++++++++++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h b/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h
index c9ab1ea8f5a9..1b9711d1bf90 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h
@@ -9,4 +9,11 @@ char *sysfs_sriov_vf_bdf_get(const char *pf_bdf, int i);
int sysfs_iommu_group_get(const char *bdf);
char *sysfs_driver_get(const char *bdf);
+/*
+ * Return the number of warnings the kernel has encountered since boot (e.g.
+ * WARN(), KASAN, and UBSAN reports), or a negative value if the kernel does
+ * not support /sys/kernel/warn_count.
+ */
+int sysfs_kernel_warn_count_get(void);
+
#endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_SYSFS_H */
diff --git a/tools/testing/selftests/vfio/lib/sysfs.c b/tools/testing/selftests/vfio/lib/sysfs.c
index d88e348a1e0d..71470196f092 100644
--- a/tools/testing/selftests/vfio/lib/sysfs.c
+++ b/tools/testing/selftests/vfio/lib/sysfs.c
@@ -33,15 +33,12 @@ static void readlink_base(const char *path, const char *data_fmt, void *out_data
VFIO_ASSERT_EQ(ret, 1);
}
-static int sysfs_val_get_int(const char *component, const char *name,
- const char *file)
+static int sysfs_path_get_int(const char *path)
{
- char path[PATH_MAX];
char buf[32];
int ret;
int fd;
- snprintf_assert(path, PATH_MAX, "/sys/bus/pci/%s/%s/%s", component, name, file);
fd = open(path, O_RDONLY);
if (fd < 0)
return fd;
@@ -56,6 +53,15 @@ static int sysfs_val_get_int(const char *component, const char *name,
return ret;
}
+static int sysfs_val_get_int(const char *component, const char *name,
+ const char *file)
+{
+ char path[PATH_MAX];
+
+ snprintf_assert(path, PATH_MAX, "/sys/bus/pci/%s/%s/%s", component, name, file);
+ return sysfs_path_get_int(path);
+}
+
static void sysfs_val_set(const char *component, const char *name,
const char *file, const char *val)
{
@@ -148,3 +154,8 @@ char *sysfs_driver_get(const char *bdf)
return out_driver;
}
+
+int sysfs_kernel_warn_count_get(void)
+{
+ return sysfs_path_get_int("/sys/kernel/warn_count");
+}
--
2.56.0.317.g454f8302e1-goog
next prev parent reply other threads:[~2026-10-29 20:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 20:33 [PATCH 0/5] vfio/pci: Fix power state race with SR-IOV enablement David Matlack
2026-10-29 20:33 ` [PATCH 1/5] vfio/pci: Hold memory_lock for all calls to vfio_pci_set_power_state() David Matlack
2026-10-29 20:33 ` [PATCH 2/5] vfio/pci: Annotate lockless accesses to vdev->sriov_active David Matlack
2026-10-29 20:33 ` [PATCH 3/5] vfio: selftests: Add vfio_pci_find_capability() David Matlack
2026-10-29 20:33 ` David Matlack [this message]
2026-10-29 20:33 ` [PATCH 5/5] vfio: selftests: Add test for device power state transitions David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261029203324.1637772-5-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=abhsahu@nvidia.com \
--cc=alex@shazbot.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rananta@google.com \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®