Commit Graph

1428 Commits

Author SHA1 Message Date
Omar Sandoval
80e5cc52ae vmtest: manage: add option to not build anything
Now `python3 -m vmtest.manage -K --no-build` can be used to get the list
of latest kernel releases that need to be built. Also rename --dry-run
to --no-upload since --no-build is also a dry run in a way.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-12 13:25:14 -07:00
Omar Sandoval
cb3bb6cc2b helpers: add slab cache merging helper and documentation
Slab cache merging can cause major confusion when debugging using slab
cache helpers. Add a helper to detect whether a slab cache is merged and
an explanation of the implications.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-09 16:27:24 -07:00
alexlzhu
5c66aab23f helpers: add helpers for iterating over allocated slab objects
These are ported from https://github.com/josefbacik/debug-scripts.

Signed-off-by: alexlzhu <alexlzhu@fb.com>
[Omar: make test case check for exception on SLOB]
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-09 16:05:16 -07:00
Omar Sandoval
f3f51942e2 docs: document that StackFrame.name requires debugging information
And how to get a reasonable name for, e.g., functions implemented in
assembly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-05 08:22:34 -07:00
Omar Sandoval
a541e9b170 libdrgn: support reference and absent objects with >64-bit integer types
GCC and Clang have 128-bit integer types on 64-bit targets: __int128 and
unsigned __int128. Clang additionally has N-bit integers of up to 2<<24
bits with _ExtInt(N), which was standardized in C23 as _BitInt(N).

Currently, we disallow creating objects with a >64-bit integer type. Jay
Kamat reported that this would cause errors when examining some
binaries. The reason we disallow this is that we don't have a way to
represent or do operations on >64-bit values. We could make use of a
bignum library like GMP to do this in the future.

However, for now, we can loosen this restriction and at least allow
reference and absent objects with big integer types. This requires
enforcing two things: that we never create a value object with a >64-bit
integer type, and that we never read the value of a reference object
with a >64-bit integer type.

Co-authored-by: Jay Kamat <jaygkamat@gmail.com>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-28 13:38:38 -07:00
Omar Sandoval
084e636341 libdrgn: add DRGN_ERROR_NOT_IMPLEMENTED
This will be used for partial 128-bit object support. There are other
places that should probably be converted to use it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-28 13:38:38 -07:00
Omar Sandoval
ad7e64d9d8 libdrgn: make memdup() take a const void *
Just like strdup(), memdup() doesn't modify the thing it's copying, so
mark it const.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-27 00:37:46 -07:00
Davide Cavalca
031e48e6a0 packit: reenable fedora-eln-ppc64le builds
Signed-off-by: Davide Cavalca <dcavalca@fb.com>
2022-04-22 10:48:33 -07:00
Omar Sandoval
2dada19ab9 setup.py: add 5.18 to vmtest kernels
The tiny flavor was failing due to a bug fixed in Linux kernel commit
c12cd77cb028 ("mm/vmalloc: fix spinning drain_vmap_work after reading
from /proc/vmcore") (in v5.18-rc3). Now that the fix is in, we can add
5.18 with no changes required.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-21 16:17:42 -07:00
Davide Cavalca
7f2d47f7bd Use dedicated copr for packit builds
Signed-off-by: Davide Cavalca <dcavalca@fb.com>
2022-04-20 17:09:21 -07:00
Omar Sandoval
14642fb3b6 libdrgn: add stub RISC-V architecture with relocation implementation
The 32-bit and 64-bit variants have different register sizes, so they're
different architectures in drgn. For now, put them in the same file so
that they can share the relocation implementation. We'll need to figure
out how to handle registers later.

P.S. RISC-V has the weirdest relocations so far. /proc/kcore also
appears to be broken.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-19 11:51:23 -07:00
Omar Sandoval
d27204260e libdrgn: add stub Arm architecture with relocation implementation
The only relocation type I saw in Debian's kernel module debug info was
R_ARM_ABS32. R_ARM_REL32 is easy. The Linux kernel supports a bunch of
other ones that don't seem relevant to debug info.

Unfortunately, I wasn't able to test this because /proc/kcore doesn't
exist on Arm. This apparently goes all the way back to 2003:
https://lwn.net/Articles/45315/.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-19 00:25:05 -07:00
Omar Sandoval
3f246f7054 libdrgn: add stub AArch64 architecture with relocation implementation
The only relocation types I saw in Debian's kernel module debug info
were R_AARCH64_ABS64 and R_AARCH64_ABS32. R_AARCH64_ABS16,
R_AARCH64_PREL64, R_AARCH64_PREL32, and R_AARCH64_PREL16 are all easy.
The remaining types supported by the Linux kernel are for movw and
immediate instructions, which aren't relevant to debug info.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-19 00:23:56 -07:00
Omar Sandoval
7535838cd5 libdrgn: add stub i386 architecture with relocation implementation
The only relocation type I saw in Debian's kernel module debug info was
R_386_32. R_386_PC32 is easy. The Linux kernel also supports
R_386_PLT32, but that's the same story as R_X86_64_PLT32 in x86-64, so
we don't implement it for now.

I was torn between naming it i386, x86, or IA-32. x86 isn't immediately
clear whether x86-64 is included or not. No one other than Intel calls
it IA-32. i386 might incorrectly imply that it is strictly the original
i386 instruction set with no later extensions, but the more general
meaning is used frequently in the Linux world (e.g., Debian and QEMU
both call it i386), so I went with that in the end.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-19 00:21:59 -07:00
Omar Sandoval
03f9f339e5 libdrgn: ppc64: add relocation implementation
One of the biggest things we depend on libdwfl for is applying
relocations on architectures other than x86-64. I'm exploring the
possibility of removing the libdwfl dependency, so I'm going to add
relocation implementations for more architectures, starting with ppc64.

R_PPC64_ADDR32 and R_PPC64_ADDR64 were the only ones I saw in Debian's
kernel module debug info. R_PPC64_REL32 and R_PPC64_REL64 are
straightforward. The Linux kernel also implements R_PPC64_TOC*, which
don't seem relevant to debugging information, and R_PPC64_REL24 and
R_PPC64_REL16*, which I'd prefer to have a real example of.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-18 17:56:37 -07:00
Omar Sandoval
da16a12fad libdrgn: x86_64: implement more relocation types
Implement R_X86_64_32S and R_X86_64_PC64. I haven't seen these for debug
info in the wild, but they're supported by the Linux kernel and they're
easy to support. The only other type of relocation currently supported
by the kernel is R_X86_64_PLT32, which is trickier. For kernel modules,
it's equivalent to R_X86_64_PC32 (see Linux kernel commit b21ebf2fb4cd
("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32"), but that doesn't seem to
be true in general. It doesn't seem applicable to debug info sections,
so hopefully we don't need to worry about it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-18 17:56:37 -07:00
Omar Sandoval
b16dad8a36 libdrgn: support SHT_REL relocations
In preparation for supporting ELF relocations for more architectures,
generalize ELF relocations to handle SHT_REL sections/ElfN_Rel.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-18 17:56:37 -07:00
Omar Sandoval
558aa52d86 libdrgn: hash_table: sanity check integer sizes more
Check that size_t makes sense and make sure int_key_hash_pair() doesn't
get an integer type larger than it supports. I can't imagine either of
these failing in practice, but make our assumptions explicit.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-12 16:18:46 -07:00
Omar Sandoval
af01ee63c5 libdrgn: hash_table: support types larger than size_t for hash_combine()
We call hash_combine() with a uint64_t in
drgn_debug_info_module_key_hash_pair() and drgn_type_dedupe_hash_pair().
On 32-bit systems, this only uses the least-significant 32 bits. Use
hash_64_to_32() on 32-bit and hash_128_to_64() on 64-bit to ensure that
we use all bits if we're given a type larger than size_t, and sanity
check that we're not given anything larger than we support.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-12 16:18:13 -07:00
Omar Sandoval
13144eda11 vmtest: download: fix hang on HTTP error
If gh.download() in _download_kernel() raises an exception (e.g.,
because of an HTTP 403 error due to rate-limiting), then we will try to
exit the subprocess context managers for zstd and tar.
subprocess.Popen.__exit__() closes stdin if it is a pipe and then waits
for the subprocess. The context managers are exited in reverse order, so
first we'll try to wait for tar. But, that will never exit because its
stdin (piped from zstd) is still open. Fix it by always explicitly
closing zstd's stdin once the tar process is running.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-04 16:38:30 -07:00
Omar Sandoval
9366294d8d vmtest: kbuild: don't use ~ for flavors
GitHub release assets don't allow "~" in filenames; they are changed
into ".". This means that we can't take advantage of the fact that ~
version sorts before anything, so add a sub-version to the localversion
which is 1 for the default flavor and 0 for everything else.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-02 22:25:51 -07:00
Omar Sandoval
2152702bc0 vmtest: manage: delete builds after packaging
The vmtest build workflow is running out of disk space because the build
directories are big, and we have a lot of them now. Default to deleting
them if uploading packages, default to keeping them in dry run mode, and
add options to choose one or the other explicitly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-02 22:21:53 -07:00
Omar Sandoval
7d644e40ea vmtest: add kernel configuration flavors
In order to test the upcoming slab helpers (#166) with the different
slab allocators, we need kernels built with SLAB and SLOB in addition to
the default SLUB. We also have some helpers which depend on SMP vs !SMP.
There will likely be other options to test in the future, like RCU
implementations.

A testing matrix of all of these options would be too big. Instead,
introduce the notion of "flavors": groups of tweaks to the vmtest kernel
configuration. For now, we have three flavors: "default" (which uses
SLUB), "alternative" (which uses SLAB), and "tiny" (which is !SMP,
!PREEMPT, and uses SLOB). As long as the options are orthogonal enough
and each one doesn't have many choices, we won't need many more flavors
than that.

I haven't decided yet exactly how to use these flavors. The easiest
thing to do is probably to run the entire Linux kernel test suite on
every flavor of every version. Since the total runtime is dominated by
boot and loading debugging information, this won't be much slower than
only running targeted tests. That will be sorted out later; for now,
this adds the build infrastructure.

While we're bumping the vmtest localversion, let's also add
CONFIG_CC_OPTIMIZE_FOR_SIZE=y.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-02 01:53:00 -07:00
Omar Sandoval
eb75ecadd6 tests: fix slab tests for SLOB allocator
SLOB doesn't have /proc/slabinfo (and it can be disabled for SLUB and
SLAB on some kernel versions, too). Fall back to some known slab caches
if /proc/slabinfo doesn't exist.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-01 16:48:29 -07:00
Omar Sandoval
f43af4b037 libdrgn: fix drgn_program_crashed_thread() on !SMP kernels
On !SMP kernels, crashing_cpu either doesn't exist or is always -1, so
drgn_program_crashed_thread() fails. Detect those cases and treat
crashing_cpu as 0.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-01 15:10:04 -07:00
Omar Sandoval
d9b8392d7f pre-commit: roll mypy back to v0.931
pre-commit/mirrors-mypy@d37f9c4f0c added
"from __future__ import annotations", which doesn't work on Python 3.6.
Python 3.6 is EOL, so it's probably time to drop it, but that should be
a different, intentional change.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-31 17:00:26 -07:00
Omar Sandoval
fbfe7f45ad pre-commit: update Black and mypy
Black 22.3.0 fixes psf/black#2964, which was breaking the CI with:

  ImportError: cannot import name '_unicodefun' from 'click'

mypy v0.942 doesn't complain about anything new.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-31 16:28:40 -07:00
Omar Sandoval
cb69aec85a tests: add Linux kernel version to VM test result
We currently log "Tests in VM returned $STATUS" when vmtest returns. To
find out what kernel version just returned, you have to scroll up to
find a previous log line that mentions the version. Make things more
convenient by adding the version to that message.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-25 17:47:56 -07:00
alexlzhu
88a6ecfe90 helpers: add helpers for listing and finding slab caches
These are ported from https://github.com/josefbacik/debug-scripts.

Signed-off-by: alexlzhu <alexlzhu@fb.com>
2022-03-16 16:43:40 -07:00
Omar Sandoval
322e2b1c69 tests: move non-helper Linux kernel tests
tests/helpers/linux contains test cases for Linux kernel helpers and
test cases for core Linux kernel support. The latter don't make sense
there; move them to tests/linux_kernel instead, along with the
scaffolding.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-04 15:43:33 -08:00
Omar Sandoval
45eb3eb858 tests: find tests/sample.coredump.zst more robustly
First, find the sample file relative to the test module so that tests
can be run from a different directory. Second, pass --force to zstd so
that it doesn't ignore symlinks, which is required for environments like
Buck that copy the test files as a symlinks.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 11:53:21 -08:00
Omar Sandoval
b300021ba3 scripts/build_dists.sh: use docker run --pull always instead of docker pull
This way we only need to invoke docker (and sudo, if running with
DOCKER="sudo docker") once.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 01:23:01 -08:00
Omar Sandoval
6418ad1403 Run tests when building manylinux wheels
This will catch issues like the one fixed in commit 549cd7facc ("Add
tests/sample.core.zst to sdist").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 01:20:03 -08:00
Omar Sandoval
b6e0ad2af1 tests: check for missing or invalid /proc/kcore for Linux kernel tests
If /proc/kcore is missing (e.g., because CONFIG_PROC_KCORE is not
enabled) or invalid (e.g., Docker mounts /dev/null over /proc/kcore),
then skip the tests.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 01:17:51 -08:00
Omar Sandoval
9803c4ac65 drgn 0.0.18
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 00:30:06 -08:00
Omar Sandoval
549cd7facc Add tests/sample.core.zst to sdist
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 00:29:01 -08:00
Omar Sandoval
bf95af8c0d drgn 0.0.17
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-02 23:32:29 -08:00
Omar Sandoval
af6f5a887d libdrgn: replace gen_arch.awk with gen_arch_inc_strswitch.py
Now that we have gen_strswitch.py, there's no reason to keep this AWK
script around. Replace it with a Python script that outputs a strswitch
file. This also gets rid of our gawk dependency.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-02 16:10:43 -08:00
Omar Sandoval
95dff5b755 libdrgn: split some helpers out of gen_strswitch.py
These will be used by other code generation scripts.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-02 16:00:39 -08:00
Omar Sandoval
24609a3a2e libdrgn: add autoconf option to enable compiler warnings
This adds an --enable-compiler-warnings flag that:

* Defines a canonical list of warnings that we enforce. For now, this is
  -Wall -Wformat-overflow=2 -Wformat-truncation=2, but we can add to it
  going forward.
* Enables warnings by default.
* Allows erroring on warnings. We recommend that developers use this and
  use it for the CI.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 15:38:05 -08:00
Omar Sandoval
36277e22f3 libdrgn: add autoconf option to enable UBSan
Similar to --enable-asan for ASan, this is enabled with --enable-ubsan.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 15:11:16 -08:00
Omar Sandoval
3f32750155 helpers: optimize get_printk_records()
Pre-read objects that are accessed multiple times to reduce reads from
/proc/kcore or the core dump. For both the lockless and old structured
variant on a live system with a full buffer, this is about 40-50%
faster.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 11:28:35 -08:00
Omar Sandoval
73e8b97a68 helpers: add basic protection against printk buffer corruption
_get_printk_records_lockless() is guaranteed to terminate because the
loop control variable is a simple counter, but for
_get_printk_records_structured(), the log lengths essentially create a
linked list. This list could theoretically contain a cycle if the buffer
is corrupted. Add a simple check for this so we never get into an
infinite loop.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 02:42:59 -08:00
Omar Sandoval
c198afeba5 helpers: add caller ID to printk records
Knowing the thread or CPU that logged a specific message can be very
useful when investigating multithreaded bugs. Additionally, on kernels
since 5.10, the caller ID is always saved but only exposed to userspace
if CONFIG_PRINTK_CALLER is enabled, which distros don't currently seem
to do.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 02:32:45 -08:00
Omar Sandoval
0884b303ea helpers: rename dmesg module to printk
This is more in line with the naming in the kernel. Also slightly reword
some comments.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 02:18:03 -08:00
Omar Sandoval
fae5afaa0e helpers: add get_dmesg()
get_printk_records() provides programmatic access to the kernel log
buffer. Add a shortcut for just getting the text with timestamps.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-28 21:20:20 -08:00
alexlzhu
ba51e8840b helpers: add get_printk_records()
Helper allows user to obtain the raw contents plus metadata of dmesg.

Signed-off-by: alexlzhu <alexlzhu@fb.com>
2022-02-28 21:20:20 -08:00
Kevin Svetlitski
e6306853d2 Make iwyu.py respect the CFLAGS environment variable
Previously iwyu.py overwrote the value of the `CFLAGS` environment
variable regardless of whether it was already set. This was very
frustrating when trying to set custom `CFLAGS` to be used in the
generation of compile_commands.json, so the script now only sets
`CFLAGS` if it is not already present in the environment.

Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2022-02-25 11:33:30 -08:00
Davide Cavalca
6153cf6e55 packit: add s390x and build for EPEL 9 as well
Signed-off-by: Davide Cavalca <dcavalca@fb.com>
2022-02-24 09:47:58 -08:00
Omar Sandoval
b15706ebc4 CONTRIBUTING: elaborate on pre-commit
Get rid of the directions for running isort and black directly, since
that might run a different version than we have configured for
pre-commit. Instead, elaborate on pre-commit, including how to run
pre-commit manually.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-22 15:14:34 -08:00