This is the exact copy of linux-2.6.32-220.7.1.el6.x86_64/drivers/vhost/vhost.h
#include <linux/eventfd.h>
#include "./linux/vhost.h"
#include <linux/skbuff.h>
#include <linux/virtio_config.h>
#include <linux/virtio_ring.h>
/* This is for zerocopy, used buffer len is set to 1 when lower device DMA
#define VHOST_DMA_DONE_LEN 1
#define VHOST_DMA_CLEAR_LEN 0
typedef void (*vhost_work_fn_t
)(struct vhost_work
*work
);
/* Poll a file (eventfd or socket) */
/* Note: there's nothing vhost specific about this structure. */
void vhost_poll_init(struct vhost_poll
*poll
, vhost_work_fn_t fn
,
unsigned long mask
, struct vhost_dev
*dev
);
void vhost_poll_start(struct vhost_poll
*poll
, struct file
*file
);
void vhost_poll_stop(struct vhost_poll
*poll
);
void vhost_poll_flush(struct vhost_poll
*poll
);
void vhost_poll_queue(struct vhost_poll
*poll
);
struct vhost_virtqueue
*vq
;
struct vhost_ubuf_ref
*vhost_ubuf_alloc(struct vhost_virtqueue
*, bool zcopy
);
void vhost_ubuf_put(struct vhost_ubuf_ref
*);
void vhost_ubuf_put_and_wait(struct vhost_ubuf_ref
*);
/* The virtqueue structure describes a queue attached to a device. */
/* The actual ring of buffers. */
struct vring_desc __user
*desc
;
struct vring_avail __user
*avail
;
struct vring_used __user
*used
;
struct eventfd_ctx
*call_ctx
;
struct eventfd_ctx
*error_ctx
;
struct eventfd_ctx
*log_ctx
;
/* The routine to call when the Guest pings us, or timeout. */
vhost_work_fn_t handle_kick
;
/* Last available index we saw. */
/* Caches available index value from user. */
/* Last index we used. */
/* Last used index value we have signalled on */
/* Last used index value we have signalled on */
bool signalled_used_valid
;
/* Log writes to used structure. */
struct iovec iov
[UIO_MAXIOV
];
/* hdr is used to store the virtio header.
* Since each iovec has >= 1 byte length, we never need more than
* header length entries to store the header. */
struct iovec hdr
[sizeof(struct virtio_net_hdr_mrg_rxbuf
)];
struct vring_used_elem
*heads
;
/* We use a kind of RCU to access private pointer.
* All readers access it from worker, which makes it possible to
* flush the vhost_work instead of synchronize_rcu. Therefore readers do
* not need to call rcu_read_lock/rcu_read_unlock: the beginning of
* vhost_work execution acts instead of rcu_read_lock() and the end of
* vhost_work execution acts instead of rcu_read_lock().
* Writers use virtqueue mutex. */
/* Log write descriptors */
/* vhost zerocopy support fields below: */
/* last used idx for outstanding DMA zerocopy buffers */
/* first used idx for DMA done zerocopy buffers */
/* an array of userspace buffers info */
struct ubuf_info
*ubuf_info
;
/* Reference counting for outstanding ubufs.
* Protected by vq mutex. Writers must also take device mutex. */
struct vhost_ubuf_ref
*ubufs
;
/* Readers use RCU to access memory table pointer
* log base pointer and features.
* Writers use mutex below.*/
struct vhost_memory
*memory
;
struct vhost_virtqueue
*vqs
;
struct eventfd_ctx
*log_ctx
;
struct list_head work_list
;
struct task_struct
*worker
;
long vhost_dev_init(struct vhost_dev
*, struct vhost_virtqueue
*vqs
, int nvqs
);
long vhost_dev_check_owner(struct vhost_dev
*);
long vhost_dev_reset_owner(struct vhost_dev
*);
void vhost_dev_cleanup(struct vhost_dev
*);
long vhost_dev_ioctl(struct vhost_dev
*, unsigned int ioctl
, unsigned long arg
);
int vhost_vq_access_ok(struct vhost_virtqueue
*vq
);
int vhost_log_access_ok(struct vhost_dev
*);
int vhost_get_vq_desc(struct vhost_dev
*, struct vhost_virtqueue
*,
struct iovec iov
[], unsigned int iov_count
,
unsigned int *out_num
, unsigned int *in_num
,
struct vhost_log
*log
, unsigned int *log_num
);
void vhost_discard_vq_desc(struct vhost_virtqueue
*, int n
);
int vhost_init_used(struct vhost_virtqueue
*);
int vhost_add_used(struct vhost_virtqueue
*, unsigned int head
, int len
);
int vhost_add_used_n(struct vhost_virtqueue
*, struct vring_used_elem
*heads
,
void vhost_add_used_and_signal(struct vhost_dev
*, struct vhost_virtqueue
*,
unsigned int id
, int len
);
void vhost_add_used_and_signal_n(struct vhost_dev
*, struct vhost_virtqueue
*,
struct vring_used_elem
*heads
, unsigned count
);
void vhost_signal(struct vhost_dev
*, struct vhost_virtqueue
*);
void vhost_disable_notify(struct vhost_dev
*, struct vhost_virtqueue
*);
bool vhost_enable_notify(struct vhost_dev
*, struct vhost_virtqueue
*);
int vhost_log_write(struct vhost_virtqueue
*vq
, struct vhost_log
*log
,
unsigned int log_num
, u64 len
);
void vhost_zerocopy_callback(void *arg
);
int vhost_zerocopy_signal_used(struct vhost_virtqueue
*vq
);
#define vq_err(vq, fmt, ...) do { \
pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
eventfd_signal((vq)->error_ctx, 1);\
#ifndef __rcu_dereference_index_check
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0))
#define __rcu_dereference_index_check(p, c) \
typeof(p) _________p1 = ACCESS_ONCE(p); \
"suspicious rcu_dereference_index_check()" \
smp_read_barrier_depends(); \
#define __rcu_dereference_index_check(p, c) \
typeof(p) _________p1 = ACCESS_ONCE(p); \
"suspicious rcu_dereference_index_check()" \
smp_read_barrier_depends(); \
VHOST_FEATURES
= (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY
) |
(1ULL << VIRTIO_RING_F_INDIRECT_DESC
) |
(1ULL << VIRTIO_RING_F_EVENT_IDX
) |
(1ULL << VHOST_F_LOG_ALL
) |
(1ULL << VHOST_NET_F_VIRTIO_NET_HDR
) |
(1ULL << VIRTIO_NET_F_MRG_RXBUF
),
static inline int vhost_has_feature(struct vhost_dev
*dev
, int bit
)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
unsigned acked_features
= rcu_dereference_index_check(dev
->acked_features
, rcu_read_lock_held());
unsigned acked_features
= rcu_dereference(dev
->acked_features
);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0))
unsigned acked_features
= rcu_dereference_index_check(dev
->acked_features
, rcu_read_lock_held());
unsigned acked_features
= __rcu_dereference_index_check(dev
->acked_features
, rcu_read_lock_held());
return acked_features
& (1 << bit
);
void vhost_enable_zcopy(int vq
);