doc: add vhost library
[dpdk.git] / doc / guides / prog_guide / vhost_lib.rst
1 ..  BSD LICENSE
2     Copyright(c) 2010-2014 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 Vhost Library
32 =============
33
34 The vhost cuse (cuse: user space character device driver) library implements a
35 vhost cuse driver. It also creates, manages and destroys vhost devices for
36 corresponding virtio devices in the guest. Vhost supported vSwitch could register
37 callbacks to this library, which will be called when a vhost device is activated
38 or deactivated by guest virtual machine.
39
40 Vhost API Overview
41 ------------------
42
43 *   Vhost driver registration
44
45       rte_vhost_driver_register registers the vhost cuse driver into the system.
46       Character device file will be created in the /dev directory.
47       Character device name is specified as the parameter.
48
49 *   Vhost session start
50
51       rte_vhost_driver_session_start starts the vhost session loop.
52       Vhost cuse session is an infinite blocking loop.
53       Put the session in a dedicate DPDK thread.
54
55 *   Callback register
56
57       Vhost supported vSwitch could call rte_vhost_driver_callback_register to
58       register two callbacks, new_destory and destroy_device.
59       When virtio device is activated or deactivated by guest virtual machine,
60       the callback will be called, then vSwitch could put the device onto data
61       core or remove the device from data core.
62
63 *   Read/write packets from/to guest virtual machine
64
65       rte_vhost_enqueue_burst transmit host packets to guest.
66       rte_vhost_dequeue_burst receives packets from guest.
67
68 *   Feature enable/disable
69
70       Now one negotiate-able feature in vhost is merge-able.
71       vSwitch could enable/disable this feature for performance consideration.
72
73 Vhost Implementation
74 --------------------
75
76 When vSwitch registers the vhost driver, it will register a cuse device driver
77 into the system and creates a character device file. This cuse driver will
78 receive vhost open/release/IOCTL message from QEMU simulator.
79
80 When the open call is received, vhost driver will create a vhost device for the
81 virtio device in the guest.
82
83 When VHOST_SET_MEM_TABLE IOCTL is received, vhost searches the memory region
84 to find the starting user space virtual address that maps the memory of guest
85 virtual machine. Through this virtual address and the QEMU pid, vhost could
86 find the file QEMU uses to map the guest memory. Vhost maps this file into its
87 address space, in this way vhost could fully access the guest physical memory,
88 which means vhost could access the shared virtio ring and the guest physical
89 address specified in the entry of the ring.
90
91 The guest virtual machine tells the vhost whether the virtio device is ready
92 for processing or is de-activated through VHOST_SET_BACKEND message.
93 The registered callback from vSwitch will be called.
94
95 When the release call is released, vhost will destroy the device.
96
97 Vhost supported vSwitch reference
98 ---------------------------------
99
100 For how to support vhost in vSwitch, please refer to vhost example in the
101 DPDK Sample Applications Guide.