Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kernels/ksysfs.c: export kernel address bits

This can be used by userspace to determine the address size of the
running kernel.
It frees userspace from having to interpret this information from the
UTS machine field.

Userspace implementation:
https://github.com/util-linux/util-linux/pull/1966

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20221221-address-bits-v1-1-8446b13244ac@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
00142bfd e5da06b2

+19
+10
Documentation/ABI/testing/sysfs-kernel-address_bits
··· 1 + What: /sys/kernel/address_bit 2 + Date: May 2023 3 + KernelVersion: 6.3 4 + Contact: Thomas Weißschuh <linux@weissschuh.net> 5 + Description: 6 + The address size of the running kernel in bits. 7 + 8 + Access: Read 9 + 10 + Users: util-linux
+9
kernel/ksysfs.c
··· 51 51 } 52 52 KERNEL_ATTR_RO(cpu_byteorder); 53 53 54 + /* address bits */ 55 + static ssize_t address_bits_show(struct kobject *kobj, 56 + struct kobj_attribute *attr, char *buf) 57 + { 58 + return sysfs_emit(buf, "%zu\n", sizeof(void *) * 8 /* CHAR_BIT */); 59 + } 60 + KERNEL_ATTR_RO(address_bits); 61 + 54 62 #ifdef CONFIG_UEVENT_HELPER 55 63 /* uevent helper program, used during early boot */ 56 64 static ssize_t uevent_helper_show(struct kobject *kobj, ··· 241 233 &fscaps_attr.attr, 242 234 &uevent_seqnum_attr.attr, 243 235 &cpu_byteorder_attr.attr, 236 + &address_bits_attr.attr, 244 237 #ifdef CONFIG_UEVENT_HELPER 245 238 &uevent_helper_attr.attr, 246 239 #endif