Skip to content

Commit

Permalink
Test hypervisor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Oct 4, 2023
1 parent 14f3e66 commit e2e5971
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/hp-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CARTESI_MACHINE=lua ../cartesi-machine.lua

all: host-rootfs.ext2 guest-rootfs.ext2

%.ext2: %.gnutar
genext2fs --faketime --block-size 4096 --readjustment +0 --tarball $< $@

%.gnutar: %.tar
bsdtar -cf $@ --format=gnutar @$<

host-rootfs.tar: host-rootfs.Dockerfile guest-linux.bin lkvm-test.sh
%.tar: %.Dockerfile
docker build --platform=linux/riscv64 --file $< --output type=tar,dest=$@ --progress plain .

clean:
rm -f *.ext2 *.tar *.gnutar

shell:
$(CARTESI_MACHINE) \
--ram-image=host-linux.bin \
--flash-drive=label:root,filename:host-rootfs.ext2 \
--flash-drive=label:guest-root,filename:guest-rootfs.ext2 \
--ram-length=1024Mi \
-i bash

test:
$(CARTESI_MACHINE) \
--ram-image=host-linux.bin \
--flash-drive=label:root,filename:host-rootfs.ext2 \
--flash-drive=label:guest-root,filename:guest-rootfs.ext2 \
--ram-length=1024Mi \
/root/lkvm-test.sh

.PHONY: clean shell test
30 changes: 30 additions & 0 deletions src/hp-test/guest-rootfs.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker.io/docker/dockerfile:1.4
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04

# Update system
RUN <<EOF
apt-get update
apt-get upgrade -y
EOF

# Install busybox
RUN <<EOF
apt-get install -y busybox-static
EOF

# Install emulator tools
RUN <<EOF
apt-get install -y wget
wget -O machine-emulator-tools.deb https://github.com/cartesi/machine-emulator-tools/releases/download/v0.12.0/machine-emulator-tools-v0.12.0.deb
dpkg -i machine-emulator-tools.deb
rm -f machine-emulator-tools.deb
EOF

# Make build more or less reproducible
RUN <<EOF
rm -rf /var/lib/apt/lists/*
rm -rf /var/log/*
EOF

# Hack to disable auto mounting
RUN rm -rf /mnt
62 changes: 62 additions & 0 deletions src/hp-test/host-rootfs.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# syntax=docker.io/docker/dockerfile:1.4
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04

# Update system
RUN <<EOF
apt-get update
apt-get upgrade -y
EOF

# Install busybox
RUN <<EOF
apt-get install -y busybox-static
EOF

# Install emulator tools
RUN <<EOF
apt-get install -y wget
wget -O machine-emulator-tools.deb https://github.com/cartesi/machine-emulator-tools/releases/download/v0.12.0/machine-emulator-tools-v0.12.0.deb
dpkg -i machine-emulator-tools.deb
rm -f machine-emulator-tools.deb
EOF

# Install build tools
RUN <<EOF
apt-get install -y build-essential git
EOF

# Install debugging utilities
RUN <<EOF
apt-get install -y gdb strace
EOF

WORKDIR /root

# Install kvmtool
RUN <<EOF
apt-get install -y libfdt-dev kmod
git clone https://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git
EOF
COPY kvmtool-net-exit.patch .
RUN <<EOF
cd kvmtool
patch -Np1 < ../kvmtool-net-exit.patch
make lkvm-static
install lkvm-static /usr/bin/lkvm
EOF

# Make build more or less reproducible
RUN <<EOF
rm -rf /var/lib/apt/lists/*
rm -rf /var/log/*
EOF

# Hack to disable auto mounting
RUN rm -rf /mnt

# Copy guest linux and rootfs
COPY guest-linux.bin /root

COPY kvm.ko /root
COPY --chmod=755 lkvm-test.sh /root

12 changes: 12 additions & 0 deletions src/hp-test/kvmtool-net-exit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/virtio/net.c b/virtio/net.c
index f09dd0a..4e559cc 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -971,6 +971,7 @@ int virtio_net__exit(struct kvm *kvm)
virtio_net_exec_script(params->downscript, ndev->tap_name);

list_del(&ndev->list);
+ ndev->vdev.ops->exit(kvm, &ndev->vdev);
free(ndev);
}
return 0;
16 changes: 16 additions & 0 deletions src/hp-test/lkvm-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -e
insmod kvm.ko

while true; do
lkvm run \
--network virtio \
--disk /dev/mtdblock1 \
--kernel guest-linux.bin \
--virtio-transport mmio \
--params "\
init=/opt/cartesi/bin/init loglevel=5 splash=no single=yes \
-- \
busybox ip link set dev eth0 up &&
echo booted"
done

0 comments on commit e2e5971

Please sign in to comment.