jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.64k stars 180 forks source link

ghw-snapshot broken on Linux >= 5.16-rc3: hugepages demote #306

Closed taigrr closed 2 years ago

taigrr commented 2 years ago

ghw-snapshot no longer operates as expected on newer releases of the Linux kernel because it attempts to copy the demote interface (by glob expansion) from inside hugepages sysfs. The demote interface is, as per the spec, write-only and therefore cannot be copied.

This is easily reproducible on any system running the latest Linux kernel (discovered when attempting to run on up-to-date Arch Linux). Failure produced:

$ ./ghw-snapshot
Error: open /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/demote: permission denied
Usage:
  ghw-snapshot [flags]

Flags:
  -d, --debug        Enable or disable debug mode
  -h, --help         help for ghw-snapshot
  -o, --out string   Path to place snapshot. Defaults to file in current directory with name $OS-$ARCH-$HASHSYSTEMNAME.tar.gz

More information (evidence of write-only interface):

$ cd/sys/devices/system/node/node0/hugepages/hugepages-1048576kB
$ ls -ashil
total 0
3404 0 drwxr-xr-x 2 root root    0 Mar 18 13:49 .
3403 0 drwxr-xr-x 4 root root    0 Mar 18 13:49 ..
3409 0 --w------- 1 root root 4.0K Mar 19 10:37 demote
3408 0 -rw-r--r-- 1 root root 4.0K Mar 19 10:40 demote_size
3406 0 -r--r--r-- 1 root root 4.0K Mar 19 10:40 free_hugepages
3405 0 -rw-r--r-- 1 root root 4.0K Mar 19 10:40 nr_hugepages
3407 0 -r--r--r-- 1 root root 4.0K Mar 19 10:40 surplus_hugepages

External references:

https://www.kernel.org/doc/html/v5.16-rc3/admin-guide/mm/hugetlbpage.html

I would recommend only attempting to copy files with the read permission set to avoid more issues such as this in the future. I can send a PR.

taigrr commented 2 years ago

Hey @fromanirh while I have your attention here, if I could get you to take a look at this as well, hopefully this is a much easier review.