Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysfs: runtime byteorder detection #1872

Merged
merged 8 commits into from Dec 21, 2022
Merged

Conversation

t-8ch
Copy link
Member

@t-8ch t-8ch commented Oct 30, 2022

This is a proof-of-concept that makes use of a new procfs file[0] to detect the byteorder of a running kernel at runtime.
The advantage is that lsfd and lscpu work correctly even in the face of emulation.

Cc @karelzak @masatake

[0] https://git.sr.ht/~t-8ch/linux/log/proc-byteorder

@t-8ch t-8ch force-pushed the proc/byteorder branch 3 times, most recently from 39bcedd to 9e55845 Compare October 31, 2022 00:10
lib/procfs.c Outdated Show resolved Hide resolved
@karelzak
Copy link
Collaborator

I like it :-)

@@ -639,9 +651,9 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil
sock->class = class;
sock->inode = (ino_t)inode;
sock->netns_inode = netns_inode;
inet->local_addr = local_addr;
inet->local_addr = kernel32_to_cpu(byteorder, local_addr);
tcp->local_port = local_port;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need kernel16_to_cpu(byteorder, local_port);.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually works without it.
IIRC the kernel always uses network-endianness for the port.

The inconsistency between address and port feels very much like a bug. But there's nothing to be done about it.

@karelzak
Copy link
Collaborator

karelzak commented Nov 1, 2022

OK, if I good understand, we need to wait for changes in Linus' tree.

@karelzak karelzak added the KERNEL-FIRST Postponed until the kernel portion got merged into Linus' tree. label Nov 1, 2022
@t-8ch
Copy link
Member Author

t-8ch commented Nov 1, 2022

OK, if I good understand, we need to wait for changes in Linus' tree.

Indeed.

For now I dropped the alternative filesystem specification as it is an unnecessary burden to carry around during the coordination process with the kernel.
We can easily re-introduce it when the first version of the feature is merged.

FYI the file has now moved to /sys/kernel/byteorder.

@t-8ch
Copy link
Member Author

t-8ch commented Nov 10, 2022

The kernelpatch has been picked up by Greg and should end up in Linux 6.2

@t-8ch
Copy link
Member Author

t-8ch commented Nov 18, 2022

@karelzak To adapt the tests for lscpu all the dumps need the file /sys/kernel/cpu_byteorder added.
With the current .tar.gz archives this will create a lot of churn.

The alternative would be to move from archives to plain directories. This would make the diffs cleaner.
What is your preference?

@t-8ch t-8ch changed the title procfs: runtime byteorder detection sysfs: runtime byteorder detection Nov 18, 2022
@karelzak
Copy link
Collaborator

I guess the change is backwardly compatible ;-), so the tests without /sys/kernel/cpu_byteorder will work without a change, right?

We need to update the script tests/ts/lscpu/mk-input.sh to gather cpu_byteorder too.

@t-8ch
Copy link
Member Author

t-8ch commented Nov 21, 2022

Yes it will work without the file.
But to test the feature we need to have the file in all the dumps.

Do we want to update a bunch of binary archives or unpack them first?

@karelzak
Copy link
Collaborator

The dumps already contain obsolete things but want to be compatible with these old kernels/dumps, so it makes sense to keep the old dumps unchanged.

It would be better to create a new dump with the new kernel and add it as x86_64-linux-6.2.tar.gz or so (or something more exotic if you have ...).

This can be used to skip tests that require that the machine executing
the tests has the same byteorder as the test executable.

Useful for tests emulated with qemu-user.
It contains the new file /sys/kernel/cpu_byteorder that lscpu will use
to read the actual byteorder.
@t-8ch t-8ch marked this pull request as ready for review November 27, 2022 17:37
@t-8ch
Copy link
Member Author

t-8ch commented Dec 16, 2022

@karelzak karelzak merged commit 97be86c into util-linux:master Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
KERNEL-FIRST Postponed until the kernel portion got merged into Linus' tree.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants