SR-IOV Configuration
SR-IOV (Single Root I/O Virtualization) allows virtual machines to directly access physical network adapter Virtual Functions (VFs), bypassing the hypervisor virtual switch for near-native I/O throughput and ultra-low latency.
Prerequisites
Section titled “Prerequisites”Hardware Requirements
Section titled “Hardware Requirements”- CPU with VT-d (Intel) or AMD-Vi (AMD) support
- SR-IOV capable NIC (Intel 82599, X710, Mellanox ConnectX, etc.)
- Motherboard with IOMMU support
Enable IOMMU
Section titled “Enable IOMMU”# Intel VT-d# Edit /etc/default/grubGRUB_CMDLINE_LINUX="intel_iommu=on iommu=pt"
# AMD-ViGRUB_CMDLINE_LINUX="amd_iommu=on iommu=pt"
# Update GRUBupdate-grubreboot
# Verify IOMMUdmesg | grep -i iommuEnable SR-IOV
Section titled “Enable SR-IOV”Check SR-IOV Support
Section titled “Check SR-IOV Support”# Check if NIC supports SR-IOVlspci -vvv -s <NIC_PCI_ADDRESS> | grep -i "sr-iov"
# Example output:# Capabilities: [150] Single Root I/O Virtualization (SR-IOV)Enable VFs
Section titled “Enable VFs”# Enable 8 VFs on eth2echo 8 > /sys/class/net/eth2/device/sriov_numvfs
# Verify VFs createdlspci | grep -i "Virtual Function"
# Make persistentcat > /etc/systemd/system/sriov-eth2.service <<EOF[Unit]Description=Enable SR-IOV on eth2After=network.target
[Service]Type=oneshotExecStart=/bin/sh -c 'echo 8 > /sys/class/net/eth2/device/sriov_numvfs'RemainAfterExit=yes
[Install]WantedBy=multi-user.targetEOF
systemctl enable sriov-eth2.serviceConfigure VF
Section titled “Configure VF”Bind VF to VFIO
Section titled “Bind VF to VFIO”# Get VF PCI addresslspci | grep "Virtual Function" | head -1# Example: 03:10.0 Ethernet controller: Intel Corporation 82599 VF
# Get vendor and device IDlspci -n -s 03:10.0# Example: 03:10.0 0200: 8086:10ed (rev 01)
# Unbind from current driverecho 0000:03:10.0 > /sys/bus/pci/drivers/ixgbevf/unbind
# Bind to vfio-pcimodprobe vfio-pciecho "8086 10ed" > /sys/bus/pci/drivers/vfio-pci/new_idecho 0000:03:10.0 > /sys/bus/pci/drivers/vfio-pci/bindConfigure VF Network
Section titled “Configure VF Network”# Set MAC addressip link set eth2 vf 0 mac aa:bb:cc:dd:ee:01
# Set VLANip link set eth2 vf 0 vlan 100
# Set rate limit (in Mbps)ip link set eth2 vf 0 rate 1000PiVirt Configuration
Section titled “PiVirt Configuration”Network Configuration
Section titled “Network Configuration”network: sriov: - name: "sriov-net" pf: "eth2" vfs: 8 vf_driver: "vfio-pci"VM Configuration
Section titled “VM Configuration”spec: nics: - name: eth0 network: sriov-net model: vfio-pci pci_address: "03:10.0" mac: "aa:bb:cc:dd:ee:01"Performance Tuning
Section titled “Performance Tuning”CPU Pinning
Section titled “CPU Pinning”spec: cpu: cores: 4 pinning: - vcpu: 0 host_cpu: 0 - vcpu: 1 host_cpu: 1 - vcpu: 2 host_cpu: 2 - vcpu: 3 host_cpu: 3NUMA Awareness
Section titled “NUMA Awareness”spec: numa: nodes: - id: 0 cpus: "0-3" memory: "8Gi"Hugepages
Section titled “Hugepages”spec: memory: size: 8Gi hugepages: enabled: true size: "2Mi"Monitoring
Section titled “Monitoring”Check VF Status
Section titled “Check VF Status”# List VFsip link show eth2
# Check VF statsethtool -S eth2 | grep -i vfPerformance Metrics
Section titled “Performance Metrics”# Check network statsethtool -S eth2
# Check VF throughputiperf3 -c 10.10.1.11 -t 60Troubleshooting
Section titled “Troubleshooting”VF Not Created
Section titled “VF Not Created”# Check SR-IOV supportlspci -vvv -s <NIC_PCI_ADDRESS> | grep -i "sr-iov"
# Check IOMMUdmesg | grep -i iommu
# Check kernel parameterscat /proc/cmdline | grep iommuVFIO Bind Failed
Section titled “VFIO Bind Failed”# Check if VFIO is loadedlsmod | grep vfio
# Check IOMMU groupsls -la /sys/kernel/iommu_groups/
# Check VF PCI addresslspci -n -s <VF_PCI_ADDRESS>VM Can’t Access VF
Section titled “VM Can’t Access VF”# Check VF bindingls -la /sys/bus/pci/drivers/vfio-pci/
# Check VM configpvcli vm get web-01 -o json | jq '.spec.nics'
# Check QEMU logsjournalctl -u pivirtd -f | grep -i vfio