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