2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2018-04-05 16:01:30 +00:00
|
|
|
* Copyright(c) 2010-2018 Intel Corporation
|
2014-02-10 13:57:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _VHOST_NET_CDEV_H_
|
|
|
|
#define _VHOST_NET_CDEV_H_
|
2014-10-08 18:54:54 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2018-03-28 05:49:24 +00:00
|
|
|
#include <stdbool.h>
|
2014-10-08 18:54:54 +00:00
|
|
|
#include <sys/types.h>
|
vhost: add dequeue zero copy
The basic idea of dequeue zero copy is, instead of copying data from
the desc buf, here we let the mbuf reference the desc buf addr directly.
Doing so, however, has one major issue: we can't update the used ring
at the end of rte_vhost_dequeue_burst. Because we don't do the copy
here, an update of the used ring would let the driver to reclaim the
desc buf. As a result, DPDK might reference a stale memory region.
To update the used ring properly, this patch does several tricks:
- when mbuf references a desc buf, refcnt is added by 1.
This is to pin lock the mbuf, so that a mbuf free from the DPDK
won't actually free it, instead, refcnt is subtracted by 1.
- We chain all those mbuf together (by tailq)
And we check it every time on the rte_vhost_dequeue_burst entrance,
to see if the mbuf is freed (when refcnt equals to 1). If that
happens, it means we are the last user of this mbuf and we are
safe to update the used ring.
- "struct zcopy_mbuf" is introduced, to associate an mbuf with the
right desc idx.
Dequeue zero copy is introduced for performance reason, and some rough
tests show about 50% perfomance boost for packet size 1500B. For small
packets, (e.g. 64B), it actually slows a bit down (well, it could up to
15%). That is expected because this patch introduces some extra works,
and it outweighs the benefit from saving few bytes copy.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Qian Xu <qian.q.xu@intel.com>
2016-10-09 07:27:57 +00:00
|
|
|
#include <sys/queue.h>
|
2014-10-08 18:54:54 +00:00
|
|
|
#include <unistd.h>
|
2014-02-10 13:57:48 +00:00
|
|
|
#include <linux/vhost.h>
|
2017-04-01 07:22:51 +00:00
|
|
|
#include <linux/virtio_net.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <linux/if.h>
|
2014-02-10 13:57:48 +00:00
|
|
|
|
2014-10-08 18:54:54 +00:00
|
|
|
#include <rte_log.h>
|
2017-04-01 07:22:51 +00:00
|
|
|
#include <rte_ether.h>
|
2017-10-05 08:36:14 +00:00
|
|
|
#include <rte_rwlock.h>
|
2014-10-08 18:54:54 +00:00
|
|
|
|
2017-04-01 07:22:57 +00:00
|
|
|
#include "rte_vhost.h"
|
2018-04-02 11:46:54 +00:00
|
|
|
#include "rte_vdpa.h"
|
2015-02-23 17:36:31 +00:00
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/* Used to indicate that the device is running on a data core */
|
|
|
|
#define VIRTIO_DEV_RUNNING 1
|
2017-03-12 16:34:00 +00:00
|
|
|
/* Used to indicate that the device is ready to operate */
|
|
|
|
#define VIRTIO_DEV_READY 2
|
2018-01-31 17:46:50 +00:00
|
|
|
/* Used to indicate that the built-in vhost net device backend is enabled */
|
|
|
|
#define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
|
2018-04-02 11:46:55 +00:00
|
|
|
/* Used to indicate that the device has its own data path and configured */
|
|
|
|
#define VIRTIO_DEV_VDPA_CONFIGURED 8
|
2016-04-30 05:11:19 +00:00
|
|
|
|
|
|
|
/* Backend value set by guest. */
|
|
|
|
#define VIRTIO_DEV_STOPPED -1
|
|
|
|
|
|
|
|
#define BUF_VECTOR_MAX 256
|
|
|
|
|
2018-05-17 11:44:47 +00:00
|
|
|
#define VHOST_LOG_CACHE_NR 32
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/**
|
|
|
|
* Structure contains buffer address, length and descriptor index
|
|
|
|
* from vring to do scatter RX.
|
|
|
|
*/
|
|
|
|
struct buf_vector {
|
2018-07-06 07:04:46 +00:00
|
|
|
uint64_t buf_iova;
|
2016-04-30 05:11:19 +00:00
|
|
|
uint64_t buf_addr;
|
|
|
|
uint32_t buf_len;
|
|
|
|
uint32_t desc_idx;
|
|
|
|
};
|
|
|
|
|
vhost: add dequeue zero copy
The basic idea of dequeue zero copy is, instead of copying data from
the desc buf, here we let the mbuf reference the desc buf addr directly.
Doing so, however, has one major issue: we can't update the used ring
at the end of rte_vhost_dequeue_burst. Because we don't do the copy
here, an update of the used ring would let the driver to reclaim the
desc buf. As a result, DPDK might reference a stale memory region.
To update the used ring properly, this patch does several tricks:
- when mbuf references a desc buf, refcnt is added by 1.
This is to pin lock the mbuf, so that a mbuf free from the DPDK
won't actually free it, instead, refcnt is subtracted by 1.
- We chain all those mbuf together (by tailq)
And we check it every time on the rte_vhost_dequeue_burst entrance,
to see if the mbuf is freed (when refcnt equals to 1). If that
happens, it means we are the last user of this mbuf and we are
safe to update the used ring.
- "struct zcopy_mbuf" is introduced, to associate an mbuf with the
right desc idx.
Dequeue zero copy is introduced for performance reason, and some rough
tests show about 50% perfomance boost for packet size 1500B. For small
packets, (e.g. 64B), it actually slows a bit down (well, it could up to
15%). That is expected because this patch introduces some extra works,
and it outweighs the benefit from saving few bytes copy.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Qian Xu <qian.q.xu@intel.com>
2016-10-09 07:27:57 +00:00
|
|
|
/*
|
|
|
|
* A structure to hold some fields needed in zero copy code path,
|
|
|
|
* mainly for associating an mbuf with the right desc_idx.
|
|
|
|
*/
|
|
|
|
struct zcopy_mbuf {
|
|
|
|
struct rte_mbuf *mbuf;
|
|
|
|
uint32_t desc_idx;
|
|
|
|
uint16_t in_use;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(zcopy_mbuf) next;
|
|
|
|
};
|
|
|
|
TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
|
|
|
|
|
2017-09-08 12:50:46 +00:00
|
|
|
/*
|
|
|
|
* Structure contains the info for each batched memory copy.
|
|
|
|
*/
|
|
|
|
struct batch_copy_elem {
|
|
|
|
void *dst;
|
|
|
|
void *src;
|
|
|
|
uint32_t len;
|
|
|
|
uint64_t log_addr;
|
|
|
|
};
|
|
|
|
|
2018-05-17 11:44:47 +00:00
|
|
|
/*
|
|
|
|
* Structure that contains the info for batched dirty logging.
|
|
|
|
*/
|
|
|
|
struct log_cache_entry {
|
|
|
|
uint32_t offset;
|
|
|
|
unsigned long val;
|
|
|
|
};
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/**
|
|
|
|
* Structure contains variables relevant to RX/TX virtqueues.
|
|
|
|
*/
|
|
|
|
struct vhost_virtqueue {
|
|
|
|
struct vring_desc *desc;
|
|
|
|
struct vring_avail *avail;
|
|
|
|
struct vring_used *used;
|
|
|
|
uint32_t size;
|
|
|
|
|
2016-10-09 07:27:56 +00:00
|
|
|
uint16_t last_avail_idx;
|
2016-10-14 09:34:32 +00:00
|
|
|
uint16_t last_used_idx;
|
2018-01-09 11:03:48 +00:00
|
|
|
/* Last used index we notify to front end. */
|
|
|
|
uint16_t signalled_used;
|
2016-04-30 05:11:19 +00:00
|
|
|
#define VIRTIO_INVALID_EVENTFD (-1)
|
|
|
|
#define VIRTIO_UNINITIALIZED_EVENTFD (-2)
|
|
|
|
|
|
|
|
/* Backend value to determine if device should started/stopped */
|
|
|
|
int backend;
|
2018-01-17 13:49:25 +00:00
|
|
|
int enabled;
|
|
|
|
int access_ok;
|
|
|
|
rte_spinlock_t access_lock;
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/* Used to notify the guest (trigger interrupt) */
|
|
|
|
int callfd;
|
|
|
|
/* Currently unused as polling mode is enabled */
|
|
|
|
int kickfd;
|
|
|
|
|
|
|
|
/* Physical address of used ring, for logging */
|
|
|
|
uint64_t log_guest_addr;
|
vhost: add dequeue zero copy
The basic idea of dequeue zero copy is, instead of copying data from
the desc buf, here we let the mbuf reference the desc buf addr directly.
Doing so, however, has one major issue: we can't update the used ring
at the end of rte_vhost_dequeue_burst. Because we don't do the copy
here, an update of the used ring would let the driver to reclaim the
desc buf. As a result, DPDK might reference a stale memory region.
To update the used ring properly, this patch does several tricks:
- when mbuf references a desc buf, refcnt is added by 1.
This is to pin lock the mbuf, so that a mbuf free from the DPDK
won't actually free it, instead, refcnt is subtracted by 1.
- We chain all those mbuf together (by tailq)
And we check it every time on the rte_vhost_dequeue_burst entrance,
to see if the mbuf is freed (when refcnt equals to 1). If that
happens, it means we are the last user of this mbuf and we are
safe to update the used ring.
- "struct zcopy_mbuf" is introduced, to associate an mbuf with the
right desc idx.
Dequeue zero copy is introduced for performance reason, and some rough
tests show about 50% perfomance boost for packet size 1500B. For small
packets, (e.g. 64B), it actually slows a bit down (well, it could up to
15%). That is expected because this patch introduces some extra works,
and it outweighs the benefit from saving few bytes copy.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Qian Xu <qian.q.xu@intel.com>
2016-10-09 07:27:57 +00:00
|
|
|
|
|
|
|
uint16_t nr_zmbuf;
|
|
|
|
uint16_t zmbuf_size;
|
|
|
|
uint16_t last_zmbuf_idx;
|
|
|
|
struct zcopy_mbuf *zmbufs;
|
|
|
|
struct zcopy_mbuf_list zmbuf_list;
|
2016-10-14 09:34:36 +00:00
|
|
|
|
|
|
|
struct vring_used_elem *shadow_used_ring;
|
|
|
|
uint16_t shadow_used_idx;
|
2017-10-05 08:36:23 +00:00
|
|
|
struct vhost_vring_addr ring_addrs;
|
2017-09-08 12:50:46 +00:00
|
|
|
|
|
|
|
struct batch_copy_elem *batch_copy_elems;
|
|
|
|
uint16_t batch_copy_nb_elems;
|
2017-10-05 08:36:14 +00:00
|
|
|
|
2018-05-17 11:44:47 +00:00
|
|
|
struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
|
|
|
|
uint16_t log_cache_nb_elem;
|
|
|
|
|
2017-10-05 08:36:14 +00:00
|
|
|
rte_rwlock_t iotlb_lock;
|
2017-10-05 08:36:15 +00:00
|
|
|
rte_rwlock_t iotlb_pending_lock;
|
2017-10-05 08:36:14 +00:00
|
|
|
struct rte_mempool *iotlb_pool;
|
|
|
|
TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
|
|
|
|
int iotlb_cache_nr;
|
2017-10-05 08:36:15 +00:00
|
|
|
TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
|
2016-04-30 05:11:19 +00:00
|
|
|
} __rte_cache_aligned;
|
|
|
|
|
2017-03-01 10:41:59 +00:00
|
|
|
/* Old kernels have no such macros defined */
|
2016-04-30 05:11:19 +00:00
|
|
|
#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
|
|
|
|
#define VIRTIO_NET_F_GUEST_ANNOUNCE 21
|
|
|
|
#endif
|
|
|
|
|
2017-03-01 10:41:59 +00:00
|
|
|
#ifndef VIRTIO_NET_F_MQ
|
2017-03-01 10:41:58 +00:00
|
|
|
#define VIRTIO_NET_F_MQ 22
|
2016-04-30 05:11:19 +00:00
|
|
|
#endif
|
2017-04-01 07:22:45 +00:00
|
|
|
|
|
|
|
#define VHOST_MAX_VRING 0x100
|
2017-03-01 10:41:59 +00:00
|
|
|
#define VHOST_MAX_QUEUE_PAIRS 0x80
|
2016-04-30 05:11:19 +00:00
|
|
|
|
2017-03-12 16:33:58 +00:00
|
|
|
#ifndef VIRTIO_NET_F_MTU
|
|
|
|
#define VIRTIO_NET_F_MTU 3
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 14:20:57 +00:00
|
|
|
#ifndef VIRTIO_F_ANY_LAYOUT
|
|
|
|
#define VIRTIO_F_ANY_LAYOUT 27
|
|
|
|
#endif
|
|
|
|
|
2017-10-05 08:36:13 +00:00
|
|
|
/* Declare IOMMU related bits for older kernels */
|
|
|
|
#ifndef VIRTIO_F_IOMMU_PLATFORM
|
|
|
|
|
|
|
|
#define VIRTIO_F_IOMMU_PLATFORM 33
|
|
|
|
|
|
|
|
struct vhost_iotlb_msg {
|
|
|
|
__u64 iova;
|
|
|
|
__u64 size;
|
|
|
|
__u64 uaddr;
|
|
|
|
#define VHOST_ACCESS_RO 0x1
|
|
|
|
#define VHOST_ACCESS_WO 0x2
|
|
|
|
#define VHOST_ACCESS_RW 0x3
|
|
|
|
__u8 perm;
|
|
|
|
#define VHOST_IOTLB_MISS 1
|
|
|
|
#define VHOST_IOTLB_UPDATE 2
|
|
|
|
#define VHOST_IOTLB_INVALIDATE 3
|
|
|
|
#define VHOST_IOTLB_ACCESS_FAIL 4
|
|
|
|
__u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VHOST_IOTLB_MSG 0x1
|
|
|
|
|
|
|
|
struct vhost_msg {
|
|
|
|
int type;
|
|
|
|
union {
|
|
|
|
struct vhost_iotlb_msg iotlb;
|
|
|
|
__u8 padding[64];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/*
|
|
|
|
* Define virtio 1.0 for older kernels
|
|
|
|
*/
|
|
|
|
#ifndef VIRTIO_F_VERSION_1
|
|
|
|
#define VIRTIO_F_VERSION_1 32
|
|
|
|
#endif
|
|
|
|
|
2018-07-06 07:07:08 +00:00
|
|
|
/* Declare packed ring related bits for older kernels */
|
|
|
|
#ifndef VIRTIO_F_RING_PACKED
|
|
|
|
|
|
|
|
#define VIRTIO_F_RING_PACKED 34
|
|
|
|
|
|
|
|
#define VRING_DESC_F_NEXT 1
|
|
|
|
#define VRING_DESC_F_WRITE 2
|
|
|
|
#define VRING_DESC_F_INDIRECT 4
|
|
|
|
|
|
|
|
#define VRING_DESC_F_AVAIL (1ULL << 7)
|
|
|
|
#define VRING_DESC_F_USED (1ULL << 15)
|
|
|
|
|
|
|
|
struct vring_packed_desc {
|
|
|
|
uint64_t addr;
|
|
|
|
uint32_t len;
|
|
|
|
uint16_t id;
|
|
|
|
uint16_t flags;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-07-02 13:56:34 +00:00
|
|
|
/*
|
|
|
|
* Available and used descs are in same order
|
|
|
|
*/
|
|
|
|
#ifndef VIRTIO_F_IN_ORDER
|
|
|
|
#define VIRTIO_F_IN_ORDER 35
|
|
|
|
#endif
|
|
|
|
|
2017-04-01 07:22:41 +00:00
|
|
|
/* Features supported by this builtin vhost-user net driver. */
|
|
|
|
#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
|
2018-01-19 19:02:50 +00:00
|
|
|
(1ULL << VIRTIO_F_ANY_LAYOUT) | \
|
2017-04-01 07:22:41 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_CTRL_VQ) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_CTRL_RX) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_MQ) | \
|
|
|
|
(1ULL << VIRTIO_F_VERSION_1) | \
|
|
|
|
(1ULL << VHOST_F_LOG_ALL) | \
|
|
|
|
(1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
|
2017-11-28 05:28:33 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_GSO) | \
|
2017-04-01 07:22:41 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_HOST_TSO4) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_HOST_TSO6) | \
|
2017-11-21 06:56:52 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_HOST_UFO) | \
|
2017-11-22 03:19:42 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_HOST_ECN) | \
|
2017-04-01 07:22:41 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_CSUM) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
|
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
|
2017-11-21 06:56:52 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_UFO) | \
|
2017-11-22 03:19:42 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_GUEST_ECN) | \
|
2017-04-01 07:22:41 +00:00
|
|
|
(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
|
2018-01-09 11:03:48 +00:00
|
|
|
(1ULL << VIRTIO_RING_F_EVENT_IDX) | \
|
2018-07-02 13:56:34 +00:00
|
|
|
(1ULL << VIRTIO_NET_F_MTU) | \
|
|
|
|
(1ULL << VIRTIO_F_IN_ORDER) | \
|
2017-10-05 08:36:27 +00:00
|
|
|
(1ULL << VIRTIO_F_IOMMU_PLATFORM))
|
2017-04-01 07:22:41 +00:00
|
|
|
|
|
|
|
|
2016-10-09 07:27:55 +00:00
|
|
|
struct guest_page {
|
|
|
|
uint64_t guest_phys_addr;
|
|
|
|
uint64_t host_phys_addr;
|
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
2018-04-05 16:01:30 +00:00
|
|
|
/**
|
|
|
|
* function prototype for the vhost backend to handler specific vhost user
|
|
|
|
* messages prior to the master message handling
|
|
|
|
*
|
|
|
|
* @param vid
|
|
|
|
* vhost device id
|
|
|
|
* @param msg
|
|
|
|
* Message pointer.
|
|
|
|
* @param require_reply
|
|
|
|
* If the handler requires sending a reply, this varaible shall be written 1,
|
|
|
|
* otherwise 0.
|
|
|
|
* @param skip_master
|
|
|
|
* If the handler requires skipping the master message handling, this variable
|
|
|
|
* shall be written 1, otherwise 0.
|
|
|
|
* @return
|
|
|
|
* 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
typedef int (*vhost_msg_pre_handle)(int vid, void *msg,
|
|
|
|
uint32_t *require_reply, uint32_t *skip_master);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function prototype for the vhost backend to handler specific vhost user
|
|
|
|
* messages after the master message handling is done
|
|
|
|
*
|
|
|
|
* @param vid
|
|
|
|
* vhost device id
|
|
|
|
* @param msg
|
|
|
|
* Message pointer.
|
|
|
|
* @param require_reply
|
|
|
|
* If the handler requires sending a reply, this varaible shall be written 1,
|
|
|
|
* otherwise 0.
|
|
|
|
* @return
|
|
|
|
* 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
typedef int (*vhost_msg_post_handle)(int vid, void *msg,
|
|
|
|
uint32_t *require_reply);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pre and post vhost user message handlers
|
|
|
|
*/
|
|
|
|
struct vhost_user_extern_ops {
|
|
|
|
vhost_msg_pre_handle pre_msg_handle;
|
|
|
|
vhost_msg_post_handle post_msg_handle;
|
|
|
|
};
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/**
|
|
|
|
* Device structure contains all configuration information relating
|
|
|
|
* to the device.
|
|
|
|
*/
|
|
|
|
struct virtio_net {
|
|
|
|
/* Frontend (QEMU) memory and memory region information */
|
2017-04-01 07:22:43 +00:00
|
|
|
struct rte_vhost_memory *mem;
|
2016-04-30 05:11:19 +00:00
|
|
|
uint64_t features;
|
|
|
|
uint64_t protocol_features;
|
|
|
|
int vid;
|
|
|
|
uint32_t flags;
|
2016-05-01 23:58:52 +00:00
|
|
|
uint16_t vhost_hlen;
|
2016-05-03 00:46:18 +00:00
|
|
|
/* to tell if we need broadcast rarp packet */
|
|
|
|
rte_atomic16_t broadcast_rarp;
|
2017-04-01 07:22:47 +00:00
|
|
|
uint32_t nr_vring;
|
vhost: add dequeue zero copy
The basic idea of dequeue zero copy is, instead of copying data from
the desc buf, here we let the mbuf reference the desc buf addr directly.
Doing so, however, has one major issue: we can't update the used ring
at the end of rte_vhost_dequeue_burst. Because we don't do the copy
here, an update of the used ring would let the driver to reclaim the
desc buf. As a result, DPDK might reference a stale memory region.
To update the used ring properly, this patch does several tricks:
- when mbuf references a desc buf, refcnt is added by 1.
This is to pin lock the mbuf, so that a mbuf free from the DPDK
won't actually free it, instead, refcnt is subtracted by 1.
- We chain all those mbuf together (by tailq)
And we check it every time on the rte_vhost_dequeue_burst entrance,
to see if the mbuf is freed (when refcnt equals to 1). If that
happens, it means we are the last user of this mbuf and we are
safe to update the used ring.
- "struct zcopy_mbuf" is introduced, to associate an mbuf with the
right desc idx.
Dequeue zero copy is introduced for performance reason, and some rough
tests show about 50% perfomance boost for packet size 1500B. For small
packets, (e.g. 64B), it actually slows a bit down (well, it could up to
15%). That is expected because this patch introduces some extra works,
and it outweighs the benefit from saving few bytes copy.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Qian Xu <qian.q.xu@intel.com>
2016-10-09 07:27:57 +00:00
|
|
|
int dequeue_zero_copy;
|
2016-05-03 00:46:18 +00:00
|
|
|
struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
|
2016-04-30 05:11:19 +00:00
|
|
|
#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
|
|
|
|
char ifname[IF_NAME_SZ];
|
|
|
|
uint64_t log_size;
|
|
|
|
uint64_t log_base;
|
2016-06-16 09:16:37 +00:00
|
|
|
uint64_t log_addr;
|
2016-04-30 05:11:19 +00:00
|
|
|
struct ether_addr mac;
|
2017-03-12 16:33:59 +00:00
|
|
|
uint16_t mtu;
|
2016-04-30 05:11:19 +00:00
|
|
|
|
2017-04-01 07:22:52 +00:00
|
|
|
struct vhost_device_ops const *notify_ops;
|
2017-04-01 07:22:42 +00:00
|
|
|
|
2016-10-09 07:27:55 +00:00
|
|
|
uint32_t nr_guest_pages;
|
|
|
|
uint32_t max_guest_pages;
|
|
|
|
struct guest_page *guest_pages;
|
2017-10-05 08:36:12 +00:00
|
|
|
|
|
|
|
int slave_req_fd;
|
2018-06-08 03:22:23 +00:00
|
|
|
rte_spinlock_t slave_req_lock;
|
2018-04-02 11:46:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Device id to identify a specific backend device.
|
|
|
|
* It's set to -1 for the default software implementation.
|
|
|
|
*/
|
|
|
|
int vdpa_dev_id;
|
2016-04-30 05:11:19 +00:00
|
|
|
|
2018-04-05 16:01:30 +00:00
|
|
|
/* private data for virtio device */
|
|
|
|
void *extern_data;
|
|
|
|
/* pre and post vhost user message handlers for the device */
|
|
|
|
struct vhost_user_extern_ops extern_ops;
|
|
|
|
} __rte_cache_aligned;
|
2017-04-01 07:22:55 +00:00
|
|
|
|
|
|
|
#define VHOST_LOG_PAGE 4096
|
|
|
|
|
2017-08-01 09:01:21 +00:00
|
|
|
/*
|
2018-04-20 08:39:21 +00:00
|
|
|
* Atomically set a bit in memory.
|
2017-08-01 09:01:21 +00:00
|
|
|
*/
|
2018-04-20 08:39:21 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_set_bit(unsigned int nr, volatile uint8_t *addr)
|
|
|
|
{
|
2018-05-17 11:44:47 +00:00
|
|
|
#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION < 70100)
|
|
|
|
/*
|
|
|
|
* __sync_ built-ins are deprecated, but __atomic_ ones
|
|
|
|
* are sub-optimized in older GCC versions.
|
|
|
|
*/
|
|
|
|
__sync_fetch_and_or_1(addr, (1U << nr));
|
|
|
|
#else
|
|
|
|
__atomic_fetch_or(addr, (1U << nr), __ATOMIC_RELAXED);
|
|
|
|
#endif
|
2018-04-20 08:39:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 09:27:25 +00:00
|
|
|
static __rte_always_inline void
|
2017-04-01 07:22:55 +00:00
|
|
|
vhost_log_page(uint8_t *log_base, uint64_t page)
|
|
|
|
{
|
2018-04-20 08:39:21 +00:00
|
|
|
vhost_set_bit(page % 8, &log_base[page / 8]);
|
2017-04-01 07:22:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 09:27:25 +00:00
|
|
|
static __rte_always_inline void
|
2017-04-01 07:22:55 +00:00
|
|
|
vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
|
|
|
|
{
|
|
|
|
uint64_t page;
|
|
|
|
|
|
|
|
if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
|
|
|
|
!dev->log_base || !len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (unlikely(dev->log_size <= ((addr + len - 1) / VHOST_LOG_PAGE / 8)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* To make sure guest memory updates are committed before logging */
|
|
|
|
rte_smp_wmb();
|
|
|
|
|
|
|
|
page = addr / VHOST_LOG_PAGE;
|
|
|
|
while (page * VHOST_LOG_PAGE < addr + len) {
|
|
|
|
vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page);
|
|
|
|
page += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 11:44:47 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
|
|
|
|
{
|
|
|
|
unsigned long *log_base;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
|
|
|
|
!dev->log_base))
|
|
|
|
return;
|
|
|
|
|
|
|
|
log_base = (unsigned long *)(uintptr_t)dev->log_base;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is expected a write memory barrier has been issued
|
|
|
|
* before this function is called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < vq->log_cache_nb_elem; i++) {
|
|
|
|
struct log_cache_entry *elem = vq->log_cache + i;
|
|
|
|
|
|
|
|
#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION < 70100)
|
|
|
|
/*
|
|
|
|
* '__sync' builtins are deprecated, but '__atomic' ones
|
|
|
|
* are sub-optimized in older GCC versions.
|
|
|
|
*/
|
|
|
|
__sync_fetch_and_or(log_base + elem->offset, elem->val);
|
|
|
|
#else
|
|
|
|
__atomic_fetch_or(log_base + elem->offset, elem->val,
|
|
|
|
__ATOMIC_RELAXED);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
rte_smp_wmb();
|
|
|
|
|
|
|
|
vq->log_cache_nb_elem = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_page(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t page)
|
|
|
|
{
|
|
|
|
uint32_t bit_nr = page % (sizeof(unsigned long) << 3);
|
|
|
|
uint32_t offset = page / (sizeof(unsigned long) << 3);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < vq->log_cache_nb_elem; i++) {
|
|
|
|
struct log_cache_entry *elem = vq->log_cache + i;
|
|
|
|
|
|
|
|
if (elem->offset == offset) {
|
|
|
|
elem->val |= (1UL << bit_nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(i >= VHOST_LOG_CACHE_NR)) {
|
|
|
|
/*
|
|
|
|
* No more room for a new log cache entry,
|
|
|
|
* so write the dirty log map directly.
|
|
|
|
*/
|
|
|
|
rte_smp_wmb();
|
|
|
|
vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vq->log_cache[i].offset = offset;
|
|
|
|
vq->log_cache[i].val = (1UL << bit_nr);
|
2018-06-15 13:48:46 +00:00
|
|
|
vq->log_cache_nb_elem++;
|
2018-05-17 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t addr, uint64_t len)
|
|
|
|
{
|
|
|
|
uint64_t page;
|
|
|
|
|
|
|
|
if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
|
|
|
|
!dev->log_base || !len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (unlikely(dev->log_size <= ((addr + len - 1) / VHOST_LOG_PAGE / 8)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
page = addr / VHOST_LOG_PAGE;
|
|
|
|
while (page * VHOST_LOG_PAGE < addr + len) {
|
|
|
|
vhost_log_cache_page(dev, vq, page);
|
|
|
|
page += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t offset, uint64_t len)
|
|
|
|
{
|
|
|
|
vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset, len);
|
|
|
|
}
|
|
|
|
|
2017-05-13 09:27:25 +00:00
|
|
|
static __rte_always_inline void
|
2017-04-01 07:22:55 +00:00
|
|
|
vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t offset, uint64_t len)
|
|
|
|
{
|
|
|
|
vhost_log_write(dev, vq->log_guest_addr + offset, len);
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:54:52 +00:00
|
|
|
/* Macros for printing using RTE_LOG */
|
|
|
|
#define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
|
|
|
|
#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
|
|
|
|
|
|
|
|
#ifdef RTE_LIBRTE_VHOST_DEBUG
|
|
|
|
#define VHOST_MAX_PRINT_BUFF 6072
|
2018-02-09 17:24:00 +00:00
|
|
|
#define VHOST_LOG_DEBUG(log_type, fmt, args...) \
|
|
|
|
RTE_LOG(DEBUG, log_type, fmt, ##args)
|
2014-10-08 18:54:52 +00:00
|
|
|
#define PRINT_PACKET(device, addr, size, header) do { \
|
|
|
|
char *pkt_addr = (char *)(addr); \
|
|
|
|
unsigned int index; \
|
|
|
|
char packet[VHOST_MAX_PRINT_BUFF]; \
|
|
|
|
\
|
|
|
|
if ((header)) \
|
2016-05-23 08:36:33 +00:00
|
|
|
snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
|
2014-10-08 18:54:52 +00:00
|
|
|
else \
|
2016-05-23 08:36:33 +00:00
|
|
|
snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
|
2014-10-08 18:54:52 +00:00
|
|
|
for (index = 0; index < (size); index++) { \
|
|
|
|
snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
|
|
|
|
"%02hhx ", pkt_addr[index]); \
|
|
|
|
} \
|
|
|
|
snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
|
|
|
|
\
|
2018-02-09 17:24:00 +00:00
|
|
|
VHOST_LOG_DEBUG(VHOST_DATA, "%s", packet); \
|
2014-10-08 18:54:52 +00:00
|
|
|
} while (0)
|
|
|
|
#else
|
2018-02-09 17:24:00 +00:00
|
|
|
#define VHOST_LOG_DEBUG(log_type, fmt, args...) do {} while (0)
|
2014-10-08 18:54:52 +00:00
|
|
|
#define PRINT_PACKET(device, addr, size, header) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
vhost: refactor code structure
The code structure is a bit messy now. For example, vhost-user message
handling is spread to three different files:
vhost-net-user.c virtio-net.c virtio-net-user.c
Where, vhost-net-user.c is the entrance to handle all those messages
and then invoke the right method for a specific message. Some of them
are stored at virtio-net.c, while others are stored at virtio-net-user.c.
The truth is all of them should be in one file, vhost_user.c.
So this patch refactors the source code structure: mainly on renaming
files and moving code from one file to another file that is more suitable
for storing it. Thus, no functional changes are made.
After the refactor, the code structure becomes to:
- socket.c handles all vhost-user socket file related stuff, such
as, socket file creation for server mode, reconnection
for client mode.
- vhost.c mainly on stuff like vhost device creation/destroy/reset.
Most of the vhost API implementation are there, too.
- vhost_user.c all stuff about vhost-user messages handling goes there.
- virtio_net.c all stuff about virtio-net should go there. It has virtio
net Rx/Tx implementation only so far: it's just a rename
from vhost_rxtx.c
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2016-08-18 08:48:39 +00:00
|
|
|
extern uint64_t VHOST_FEATURES;
|
|
|
|
#define MAX_VHOST_DEVICE 1024
|
|
|
|
extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
|
|
|
|
|
2016-10-09 07:27:55 +00:00
|
|
|
/* Convert guest physical address to host physical address */
|
2017-10-20 12:31:31 +00:00
|
|
|
static __rte_always_inline rte_iova_t
|
2016-10-09 07:27:55 +00:00
|
|
|
gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
struct guest_page *page;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->nr_guest_pages; i++) {
|
|
|
|
page = &dev->guest_pages[i];
|
|
|
|
|
|
|
|
if (gpa >= page->guest_phys_addr &&
|
|
|
|
gpa + size < page->guest_phys_addr + page->size) {
|
|
|
|
return gpa - page->guest_phys_addr +
|
|
|
|
page->host_phys_addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-14 04:01:00 +00:00
|
|
|
static __rte_always_inline struct virtio_net *
|
|
|
|
get_device(int vid)
|
|
|
|
{
|
|
|
|
struct virtio_net *dev = vhost_devices[vid];
|
|
|
|
|
|
|
|
if (unlikely(!dev)) {
|
|
|
|
RTE_LOG(ERR, VHOST_CONFIG,
|
|
|
|
"(%d) device not found.\n", vid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
2016-04-30 05:25:42 +00:00
|
|
|
|
2016-04-29 23:24:27 +00:00
|
|
|
int vhost_new_device(void);
|
vhost: refactor code structure
The code structure is a bit messy now. For example, vhost-user message
handling is spread to three different files:
vhost-net-user.c virtio-net.c virtio-net-user.c
Where, vhost-net-user.c is the entrance to handle all those messages
and then invoke the right method for a specific message. Some of them
are stored at virtio-net.c, while others are stored at virtio-net-user.c.
The truth is all of them should be in one file, vhost_user.c.
So this patch refactors the source code structure: mainly on renaming
files and moving code from one file to another file that is more suitable
for storing it. Thus, no functional changes are made.
After the refactor, the code structure becomes to:
- socket.c handles all vhost-user socket file related stuff, such
as, socket file creation for server mode, reconnection
for client mode.
- vhost.c mainly on stuff like vhost device creation/destroy/reset.
Most of the vhost API implementation are there, too.
- vhost_user.c all stuff about vhost-user messages handling goes there.
- virtio_net.c all stuff about virtio-net should go there. It has virtio
net Rx/Tx implementation only so far: it's just a rename
from vhost_rxtx.c
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2016-08-18 08:48:39 +00:00
|
|
|
void cleanup_device(struct virtio_net *dev, int destroy);
|
|
|
|
void reset_device(struct virtio_net *dev);
|
2016-04-29 23:24:27 +00:00
|
|
|
void vhost_destroy_device(int);
|
2018-06-13 11:54:18 +00:00
|
|
|
void vhost_destroy_device_notify(struct virtio_net *dev);
|
2014-02-10 13:57:48 +00:00
|
|
|
|
2017-12-13 08:51:08 +00:00
|
|
|
void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
|
|
|
|
void free_vq(struct vhost_virtqueue *vq);
|
|
|
|
|
2017-04-01 07:22:47 +00:00
|
|
|
int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
|
2014-02-10 13:57:48 +00:00
|
|
|
|
2018-04-02 11:46:54 +00:00
|
|
|
void vhost_attach_vdpa_device(int vid, int did);
|
|
|
|
void vhost_detach_vdpa_device(int vid);
|
|
|
|
|
vhost: refactor code structure
The code structure is a bit messy now. For example, vhost-user message
handling is spread to three different files:
vhost-net-user.c virtio-net.c virtio-net-user.c
Where, vhost-net-user.c is the entrance to handle all those messages
and then invoke the right method for a specific message. Some of them
are stored at virtio-net.c, while others are stored at virtio-net-user.c.
The truth is all of them should be in one file, vhost_user.c.
So this patch refactors the source code structure: mainly on renaming
files and moving code from one file to another file that is more suitable
for storing it. Thus, no functional changes are made.
After the refactor, the code structure becomes to:
- socket.c handles all vhost-user socket file related stuff, such
as, socket file creation for server mode, reconnection
for client mode.
- vhost.c mainly on stuff like vhost device creation/destroy/reset.
Most of the vhost API implementation are there, too.
- vhost_user.c all stuff about vhost-user messages handling goes there.
- virtio_net.c all stuff about virtio-net should go there. It has virtio
net Rx/Tx implementation only so far: it's just a rename
from vhost_rxtx.c
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2016-08-18 08:48:39 +00:00
|
|
|
void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
|
2016-10-09 07:27:58 +00:00
|
|
|
void vhost_enable_dequeue_zero_copy(int vid);
|
2018-01-31 17:46:50 +00:00
|
|
|
void vhost_set_builtin_virtio_net(int vid, bool enable);
|
2016-02-10 18:40:55 +00:00
|
|
|
|
2017-04-01 07:22:52 +00:00
|
|
|
struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
|
2017-04-01 07:22:42 +00:00
|
|
|
|
2016-02-10 18:40:55 +00:00
|
|
|
/*
|
2016-11-02 03:15:01 +00:00
|
|
|
* Backend-specific cleanup.
|
|
|
|
*
|
|
|
|
* TODO: fix it; we have one backend now
|
2016-02-10 18:40:55 +00:00
|
|
|
*/
|
|
|
|
void vhost_backend_cleanup(struct virtio_net *dev);
|
|
|
|
|
2017-10-05 08:36:19 +00:00
|
|
|
uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
2018-01-23 13:26:02 +00:00
|
|
|
uint64_t iova, uint64_t *len, uint8_t perm);
|
2017-10-05 08:36:25 +00:00
|
|
|
int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
|
2017-10-05 08:36:26 +00:00
|
|
|
void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
|
2017-10-05 08:36:19 +00:00
|
|
|
|
|
|
|
static __rte_always_inline uint64_t
|
|
|
|
vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
2018-01-23 13:26:02 +00:00
|
|
|
uint64_t iova, uint64_t *len, uint8_t perm)
|
2017-10-05 08:36:19 +00:00
|
|
|
{
|
|
|
|
if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
|
2018-01-23 13:37:50 +00:00
|
|
|
return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
|
2017-10-05 08:36:19 +00:00
|
|
|
|
2018-01-23 13:26:02 +00:00
|
|
|
return __vhost_iova_to_vva(dev, vq, iova, len, perm);
|
2017-10-05 08:36:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 11:03:48 +00:00
|
|
|
#define vhost_used_event(vr) \
|
|
|
|
(*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is used with VIRTIO_RING_F_EVENT_IDX.
|
|
|
|
* Assuming a given event_idx value from the other size, if we have
|
|
|
|
* just incremented index from old to new_idx, should we trigger an
|
|
|
|
* event?
|
|
|
|
*/
|
|
|
|
static __rte_always_inline int
|
|
|
|
vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
|
|
|
|
{
|
|
|
|
return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
|
|
|
|
}
|
|
|
|
|
2018-01-02 09:31:35 +00:00
|
|
|
static __rte_always_inline void
|
2018-01-09 11:03:48 +00:00
|
|
|
vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
|
2018-01-02 09:31:35 +00:00
|
|
|
{
|
|
|
|
/* Flush used->idx update before we read avail->flags. */
|
2018-06-07 14:38:26 +00:00
|
|
|
rte_smp_mb();
|
2018-01-02 09:31:35 +00:00
|
|
|
|
2018-01-09 11:03:48 +00:00
|
|
|
/* Don't kick guest if we don't reach index specified by guest. */
|
|
|
|
if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
|
|
|
|
uint16_t old = vq->signalled_used;
|
|
|
|
uint16_t new = vq->last_used_idx;
|
|
|
|
|
2018-02-09 17:24:00 +00:00
|
|
|
VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
|
2018-01-09 11:03:48 +00:00
|
|
|
__func__,
|
|
|
|
vhost_used_event(vq),
|
|
|
|
old, new);
|
|
|
|
if (vhost_need_event(vhost_used_event(vq), new, old)
|
|
|
|
&& (vq->callfd >= 0)) {
|
|
|
|
vq->signalled_used = vq->last_used_idx;
|
|
|
|
eventfd_write(vq->callfd, (eventfd_t) 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Kick the guest if necessary. */
|
|
|
|
if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
|
|
|
|
&& (vq->callfd >= 0))
|
|
|
|
eventfd_write(vq->callfd, (eventfd_t)1);
|
|
|
|
}
|
2018-01-02 09:31:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:57:48 +00:00
|
|
|
#endif /* _VHOST_NET_CDEV_H_ */
|