Commit Graph

77 Commits

Author SHA1 Message Date
Omar Sandoval
48dd87da98 vmtest.download: check actual download length against Content-Length
The CI keeps has been sporadically hitting errors like:

  downloading kernel release 6.0.19-vmtest17.1default to build/vmtest/x86_64/kernel-6.0.19-vmtest17.1default from https://api.github.com/repos/osandov/drgn/releases/assets/91622017
  /*stdin*\ : Read error (39) : premature end
  tar: Unexpected EOF in archive
  tar: Unexpected EOF in archive
  tar: Error is not recoverable: exiting now

The only way I can see this happening is if the download is being
truncated, so add a check (inspired by urllib.request.urlretrieve()).

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-23 15:43:54 -08:00
Omar Sandoval
7a3ddf20d3 vmtest: kbuild: fix typo in comment
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 14:17:11 -08:00
Omar Sandoval
d829775287 vmtest: kbuild: enable Unix sockets
Lots of core tools expect Unix sockets to work. Stephen Brennan recently
hit issue where installing Ksplice on Ubuntu replaced modprobe with a
version that uses Unix sockets, which caused the kernel to call modprobe
to load the Unix socket module, recursively until the kernel's modprobe
limit of 50 was hit.

Enable Unix sockets to avoid other surprises like this. (We'll probably
eventually have drgn helpers for Unix sockets, too.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 14:12:09 -08:00
Omar Sandoval
c9e970c935 vmtest: set raise_for_status=True for GitHub API requests
The vmtest build is silently failing to upload kernel builds. We're not
checking for HTTP errors, so let's see if that provides some
information.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-28 23:24:52 -08:00
Omar Sandoval
c6a24eea6b vmtest: kbuild: prepare for SLOB deprecation in Linux 6.2
CONFIG_SLOB was renamed to CONFIG_SLOB_DEPRECATED during the Linux 6.2
merge window. Let's prepare for that now before rc1 is released.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-14 21:32:40 -08:00
Omar Sandoval
3c76c12ef1 Stop testing Linux 4.4
I wanted to add tests for the radix tree helpers, but found that they
have never worked for Linux 4.4. Linux 4.4 has been EOL for almost a
year, so rather than going out of our way to support it, let's just stop
testing it. I'm not going to go back and remove existing support for
4.4 (yet), but I'm also not going to make sure future changes support
it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-13 15:44:43 -08:00
Omar Sandoval
25aee8f6a1 vmtest: kbuild: enable transparent hugepages
I want to add support for multi-index XArray entries. This requires
CONFIG_XARRAY_MULTI. The easiest way to enable that is by enabling
CONFIG_TRANSPARENT_HUGEPAGE. We'll probably also want to test helpers
for transparent hugepages themselves later, so let's also enable
CONFIG_READ_ONLY_THP_FOR_FS.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-12 19:08:58 -08:00
Omar Sandoval
7cb7ac0fc4 vmtest: kbuild: enable Btrfs, ext4, and XFS
For some upcoming helpers (#218), we're going to want to test against a
few common filesystems.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-01 17:47:19 -08:00
Omar Sandoval
c08f6be52a vmtest: kbuild: add CONFIG_MODULE_UNLOAD=y
I currently have no idea whether the test kmod can actually unload
successfully because the vmtest kernels don't support unloading modules.
It might also be useful to test unloading other modules in the future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-21 11:59:21 -08:00
Omar Sandoval
87b7292aa5 Relicense drgn from GPLv3+ to LGPLv2.1+
drgn is currently licensed as GPLv3+. Part of the long term vision for
drgn is that other projects can use it as a library providing
programmatic interfaces for debugger functionality. A more permissive
license is better suited to this goal. We decided on LGPLv2.1+ as a good
balance between software freedom and permissiveness.

All contributors not employed by Meta were contacted via email and
consented to the license change. The only exception was the author of
commit c4fbf7e589 ("libdrgn: fix for compilation error"), who did not
respond. That commit reverted a single line of code to one originally
written by me in commit 640b1c011d ("libdrgn: embed DWARF index in
DWARF info cache").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-01 17:05:16 -07:00
Omar Sandoval
6cc41dbcf8 vmtest.vm: support running with root directory different from the host
This will be useful for testing different architectures (e.g., by
creating a rootfs with debootstrap) or different userspace environments.
For example, we can test busybox with something like:

  mkdir busyboxroot busyboxroot/bin busyboxroot/tmp
  cp "$(which busybox)" busyboxroot/bin
  busyboxroot/bin/busybox --install busyboxroot/bin
  python3 -Bm vmtest.vm -k '*' -r busyboxroot

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:13:10 -07:00
Omar Sandoval
9e5fb3ef08 vmtest.vm: don't set PYTHON
This is more appropriately done in the test command in setup.py.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:13:10 -07:00
Omar Sandoval
3b6c02107e vmtest: get SYS_kexec_file_load from util.SYS
This still isn't enough to be fully generic since since some
architectures don't support kexec_file_load, especially on older
kernels, and some architectures can't use the vmlinuz directly (e.g.,
AArch64 may need it to be decompressed). But, this is at least cleaner
than hard-coding the number for x86-64.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:08:20 -07:00
Omar Sandoval
b535b8f82e vmtest: don't use BusyBox
We don't specifically need BusyBox; we just need a reasonable Linux
userspace, which we can assume is already available on the host, whether
it's coreutils+util-linux, BusyBox, or something else.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-01 11:23:26 -07:00
Omar Sandoval
1b8d0ae82b vmtest.vm: change to host's working directory by default
The test command does this, and I always end up doing it when I'm doing
manual testing with the vmtest.vm CLI, so let's just do it by default.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-01 10:59:05 -07:00
Omar Sandoval
ca6c2b8734 vmtest: kbuild: add BPF kernel config options
We currently don't have any tests for the BPF helpers or the
bpf_inspect.py tool. As a result, the latter is broken on newer kernel
versions. Before we can add tests, we need the vmtest kernel to support
BPF.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-07-19 23:47:32 -07:00
Omar Sandoval
46367a437a vmtest: kbuild: allow packaging as directory
For local testing with vmtest, we just want an extracted kernel package,
so save the trouble of compressing the package only to extract it and
allow vmtest.kbuild to output the directory directly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-07-06 18:06:18 -07:00
Omar Sandoval
a000eed8f4 vmtest: kbuild: add scripts/check-local-export to module build files
Linux kernel commit 31cb50b5590f ("kbuild: check static EXPORT_SYMBOL*
by script instead of modpost") (in v5.19-rc1) added this script to the
build process, and the latest vmtest kernel build failed without it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-06-06 02:08:23 -07:00
Omar Sandoval
1d766c4e34 vmtest: kbuild: add CONFIG_SLAB_FREELIST_HARDENED=y to kernel config
Since most Linux distros enable this, we should make sure we test it. It
was added for SLUB in Linux kernel commit 2482ddec670f ("mm: add SLUB
free list pointer obfuscation") (in v4.14), so we'll still get test
coverage of the non-hardened codepath while 4.9 is around.

It was also added for SLAB in Linux kernel commit 3404be67bf73
("mm/slab: expand CONFIG_SLAB_FREELIST_HARDENED to include SLAB") (in
v5.9), although that currently doesn't change the in-memory data
structures.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-20 15:33:18 -07:00
Omar Sandoval
1e2ba05059 vmtest: kbuild: exclude .cmd files from package
The include directories contain these dependency files for generated
header files.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-20 15:22:05 -07:00
Omar Sandoval
a3b72e33c8 Fix some more flake8 errors
Several have snuck in since the last time I did this in commit
5541fad063 ("Fix some flake8 errors"). Prepare for adding flake8 to
pre-commit by fixing them.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-17 15:23:42 -07:00
Omar Sandoval
6a3dcad19b tests: add framework for test kernel module
Now that commit d999703f94 ("vmtest: add kernel module build
dependencies to kernel packages") added the files necessary to build a
test kernel module, add the module (currently a stub) and the
scaffolding necessary to build and load it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-16 14:27:35 -07:00
Omar Sandoval
d999703f94 vmtest: add kernel module build dependencies to kernel packages
We have several helpers that are difficult to test because there are no
userspace APIs to test them against. Radix trees, slab objects, and
hlists are a few examples. For lists and rbtrees, luckily we can find
instances of those data structures exposed to userspace in some way, but
this is somewhat brittle.

We'd like a way to be able to unit test directly against kernel code
that sets things up in a way that is easy to test against. The easiest
way to do this is with a custom kernel module.

There are two options for how to enable this:

1. Build the custom kernel module as part of the vmtest kernel build and
   package it with the vmtest kernel package.
2. Include the artifacts needed for kernel module builds in the vmtest
   kernel package, then build the kernel module when running tests.

The latter makes the kernel packages significantly larger (on a build of
v5.18-rc6, 46M -> 53M compressed, 173M -> 217M decompressed), but it has
the huge advantage that it does not require a vmtest kernel rebuild to
add or modify tests. In order to optimize for making it easy to add new
helpers with test cases, this is the approach I chose.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-13 11:05:45 -07:00
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
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
2a132caaee vmtest: elaborate on kernel builds in README
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-09 10:36:31 -08:00
Kevin Svetlitski
32a968deb0 vmtest: only disable SMP for the capture kernel when not using KVM acceleration
Disabling SMP is necessary to work around a bug in QEMU's handling of
the capture kernel, but makes the tests run much slower. However, this
bug only appears to manifest when KVM acceleration is disabled, so the
testing harness has been modified to only disable SMP when this is true.

[Omar: use an environment variable instead of touching a file]
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2022-01-11 17:28:17 -08:00
Kevin Svetlitski
ac2cadabcd Add framework for testing in kdump
Now that the vmtest kernel supports kdump, add a script that can be used
to crash and enter the kdump environment on demand. Use that to crash
after running the normal test suite so that we can run tests against
/proc/vmcore. vmcore tests live in their own directory; presently the
only test is a simple sanity check that ensures we can can attach to
/proc/vmcore.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2022-01-07 14:03:00 -08:00
Omar Sandoval
2a0b4c8848 vmtest: also add kexec_file_load() syscall config options
We can avoid the need for the kexec tool if we load the kdump kernel
ourselves, which is much easier with kexec_file_load(). Add the config
options to enable it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-21 23:32:49 -08:00
Omar Sandoval
ba93fd5a71 vmtest: add kdump kernel config options
We would like to test drgn against kernel core dumps (e.g., for #129).
One option would be to include some vmcore files in the repository and
test against those. But those can be huge, and we'd need a lot of them
to test different kernel versions. Instead, we can run vmtest, enable
kdump, and trigger a crash. To do that, we first need to enable a few
kernel config options.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-21 17:39:32 -08:00
Omar Sandoval
92f25e2974 vmtest: enable logging when running vmtest.vm CLI
Specifically, we want logs from vmtest.download.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-21 14:34:45 -08:00
Omar Sandoval
0f68cd44e2 vmtest: mount /dev/shm in VM
PR #133 adds a test case using multiprocessing.Barrier(), which needs
/dev/shm.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-17 13:01:18 -08:00
Omar Sandoval
c0d8709b45 Update copyright headers to Meta
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-21 15:59:44 -08:00
Omar Sandoval
801f9d645c tests: improve cgroup helper tests
These haven't been running in vmtest since they were added. Enable
cgroup2 in vmtest and rework the cgroup tests to create cgroups that we
can test with.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-09-02 16:05:46 -07:00
Omar Sandoval
62efd2aab3 vmtest: use virtio-rng
Now that the kernel module is enabled, let's enable the device and load
the module.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-09-02 09:31:47 -07:00
Omar Sandoval
ce845ad340 vmtest: add virtio-rng and cgroup Kconfig options
We're seeing some hangs waiting for entropy when running tests, so let's
enable the virtio-rng module. While we're doing a rebuild, we might as
well enable cgroups so that we can finally run those tests.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-09-02 09:12:19 -07:00
Omar Sandoval
6ee7ba4cb1 vmtest: add some Traffic Control config options
We need these to test #117.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-09-01 14:13:34 -07:00
Omar Sandoval
5977dcc1e8 vmtest: use larger msize for 9pfs mounts
QEMU warns about the default 8k msize
(https://wiki.qemu.org/Documentation/9psetup#msize). I wasn't able to
measure any performance difference, but bump it to 1MiB to silence the
warning.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-16 12:47:05 -07:00
Omar Sandoval
333652dba3 vmtest: fix deprecated QEMU option warnings
QEMU 6.0 deprecated boolean options without an explicit =on or =off
(https://wiki.qemu.org/ChangeLog/6.0#New_deprecated_options_and_features).
Change readonly to readonly=on.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-16 12:43:14 -07:00
Omar Sandoval
5541fad063 Fix some flake8 errors
Mainly unused imports, unused variables, unnecessary f-strings, and
regex literals missing the r prefix. I'm not adding it to the CI linter
because it's too noisy, though.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-11 14:52:44 -07:00
Omar Sandoval
50e3cf936a vmtest: add CONFIG_NUMA=y
We're adding NUMA node mask helpers in #107, so make sure we can run
them.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-07-29 17:04:52 -07:00
Omar Sandoval
68fae425b6 vmtest: manage: get mainline releases from mainline linux repository
I incorrectly assumed that the stable repo would have the mainline tags
soon after they were released, but this is not the case. We also need to
check the mainline repo for tags and fetch them from the mainline repo.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-10 10:55:06 -07:00
Omar Sandoval
47ab6142d5 vmtest: fix vmtest.vm -k
The argument to download_kernels() is an iterable of kernels, but we're
passing it a single kernel string.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-06 01:35:27 -07:00
Omar Sandoval
abeea40b8a vmtest: fix cleanup of temporary directory on Python < 3.8
In Python before 3.8, tempfile.TemporaryDirectory.cleanup() fails when
the directory doesn't exist. Since we rename the temporary download
directory to its final name, this always fails. Switch to using
tempfile.mkdtemp() directly instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 13:48:35 -07:00
Omar Sandoval
a15de13a7c vmtest: handle exceptions when downloading in thread
Otherwise, an exception causes setup.py test -K to hang.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 13:19:44 -07:00
Omar Sandoval
841a3dae88 Move vmtest assets to GitHub releases
As noted by commit 738261290f ("CI: temporarily disable vmtest"),
vmtest was generating too much traffic to the Dropbox shared folder that
hosted vmtest kernels. Instead, we can store kernel packages as GitHub
release assets. Update the code for downloading and uploading vmtest
assets, and also add a scheduled GitHub action to build new kernels
every Monday so I don't have to remember to do it manually.

This also drops vmtest support for 5.6-5.9, which now fail to build with
newer binutils due to the issue fixed in Linux kernel commit
1d489151e9f9 ("objtool: Don't fail on missing symbol table").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 00:28:56 -07:00
Omar Sandoval
a4b9d68a8c Use GPL-3.0-or-later license identifier instead of GPL-3.0+
Apparently the latter is deprecated and the former is preferred.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-03 01:10:35 -07:00