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 31Vhost Library 32============= 33 34The vhost cuse (cuse: user space character device driver) library implements a 35vhost cuse driver. It also creates, manages and destroys vhost devices for 36corresponding virtio devices in the guest. Vhost supported vSwitch could register 37callbacks to this library, which will be called when a vhost device is activated 38or deactivated by guest virtual machine. 39 40Vhost 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 by setting or unsetting 62 VIRTIO_DEV_RUNNING on the device flags. 63 64* Read/write packets from/to guest virtual machine 65 66 rte_vhost_enqueue_burst transmit host packets to guest. 67 rte_vhost_dequeue_burst receives packets from guest. 68 69* Feature enable/disable 70 71 Now one negotiate-able feature in vhost is merge-able. 72 vSwitch could enable/disable this feature for performance consideration. 73 74Vhost Implementation 75-------------------- 76 77When vSwitch registers the vhost driver, it will register a cuse device driver 78into the system and creates a character device file. This cuse driver will 79receive vhost open/release/IOCTL message from QEMU simulator. 80 81When the open call is received, vhost driver will create a vhost device for the 82virtio device in the guest. 83 84When VHOST_SET_MEM_TABLE IOCTL is received, vhost searches the memory region 85to find the starting user space virtual address that maps the memory of guest 86virtual machine. Through this virtual address and the QEMU pid, vhost could 87find the file QEMU uses to map the guest memory. Vhost maps this file into its 88address space, in this way vhost could fully access the guest physical memory, 89which means vhost could access the shared virtio ring and the guest physical 90address specified in the entry of the ring. 91 92The guest virtual machine tells the vhost whether the virtio device is ready 93for processing or is de-activated through VHOST_SET_BACKEND message. 94The registered callback from vSwitch will be called. 95 96When the release call is released, vhost will destroy the device. 97 98Vhost supported vSwitch reference 99--------------------------------- 100 101For how to support vhost in vSwitch, please refer to vhost example in the 102DPDK Sample Applications Guide. 103