From 812fa9e4c1cf5c7177f022bbd85448c59ecea383 Mon Sep 17 00:00:00 2001 From: Albrecht Lohofener Date: Fri, 10 Jan 2025 21:42:08 +0100 Subject: [PATCH] Improve PCI pass-through error handling --- docker-compose.yml | 2 +- src/run_openwrt.sh | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4020ae8..6ddc153 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ services: # PCI and PCIe pass-through # Host system requirements - # - IOMMU CPU feature has to enabled in bios + # - IOMMU CPU virtualization feature (e.g. Intel VT-d) has to enabled in bios # - Host kernel has to switch on intel_iommu=on or amd_iommu=on # - Host kernel module 'vfio-pci' has to exists # - Ubuntu 24.04 is working by default diff --git a/src/run_openwrt.sh b/src/run_openwrt.sh index 6e4c698..efc8d1b 100755 --- a/src/run_openwrt.sh +++ b/src/run_openwrt.sh @@ -143,7 +143,7 @@ attach_pci_device () { info "Preparing PCI pass-through for device $PCI_DEVICE ..." if [ ! -e "$PCI_PATH" ]; then - echo "Error: PCI device $PCI_DEVICE not found" + error "Error: PCI device $PCI_DEVICE not found" exit 1 fi @@ -162,12 +162,9 @@ attach_pci_device () { # Bind to vfio-pci echo "vfio-pci" > "$PCI_PATH/driver_override" - echo "$PCI_DEVICE" > /sys/bus/pci/drivers/vfio-pci/bind - - # Verify binding - if [ "$(basename "$(readlink "$PCI_PATH/driver" 2>/dev/null)")" != "vfio-pci" ]; then - echo "Failed to bind $PCI_DEVICE to vfio-pci" - exit 1 + if ! echo "$PCI_DEVICE" > /sys/bus/pci/drivers/vfio-pci/bind 2>/dev/null; then + error "Failed to bind PCI device $PCI_DEVICE to vfio-pci. Please double check if your system supports IOMMU and if CPU virtualization features (e.g. Intel VT-d) is enabled in your bios." + exit 1 fi echo "Successfully bound $PCI_DEVICE to vfio-pci"