全部產品
Search
文件中心

Elastic Compute Service:使用VFIO驅動替代UIO驅動

更新時間:Jul 16, 2026

本文介紹如何在普通雲端服務器和ECS Bare Metal Instance中使用VFIO驅動替代UIO驅動,解決DPDK應用運行異常的問題。

前提條件

背景資訊

如果您在六代(g6、c6、r6等)及以後的執行個體規格(包含通用算力型執行個體)上部署DPDK應用,運行DPDK應用時可能發生異常。例如,使用pktgen-dpdk工具進行網路發包測試時可能檢測不到網卡綁定的igb_uio連接埠,出現以下報錯時,您可以使用VFIO驅動替代UIO驅動解決此類問題。

EAL: eal_parse_sysfs_value(): cannot open sysfs value /sys/bus/pci/devices/0000:00:06.0/uio/uio0/portio/port0/start

操作步驟

  1. 遠端連線普通雲端服務器和ECS Bare Metal Instance。

    具體操作,請參見使用Workbench登入Linux執行個體

  2. 檢查GRUB配置。

    cat /proc/cmdline
    • 如果GRUB配置中包括intel_iommu=on,且沒有iommu=pt,請執行步驟4

    • 如果是其他情況,需要添加intel_iommu=on並刪除iommu=pt,請執行步驟3

      GRUB配置中沒有intel_iommu=on,也沒有iommu=pt,需要添加intel_iommu=on

      [test@iZ2ze9h6rn63          ~]$ cat /proc/cmdline
      BOOT_IMAGE=/boot/vmlinuz-4.19.91-27.4.al7.x86_64 root=UUID=90179e0e-4e13-4c59-a6cc-0ce5cxxx ro crashkernel=0M-2G:0M
  3. /etc/default/grub設定檔中添加intel_iommu=on

    1. 開啟設定檔。

      sudo vim /etc/default/grub
    2. i切換到編輯模式,在GRUB_CMDLINE_LINUX中添加intel_iommu=on,然後儲存設定檔。

      修改完成後的樣本如下所示。

      GRUB_TIMEOUT=1
      GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
      GRUB_DEFAULT=saved
      GRUB_DISABLE_SUBMENU=true
      GRUB_TERMINAL_OUTPUT="console"
      GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet idle=halt biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8 noibrs intel_iommu=on"
      GRUB_DISABLE_RECOVERY="true"
    3. 應用修改後的配置。

      sudo grub2-mkconfig -o /boot/grub2/grub.cfg
      [test@iZ2ze9h6rn          ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
      Generating grub configuration file ...
      Found linux image: /boot/vmlinuz-4.19.91-27.4.al7.x86_64
      Found initrd image: /boot/initramfs-4.19.91-27.4.al7.x86_64.img
      Found linux image: /boot/vmlinuz-0-rescue-2cea6e3dd20d4251bf6880159559f2c9
      Found initrd image: /boot/initramfs-0-rescue-2cea6e3dd20d4251bf6880159559f2c9.img
      done
    4. 執行以下命令,重啟執行個體並再次遠端連線執行個體。

      reboot
      警告

      重啟執行個體會造成您的執行個體停止工作,可能導致業務中斷,建議您在非業務高峰期時執行該操作。

  4. 安裝VFIO和VFIO-PCI驅動。

    sudo modprobe vfio && \
    sudo modprobe vfio-pci
  5. 配置noiommu_mode。

    sudo bash -c 'echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode'
  6. 查看並記錄網卡裝置的bus-info值。

    ethtool -i ethX

    請將ethX替換為對應網卡的編號,查看eth1網卡的樣本如下所示。輸出中 bus-info 欄位的值即為網卡的匯流排地址(本例為 0000:00:06.0)。

    [root@izxxx ~]# ethtool -i eth1
    driver: virtio_net
    version: 1.0.0
    firmware-version:
    expansion-rom-version:
    bus-info: 0000:00:06.0
    supports-statistics: no
    supports-test: no
    supports-eeprom-access: no
    supports-register-dump: no
    supports-priv-flags: no
  7. 切換到DPDK安裝目錄的usertools目錄下,然後執行以下命令綁定網卡到vfio-pci驅動。

    sudo ./dpdk-devbind.py -b vfio-pci 0000:00:06.0
    說明

    0000:00:06.0為網卡的bus-info值,用於指定對應的網卡,請按實際情況替換。

    綁定後可以運行./dpdk-devbind.py --status查看綁定狀態,下方樣本表示0000:00:06.0對應的網卡已綁定到vfio-pci驅動。

    [root@izxxxxxxxxxxxxx usertools]# ./dpdk-devbind.py --status
    
    Network devices using DPDK-compatible driver
    =============================================
    0000:00:06.0 'Virtio network device 1000' drv=vfio-pci unused=virtio pci
    
    Network devices using kernel driver
    ====================================
    0000:00:05.0 'Virtio network device 1000' if=eth0 drv=virtio-pci unused=virtio_pci,vfio-pci *Active*
  8. 切換到DPDK安裝目錄的build/app目錄下,然後根據DPDK版本執行命令運行DPDK應用程式。

    • DPDK 18.02及更高版本

      sudo ./testpmd -w 0000:00:06.0 -c 0x3 -- --total-num-mbufs=2048 -ai
    • 低於DPDK 18.02的版本

      sudo ./testpmd -w 0000:00:06.0 -c 0x3 -- --total-num-mbufs=2048 --disable-hw-vlan -ai
    說明

    -w 0000:00:06.0用於指定網卡,total-num-mbufs=2048對應設定的HugePages大小,請按實際情況替換。

    運行DPDK應用程式的樣本如下所示。

    [    @izxxxxxxxxxxxZ app]# ./testpmd -w 0000:00:06.0 -c 0x3 -- --total-num-mbufs=2048 -ai
    EAL: Detected 2 lcore(s)
    EAL: Detected 1 NUMA nodes
    EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
    EAL: No free hugepages reported in hugepages-1048576kB
    EAL: Probing VFIO support...
    EAL: VFIO support initialized
    EAL: PCI device 0000:00:06.0 on NUMA socket -1
    EAL:   Invalid NUMA socket, default to 0
    EAL:   probe driver: 1af4:1000 net_virtio
    EAL:   using IOMMU type 8 (No-IOMMU)
    Auto-start selected
    Interactive-mode selected
    testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=2048, size=2176, socket=0
    testpmd: preferred mempool ops selected: ring_mp_mc
    
    Warning! port-topology=paired and odd forward ports number, the last port will pair with itself.
    
    Configuring Port 0 (socket 0)
    EAL: Error disabling MSI-X interrupts for fd 18
    Port 0: 00:16:3E:35:CC:C4
    Checking link statuses...
    Done
    Start automatic packet forwarding
    io packet forwarding - ports=1 - cores=1 - streams=1 - NUMA support enabled, MP allocation mode: native
    Logical Core 1 (socket 0) forwards packets on 1 streams:
      RX P=0/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
    
      io packet forwarding packets/burst=32
      nb forwarding cores=1 - nb forwarding ports=1
      port 0: RX queue number: 1 Tx queue number: 1
        Rx offloads=0x0 Tx offloads=0x0
        RX queue: 0
          RX desc=0 - RX free threshold=0
          RX threshold registers: pthresh=0 hthresh=0  wthresh=0
          RX Offloads=0x0
        TX queue: 0
          TX desc=0 - TX free threshold=0
          TX threshold registers: pthresh=0 hthresh=0  wthresh=0
          TX offloads=0x0 - TX RS bit threshold=0
    testpmd>