manibuilder/anita: Enable KVM when running on x86_64

This requires us to use privileged containers. Although, the QEMU
inside should still provide enough encapsulation, we might want to
disable this in automated environments.

Change-Id: I767287649511b46cd25125bcbceea8a0446fc76b
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/70914
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/util/manibuilder/Makefile b/util/manibuilder/Makefile
index 294bc28..60332c0 100644
--- a/util/manibuilder/Makefile
+++ b/util/manibuilder/Makefile
@@ -57,6 +57,7 @@
 	$(QUIET_TEST)docker rm -f mani_$(call ident,$*) >/dev/null 2>&1 || true
 	$(QUIET_TEST)\
 	docker run \
+		$(MANI_DOCKER_ARGS) \
 		--env IDENT=$(call ident,$*) \
 		--volume manicache:/home/mani/.ccache \
 		--network=manibuilder \
@@ -75,6 +76,7 @@
 	if [ $$(docker ps -a -q -f name=mani_$(call ident,$*)) ]; then \
 		docker commit mani_$(call ident,$*) mani_run/$* && \
 		docker run --rm -it \
+			$(MANI_DOCKER_ARGS) \
 			--env IDENT=$(call ident,$*) \
 			--volume manicache:/home/mani/.ccache \
 			--network=manibuilder \
@@ -84,6 +86,7 @@
 		docker image rm mani_run/$*; \
 	else \
 		docker run --rm -it \
+			$(MANI_DOCKER_ARGS) \
 			--env IDENT=$(call ident,$*) \
 			--volume manicache:/home/mani/.ccache \
 			--network=manibuilder \
diff --git a/util/manibuilder/Makefile.anita b/util/manibuilder/Makefile.anita
index ba8c82d..f5b87ee 100644
--- a/util/manibuilder/Makefile.anita
+++ b/util/manibuilder/Makefile.anita
@@ -50,3 +50,12 @@
 		--build-arg DISK_SIZE=$(QEMU_DISK_SIZE) \
 		--build-arg INSTALL_MEM=$(QEMU_INSTALL_MEM) \
 		--build-arg RUNTIME_MEM=$(QEMU_RUNTIME_MEM)
+
+kvm_arches = \
+	$(if $(filter x86_64,$(shell uname -m)),amd64 i386)
+
+ANITA_KVM_TAGS := $(filter $(addprefix %-,$(kvm_arches)),$(ANITA_TAGS))
+ANITA_KVM_TAGS += $(addsuffix -shell,$(ANITA_KVM_TAGS))
+
+$(ANITA_KVM_TAGS): MANI_DOCKER_ARGS=--privileged
+$(ANITA_KVM_TAGS): MANI_DOCKER_ARGS+=--env ANITA_VMM_ARGS="-enable-kvm"
diff --git a/util/manibuilder/anita-wrapper.sh b/util/manibuilder/anita-wrapper.sh
index 3ff9ee1..495069e 100644
--- a/util/manibuilder/anita-wrapper.sh
+++ b/util/manibuilder/anita-wrapper.sh
@@ -8,11 +8,13 @@
 
 [ -f ${CCACHE} ] || zcat cache.img.gz >${CCACHE}
 
+AV_ARGS="${ANITA_VMM_ARGS} -hdb ${CCACHE}"
+
 if [ $# -eq 0 ]; then
-	exec anita --vmm-args "-hdb ${CCACHE}" --memory-size=${MEM_SIZE} \
+	exec anita --vmm-args "${AV_ARGS}" --memory-size=${MEM_SIZE} \
 		interact ${INST_IMG}
 else
-	exec anita --vmm-args "-hdb ${CCACHE}" --memory-size=${MEM_SIZE} \
+	exec anita --vmm-args "${AV_ARGS}" --memory-size=${MEM_SIZE} \
 		--persist --run ". ./init && manitest \"$*\"" \
 		boot ${INST_IMG}
 fi