aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/vhost.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vhost/vhost.h')
-rw-r--r--drivers/vhost/vhost.h38
1 files changed, 25 insertions, 13 deletions
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 11ee13dba0f7..3693327549b3 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -5,13 +5,13 @@
5#include <linux/vhost.h> 5#include <linux/vhost.h>
6#include <linux/mm.h> 6#include <linux/mm.h>
7#include <linux/mutex.h> 7#include <linux/mutex.h>
8#include <linux/workqueue.h>
9#include <linux/poll.h> 8#include <linux/poll.h>
10#include <linux/file.h> 9#include <linux/file.h>
11#include <linux/skbuff.h> 10#include <linux/skbuff.h>
12#include <linux/uio.h> 11#include <linux/uio.h>
13#include <linux/virtio_config.h> 12#include <linux/virtio_config.h>
14#include <linux/virtio_ring.h> 13#include <linux/virtio_ring.h>
14#include <asm/atomic.h>
15 15
16struct vhost_device; 16struct vhost_device;
17 17
@@ -20,19 +20,31 @@ enum {
20 VHOST_NET_MAX_SG = MAX_SKB_FRAGS + 2, 20 VHOST_NET_MAX_SG = MAX_SKB_FRAGS + 2,
21}; 21};
22 22
23struct vhost_work;
24typedef void (*vhost_work_fn_t)(struct vhost_work *work);
25
26struct vhost_work {
27 struct list_head node;
28 vhost_work_fn_t fn;
29 wait_queue_head_t done;
30 int flushing;
31 unsigned queue_seq;
32 unsigned done_seq;
33};
34
23/* Poll a file (eventfd or socket) */ 35/* Poll a file (eventfd or socket) */
24/* Note: there's nothing vhost specific about this structure. */ 36/* Note: there's nothing vhost specific about this structure. */
25struct vhost_poll { 37struct vhost_poll {
26 poll_table table; 38 poll_table table;
27 wait_queue_head_t *wqh; 39 wait_queue_head_t *wqh;
28 wait_queue_t wait; 40 wait_queue_t wait;
29 /* struct which will handle all actual work. */ 41 struct vhost_work work;
30 struct work_struct work;
31 unsigned long mask; 42 unsigned long mask;
43 struct vhost_dev *dev;
32}; 44};
33 45
34void vhost_poll_init(struct vhost_poll *poll, work_func_t func, 46void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
35 unsigned long mask); 47 unsigned long mask, struct vhost_dev *dev);
36void vhost_poll_start(struct vhost_poll *poll, struct file *file); 48void vhost_poll_start(struct vhost_poll *poll, struct file *file);
37void vhost_poll_stop(struct vhost_poll *poll); 49void vhost_poll_stop(struct vhost_poll *poll);
38void vhost_poll_flush(struct vhost_poll *poll); 50void vhost_poll_flush(struct vhost_poll *poll);
@@ -63,7 +75,7 @@ struct vhost_virtqueue {
63 struct vhost_poll poll; 75 struct vhost_poll poll;
64 76
65 /* The routine to call when the Guest pings us, or timeout. */ 77 /* The routine to call when the Guest pings us, or timeout. */
66 work_func_t handle_kick; 78 vhost_work_fn_t handle_kick;
67 79
68 /* Last available index we saw. */ 80 /* Last available index we saw. */
69 u16 last_avail_idx; 81 u16 last_avail_idx;
@@ -86,11 +98,11 @@ struct vhost_virtqueue {
86 struct iovec hdr[VHOST_NET_MAX_SG]; 98 struct iovec hdr[VHOST_NET_MAX_SG];
87 size_t hdr_size; 99 size_t hdr_size;
88 /* We use a kind of RCU to access private pointer. 100 /* We use a kind of RCU to access private pointer.
89 * All readers access it from workqueue, which makes it possible to 101 * All readers access it from worker, which makes it possible to
90 * flush the workqueue instead of synchronize_rcu. Therefore readers do 102 * flush the vhost_work instead of synchronize_rcu. Therefore readers do
91 * not need to call rcu_read_lock/rcu_read_unlock: the beginning of 103 * not need to call rcu_read_lock/rcu_read_unlock: the beginning of
92 * work item execution acts instead of rcu_read_lock() and the end of 104 * vhost_work execution acts instead of rcu_read_lock() and the end of
93 * work item execution acts instead of rcu_read_lock(). 105 * vhost_work execution acts instead of rcu_read_lock().
94 * Writers use virtqueue mutex. */ 106 * Writers use virtqueue mutex. */
95 void *private_data; 107 void *private_data;
96 /* Log write descriptors */ 108 /* Log write descriptors */
@@ -110,6 +122,9 @@ struct vhost_dev {
110 int nvqs; 122 int nvqs;
111 struct file *log_file; 123 struct file *log_file;
112 struct eventfd_ctx *log_ctx; 124 struct eventfd_ctx *log_ctx;
125 spinlock_t work_lock;
126 struct list_head work_list;
127 struct task_struct *worker;
113}; 128};
114 129
115long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue *vqs, int nvqs); 130long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue *vqs, int nvqs);
@@ -136,9 +151,6 @@ bool vhost_enable_notify(struct vhost_virtqueue *);
136int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, 151int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
137 unsigned int log_num, u64 len); 152 unsigned int log_num, u64 len);
138 153
139int vhost_init(void);
140void vhost_cleanup(void);
141
142#define vq_err(vq, fmt, ...) do { \ 154#define vq_err(vq, fmt, ...) do { \
143 pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ 155 pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
144 if ((vq)->error_ctx) \ 156 if ((vq)->error_ctx) \