[patch V5 16/16] [RFC] vdso, x86: Expose vdso.so.dbg through sysfs

From: Thomas Gleixner

Date: Tue Jun 02 2026 - 05:28:47 EST


Finding the debug version of the VDSO is not trivial as there is no common
scheme where it is placed. That's especially problematic for CI testing.

The VDSO futex unlock mechanism requires for testing to have access to the
inner labels of the unlock assembly, which are only accessible via the
debug so.

Also for general debugging purposes it's conveniant to have access to the
debug VDSO at a well defined place.

The files are placed in /sys/kernel/vdso/ and named vdso32.so.dbg,
vdso64.so.dbg, vdsox32.so.dbg.

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
arch/x86/Kconfig | 1 +
arch/x86/include/asm/vdso.h | 3 +++
arch/x86/tools/vdso2c.c | 15 ++++++++++-----
arch/x86/tools/vdso2c.h | 32 ++++++++++++++++++++++++++++++--
include/vdso/sysfs.h | 7 +++++++
lib/vdso/Kconfig | 6 ++++++
lib/vdso/Makefile | 3 ++-
lib/vdso/sysfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 103 insertions(+), 8 deletions(-)

--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -306,6 +306,7 @@ config X86
select HAVE_UNWIND_USER_FP if X86_64
select HAVE_USER_RETURN_NOTIFIER
select HAVE_GENERIC_VDSO
+ select HAVE_VDSO_DEBUG_SYSFS
select VDSO_GETRANDOM if X86_64
select HOTPLUG_PARALLEL if SMP && X86_64
select HOTPLUG_SMT if SMP
--- a/arch/x86/include/asm/vdso.h
+++ b/arch/x86/include/asm/vdso.h
@@ -14,6 +14,9 @@ struct vdso_image {
void *data;
unsigned long size; /* Always a multiple of PAGE_SIZE */

+ void *dbg_data;
+ unsigned long dbg_size; /* Always a multiple of PAGE_SIZE */
+
unsigned long alt, alt_len;
unsigned long extable_base, extable_len;
const void *extable;
--- a/arch/x86/tools/vdso2c.c
+++ b/arch/x86/tools/vdso2c.c
@@ -150,16 +150,16 @@ extern void bad_put_le(void);

static void go(void *raw_addr, size_t raw_len,
void *stripped_addr, size_t stripped_len,
- FILE *outfile, const char *name)
+ FILE *outfile, const char *name, const char *dbg_name)
{
Elf64_Ehdr *hdr = (Elf64_Ehdr *)raw_addr;

if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
go64(raw_addr, raw_len, stripped_addr, stripped_len,
- outfile, name);
+ outfile, name, dbg_name);
} else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
go32(raw_addr, raw_len, stripped_addr, stripped_len,
- outfile, name);
+ outfile, name, dbg_name);
} else {
fail("unknown ELF class\n");
}
@@ -189,8 +189,8 @@ int main(int argc, char **argv)
{
size_t raw_len, stripped_len;
void *raw_addr, *stripped_addr;
+ char *name, *tmp, *dbg_name;
FILE *outfile;
- char *name, *tmp;
int namelen;

if (argc != 4) {
@@ -226,7 +226,12 @@ int main(int argc, char **argv)
if (!outfile)
err(1, "fopen(%s)", outfilename);

- go(raw_addr, raw_len, stripped_addr, stripped_len, outfile, name);
+ dbg_name = strdup(argv[1]);
+ tmp = strrchr(dbg_name, '/');
+ if (tmp)
+ dbg_name = tmp + 1;
+
+ go(raw_addr, raw_len, stripped_addr, stripped_len, outfile, name, dbg_name);

munmap(raw_addr, raw_len);
munmap(stripped_addr, stripped_len);
--- a/arch/x86/tools/vdso2c.h
+++ b/arch/x86/tools/vdso2c.h
@@ -42,11 +42,12 @@ static void BITSFUNC(extract)(const unsi

static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
void *stripped_addr, size_t stripped_len,
- FILE *outfile, const char *image_name)
+ FILE *outfile, const char *image_name,
+ const char *dbg_name)
{
int found_load = 0;
unsigned long load_size = -1; /* Work around bogus warning */
- unsigned long mapping_size;
+ unsigned long mapping_size, dbg_size;
ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
unsigned long i, syms_nr;
ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
@@ -160,6 +161,7 @@ static void BITSFUNC(go)(void *raw_addr,
fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
fprintf(outfile, "#include <linux/linkage.h>\n");
fprintf(outfile, "#include <linux/init.h>\n");
+ fprintf(outfile, "#include <vdso/sysfs.h>\n");
fprintf(outfile, "#include <asm/page_types.h>\n");
fprintf(outfile, "#include <asm/vdso.h>\n");
fprintf(outfile, "\n");
@@ -173,6 +175,21 @@ static void BITSFUNC(go)(void *raw_addr,
(int)((unsigned char *)stripped_addr)[i]);
}
fprintf(outfile, "\n};\n\n");
+
+ dbg_size = (raw_len + 4095) / 4096 * 4096;
+
+ fprintf(outfile, "#ifdef CONFIG_VDSO_DEBUG_SYSFS\n");
+ fprintf(outfile,
+ "static unsigned char dbg_data[%lu] __ro_after_init __aligned(PAGE_SIZE) = {",
+ dbg_size);
+ for (i = 0; i < raw_len; i++) {
+ if (i % 10 == 0)
+ fprintf(outfile, "\n\t");
+ fprintf(outfile, "0x%02X, ", (int)((unsigned char *)raw_addr)[i]);
+ }
+ fprintf(outfile, "\n};\n");
+ fprintf(outfile, "#endif\n\n");
+
if (extable_sec)
BITSFUNC(extract)(raw_addr, raw_len, outfile,
extable_sec, "extable");
@@ -180,6 +197,10 @@ static void BITSFUNC(go)(void *raw_addr,
fprintf(outfile, "const struct vdso_image %s = {\n", image_name);
fprintf(outfile, "\t.data = raw_data,\n");
fprintf(outfile, "\t.size = %lu,\n", mapping_size);
+ fprintf(outfile, "#ifdef CONFIG_VDSO_DEBUG_SYSFS\n");
+ fprintf(outfile, "\t.dbg_data = dbg_data,\n");
+ fprintf(outfile, "\t.dbg_size = %lu,\n", dbg_size);
+ fprintf(outfile, "#endif\n");
if (alt_sec) {
fprintf(outfile, "\t.alt = %lu,\n",
(unsigned long)GET_LE(&alt_sec->sh_offset));
@@ -205,4 +226,11 @@ static void BITSFUNC(go)(void *raw_addr,
fprintf(outfile, "};\n");
fprintf(outfile, "subsys_initcall(init_%s);\n", image_name);

+ fprintf(outfile, "\n#ifdef CONFIG_VDSO_DEBUG_SYSFS\n");
+ fprintf(outfile, "static __init int sysfs_init_%s(void) {\n", image_name);
+ fprintf(outfile, "\treturn vdso_sysfs_init_image(\"%s\", (void *)%s.dbg_data, %lu);\n",
+ dbg_name, image_name, raw_len);
+ fprintf(outfile, "};\n");
+ fprintf(outfile, "late_initcall(sysfs_init_%s);\n", image_name);
+ fprintf(outfile, "#endif\n");
}
--- /dev/null
+++ b/include/vdso/sysfs.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __VDSO_SYSFS_H
+#define __VDSO_SYSFS_H
+
+int vdso_sysfs_init_image(const char *name, void *addr, unsigned int size);
+
+#endif /* __VDSO_SYSFS_H */
--- a/lib/vdso/Kconfig
+++ b/lib/vdso/Kconfig
@@ -3,6 +3,9 @@
config HAVE_GENERIC_VDSO
bool

+config HAVE_VDSO_DEBUG_SYSFS
+ bool
+
if HAVE_GENERIC_VDSO

config GENERIC_GETTIMEOFDAY
@@ -24,4 +27,7 @@ config VDSO_GETRANDOM
help
Selected by architectures that support vDSO getrandom().

+config VDSO_DEBUG_SYSFS
+ def_bool y if SYSFS && HAVE_VDSO_DEBUG_SYSFS
+
endif
--- a/lib/vdso/Makefile
+++ b/lib/vdso/Makefile
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only

-obj-$(CONFIG_HAVE_GENERIC_VDSO) += datastore.o
+obj-$(CONFIG_HAVE_GENERIC_VDSO) += datastore.o
+obj-$(CONFIG_VDSO_DEBUG_SYSFS) += sysfs.o
--- /dev/null
+++ b/lib/vdso/sysfs.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/kobject.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+#include <vdso/sysfs.h>
+
+static struct kobject *vdso_kobj __ro_after_init;
+static DEFINE_MUTEX(sysfs_mutex);
+
+int __init vdso_sysfs_init_image(const char *name, void *addr, unsigned int size)
+{
+ struct bin_attribute *attr = NULL;
+ int ret = -ENOMEM;
+
+ guard(mutex)(&sysfs_mutex);
+ if (!vdso_kobj) {
+ vdso_kobj = kobject_create_and_add("vdso", kernel_kobj);
+ if (!vdso_kobj)
+ return -ENOMEM;
+ }
+
+ attr = kzalloc_obj(*attr);
+ if (!attr)
+ goto out;
+
+ sysfs_bin_attr_init(attr);
+ attr->attr.name = name;
+ attr->attr.mode = 0444;
+ attr->private = addr;
+ attr->size = size;
+ attr->read = sysfs_bin_attr_simple_read;
+
+ ret = sysfs_create_bin_file(vdso_kobj, attr);
+ if (ret) {
+ pr_warn("Failed to register %s in sysfs: %d\n", name, ret);
+ goto out;
+ }
+ return 0;
+out:
+ kobject_put(vdso_kobj);
+ kfree(attr);
+ return ret;
+}