From eb8655b2fe63c1aa60ca1ded98dadb01ce4ed1eb Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Fri, 25 Feb 2022 14:45:44 +0100 Subject: [PATCH] setup.sh: Make sure driver is known upon reset In case collect_driver() returns immediately due to missing modalias attr, an empty $driver will be passed to check_for_driver() causing grep inside to fail. Further false-positive then leads to call to linux_bind_driver() as it's not able to locate proper paths for given driver. To avoid this, make sure collect_driver() always attempts to fallback to a driver setup.sh supports for a target device. Signed-off-by: Michal Berger Change-Id: Id5631a731910f60b63c6afb3a412575bb69d784a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11747 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- scripts/setup.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 2fd520ac4..d0c09430a 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -86,6 +86,10 @@ function usage() { # /sys/bus/pci/drivers/ as neither lsmod nor /sys/modules might # contain needed info (like in Fedora-like OS). function check_for_driver() { + if [[ -z $1 ]]; then + return 0 + fi + if lsmod | grep -q ${1//-/_}; then return 1 fi @@ -166,6 +170,11 @@ function linux_unbind_driver() { ven_dev_id="${pci_ids_vendor["$bdf"]#0x} ${pci_ids_device["$bdf"]#0x}" local old_driver_name=${drivers_d["$bdf"]:-no driver} + if [[ $old_driver_name == "no driver" ]]; then + pci_dev_echo "$bdf" "Not bound to any driver" + return 0 + fi + if [[ -e /sys/bus/pci/drivers/$old_driver_name ]]; then echo "$ven_dev_id" > "/sys/bus/pci/drivers/$old_driver_name/remove_id" 2> /dev/null || true echo "$bdf" > "/sys/bus/pci/drivers/$old_driver_name/unbind" @@ -256,8 +265,8 @@ function collect_driver() { local bdf=$1 local drivers driver - [[ -e /sys/bus/pci/devices/$bdf/modalias ]] || return 1 - if drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then + if [[ -e /sys/bus/pci/devices/$bdf/modalias ]] \ + && drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then # Pick first entry in case multiple aliases are bound to a driver. driver=$(readlink -f "/sys/module/${drivers[0]}/drivers/pci:"*) driver=${driver##*/} @@ -537,7 +546,7 @@ function reset_linux_pci() { ((all_devices_d["$bdf"] == 0)) || continue driver=$(collect_driver "$bdf") - if ! check_for_driver "$driver"; then + if [[ -n $driver ]] && ! check_for_driver "$driver"; then linux_bind_driver "$bdf" "$driver" else linux_unbind_driver "$bdf"