Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions boot-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ function setup_qemu_args() {
arm64)
KIMAGE=Image.gz
APPEND_STRING+="console=ttyAMA0 "
if [[ "$(uname -m)" = "aarch64" && -e /dev/kvm ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we can do to make the host check more consistent with the x86 check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we can do to make the host check more consistent with the x86 check?

What kind of consistency were you looking for? The logic for this check was copied from the cpu-checker package on Debian and Ubuntu, which contains kvm-ok. Apparently all AArch64 hardware is KVM compatible, all the script does is check if the KVM module is loaded (i.e. /dev/kvm exists).

I can probably refine the second half of the x86 check to just be "does /dev/kvm exist" but I would need to test it later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have uname guards on one and not both? Is there something in cpuinfo that we should check on aarch64?

I would expect both or neither to have cpuinfo checks.

I would expect both or neither to have uname checks.

Not different approaches per target.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all x86 CPUs have hardware virtualization; we have to check /proc/cpuinfo for the feature flags (vmx for Intel, svm for AMD). We do not need a uname check for that as non-x86 processors will not have those flags. All AArch64 CPUs have hardware virtualization so we just need to check if we are running on an AArch64 processor to determine if we have hardware virtualization; I do not see any flags in /proc/cpuinfo that we can use to check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will /dev/kvm exist on x86 cpus that don't support vmx|svm? If not, then it seems better to do a uname -m check for x86 hosts, rather than check cpuinfo. What if svm appears in an aarch64 host's /dev/cpuinfo trying to boot x86?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will /dev/kvm exist on x86 cpus that don't support vmx|svm? If not, then it seems better to do a uname -m check for x86 hosts, rather than check cpuinfo. What if svm appears in an aarch64 host's /dev/cpuinfo trying to boot x86?

Ah, I see what you are saying. I do not think that /dev/kvm can exist if the CPU does not have hardware virtualization. I highly doubt that svm would appear on an AArch64 device but who knows? I still think the check is consistent with how it is in kvm-ok but I am fine with changing it (although I guess I will need to check for either x86_64 or i386 through i686 right?)

ARM64_CPU=host
ARM64_KVM_FLAGS=(-enable-kvm)
fi
QEMU_ARCH_ARGS=(
-cpu max
"${ARM64_KVM_FLAGS[@]}"
-cpu "${ARM64_CPU:-max}"
-machine virt)
QEMU=(qemu-system-aarch64)
;;
Expand Down Expand Up @@ -201,8 +206,8 @@ function setup_qemu_args() {
x86 | x86_64)
KIMAGE=bzImage
APPEND_STRING+="console=ttyS0 "
# Use KVM if the processor supports it (first part) and the KVM module is loaded (second part)
[[ $(grep -c -E 'vmx|svm' /proc/cpuinfo) -gt 0 && $(lsmod 2>/dev/null | grep -c kvm) -gt 0 ]] &&
# Use KVM if the processor supports it and the KVM module is loaded (i.e. /dev/kvm exists)
[[ $(grep -c -E 'vmx|svm' /proc/cpuinfo) -gt 0 && -e /dev/kvm ]] &&
QEMU_ARCH_ARGS=("${QEMU_ARCH_ARGS[@]}" -cpu host -d "unimp,guest_errors" -enable-kvm -smp "$(nproc)")
case ${ARCH} in
x86) QEMU=(qemu-system-i386) ;;
Expand Down