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.

Signed-off-by: Richard Weinberger <richard@nod.at>
diff --git a/Documentation/ABI/testing/sysfs-kernel-hardware_name b/Documentation/ABI/testing/sysfs-kernel-hardware_name
new file mode 100644
index 0000000..21d130d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-hardware_name
@@ -0,0 +1,8 @@
+What:		/sys/kernel/hardware_name
+Date:		Feb 2026
+KernelVersion:	7.1
+Contact:	Richard Weinberger <richard@nod.at>
+Description:
+		The hardware name as shown in stack traces.
+
+		Access: Read
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 63d516c..b892949 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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 */
 
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index a9e6354..af72657 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -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.
  */
@@ -206,6 +216,9 @@ static struct attribute * kernel_attrs[] = {
 	&rcu_expedited_attr.attr,
 	&rcu_normal_attr.attr,
 #endif
+#ifdef CONFIG_PRINTK
+	&hardware_name_attr.attr,
+#endif
 	NULL
 };
 
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index f0c78b5..bce41e6 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -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