2 Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
15 * Neither the name of Intel Corporation nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 Poll Mode Driver for Emulated Virtio NIC
32 ========================================
34 Virtio is a para-virtualization framework initiated by IBM, and supported by KVM hypervisor.
35 In the Data Plane Development Kit (DPDK),
36 we provide a virtio Poll Mode Driver (PMD) as a software solution, comparing to SRIOV hardware solution,
37 for fast guest VM to guest VM communication and guest VM to host communication.
39 Vhost is a kernel acceleration module for virtio qemu backend.
40 The DPDK extends kni to support vhost raw socket interface,
41 which enables vhost to directly read/ write packets from/to a physical port.
42 With this enhancement, virtio could achieve quite promising performance.
44 In future release, we will also make enhancement to vhost backend,
45 releasing peak performance of virtio PMD driver.
47 For basic qemu-KVM installation and other Intel EM poll mode driver in guest VM,
48 please refer to Chapter "Driver for VM Emulated Devices".
50 In this chapter, we will demonstrate usage of virtio PMD driver with two backends,
51 standard qemu vhost back end and vhost kni back end.
53 Virtio Implementation in DPDK
54 -----------------------------
56 For details about the virtio spec, refer to Virtio PCI Card Specification written by Rusty Russell.
58 As a PMD, virtio provides packet reception and transmission callbacks virtio_recv_pkts and virtio_xmit_pkts.
60 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.
62 In virtio_xmit_pkts, same index range in vring is available for virtio to clean.
63 Virtio will enqueue to be transmitted packets into vring, advance the vq->vq_ring.avail->idx,
64 and then notify the host back end if necessary.
66 Features and Limitations of virtio PMD
67 --------------------------------------
69 In this release, the virtio PMD driver provides the basic functionality of packet reception and transmission.
71 * This release does not support mergeable buffers per packet for performance reasons.
72 The packet size supported is from 64 to 1518.
73 rte_mbuf should be big enough to hold the whole packet.
75 * The descriptor number for the RX/TX queue is hard-coded to be 256 by qemu.
76 If given a different descriptor number by the upper application,
77 the virtio PMD generates a warning and fall back to the hard-coded value.
79 * Features such as mac/vlan filter are not supported.
81 * RTE_PKTMBUF_HEADROOM should be defined larger than sizeof(struct virtio_net_hdr), which is 10 bytes.
83 * Virtio does not support runtime configuration.
88 The following prerequisites apply:
90 * In the BIOS, turn VT-x and VT-d on
92 * Linux kernel with KVM module; vhost module loaded and ioeventfd supported.
93 Qemu standard backend without vhost support isn't tested, and probably isn't supported.
95 Virtio with kni vhost Back End
96 ------------------------------
98 This section demonstrates kni vhost back end example setup for Phy-VM Communication.
102 **Figure 14. Host2VM Communication Example Using kni vhost Back End**
104 .. image29_png has been renamed
108 Host2VM communication example
110 #. Load the kni kernel module:
112 .. code-block:: console
116 Other basic DPDK preparations like hugepage enabling, igb_uio port binding are not listed here.
117 Please refer to the *DPDK Getting Started Guide* for detailed instructions.
119 #. Launch the kni user application:
121 .. code-block:: console
123 examples/kni/build/app/kni -c 0xf -n 4 -- -p 0x1 -i 0x1 -o 0x2
125 This command generates one network device vEth0 for physical port.
126 If specify more physical ports, the generated network device will be vEth1, vEth2, and so on.
128 For each physical port, kni creates two user threads.
129 One thread loops to fetch packets from the physical NIC port into the kni receive queue.
130 The other user thread loops to send packets in the kni transmit queue.
132 For each physical port, kni also creates a kernel thread that retrieves packets from the kni receive queue,
133 place them onto kni's raw socket's queue and wake up the vhost kernel thread to exchange packets with the virtio virt queue.
135 For more details about kni, please refer to Chapter 24 "Kernel NIC Interface".
137 #. Enable the kni raw socket functionality for the specified physical NIC port,
138 get the generated file descriptor and set it in the qemu command line parameter.
139 Always remember to set ioeventfd_on and vhost_on.
143 .. code-block:: console
145 echo 1 > /sys/class/net/vEth0/sock_en
146 fd=`cat /sys/class/net/vEth0/sock_fd`
147 exec qemu-system-x86_64 -enable-kvm -cpu host \
148 -m 2048 -smp 4 -name dpdk-test1-vm1 \
149 -drive file=/data/DPDKVMS/dpdk-vm.img \
150 -netdev tap, fd=$fd,id=mynet_kni, script=no,vhost=on \
151 -device virtio-net-pci,netdev=mynet_kni,bus=pci.0,addr=0x3,ioeventfd=on \
154 In the above example, virtio port 0 in the guest VM will be associated with vEth0, which in turns corresponds to a physical port,
155 which means received packets come from vEth0, and transmitted packets is sent to vEth0.
157 #. In the guest, bind the virtio device to the igb_uio kernel module and start the forwarding application.
158 When the virtio port in guest bursts rx, it is getting packets from the raw socket's receive queue.
159 When the virtio port bursts tx, it is sending packet to the tx_q.
161 .. code-block:: console
164 echo 512 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
165 insmod x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
166 python tools/dpdk_nic_bind.py -b igb_uio 00:03.0
168 We use testpmd as the forwarding application in this example.
170 .. image30_png has been renamed
174 #. Use IXIA packet generator to inject a packet stream into the KNI physical port.
176 The packet reception and transmission flow path is:
178 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
180 Virtio with qemu virtio Back End
181 --------------------------------
185 **Figure 15. Host2VM Communication Example Using qemu vhost Back End**
187 .. image31_png has been renamed
191 .. code-block:: console
193 qemu-system-x86_64 -enable-kvm -cpu host -m 2048 -smp 2 -mem-path /dev/
194 hugepages -mem-prealloc
195 -drive file=/data/DPDKVMS/dpdk-vm1
196 -netdev tap,id=vm1_p1,ifname=tap0,script=no,vhost=on
197 -device virtio-net-pci,netdev=vm1_p1,bus=pci.0,addr=0x3,ioeventfd=on
198 -device pci-assign,host=04:10.1 \
200 In this example, the packet reception flow path is:
202 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
204 The packet transmission flow is:
206 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
208 .. |host_vm_comms| image:: img/host_vm_comms.png
210 .. |console| image:: img/console.png
212 .. |host_vm_comms_qemu| image:: img/host_vm_comms_qemu.png