Skip to content

Commit ba56cd2

Browse files
ShadowCurseJackThomson2
authored andcommitted
devtool: move ensure_kvm into devtool
This one was only used in devtool, so move it there. No functional change. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent cdbcdd6 commit ba56cd2

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

tools/devtool

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,43 @@ ensure_ci_artifacts() {
583583
fi
584584
}
585585

586+
# Attempt to load the appropriate KVM module for the current platform.
587+
# Returns 0 on success, non-zero on failure.
588+
#
589+
load_kvm() {
590+
local arch
591+
arch=$(uname -m)
592+
593+
case "$arch" in
594+
x86_64|i*86)
595+
if grep -q "vmx" /proc/cpuinfo; then
596+
modprobe kvm_intel || return 1
597+
elif grep -q "svm" /proc/cpuinfo; then
598+
modprobe kvm_amd avic=1 || return 1
599+
else
600+
return 1
601+
fi
602+
;;
603+
aarch64|arm*)
604+
modprobe kvm || return 1
605+
;;
606+
*)
607+
return 1
608+
;;
609+
esac
610+
611+
# Check /dev/kvm now exists
612+
[[ -c /dev/kvm ]]
613+
}
614+
615+
# Check if /dev/kvm exists. Attempt to load the module if it doesn't.
616+
# Exit if KVM is unavailable. Upon returning from this call, the caller
617+
# can be certain /dev/kvm is available.
618+
#
619+
ensure_kvm() {
620+
[[ -c /dev/kvm ]] || load_kvm || die "/dev/kvm not found. Aborting."
621+
}
622+
586623
apply_linux_61_tweaks() {
587624
KV=$(uname -r)
588625
if [[ $KV != 6.1.* ]] || [ $(uname -m) != x86_64 ]; then

tools/functions

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,3 @@ function validate_version {
125125
die "Invalid version number: $version. Version should not contain \`wip\` or \`dirty\`."
126126
fi
127127
}
128-
129-
#########################
130-
# Firecracker functions #
131-
#########################
132-
133-
# Check if /dev/kvm exists. Exit if it doesn't.
134-
# Upon returning from this call, the caller can be certain /dev/kvm is
135-
# available.
136-
#
137-
ensure_kvm() {
138-
[[ -c /dev/kvm ]] || die "/dev/kvm not found. Aborting."
139-
}

0 commit comments

Comments
 (0)