Commit Graph

1588 Commits

Author SHA1 Message Date
Omar Sandoval
860a9555e9 CI: actually install pahole
The package is called dwarves.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-18 01:48:52 -08:00
Omar Sandoval
768a070461 CI: install pahole
This is required for building the test kernel module.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-18 01:47:52 -08:00
Omar Sandoval
cfda1942f8 tests: only run stack tracing tests on implemented architectures
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-18 01:42:38 -08:00
Omar Sandoval
c911ccdd36 tests: build test kernel module with kernel.org compiler
Now we'll always get the same compiler that was used for the actual
kernel build. Also split this into its own runnable module, vmtest.kmod,
for testing and custom scripting.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-18 01:42:38 -08:00
Omar Sandoval
4697b4ce0e CI: build vmtest kernels for all architectures
In order to hopefully not have jobs time out, split it into jobs by
architecture and flavor, but limit the parallelism to leave room for
actual test runs. Some of the very old kernel versions don't work on the
other architectures, but we can look into that later.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 17:58:14 -08:00
Omar Sandoval
4f437b395d vmtest.manage: support building other architectures
Note that this will now always use the kernel.org compilers even for the
host architecture.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
cf5cbbe868 vmtest.manage: add --flavor
This limits what flavors we build.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
1b3e58a11d vmtest.manage: apply kernel patches before building
We also need to force the checkout and clean it in order to revert the
patches between versions.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
45e7fc2d3b vmtest.kbuild: add patch to fix build for s390x on Linux 4.9
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
35dcd78943 vmtest.kbuild: also check image_name under arch/$SRCARCH/boot
This is a workaround for AArch64 and Arm on old kernel versions.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
8e86f5a41e vmtest.kbuild: add arch/powerpc/lib/crtsaveres.o to ppc64 packages
Old kernel versions (and new kernel versions built with old binutils)
need this for ppc64 module builds.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
4f5072cb48 vmtest.kbuild: add arch/arm/include/asm/opcodes.h to AArch64 packages
This is required for AArch64 module builds before Linux 4.10.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
441055cf41 vmtest.kbuild: add arch/$SRCARCH/kernel/module.lds to packages
Before Linux kernel commit 596b0474d3d9 ("kbuild: preprocess module
linker script") (in v5.10), AArch64 module builds require it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
b4801e8f7a vmtest.kbuild: add scripts/ld-version.sh to packages
Before Linux kernel commit 05f6bbf2d714 ("kbuild: remove ld-version
macro") (in v5.12), ppc64 module builds require it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
2ec06cfd24 vmtest.kbuild: add patch to allow enabling /proc/kcore on ARM
I don't know yet whether this is safe to upstream, but for now it should
be good enough for testing.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
bf45199682 vmtest.kbuild: add patch for BTFIDS errors with newer pahole
This was patched in recent stable and longterm branches, but we need it
for older branches. We need a few different backports of it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:23:04 -08:00
Omar Sandoval
d2b817964f vmtest.kbuild: add infrastructure for applying kernel patches
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:17:20 -08:00
Omar Sandoval
1798642f0d vmtest.kbuild: set localversion on command line instead of kconfig
This will allow us to apply patches without affecting the localversion.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:17:20 -08:00
Omar Sandoval
f8c63b63a1 vmtest.kbuild: enable BTF for kernel modules
Move vmlinux to the module build directory and copy in resolve_btfids.
This is mainly to silence the annoying warning:

  Skipping BTF generation for /home/osandov/repos/drgn/build/vmtest/x86_64/tmpge3udm_a/drgn_test.ko due to unavailability of vmlinux

But it might also be useful for testing in the future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:17:20 -08:00
Omar Sandoval
07b01acb7f vmtest.config: add Arm definition
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-16 02:17:17 -08:00
Omar Sandoval
1a898961d7 vmtest.config: add s390x definition
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-15 15:41:40 -08:00
Omar Sandoval
3b7b6273ab vmtest.config: add ppc64 definition
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-15 15:41:37 -08:00
Omar Sandoval
fd41642e58 vmtest.config: add AArch64 definition
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
1626cc32f2 vmtest.vm: support other architectures
Add the per-architecture QEMU options to the Architecture class and
allow specifying an architecture in -k.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
5f25c213c1 vmtest.kbuild: add --download-compiler
This will automatically download and use a standard cross compiler
instead of requiring the user to do so.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
7b8872424e vmtest.download: support downloading cross compilers from kernel.org
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
404fb80ca8 vmtest.download: specify kernel architecture per download
This also prepares us for being able to download other things.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
b0ff020a50 vmtest.kbuild: add --architecture option
It defaults to the host architecture (if available). x86_64 is currently
the only option. CROSS_COMPILE must be set in the environment manually.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-10 17:42:37 -08:00
Omar Sandoval
88fabc79c5 vmtest.config: add architecture definition
To prepare for building architectures other than x86-64, add a
description of architectures, and split the architecture-specific kernel
options into it. For now, we still hard-code x86-64 everywhere.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-10 17:15:12 -08:00
Omar Sandoval
df1a17dc11 vmtest: move kconfig and flavor definitions to a new module
vmtest.config will contain configuration/settings for vmtest.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-10 16:56:19 -08:00
Omar Sandoval
94443457aa libdrgn: handle GNU Debug Fission attributes, forms, and opcodes
These are all equivalent to their DWARF 5 counterparts, which we already
support:

* DW_FORM_GNU_addr_index <-> DW_FORM_addrx
* DW_FORM_GNU_str_index <-> DW_FORM_strx
* DW_AT_GNU_addr_base <-> DW_AT_addr_base
* DW_OP_GNU_addr_index <-> DW_OP_addrx
* DW_OP_GNU_const_index <-> DW_OP_constx

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-08 13:25:45 -08:00
Omar Sandoval
02e344a7dd libdrgn: use strswitch for ELF section names
Move the definitions of the section names to a Python script,
gen_elf_sections.py, and use that to generate the enum definitions and a
lookup function. This is preparation for checking for section names with
the .dwo suffix in the future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-08 13:25:22 -08:00
Martin Liska
93cd8ee0b3 mm: introduce new helper function totalram_pages
Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-08 08:07:56 -08:00
Martin Liska
53a639ce70 Introduce loadavg helper.
The helper function returns a tuple with load
averaged over last 1, 5 and 15 minutes.

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-07 14:04:49 -08:00
Omar Sandoval
b05e02d4ec tests: add @skip_unless_have_test_kmod to test_print_annotated_stack()
The test case checks `drgn_test_slob` from the test kmod.

Fixes: 975255f209 ("tests: handle cases without slab support in print_annotated_stack() test")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:51:08 -08:00
Omar Sandoval
cf3c4e736e contrib: vmstat.py: move implementation comment out of docstring
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:44:04 -08:00
Martin Liska
d5c3be72c3 add vmstat.py script to contrib
The script mimics what crash> kmem -V does, the script
reports the following:

Event                                           Count
VM_ZONE_STAT:
NR_FREE_PAGES                                  512147
NR_ZONE_LRU_BASE                               234271
NR_ZONE_INACTIVE_ANON                          234271
NR_ZONE_ACTIVE_ANON                               196
NR_ZONE_INACTIVE_FILE                           97200
NR_ZONE_ACTIVE_FILE                            110611
NR_ZONE_UNEVICTABLE                              1000
NR_ZONE_WRITE_PENDING                              84
NR_MLOCK                                            0
NR_BOUNCE                                           0
NR_ZSPAGES                                          0
NR_FREE_CMA_PAGES                                   0

VM_NODE_STAT:
NR_LRU_BASE                                    234322
NR_INACTIVE_ANON                               234322
NR_ACTIVE_ANON                                    196
NR_INACTIVE_FILE                                97200
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:37:19 -08:00
Omar Sandoval
b51f5a3c31 drgn.helpers.common.format: add number_to_binary_units()
Martin Liška added something like this for PR #257. As he pointed out,
it'd be nice to have this available in general. I copied my
implementation from
https://github.com/osandov/osandov-linux/blob/master/scripts/xfs_rt_debug.py.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-01 13:18:16 -08:00
Omar Sandoval
52c0de0c67 drgn.cli: reorder REPL initialization
First, call user-provided callbacks before changing any global state.
Second, only write the history file if we make it to code.interact().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-01 10:17:14 -08:00
Stephen Brennan
c24ba99c8c cli: Separate the main function from the REPL
It's quite useful to run drgn's interactive REPL from a user-provided
script. One reason is saving the drgn core dump and debuginfo setup into
a script to more easily start analysis. Another might be to replace
drgn's debuginfo loading scheme with one customized to a different
environment. Or, a script might want to handle errors by allowing an
interactive user to examine the program themselves.

To serve all of these cases and more, separate out the logic of running
the drgn REPL from the internal logic relating to argument parsing,
choosing the correct target, and loading debuginfo. While this may seem
like a simple case of code.interact, there are several important
internal features drgn provides in its CLI: a custom displayhook, a
custom readline completer, a history file, and of course the logic to
import and include the proper drgn APIs and helpers for a core dump.

This means creating a run_interactive() function and moving the cli
module out of the drgn.internal package.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-02-01 09:30:02 -08:00
Martin Liska
55e098b560 tests: add test for sock_cgroup_ptr function
Related to: #253.

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-01-31 07:42:52 -08:00
Stephen Brennan
9113c1ba51 scripts: Allow building just one Python release
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-01-30 12:20:15 -08:00
Omar Sandoval
f0beba13e2 vmtest: kbuild: enable net_cls cgroups
For the sock_cgroup_ptr() test case in #255, we need
CONFIG_SOCK_CGROUP_DATA to be selected. Since Linux 4.10, we get that
from CONFIG_CGROUP_BPF, but before that, we need either
CONFIG_CGROUP_NET_CLASSID or CONFIG_CGROUP_NET_PRIO. The former appears
to be slightly smaller than the latter, so let's enable that one.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-30 10:30:27 -08:00
Stephen Brennan
e5f10c68a8 pre-commit: Update isort version to 5.12.0
Currently on Ubuntu 22.04 LTS, pre-commit hook installation is broken
for isort, with an error that can be seen at [1]. The solution is to
update isort to 5.12.0.

[1]: https://github.com/PyCQA/isort/issues/2077

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-01-30 10:24:41 -08:00
Omar Sandoval
9ee9877727 CI: cancel previous runs when PR is force-pushed
This way, older versions don't block the queue for newer versions and
contributors get faster feedback on their latest version.

Based on
https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-27 11:29:02 -08:00
Martin Liska
7b0cdcf4a5 port contrib/tcp_sock.py to v5.19+
Since Linux kernel commit cae3873c5b3a ("net: inet: Retire port only
listening_hash") (in v5.19), listening_hash is removed and we need
to iterate lhash2 table.

The script reports now:
LISTEN                                           [::]:22                                         [::]:0      /system.slice/sshd.service
LISTEN                                        0.0.0.0:22                                      0.0.0.0:0      /system.slice/sshd.service
LISTEN                                          [::1]:631                                        [::]:0      /system.slice/cups.service
LISTEN                                      127.0.0.1:25                                      0.0.0.0:0      /system.slice/postfix.service
LISTEN                                          [::1]:25                                         [::]:0      /system.slice/postfix.service
LISTEN                                      127.0.0.1:631                                     0.0.0.0:0      /system.slice/cups.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:45906  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:48066  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:41128  /system.slice/sshd.service

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 10:24:11 -08:00
Martin Liska
7ab5b48737 fix sock_cgroup_ptr for v.5.15+
Since Linux kernel commit 8520e224f547 ("bpf, cgroups: Fix
cgroup v2 fallback on v1/v2 mixed mode") (in v5.15), the sock_cgroup_data
contains directly cgroup member (of struct cgroup * type).

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 10:12:42 -08:00
Martin Liska
b86417c8a2 add mount.py contrib script
Provides crash-like output:

Mount            Type         Devname      Dirname
ffff8fed001d8500 rootfs       rootfs       /
ffff8fed06a197c0 proc         proc         /proc
ffff8fed06a192c0 sysfs        sysfs        /sys
ffff8fed06a18c80 devtmpfs     devtmpfs     /dev
ffff8fed06a18b40 securityfs   securityfs   /sys/kernel/security
ffff8fed06a19cc0 tmpfs        tmpfs        /dev/shm
ffff8fed06a18500 devpts       devpts       /dev/pts
ffff8fed06a18dc0 tmpfs        tmpfs        /run
...

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 09:56:57 -08:00
Martin Liska
724d15563d enhance ps
New output:

PID     PPID    CPU  ST COMM
1       0       4    S  systemd
2       0       13   S  [kthreadd]
3       2       0    I  [rcu_gp]
4       2       0    I  [rcu_par_gp]
5       2       0    I  [slub_flushwq]
6       2       0    I  [netns]
8       2       0    I  [kworker/0:0H]
10      2       0    I  [mm_percpu_wq]
11      2       0    I  [rcu_tasks_kthre]
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-01-27 08:19:50 -08:00
Stephen Brennan
2bb0f9861c drgn.helpers.linux.slab: Handle SLUB freelist dereference without swab()
Linux commit 1ad53d9fa3f6 ("slub: improve bit diffusion for freelist ptr
obfuscation"), adds a swab() into the freelist_ptr() calculation.
Unfortunately we can't detect this except by trial and error. The commit
was added in 5.7 and has been included in stable backports, which means
that pre-5.7 kernels which haven't recently been updated may still have
this behavior. Add in logic to do the trial and error in order to
support this oddity.

Reported-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-01-26 13:55:30 -08:00