6. Virtio_user as Exceptional Path

The virtual device, virtio-user, was originally introduced with vhost-user backend, as a high performance solution for IPC (Inter-Process Communication) and user space container networking.

Virtio_user with vhost-kernel backend is a solution for exceptional path, such as KNI which exchanges packets with kernel networking stack. This solution is very promising in:

  • Maintenance

    All kernel modules needed by this solution, vhost and vhost-net (kernel), are upstreamed and extensively used kernel module.

  • Features

    vhost-net is born to be a networking solution, which has lots of networking related featuers, like multi queue, tso, multi-seg mbuf, etc.

  • Performance

    similar to KNI, this solution would use one or more kthreads to send/receive packets from user space DPDK applications, which has little impact on user space polling thread (except that it might enter into kernel space to wake up those kthreads if necessary).

The overview of an application using virtio-user as exceptional path is shown in Fig. 6.3.

Fig. 6.3 Overview of a DPDK app using virtio-user as excpetional path

6.1. Sample Usage

As a prerequisite, the vhost/vhost-net kernel CONFIG should be chosen before compiling the kernel and those kernel modules should be inserted.

  1. Compile DPDK and bind a physical NIC to igb_uio/uio_pci_generic/vfio-pci.

    This physical NIC is for communicating with outside.

  2. Run testpmd.

    $(testpmd) -c 0xc -n 4 \
            --vdev=virtio_user0,path=/dev/vhost-net,queue_size=1024 \
            -- -i --txqflags=0x0 --disable-hw-vlan --enable-lro --crc-strip \
            --enable-rx-cksum --rxd=1024 --txd=1024
    

    This command runs testpmd with two ports, one physical NIC to communicate with outside, and one virtio-user to communicate with kernel.

  • --enable-lro

    This is used to negotiate VIRTIO_NET_F_GUEST_TSO4 and VIRTIO_NET_F_GUEST_TSO6 feature so that large packets from kernel can be transmitted DPDK application and further TSOed by physical NIC.

  • --enable-rx-cksum

    This is used to negotiate VIRTIO_NET_F_GUEST_CSUM so that packets from kernel can be deemed as valid Rx checksumed.

  • queue_size

    256 by default. To avoid shortage of descriptors, we can increase it to 1024.

  • queues

    Number of multi-queues. Each qeueue will be served by a kthread. For example:

    $(testpmd) -c 0xc -n 4 \
            --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \
            -- -i --txqflags=0x0 --disable-hw-vlan --enable-lro \
            --crc-strip --enable-rx-cksum --txq=2 --rxq=2 --rxd=1024 \
            --txd=1024
    
  1. Start testpmd:

    (testpmd) start
    
  2. Configure IP address and start tap:

    ifconfig tap0 1.1.1.1/24 up
    

Note

The tap device will be named tap0, tap1, etc, by kernel.

Then, all traffic from physical NIC can be forwarded into kernel stack, and all traffic on the tap0 can be sent out from physical NIC.

6.2. Limitations

This solution is only available on Linux systems.