xref: /dpdk/doc/guides/prog_guide/vhost_lib.rst (revision 0ee5e7fb93aefe9bccb6a9c331cfe27c14bc7ec6)
1*0ee5e7fbSSiobhan Butler..  BSD LICENSE
2*0ee5e7fbSSiobhan Butler    Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
3*0ee5e7fbSSiobhan Butler    All rights reserved.
4*0ee5e7fbSSiobhan Butler
5*0ee5e7fbSSiobhan Butler    Redistribution and use in source and binary forms, with or without
6*0ee5e7fbSSiobhan Butler    modification, are permitted provided that the following conditions
7*0ee5e7fbSSiobhan Butler    are met:
8*0ee5e7fbSSiobhan Butler
9*0ee5e7fbSSiobhan Butler    * Redistributions of source code must retain the above copyright
10*0ee5e7fbSSiobhan Butler    notice, this list of conditions and the following disclaimer.
11*0ee5e7fbSSiobhan Butler    * Redistributions in binary form must reproduce the above copyright
12*0ee5e7fbSSiobhan Butler    notice, this list of conditions and the following disclaimer in
13*0ee5e7fbSSiobhan Butler    the documentation and/or other materials provided with the
14*0ee5e7fbSSiobhan Butler    distribution.
15*0ee5e7fbSSiobhan Butler    * Neither the name of Intel Corporation nor the names of its
16*0ee5e7fbSSiobhan Butler    contributors may be used to endorse or promote products derived
17*0ee5e7fbSSiobhan Butler    from this software without specific prior written permission.
18*0ee5e7fbSSiobhan Butler
19*0ee5e7fbSSiobhan Butler    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*0ee5e7fbSSiobhan Butler    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*0ee5e7fbSSiobhan Butler    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*0ee5e7fbSSiobhan Butler    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*0ee5e7fbSSiobhan Butler    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*0ee5e7fbSSiobhan Butler    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*0ee5e7fbSSiobhan Butler    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*0ee5e7fbSSiobhan Butler    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*0ee5e7fbSSiobhan Butler    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*0ee5e7fbSSiobhan Butler    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*0ee5e7fbSSiobhan Butler    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*0ee5e7fbSSiobhan Butler
31*0ee5e7fbSSiobhan ButlerVhost Library
32*0ee5e7fbSSiobhan Butler=============
33*0ee5e7fbSSiobhan Butler
34*0ee5e7fbSSiobhan ButlerThe vhost cuse (cuse: user space character device driver) library implements a
35*0ee5e7fbSSiobhan Butlervhost cuse driver. It also creates, manages and destroys vhost devices for
36*0ee5e7fbSSiobhan Butlercorresponding virtio devices in the guest. Vhost supported vSwitch could register
37*0ee5e7fbSSiobhan Butlercallbacks to this library, which will be called when a vhost device is activated
38*0ee5e7fbSSiobhan Butleror deactivated by guest virtual machine.
39*0ee5e7fbSSiobhan Butler
40*0ee5e7fbSSiobhan ButlerVhost API Overview
41*0ee5e7fbSSiobhan Butler------------------
42*0ee5e7fbSSiobhan Butler
43*0ee5e7fbSSiobhan Butler*   Vhost driver registration
44*0ee5e7fbSSiobhan Butler
45*0ee5e7fbSSiobhan Butler      rte_vhost_driver_register registers the vhost cuse driver into the system.
46*0ee5e7fbSSiobhan Butler      Character device file will be created in the /dev directory.
47*0ee5e7fbSSiobhan Butler      Character device name is specified as the parameter.
48*0ee5e7fbSSiobhan Butler
49*0ee5e7fbSSiobhan Butler*   Vhost session start
50*0ee5e7fbSSiobhan Butler
51*0ee5e7fbSSiobhan Butler      rte_vhost_driver_session_start starts the vhost session loop.
52*0ee5e7fbSSiobhan Butler      Vhost cuse session is an infinite blocking loop.
53*0ee5e7fbSSiobhan Butler      Put the session in a dedicate DPDK thread.
54*0ee5e7fbSSiobhan Butler
55*0ee5e7fbSSiobhan Butler*   Callback register
56*0ee5e7fbSSiobhan Butler
57*0ee5e7fbSSiobhan Butler      Vhost supported vSwitch could call rte_vhost_driver_callback_register to
58*0ee5e7fbSSiobhan Butler      register two callbacks, new_destory and destroy_device.
59*0ee5e7fbSSiobhan Butler      When virtio device is activated or deactivated by guest virtual machine,
60*0ee5e7fbSSiobhan Butler      the callback will be called, then vSwitch could put the device onto data
61*0ee5e7fbSSiobhan Butler      core or remove the device from data core.
62*0ee5e7fbSSiobhan Butler
63*0ee5e7fbSSiobhan Butler*   Read/write packets from/to guest virtual machine
64*0ee5e7fbSSiobhan Butler
65*0ee5e7fbSSiobhan Butler      rte_vhost_enqueue_burst transmit host packets to guest.
66*0ee5e7fbSSiobhan Butler      rte_vhost_dequeue_burst receives packets from guest.
67*0ee5e7fbSSiobhan Butler
68*0ee5e7fbSSiobhan Butler*   Feature enable/disable
69*0ee5e7fbSSiobhan Butler
70*0ee5e7fbSSiobhan Butler      Now one negotiate-able feature in vhost is merge-able.
71*0ee5e7fbSSiobhan Butler      vSwitch could enable/disable this feature for performance consideration.
72*0ee5e7fbSSiobhan Butler
73*0ee5e7fbSSiobhan ButlerVhost Implementation
74*0ee5e7fbSSiobhan Butler--------------------
75*0ee5e7fbSSiobhan Butler
76*0ee5e7fbSSiobhan ButlerWhen vSwitch registers the vhost driver, it will register a cuse device driver
77*0ee5e7fbSSiobhan Butlerinto the system and creates a character device file. This cuse driver will
78*0ee5e7fbSSiobhan Butlerreceive vhost open/release/IOCTL message from QEMU simulator.
79*0ee5e7fbSSiobhan Butler
80*0ee5e7fbSSiobhan ButlerWhen the open call is received, vhost driver will create a vhost device for the
81*0ee5e7fbSSiobhan Butlervirtio device in the guest.
82*0ee5e7fbSSiobhan Butler
83*0ee5e7fbSSiobhan ButlerWhen VHOST_SET_MEM_TABLE IOCTL is received, vhost searches the memory region
84*0ee5e7fbSSiobhan Butlerto find the starting user space virtual address that maps the memory of guest
85*0ee5e7fbSSiobhan Butlervirtual machine. Through this virtual address and the QEMU pid, vhost could
86*0ee5e7fbSSiobhan Butlerfind the file QEMU uses to map the guest memory. Vhost maps this file into its
87*0ee5e7fbSSiobhan Butleraddress space, in this way vhost could fully access the guest physical memory,
88*0ee5e7fbSSiobhan Butlerwhich means vhost could access the shared virtio ring and the guest physical
89*0ee5e7fbSSiobhan Butleraddress specified in the entry of the ring.
90*0ee5e7fbSSiobhan Butler
91*0ee5e7fbSSiobhan ButlerThe guest virtual machine tells the vhost whether the virtio device is ready
92*0ee5e7fbSSiobhan Butlerfor processing or is de-activated through VHOST_SET_BACKEND message.
93*0ee5e7fbSSiobhan ButlerThe registered callback from vSwitch will be called.
94*0ee5e7fbSSiobhan Butler
95*0ee5e7fbSSiobhan ButlerWhen the release call is released, vhost will destroy the device.
96*0ee5e7fbSSiobhan Butler
97*0ee5e7fbSSiobhan ButlerVhost supported vSwitch reference
98*0ee5e7fbSSiobhan Butler---------------------------------
99*0ee5e7fbSSiobhan Butler
100*0ee5e7fbSSiobhan ButlerFor how to support vhost in vSwitch, please refer to vhost example in the
101*0ee5e7fbSSiobhan ButlerDPDK Sample Applications Guide.
102