Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Add VF recovery tests

The basic EEH test ignores VFs since we the way the eeh_dev_break debugfs
interface works means that if multiple VFs are enabled we may cause errors
on all them them. However, we can work around that by only enabling a
single VF at a time.

This patch adds some infrastructure for finding SR-IOV capable devices and
enabling / disabling VFs so we can exercise the VF specific EEH recovery
paths. Two new tests are added, one for testing EEH aware devices and one
for EEH un-aware VFs.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201103044503.917128-3-oohall@gmail.com

authored by

Oliver O'Halloran and committed by
Michael Ellerman
38132cc0 d6749ccb

+188
+108
tools/testing/selftests/powerpc/eeh/eeh-functions.sh
··· 135 135 return 0; 136 136 } 137 137 138 + eeh_has_driver() { 139 + test -e /sys/bus/pci/devices/$1/driver; 140 + return $? 141 + } 142 + 143 + eeh_can_recover() { 144 + # we'll get an IO error if the device's current driver doesn't support 145 + # error recovery 146 + echo $1 > '/sys/kernel/debug/powerpc/eeh_dev_can_recover' 2>/dev/null 147 + 148 + return $? 149 + } 150 + 151 + eeh_find_all_pfs() { 152 + devices="" 153 + 154 + # SR-IOV on pseries requires hypervisor support, so check for that 155 + is_pseries="" 156 + if grep -q pSeries /proc/cpuinfo ; then 157 + if [ ! -f /proc/device-tree/rtas/ibm,open-sriov-allow-unfreeze ] || 158 + [ ! -f /proc/device-tree/rtas/ibm,open-sriov-map-pe-number ] ; then 159 + return 1; 160 + fi 161 + 162 + is_pseries="true" 163 + fi 164 + 165 + for dev in `ls -1 /sys/bus/pci/devices/` ; do 166 + sysfs="/sys/bus/pci/devices/$dev" 167 + if [ ! -e "$sysfs/sriov_numvfs" ] ; then 168 + continue 169 + fi 170 + 171 + # skip unsupported PFs on pseries 172 + if [ -z "$is_pseries" ] && 173 + [ ! -f "$sysfs/of_node/ibm,is-open-sriov-pf" ] && 174 + [ ! -f "$sysfs/of_node/ibm,open-sriov-vf-bar-info" ] ; then 175 + continue; 176 + fi 177 + 178 + # no driver, no vfs 179 + if ! eeh_has_driver $dev ; then 180 + continue 181 + fi 182 + 183 + devices="$devices $dev" 184 + done 185 + 186 + if [ -z "$devices" ] ; then 187 + return 1; 188 + fi 189 + 190 + echo $devices 191 + return 0; 192 + } 193 + 194 + # attempts to enable one VF on each PF so we can do VF specific tests. 195 + # stdout: list of enabled VFs, one per line 196 + # return code: 0 if vfs are found, 1 otherwise 197 + eeh_enable_vfs() { 198 + pf_list="$(eeh_find_all_pfs)" 199 + 200 + vfs=0 201 + for dev in $pf_list ; do 202 + pf_sysfs="/sys/bus/pci/devices/$dev" 203 + 204 + # make sure we have a single VF 205 + echo 0 > "$pf_sysfs/sriov_numvfs" 206 + echo 1 > "$pf_sysfs/sriov_numvfs" 207 + if [ "$?" != 0 ] ; then 208 + log "Unable to enable VFs on $pf, skipping" 209 + continue; 210 + fi 211 + 212 + vf="$(basename $(realpath "$pf_sysfs/virtfn0"))" 213 + if [ $? != 0 ] ; then 214 + log "unable to find enabled vf on $pf" 215 + echo 0 > "$pf_sysfs/sriov_numvfs" 216 + continue; 217 + fi 218 + 219 + if ! eeh_can_break $vf ; then 220 + log "skipping " 221 + 222 + echo 0 > "$pf_sysfs/sriov_numvfs" 223 + continue; 224 + fi 225 + 226 + vfs="$((vfs + 1))" 227 + echo $vf 228 + done 229 + 230 + test "$vfs" != 0 231 + return $? 232 + } 233 + 234 + eeh_disable_vfs() { 235 + pf_list="$(eeh_find_all_pfs)" 236 + if [ -z "$pf_list" ] ; then 237 + return 1; 238 + fi 239 + 240 + for dev in $pf_list ; do 241 + echo 0 > "/sys/bus/pci/devices/$dev/sriov_numvfs" 242 + done 243 + 244 + return 0; 245 + }
+45
tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + . ./eeh-functions.sh 5 + 6 + eeh_test_prep # NB: may exit 7 + 8 + vf_list="$(eeh_enable_vfs)"; 9 + if $? != 0 ; then 10 + log "No usable VFs found. Skipping EEH unaware VF test" 11 + exit $KSELFTESTS_SKIP; 12 + fi 13 + 14 + log "Enabled VFs: $vf_list" 15 + 16 + tested=0 17 + passed=0 18 + for vf in $vf_list ; do 19 + log "Testing $vf" 20 + 21 + if ! eeh_can_recover $vf ; then 22 + log "Driver for $vf doesn't support error recovery, skipping" 23 + continue; 24 + fi 25 + 26 + tested="$((tested + 1))" 27 + 28 + log "Breaking $vf..." 29 + if ! eeh_one_dev $vf ; then 30 + log "$vf failed to recover" 31 + continue; 32 + fi 33 + 34 + passed="$((passed + 1))" 35 + done 36 + 37 + eeh_disable_vfs 38 + 39 + if [ "$tested" == 0 ] ; then 40 + echo "No VFs with EEH aware drivers found, skipping" 41 + exit $KSELFTESTS_SKIP 42 + fi 43 + 44 + test "$failed" != 0 45 + exit $?;
+35
tools/testing/selftests/powerpc/eeh/eeh-vf-unaware.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + . ./eeh-functions.sh 5 + 6 + eeh_test_prep # NB: may exit 7 + 8 + vf_list="$(eeh_enable_vfs)"; 9 + if $? != 0 ; then 10 + log "No usable VFs found. Skipping EEH unaware VF test" 11 + exit $KSELFTESTS_SKIP; 12 + fi 13 + 14 + log "Enabled VFs: $vf_list" 15 + 16 + failed=0 17 + for vf in $vf_list ; do 18 + log "Testing $vf" 19 + 20 + if eeh_can_recover $vf ; then 21 + log "Driver for $vf supports error recovery. Unbinding..." 22 + echo "$vf" > /sys/bus/pci/devices/$vf/driver/unbind 23 + fi 24 + 25 + log "Breaking $vf..." 26 + if ! eeh_one_dev $vf ; then 27 + log "$vf failed to recover" 28 + failed="$((failed + 1))" 29 + fi 30 + done 31 + 32 + eeh_disable_vfs 33 + 34 + test "$failed" != 0 35 + exit $?;