From: Alan Maguire <alan.maguire@oracle.com>
To: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
eddyz87@gmail.com
Cc: jolsa@kernel.org, ihor.solodrai@linux.dev,
yonghong.song@linux.dev, song@kernel.org, qmo@kernel.org,
martin.lau@linux.dev, memxor@gmail.com, emil@etsalapatis.com,
mcgrof@kernel.org, petr.pavlu@suse.com, tj@kernel.org,
kees@kernel.org, nathan@kernel.org, arnd@arndb.de,
puranjay@kernel.org, yatsenko@meta.com, atenart@kernel.org,
ojeda@kernel.org, linux-modules@vger.kernel.org,
arnaldo.melo@gmail.com, bpf@vger.kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH v3 bpf-next 6/7] selftests/bpf: Test BTF sysfs inline representations
Date: Sat, 3 Oct 2026 20:43:22 +0100 [thread overview]
Message-ID: <20261003194323.817885-7-alan.maguire@oracle.com> (raw)
In-Reply-To: <20261003194323.817885-1-alan.maguire@oracle.com>
Load vmlinux, vmlinux.inline and all module and module.inline
entries in /sys/fs/btf; this will allow us to sanity-check
- kernel and its inline representations
- in-tree modules and their inline multi-split BTF representations
- out-of-tree modules and the kernel relocation done for
module and module inline BTF
Since bpf_testmod.ko is built as an out-of-tree module, the
combination of vmlinux, normal in-tree module BTF and out-of-tree
testmod ensures we sanity check relocations for each case.
Also test mmap for vmlinux.inline.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
.../selftests/bpf/prog_tests/btf_sysfs.c | 76 +++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
index 3923e64c4c1d..069c4483b3a2 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
@@ -3,11 +3,16 @@
#include <test_progs.h>
#include <bpf/btf.h>
+#include <dirent.h>
+#include <limits.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
+#define BTF_SYSFS_DIR "/sys/kernel/btf"
+#define BTF_INLINE_SUFFIX ".inline"
+
static void test_btf_mmap_sysfs(const char *path, struct btf *base)
{
struct stat st;
@@ -75,7 +80,78 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
close(fd);
}
+static void test_btf_inline_sysfs_all(void)
+{
+ struct btf *vmlinux_btf;
+ struct dirent *dentry;
+ DIR *dir;
+ int err = 0;
+
+ dir = opendir(BTF_SYSFS_DIR);
+ if (!ASSERT_OK_PTR(dir, "open_btf_sysfs"))
+ return;
+
+ vmlinux_btf = btf__parse(BTF_SYSFS_DIR "/vmlinux", NULL);
+ if (!ASSERT_OK_PTR(vmlinux_btf, "parse_vmlinux_btf")) {
+ closedir(dir);
+ return;
+ }
+
+ while ((dentry = readdir(dir)) != NULL) {
+ struct btf *base_btf = NULL, *module_btf = NULL, *inline_btf = NULL;
+ char btf_path[PATH_MAX], inline_path[PATH_MAX];
+ struct stat st;
+
+ /* Skip ".", ".." and "foo.inline" */
+ if (strstr(dentry->d_name, "."))
+ continue;
+
+ if (strcmp(dentry->d_name, "vmlinux") == 0)
+ base_btf = vmlinux_btf;
+
+ if (snprintf(btf_path, sizeof(btf_path), "%s/%s",
+ BTF_SYSFS_DIR, dentry->d_name) >= sizeof(btf_path) ||
+ snprintf(inline_path, sizeof(inline_path), "%s/%s%s",
+ BTF_SYSFS_DIR, dentry->d_name, BTF_INLINE_SUFFIX) >=
+ sizeof(inline_path)) {
+ ASSERT_FAIL("BTF sysfs path is too long\n");
+ break;
+ }
+
+ if (!base_btf) {
+ module_btf = btf__parse_split(btf_path, vmlinux_btf);
+ err = libbpf_get_error(module_btf);
+ if (err) {
+ /* A module can be unloaded while its sysfs entry is iterated. */
+ if (err == -ENOENT)
+ continue;
+ ASSERT_OK(err, "parse_module_btf");
+ continue;
+ }
+ base_btf = module_btf;
+ }
+ if (stat(inline_path, &st)) {
+ err = errno;
+ if (err == ENOENT)
+ continue;
+ ASSERT_OK(err, "stat_inline_btf");
+ }
+ if (base_btf == vmlinux_btf)
+ test_btf_mmap_sysfs(inline_path, base_btf);
+ inline_btf = btf__parse_split(inline_path, base_btf);
+ err = libbpf_get_error(inline_btf);
+ if (!err)
+ btf__free(inline_btf);
+ ASSERT_OK(err, "parse_inline_btf");
+ btf__free(module_btf);
+ }
+ closedir(dir);
+
+ btf__free(vmlinux_btf);
+}
+
void test_btf_sysfs(void)
{
test_btf_mmap_sysfs("/sys/kernel/btf/vmlinux", NULL);
+ test_btf_inline_sysfs_all();
}
--
2.43.5
next prev parent reply other threads:[~2026-10-03 19:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 19:43 [PATCH v3 bpf-next 0/7] kbuild, bpf: Support inline info in BTF Alan Maguire
2026-10-03 19:43 ` [PATCH v3 bpf-next 1/7] resolve_btfids: Build separate main and inline BTF objects Alan Maguire
2026-10-03 20:27 ` bot+bpf-ci
2026-10-06 17:30 ` Alan Maguire
2026-10-03 19:43 ` [PATCH v3 bpf-next 2/7] resolve_btfids: Populate BTF link section Alan Maguire
2026-10-03 20:27 ` bot+bpf-ci
2026-10-03 19:43 ` [PATCH v3 bpf-next 3/7] kbuild, btf: Expose vmlinux inline BTF through sysfs Alan Maguire
2026-10-03 19:56 ` sashiko-bot
2026-10-06 18:12 ` Alan Maguire
2026-10-03 20:41 ` bot+bpf-ci
2026-10-06 18:42 ` Alan Maguire
2026-10-03 19:43 ` [PATCH v3 bpf-next 4/7] btf: Preserve string relocation maps for split BTF Alan Maguire
2026-10-03 19:43 ` [PATCH v3 bpf-next 5/7] btf: Relocate and expose module inline BTF Alan Maguire
2026-10-03 19:59 ` sashiko-bot
2026-10-06 18:56 ` Alan Maguire
2026-10-03 20:27 ` bot+bpf-ci
2026-10-03 19:43 ` Alan Maguire [this message]
2026-10-03 19:54 ` [PATCH v3 bpf-next 6/7] selftests/bpf: Test BTF sysfs inline representations sashiko-bot
2026-10-03 19:43 ` [PATCH v3 bpf-next 7/7] selftests/bpf: Add a test verifying inline information Alan Maguire
2026-10-03 19:54 ` sashiko-bot
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=20261003194323.817885-7-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=atenart@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mcgrof@kernel.org \
--cc=memxor@gmail.com \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=puranjay@kernel.org \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=yatsenko@meta.com \
--cc=yonghong.song@linux.dev \
/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