From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 738903CF663 for ; Tue, 2 Jun 2026 09:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780391429; cv=none; b=m+x1eejXSFL8MYpFZQN+uIo+FStAxz++fWhcV6dIEpxi47oqrodavK2eC2uw9uL8dJxGMQemM6PV51vqCkQTPtE7vEKtMBJ7VzA2vQM87cVpOfg3bbffAtvA92+oGzgzr5MeH5CS0QaXmW9t4sfx3CPxIfeFy/A9vDKXN8MYBHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780391429; c=relaxed/simple; bh=D9ldjjPrxe0lUeJc8xxBdxlD8n+NTqzl2l9VaBK2Pz0=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=IDO/wNy10dvgkUt+PA/8I38CBCgBzvJp/8UxDeym2it6FnHqM9WBM+GR1bEyl7MBKPZXzS13iLJ6f1TZWms0HG4YCGjCsXcpIKAt+6onbq+DTDQoW+6EZ5JD1UUAzbeAJ5EBcSVH3bGZZuX20G6req+1IWcpUP2iYLncUkAnuQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m1QlDY7R; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m1QlDY7R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8043F1F00893; Tue, 2 Jun 2026 09:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780391428; bh=h0Z5dnueiIaw9nR6EV1+jbDJD+OB8/07Qqxenh/vVYo=; h=Date:From:To:Cc:Subject:References; b=m1QlDY7RjDBCmk1jD+GCXp1SzShvxtx9N1jPElCLOifbXbt5/7lQLsxHZnJLipeSN mgH2OuD4ME1qkOn24JgOrComL7JXDCBtioGNtUOIZQhi9lBa87s1c2Vt6b4Ur45BsS kpemNq2tqCtPROEznJRIB87wHwCYcbO1MkgnbvCSvLkXGcNxRUMu0Vzhk6ANfcX9+D J++l6L/P/VgIP5Gz+krCPKGf5Rk6Pnl+hLsLn2rdERmI+DD3Bi7Fss6N87KnkBbFi7 JC2EObRMyosUoHcWqrjoY+61pug+8Q9PoRnZv9cixhgFIvXxIMTXrLR+D8/8jM2bxw FXa/88FLLT85g== Date: Tue, 02 Jun 2026 11:10:25 +0200 Message-ID: <20260602090536.045586688@kernel.org> User-Agent: quilt/0.69 From: Thomas Gleixner To: LKML Cc: Mathieu Desnoyers , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Mark Brown , Richard Weinberger Subject: [patch V5 16/16] [RFC] vdso, x86: Expose vdso.so.dbg through sysfs References: <20260602084648.462672743@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 --- 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 \n"); fprintf(outfile, "#include \n"); + fprintf(outfile, "#include \n"); fprintf(outfile, "#include \n"); fprintf(outfile, "#include \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 +#include +#include +#include +#include + +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; +}