Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2321849rwi; Tue, 1 Nov 2022 06:31:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Xq2SDxvKikL/SBNsbaeSDOM8PxeHytkMoE8c36cN0Mci1AT8n2TWzqBxhW2yLHkuv6IGH X-Received: by 2002:a17:90b:1bc1:b0:213:e2af:b1f4 with SMTP id oa1-20020a17090b1bc100b00213e2afb1f4mr10838037pjb.47.1667309502339; Tue, 01 Nov 2022 06:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667309502; cv=none; d=google.com; s=arc-20160816; b=qn8O06ogY48+AuR+QSIW0DM1qRN6v9InEKeMzEDhBMyu+pftHMSXQmNJRRMWgepHf8 mWLjEw+MjWITRVa5S7QmT1M/teDPdDfJuNyTqihWIBAOmqXRG5NPkUKqAmNRUTNz8ZDy UXGoqB7h/OsfjRmwtJA5U54enGwnPWVKuIC2DmBU32jxcOZxmL/+ykZbn+CA4FeuFHOL DiQUv4ZfM/PP84TIEmQxXZOYr5Ie1HJatM5jNcmJEDOrJ0oc9mEjHHI3adWgYSCsZjs/ XxH+ZnRuD/XIDsAKfHKvEbWeNLT/7DlJo8rXWmxPWyFRdVoAuFOMydleNfvNgpnI8qds ktPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=hJ4r7RVWbbgSAJiJh9Xhv6KwfIug1v61BATaTCAwPWM=; b=j3qHtGh2RiQsxH5cT8fyn2no7taP9BJYFLcjltaYH0N5xhOdm5pz0tnnH/t0nWmW2t S6478DLit638Z9Mky1+4VtCfOWYOKw9YjtNtR6PMZa3vWl7Sh3r9xrSLgE8dn5fMyEme tp9HYm2vHBSF0Q7P70RIXFi4xscDmk1zQknBYqBVoSeUcXI3h1tOw3nKigXa+uo+CUug xTc6WxyrcWhdUxvuCOhdzseDuaKl+ef9RdkkfWZrdwmZ50xczGKCbIJFdOlh/5w6kH0Z rFz2ZIPOjlMefe2QmFeeDyxtmXJBifj8YhVEQd4iqKztUUiCKRJyQex5Y5wVIEVE/Z/V uK5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=eFp+gYnv; 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 q5-20020a17090311c500b0017a0a2e40e6si14810865plh.159.2022.11.01.06.31.20; Tue, 01 Nov 2022 06:31:42 -0700 (PDT) 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=eFp+gYnv; 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 S229813AbiKANEf (ORCPT + 97 others); Tue, 1 Nov 2022 09:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbiKANEd (ORCPT ); Tue, 1 Nov 2022 09:04:33 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC82712D16; Tue, 1 Nov 2022 06:04:32 -0700 (PDT) From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1667307870; bh=WKsfKfXzkJWoJQvD09hXFWT3kjqAmgF8ogC0a2yCnWQ=; h=From:To:Cc:Subject:Date:From; b=eFp+gYnvUzd555IsQfvG45RQND3MuvtWYUdXrThDC7n0XGhkngGCdL3imHyi+so6p EEUk9n8nYaH+kaGjALVrj02IJzSbz+pqN3jGnqpn+QmZAZImHdsgNrUcmppmfWi8/g uMSVFkN+F1YIQ3kmsisp3d9PqkaFsJgLgyXCI2wg= To: linux-fsdevel@vger.kernel.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Karel Zak , Masatake YAMATO , linux-api@vger.kernel.org, Greg KH Subject: [PATCH v2] proc: add byteorder file Date: Tue, 1 Nov 2022 14:04:01 +0100 Message-Id: <20221101130401.1841-1-linux@weissschuh.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=ed25519-sha256; t=1667307838; l=2910; s=20211113; h=from:subject; bh=WKsfKfXzkJWoJQvD09hXFWT3kjqAmgF8ogC0a2yCnWQ=; b=uDOy06fc7qHj8VYikcsRGtc3ggGiSSQhV5XQOrXFXXlgF8OEaJAZgZmGxu3CNyT2U5oPwJvfhNRX FG8dV0gcCgTQyakBKLbyUCJkDZVHqB+XmBPb+OPLhNp7s+GakK1N X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=9LP6KM4vD/8CwHW7nouRBhWLyQLcK1MkP6aTZbzUlj4= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Certain files in procfs are formatted in byteorder dependent ways. For example the IP addresses in /proc/net/udp. Assuming the byteorder of the userspace program is not guaranteed to be correct in the face of emulation as for example with qemu-user. Also this makes it easier for non-compiled applications like shellscripts to discover the byteorder. Signed-off-by: Thomas Weißschuh --- Development of userspace part: https://github.com/util-linux/util-linux/pull/1872 v1: https://lore.kernel.org/lkml/20221101005043.1791-1-linux@weissschuh.net/ v1->v2: * Move file to /sys/kernel/byteorder --- .../ABI/testing/sysfs-kernel-byteorder | 12 ++++++++++++ kernel/ksysfs.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-byteorder diff --git a/Documentation/ABI/testing/sysfs-kernel-byteorder b/Documentation/ABI/testing/sysfs-kernel-byteorder new file mode 100644 index 000000000000..4c45016d78ae --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-byteorder @@ -0,0 +1,12 @@ +What: /sys/kernel/byteorder +Date: February 2023 +KernelVersion: 6.2 +Contact: linux-fsdevel@vger.kernel.org +Description: + The current endianness of the running kernel. + + Access: Read + + Valid values: + "little", "big" +Users: util-linux diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 65dba9076f31..7c7cb2c96ac0 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -6,6 +6,7 @@ * Copyright (C) 2004 Kay Sievers */ +#include #include #include #include @@ -20,6 +21,14 @@ #include /* rcu_expedited and rcu_normal */ +#if defined(__LITTLE_ENDIAN) +#define BYTEORDER_STRING "little" +#elif defined(__BIG_ENDIAN) +#define BYTEORDER_STRING "big" +#else +#error Unknown byteorder +#endif + #define KERNEL_ATTR_RO(_name) \ static struct kobj_attribute _name##_attr = __ATTR_RO(_name) @@ -34,6 +43,14 @@ static ssize_t uevent_seqnum_show(struct kobject *kobj, } KERNEL_ATTR_RO(uevent_seqnum); +/* kernel byteorder */ +static ssize_t byteorder_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "%s\n", BYTEORDER_STRING); +} +KERNEL_ATTR_RO(byteorder); + #ifdef CONFIG_UEVENT_HELPER /* uevent helper program, used during early boot */ static ssize_t uevent_helper_show(struct kobject *kobj, @@ -215,6 +232,7 @@ EXPORT_SYMBOL_GPL(kernel_kobj); static struct attribute * kernel_attrs[] = { &fscaps_attr.attr, &uevent_seqnum_attr.attr, + &byteorder_attr.attr, #ifdef CONFIG_UEVENT_HELPER &uevent_helper_attr.attr, #endif base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737 -- 2.38.1