Skip to content

Instantly share code, notes, and snippets.

@inclyc
Created September 20, 2023 11:22
Show Gist options
  • Save inclyc/ce3cbf3f2254526d4fcadccfd1e56ace to your computer and use it in GitHub Desktop.
Save inclyc/ce3cbf3f2254526d4fcadccfd1e56ace to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# add-vfio.sh: detect iommu groups and override the driver of these devices to vfio-pci
IsolatingDevice="$1"
IOMMUGroup=$(ls "/sys/bus/pci/devices/$IsolatingDevice/iommu_group/devices")
for Device in ${IOMMUGroup}; do
DeviceDir="/sys/bus/pci/devices/$Device"
echo "Isolating: $(lspci -nns $Device)"
# Remove it from previous binded driver
if [ -d "$DeviceDir/driver" ]; then
echo "$Device" > "$DeviceDir/driver/unbind"
fi
# Bind it to vfio-pci
echo 'vfio-pci' > "$DeviceDir/driver_override"
echo "$Device" > /sys/bus/pci/drivers_probe
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment