Gentoo Archives: gentoo-user

From: Ashley Dixon <ash@××××××××××.uk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] preparing for make menuconfig
Date: Thu, 08 Oct 2020 20:28:30
Message-Id: 20201008202619.won4jst7u3jvqabk@ad-gentoo-main
In Reply to: Re: [gentoo-user] preparing for make menuconfig by John Covici
1 On Thu, Oct 08, 2020 at 01:55:04PM -0400, John Covici wrote:
2 > modules.alias modules.builtin
3 > modules.builtin.bin modules.dep.bin modules.order
4 > modules.symbols
5 > modules.alias.bin modules.builtin.alias.bin modules.dep
6 > modules.devname modules.softdep
7 > modules.symbols.bin
8
9 That's fine.
10
11 > and the error message is
12 >
13 > lspci: Unable to load libkmod resources: error -12
14
15 That error message is printed by lspci [1], although it is the result of the
16 libkmod `kmod_load_resources` function returning less than zero [2]. With a -12
17 error, this suggests a failing with the `index_mm_open` function [3]. It's quite
18 a beast of a function; the failure could be due to a multitude of reasons.
19
20 Considering the nature of the error (memory allocation failure), I reckon it
21 must be either the following call to mmap(2), or the preceding call to open(2):
22 (paraphrasing for formatting):
23
24
25 if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
26 DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
27 err = -errno;
28 goto fail_open;
29 }
30
31 /* [...] */
32
33 if ( ( idx->mm = mmap ( NULL, st.st_size, PROT_READ,
34 MAP_PRIVATE, fd, 0 ) ) == MAP_FAILED) {
35 ERR(ctx, "mmap (NULL, %"PRIu64", PROT_READ, %d, " \
36 "MAP_PRIVATE, 0 ): %m\n", st.st_size, fd);
37 err = -errno;
38 goto fail_nommap;
39 }
40
41 I might you need to debug this on your machine, as I can't reproduce it myself.
42 You'll need to clone, recompile, and relink libkmod and pciutils with the
43 maximum debugging settings, to keep all symbols in the executable. I assume
44 you're using GCC, although I suspect the same should work with Clang.
45
46 git clone both repos: [4] and [5].
47
48 libkmod:
49 - Save the old symlink, by renaming /lib64/libkmod.<version> to
50 something temporary, like libkmod.old.
51 - Execute ./autogen.sh to create a configure script.
52 - Run the configure script to enable maximum debugging:
53 ./configure CFLAGS='-ggdb3' --prefix=/usr --sysconfdir=/etc \
54 --libdir=/usr/lib64 --with-rootprefix= --with-rootlibdir=/lib64
55 - Compile and install the shared objects (you need to be root):
56 make && make install
57 - Ensure the `make install` has recreated the major version symlink in
58 /lib64 to the new shared object file.
59
60 pciutils:
61 - Compile; there is no need to install:
62 make CFLAGS="-ggdb3"
63
64 Now you have an lspci executable which is linked with the new libkmod, just need
65 to attach a debugger, such as gdb, and break on the troublesome function:
66
67 $ gdb ./lspci
68 Reading symbols from ./lspci...
69 (gdb) b index_mm_open
70 Function "index_mm_open" not defined.
71 Make breakpoint pending on future shared library load? (y or [n]) y
72 Breakpoint 1 (index_mm_open) pending.
73 (gdb) run -k
74
75 ... after a while, you'll encounter the first invocation of the troublemaker:
76
77 Breakpoint 1, index_mm_open (ctx=0x555555583340, filename=0x7fffffffc920
78 "/lib/modules/5.4.60-gentoo/modules.dep.bin", stamp=0x5555555833a0,
79 pidx=0x555555583378) at libkmod/libkmod-index.c:744
80
81 Before going any further, I want to confirm that `filename` does point to a
82 correct file? I doubt the open(2) call would fail with ENOMEM if the file was
83 invalid, although you never know. Assuming `filename` is valid, we can start
84 stepping through the function to determine which inner function is failing. My
85 bets are on mmap.
86
87 Hope to hear from you soon.
88
89 [1] https://git.kernel.org/pub/scm/utils/pciutils/pciutils.git/tree/ls-kernel.c#n42
90 [2] https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n842
91 [3] https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod-index.c#n742
92 [4] git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git
93 [5] git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
94
95 --
96
97 Ashley Dixon
98 suugaku.co.uk
99
100 2A9A 4117
101 DA96 D18A
102 8A7B B0D2
103 A30E BF25
104 F290 A8AA

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-user] preparing for make menuconfig John Covici <covici@××××××××××.com>