forked from tinygrad/tinygrad
A misbehaving device doing raw DMA to host memory used to take the whole system down (fatal machine check from corrupted/poisoned memory). When the device is managed by a real IOMMU, bind it to vfio-pci and pin every page exposed to the device (sysmem allocations, mapped CPU buffers) into the container at iova=paddr, so a wild DMA faults in the IOMMU instead of corrupting host memory. Falls back to vfio no-iommu (with a warning) when no IOMMU is available. Also map BARs through the vfio device fd, since sysfs BAR mappings are revoked under vfio-pci.