|
14
by Kees Cook
adjust licenses, add tarball target, move old stuff out of the way |
1 |
#!/bin/sh
|
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
2 |
#
|
3 |
# kvm-ok - check whether the CPU we're running on supports KVM acceleration
|
|
4 |
# Copyright (C) 2008-2010 Canonical Ltd.
|
|
5 |
#
|
|
|
23
by Kees Cook
* kvm-ok: replace dmesg review with MSR tests. |
6 |
# Authors:
|
7 |
# Dustin Kirkland <kirkland@canonical.com>
|
|
8 |
# Kees Cook <kees.cook@canonical.com>
|
|
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
9 |
#
|
10 |
# This program is free software: you can redistribute it and/or modify
|
|
|
14
by Kees Cook
adjust licenses, add tarball target, move old stuff out of the way |
11 |
# it under the terms of the GNU General Public License version 3,
|
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
12 |
# as published by the Free Software Foundation.
|
13 |
#
|
|
14 |
# This program is distributed in the hope that it will be useful,
|
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 |
# GNU General Public License for more details.
|
|
18 |
#
|
|
19 |
# You should have received a copy of the GNU General Public License
|
|
20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
14
by Kees Cook
adjust licenses, add tarball target, move old stuff out of the way |
21 |
set -e
|
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
22 |
|
|
32
by Dustin Kirkland
kvm-ok: fix $id bug; update brand detection; ensure that the |
23 |
assert_root() { |
24 |
if [ "$(id -u)" != "0" ]; then |
|
25 |
echo "INFO: For more detailed results, you should run this as root" |
|
26 |
echo "HINT: sudo $0" |
|
27 |
exit 1
|
|
28 |
fi
|
|
29 |
}
|
|
30 |
||
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
31 |
verdict() { |
32 |
# Print verdict
|
|
33 |
if [ "$1" = "0" ]; then |
|
34 |
echo "KVM acceleration can be used" |
|
35 |
exit 0
|
|
36 |
else
|
|
37 |
echo "KVM acceleration can NOT be used" |
|
38 |
exit 1
|
|
39 |
fi
|
|
40 |
}
|
|
41 |
||
|
24
by Kees Cook
move initial failure before MSR loading to handle non-x86 CPUs more sanely |
42 |
# check cpu flags for capability
|
|
35
by Dustin Kirkland
releasing 0.5 |
43 |
virt=$(egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)') || true |
|
32
by Dustin Kirkland
kvm-ok: fix $id bug; update brand detection; ensure that the |
44 |
[ "$virt" = "vmx" ] && brand="intel" |
45 |
[ "$virt" = "svm" ] && brand="amd" |
|
|
31
by Dustin Kirkland
kvm-ok: fix $id bug; update brand detection |
46 |
|
|
24
by Kees Cook
move initial failure before MSR loading to handle non-x86 CPUs more sanely |
47 |
if [ -z "$virt" ]; then |
48 |
echo "INFO: Your CPU does not support KVM extensions" |
|
|
37
by Dustin Kirkland
* kvm-ok: LP: #843972 |
49 |
assert_root |
50 |
verdict 1 |
|
|
24
by Kees Cook
move initial failure before MSR loading to handle non-x86 CPUs more sanely |
51 |
fi
|
52 |
||
|
26
by Dustin Kirkland
kvm-ok: exit informatively if we are not root before doing MSR |
53 |
# Now, check that the device exists
|
54 |
if [ -e /dev/kvm ]; then |
|
55 |
echo "INFO: /dev/kvm exists" |
|
56 |
verdict 0 |
|
57 |
else
|
|
58 |
echo "INFO: /dev/kvm does not exist" |
|
|
32
by Dustin Kirkland
kvm-ok: fix $id bug; update brand detection; ensure that the |
59 |
echo "HINT: sudo modprobe kvm_$brand" |
|
26
by Dustin Kirkland
kvm-ok: exit informatively if we are not root before doing MSR |
60 |
fi
|
61 |
||
|
32
by Dustin Kirkland
kvm-ok: fix $id bug; update brand detection; ensure that the |
62 |
assert_root |
|
26
by Dustin Kirkland
kvm-ok: exit informatively if we are not root before doing MSR |
63 |
|
|
23
by Kees Cook
* kvm-ok: replace dmesg review with MSR tests. |
64 |
# Prepare MSR access
|
65 |
msr="/dev/cpu/0/msr" |
|
66 |
if [ ! -r "$msr" ]; then |
|
67 |
modprobe msr
|
|
68 |
fi
|
|
69 |
if [ ! -r "$msr" ]; then |
|
70 |
echo "You must be root to run this check." >&2 |
|
71 |
exit 2
|
|
72 |
fi
|
|
73 |
||
|
24
by Kees Cook
move initial failure before MSR loading to handle non-x86 CPUs more sanely |
74 |
echo "INFO: Your CPU supports KVM extensions" |
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
75 |
|
|
23
by Kees Cook
* kvm-ok: replace dmesg review with MSR tests. |
76 |
disabled=0 |
77 |
# check brand-specific registers
|
|
78 |
if [ "$virt" = "vmx" ]; then |
|
79 |
BIT=$(rdmsr --bitfield 0:0 0x3a 2>/dev/null || true) |
|
80 |
if [ "$BIT" = "1" ]; then |
|
81 |
# and FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX clear (no tboot)
|
|
82 |
BIT=$(rdmsr --bitfield 2:2 0x3a 2>/dev/null || true) |
|
83 |
if [ "$BIT" = "0" ]; then |
|
84 |
disabled=1 |
|
85 |
fi
|
|
86 |
fi
|
|
87 |
||
88 |
elif [ "$virt" = "svm" ]; then |
|
89 |
BIT=$(rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || true) |
|
90 |
if [ "$BIT" = "1" ]; then |
|
91 |
disabled=1 |
|
92 |
fi
|
|
93 |
else
|
|
94 |
echo "FAIL: Unknown virtualization extension: $virt" |
|
95 |
verdict 1 |
|
96 |
fi
|
|
97 |
||
98 |
if [ "$disabled" -eq 1 ]; then |
|
99 |
echo "INFO: KVM ($virt) is disabled by your BIOS" |
|
|
11.1.2
by Dustin Kirkland
added kvm-ok script, lifted and moved from the qemu-kvm package in Ubuntu |
100 |
echo "HINT: Enter your BIOS setup and enable Virtualization Technology (VT)," |
101 |
echo " and then hard poweroff/poweron your system" |
|
102 |
verdict 1 |
|
103 |
fi
|
|
104 |
||
105 |
verdict 0 |