ksysfs: Expose hardware name
Subsystems (3)
PATCH 1/1 ksysfs: Expose hardware name
Userspace tools often require a short, descriptive name of the hardware platform. Currently, this information is fragmented: Device Tree-based platforms typically use /proc/device-tree/model, while x86 platforms combine multiple values from /sys/class/dmi/id/. There is no uniform, platform-agnostic way to retrieve this string.
The kernel already maintains dump_stack_arch_desc_str[], which contains the model name or DMI values used for the "Hardware name:" field in stack traces.
Expose dump_stack_arch_desc_str[] at /sys/kernel/hardware_name to provide userspace with a consistent interface for identifying the underlying hardware.
--- .../ABI/testing/sysfs-kernel-hardware_name | 8 ++++++++ include/linux/printk.h | 1 + kernel/ksysfs.c | 13 +++++++++++++ lib/dump_stack.c | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-hardware_name
Documentation/ABI/testing/sysfs-kernel-hardware_name new file +8 -0
@@ -0,0 +1,8 @@ +What: /sys/kernel/hardware_name +Date: Feb 2026 +KernelVersion: 7.1 +Contact: Richard Weinberger <[email protected]> +Description: + The hardware name as shown in stack traces. + + Access: Read
include/linux/printk.h +1 -0
@@ -13,6 +13,7 @@ struct console;extern const char linux_banner[];extern const char linux_proc_banner[]; +extern char dump_stack_arch_desc_str[128 ];extern int oops_in_progress;/* If set, an oops, panic(), BUG() or die() is in progress */
kernel/ksysfs.c +13 -0
@@ -176,6 +176,16 @@ static ssize_t rcu_normal_store(struct kobject *kobj,KERNEL_ATTR_RW (rcu_normal);#endif /* #ifndef CONFIG_TINY_RCU */ +#ifdef CONFIG_PRINTK +/* hardware name */ +static ssize_t hardware_name_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" , dump_stack_arch_desc_str); +} +KERNEL_ATTR_RO (hardware_name); +#endif +/* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */
@@ -205,6 +215,9 @@ static struct attribute * kernel_attrs[] = {#ifndef CONFIG_TINY_RCU &rcu_expedited_attr.attr, &rcu_normal_attr.attr, +#endif +#ifdef CONFIG_PRINTK + &hardware_name_attr.attr, #endifNULL };
lib/dump_stack.c +1 -1
@@ -15,7 +15,7 @@#include <linux/utsname.h> #include <linux/stop_machine.h> -static char dump_stack_arch_desc_str[128 ]; +char dump_stack_arch_desc_str[128 ];/** * dump_stack_set_arch_desc - set arch-specific str to show with task dumps
Signature · 1 line
2.51.0
Greg KH
maintainerQuoted 6 lines · Richard Weinberger
Userspace tools often require a short, descriptive name of the hardware platform. Currently, this information is fragmented: Device Tree-based platforms typically use
/proc/device-tree/model, while x86 platforms combine multiple values from/sys/class/dmi/id/. There is no uniform, platform-agnostic way to retrieve this string.
Quoted 7 lines
The kernel already maintains dump_stack_arch_desc_str[], which contains the model name or DMI values used for the "Hardware name:" field in stack traces.
Expose dump_stack_arch_desc_str[] at
/sys/kernel/hardware_nameto provide userspace with a consistent interface for identifying the underlying hardware.
No objection from me, but now that this is a global symbol in the kernel, "dump_" seems like an odd prefix for this. How about "linux_hardware_name" to match up with the sysfs file name?
</bikeshed>
thanks,
greg k-h
----- Ursprüngliche Mail -----
Quoted 19 lines
Von: "Greg Kroah-Hartman" <[email protected]>
An: "richard" <[email protected]>
CC: "linux-kernel" <[email protected]>, "bhe" <[email protected]>, [email protected], "Andrew Morton" <[email protected]>, "senozhatsky" <[email protected]>, "John Ogness" <[email protected]>, "Steven Rostedt" <[email protected]>, "Petr Mladek" <[email protected]>, [email protected]
Gesendet: Montag, 23. Februar 2026 14:49:31
Betreff: Re: [PATCH] ksysfs: Expose hardware nameQuoted 10 lines · Richard Weinberger
Userspace tools often require a short, descriptive name of the hardware platform. Currently, this information is fragmented: Device Tree-based platforms typically use
/proc/device-tree/model, while x86 platforms combine multiple values from/sys/class/dmi/id/. There is no uniform, platform-agnostic way to retrieve this string.The kernel already maintains dump_stack_arch_desc_str[], which contains the model name or DMI values used for the "Hardware name:" field in stack traces.
Quoted 7 lines
Quoted 3 lines
Expose dump_stack_arch_desc_str[] at
/sys/kernel/hardware_nameto provide userspace with a consistent interface for identifying the underlying hardware.No objection from me, but now that this is a global symbol in the kernel, "
dump_" seems like an odd prefix for this. How about "linux_hardware_name" to match up with the sysfs file name?
I don't care much. The reason why I kept the variable as-is is because the function to set it is dump_stack_set_arch_desc().
So the prefix makes kinda sense.
Thanks,
//richard
John Ogness
maintainerHi Richard,
Quoted 30 lines · Richard Weinberger
Userspace tools often require a short, descriptive name of the hardware platform. Currently, this information is fragmented: Device Tree-based platforms typically use
/proc/device-tree/model, while x86 platforms combine multiple values from/sys/class/dmi/id/. There is no uniform, platform-agnostic way to retrieve this string.The kernel already maintains dump_stack_arch_desc_str[], which contains the model name or DMI values used for the "Hardware name:" field in stack traces.
Expose dump_stack_arch_desc_str[] at
/sys/kernel/hardware_nameto provide userspace with a consistent interface for identifying the underlying hardware.Signed-off-by Richard Weinberger <[email protected]>--- .../ABI/testing/sysfs-kernel-hardware_name | 8 ++++++++ include/linux/printk.h | 1 + kernel/ksysfs.c | 13 +++++++++++++ lib/dump_stack.c | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-hardware_namekernel/ksysfs.c +0
-0@@ -176,6 +176,16 @@ static ssize_t rcu_normal_store(struct kobject *kobj,KERNEL_ATTR_RW (rcu_normal);#endif /* #ifndef CONFIG_TINY_RCU */
kernel/ksysfs.c static ssize_t rcu_normal_store(struct kobject *kobj, · line 187
Quoted 10 lines
kernel/ksysfs.c +9
-0+#ifdef CONFIG_PRINTK +/* hardware name */ +static ssize_t hardware_name_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" , dump_stack_arch_desc_str); +} +KERNEL_ATTR_RO (hardware_name); +#endif
It seems a bit odd to make this a dependency of CONFIG_PRINTK. Perhaps @dump_stack_arch_desc_str and dump_stack_set_arch_desc() should move out of lib/dump_stack.c if this new sysfs attribute is accepted?
John Ogness
----- Ursprüngliche Mail -----
Quoted 6 lines
Von: "John Ogness" <[email protected]>
An: "richard" <[email protected]>, "linux-kernel" <[email protected]>It seems a bit odd to make this a dependency of
CONFIG_PRINTK. Perhaps @dump_stack_arch_desc_str anddump_stack_set_arch_desc()should move out oflib/dump_stack.cif this new sysfs attribute is accepted?
Sure. I was surprised too that lib/dump_stack.c depends on CONFIG_PRINTK.
Thanks,
//richard
Steven Rostedt
reviewerQuoted 10 lines · On Mon, 23 Feb 2026 15:20:22 +0100 (CET) Richard Weinberger <[email protected]>…
----- Ursprüngliche Mail -----
Quoted 6 lines
Von: "John Ogness" <[email protected]>
An: "richard" <[email protected]>, "linux-kernel" <[email protected]>It seems a bit odd to make this a dependency of
CONFIG_PRINTK. Perhaps @dump_stack_arch_desc_str anddump_stack_set_arch_desc()should move out oflib/dump_stack.cif this new sysfs attribute is accepted?Sure. I was surprised too that
lib/dump_stack.cdepends onCONFIG_PRINTK.
Or possibly we should make dump_stack.c not depend on CONFIG_PRINTK. I'm guessing that it was done that way because it expects to dump the stack to the console?
(haven't looked at the code yet)
-- Steve
Petr Mladek
maintainerQuoted 11 lines · Steven Rostedt
Quoted 8 lines · On Mon, 23 Feb 2026 15:20:22 +0100 (CET) Richard Weinberger <[email protected]>…
----- Ursprüngliche Mail -----
Quoted 6 lines
Von: "John Ogness" <[email protected]>
An: "richard" <[email protected]>, "linux-kernel" <[email protected]>It seems a bit odd to make this a dependency of
CONFIG_PRINTK. Perhaps @dump_stack_arch_desc_str anddump_stack_set_arch_desc()should move out oflib/dump_stack.cif this new sysfs attribute is accepted?
Quoted 6 lines
Quoted 2 lines
Sure. I was surprised too that
lib/dump_stack.cdepends onCONFIG_PRINTK.Or possibly we should make
dump_stack.cnot depend onCONFIG_PRINTK. I'm guessing that it was done that way because it expects to dump the stack to the console?
My guess is that dump_stack.c depends on CONFIG_PRINTK because the stack is stored using printk(). Nothing is stored when printk() is a NOP ;-)
A clean solution would be to move dump_stack_arch_desc_str and dump_stack_set_arch_desc() somewhere else (ksysfs.c ?) and rename them to hardware_name and set_hardware_name().
Best Regards,
Petr