app/testpmd: disable Rx VLAN offloads by default
[dpdk.git] / doc / guides / nics / virtio.rst
1 ..  BSD LICENSE
2     Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
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
14     distribution.
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.
18
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.
30
31 Poll Mode Driver for Emulated Virtio NIC
32 ========================================
33
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
38 for fast guest VM to guest VM communication and guest VM to host communication.
39
40 Vhost is a kernel acceleration module for virtio qemu backend.
41 The DPDK extends kni to support vhost raw socket interface,
42 which enables vhost to directly read/ write packets from/to a physical port.
43 With this enhancement, virtio could achieve quite promising performance.
44
45 For basic qemu-KVM installation and other Intel EM poll mode driver in guest VM,
46 please refer to Chapter "Driver for VM Emulated Devices".
47
48 In this chapter, we will demonstrate usage of virtio PMD driver with two backends,
49 standard qemu vhost back end and vhost kni back end.
50
51 Virtio Implementation in DPDK
52 -----------------------------
53
54 For details about the virtio spec, refer to Virtio PCI Card Specification written by Rusty Russell.
55
56 As a PMD, virtio provides packet reception and transmission callbacks virtio_recv_pkts and virtio_xmit_pkts.
57
58 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.
59
60 In virtio_xmit_pkts, same index range in vring is available for virtio to clean.
61 Virtio will enqueue to be transmitted packets into vring, advance the vq->vq_ring.avail->idx,
62 and then notify the host back end if necessary.
63
64 Features and Limitations of virtio PMD
65 --------------------------------------
66
67 In this release, the virtio PMD driver provides the basic functionality of packet reception and transmission.
68
69 *   It supports merge-able buffers per packet when receiving packets and scattered buffer per packet
70     when transmitting packets. The packet size supported is from 64 to 1518.
71
72 *   It supports multicast packets and promiscuous mode.
73
74 *   The descriptor number for the Rx/Tx queue is hard-coded to be 256 by qemu 2.7 and below.
75     If given a different descriptor number by the upper application,
76     the virtio PMD generates a warning and fall back to the hard-coded value.
77     Rx queue size can be configureable and up to 1024 since qemu 2.8 and above. Rx queue size is 256
78     by default. Tx queue size is still hard-coded to be 256.
79
80 *   Features of mac/vlan filter are supported, negotiation with vhost/backend are needed to support them.
81     When backend can't support vlan filter, virtio app on guest should not enable vlan filter in order
82     to make sure the virtio port is configured correctly. E.g. do not specify '--enable-hw-vlan' in testpmd
83     command line.
84
85 *   "RTE_PKTMBUF_HEADROOM" should be defined
86     no less than "sizeof(struct virtio_net_hdr_mrg_rxbuf)", which is 12 bytes when mergeable or
87     "VIRTIO_F_VERSION_1" is set.
88     no less than "sizeof(struct virtio_net_hdr)", which is 10 bytes, when using non-mergeable.
89
90 *   Virtio does not support runtime configuration.
91
92 *   Virtio supports Link State interrupt.
93
94 *   Virtio supports Rx interrupt (so far, only support 1:1 mapping for queue/interrupt).
95
96 *   Virtio supports software vlan stripping and inserting.
97
98 *   Virtio supports using port IO to get PCI resource when uio/igb_uio module is not available.
99
100 Prerequisites
101 -------------
102
103 The following prerequisites apply:
104
105 *   In the BIOS, turn VT-x and VT-d on
106
107 *   Linux kernel with KVM module; vhost module loaded and ioeventfd supported.
108     Qemu standard backend without vhost support isn't tested, and probably isn't supported.
109
110 Virtio with kni vhost Back End
111 ------------------------------
112
113 This section demonstrates kni vhost back end example setup for Phy-VM Communication.
114
115 .. _figure_host_vm_comms:
116
117 .. figure:: img/host_vm_comms.*
118
119    Host2VM Communication Example Using kni vhost Back End
120
121
122 Host2VM communication example
123
124 #.  Load the kni kernel module:
125
126     .. code-block:: console
127
128         insmod rte_kni.ko
129
130     Other basic DPDK preparations like hugepage enabling, uio port binding are not listed here.
131     Please refer to the *DPDK Getting Started Guide* for detailed instructions.
132
133 #.  Launch the kni user application:
134
135     .. code-block:: console
136
137         examples/kni/build/app/kni -l 0-3 -n 4 -- -p 0x1 -P --config="(0,1,3)"
138
139     This command generates one network device vEth0 for physical port.
140     If specify more physical ports, the generated network device will be vEth1, vEth2, and so on.
141
142     For each physical port, kni creates two user threads.
143     One thread loops to fetch packets from the physical NIC port into the kni receive queue.
144     The other user thread loops to send packets in the kni transmit queue.
145
146     For each physical port, kni also creates a kernel thread that retrieves packets from the kni receive queue,
147     place them onto kni's raw socket's queue and wake up the vhost kernel thread to exchange packets with the virtio virt queue.
148
149     For more details about kni, please refer to :ref:`kni`.
150
151 #.  Enable the kni raw socket functionality for the specified physical NIC port,
152     get the generated file descriptor and set it in the qemu command line parameter.
153     Always remember to set ioeventfd_on and vhost_on.
154
155     Example:
156
157     .. code-block:: console
158
159         echo 1 > /sys/class/net/vEth0/sock_en
160         fd=`cat /sys/class/net/vEth0/sock_fd`
161         exec qemu-system-x86_64 -enable-kvm -cpu host \
162         -m 2048 -smp 4 -name dpdk-test1-vm1 \
163         -drive file=/data/DPDKVMS/dpdk-vm.img \
164         -netdev tap, fd=$fd,id=mynet_kni, script=no,vhost=on \
165         -device virtio-net-pci,netdev=mynet_kni,bus=pci.0,addr=0x3,ioeventfd=on \
166         -vnc:1 -daemonize
167
168     In the above example, virtio port 0 in the guest VM will be associated with vEth0, which in turns corresponds to a physical port,
169     which means received packets come from vEth0, and transmitted packets is sent to vEth0.
170
171 #.  In the guest, bind the virtio device to the uio_pci_generic kernel module and start the forwarding application.
172     When the virtio port in guest bursts Rx, it is getting packets from the
173     raw socket's receive queue.
174     When the virtio port bursts Tx, it is sending packet to the tx_q.
175
176     .. code-block:: console
177
178         modprobe uio
179         echo 512 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
180         modprobe uio_pci_generic
181         python usertools/dpdk-devbind.py -b uio_pci_generic 00:03.0
182
183     We use testpmd as the forwarding application in this example.
184
185     .. figure:: img/console.*
186
187        Running testpmd
188
189 #.  Use IXIA packet generator to inject a packet stream into the KNI physical port.
190
191     The packet reception and transmission flow path is:
192
193     IXIA packet generator->82599 PF->KNI Rx queue->KNI raw socket queue->Guest
194     VM virtio port 0 Rx burst->Guest VM virtio port 0 Tx burst-> KNI Tx queue
195     ->82599 PF-> IXIA packet generator
196
197 Virtio with qemu virtio Back End
198 --------------------------------
199
200 .. _figure_host_vm_comms_qemu:
201
202 .. figure:: img/host_vm_comms_qemu.*
203
204    Host2VM Communication Example Using qemu vhost Back End
205
206
207 .. code-block:: console
208
209     qemu-system-x86_64 -enable-kvm -cpu host -m 2048 -smp 2 -mem-path /dev/
210     hugepages -mem-prealloc
211     -drive file=/data/DPDKVMS/dpdk-vm1
212     -netdev tap,id=vm1_p1,ifname=tap0,script=no,vhost=on
213     -device virtio-net-pci,netdev=vm1_p1,bus=pci.0,addr=0x3,ioeventfd=on
214     -device pci-assign,host=04:10.1 \
215
216 In this example, the packet reception flow path is:
217
218     IXIA packet generator->82599 PF->Linux Bridge->TAP0's socket queue-> Guest
219     VM virtio port 0 Rx burst-> Guest VM 82599 VF port1 Tx burst-> IXIA packet
220     generator
221
222 The packet transmission flow is:
223
224     IXIA packet generator-> Guest VM 82599 VF port1 Rx burst-> Guest VM virtio
225     port 0 Tx burst-> tap -> Linux Bridge->82599 PF-> IXIA packet generator
226
227
228 Virtio PMD Rx/Tx Callbacks
229 --------------------------
230
231 Virtio driver has 3 Rx callbacks and 2 Tx callbacks.
232
233 Rx callbacks:
234
235 #. ``virtio_recv_pkts``:
236    Regular version without mergeable Rx buffer support.
237
238 #. ``virtio_recv_mergeable_pkts``:
239    Regular version with mergeable Rx buffer support.
240
241 #. ``virtio_recv_pkts_vec``:
242    Vector version without mergeable Rx buffer support, also fixes the available
243    ring indexes and uses vector instructions to optimize performance.
244
245 Tx callbacks:
246
247 #. ``virtio_xmit_pkts``:
248    Regular version.
249
250 #. ``virtio_xmit_pkts_simple``:
251    Vector version fixes the available ring indexes to optimize performance.
252
253
254 By default, the non-vector callbacks are used:
255
256 *   For Rx: If mergeable Rx buffers is disabled then ``virtio_recv_pkts`` is
257     used; otherwise ``virtio_recv_mergeable_pkts``.
258
259 *   For Tx: ``virtio_xmit_pkts``.
260
261
262 Vector callbacks will be used when:
263
264 *   ``txq_flags`` is set to ``VIRTIO_SIMPLE_FLAGS`` (0xF01), which implies:
265
266     *   Single segment is specified.
267
268     *   No offload support is needed.
269
270 *   Mergeable Rx buffers is disabled.
271
272 The corresponding callbacks are:
273
274 *   For Rx: ``virtio_recv_pkts_vec``.
275
276 *   For Tx: ``virtio_xmit_pkts_simple``.
277
278
279 Example of using the vector version of the virtio poll mode driver in
280 ``testpmd``::
281
282    testpmd -l 0-2 -n 4 -- -i --txqflags=0xF01 --rxq=1 --txq=1 --nb-cores=1
283
284
285 Interrupt mode
286 --------------
287
288 .. _virtio_interrupt_mode:
289
290 There are three kinds of interrupts from a virtio device over PCI bus: config
291 interrupt, Rx interrupts, and Tx interrupts. Config interrupt is used for
292 notification of device configuration changes, especially link status (lsc).
293 Interrupt mode is translated into Rx interrupts in the context of DPDK.
294
295 .. Note::
296
297    Virtio PMD already has support for receiving lsc from qemu when the link
298    status changes, especially when vhost user disconnects. However, it fails
299    to do that if the VM is created by qemu 2.6.2 or below, since the
300    capability to detect vhost user disconnection is introduced in qemu 2.7.0.
301
302 Prerequisites for Rx interrupts
303 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304
305 To support Rx interrupts,
306 #. Check if guest kernel supports VFIO-NOIOMMU:
307
308     Linux started to support VFIO-NOIOMMU since 4.8.0. Make sure the guest
309     kernel is compiled with:
310
311     .. code-block:: console
312
313         CONFIG_VFIO_NOIOMMU=y
314
315 #. Properly set msix vectors when starting VM:
316
317     Enable multi-queue when starting VM, and specify msix vectors in qemu
318     cmdline. (N+1) is the minimum, and (2N+2) is mostly recommended.
319
320     .. code-block:: console
321
322         $(QEMU) ... -device virtio-net-pci,mq=on,vectors=2N+2 ...
323
324 #. In VM, insert vfio module in NOIOMMU mode:
325
326     .. code-block:: console
327
328         modprobe vfio enable_unsafe_noiommu_mode=1
329         modprobe vfio-pci
330
331 #. In VM, bind the virtio device with vfio-pci:
332
333     .. code-block:: console
334
335         python usertools/dpdk-devbind.py -b vfio-pci 00:03.0
336
337 Example
338 ~~~~~~~
339
340 Here we use l3fwd-power as an example to show how to get started.
341
342     Example:
343
344     .. code-block:: console
345
346         $ l3fwd-power -l 0-1 -- -p 1 -P --config="(0,0,1)" \
347                                                --no-numa --parse-ptype