[PATCH bpf-next v3 6/9] tools: Copy KALLSYMS_QUERY_* definitions to linux/fs.h
From: Samuel Wu
Date: Fri Nov 13 2026 - 17:15:31 EST
Copy the KALLSYMS_QUERY_* definitions from include/uapi/linux/fs.h for
the proc selftests.
Signed-off-by: Samuel Wu <wusamuel@xxxxxxxxxx>
---
tools/include/uapi/linux/fs.h | 56 +++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h
index f0a26309b6d5..286e82c61189 100644
--- a/tools/include/uapi/linux/fs.h
+++ b/tools/include/uapi/linux/fs.h
@@ -567,4 +567,60 @@ struct procmap_query {
__u64 build_id_addr; /* in */
};
+/* /proc/kallsyms ioctls. -EPERM if the opener cannot see kernel addresses. */
+#define KALLSYMS_QUERY_BY_NAME _IOC(_IOC_READ | _IOC_WRITE, PROCFS_IOCTL_MAGIC, 48, 0)
+#define KALLSYMS_QUERY_BY_ADDR _IOC(_IOC_READ | _IOC_WRITE, PROCFS_IOCTL_MAGIC, 49, 0)
+
+enum kallsyms_query_flags {
+ /* Match query_name as a prefix. */
+ KALLSYMS_QUERY_NAME_PREFIX = 0x01,
+};
+
+/*
+ * Symbol returned by a query. Each buffer pointer and its *_len must both be
+ * set or both be 0. When set, the kernel sets *_len to the string size
+ * including the NUL, even if the buffer is too small and the ioctl fails with
+ * -ENAMETOOLONG. The module name of a vmlinux symbol is "".
+ */
+struct kallsyms_query_sym {
+ __u64 sym_addr; /* out - start address */
+ __u64 sym_size; /* out - bytes to next symbol, 0 if unknown */
+ __u64 sym_name; /* in - user ptr to name buffer, or 0 */
+ __u64 sym_name_len; /* in/out - buffer size / string size */
+ __u64 sym_module; /* in - user ptr to module name buffer, or 0 */
+ __u64 sym_module_len; /* in/out - buffer size / string size */
+};
+
+/*
+ * Find a symbol by exact name, or by prefix with KALLSYMS_QUERY_NAME_PREFIX,
+ * in the entries of /proc/kallsyms, except undefined module symbols. vmlinux
+ * matches come first. A module_filter of "vmlinux" selects the core kernel.
+ *
+ * Each call returns one match and sets pos to its position, even on
+ * -ENAMETOOLONG. Start with pos 0 and use pos + 1 for the next match, until
+ * -ENOENT. Use pos only with the same query. Matches can be skipped or
+ * repeated if symbols change between calls.
+ */
+struct kallsyms_query_by_name {
+ __u64 size; /* in - sizeof(struct kallsyms_query_by_name) */
+ __u64 query_flags; /* in - enum kallsyms_query_flags */
+ __u64 query_name; /* in - user ptr to name or prefix */
+ __u64 module_filter; /* in - user ptr to loaded module name, or 0 */
+ __u64 pos; /* in/out - start position / match position */
+ __u64 sym; /* in - user ptr to struct kallsyms_query_sym */
+ __u64 sym_struct_size; /* in - sizeof(struct kallsyms_query_sym) */
+};
+
+/*
+ * Find the /proc/kallsyms entry that covers query_addr, or return -ENOENT.
+ * ftrace trampolines and kprobe pages are not resolved yet.
+ */
+struct kallsyms_query_by_addr {
+ __u64 size; /* in - sizeof(struct kallsyms_query_by_addr) */
+ __u64 query_flags; /* in - must be 0 */
+ __u64 query_addr; /* in - kernel address */
+ __u64 sym; /* in - user ptr to struct kallsyms_query_sym */
+ __u64 sym_struct_size; /* in - sizeof(struct kallsyms_query_sym) */
+};
+
#endif /* _UAPI_LINUX_FS_H */
--
2.56.0.679.gc527c65306-goog