2018-02-01 17:18:17 +00:00
|
|
|
.. SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
Copyright(c) 2010-2015 Intel Corporation.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
Poll Mode Driver for Emulated Virtio NIC
|
|
|
|
========================================
|
|
|
|
|
|
|
|
Virtio is a para-virtualization framework initiated by IBM, and supported by KVM hypervisor.
|
2014-12-19 14:30:42 +00:00
|
|
|
In the Data Plane Development Kit (DPDK),
|
2014-11-14 11:53:41 +00:00
|
|
|
we provide a virtio Poll Mode Driver (PMD) as a software solution, comparing to SRIOV hardware solution,
|
2017-05-11 02:16:35 +00:00
|
|
|
|
2014-11-14 11:53:41 +00:00
|
|
|
for fast guest VM to guest VM communication and guest VM to host communication.
|
|
|
|
|
|
|
|
Vhost is a kernel acceleration module for virtio qemu backend.
|
2014-12-19 14:30:42 +00:00
|
|
|
The DPDK extends kni to support vhost raw socket interface,
|
2014-11-14 11:53:41 +00:00
|
|
|
which enables vhost to directly read/ write packets from/to a physical port.
|
|
|
|
With this enhancement, virtio could achieve quite promising performance.
|
|
|
|
|
|
|
|
For basic qemu-KVM installation and other Intel EM poll mode driver in guest VM,
|
|
|
|
please refer to Chapter "Driver for VM Emulated Devices".
|
|
|
|
|
|
|
|
In this chapter, we will demonstrate usage of virtio PMD driver with two backends,
|
|
|
|
standard qemu vhost back end and vhost kni back end.
|
|
|
|
|
2014-12-19 14:30:42 +00:00
|
|
|
Virtio Implementation in DPDK
|
|
|
|
-----------------------------
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
For details about the virtio spec, refer to Virtio PCI Card Specification written by Rusty Russell.
|
|
|
|
|
|
|
|
As a PMD, virtio provides packet reception and transmission callbacks virtio_recv_pkts and virtio_xmit_pkts.
|
|
|
|
|
|
|
|
In virtio_recv_pkts, index in range [vq->vq_used_cons_idx , vq->vq_ring.used->idx) in vring is available for virtio to burst out.
|
|
|
|
|
|
|
|
In virtio_xmit_pkts, same index range in vring is available for virtio to clean.
|
|
|
|
Virtio will enqueue to be transmitted packets into vring, advance the vq->vq_ring.avail->idx,
|
|
|
|
and then notify the host back end if necessary.
|
|
|
|
|
|
|
|
Features and Limitations of virtio PMD
|
|
|
|
--------------------------------------
|
|
|
|
|
|
|
|
In this release, the virtio PMD driver provides the basic functionality of packet reception and transmission.
|
|
|
|
|
2015-03-02 08:40:47 +00:00
|
|
|
* It supports merge-able buffers per packet when receiving packets and scattered buffer per packet
|
|
|
|
when transmitting packets. The packet size supported is from 64 to 1518.
|
|
|
|
|
|
|
|
* It supports multicast packets and promiscuous mode.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
2017-05-11 02:16:35 +00:00
|
|
|
* The descriptor number for the Rx/Tx queue is hard-coded to be 256 by qemu 2.7 and below.
|
2014-11-14 11:53:41 +00:00
|
|
|
If given a different descriptor number by the upper application,
|
|
|
|
the virtio PMD generates a warning and fall back to the hard-coded value.
|
2017-05-11 02:16:35 +00:00
|
|
|
Rx queue size can be configureable and up to 1024 since qemu 2.8 and above. Rx queue size is 256
|
|
|
|
by default. Tx queue size is still hard-coded to be 256.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
2015-03-02 08:40:47 +00:00
|
|
|
* Features of mac/vlan filter are supported, negotiation with vhost/backend are needed to support them.
|
2018-01-31 17:32:03 +00:00
|
|
|
When backend can't support vlan filter, virtio app on guest should not enable vlan filter in order
|
|
|
|
to make sure the virtio port is configured correctly. E.g. do not specify '--enable-hw-vlan' in testpmd
|
|
|
|
command line.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
2017-05-11 02:16:35 +00:00
|
|
|
* "RTE_PKTMBUF_HEADROOM" should be defined
|
|
|
|
no less than "sizeof(struct virtio_net_hdr_mrg_rxbuf)", which is 12 bytes when mergeable or
|
|
|
|
"VIRTIO_F_VERSION_1" is set.
|
|
|
|
no less than "sizeof(struct virtio_net_hdr)", which is 10 bytes, when using non-mergeable.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
* Virtio does not support runtime configuration.
|
|
|
|
|
2015-03-02 08:40:47 +00:00
|
|
|
* Virtio supports Link State interrupt.
|
|
|
|
|
2017-01-17 08:00:03 +00:00
|
|
|
* Virtio supports Rx interrupt (so far, only support 1:1 mapping for queue/interrupt).
|
|
|
|
|
2015-03-02 08:40:47 +00:00
|
|
|
* Virtio supports software vlan stripping and inserting.
|
|
|
|
|
|
|
|
* Virtio supports using port IO to get PCI resource when uio/igb_uio module is not available.
|
|
|
|
|
2014-11-14 11:53:41 +00:00
|
|
|
Prerequisites
|
|
|
|
-------------
|
|
|
|
|
|
|
|
The following prerequisites apply:
|
|
|
|
|
|
|
|
* In the BIOS, turn VT-x and VT-d on
|
|
|
|
|
|
|
|
* Linux kernel with KVM module; vhost module loaded and ioeventfd supported.
|
|
|
|
Qemu standard backend without vhost support isn't tested, and probably isn't supported.
|
|
|
|
|
|
|
|
Virtio with kni vhost Back End
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
This section demonstrates kni vhost back end example setup for Phy-VM Communication.
|
|
|
|
|
2015-05-18 11:34:06 +00:00
|
|
|
.. _figure_host_vm_comms:
|
2014-11-14 11:53:41 +00:00
|
|
|
|
2015-05-18 11:34:06 +00:00
|
|
|
.. figure:: img/host_vm_comms.*
|
|
|
|
|
|
|
|
Host2VM Communication Example Using kni vhost Back End
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
Host2VM communication example
|
|
|
|
|
|
|
|
#. Load the kni kernel module:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
insmod rte_kni.ko
|
|
|
|
|
2015-02-24 16:27:40 +00:00
|
|
|
Other basic DPDK preparations like hugepage enabling, uio port binding are not listed here.
|
2014-12-19 14:30:42 +00:00
|
|
|
Please refer to the *DPDK Getting Started Guide* for detailed instructions.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
#. Launch the kni user application:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-02-27 19:13:40 +00:00
|
|
|
examples/kni/build/app/kni -l 0-3 -n 4 -- -p 0x1 -P --config="(0,1,3)"
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
This command generates one network device vEth0 for physical port.
|
|
|
|
If specify more physical ports, the generated network device will be vEth1, vEth2, and so on.
|
|
|
|
|
|
|
|
For each physical port, kni creates two user threads.
|
|
|
|
One thread loops to fetch packets from the physical NIC port into the kni receive queue.
|
|
|
|
The other user thread loops to send packets in the kni transmit queue.
|
|
|
|
|
|
|
|
For each physical port, kni also creates a kernel thread that retrieves packets from the kni receive queue,
|
|
|
|
place them onto kni's raw socket's queue and wake up the vhost kernel thread to exchange packets with the virtio virt queue.
|
|
|
|
|
2016-04-11 21:21:35 +00:00
|
|
|
For more details about kni, please refer to :ref:`kni`.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
#. Enable the kni raw socket functionality for the specified physical NIC port,
|
|
|
|
get the generated file descriptor and set it in the qemu command line parameter.
|
|
|
|
Always remember to set ioeventfd_on and vhost_on.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
echo 1 > /sys/class/net/vEth0/sock_en
|
|
|
|
fd=`cat /sys/class/net/vEth0/sock_fd`
|
|
|
|
exec qemu-system-x86_64 -enable-kvm -cpu host \
|
|
|
|
-m 2048 -smp 4 -name dpdk-test1-vm1 \
|
|
|
|
-drive file=/data/DPDKVMS/dpdk-vm.img \
|
|
|
|
-netdev tap, fd=$fd,id=mynet_kni, script=no,vhost=on \
|
|
|
|
-device virtio-net-pci,netdev=mynet_kni,bus=pci.0,addr=0x3,ioeventfd=on \
|
|
|
|
-vnc:1 -daemonize
|
|
|
|
|
|
|
|
In the above example, virtio port 0 in the guest VM will be associated with vEth0, which in turns corresponds to a physical port,
|
|
|
|
which means received packets come from vEth0, and transmitted packets is sent to vEth0.
|
|
|
|
|
2015-02-24 16:27:40 +00:00
|
|
|
#. In the guest, bind the virtio device to the uio_pci_generic kernel module and start the forwarding application.
|
2016-07-01 03:28:01 +00:00
|
|
|
When the virtio port in guest bursts Rx, it is getting packets from the
|
|
|
|
raw socket's receive queue.
|
|
|
|
When the virtio port bursts Tx, it is sending packet to the tx_q.
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
modprobe uio
|
|
|
|
echo 512 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
|
2015-02-24 16:27:40 +00:00
|
|
|
modprobe uio_pci_generic
|
2016-12-15 21:25:36 +00:00
|
|
|
python usertools/dpdk-devbind.py -b uio_pci_generic 00:03.0
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
We use testpmd as the forwarding application in this example.
|
|
|
|
|
2015-05-18 11:34:06 +00:00
|
|
|
.. figure:: img/console.*
|
|
|
|
|
|
|
|
Running testpmd
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
#. Use IXIA packet generator to inject a packet stream into the KNI physical port.
|
|
|
|
|
|
|
|
The packet reception and transmission flow path is:
|
|
|
|
|
2016-07-01 03:28:01 +00:00
|
|
|
IXIA packet generator->82599 PF->KNI Rx queue->KNI raw socket queue->Guest
|
|
|
|
VM virtio port 0 Rx burst->Guest VM virtio port 0 Tx burst-> KNI Tx queue
|
|
|
|
->82599 PF-> IXIA packet generator
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
Virtio with qemu virtio Back End
|
|
|
|
--------------------------------
|
|
|
|
|
2015-05-18 11:34:06 +00:00
|
|
|
.. _figure_host_vm_comms_qemu:
|
|
|
|
|
|
|
|
.. figure:: img/host_vm_comms_qemu.*
|
2014-11-14 11:53:41 +00:00
|
|
|
|
2015-05-18 11:34:06 +00:00
|
|
|
Host2VM Communication Example Using qemu vhost Back End
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
qemu-system-x86_64 -enable-kvm -cpu host -m 2048 -smp 2 -mem-path /dev/
|
|
|
|
hugepages -mem-prealloc
|
|
|
|
-drive file=/data/DPDKVMS/dpdk-vm1
|
|
|
|
-netdev tap,id=vm1_p1,ifname=tap0,script=no,vhost=on
|
|
|
|
-device virtio-net-pci,netdev=vm1_p1,bus=pci.0,addr=0x3,ioeventfd=on
|
|
|
|
-device pci-assign,host=04:10.1 \
|
|
|
|
|
|
|
|
In this example, the packet reception flow path is:
|
|
|
|
|
2016-07-01 03:28:01 +00:00
|
|
|
IXIA packet generator->82599 PF->Linux Bridge->TAP0's socket queue-> Guest
|
|
|
|
VM virtio port 0 Rx burst-> Guest VM 82599 VF port1 Tx burst-> IXIA packet
|
|
|
|
generator
|
2014-11-14 11:53:41 +00:00
|
|
|
|
|
|
|
The packet transmission flow is:
|
|
|
|
|
2016-07-01 03:28:01 +00:00
|
|
|
IXIA packet generator-> Guest VM 82599 VF port1 Rx burst-> Guest VM virtio
|
|
|
|
port 0 Tx burst-> tap -> Linux Bridge->82599 PF-> IXIA packet generator
|
|
|
|
|
|
|
|
|
|
|
|
Virtio PMD Rx/Tx Callbacks
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
Virtio driver has 3 Rx callbacks and 2 Tx callbacks.
|
|
|
|
|
|
|
|
Rx callbacks:
|
|
|
|
|
|
|
|
#. ``virtio_recv_pkts``:
|
|
|
|
Regular version without mergeable Rx buffer support.
|
|
|
|
|
|
|
|
#. ``virtio_recv_mergeable_pkts``:
|
|
|
|
Regular version with mergeable Rx buffer support.
|
|
|
|
|
|
|
|
#. ``virtio_recv_pkts_vec``:
|
|
|
|
Vector version without mergeable Rx buffer support, also fixes the available
|
|
|
|
ring indexes and uses vector instructions to optimize performance.
|
|
|
|
|
|
|
|
Tx callbacks:
|
|
|
|
|
|
|
|
#. ``virtio_xmit_pkts``:
|
|
|
|
Regular version.
|
|
|
|
|
|
|
|
#. ``virtio_xmit_pkts_simple``:
|
|
|
|
Vector version fixes the available ring indexes to optimize performance.
|
|
|
|
|
|
|
|
|
|
|
|
By default, the non-vector callbacks are used:
|
|
|
|
|
|
|
|
* For Rx: If mergeable Rx buffers is disabled then ``virtio_recv_pkts`` is
|
|
|
|
used; otherwise ``virtio_recv_mergeable_pkts``.
|
|
|
|
|
|
|
|
* For Tx: ``virtio_xmit_pkts``.
|
|
|
|
|
|
|
|
|
|
|
|
Vector callbacks will be used when:
|
|
|
|
|
|
|
|
* ``txq_flags`` is set to ``VIRTIO_SIMPLE_FLAGS`` (0xF01), which implies:
|
|
|
|
|
|
|
|
* Single segment is specified.
|
|
|
|
|
|
|
|
* No offload support is needed.
|
|
|
|
|
|
|
|
* Mergeable Rx buffers is disabled.
|
|
|
|
|
|
|
|
The corresponding callbacks are:
|
|
|
|
|
|
|
|
* For Rx: ``virtio_recv_pkts_vec``.
|
|
|
|
|
|
|
|
* For Tx: ``virtio_xmit_pkts_simple``.
|
|
|
|
|
|
|
|
|
|
|
|
Example of using the vector version of the virtio poll mode driver in
|
|
|
|
``testpmd``::
|
|
|
|
|
2017-02-27 19:13:40 +00:00
|
|
|
testpmd -l 0-2 -n 4 -- -i --txqflags=0xF01 --rxq=1 --txq=1 --nb-cores=1
|
2017-01-17 08:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
Interrupt mode
|
|
|
|
--------------
|
|
|
|
|
|
|
|
.. _virtio_interrupt_mode:
|
|
|
|
|
|
|
|
There are three kinds of interrupts from a virtio device over PCI bus: config
|
|
|
|
interrupt, Rx interrupts, and Tx interrupts. Config interrupt is used for
|
|
|
|
notification of device configuration changes, especially link status (lsc).
|
|
|
|
Interrupt mode is translated into Rx interrupts in the context of DPDK.
|
|
|
|
|
2017-10-16 05:41:21 +00:00
|
|
|
.. Note::
|
|
|
|
|
|
|
|
Virtio PMD already has support for receiving lsc from qemu when the link
|
|
|
|
status changes, especially when vhost user disconnects. However, it fails
|
|
|
|
to do that if the VM is created by qemu 2.6.2 or below, since the
|
|
|
|
capability to detect vhost user disconnection is introduced in qemu 2.7.0.
|
|
|
|
|
2017-01-17 08:00:03 +00:00
|
|
|
Prerequisites for Rx interrupts
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
To support Rx interrupts,
|
|
|
|
#. Check if guest kernel supports VFIO-NOIOMMU:
|
|
|
|
|
|
|
|
Linux started to support VFIO-NOIOMMU since 4.8.0. Make sure the guest
|
|
|
|
kernel is compiled with:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
CONFIG_VFIO_NOIOMMU=y
|
|
|
|
|
|
|
|
#. Properly set msix vectors when starting VM:
|
|
|
|
|
|
|
|
Enable multi-queue when starting VM, and specify msix vectors in qemu
|
|
|
|
cmdline. (N+1) is the minimum, and (2N+2) is mostly recommended.
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$(QEMU) ... -device virtio-net-pci,mq=on,vectors=2N+2 ...
|
|
|
|
|
|
|
|
#. In VM, insert vfio module in NOIOMMU mode:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
modprobe vfio enable_unsafe_noiommu_mode=1
|
|
|
|
modprobe vfio-pci
|
|
|
|
|
|
|
|
#. In VM, bind the virtio device with vfio-pci:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-05-02 11:54:20 +00:00
|
|
|
python usertools/dpdk-devbind.py -b vfio-pci 00:03.0
|
2017-01-17 08:00:03 +00:00
|
|
|
|
|
|
|
Example
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
Here we use l3fwd-power as an example to show how to get started.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-02-27 19:13:40 +00:00
|
|
|
$ l3fwd-power -l 0-1 -- -p 1 -P --config="(0,0,1)" \
|
2017-01-17 08:00:03 +00:00
|
|
|
--no-numa --parse-ptype
|