Browse Source

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
Marek Marczykowski-Górecki 6 years ago
parent
commit
ee122eefef
1 changed files with 24 additions and 0 deletions
  1. 24 0
      qubes-rpc/prepare-suspend

+ 24 - 0
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 \