From patchwork Tue Nov 1 13:04:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2952101wru; Tue, 1 Nov 2022 06:08:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44z3G1qgDnviYyh14JXscfXQhtn3dkJ4dBXErc1TMCNybpR3DhCfdya7rSoSn0S3VgEsZK X-Received: by 2002:a17:907:c27:b0:7ad:be77:561e with SMTP id ga39-20020a1709070c2700b007adbe77561emr13705208ejc.314.1667308102735; Tue, 01 Nov 2022 06:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667308102; cv=none; d=google.com; s=arc-20160816; b=QS6BZm1/jvKSvCTI+F6IY0uXIt9JKEKnpegPqeVbham3QXwQy5zPzXOGNRxFaDWhKh gZDigjnXCQ/tpMjA+wKNXme+DZZ1EYOh5DdAvvzyi0qJxuarwG8dVr+k/05vdcWuD9HF 7vfNR7sLWrkV/7Y7fl6C5R80iJqS0RLajIkNM3bUD58caLdp6PeiIlv9r+H0uqB5vQ4X f3tRkDFOj8+Zb3Kaz0fWU5HkEmlZC+yJRLU/qi1zMIozj+K1hp33GVmtx5A+M5HiU/vv qXdW+y+WAnLqC1+6PEsj/xQWfjUDb32iCR6Ta+kFyf1PfhNpJk/fj8SJJYiYCrvY0woi 6f9Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c97-20020a509fea000000b0046198ab2c0bsi9732649edf.283.2022.11.01.06.07.47; Tue, 01 Nov 2022 06:08:22 -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 + 99 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_Wei=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_Wei=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 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= 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748253097413110196?= X-GMAIL-MSGID: =?utf-8?q?1748299261203138591?= 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 base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737 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