ae23c9
#! /bin/bash
ae23c9
ae23c9
kvm_setup_powerpc () {
ae23c9
    if grep '^platform[[:space:]]*:[[:space:]]*PowerNV' /proc/cpuinfo > /dev/null; then
ae23c9
	# PowerNV platform, which is KVM HV capable
ae23c9
ae23c9
	if [ -z "$SUBCORES" ]; then
ae23c9
	    SUBCORES=1
ae23c9
	fi
ae23c9
ae23c9
	# Step 1. Load the KVM HVmodule
ae23c9
	if ! modprobe -b kvm_hv; then
ae23c9
	    return
ae23c9
	fi
ae23c9
ae23c9
	# On POWER8 a host core can only run threads of a single
ae23c9
	# guest, meaning that SMT must be disabled on the host in
ae23c9
	# order to run KVM guests. (Also applieds to POWER7, but we
ae23c9
	# don't support that).
ae23c9
	#
ae23c9
	# POWER9 doesn't have this limitation (though it will for hash
ae23c9
	# guests on radix host when that's implemented).  So, only set
ae23c9
	# up subcores and disable SMT for POWER*.
ae23c9
	if grep '^cpu[[:space:]]*:[[:space:]]*POWER8' /proc/cpuinfo > /dev/null; then
ae23c9
	    # Step 2. Configure subcore mode
ae23c9
	    /usr/sbin/ppc64_cpu --subcores-per-core=$SUBCORES
ae23c9
ae23c9
	    # Step 3. Disable SMT (multithreading)
ae23c9
	    /usr/sbin/ppc64_cpu --smt=off
ae23c9
	fi
ae23c9
    fi
ae23c9
}
ae23c9
ae23c9
kvm_setup_s390x () {
ae23c9
    if grep -q "^features.*sie" /proc/cpuinfo; then
ae23c9
        modprobe kvm
ae23c9
    fi
ae23c9
}
ae23c9
ae23c9
case $(uname -m) in
ae23c9
    ppc64|ppc64le)
ae23c9
	kvm_setup_powerpc
ae23c9
	;;
ae23c9
    s390x)
ae23c9
	kvm_setup_s390x
ae23c9
	;;
ae23c9
esac
ae23c9
ae23c9
exit 0