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
This commit is contained in:
Marek Marczykowski-Górecki 2018-01-22 19:14:07 +01:00
parent 79b38cf106
commit ee122eefef
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -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 \