diff options
Diffstat (limited to 'drivers/vhost/vhost.h')
-rw-r--r-- | drivers/vhost/vhost.h | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 11ee13dba0f7..afd77295971c 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 | ||
16 | struct vhost_device; | 16 | struct 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 | ||
23 | struct vhost_work; | ||
24 | typedef void (*vhost_work_fn_t)(struct vhost_work *work); | ||
25 | |||
26 | struct 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. */ |
25 | struct vhost_poll { | 37 | struct 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 | ||
34 | void vhost_poll_init(struct vhost_poll *poll, work_func_t func, | 46 | void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, |
35 | unsigned long mask); | 47 | unsigned long mask, struct vhost_dev *dev); |
36 | void vhost_poll_start(struct vhost_poll *poll, struct file *file); | 48 | void vhost_poll_start(struct vhost_poll *poll, struct file *file); |
37 | void vhost_poll_stop(struct vhost_poll *poll); | 49 | void vhost_poll_stop(struct vhost_poll *poll); |
38 | void vhost_poll_flush(struct vhost_poll *poll); | 50 | void 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; |
@@ -84,13 +96,15 @@ struct vhost_virtqueue { | |||
84 | struct iovec indirect[VHOST_NET_MAX_SG]; | 96 | struct iovec indirect[VHOST_NET_MAX_SG]; |
85 | struct iovec iov[VHOST_NET_MAX_SG]; | 97 | struct iovec iov[VHOST_NET_MAX_SG]; |
86 | struct iovec hdr[VHOST_NET_MAX_SG]; | 98 | struct iovec hdr[VHOST_NET_MAX_SG]; |
87 | size_t hdr_size; | 99 | size_t vhost_hlen; |
100 | size_t sock_hlen; | ||
101 | struct vring_used_elem heads[VHOST_NET_MAX_SG]; | ||
88 | /* We use a kind of RCU to access private pointer. | 102 | /* We use a kind of RCU to access private pointer. |
89 | * All readers access it from workqueue, which makes it possible to | 103 | * All readers access it from worker, which makes it possible to |
90 | * flush the workqueue instead of synchronize_rcu. Therefore readers do | 104 | * 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 | 105 | * 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 | 106 | * vhost_work execution acts instead of rcu_read_lock() and the end of |
93 | * work item execution acts instead of rcu_read_lock(). | 107 | * vhost_work execution acts instead of rcu_read_lock(). |
94 | * Writers use virtqueue mutex. */ | 108 | * Writers use virtqueue mutex. */ |
95 | void *private_data; | 109 | void *private_data; |
96 | /* Log write descriptors */ | 110 | /* Log write descriptors */ |
@@ -110,6 +124,9 @@ struct vhost_dev { | |||
110 | int nvqs; | 124 | int nvqs; |
111 | struct file *log_file; | 125 | struct file *log_file; |
112 | struct eventfd_ctx *log_ctx; | 126 | struct eventfd_ctx *log_ctx; |
127 | spinlock_t work_lock; | ||
128 | struct list_head work_list; | ||
129 | struct task_struct *worker; | ||
113 | }; | 130 | }; |
114 | 131 | ||
115 | long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue *vqs, int nvqs); | 132 | long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue *vqs, int nvqs); |
@@ -124,21 +141,22 @@ int vhost_get_vq_desc(struct vhost_dev *, struct vhost_virtqueue *, | |||
124 | struct iovec iov[], unsigned int iov_count, | 141 | struct iovec iov[], unsigned int iov_count, |
125 | unsigned int *out_num, unsigned int *in_num, | 142 | unsigned int *out_num, unsigned int *in_num, |
126 | struct vhost_log *log, unsigned int *log_num); | 143 | struct vhost_log *log, unsigned int *log_num); |
127 | void vhost_discard_vq_desc(struct vhost_virtqueue *); | 144 | void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); |
128 | 145 | ||
129 | int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len); | 146 | int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len); |
130 | void vhost_signal(struct vhost_dev *, struct vhost_virtqueue *); | 147 | int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads, |
148 | unsigned count); | ||
131 | void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *, | 149 | void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *, |
132 | unsigned int head, int len); | 150 | unsigned int id, int len); |
151 | void vhost_add_used_and_signal_n(struct vhost_dev *, struct vhost_virtqueue *, | ||
152 | struct vring_used_elem *heads, unsigned count); | ||
153 | void vhost_signal(struct vhost_dev *, struct vhost_virtqueue *); | ||
133 | void vhost_disable_notify(struct vhost_virtqueue *); | 154 | void vhost_disable_notify(struct vhost_virtqueue *); |
134 | bool vhost_enable_notify(struct vhost_virtqueue *); | 155 | bool vhost_enable_notify(struct vhost_virtqueue *); |
135 | 156 | ||
136 | int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, | 157 | int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, |
137 | unsigned int log_num, u64 len); | 158 | unsigned int log_num, u64 len); |
138 | 159 | ||
139 | int vhost_init(void); | ||
140 | void vhost_cleanup(void); | ||
141 | |||
142 | #define vq_err(vq, fmt, ...) do { \ | 160 | #define vq_err(vq, fmt, ...) do { \ |
143 | pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ | 161 | pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ |
144 | if ((vq)->error_ctx) \ | 162 | if ((vq)->error_ctx) \ |
@@ -149,7 +167,8 @@ enum { | |||
149 | VHOST_FEATURES = (1 << VIRTIO_F_NOTIFY_ON_EMPTY) | | 167 | VHOST_FEATURES = (1 << VIRTIO_F_NOTIFY_ON_EMPTY) | |
150 | (1 << VIRTIO_RING_F_INDIRECT_DESC) | | 168 | (1 << VIRTIO_RING_F_INDIRECT_DESC) | |
151 | (1 << VHOST_F_LOG_ALL) | | 169 | (1 << VHOST_F_LOG_ALL) | |
152 | (1 << VHOST_NET_F_VIRTIO_NET_HDR), | 170 | (1 << VHOST_NET_F_VIRTIO_NET_HDR) | |
171 | (1 << VIRTIO_NET_F_MRG_RXBUF), | ||
153 | }; | 172 | }; |
154 | 173 | ||
155 | static inline int vhost_has_feature(struct vhost_dev *dev, int bit) | 174 | static inline int vhost_has_feature(struct vhost_dev *dev, int bit) |