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>
|
2022-08-27 11:32:22 +00:00
|
|
|
#include <stdlib.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>
|
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>
|
2018-12-18 08:02:00 +00:00
|
|
|
#include <rte_malloc.h>
|
2022-02-09 12:51:45 +00:00
|
|
|
#include <rte_dmadev.h>
|
2014-10-08 18:54:54 +00:00
|
|
|
|
2017-04-01 07:22:57 +00:00
|
|
|
#include "rte_vhost.h"
|
2021-11-02 09:56:11 +00:00
|
|
|
#include "vdpa_driver.h"
|
2015-02-23 17:36:31 +00:00
|
|
|
|
2020-07-07 05:07:08 +00:00
|
|
|
#include "rte_vhost_async.h"
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/* Used to indicate that the device is running on a data core */
|
2021-05-03 16:43:44 +00:00
|
|
|
#define VIRTIO_DEV_RUNNING ((uint32_t)1 << 0)
|
2017-03-12 16:34:00 +00:00
|
|
|
/* Used to indicate that the device is ready to operate */
|
2021-05-03 16:43:44 +00:00
|
|
|
#define VIRTIO_DEV_READY ((uint32_t)1 << 1)
|
2018-01-31 17:46:50 +00:00
|
|
|
/* Used to indicate that the built-in vhost net device backend is enabled */
|
2021-05-03 16:43:44 +00:00
|
|
|
#define VIRTIO_DEV_BUILTIN_VIRTIO_NET ((uint32_t)1 << 2)
|
2018-04-02 11:46:55 +00:00
|
|
|
/* Used to indicate that the device has its own data path and configured */
|
2021-05-03 16:43:44 +00:00
|
|
|
#define VIRTIO_DEV_VDPA_CONFIGURED ((uint32_t)1 << 3)
|
2020-07-06 11:24:50 +00:00
|
|
|
/* Used to indicate that the feature negotiation failed */
|
2021-05-03 16:43:44 +00:00
|
|
|
#define VIRTIO_DEV_FEATURES_FAILED ((uint32_t)1 << 4)
|
|
|
|
/* Used to indicate that the virtio_net tx code should fill TX ol_flags */
|
|
|
|
#define VIRTIO_DEV_LEGACY_OL_FLAGS ((uint32_t)1 << 5)
|
2022-05-10 20:17:16 +00:00
|
|
|
/* Used to indicate the application has requested statistics collection */
|
|
|
|
#define VIRTIO_DEV_STATS_ENABLED ((uint32_t)1 << 6)
|
2022-09-16 09:02:02 +00:00
|
|
|
/* Used to indicate the application has requested iommu support */
|
|
|
|
#define VIRTIO_DEV_SUPPORT_IOMMU ((uint32_t)1 << 7)
|
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
|
|
|
|
|
2020-07-07 05:07:08 +00:00
|
|
|
#define MAX_PKT_BURST 32
|
|
|
|
|
2021-10-26 16:28:53 +00:00
|
|
|
#define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST)
|
2021-10-26 16:29:04 +00:00
|
|
|
#define VHOST_MAX_ASYNC_VEC 2048
|
2022-02-09 12:51:45 +00:00
|
|
|
#define VIRTIO_MAX_RX_PKTLEN 9728U
|
|
|
|
#define VHOST_DMA_MAX_COPY_COMPLETE ((VIRTIO_MAX_RX_PKTLEN / RTE_MBUF_DEFAULT_DATAROOM) \
|
|
|
|
* MAX_PKT_BURST)
|
2020-07-07 05:07:08 +00:00
|
|
|
|
2019-10-24 16:08:27 +00:00
|
|
|
#define PACKED_DESC_ENQUEUE_USED_FLAG(w) \
|
|
|
|
((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \
|
|
|
|
VRING_DESC_F_WRITE)
|
2019-10-24 16:08:28 +00:00
|
|
|
#define PACKED_DESC_DEQUEUE_USED_FLAG(w) \
|
|
|
|
((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED) : 0x0)
|
2019-10-24 16:08:25 +00:00
|
|
|
#define PACKED_DESC_SINGLE_DEQUEUE_FLAG (VRING_DESC_F_NEXT | \
|
|
|
|
VRING_DESC_F_INDIRECT)
|
|
|
|
|
2019-10-24 16:08:22 +00:00
|
|
|
#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \
|
|
|
|
sizeof(struct vring_packed_desc))
|
|
|
|
#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
|
|
|
|
|
|
|
|
#ifdef VHOST_GCC_UNROLL_PRAGMA
|
|
|
|
#define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
|
|
|
|
for (iter = val; iter < size; iter++)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VHOST_CLANG_UNROLL_PRAGMA
|
|
|
|
#define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
|
|
|
|
for (iter = val; iter < size; iter++)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VHOST_ICC_UNROLL_PRAGMA
|
|
|
|
#define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll (4)") \
|
|
|
|
for (iter = val; iter < size; iter++)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef vhost_for_each_try_unroll
|
|
|
|
#define vhost_for_each_try_unroll(iter, val, num) \
|
|
|
|
for (iter = val; iter < num; iter++)
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-07-06 07:07:16 +00:00
|
|
|
struct vring_used_elem_packed {
|
|
|
|
uint16_t id;
|
2019-10-24 16:08:28 +00:00
|
|
|
uint16_t flags;
|
2018-07-06 07:07:16 +00:00
|
|
|
uint32_t len;
|
|
|
|
uint32_t count;
|
|
|
|
};
|
|
|
|
|
2022-05-10 20:17:16 +00:00
|
|
|
/**
|
|
|
|
* Virtqueue statistics
|
|
|
|
*/
|
|
|
|
struct virtqueue_stats {
|
|
|
|
uint64_t packets;
|
|
|
|
uint64_t bytes;
|
|
|
|
uint64_t multicast;
|
|
|
|
uint64_t broadcast;
|
|
|
|
/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */
|
|
|
|
uint64_t size_bins[8];
|
2022-05-10 20:17:18 +00:00
|
|
|
uint64_t guest_notifications;
|
2022-05-10 20:17:19 +00:00
|
|
|
uint64_t iotlb_hits;
|
|
|
|
uint64_t iotlb_misses;
|
2022-05-10 20:17:20 +00:00
|
|
|
uint64_t inflight_submitted;
|
|
|
|
uint64_t inflight_completed;
|
2022-05-10 20:17:16 +00:00
|
|
|
};
|
|
|
|
|
2022-02-09 12:51:45 +00:00
|
|
|
/**
|
|
|
|
* iovec
|
|
|
|
*/
|
|
|
|
struct vhost_iovec {
|
|
|
|
void *src_addr;
|
|
|
|
void *dst_addr;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iovec iterator
|
|
|
|
*/
|
|
|
|
struct vhost_iov_iter {
|
|
|
|
/** pointer to the iovec array */
|
|
|
|
struct vhost_iovec *iov;
|
|
|
|
/** number of iovec in this iterator */
|
|
|
|
unsigned long nr_segs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct async_dma_vchan_info {
|
|
|
|
/* circular array to track if packet copy completes */
|
|
|
|
bool **pkts_cmpl_flag_addr;
|
|
|
|
|
|
|
|
/* max elements in 'pkts_cmpl_flag_addr' */
|
|
|
|
uint16_t ring_size;
|
|
|
|
/* ring index mask for 'pkts_cmpl_flag_addr' */
|
|
|
|
uint16_t ring_mask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DMA virtual channel lock. Although it is able to bind DMA
|
|
|
|
* virtual channels to data plane threads, vhost control plane
|
|
|
|
* thread could call data plane functions too, thus causing
|
|
|
|
* DMA device contention.
|
|
|
|
*
|
|
|
|
* For example, in VM exit case, vhost control plane thread needs
|
|
|
|
* to clear in-flight packets before disable vring, but there could
|
|
|
|
* be anotther data plane thread is enqueuing packets to the same
|
|
|
|
* vring with the same DMA virtual channel. As dmadev PMD functions
|
|
|
|
* are lock-free, the control plane and data plane threads could
|
|
|
|
* operate the same DMA virtual channel at the same time.
|
|
|
|
*/
|
|
|
|
rte_spinlock_t dma_lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct async_dma_info {
|
|
|
|
struct async_dma_vchan_info *vchans;
|
|
|
|
/* number of registered virtual channels */
|
|
|
|
uint16_t nr_vchans;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct async_dma_info dma_copy_track[RTE_DMADEV_DEFAULT_MAX];
|
|
|
|
|
2021-10-26 16:28:51 +00:00
|
|
|
/**
|
|
|
|
* inflight async packet information
|
|
|
|
*/
|
|
|
|
struct async_inflight_info {
|
|
|
|
struct rte_mbuf *mbuf;
|
|
|
|
uint16_t descs; /* num of descs inflight */
|
|
|
|
uint16_t nr_buffers; /* num of buffers inflight for packed ring */
|
2022-05-16 11:10:39 +00:00
|
|
|
struct virtio_net_hdr nethdr;
|
2021-10-26 16:28:51 +00:00
|
|
|
};
|
|
|
|
|
2021-10-26 16:28:50 +00:00
|
|
|
struct vhost_async {
|
2022-02-09 12:51:45 +00:00
|
|
|
struct vhost_iov_iter iov_iter[VHOST_MAX_ASYNC_IT];
|
|
|
|
struct vhost_iovec iovec[VHOST_MAX_ASYNC_VEC];
|
2021-10-26 16:28:57 +00:00
|
|
|
uint16_t iter_idx;
|
|
|
|
uint16_t iovec_idx;
|
2021-10-26 16:28:50 +00:00
|
|
|
|
|
|
|
/* data transfer status */
|
|
|
|
struct async_inflight_info *pkts_info;
|
2022-02-09 12:51:45 +00:00
|
|
|
/**
|
|
|
|
* Packet reorder array. "true" indicates that DMA device
|
|
|
|
* completes all copies for the packet.
|
|
|
|
*
|
|
|
|
* Note that this array could be written by multiple threads
|
|
|
|
* simultaneously. For example, in the case of thread0 and
|
|
|
|
* thread1 RX packets from NIC and then enqueue packets to
|
|
|
|
* vring0 and vring1 with own DMA device DMA0 and DMA1, it's
|
|
|
|
* possible for thread0 to get completed copies belonging to
|
|
|
|
* vring1 from DMA0, while thread0 is calling rte_vhost_poll
|
|
|
|
* _enqueue_completed() for vring0 and thread1 is calling
|
|
|
|
* rte_vhost_submit_enqueue_burst() for vring1. In this case,
|
|
|
|
* vq->access_lock cannot protect pkts_cmpl_flag of vring1.
|
|
|
|
*
|
|
|
|
* However, since offloading is per-packet basis, each packet
|
|
|
|
* flag will only be written by one thread. And single byte
|
|
|
|
* write is atomic, so no lock for pkts_cmpl_flag is needed.
|
|
|
|
*/
|
|
|
|
bool *pkts_cmpl_flag;
|
2021-10-26 16:28:50 +00:00
|
|
|
uint16_t pkts_idx;
|
|
|
|
uint16_t pkts_inflight_n;
|
|
|
|
union {
|
|
|
|
struct vring_used_elem *descs_split;
|
|
|
|
struct vring_used_elem_packed *buffers_packed;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint16_t desc_idx_split;
|
|
|
|
uint16_t buffer_idx_packed;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint16_t last_desc_idx_split;
|
|
|
|
uint16_t last_buffer_idx_packed;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-04-30 05:11:19 +00:00
|
|
|
/**
|
|
|
|
* Structure contains variables relevant to RX/TX virtqueues.
|
|
|
|
*/
|
|
|
|
struct vhost_virtqueue {
|
2018-07-06 07:07:10 +00:00
|
|
|
union {
|
|
|
|
struct vring_desc *desc;
|
|
|
|
struct vring_packed_desc *desc_packed;
|
|
|
|
};
|
2018-07-06 07:07:21 +00:00
|
|
|
union {
|
|
|
|
struct vring_avail *avail;
|
|
|
|
struct vring_packed_desc_event *driver_event;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct vring_used *used;
|
|
|
|
struct vring_packed_desc_event *device_event;
|
|
|
|
};
|
2021-03-23 09:02:19 +00:00
|
|
|
uint16_t size;
|
2016-04-30 05:11:19 +00:00
|
|
|
|
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;
|
2018-07-06 07:07:21 +00:00
|
|
|
bool signalled_used_valid;
|
2016-04-30 05:11:19 +00:00
|
|
|
#define VIRTIO_INVALID_EVENTFD (-1)
|
|
|
|
#define VIRTIO_UNINITIALIZED_EVENTFD (-2)
|
|
|
|
|
2021-03-23 09:02:19 +00:00
|
|
|
bool enabled;
|
|
|
|
bool access_ok;
|
|
|
|
bool ready;
|
2020-07-23 13:08:53 +00:00
|
|
|
|
2018-01-17 13:49:25 +00:00
|
|
|
rte_spinlock_t access_lock;
|
|
|
|
|
2019-10-09 20:48:33 +00:00
|
|
|
|
2018-07-06 07:07:16 +00:00
|
|
|
union {
|
|
|
|
struct vring_used_elem *shadow_used_split;
|
|
|
|
struct vring_used_elem_packed *shadow_used_packed;
|
|
|
|
};
|
2016-10-14 09:34:36 +00:00
|
|
|
uint16_t shadow_used_idx;
|
2019-10-24 16:08:26 +00:00
|
|
|
/* Record packed ring enqueue latest desc cache aligned index */
|
|
|
|
uint16_t shadow_aligned_idx;
|
2019-10-24 16:08:28 +00:00
|
|
|
/* Record packed ring first dequeue desc index */
|
|
|
|
uint16_t shadow_last_used_idx;
|
2017-09-08 12:50:46 +00:00
|
|
|
|
|
|
|
uint16_t batch_copy_nb_elems;
|
2021-03-23 09:02:19 +00:00
|
|
|
struct batch_copy_elem *batch_copy_elems;
|
2021-06-29 16:11:32 +00:00
|
|
|
int numa_node;
|
2018-07-06 07:07:10 +00:00
|
|
|
bool used_wrap_counter;
|
|
|
|
bool avail_wrap_counter;
|
2017-10-05 08:36:14 +00:00
|
|
|
|
2021-03-23 09:02:19 +00:00
|
|
|
/* Physical address of used ring, for logging */
|
|
|
|
uint16_t log_cache_nb_elem;
|
|
|
|
uint64_t log_guest_addr;
|
|
|
|
struct log_cache_entry *log_cache;
|
2018-05-17 11:44:47 +00:00
|
|
|
|
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;
|
2022-07-25 20:32:06 +00:00
|
|
|
struct vhost_iotlb_entry *iotlb_pool;
|
2017-10-05 08:36:14 +00:00
|
|
|
TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
|
2017-10-05 08:36:15 +00:00
|
|
|
TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
|
2021-03-23 09:02:19 +00:00
|
|
|
int iotlb_cache_nr;
|
2022-07-25 20:32:06 +00:00
|
|
|
rte_spinlock_t iotlb_free_lock;
|
|
|
|
SLIST_HEAD(, vhost_iotlb_entry) iotlb_free_list;
|
2021-03-23 09:02:19 +00:00
|
|
|
|
|
|
|
/* Used to notify the guest (trigger interrupt) */
|
|
|
|
int callfd;
|
|
|
|
/* Currently unused as polling mode is enabled */
|
|
|
|
int kickfd;
|
|
|
|
|
2022-07-25 20:32:05 +00:00
|
|
|
/* Index of this vq in dev->virtqueue[] */
|
|
|
|
uint32_t index;
|
|
|
|
|
2021-03-23 09:02:19 +00:00
|
|
|
/* inflight share memory info */
|
|
|
|
union {
|
|
|
|
struct rte_vhost_inflight_info_split *inflight_split;
|
|
|
|
struct rte_vhost_inflight_info_packed *inflight_packed;
|
|
|
|
};
|
|
|
|
struct rte_vhost_resubmit_info *resubmit_inflight;
|
|
|
|
uint64_t global_counter;
|
2020-07-07 05:07:08 +00:00
|
|
|
|
2021-10-26 16:28:50 +00:00
|
|
|
struct vhost_async *async;
|
2021-03-23 09:02:19 +00:00
|
|
|
|
|
|
|
int notif_enable;
|
|
|
|
#define VIRTIO_UNINITIALIZED_NOTIF (-1)
|
|
|
|
|
|
|
|
struct vhost_vring_addr ring_addrs;
|
2022-05-10 20:17:16 +00:00
|
|
|
struct virtqueue_stats stats;
|
2016-04-30 05:11:19 +00:00
|
|
|
} __rte_cache_aligned;
|
|
|
|
|
2020-07-06 11:24:49 +00:00
|
|
|
/* Virtio device status as per Virtio specification */
|
2020-08-10 13:18:02 +00:00
|
|
|
#define VIRTIO_DEVICE_STATUS_RESET 0x00
|
2020-07-06 11:24:49 +00:00
|
|
|
#define VIRTIO_DEVICE_STATUS_ACK 0x01
|
|
|
|
#define VIRTIO_DEVICE_STATUS_DRIVER 0x02
|
|
|
|
#define VIRTIO_DEVICE_STATUS_DRIVER_OK 0x04
|
|
|
|
#define VIRTIO_DEVICE_STATUS_FEATURES_OK 0x08
|
|
|
|
#define VIRTIO_DEVICE_STATUS_DEV_NEED_RESET 0x40
|
|
|
|
#define VIRTIO_DEVICE_STATUS_FAILED 0x80
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
struct vring_packed_desc {
|
|
|
|
uint64_t addr;
|
|
|
|
uint32_t len;
|
|
|
|
uint16_t id;
|
|
|
|
uint16_t flags;
|
|
|
|
};
|
2018-07-06 07:07:21 +00:00
|
|
|
|
|
|
|
struct vring_packed_desc_event {
|
|
|
|
uint16_t off_wrap;
|
|
|
|
uint16_t flags;
|
|
|
|
};
|
2018-07-06 07:07:08 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-22 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Declare below packed ring defines unconditionally
|
|
|
|
* as Kernel header might use different names.
|
|
|
|
*/
|
|
|
|
#define VRING_DESC_F_AVAIL (1ULL << 7)
|
|
|
|
#define VRING_DESC_F_USED (1ULL << 15)
|
|
|
|
|
|
|
|
#define VRING_EVENT_F_ENABLE 0x0
|
|
|
|
#define VRING_EVENT_F_DISABLE 0x1
|
|
|
|
#define VRING_EVENT_F_DESC 0x2
|
|
|
|
|
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) | \
|
2018-10-31 10:26:40 +00:00
|
|
|
(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
|
|
|
|
(1ULL << VIRTIO_F_RING_PACKED))
|
2017-04-01 07:22:41 +00:00
|
|
|
|
|
|
|
|
2016-10-09 07:27:55 +00:00
|
|
|
struct guest_page {
|
|
|
|
uint64_t guest_phys_addr;
|
2022-02-15 15:02:25 +00:00
|
|
|
uint64_t host_iova;
|
2022-02-15 15:02:26 +00:00
|
|
|
uint64_t host_user_addr;
|
2016-10-09 07:27:55 +00:00
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
2019-10-09 20:48:32 +00:00
|
|
|
struct inflight_mem_info {
|
|
|
|
int fd;
|
|
|
|
void *addr;
|
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
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 */
|
2020-04-23 16:54:49 +00:00
|
|
|
int16_t broadcast_rarp;
|
2017-04-01 07:22:47 +00:00
|
|
|
uint32_t nr_vring;
|
2020-07-07 05:07:08 +00:00
|
|
|
int async_copy;
|
2021-10-11 07:59:42 +00:00
|
|
|
|
2019-10-15 18:59:51 +00:00
|
|
|
int extbuf;
|
|
|
|
int linearbuf;
|
2016-05-03 00:46:18 +00:00
|
|
|
struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
|
2019-10-09 20:48:32 +00:00
|
|
|
struct inflight_mem_info *inflight_info;
|
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;
|
2019-05-21 16:13:03 +00:00
|
|
|
struct rte_ether_addr mac;
|
2017-03-12 16:33:59 +00:00
|
|
|
uint16_t mtu;
|
2020-07-06 11:24:49 +00:00
|
|
|
uint8_t status;
|
2016-04-30 05:11:19 +00:00
|
|
|
|
2021-11-02 10:47:48 +00:00
|
|
|
struct rte_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
|
|
|
|
2018-10-12 12:40:39 +00:00
|
|
|
int postcopy_ufd;
|
2018-10-12 12:40:40 +00:00
|
|
|
int postcopy_listening;
|
2018-10-12 12:40:39 +00:00
|
|
|
|
2020-06-26 14:04:33 +00:00
|
|
|
struct rte_vdpa_device *vdpa_dev;
|
2016-04-30 05:11:19 +00:00
|
|
|
|
2019-01-17 15:32:26 +00:00
|
|
|
/* context data for the external message handlers */
|
2018-04-05 16:01:30 +00:00
|
|
|
void *extern_data;
|
|
|
|
/* pre and post vhost user message handlers for the device */
|
2019-01-17 15:32:26 +00:00
|
|
|
struct rte_vhost_user_extern_ops extern_ops;
|
2018-04-05 16:01:30 +00:00
|
|
|
} __rte_cache_aligned;
|
2017-04-01 07:22:55 +00:00
|
|
|
|
2018-07-06 07:07:09 +00:00
|
|
|
static __rte_always_inline bool
|
|
|
|
vq_is_packed(struct virtio_net *dev)
|
|
|
|
{
|
|
|
|
return dev->features & (1ull << VIRTIO_F_RING_PACKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
|
|
|
|
{
|
2019-09-17 05:28:25 +00:00
|
|
|
uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
|
2018-12-05 15:09:26 +00:00
|
|
|
|
|
|
|
return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
|
|
|
|
wrap_counter != !!(flags & VRING_DESC_F_USED);
|
2018-07-06 07:07:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:08:20 +00:00
|
|
|
static inline void
|
|
|
|
vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
|
|
|
|
{
|
|
|
|
vq->last_used_idx += num;
|
|
|
|
if (vq->last_used_idx >= vq->size) {
|
|
|
|
vq->used_wrap_counter ^= 1;
|
|
|
|
vq->last_used_idx -= vq->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
|
|
|
|
{
|
|
|
|
vq->last_avail_idx += num;
|
|
|
|
if (vq->last_avail_idx >= vq->size) {
|
|
|
|
vq->avail_wrap_counter ^= 1;
|
|
|
|
vq->last_avail_idx -= vq->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:04:16 +00:00
|
|
|
void __vhost_log_cache_write(struct virtio_net *dev,
|
|
|
|
struct vhost_virtqueue *vq,
|
|
|
|
uint64_t addr, uint64_t len);
|
2019-10-09 11:54:31 +00:00
|
|
|
void __vhost_log_cache_write_iova(struct virtio_net *dev,
|
|
|
|
struct vhost_virtqueue *vq,
|
|
|
|
uint64_t iova, uint64_t len);
|
2019-05-29 13:04:16 +00:00
|
|
|
void __vhost_log_cache_sync(struct virtio_net *dev,
|
|
|
|
struct vhost_virtqueue *vq);
|
|
|
|
void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
|
2019-10-09 11:54:31 +00:00
|
|
|
void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t iova, uint64_t len);
|
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)
|
|
|
|
{
|
2019-05-29 13:04:16 +00:00
|
|
|
if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
|
|
|
|
__vhost_log_write(dev, addr, len);
|
2017-04-01 07:22:55 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2019-05-29 13:04:16 +00:00
|
|
|
if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
|
|
|
|
__vhost_log_cache_sync(dev, vq);
|
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)
|
|
|
|
{
|
2019-05-29 13:04:16 +00:00
|
|
|
if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
|
|
|
|
__vhost_log_cache_write(dev, vq, addr, len);
|
2018-05-17 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t offset, uint64_t len)
|
|
|
|
{
|
2020-02-13 10:04:58 +00:00
|
|
|
if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
|
|
|
|
if (unlikely(vq->log_guest_addr == 0))
|
|
|
|
return;
|
|
|
|
__vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,
|
|
|
|
len);
|
|
|
|
}
|
2018-05-17 11:44:47 +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_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t offset, uint64_t len)
|
|
|
|
{
|
2020-02-13 10:04:58 +00:00
|
|
|
if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
|
|
|
|
if (unlikely(vq->log_guest_addr == 0))
|
|
|
|
return;
|
|
|
|
__vhost_log_write(dev, vq->log_guest_addr + offset, len);
|
|
|
|
}
|
2017-04-01 07:22:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 11:54:31 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t iova, uint64_t len)
|
|
|
|
{
|
|
|
|
if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
|
|
|
|
__vhost_log_cache_write_iova(dev, vq, iova, len);
|
|
|
|
else
|
|
|
|
__vhost_log_cache_write(dev, vq, iova, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t iova, uint64_t len)
|
|
|
|
{
|
|
|
|
if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
|
|
|
|
__vhost_log_write_iova(dev, vq, iova, len);
|
|
|
|
else
|
|
|
|
__vhost_log_write(dev, iova, len);
|
|
|
|
}
|
|
|
|
|
2019-12-04 15:07:29 +00:00
|
|
|
extern int vhost_config_log_level;
|
|
|
|
extern int vhost_data_log_level;
|
|
|
|
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
#define VHOST_LOG_CONFIG(prefix, level, fmt, args...) \
|
2019-12-04 15:07:29 +00:00
|
|
|
rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
"VHOST_CONFIG: (%s) " fmt, prefix, ##args)
|
2019-12-04 15:07:29 +00:00
|
|
|
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
#define VHOST_LOG_DATA(prefix, level, fmt, args...) \
|
2019-12-04 15:07:29 +00:00
|
|
|
(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
|
|
|
|
rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
"VHOST_DATA: (%s) " fmt, prefix, ##args) : \
|
2019-12-04 15:07:29 +00:00
|
|
|
0)
|
2014-10-08 18:54:52 +00:00
|
|
|
|
|
|
|
#ifdef RTE_LIBRTE_VHOST_DEBUG
|
|
|
|
#define VHOST_MAX_PRINT_BUFF 6072
|
|
|
|
#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"); \
|
|
|
|
\
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
VHOST_LOG_DATA(device->ifname, DEBUG, "%s", packet); \
|
2014-10-08 18:54:52 +00:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define PRINT_PACKET(device, addr, size, header) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2022-02-09 12:51:45 +00:00
|
|
|
extern struct virtio_net *vhost_devices[RTE_MAX_VHOST_DEVICE];
|
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
|
|
|
|
2020-04-29 01:04:22 +00:00
|
|
|
#define VHOST_BINARY_SEARCH_THRESH 256
|
|
|
|
|
|
|
|
static __rte_always_inline int guest_page_addrcmp(const void *p1,
|
|
|
|
const void *p2)
|
|
|
|
{
|
|
|
|
const struct guest_page *page1 = (const struct guest_page *)p1;
|
|
|
|
const struct guest_page *page2 = (const struct guest_page *)p2;
|
|
|
|
|
|
|
|
if (page1->guest_phys_addr > page2->guest_phys_addr)
|
|
|
|
return 1;
|
|
|
|
if (page1->guest_phys_addr < page2->guest_phys_addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-17 16:20:27 +00:00
|
|
|
static __rte_always_inline int guest_page_rangecmp(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const struct guest_page *page1 = (const struct guest_page *)p1;
|
|
|
|
const struct guest_page *page2 = (const struct guest_page *)p2;
|
|
|
|
|
|
|
|
if (page1->guest_phys_addr >= page2->guest_phys_addr) {
|
|
|
|
if (page1->guest_phys_addr < page2->guest_phys_addr + page2->size)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-07-29 02:04:56 +00:00
|
|
|
static __rte_always_inline rte_iova_t
|
|
|
|
gpa_to_first_hpa(struct virtio_net *dev, uint64_t gpa,
|
|
|
|
uint64_t gpa_size, uint64_t *hpa_size)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
struct guest_page *page;
|
|
|
|
struct guest_page key;
|
|
|
|
|
|
|
|
*hpa_size = gpa_size;
|
|
|
|
if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
|
2022-01-17 16:20:27 +00:00
|
|
|
key.guest_phys_addr = gpa;
|
2020-07-29 02:04:56 +00:00
|
|
|
page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
|
2022-01-17 16:20:27 +00:00
|
|
|
sizeof(struct guest_page), guest_page_rangecmp);
|
2020-07-29 02:04:56 +00:00
|
|
|
if (page) {
|
|
|
|
if (gpa + gpa_size <=
|
|
|
|
page->guest_phys_addr + page->size) {
|
|
|
|
return gpa - page->guest_phys_addr +
|
2022-02-15 15:02:25 +00:00
|
|
|
page->host_iova;
|
2020-07-29 02:04:56 +00:00
|
|
|
} else if (gpa < page->guest_phys_addr +
|
|
|
|
page->size) {
|
|
|
|
*hpa_size = page->guest_phys_addr +
|
|
|
|
page->size - gpa;
|
|
|
|
return gpa - page->guest_phys_addr +
|
2022-02-15 15:02:25 +00:00
|
|
|
page->host_iova;
|
2020-07-29 02:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < dev->nr_guest_pages; i++) {
|
|
|
|
page = &dev->guest_pages[i];
|
|
|
|
|
|
|
|
if (gpa >= page->guest_phys_addr) {
|
|
|
|
if (gpa + gpa_size <=
|
|
|
|
page->guest_phys_addr + page->size) {
|
|
|
|
return gpa - page->guest_phys_addr +
|
2022-02-15 15:02:25 +00:00
|
|
|
page->host_iova;
|
2020-07-29 02:04:56 +00:00
|
|
|
} else if (gpa < page->guest_phys_addr +
|
|
|
|
page->size) {
|
|
|
|
*hpa_size = page->guest_phys_addr +
|
|
|
|
page->size - gpa;
|
|
|
|
return gpa - page->guest_phys_addr +
|
2022-02-15 15:02:25 +00:00
|
|
|
page->host_iova;
|
2020-07-29 02:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*hpa_size = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 02:06:08 +00:00
|
|
|
/* Convert guest physical address to host physical address */
|
|
|
|
static __rte_always_inline rte_iova_t
|
|
|
|
gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
|
|
|
|
{
|
|
|
|
rte_iova_t hpa;
|
|
|
|
uint64_t hpa_size;
|
|
|
|
|
|
|
|
hpa = gpa_to_first_hpa(dev, gpa, size, &hpa_size);
|
|
|
|
return hpa_size == size ? hpa : 0;
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:54:30 +00:00
|
|
|
static __rte_always_inline uint64_t
|
|
|
|
hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
|
|
|
|
{
|
|
|
|
struct rte_vhost_mem_region *r;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
if (unlikely(!dev || !dev->mem))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->mem->nregions; i++) {
|
|
|
|
r = &dev->mem->regions[i];
|
|
|
|
|
|
|
|
if (vva >= r->host_user_addr &&
|
|
|
|
vva + len < r->host_user_addr + r->size) {
|
|
|
|
return r->guest_phys_addr + vva - r->host_user_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)) {
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
VHOST_LOG_CONFIG("device", ERR, "(%d) device not found.\n", vid);
|
2018-02-14 04:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-10-09 20:48:33 +00:00
|
|
|
void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
|
2018-07-06 07:07:16 +00:00
|
|
|
void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
|
2017-12-13 08:51:08 +00:00
|
|
|
|
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
|
|
|
|
2020-06-26 14:04:33 +00:00
|
|
|
void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
|
2018-04-02 11:46:54 +00:00
|
|
|
|
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);
|
2022-09-16 09:02:02 +00:00
|
|
|
void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled,
|
|
|
|
bool support_iommu);
|
2019-10-15 18:59:51 +00:00
|
|
|
void vhost_enable_extbuf(int vid);
|
|
|
|
void vhost_enable_linearbuf(int vid);
|
2020-07-23 13:08:53 +00:00
|
|
|
int vhost_enable_guest_notification(struct virtio_net *dev,
|
|
|
|
struct vhost_virtqueue *vq, int enable);
|
2016-02-10 18:40:55 +00:00
|
|
|
|
2021-11-02 10:47:48 +00:00
|
|
|
struct rte_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);
|
2019-05-29 13:04:18 +00:00
|
|
|
void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
|
|
|
|
struct vhost_virtqueue *vq,
|
|
|
|
uint64_t desc_addr, uint64_t desc_len);
|
2017-10-05 08:36:25 +00:00
|
|
|
int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
|
2020-02-13 10:04:58 +00:00
|
|
|
uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
|
|
|
|
uint64_t log_addr);
|
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-09-04 23:55:55 +00:00
|
|
|
#define vhost_avail_event(vr) \
|
|
|
|
(*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
|
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-07-06 07:07:21 +00:00
|
|
|
vhost_vring_call_split(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. */
|
2020-12-21 15:50:33 +00:00
|
|
|
rte_atomic_thread_fence(__ATOMIC_SEQ_CST);
|
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;
|
2021-01-11 12:16:27 +00:00
|
|
|
uint16_t new = vq->last_used_idx;
|
2019-03-17 06:38:32 +00:00
|
|
|
bool signalled_used_valid = vq->signalled_used_valid;
|
|
|
|
|
|
|
|
vq->signalled_used = new;
|
|
|
|
vq->signalled_used_valid = true;
|
2018-01-09 11:03:48 +00:00
|
|
|
|
vhost: prefix logs with context
We recently improved the log messages in the vhost library, adding some
context that helps filtering for a given vhost-user device.
However, some parts of the code were missed, and some later code changes
broke this new convention (fixes were sent previous to this patch).
Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string
used as context. This should help limit regressions on this topic.
Most of the time, the context is the vhost-user device socket path.
For the rest when a vhost-user device can not be related, generic
names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2022-07-01 13:20:56 +00:00
|
|
|
VHOST_LOG_DATA(dev->ifname, DEBUG,
|
|
|
|
"%s: used_event_idx=%d, old=%d, new=%d\n",
|
|
|
|
__func__, vhost_used_event(vq), old, new);
|
2019-03-17 06:38:32 +00:00
|
|
|
|
|
|
|
if ((vhost_need_event(vhost_used_event(vq), new, old) &&
|
|
|
|
(vq->callfd >= 0)) ||
|
2019-08-28 14:49:39 +00:00
|
|
|
unlikely(!signalled_used_valid)) {
|
2018-01-09 11:03:48 +00:00
|
|
|
eventfd_write(vq->callfd, (eventfd_t) 1);
|
2022-05-10 20:17:18 +00:00
|
|
|
if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
|
|
|
|
vq->stats.guest_notifications++;
|
2019-08-28 14:49:39 +00:00
|
|
|
if (dev->notify_ops->guest_notified)
|
|
|
|
dev->notify_ops->guest_notified(dev->vid);
|
|
|
|
}
|
2018-01-09 11:03:48 +00:00
|
|
|
} else {
|
|
|
|
/* Kick the guest if necessary. */
|
|
|
|
if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
|
2019-08-28 14:49:39 +00:00
|
|
|
&& (vq->callfd >= 0)) {
|
2018-01-09 11:03:48 +00:00
|
|
|
eventfd_write(vq->callfd, (eventfd_t)1);
|
2022-05-10 20:17:18 +00:00
|
|
|
if (dev->flags & VIRTIO_DEV_STATS_ENABLED)
|
|
|
|
vq->stats.guest_notifications++;
|
2019-08-28 14:49:39 +00:00
|
|
|
if (dev->notify_ops->guest_notified)
|
|
|
|
dev->notify_ops->guest_notified(dev->vid);
|
|
|
|
}
|
2018-01-09 11:03:48 +00:00
|
|
|
}
|
2018-01-02 09:31:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 07:07:21 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
|
|
|
|
{
|
|
|
|
uint16_t old, new, off, off_wrap;
|
|
|
|
bool signalled_used_valid, kick = false;
|
|
|
|
|
|
|
|
/* Flush used desc update. */
|
2020-12-21 15:50:33 +00:00
|
|
|
rte_atomic_thread_fence(__ATOMIC_SEQ_CST);
|
2018-07-06 07:07:21 +00:00
|
|
|
|
|
|
|
if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
|
|
|
|
if (vq->driver_event->flags !=
|
|
|
|
VRING_EVENT_F_DISABLE)
|
|
|
|
kick = true;
|
|
|
|
goto kick;
|
|
|
|
}
|
|
|
|
|
|
|
|
old = vq->signalled_used;
|
|
|
|
new = vq->last_used_idx;
|
|
|
|
vq->signalled_used = new;
|
|
|
|
signalled_used_valid = vq->signalled_used_valid;
|
|
|
|
vq->signalled_used_valid = true;
|
|
|
|
|
|
|
|
if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
|
|
|
|
if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
|
|
|
|
kick = true;
|
|
|
|
goto kick;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(!signalled_used_valid)) {
|
|
|
|
kick = true;
|
|
|
|
goto kick;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:50:33 +00:00
|
|
|
rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
|
2018-07-06 07:07:21 +00:00
|
|
|
|
|
|
|
off_wrap = vq->driver_event->off_wrap;
|
|
|
|
off = off_wrap & ~(1 << 15);
|
|
|
|
|
|
|
|
if (new <= old)
|
|
|
|
old -= vq->size;
|
|
|
|
|
|
|
|
if (vq->used_wrap_counter != off_wrap >> 15)
|
|
|
|
off -= vq->size;
|
|
|
|
|
|
|
|
if (vhost_need_event(off, new, old))
|
|
|
|
kick = true;
|
|
|
|
kick:
|
2019-08-28 14:49:39 +00:00
|
|
|
if (kick) {
|
2018-07-06 07:07:21 +00:00
|
|
|
eventfd_write(vq->callfd, (eventfd_t)1);
|
2019-08-28 14:49:39 +00:00
|
|
|
if (dev->notify_ops->guest_notified)
|
|
|
|
dev->notify_ops->guest_notified(dev->vid);
|
|
|
|
}
|
2018-07-06 07:07:21 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 08:02:00 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
free_ind_table(void *idesc)
|
|
|
|
{
|
|
|
|
rte_free(idesc);
|
|
|
|
}
|
|
|
|
|
2019-02-22 02:42:06 +00:00
|
|
|
static __rte_always_inline void
|
|
|
|
restore_mbuf(struct rte_mbuf *m)
|
|
|
|
{
|
|
|
|
uint32_t mbuf_size, priv_size;
|
|
|
|
|
|
|
|
while (m) {
|
|
|
|
priv_size = rte_pktmbuf_priv_size(m->pool);
|
|
|
|
mbuf_size = sizeof(struct rte_mbuf) + priv_size;
|
|
|
|
/* start of buffer is after mbuf structure and priv data */
|
|
|
|
|
|
|
|
m->buf_addr = (char *)m + mbuf_size;
|
2022-10-07 21:02:05 +00:00
|
|
|
rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size);
|
2019-02-22 02:42:06 +00:00
|
|
|
m = m->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 02:42:07 +00:00
|
|
|
static __rte_always_inline bool
|
|
|
|
mbuf_is_consumed(struct rte_mbuf *m)
|
|
|
|
{
|
|
|
|
while (m) {
|
|
|
|
if (rte_mbuf_refcnt_read(m) > 1)
|
|
|
|
return false;
|
|
|
|
m = m->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 13:57:48 +00:00
|
|
|
#endif /* _VHOST_NET_CDEV_H_ */
|