Skip to content

Commit fe2fc2d

Browse files
committed
tools: try modprobe kvm if not loaded
Some tests are failing with error `[Firecracker devtool] /dev/kvm not found. Aborting.`. These all pass on a retry, indicating kvm hadn't yet been loaded. Update the `check_kvm` method to now attempt to modprobe kvm and assert that /dev/kvm is now present. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent 78bfc21 commit fe2fc2d

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

tools/functions

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,39 @@ function validate_version {
130130
# Firecracker functions #
131131
#########################
132132

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.
133+
# Attempt to load the appropriate KVM module for the current platform.
134+
# Returns 0 on success, non-zero on failure.
135+
#
136+
load_kvm() {
137+
local arch
138+
arch=$(uname -m)
139+
140+
case "$arch" in
141+
x86_64|i*86)
142+
if grep -q "vmx" /proc/cpuinfo; then
143+
modprobe kvm_intel || return 1
144+
elif grep -q "svm" /proc/cpuinfo; then
145+
modprobe kvm_amd || return 1
146+
else
147+
return 1
148+
fi
149+
;;
150+
aarch64|arm*)
151+
modprobe kvm || return 1
152+
;;
153+
*)
154+
return 1
155+
;;
156+
esac
157+
158+
# Check /dev/kvm now exists
159+
[[ -c /dev/kvm ]]
160+
}
161+
162+
# Check if /dev/kvm exists. Attempt to load the module if it doesn't.
163+
# Exit if KVM is unavailable. Upon returning from this call, the caller
164+
# can be certain /dev/kvm is available.
136165
#
137166
ensure_kvm() {
138-
[[ -c /dev/kvm ]] || die "/dev/kvm not found. Aborting."
167+
[[ -c /dev/kvm ]] || load_kvm || die "/dev/kvm not found. Aborting."
139168
}

0 commit comments

Comments
 (0)