Commit Graph

88 Commits

Author SHA1 Message Date
Tetsuya Mukawa
07d37fbf5e vhost: fix crash with multiqueue enabled
The patch fixes wrong handling of virtqueue array index when
GET_VRING_BASE message comes.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
2015-10-30 15:46:01 +01:00
Yuanhan Liu
19d4d7ef2a vhost-user: enable multiple queue
By setting VHOST_USER_PROTOCOL_F_MQ protocol feature bit, and
VIRTIO_NET_F_MQ feature bit.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:23:54 +01:00
Changchun Ouyang
77d20126b4 vhost-user: handle message to enable vring
This message is used to enable/disable a specific vring queue pair.
The first queue pair is enabled by default.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:23:53 +01:00
Changchun Ouyang
7c46842c9e vhost: use queue id instead of constant ring index
Do not use VIRTIO_RXQ or VIRTIO_TXQ anymore; use the queue_id
instead, which will be set to a proper value for a specific queue
when we have multiple queue support enabled.

For now, queue_id is still set with VIRTIO_RXQ or VIRTIO_TXQ,
so it should not break anything.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:23:49 +01:00
Yuanhan Liu
e049ca6d10 vhost-user: prepare multiple queue setup
All queue pairs, including the default (the first) queue pair,
are allocated dynamically, when a vring_call message is received
first time for a specific queue pair.

This is a refactor work for enabling vhost-user multiple queue;
it should not break anything as it does no functional changes:
we don't support mq set, so there is only one mq at max.

This patch is based on Changchun's patch.

Signed-off-by: Ouyang Changchun <changchun.ouyang@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:22:37 +01:00
Yuanhan Liu
b09b198bfb vhost-user: announce queue number in message
Add VHOST_USER_GET_QUEUE_NUM message
to tell the frontend (qemu) how many queue pairs we support.

And it is initiated to VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:22:32 +01:00
Yuanhan Liu
381316f6a2 vhost-user: support protocol features
The two protocol features messages are introduced by qemu vhost
maintainer(Michael) for extendting vhost-user interface. Here is
an excerpta from the vhost-user spec:

    Any protocol extensions are gated by protocol feature bits,
    which allows full backwards compatibility on both master
    and slave.

The vhost-user multiple queue features will be treated as a vhost-user
extension, hence, we have to implement the two messages first.

VHOST_USER_PROTOCOL_FEATURES is initialized to 0, as we don't support
any yet.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-10-26 21:22:27 +01:00
Jerome Jutteau
6c6373c763 vhost: fix missing device checks
virtio-net search for it's device in reset_owner.
The function don't check the return result of get_config_ll_entry.
Using get_config_ll_entry in reset_owner don't show any error when the
device is not found. This patch fix this by using get_device instead
instead of get_config_ll_entry.

In user_get_vring_base, get_device return is not checked and may cause
segfault when device is not found.

Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
2015-10-21 12:21:18 +02:00
Jerome Jutteau
2c95f4de6a vhost: keep device identifier after reset owner
virtio-net clean and init device after a VHOST_USER_RESET_OWNER.
This reset device identifier to 0 and break ll_root listing logic.
This patch keep the old device identifier and re-write it on the cleaned
device.

Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
2015-10-21 12:03:57 +02:00
Huawei Xie
5dab2f1137 vhost: inject only one interrupt for a batch of packets
In merge-able RX path, vhost injects interrupts to guest for each packet.
This should degrade performance a lot.
This patch fixes this issue by injecting one interrupt for a batch of packets.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Jianfeng Tan <jianfeng.tan@intel.com>
2015-09-30 01:19:19 +02:00
Yuanhan Liu
9702b2b53f vhost: fix wrong usage of eventfd_t
According to eventfd man page:

    typedef uint64_t eventfd_t;

    int eventfd_read(int fd, eventfd_t *value);
    int eventfd_write(int fd, eventfd_t value);

eventfd_t is defined for the second arg(value), but not for fd.

Here I redefine those fd fields to `int' type, which also removes
the redundant (int) cast. And as the man page stated, we should
cast 1 to eventfd_t type for eventfd_write().

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-09-25 14:58:30 +02:00
Yuanhan Liu
dbd897d0a1 vhost: get rid of duplicate code
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-09-25 14:55:17 +02:00
Yuanhan Liu
2bb29a9fc1 vhost: fix typo
_det => _dev

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-09-25 14:53:28 +02:00
Yuanhan Liu
8426af8e57 vhost: remove extra semicolon
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-09-25 14:50:46 +02:00
Aaron Conole
a17cc4f172 vhost: build eventfd_link module against specified kernel
The vHost eventlink driver is a kernel module that requires a kernel
source/build directory to build the ko. Convert the fixed kernel build
directory specifier to one which may be user specified on the command-line.

Signed-off-by: Aaron Conole <aconole@redhat.com>
2015-09-24 22:01:53 +02:00
Ouyang Changchun
d533647a87 vhost: fix qemu shutdown
This patch originates from the patch:
"Patch for Qemu wrapper for US-VHost to ensure Qemu process ends when
VM is shutdown", http://dpdk.org/ml/archives/dev/2014-June/003606.html

Also update the vhost sample guide doc.

Signed-off-by: Claire Murphy <claire.k.murphy@intel.com>
Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
2015-09-24 14:57:36 +02:00
Ouyang Changchun
43866bf71d doc: fix vhost sample parameter
This commit removes the dev-index, so update the doc for this change:

Fixes: 17b8320a3e ("vhost: remove index parameter")

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
2015-09-24 12:17:01 +02:00
Ouyang Changchun
1cbf787ef8 vhost: add log on socket bind failure
It adds more readable log info if a socket fails to bind to
local socket file name.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-07-17 14:53:26 +02:00
Huawei Xie
cca619e459 vhost: comment unwanted callback
add comment for potential unwanted callback on listenfds

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
2015-06-30 17:49:08 +02:00
Huawei Xie
292959c719 vhost: cleanup unix socket
rte_vhost_driver_unregister API will remove the listenfd from event list,
and then close it.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Signed-off-by: Peng Sun <peng.a.sun@intel.com>
2015-06-30 17:49:08 +02:00
Huawei Xie
3670686ab9 vhost: fix race for connection fd
In the event handler of connection fd, the connection fd could be possibly
closed. The event dispatch loop would then try to remove the fd from fdset.
Between these two actions, another thread might register a new listenfd
reusing the val of just closed fd, so we couldn't call fdset_del which would
wrongly clean up the new listenfd. A new function fdset_del_slot is provided
to cleanup the fd at the specified location.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
2015-06-30 17:49:07 +02:00
Huawei Xie
af295ad469 vhost: realloc device and queues to same numa node as vring desc
When we get the address of vring descriptor table in VHOST_SET_VRING_ADDR
message, will try to reallocate vhost device and virt queue to the same
numa node.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
2015-06-29 18:57:33 +02:00
Huawei Xie
4113e38100 vhost: use rte_malloc to allocate device and queues
use rte_malloc to allocate vhost device and queues

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
2015-06-29 18:57:33 +02:00
Cyril Chemparathy
82be8d5442 mbuf: use offset macro
This patch simply applies the transform previously committed in
scripts/cocci/mtod-offset.cocci.  No other modifications have been
made here.

Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
2015-06-24 12:01:14 +02:00
Ouyang Changchun
8b636a50c2 doc: fix doxygen warnings in vhost API
Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
2015-06-19 12:11:53 +02:00
Ouyang Changchun
5dc985ec1d vhost: remove unnecessary descriptor length updates
Remove these unnecessary vring descriptor length updating, vhost should
not change them.
virtio in front end should assign value to desc.len for both rx and tx.

Test report: http://dpdk.org/ml/archives/dev/2015-June/018610.html

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-06-17 16:56:24 +02:00
Ouyang Changchun
2927c37ca4 vhost: rework mergeable Rx
Extract codes into a function:
update_secure_len which is used to accumulate the buffer len in the
vring descriptors and to fill struct buf_vec.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-06-17 16:47:51 +02:00
Ouyang Changchun
46a8fafaa7 vhost: refine code style
Remove unnecessary new line.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-06-17 16:25:10 +02:00
Ouyang Changchun
f1a519ad98 vhost: fix enqueue/dequeue to handle chained vring descriptors
Vring enqueue need consider the 2 cases:
 1. use separate descriptors to contain virtio header and actual data,
    e.g. the first descriptor is for virtio header, and then followed
    by descriptors for actual data.
 2. virtio header and some data are put together in one descriptor,
    e.g. the first descriptor contain both virtio header and part of
    actual data, and then followed by more descriptors for rest of packet
    data, current DPDK based virtio-net pmd implementation is this case;

So does vring dequeue, it should not assume vring descriptor is chained
or not chained, it should use desc->flags to check whether it is chained
or not. This patch also fixes TX corrupt issue when vhost co-work with
virtio-net driver which uses one single vring descriptor (header and data
are in one descriptor) for virtio tx process on default.

Test report: http://dpdk.org/ml/archives/dev/2015-June/018610.html

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-06-17 16:18:40 +02:00
Krishna Murthy
f75f65abf3 vhost: enable live migration
When we migrate VM, without this feature, qemu will report error:
"migrate: Migration disabled: vhost lacks VHOST_F_LOG_ALL feature".

Signed-off-by: Krishna Murthy <krishna.j.murthy@intel.com>
2015-06-12 17:07:24 +02:00
Stephen Hemminger
a43a55472f lib: fix whitespace
More places with trailing whitespace, and empty blank lines

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2015-06-12 11:10:10 +02:00
Huawei Xie
159793ac86 vhost: fix virtio freeze due to missed interrupt
Update of used->idx and read of avail->flags could be reordered.
Memory fence should be used to ensure the order, otherwise guest could see
a stale used->idx value after it toggles the interrupt suppression flag.
After guest sets the interrupt suppression flag, it will check if there
is more buffer to process through used->idx. If it sees a stale value,
it will exit the processing while host won't send interrupt to guest.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Reviewed-by: Luke Gorrie <luke@snabb.co>
2015-05-13 12:16:47 +02:00
Bruce Richardson
ec10e8d24e vhost: remove inclusion of mbuf header
The virtio_net header file includes the mbuf header file, but it does not
need to do so as it only uses pointers to the struct rte_mbuf type, and
does not use any of the mbuf internals, nor any of the mbuf functions or
macros. Therefore the inclusion is unnecessary, and can be replaced by a
forward declaration of the mbuf type.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
2015-05-11 15:36:37 +02:00
Pavel Boldin
38f4f01f8f vhost: fix file struct leakage
Due to increased `struct file's reference counter subsequent call
to `filp_close' does not free the `struct file'. Prepend `fput' call
to decrease the reference counter.

Signed-off-by: Pavel Boldin <pboldin@mirantis.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-03-26 22:33:41 +01:00
Haifeng Lin
5c561b0a23 vhost: fix index when mbuf allocation fails
When failed to malloc buffer from mempool we just update last_used_idx but
not used->idx so after many times vhost thought have handle all packets
but virtio_net thought vhost have not handle all packets and will not
update avail->idx.

Signed-off-by: Haifeng Lin <haifeng.lin@huawei.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-03-26 22:33:41 +01:00
Huawei Xie
857af048ac vhost: fix build
Fix the error "missing initializer" and "cast to pointer from integer of different size".

For the pointer to integer cast issue, need to investigate changing the typeof mapped_address.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
2015-03-20 23:01:42 +01:00
Benoît Canet
45db8927a8 vhost: add hint on how to add or remove device to a data core
Let's make sure people will not forget to set and unset VIRTIO_DEV_RUNNING.

Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
2015-03-17 12:39:52 +01:00
Huawei Xie
28a1ccca41 vhost: add build option for vhost-user
Turn on CONFIG_RTE_LIBRTE_VHOST to enable vhost.
vhost-user is turned on by default. Turn off CONFIG_RTE_LIBRTE_VHOST_USER to
enable vhost-cuse implementation.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
2015-03-17 00:46:01 +01:00
Huawei Xie
4d16fff496 vhost: check file descriptor before closing
This avoids closing -1 in our case.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-03-09 12:46:46 +01:00
Huawei Xie
64ab971791 vhost: fix file descriptors naming
Previous vhost implementation wrongly name kickfd as callfd and callfd as kickfd.
It is functional correct, but causes confusion.
Exchange kickfd and callfd to avoid confusion.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-03-09 12:46:46 +01:00
Huawei Xie
aee87dd706 vhost: use loop instead of goto
This patch reorder the code a bit to use loop instead of goto.
Besides, remove abudant check 'fd != -1'.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
2015-03-09 12:46:46 +01:00
Huawei Xie
31ff0c6a45 vhost: combine select with sleep
combine sleep into select when there is no file descriptors to be monitored.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
2015-03-09 12:46:46 +01:00
Huawei Xie
391b5f425c vhost: fix crash by removing device when requested
This patch fixes the segfault issue in the case vhost receives
new VHOST_SET_MEM_TABLE message without VHOST_VRING_GET_VRING_BASE
(which we uses as the stop message).

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Tommy Long <thomas.long@intel.com>
2015-03-05 22:08:27 +01:00
Stefan Puiu
4db87f9739 lib: fix C++11 compilation
In C++11 concatenated string literals need to have a space in between.
Found with clang++-3.4, IIRC g++-4.8 also complains about this.

Sample error message:
error: invalid suffix on literal; C++11 requires a space between literal
and identifier [-Wreserved-user-defined-literal]

Signed-off-by: Stefan Puiu <stefan.puiu@gmail.com>
Reviewed-by: John McNamara <john.mcnamara@intel.com>
2015-02-24 02:46:52 +01:00
Huawei Xie
dbfa62d63f vhost: support dynamically registering server
* support calling rte_vhost_driver_register after rte_vhost_driver_session_start
* add mutext to protect fdset from concurrent access
* add busy flag in fdentry. this flag is set before cb and cleared after cb is finished.

mutex lock scenario in vhost:

* event_dispatch(in rte_vhost_driver_session_start) runs in a separate thread, infinitely
processing vhost messages through cb(callback).
* event_dispatch acquires the lock, get the cb and its context, mark the busy flag,
and releases the mutex.
* vserver_new_vq_conn cb calls fdset_add, which acquires the mutex and add new fd into fdset.
* vserver_message_handler cb frees data context, marks remove flag to request to delete
connfd(connection fd) from fdset.
* after cb returns, event_dispatch
  1. clears busy flag.
  2. if there is remove request, call fdset_del, which acquires mutex, checks busy flag, and
removes connfd from fdset.
* rte_vhost_driver_unregister(not implemented) runs in another thread, acquires the mutex,
calls fdset_del to remove fd(listenerfd) from fdset. Then it could free data context.

The above steps ensures fd data context isn't freed when cb is using.

VM(s) should have been shutdown before rte_vhost_driver_unregister.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-02-24 01:38:17 +01:00
Huawei Xie
54292e9520 vhost: support ifname for vhost-user
for vhost-cuse, ifname is the name of the tap device
for vhost-user, ifname is the name of the unix domain socket path

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Signed-off-by: Przemyslaw Czesnowicz <przemyslaw.czesnowicz@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-02-24 01:38:16 +01:00
Huawei Xie
8f972312b8 vhost: support vhost-user
In rte_vhost_driver_register(), vhost unix domain socket listener fd is created
and added to polled(based on select) fdset.

In rte_vhost_driver_session_start(), fds in the fdset are checked for
processing. If there is new connection from qemu, connection fd accepted is
added to polled fdset. The listener and connection fds in the fdset are
then both checked. When there is message on the connection fd, its
callback vserver_message_handler is called to process vhost-user messages.

To support identifying which virtio is from which guest VM, we could call
rte_vhost_driver_register with different socket path. Virtio devices from
same VM will connect to VM specific socket. The socket path information is
stored in the virtio_net structure.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Signed-off-by: Przemyslaw Czesnowicz <przemyslaw.czesnowicz@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-02-24 01:38:15 +01:00
Huawei Xie
fbf7e07ca1 vhost: add select based event driven processing
for more generic event driven processing, refer to:
	http://libevent.org/

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-02-24 01:38:14 +01:00
Huawei Xie
9464a44160 vhost: implement cuse memory table
remove set_memory_table ops

vhost-cuse or vhost-user will both implement their own set_memory_region handler.

In current vhost-cuse implementation, guest numa memory isn't supported.
Assume that guest memory is backed by only one file.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Signed-off-by: Przemyslaw Czesnowicz <przemyslaw.czesnowicz@intel.com>
2015-02-24 01:38:14 +01:00
Huawei Xie
c89d3e5afd vhost: make host memory mapping more generic
This functions accepts a virtual address and pid(qemu), and maps it into
current process(vhost)'s address space.

The memory behind the virtual address should be backed by a file,
and virtual address should be the starting address.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>
2015-02-24 01:38:13 +01:00