]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/vsock: auto-detect kernel for guest VMs
authorBobby Eshleman <bobbyeshleman@meta.com>
Tue, 17 Mar 2026 00:56:15 +0000 (17:56 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 19 Mar 2026 02:28:23 +0000 (19:28 -0700)
When running vmtest.sh inside a nested VM the running kernel may not be
installed on the filesystem at the standard /boot/ or /usr/lib/modules/
paths.

Previously, this would cause vng to fail with "does not exist" since it
could not find the kernel image. Instead, this patch uses --dry-run to
detect if the kernel is available. If not, then we fall back to the
kernel in the kernel source tree. If that fails, then we die.

This way runners, like NIPA, can use vng --run arch/x86/boot/bzImage to
setup an outer VM, and vmtest.sh will still do the right thing setting
up the inner VM.

Due to job control issues in vng, a workaround is used to prevent 'make
kselftest TARGETS=vsock' from hanging until test timeout. A PR has been
placed upstream to solve the issue in vng:

https://github.com/arighi/virtme-ng/pull/453

Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
Link: https://patch.msgid.link/20260316-vsock-vmtest-autodetect-kernel-v2-1-5eec7b4831f8@meta.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/vsock/vmtest.sh

index 86e338886b33a3960b34897f8e65ec0fbdeb306e..9eacb753238a02a7c5cd1f6401fb70e7d70aa27a 100755 (executable)
@@ -415,6 +415,19 @@ terminate_pids() {
        done
 }
 
+vng_dry_run() {
+       # WORKAROUND: use setsid to work around a virtme-ng bug where vng hangs
+       # when called from a background process group (e.g., under make
+       # kselftest). vng save/restores terminal settings using tcsetattr(),
+       # which is not allowed for background process groups because the
+       # controlling terminal is owned by the foreground process group. vng is
+       # stopped with SIGTTOU and hangs until kselftest's timer expires.
+       # setsid works around this by launching vng in a new session that has
+       # no controlling terminal, so tcsetattr() succeeds.
+
+       setsid -w vng --run "$@" --dry-run &>/dev/null
+}
+
 vm_start() {
        local pidfile=$1
        local ns=$2
@@ -441,6 +454,12 @@ vm_start() {
 
        if [[ "${BUILD}" -eq 1 ]]; then
                kernel_opt="${KERNEL_CHECKOUT}"
+       elif vng_dry_run; then
+               kernel_opt=""
+       elif vng_dry_run "${KERNEL_CHECKOUT}"; then
+               kernel_opt="${KERNEL_CHECKOUT}"
+       else
+               die "No suitable kernel found"
        fi
 
        if [[ "${ns}" != "init_ns" ]]; then