The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Carlos O'Donell" <carlos@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Florian Weimer" <fweimer@redhat.com>,
	"Rich Felker" <dalias@aerifal.cx>,
	"Torvald Riegel" <triegel@redhat.com>,
	"Darren Hart" <dvhart@infradead.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	"Uros Bizjak" <ubizjak@gmail.com>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Mark Brown" <broonie@kernel.org>,
	"Richard Weinberger" <richard@nod.at>
Subject: [patch V5 16/16] [RFC] vdso, x86: Expose vdso.so.dbg through sysfs
Date: Tue, 02 Jun 2026 11:10:25 +0200	[thread overview]
Message-ID: <20260602090536.045586688@kernel.org> (raw)
In-Reply-To: 20260602084648.462672743@kernel.org

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@linutronix.de>
---
 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;
+}


  parent reply	other threads:[~2026-06-02  9:10 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02  9:09 [patch V5 00/16] futex: Address the robust futex unlock race for real Thomas Gleixner
2026-06-02  9:09 ` [patch V5 01/16] percpu: Sanitize __percpu_qual include hell Thomas Gleixner
2026-06-03 14:25   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 02/16] futex: Move futex task related data into a struct Thomas Gleixner
2026-06-03 14:25   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 03/16] futex: Make futex_mm_init() void Thomas Gleixner
2026-06-03 14:25   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 04/16] futex: Move futex related mm_struct data into a struct Thomas Gleixner
2026-06-03 14:25   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 05/16] futex: Provide UABI defines for robust list entry modifiers Thomas Gleixner
2026-06-03 14:25   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 06/16] uaccess: Provide unsafe_atomic_store_release_user() Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 07/16] x86: Select ARCH_MEMORY_ORDER_TSO Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 08/16] futex: Cleanup UAPI defines Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 09/16] futex: Add support for unlocking robust futexes Thomas Gleixner
2026-06-03  8:22   ` Peter Zijlstra
2026-06-03  9:30     ` Peter Zijlstra
2026-06-03 14:40     ` Thomas Gleixner
2026-06-03  8:35   ` Peter Zijlstra
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:09 ` [patch V5 10/16] futex: Add robust futex unlock IP range Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:10 ` [patch V5 11/16] futex: Provide infrastructure to plug the non contended robust futex unlock race Thomas Gleixner
2026-06-03  8:42   ` Peter Zijlstra
2026-06-03  9:14   ` Peter Zijlstra
2026-06-03 14:47     ` Thomas Gleixner
2026-06-03  9:23   ` Peter Zijlstra
2026-06-03 14:42     ` Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:10 ` [patch V5 12/16] x86/vdso: Prepare for robust futex unlock support Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:10 ` [patch V5 13/16] x86/vdso: Implement __vdso_futex_robust_try_unlock() Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2026-06-02  9:10 ` [patch V5 14/16] Documentation: futex: Add a note about robust list race condition Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for André Almeida
2026-06-02  9:10 ` [patch V5 15/16] selftests: futex: Add tests for robust release operations Thomas Gleixner
2026-06-03 14:24   ` [tip: locking/core] " tip-bot2 for André Almeida
2026-06-02  9:10 ` Thomas Gleixner [this message]
2026-06-02 10:39   ` [patch V5 16/16] [RFC] vdso, x86: Expose vdso.so.dbg through sysfs Thomas Weißschuh
2026-06-02 20:02     ` Thomas Gleixner

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=20260602090536.045586688@kernel.org \
    --to=tglx@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=andrealmeid@igalia.com \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=broonie@kernel.org \
    --cc=carlos@redhat.com \
    --cc=dalias@aerifal.cx \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=fweimer@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=richard@nod.at \
    --cc=triegel@redhat.com \
    --cc=ubizjak@gmail.com \
    /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