From 24f1ae9aea36e648666a1341c2e890c93f84523c Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Tue, 20 Aug 2024 23:20:49 +0200 Subject: [PATCH 1/9] vmctl: add missing spdx license id Add SPDX GPL-3.0-or-later license identifier to the files not including it except for the files in the examples/ directory. Signed-off-by: Daniel Gomez --- Makefile | 1 + contrib/generate-cloud-config-seed-freebsd.sh | 1 + contrib/generate-cloud-config-seed.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/Makefile b/Makefile index b06e6f4..28323a2 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: GPL-3.0-or-later SHELLCHECK := $(shell command -v shellcheck 2>/dev/null) check: diff --git a/contrib/generate-cloud-config-seed-freebsd.sh b/contrib/generate-cloud-config-seed-freebsd.sh index 24a0eb2..26d0fbd 100755 --- a/contrib/generate-cloud-config-seed-freebsd.sh +++ b/contrib/generate-cloud-config-seed-freebsd.sh @@ -1,4 +1,5 @@ #!/bin/bash +# SPDX-License-Identifier: GPL-3.0-or-later set -euo pipefail diff --git a/contrib/generate-cloud-config-seed.sh b/contrib/generate-cloud-config-seed.sh index 79959c5..9a3e52f 100755 --- a/contrib/generate-cloud-config-seed.sh +++ b/contrib/generate-cloud-config-seed.sh @@ -1,4 +1,5 @@ #!/bin/bash +# SPDX-License-Identifier: GPL-3.0-or-later set -euo pipefail From a42facbae6afcfa5575315892edc714520415989 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Tue, 20 Aug 2024 23:30:05 +0200 Subject: [PATCH 2/9] examples: aarch64-virt-base: source common.conf Parse common.conf in aarch64-virt-base as well. Fixes unbound default_nvme_ns_extra when using with nvme.conf. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index e983305..d4f051b 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -16,6 +16,10 @@ # Extra parameters to add to the kernel "command # line". +if [[ -f "common.conf" ]]; then + source "common.conf" +fi + QEMU_SYSTEM_BINARY="$HOME/work/src/qemu/build/aarch64-softmmu/qemu-system-aarch64" GUEST_BOOT_BASE="img/debian-11-genericcloud-arm64.qcow2" From d1475f3b97d32f71921ee99e27c628ba9a7010ce Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Tue, 20 Aug 2024 23:36:26 +0200 Subject: [PATCH 3/9] examples: add nvme-aarch64.conf Add nvme-aarch64 configuration file and promote $GUEST_BOOT_BASE to the main configuration file, so it can be overwritten. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 2 +- examples/vm/nvme-aarch64.conf | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 examples/vm/nvme-aarch64.conf diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index d4f051b..911e9cb 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -21,7 +21,7 @@ if [[ -f "common.conf" ]]; then fi QEMU_SYSTEM_BINARY="$HOME/work/src/qemu/build/aarch64-softmmu/qemu-system-aarch64" -GUEST_BOOT_BASE="img/debian-11-genericcloud-arm64.qcow2" +: "${GUEST_BOOT_BASE:="img/debian-11-genericcloud-arm64.qcow2"}" : "${GUEST_DISPLAY:="1"}" : "${GUEST_CPU:="cortex-a57"}" diff --git a/examples/vm/nvme-aarch64.conf b/examples/vm/nvme-aarch64.conf new file mode 100644 index 0000000..212098f --- /dev/null +++ b/examples/vm/nvme-aarch64.conf @@ -0,0 +1,27 @@ +#!/bin/bash + +GUEST_BOOT_BASE="img/debian-13-genericcloud-arm64.qcow2" + +source "aarch64-virt-base.conf" + +_setup_nvme_aarch64() { + # setup basevm + _setup_aarch64_virt_base + + # pcie root port + qemu_pcie_add_root_port "pcie_root_port0" \ + --chassis 1 --slot 0 + + # nvme controller + qemu_nvme_add_ctrl "nvme0" \ + --serial "deadbeef" \ + --port "pcie_root_port0" \ + --extra "mdts=7" + + # nvme namespace + qemu_nvme_add_ns "nvm" \ + --nsid "1" \ + --ctrl "nvme0" \ + --size "1G" \ + --extra "$default_nvme_ns_extra" +} From 16b2027fd91e6ce29b17cd8a352fbc63a648496f Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Tue, 20 Aug 2024 23:44:42 +0200 Subject: [PATCH 4/9] examples: resolve qemu bin automatically Use which (1) to locate QEMU system binaries. Locate both binaries in their respective top level config files and assign the binary variable in the system architecture configuration file. Do not put this in common to avoid systems without all the binaries available. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 2 +- examples/vm/common.conf | 3 +-- examples/vm/nvme-aarch64.conf | 1 + examples/vm/nvme.conf | 2 ++ examples/vm/x86_64-q35-base.conf | 2 ++ 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index 911e9cb..7ce6a31 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -20,7 +20,7 @@ if [[ -f "common.conf" ]]; then source "common.conf" fi -QEMU_SYSTEM_BINARY="$HOME/work/src/qemu/build/aarch64-softmmu/qemu-system-aarch64" +QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_AARCH64} : "${GUEST_BOOT_BASE:="img/debian-11-genericcloud-arm64.qcow2"}" : "${GUEST_DISPLAY:="1"}" diff --git a/examples/vm/common.conf b/examples/vm/common.conf index efd6009..595a524 100644 --- a/examples/vm/common.conf +++ b/examples/vm/common.conf @@ -1,8 +1,7 @@ #!/bin/bash # vmctl run parameters -QEMU_SYSTEM_BINARY="/usr/local/bin/qemu-system-x86_64" -QEMU_IMG="/usr/local/bin/qemu-img" +QEMU_IMG=$(/usr/bin/which qemu-img) GUEST_KERNEL_APPEND_EXTRA="audit=0" GUEST_KERNEL_BOOTDEV="/dev/vda1" diff --git a/examples/vm/nvme-aarch64.conf b/examples/vm/nvme-aarch64.conf index 212098f..25f2e8a 100644 --- a/examples/vm/nvme-aarch64.conf +++ b/examples/vm/nvme-aarch64.conf @@ -1,5 +1,6 @@ #!/bin/bash +QEMU_SYSTEM_AARCH64=$(/usr/bin/which qemu-system-aarch64) GUEST_BOOT_BASE="img/debian-13-genericcloud-arm64.qcow2" source "aarch64-virt-base.conf" diff --git a/examples/vm/nvme.conf b/examples/vm/nvme.conf index a8c7a0d..5974f31 100644 --- a/examples/vm/nvme.conf +++ b/examples/vm/nvme.conf @@ -1,5 +1,7 @@ #!/bin/bash +QEMU_SYSTEM_X86_64=$(/usr/bin/which qemu-system-x86_64) + source "x86_64-q35-base.conf" _setup_nvme() { diff --git a/examples/vm/x86_64-q35-base.conf b/examples/vm/x86_64-q35-base.conf index e003bbb..4795a51 100644 --- a/examples/vm/x86_64-q35-base.conf +++ b/examples/vm/x86_64-q35-base.conf @@ -18,6 +18,8 @@ if [[ -f "common.conf" ]]; then source "common.conf" fi +QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_X86_64} + : "${GUEST_DISPLAY:="0"}" : "${GUEST_VIOMMU:="1"}" : "${GUEST_CPU:="host"}" From c7e145218a7dd14a4510ded78c57476ec117ba2a Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Tue, 20 Aug 2024 23:51:58 +0200 Subject: [PATCH 5/9] examples: aarch64-virt-base: add edk2 fd variable Add $QEMU_EDK2_AARCH64 variable to retrieve the UEFI EDK2 firmware binary from the common.conf file. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 2 +- examples/vm/common.conf | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index 7ce6a31..ae99975 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -45,7 +45,7 @@ _setup_aarch64_virt_base() { QEMU_PARAMS+=("-smp" "1") QEMU_PARAMS+=("-m" "$GUEST_MEMORY") - QEMU_PARAMS+=("-bios" "/usr/share/edk2-armvirt/aarch64/QEMU_EFI.fd") + QEMU_PARAMS+=("-bios" "$QEMU_EDK2_AARCH64") #QEMU_PARAMS+=("-pflash" "/tmp/flash0.img") #QEMU_PARAMS+=("-pflash" "/tmp/flash1.img") diff --git a/examples/vm/common.conf b/examples/vm/common.conf index 595a524..fd5e9af 100644 --- a/examples/vm/common.conf +++ b/examples/vm/common.conf @@ -2,6 +2,7 @@ # vmctl run parameters QEMU_IMG=$(/usr/bin/which qemu-img) +QEMU_EDK2_AARCH64="/usr/share/edk2-armvirt/aarch64/QEMU_EFI.fd" GUEST_KERNEL_APPEND_EXTRA="audit=0" GUEST_KERNEL_BOOTDEV="/dev/vda1" From f6f5d364dced282dfded1809ed3bddb8a573fb14 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Wed, 21 Aug 2024 00:19:21 +0200 Subject: [PATCH 6/9] examples: aarch64-virt-base: use virtualization Switch emulation to virtualization by setting cpu argument to host. Add acceleration argument and default it to KVM. It can be overwritten with $GUEST_ACCEL var. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index ae99975..af6d3bd 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -24,8 +24,9 @@ QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_AARCH64} : "${GUEST_BOOT_BASE:="img/debian-11-genericcloud-arm64.qcow2"}" : "${GUEST_DISPLAY:="1"}" -: "${GUEST_CPU:="cortex-a57"}" +: "${GUEST_CPU:="host"}" : "${GUEST_MEMORY:="2G"}" +: "${GUEST_ACCEL:="kvm"}" : "${GUEST_NET_USER_HOSTFWDS:="tcp::${GUEST_SSH_PORT}-:22"}" : "${GUEST_BOOT:="$GUEST_BOOT_BASE"}" : "${GUEST_KERNEL_IMAGE:="arch/arm64/boot/Image"}" @@ -40,7 +41,7 @@ _setup_aarch64_virt_base() { QEMU_PARAMS+=("-nographic") fi - QEMU_PARAMS+=("-machine" "virt") + QEMU_PARAMS+=("-machine" "virt,accel=$GUEST_ACCEL,kernel-irqchip=split") QEMU_PARAMS+=("-cpu" "$GUEST_CPU") QEMU_PARAMS+=("-smp" "1") QEMU_PARAMS+=("-m" "$GUEST_MEMORY") From ae462a22ca9c3b14af38debec9e98684611c4586 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Wed, 21 Aug 2024 00:45:03 +0200 Subject: [PATCH 7/9] examples: add guest gdb port variable Add support to accept guest gdb connection with '-gdb tcp::' using $GUEST_GDB_PORT variable. Apply option to existing configs. Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 5 +++++ examples/vm/x86_64-q35-base.conf | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index af6d3bd..7d66b77 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -27,6 +27,7 @@ QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_AARCH64} : "${GUEST_CPU:="host"}" : "${GUEST_MEMORY:="2G"}" : "${GUEST_ACCEL:="kvm"}" +: "${GUEST_GDB_PORT:=""}" : "${GUEST_NET_USER_HOSTFWDS:="tcp::${GUEST_SSH_PORT}-:22"}" : "${GUEST_BOOT:="$GUEST_BOOT_BASE"}" : "${GUEST_KERNEL_IMAGE:="arch/arm64/boot/Image"}" @@ -50,6 +51,10 @@ _setup_aarch64_virt_base() { #QEMU_PARAMS+=("-pflash" "/tmp/flash0.img") #QEMU_PARAMS+=("-pflash" "/tmp/flash1.img") + if [[ -n $GUEST_GDB_PORT ]]; then + QEMU_PARAMS+=("-gdb" "tcp::$GUEST_GDB_PORT") + fi + # simple user-level networking QEMU_PARAMS+=("-netdev" "user,id=net0,hostfwd=${GUEST_NET_USER_HOSTFWDS}") QEMU_PARAMS+=("-device" "virtio-net-pci,netdev=net0") diff --git a/examples/vm/x86_64-q35-base.conf b/examples/vm/x86_64-q35-base.conf index 4795a51..6842d3c 100644 --- a/examples/vm/x86_64-q35-base.conf +++ b/examples/vm/x86_64-q35-base.conf @@ -25,6 +25,7 @@ QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_X86_64} : "${GUEST_CPU:="host"}" : "${GUEST_SMP:="4"}" : "${GUEST_MEMORY:="8G"}" +: "${GUEST_GDB_PORT:=""}" : "${GUEST_NET_USER_HOSTFWDS:="tcp::${GUEST_SSH_PORT}-:22"}" : "${GUEST_BOOT_BASE:="img/base.qcow2"}" : "${GUEST_BOOT:="$GUEST_BOOT_BASE"}" @@ -46,6 +47,10 @@ _setup_x86_64_q35_base() { QEMU_PARAMS+=("-smp" "$GUEST_SMP") QEMU_PARAMS+=("-m" "$GUEST_MEMORY") + if [[ -n $GUEST_GDB_PORT ]]; then + QEMU_PARAMS+=("-gdb" "tcp::$GUEST_GDB_PORT") + fi + # guest iommu if [[ $GUEST_VIOMMU -ne 0 ]]; then QEMU_PARAMS+=("-device" "intel-iommu,intremap=on") From 731a9fb8d22f482a9a2c89f947a57f91d31ed687 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Thu, 29 Aug 2024 08:54:04 +0200 Subject: [PATCH 8/9] examples: add nvme-cortext-a57.conf nvme-aarch64 configuration example is now intented to be used as virtualization. Add cortex-a57 emulation example with had before but with a separate configuration file overwriting the GUEST_CPU. Signed-off-by: Daniel Gomez --- examples/vm/nvme-cortex-a57.conf | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/vm/nvme-cortex-a57.conf diff --git a/examples/vm/nvme-cortex-a57.conf b/examples/vm/nvme-cortex-a57.conf new file mode 100644 index 0000000..fb32152 --- /dev/null +++ b/examples/vm/nvme-cortex-a57.conf @@ -0,0 +1,28 @@ +#!/bin/bash + +GUEST_BOOT_BASE="img/debian-13-genericcloud-arm64.qcow2" +GUEST_CPU="cortex-a57" + +source "aarch64-virt-base.conf" + +_setup_nvme_aarch64() { + # setup basevm + _setup_aarch64_virt_base + + # pcie root port + qemu_pcie_add_root_port "pcie_root_port0" \ + --chassis 1 --slot 0 + + # nvme controller + qemu_nvme_add_ctrl "nvme0" \ + --serial "deadbeef" \ + --port "pcie_root_port0" \ + --extra "mdts=7" + + # nvme namespace + qemu_nvme_add_ns "nvm" \ + --nsid "1" \ + --ctrl "nvme0" \ + --size "1G" \ + --extra "$default_nvme_ns_extra" +} From 395414bb0775c14685d5656dc9135e71cf0e3ba1 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Thu, 29 Aug 2024 14:06:21 +0200 Subject: [PATCH 9/9] examples: aarch64-virt-base: fix display support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix display support. Switch to disabled by default if no display backend is set. $GUEST_DISPLAY configures QEMU -display if configured (variable not empty). Empty variable will use -nographic. This also uses -nodefaults regardless of the setting of the display to replicate the same setup in x86_64 example. From documentation [1]: Don’t create default devices. Normally, QEMU sets the default devices like serial port, parallel port, virtual console, monitor device, VGA adapter, floppy and CD-ROM drive and others. The -nodefaults option will disable all those default devices. [1] Manual for -nodefaults. https://www.qemu.org/docs/master/system/qemu-manpage.html https://www.qemu.org/docs/master/system/invocation.html This has been tested only on macOS with cocoa as $GUEST_DISPLAY. qemu-system-aarch -display help Available display backend types: none curses cocoa dbus Display backend types in Debian arm64 machines are: qemu-system-aarch -display help Available display backend types: none gtk sdl egl-headless curses spice-app dbus Signed-off-by: Daniel Gomez --- examples/vm/aarch64-virt-base.conf | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/vm/aarch64-virt-base.conf b/examples/vm/aarch64-virt-base.conf index 7d66b77..7be1be9 100644 --- a/examples/vm/aarch64-virt-base.conf +++ b/examples/vm/aarch64-virt-base.conf @@ -4,7 +4,7 @@ # # Configuration variables # -# GUEST_DISPLAY Set to '1' to enable graphical output +# GUEST_DISPLAY Display option (QEMU -display parameter). # GUEST_VIOMMU Set to '1' to add a virtual IOMMU to the machine # GUEST_CPU CPU model (QEMU -cpu paramater, default: 'host') # GUEST_SMP SMP configuration (QEMU -smp parameter, default: '4') @@ -23,7 +23,7 @@ fi QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_AARCH64} : "${GUEST_BOOT_BASE:="img/debian-11-genericcloud-arm64.qcow2"}" -: "${GUEST_DISPLAY:="1"}" +: "${GUEST_DISPLAY:=""}" : "${GUEST_CPU:="host"}" : "${GUEST_MEMORY:="2G"}" : "${GUEST_ACCEL:="kvm"}" @@ -35,11 +35,17 @@ QEMU_SYSTEM_BINARY=${QEMU_SYSTEM_AARCH64} : "${GUEST_KERNEL_CONSOLE:="ttyAMA0"}" _setup_aarch64_virt_base() { - QEMU_PARAMS+=("-nographic") + QEMU_PARAMS+=("-nodefaults") - if [[ $GUEST_DISPLAY -eq 0 ]]; then - #QEMU_PARAMS+=("-display" "none") + if [[ -z $GUEST_DISPLAY ]]; then QEMU_PARAMS+=("-nographic") + else + QEMU_PARAMS+=("-device" "virtio-gpu-pci") + QEMU_PARAMS+=("-display" "$GUEST_DISPLAY") + QEMU_PARAMS+=("-device" "virtio-keyboard-pci") + QEMU_PARAMS+=("-device" "virtio-mouse-pci") + QEMU_PARAMS+=("-device" "qemu-xhci") + QEMU_PARAMS+=("-device" "usb-tablet") fi QEMU_PARAMS+=("-machine" "virt,accel=$GUEST_ACCEL,kernel-irqchip=split")