Skip to content

Commit

Permalink
virtme: switch to virtme-ng
Browse files Browse the repository at this point in the history
'virtme' is no longer maintained, we had to fork it to fix issues [1].

The new 'virtme-ng' brings fixes, new features, and performances
improvement, especially for the disk IO [2].

Note that three workarounds are currently needed:
 - The new init in rust cannot be used [3].
 - The .config needs to be removed [4].
 - The whole rootfs is mounted in rw instead of only the workdir to be
   able to used virtiofs (faster) instead of 9p. But that's OK, our
   scripts are launched from a docker where only the workdir is mounted.
   Maybe even easier like that.

There are new dependences, but it is still light. 'udev' has been added
to avoid a warning, but I don't think we need it.

Link: https://github.com/matttbe/virtme [1]
Link: https://lwn.net/Articles/951313/ [2]
Link: arighi/virtme-ng#90 [3]
Link: https://github.com/arighi/virtme-ng/pulls/91 [4]
Closes: multipath-tcp/mptcp_net-next#472
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed Mar 14, 2024
1 parent 6cb159e commit 0c54a94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
15 changes: 6 additions & 9 deletions Dockerfile
Expand Up @@ -10,7 +10,8 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential libncurses5-dev gcc libssl-dev bc bison automake \
libelf-dev flex git curl tar hashalot qemu-kvm sudo expect \
python3 python3-pkg-resources busybox \
python3 python3-pip python3-pkg-resources file virtiofsd \
busybox-static coreutils python3-requests libvirt-clients udev \
iputils-ping ethtool klibc-utils kbd rsync ccache netcat-openbsd \
ca-certificates gnupg2 net-tools kmod \
libdbus-1-dev libnl-genl-3-dev libibverbs-dev \
Expand All @@ -29,14 +30,6 @@ RUN apt-get update && \
&& \
apt-get clean

# virtme
ARG VIRTME_GIT_URL="https://github.com/matttbe/virtme.git"
ARG VIRTME_GIT_SHA="57c440a1dce4476638d67a2d1aead5bdcced0de7" # include a fix for modules on linux >= 6.2 and QEmu > 6
RUN cd /opt && \
git clone "${VIRTME_GIT_URL}" && \
cd virtme && \
git checkout "${VIRTME_GIT_SHA}"

# byobu (not to have a dep to iproute2)
ARG BYOBU_URL="https://github.com/dustinkirkland/byobu/archive/refs/tags/6.12.tar.gz"
ARG BYOBU_SUM="abb000331858609dfda9214115705506249f69237625633c80487abe2093dd45 byobu.tar.gz"
Expand Down Expand Up @@ -77,6 +70,10 @@ RUN cd /opt && \
cd .. && \
rm -rf "sparse"

# Virtme NG
ARG VIRTME_NG_VERSION="1.22"
RUN pip3 install --break-system-packages virtme-ng=="${VIRTME_NG_VERSION}"

# iproute
ARG IPROUTE2_GIT_URL="https://git.kernel.org/pub/scm/network/iproute2/iproute2.git"
ARG IPROUTE2_GIT_SHA="v6.8.0"
Expand Down
39 changes: 19 additions & 20 deletions entrypoint.sh
Expand Up @@ -107,19 +107,20 @@ mkdir -p \
"${VIRTME_PERF_DIR}" \
"${CCACHE_DIR}"

VIRTME_PROG_PATH="/opt/virtme"
VIRTME_CONFIGKERNEL="${VIRTME_PROG_PATH}/virtme-configkernel"
VIRTME_RUN="${VIRTME_PROG_PATH}/virtme-run"
VIRTME_CONFIGKERNEL="virtme-configkernel"
VIRTME_RUN="virtme-run"
VIRTME_RUN_OPTS_DEFAULT=(
--arch "${VIRTME_ARCH}"
--name "mptcpdev" # hostname
--net
--no-virtme-ng-init # see https://github.com/arighi/virtme-ng/issues/90
--memory 2048M
--kdir "${VIRTME_BUILD_DIR}"
--mods=auto
--rwdir "."
--rw # Don't use "rwdir", it will use 9p ; in a container, we can use rw
--pwd
--show-command
--verbose --show-boot-console
--kopt mitigations=off
)

Expand Down Expand Up @@ -317,13 +318,18 @@ _add_symlink() {
}

# $1: normal/expect ; $2: mode ; [rest: extra kconfig]
gen_kconfig() { local type mode kconfig=() rc=0
gen_kconfig() { local type mode kconfig=() vck rc=0
type="${1}"
mode="${2}"
shift 2

log_section_start "Generate kernel config"

vck=(--arch "${VIRTME_ARCH}" --defconfig --custom "${SELFTESTS_CONFIG}")

# workaround for vng 1.22: https://github.com/arighi/virtme-ng/pull/91
rm -f "${VIRTME_KCONFIG}"

if [ "${mode}" = "debug" ]; then
kconfig+=(
-e NET_NS_REFCNT_TRACKER # useful for 'net' tests
Expand All @@ -332,13 +338,11 @@ gen_kconfig() { local type mode kconfig=() rc=0
-e BOOTPARAM_HUNG_TASK_PANIC # instead of blocking
)

_make_o defconfig debug.config || rc=${?}
vck+=(--custom kernel/configs/debug.config)
else
# low-overhead sampling-based memory safety error detector.
# Only in non-debug: KASAN is more precise
kconfig+=(-e KFENCE)

_make_o defconfig "${VIRTME_ARCH}_defconfig" || rc=${?}
fi

if [ "${type}" = "expect" ]; then
Expand All @@ -357,9 +361,7 @@ gen_kconfig() { local type mode kconfig=() rc=0

# We need more debug info but it is slow to generate
if [ "${mode}" = "btf" ]; then
kconfig+=(-e DEBUG_INFO_BTF)
# Extra options are needed for bpftests
./scripts/kconfig/merge_config.sh -m "${VIRTME_KCONFIG}" "${BPFTESTS_CONFIG}"
vck+=(--custom "${BPFTESTS_CONFIG}")
kconfig+=(-e DEBUG_INFO_BTF_MODULES -e MODULE_ALLOW_BTF_MISMATCH)
# Fix ./include/linux/if.h:28:10: fatal error:
# sys/socket.h: no such file or directory
Expand Down Expand Up @@ -404,10 +406,7 @@ gen_kconfig() { local type mode kconfig=() rc=0
kconfig+=("${@}")

# KBUILD_OUTPUT is used by virtme
"${VIRTME_CONFIGKERNEL}" --arch "${VIRTME_ARCH}" --update || rc=${?}

# Extra options are needed for kselftests
./scripts/kconfig/merge_config.sh -m "${VIRTME_KCONFIG}" "${SELFTESTS_CONFIG}" || rc=${?}
"${VIRTME_CONFIGKERNEL}" "${vck[@]}" || rc=${?}

./scripts/config --file "${VIRTME_KCONFIG}" "${kconfig[@]}" || rc=${?}

Expand Down Expand Up @@ -1095,13 +1094,14 @@ EOF
set timeout "${VIRTME_EXPECT_BOOT_TIMEOUT}"
spawn "${VIRTME_RUN_SCRIPT}"
# or with the new init: virtme-ng-init: initialization done
expect {
"virtme-init: console is ttyS0\r" {
send_user "Waiting for the console to be ready\n"
"virtme-init: Setting hostname to mptcpdev...\r" {
send_user "Waiting for the virtme-init to be ready\n"
send "\r"
} timeout {
send_user "\n$(log_section_end)"
send_user "Timeout ttyS0: stopping\n"
send_user "Timeout virtme-init: stopping\n"
exit 1
} eof {
send_user "\n$(log_section_end)"
Expand Down Expand Up @@ -1158,8 +1158,7 @@ expect eof
EOF
chmod +x "${VIRTME_RUN_EXPECT}"

# for an unknown reason, we cannot use "--script-sh", qemu is not
# started, no debug. As a workaround, we use expect.
# We could use "--script-sh", but we use expect to catch timeout, etc.
"${VIRTME_RUN_EXPECT}" | tee "${OUTPUT_VIRTME}"
}

Expand Down

0 comments on commit 0c54a94

Please sign in to comment.