Commit Graph

17 Commits

Author SHA1 Message Date
Eugene Syromiatnikov 7cba732d24 find-provides.ksyms, find-requires.ksyms: do section data parsing inside awk
Previous approach with passing the section contents as a command line
option proven to be error-prone, as it hits the command line option size
limit on some kmods.  Move the reading and processing of the section
contents inside the awk script itself;  it also saves a bit (around 3—4%)
of time on the kernels with indirect __crc_* symbols:

    $ for i in ./lib/modules/*; do \
        echo "====== $i ====="; \
        diff -u <(find $i | ./find-provides.ksyms.old) <(find $i | ./find-provides.ksyms.new); \
        echo -n "old: "; find $i | time ./find-provides.ksyms.old > /dev/null; \
        echo -n "new: "; find $i | time ./find-provides.ksyms.new > /dev/null; \
    done
    ====== ./lib/modules/4.18.0-372.57.1.el8_6.s390x =====
    old: ./find-provides.ksyms.old > /dev/null  5.38s user 4.66s system 150% cpu 6.693 total
    new: ./find-provides.ksyms.new > /dev/null  5.20s user 4.52s system 149% cpu 6.484 total
    ====== ./lib/modules/4.18.0-372.57.1.el8_6.x86_64 =====
    old: ./find-provides.ksyms.old > /dev/null  7.85s user 6.34s system 143% cpu 9.864 total
    new: ./find-provides.ksyms.new > /dev/null  7.75s user 6.32s system 143% cpu 9.809 total
    ====== ./lib/modules/5.14.0-284.15.1.el9_2.s390x =====
    old: ./find-provides.ksyms.old > /dev/null  6.19s user 4.68s system 144% cpu 7.506 total
    new: ./find-provides.ksyms.new > /dev/null  5.93s user 4.46s system 143% cpu 7.219 total
    ====== ./lib/modules/5.14.0-284.15.1.el9_2.x86_64 =====
    old: ./find-provides.ksyms.old > /dev/null  8.47s user 6.71s system 144% cpu 10.523 total
    new: ./find-provides.ksyms.new > /dev/null  8.44s user 6.59s system 144% cpu 10.435 total
    ====== ./lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.s390x =====
    old: ./find-provides.ksyms.old > /dev/null  5.21s user 4.09s system 145% cpu 6.383 total
    new: ./find-provides.ksyms.new > /dev/null  5.04s user 3.85s system 145% cpu 6.120 total
    ====== ./lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.x86_64 =====
    old: ./find-provides.ksyms.old > /dev/null  8.68s user 5.77s system 139% cpu 10.326 total
    new: ./find-provides.ksyms.new > /dev/null  8.47s user 5.57s system 139% cpu 10.067 total

* find-provides.ksyms: Add assign to revbytes the result of endianness
chack test instead of the code snippet;  do not generate SECTDATA
variable;  do not pass SECTDATA to the awk script;  pass module
and revbytes to the awk script;  retrieve the section data
into the sectdata variable and perform the byte re-shuffling
in accordance to the revbytes value in the BEGIN section of the awk
script.
* find-requires.ksyms (all_provides): Likewise.

Fixes: fd79794323 "find-provides.ksyms, find-requires.ksyms: rewrite indirect CRC parsing"
Resolves: #2178935
Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:36:55 +02:00
Eugene Syromiatnikov f40a274ef8 find-provides.ksyms, find-requires.ksyms: rewrite section data matching
Currently, it just matches the 2nd to 5th fields with awk, which leads
to occasional capturing of some garbage at the end of the section data
and minor issues when supplying it to the symbol extracting awk script:

    awk: cmd. line:1: (FILENAME=- FNR=19) fatal: argument index with `$' must be > 0
    awk: warning: escape sequence `\.' treated as plain `.'
    awk: cmd. line:1: (FILENAME=- FNR=9) fatal: not enough arguments to satisfy format string
    	`78b624dbc125415351be965ex.$..%ASQ..^'
    	                              ^ ran out for this one

While at it, also eliminate grep and sed calls (with the pair of awk and
sed being the most offending).

* find-provides.ksyms: Generate part of the awk script that performs
the byte reversal based on the endianness in the readelf -h output,
inject it into the awk script;  use substr for matching parts
of the section data instead of fields.
* find-requires.ksyms (all_provides): Likewise.

Resolves: #2115811
Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:36:25 +02:00
Eugene Syromiatnikov 60d6d64fd3 find-requires.ksyms: set LC_ALL=C globally
To bring it more in line with the way it is implemented
in find-provides.ksyms and avoid the inconsistencies prodiced by missing
the environment setting.

Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:31:57 +02:00
Eugene Syromiatnikov 45ce51d5ff find-provides.ksyms, find-requires.ksyms: use "read -r"
To avoid all kinds of fun that might stem from interpreting the user-supplied
input.

* find-provides.ksyms: Supply -r option to the read call.
* find-requires.ksyms (all_provides): Likewise.

Fixes: fd79794323 "find-provides.ksyms, find-requires.ksyms: rewrite indirect CRC parsing"
Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:31:36 +02:00
Eugene Syromiatnikov c0a9b49b96 find-requires.ksyms: call readelf -R on the sectname and not hard-coded .rodata
* find-requires.ksyms (all_provides): Pass $sectname to the readelf -R call.

Fixes: fd79794323 "find-provides.ksyms, find-requires.ksyms: rewrite indirect CRC parsing"
Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:30:31 +02:00
Eugene Syromiatnikov 4ecf0dd22f find-provides.ksyms, find-requires.ksyms: match only the section being processed
Instead of ignoring the section name in the objdump -t output, section
name has to be checked in the awk script to produce only the meaningful
output;  hit when both __kcrctab and __kcrctab_gpl are present.

* find-requires.ksyms (all_provides): Pass $sectname to the awk script,
check that the relevant field of the input matches it.
* find-provides.ksyms: Likewise.

Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-12 14:30:19 +02:00
Eugene Syromiatnikov 25b14c8700 find-provides.ksyms, find-requires.ksyms: filter local __crc_* symbols as well
Apparently, these are local in the recent kernels.

* find-provides.ksyms (all_provides): Filter local __crc_* symbols
in additional to global in the objdump -t call output.
* find-requires.ksyms: Likewise.

Resolves: #2178935
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-09 14:11:02 +02:00
Eugene Syromiatnikov dc499f2b3a find-provides.ksyms, find-requires.ksyms: avoid awaking debuginfod
Starting with RHEL 9.2 and Fedora 35, debuginfod is enabled by default,
which leads to significant startup times of various tools
from the elfutils package (namely, readelf and objdump).
Unset DEBUGINFOD_URLS to avoid it.

Resolves: #2209253
Suggested-by: Panu Matilainen <pmatilai@redhat.com>
Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2023-06-08 15:30:42 +02:00
Eugene Syromiatnikov fd79794323 find-provides.ksyms, find-requires.ksyms: rewrite indirect CRC parsing
Linux commit v5.19-rc1~139^2~2 ("kbuild: link symbol CRCs at final link,
removing CONFIG_MODULE_REL_CRCS") has broken the assumption aobut
the placement of non-absolute CRC symbols in .rodata (and also affects
the architectures that used to have these symbols as absolute);  rewrite
the parsing by utilising "objdump -t" output to figure out
the section(s) where the __crc_* symbols are stored and process
it instead of the hard-coded ".rodata" section.  The change also speeds
up the processing a bit, around 33% on synthetic tests:

    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.ppc64le -name "*.ko.xz" | find-provides.ksyms.old > /dev/null 2> /dev/null'
    sh -c   10.36s user 5.58s system 137% cpu 11.613 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.ppc64le -name "*.ko.xz" | find-provides.ksyms.new > /dev/null 2> /dev/null'
    sh -c   7.82s user 4.59s system 142% cpu 8.686 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.ppc64le -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.old" \; > /dev/null 2> /dev/null'
    sh -c   11.85s user 6.76s system 129% cpu 14.318 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.ppc64le -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.new" \; > /dev/null 2> /dev/null'
    sh -c   8.91s user 5.51s system 135% cpu 10.647 total

* find-provides.ksyms: Process "objdump -t" output to get the list
of sections where __crc_* symbol contents are placed;  retrieve
each one with "readelf -R" and supply it to an awk script that cuts
the required part of it for each __crc_* symbol in that section.
* find-requires.ksyms (all_provides): Likewise.

Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Resolves: #2135047
2023-02-08 17:13:59 +01:00
Eugene Syromiatnikov 594e5a5a30 find-provides.ksyms, find-requires.ksyms: rewrite absolute CRC parsing
Avoid running sed on the whole "nm" output and also avoid "sed | awk"
pipe in favor of a single awk call.  Overall, this gives around 20%
speedup on some quick synthetic tests:

    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.old > /dev/null 2> /dev/null'
    sh -c   14.20s user 8.93s system 144% cpu 16.014 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.new > /dev/null 2> /dev/null'
    sh -c   12.01s user 7.46s system 143% cpu 13.567 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.old" \; > /dev/null 2> /dev/null'
    sh -c   16.31s user 10.77s system 134% cpu 20.092 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.new" \; > /dev/null 2> /dev/null'
    sh -c   13.95s user 8.92s system 135% cpu 16.836 total

* find-provides.ksyms: Check presence of absolute __crc_* symbols with
"grep -q" exit code and not presence of sed output;  rewrite awk script to match
the __crc_* symbols instead of preprocessing the nm output with sed.
* find-requires.ksyms: Likewise.

Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Resolves: #2135047
2023-02-08 16:49:55 +01:00
Eugene Syromiatnikov 24312e21be find-provides.ksyms, find-requires.ksyms: work around printed __crc_* type change
Commit binutils-2_33~1385[1] has changed (and binutils-2_35~1768[2]
has not reverted) the calculated type for symbols in read-write .rodata section
from 'R' to 'D' on architectures where CONFIG_MODULE_REL_CRCS is enabled
(namely, ppc64* and s390*), since, apparently, many kernel modules have it indeed
read-write.  Work around it by matching both D and R as possible __crc_* symbol
type.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=a288c270991d
[2] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=49d9fd42acef

* find-provides.ksyms: Match D as possible __crc_* symbol type in
addition to R.
* find-requires.ksyms: Likewise.
* kernel-srpm-macros.spec (Release): Bump to 11%{?dist}.
(%changelog): Mention the change.

Resolves: #2055464
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2022-02-17 04:41:45 +01:00
Eugene Syromiatnikov bebabb191d Add zstd kmod compression support
* brp-kmod-restore-perms: Add chech for "$RPM_BUILD_ROOT/$path.zst".
* find-provides.ksyms: Add "\.zst" to the kernel module path matching
regular expression; process kernel module with zstd if its file name
ends with "zst".
* find-requires.ksyms: Likewise.
* firmware.prov: Add "\.zst" to the kernel module path matching
regular expression.
* kmodtool (%post, %preun): Likewise.
* modalias.prov: Likewise.
* modalias.attr (%__modalias_path): Add "ko\.zst" to the kernel module
path matching regular expression.
* provided_ksyms.attr (%__provided_ksyms_path): Likewise.
* required_ksyms.attr (%__required_ksyms_path): Likewise.
* kmod.attr (%__kmod_path): Add ".*\.ko\.zst" to the kernel module path
matching regular expression.
(strip_compress_sfx): Strip "\.zst" suffix, if present.

Resolves: #1942537
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 14:50:11 +01:00
Eugene Syromiatnikov 4c68fd7e56 Switch kmodtool-generated spec to internal dependency generator
It leads to some regressions in requires generation precision, though,
as it is no longer possible to exclude requires that are satisfied
by other kmods in the package.  And calling a script on each file (instead
of calling it on the whole file list at once) does not make things faster,
either (so much for "sanity and benefit").

* find-provides.ksyms: Check for "$@" as well.
* find-requires.ksyms: Likewise.
* kernel-srpm-macros.spec (Source104, Source105, Source106): New
attribute files.
(%install): Install firmware.prov and modalias.prov with executable bit;
install provided_ksyms.attr, required_ksyms.attr, and modalias.attr into
"%{buildroot}%{_fileattrsdir}".
(%files -n kernel-rpm-macros): Add provided_ksyms.attr,
required_ksyms.attr, and modalias.attr.
kmodtool: Remove "%global _use_internal_dependency_generator 0".
macros.kmp: Remove %__find_provides and %__find_requires.
* modalias.attr: New file.
* provided_ksyms.attr: Likewise.
* required_ksyms.attr: Likewise.

Resolves: #1942072
Resolves: #1942563
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 14:49:04 +01:00
Eugene Syromiatnikov f6c02f2f49 Add support for compressed kernel modules
- Add support for compressed kernel modules to find-provides.ksyms,
  find-requires.ksyms, firmware.prov (#1622019)

* find-provides.ksyms: Try to process files whose names end with
something else than "*.ko" by guessing a decompressor and uncompressing
it in a temporary file and parsing it instead.
* find-requires.ksyms (all_provides): Likewise.
Add "(\.gz|\.bz2|\.xz)?" to the end of the module path matching regular
expression.
* firmware.prov: Add "(\.gz|\.bz2|\.xz)?" to the end of the module path
matching regular expression.

Resolves: #1942537
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 14:22:00 +01:00
Eugene Syromiatnikov ddcb08281b find-requires.ksym: fix external kmod deps for symbols with the same name
Generate colon-separated pairs of symbol_name:version and then run joins
over them instead over just symbol names.

Resolves: #2002887
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 14:22:00 +01:00
Eugene Syromiatnikov 670da3c03d find-requires.ksyms: import RHEL-specific changes from RHEL 7.6
* find-requires.ksyms: Add file comment.
(check_kabi): New function.
(if [ ${#modules[@]} -gt 0 ]): Call it.

Resolves: #2002887
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 14:22:00 +01:00
Michal Domonkos 2625834549 Adopt kernel-rpm-macros from redhat-rpm-config
No changes are being made to the individual files added here; they're
1:1 copies of the ones in redhat-rpm-config.

Note the kernel-rpm-macros version - the latest c9s build is versioned
after its parent SRPM which is redhat-rpm-config-184-1, so we need to
make this one NVR-newer to allow for clean upgrades.

The respective removals from redhat-rpm-config are tracked in #1959924.

Resolves: #1959914
2021-05-13 17:52:56 +02:00