Commit Graph

32 Commits

Author SHA1 Message Date
Daniel Verkamp
6d3a4cd2a4 vhost: define VIRTIO_F_VERSION_1 if it is missing
Older kernel headers don't have the definition of this macro, so define
it if necessary.

This is the same workaround as used in rte_vhost/vhost.h.

Change-Id: I01e0661db05de517adf8e24a47c63d32853cd385
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-05-08 20:12:19 -07:00
Pawel Wodkowski
8d7acdaaef vhost: upgrade SPDK vhost code to DPDK 17.05
Also replace the internal DPDK v17.02-based rte_vhost
library with the patched DPDK v17.05-based version.

Change-Id: Ibec0b0746592a1a3911c31642a945ab65495e33e
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
2017-05-08 17:04:29 -07:00
Pawel Wodkowski
d391647bd0 vhost/rte_vhost: fix scan build and comment formatting issues
vhost_net.c file is not needed and fail scan build so remove it.

Change-Id: I5817201373f7253cc8bc1a9bdc5884197e166a14
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
2017-05-08 17:04:29 -07:00
Daniel Verkamp
c2683a8e42 vhost_scsi: access VhostUsrMsg via packed struct
Fixes unaligned access to fields.

Change-Id: I43cff0c1cca7829da8f0d90774970e5feaa95515
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
0cf6cc7b54 vhost: free virtio_net::guest_pages in vhost_backend_cleanup()
guest_pages is being allocated in vhost_setup_mem_table(), reallocated
in add_one_guest_page(), but never freed. This patch fixes a memory
leak.

Change-Id: Ie381c43bafea5cdea2ac9f057c0282044a340dce
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
13657c7d75 vhost: fix malloc in rte_vhost_get_mem_table
Amount of allocated memory was too small, causing buffer overflow.

Change-Id: Ib43e0a9040f594fed0a8c5660a45aeb07e4400c7
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
2542779301 vhost: close callfd on VHOST_USER_GET_VRING_BASE message
This prevents from destroying & recreating user device in "incomplete"
vring state. virtio_is_ready() was returning true for devices with
vrings which did not have valid callfd (their VHOST_USER_SET_VRING_CALL
hasn't arrived yet)

Change-Id: Idc4b41efd544ff5c6b093a5a48798b41c55bbe06
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
52b10970c4 vhost: added API for getting/setting last descriptor indices of vrings
vhost-net devices might keep track of last descriptors indices by
themselves, and assuming they initially start at 0, but that is not the
case for vhost-scsi. Initial last descriptor indices are set via
VHOST_USER_SET_VRING_BASE message, and we cannot possibly predict what
will they be. Setting these to vqueue->used->idx is also not an option,
because there might be some yet unprocessed requests between these and
the actual last_idx. This patch adds API for getting/setting last
descriptor indices of vrings, so that they can be synchronized between
user-device and rte_vhost.

The last_idx flow could be as following:
 * vhost start
 * received SET_VRING_BASE msg, last_idx is set on rte_vhost side
 * created user-device, last_idx pulled from rte_vhost
 * requests are being processed by user-device, last_idx changes
 * destroyed user-device, last_idx pushed to rte_vhost
 * *at this point, vrings could be recreated and another SET_VRING_BASE
 message could arrive, so last_idx would be set*
 * recreated user-device, last_idx pulled from rte_vhost

Change-Id: I247ba4e461a2a2b524ccade364f5b7bf260f7538
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
8457b98cf2 vhost: defer setting up new mem table
There is an issue when QEMU sets new memory table just after guest OS
starts booting. Then, if guest OS tries to issue any I/O to device (e.g.
using BIOS INT13h - EDD) it will get stuck because previous addresses of
mmaped memory might change.

To fix this issue, defer using the new mem table until after we receive
the first SET_VRING_ADDR message. SET_VRING_ADDR will be sent by QEMU
when guest OS virtio (e.g. virtio-scsi) driver starts initialization.
At this point it is safe to invalidate the old mem tables because there
will be no more outstanding IO at this point.

Change-Id: I24772be87a8b6c8781868b9b7773317761499748
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Dariusz Stojaczyk
fab374a7c6 vhost: destroy vhost device before updating public vring data
For now DPDK assumes that callfd, kickfd and last_idx are being set just
once during vring initialization and device cannot be running while DPDK
receives SET_VRING_KICK, SET_VRING_CALL and SET_VRING_BASE messages.
However, that assumption is wrong. For Vhost SCSI messages might arrive
at any point of time, possibly multiple times, one after another.

QEMU issues SET_VRING_CALL once during device initialization, then again
during device start. The second message will close previous callfd,
which is still being used by the user-implementation of vhost device.
This results in writing to invalid (closed) callfd.

This patch destroys vhost device before setting callfd, kickfd and last
vring indices. It will be recreated right after (with updated vring
data).

Change-Id: I293bd91106f53f6c2f65d8b8a41f47ae7548cddc
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-05-08 17:04:29 -07:00
Jim Harris
a191eedb19 vhost: import copy of dpdk rte_vhost v17.05
This will be decoupled from the build to start.  Next
patches will modify this code to prepare it for use with
SPDK vhost-scsi.  The final patch will replace the existing
v17.02-based code with this version, and make the necessary
SPDK vhost changes to use it.

This enables to better track the differences between upstream
DPDK and our internal copy, while not breaking the build at
any point in the git history.

While here, expand the POSIX include file check to exclude
any directory starting with lib/vhost/rte_vhost (which would
include this new directory).

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Icf1202c1b7a898edff12aa226943a08b578cf962
2017-05-08 14:39:55 -07:00
Ben Walker
b961d9cc12 include: Move the remainder of the code base to stdinc.h
Change-Id: I6a142feeaad3117bd3c75e7c5cb7231a1cfa78ae
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
2017-05-08 13:20:36 -07:00
Ben Walker
ba1e1d5308 vhost: Rename LOG_DEBUG to VHOST_LOG_DEBUG
LOG_DEBUG is a symbol defined by POSIX, so if sys/log.h
is included the symbols conflict.

We'll need to push this patch to upstream DPDK too.

Change-Id: Ib263731864aca4791226ea6e3abb5ddfe42e97d8
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
2017-05-08 13:19:20 -07:00
Changpeng Liu
fa511620c4 vhost: eliminate loop log print when no available requests
Change-Id: I3cd72317392b15bad888391b7bc7e1bc5e69385c
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
2017-05-04 13:21:27 -07:00
Changpeng Liu
95d9ffc26a vhost/lib: remove dependency on DPDK vhost library
Since we keep a copy of DPDK vhost library, the header file don't
have dependency on DPDK vhost library.

Change-Id: I14d48e10227633547231e4f429e7375ffa76128d
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
2017-05-04 09:11:31 -07:00
Daniel Verkamp
a3738d9031 scsi: make spdk_scsi_dev definition private
Change-Id: I62b36a22e11e845045f190886ae00aa644f96ec6
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-05-03 12:34:57 -07:00
Daniel Verkamp
12965bb6ce scsi: make spdk_scsi_lun definition private
The contents of struct spdk_scsi_lun don't need to be part of the public
API.

Change-Id: I101b77871054557380610fd901ab38bada463202
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-05-02 09:41:43 -07:00
Daniel Verkamp
6b91943209 scripts/check_format.sh: check spaces in comments
Fix up all existing spacing errors in comments and add an automated
check for patterns like /*comment*/.

Change-Id: I28f61c93612dc0f8aed66bd509da78e91ea9737e
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-04-24 13:37:41 -07:00
Pawel Wodkowski
9aaccfe3d7 vhost: enable VFIO
Vhost needs to register memory given by guest in VFIO container to be
able to do any DMA using this memory.

Currently DPDK doesn't provide any interface to handle guest memory, so
for now lets find container fd in /proc/self/fd/ directory and provide
some VFIO internal API that finally should extend DPDK API.

Change-Id: Iee9d496367ccd61219068fc0eadc17e786ff0731
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
2017-04-24 12:20:04 -07:00
Pawel Wodkowski
5109f56ea5 vhost: add info that using VFIO with vhost is not supported
As VFIO does not work with vhost library print warning during vhost
initialization

Change-Id: Iaa31808c7007f1840a6a441e2591f0a3986b0c29
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-03-30 10:45:36 -07:00
Jim Harris
f325e71c9d vhost: defer setting up new mem table
First step is do not destroy an existing device in
vhost_user_set_mem_table().  This is because we may
still be processing I/O via INT13 while QEMU is setting
up the mem tables for OS boot.

The primary part of this patch though is to defer
using the new mem table until after we receive the
first SET_VRING_ADDR message.  SET_VRING_ADDR will be
sent by QEMU when guest OS virtio-scsi driver starts
initialization.  At this point it is safe to invalidate
the old mem tables because there will be no more
INT13 I/O at this point.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I45fb5910f45e7fd2cf4a325341ad105a57d8ea40
2017-03-29 09:43:36 -07:00
Ziye Yang
2abea9da4e lib, vhost: check the numbers of reqs
Change-Id: I567b9a330aa284f08dd16993686200dd1dd7990f
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
2017-03-27 10:45:56 -07:00
Ziye Yang
e439020961 vhost: check the strlen of basename
Change-Id: I0f0eb7edbec71609754a4cda80c578b75c84c87f
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
2017-03-27 10:26:43 -07:00
Ziye Yang
fea78497a1 lib/vhost: Handle realloc failure
Change-Id: I47157e33e306205fa261e65e4b99fa13c1f1148d
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
2017-03-23 16:04:27 -07:00
Daniel Verkamp
6e2d7be8a1 vhost: add copy of virtio headers
This enables the vhost library to build on systems missing the (fairly
recent) linux/virtio_scsi.h header.

Change-Id: I680863b26961ec3cbe4ad4e575555454f6461bbf
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-03-23 13:51:04 -07:00
Dariusz Stojaczyk
b276649c98 vhost: check if file is a socket when creating a controller
This patch makes create_vhost_scsi_controller check if given file is a socket before deleting it

Change-Id: I7a37c12913b461f779732e724c85e2f7b5d67442
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
2017-03-17 08:59:02 -07:00
Daniel Verkamp
93982c19bb env/vtophys: expose mem map in public API
Change-Id: I2e96b295fa3943e004e424250c4734e8da9fb796
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-03-10 11:39:28 -07:00
Pawel Wodkowski
c90f57f99f vhost: change SCSI device configuration format
Change SCSI device configuration format from "DevX LUN0" to "Dev X LUN0"
This allow checking configuration against silly errors when device
number is out of range.
Also assert exactly only one LUN is given.

Change-Id: Idccd6878119282fc51947b092bdda7ae06aa94ad
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
2017-03-09 15:42:48 -07:00
Pawel Wodkowski
96e5267baa vhost: free string RPC parameters
Change-Id: Ic5a31f1433ff585d4ca4d0851a5fcbba7092d5e8
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
2017-03-08 11:19:35 -07:00
Daniel Verkamp
c0a54a7606 vhost: make dpdk_vid_mapping and g_need_iovecs static
They are not used outside of their respective files.

Change-Id: I754834e7354caec877cd2fe193e56854e5a34e20
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-03-07 13:05:58 -07:00
Daniel Verkamp
b58a5d73ef util: add SPDK_COUNTOF() array size macro
SPDK_COUNTOF works like sizeof, except it returns the number of elements
in an array instead of the number of bytes.

Change-Id: I38ff4dd3485ed9b630cc5660ff84851d0031911f
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-03-07 12:43:42 -07:00
Piotr Pelplinski
1dbf53eebf vhost: add a library and app for userspace vhost-scsi processing
This patch adds a library, application and test scripts for extending
SPDK to present virtio-scsi controllers to QEMU-based VMs and
process I/O submitted to devices attached to those controllers.
This functionality is dependent on QEMU patches to enable
vhost-scsi in userspace - those patches are currently working their
way through the QEMU mailing list, but temporary patches to enable
this functionality in QEMU will be made available shortly through the
SPDK github repository.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Signed-off-by: Krzysztof Jakimiak <krzysztof.jakimiak@intel.com>
Signed-off-by: Michal Kosciowski <michal.kosciowski@intel.com>
Signed-off-by: Karol Latecki <karolx.latecki@intel.com>
Signed-off-by: Piotr Pelplinski <piotr.pelplinski@intel.com>
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>

Signed-off-by: Krzysztof Jakimiak <krzysztof.jakimiak@intel.com>
Change-Id: I138e4021f0ac4b1cd9a6e4041783cdf06e6f0efb
2017-03-06 12:44:35 -07:00