summaryrefslogtreecommitdiffstats
path: root/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version
blob: 7d1190c5ac172c6b70eefa52bf470a5ccab0edac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/ash
# This script checks whether given VMware version supports the CPU:
# * Intel: check for "VMX Unrestricted Guest" CPU flag
# * AMD:   check if CPU family is Bulldozer or newer
#
# It can be called inside a dracut context and tries to do
# chroot magic to call/load the required tools.

VIRTTYPE="$( grep -m1 '^flags\s*:' /proc/cpuinfo | grep -woF -e svm -e vmx )"

if [ -z "$VIRTTYPE" ]; then
	# No need to bother with msr
	echo "legacy"
	exit 0
fi

modprobe msr

version="legacy"
if [ "$VIRTTYPE" = "vmx" ]; then    # intel
	BIT1="$( rdmsr --bitfield 0:0 0x3a 2>/dev/null || echo "fail" )"
	BIT2="$( rdmsr --bitfield 2:2 0x3a 2>/dev/null || echo "fail" )"
	if [ "$BIT1" = "0" ] || [ "$BIT2" = "1" ]; then
		flag="$( rdmsr --bitfield 5:5 0x485 )"
		[ "$flag" = "1" ] && version="new"
	fi
elif [ "$VIRTTYPE" = "svm" ]; then  # amd
	BIT="$( rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || echo "fail" )"
	if [ "$BIT" = "0" ]; then
		family="$( awk '$1$2 == "cpufamily" {print $NF;exit}' /proc/cpuinfo )"
		[ "$family" -ge 21 ] && version="new"
	fi
fi

echo "$version"