Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5944250rwj; Wed, 21 Dec 2022 08:54:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXuWh6/41mmskGWzPL9aaLTEn6q+hYV+h1WKxma+jigBNy9xeHt03fkNm+JK2V4MDH8exuCv X-Received: by 2002:a05:6a20:7d89:b0:af:ae01:547a with SMTP id v9-20020a056a207d8900b000afae01547amr4427922pzj.20.1671641669078; Wed, 21 Dec 2022 08:54:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671641669; cv=none; d=google.com; s=arc-20160816; b=qzbVW5yrc2Fsq78vzB51/LDnMiqMCowtJ+AJY3YhbevbiDoJrzrHl1pHpf3TfBoCzs yPPlkzrcBliGzKmFmePMNhH6nnDUtV8lQEA9SoioAoAKalKVV0DSyu46Ra2gzQLE5Jua GCBmk/LHYjNhh82KOVB5jt5j0aV+zxXA5bsJf319fflsFf+YY+56OX6JZhyl3ZtyXVy6 q66rOR846KqdcFXG37UJTM8stridLFJBQRzDWYIAsPloerOhH7DMbUddhaZyyTUko2LR UoX7q6vD1pEg1vLp7Oa1GmqERshQfAxeIfIqcgcQN3X+S3M7tqNzm8wzYRHmCZMlZ76H wClw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:dkim-signature:from; bh=CVWFL5L3UZ0CLUrJTSiGkpgIY7xLi3SnX9alMl2s71g=; b=SEo+9KzkjM8COpnVnD8DdWpRdrNEF9p8MLuBGUk+fpJ4d3BWio5XfnkZiPRqgKu99B yM13oSetYgmk+Ac/Tq1Q3HDL246LgelmwQsf6fMmBRGd9Fy9AE/5A+Uq/guNacjSwrho g2A7+xiauc5tJL5yCWNhwRgCcu5dTf5G4Iy06Un5QQAipkUvGmO00cGX4aA3wnUDVE8G mIQzkzs3AJvouAgVOJ9cv5LInULeBJOB4nN5XZ5pliOmIQrevmPfheJ8ktLASTOtn3vn wK4QgbdOHZBAMplJeBtkLuwvnNHc702M2OF7ZaA8C4CPpTGTT6K9c11h8UFZ1+FyofyP BwMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=AifvGmYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020a655a88000000b00478a7598e46si17324059pgt.806.2022.12.21.08.54.18; Wed, 21 Dec 2022 08:54:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=AifvGmYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbiLUQSG (ORCPT + 68 others); Wed, 21 Dec 2022 11:18:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbiLUQSD (ORCPT ); Wed, 21 Dec 2022 11:18:03 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7E1220EB; Wed, 21 Dec 2022 08:18:02 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1671639480; bh=5Kuf8mtaECc9i8ymD5ug9Qtqh/WLjoDjMBBE59Rmcpw=; h=From:Date:Subject:To:Cc:From; b=AifvGmYkaWzleaaxUikPI2TSj/gYzlkmx3hdToqFvQqnW1I04q1d1tkMHPMse+N3p HVVS34JHIPAf7K8tL929JiePLRtbVvIzOi3MsV3mffQxodNHCAnl6m09hT+IvHee6U 5v63enPS8AyTyGOrIF4W6YDVq5tHICmdP+x8kjHg= Date: Wed, 21 Dec 2022 16:17:52 +0000 Subject: [PATCH] kernels/ksysfs.c: export kernel address bits MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-Id: <20221221-address-bits-v1-1-8446b13244ac@weissschuh.net> X-B4-Tracking: v=1; b=H4sIALAxo2MC/x2NQQqDQAxFryJZG6gpqPQq0kXGiTUgU0mqFMS7G 4S/eR8e7wAXU3F4VQeY7Or6LQFNXcE4c/kIag4GehA1MeScTdwx6c+xJeK+60m6Z4ZQErtgMi7j HFLZliXO1WTS/90Y3ud5Ad40RvZzAAAA To: Greg KH , "Rafael J. Wysocki" Cc: Thomas =?utf-8?q?Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Karel Zak , linux-api@vger.kernel.org X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1671639477; l=2240; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5Kuf8mtaECc9i8ymD5ug9Qtqh/WLjoDjMBBE59Rmcpw=; b=CbJ7PXGbE8At50zccR/KhIolZERvRK+sBE2voTyCEXgFgvKGp0Iz66Uitr0NhE5l4EFZxXfypASI 7w1XZWQHA8sgg0TRx6YQEdqtg+LNHI5uXVgAlbhu7d5mChicbR1f X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Cc: linux-kernel@vger.kernel.org To: Greg KH To: "Rafael J. Wysocki" Cc: "Karel Zak" Cc: linux-api@vger.kernel.org --- Documentation/ABI/testing/sysfs-kernel-address_bits | 10 ++++++++++ kernel/ksysfs.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-address_bits b/Documentation/ABI/testing/sysfs-kernel-address_bits new file mode 100644 index 000000000000..5d09ff84d4d6 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-address_bits @@ -0,0 +1,10 @@ +What: /sys/kernel/address_bit +Date: May 2023 +KernelVersion: 6.3 +Contact: Thomas Weißschuh +Description: + The address size of the running kernel in bits. + + Access: Read + +Users: util-linux diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 2df00b789b90..0408aab80941 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -51,6 +51,14 @@ static ssize_t cpu_byteorder_show(struct kobject *kobj, } KERNEL_ATTR_RO(cpu_byteorder); +/* address bits */ +static ssize_t address_bits_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%zu\n", sizeof(void *) * 8 /* CHAR_BIT */); +} +KERNEL_ATTR_RO(address_bits); + #ifdef CONFIG_UEVENT_HELPER /* uevent helper program, used during early boot */ static ssize_t uevent_helper_show(struct kobject *kobj, @@ -233,6 +241,7 @@ static struct attribute * kernel_attrs[] = { &fscaps_attr.attr, &uevent_seqnum_attr.attr, &cpu_byteorder_attr.attr, + &address_bits_attr.attr, #ifdef CONFIG_UEVENT_HELPER &uevent_helper_attr.attr, #endif --- base-commit: b6bb9676f2165d518b35ba3bea5f1fcfc0d969bf change-id: 20221221-address-bits-622a8782e73d Best regards, -- Thomas Weißschuh