From ee122eefefa2cdf29c0c2ed104a6bb9957ad5ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 22 Jan 2018 19:14:07 +0100 Subject: [PATCH] Detach all drivers from PCI devices before suspend The most common thing to fix S3 sleep is to unload PCI devices drivers before suspend. Instead of having every user figuring out what drivers needs to be blacklisted, detach all drivers from actual PCI devices. Exclude qemu emulated devices. Fixes QubesOS/qubes-issues#3486 --- qubes-rpc/prepare-suspend | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qubes-rpc/prepare-suspend b/qubes-rpc/prepare-suspend index 6200705..f96a2c0 100755 --- a/qubes-rpc/prepare-suspend +++ b/qubes-rpc/prepare-suspend @@ -34,6 +34,24 @@ if [ x"$action" = x"suspend" ]; then fi ip l s "$intf" down done + + # detach all drivers from PCI devices (the real ones, not emulated by qemu) + echo -n > /var/run/qubes-suspend-pci-devs-detached + for dev_path in /sys/bus/pci/devices/*; do + # skip qemu emulated devs + subsystem_vendor=$(cat "$dev_path/subsystem_vendor") + if [ "$subsystem_vendor" = "0x1af4" ] || [ "$subsystem_vendor" = "0x5853" ]; then + continue + fi + if ! [ -e "$dev_path/driver" ]; then + continue + fi + bdf=$(basename "$dev_path") + driver_path=$(readlink -f "$dev_path/driver") + echo "$bdf" > "$driver_path/unbind" + echo "$bdf $driver_path" >> /var/run/qubes-suspend-pci-devs-detached + done + LOADED_MODULES="" for mod in $MODULES_BLACKLIST; do if lsmod |grep -q "$mod"; then @@ -48,6 +66,12 @@ else modprobe "$mod" done rm -f /var/run/qubes-suspend-modules-loaded + + while read -r dev driver_path; do + echo "$dev" > "$driver_path/bind" + done < /var/run/qubes-suspend-pci-devs-detached + rm -f /var/run/qubes-suspend-pci-devs-detached + if qsvc network-manager ; then dbus-send --system --print-reply \ --dest=org.freedesktop.NetworkManager \