hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/vhost/vhost.h
....@@ -12,6 +12,8 @@
1212 #include <linux/virtio_config.h>
1313 #include <linux/virtio_ring.h>
1414 #include <linux/atomic.h>
15
+#include <linux/vhost_iotlb.h>
16
+#include <linux/irqbypass.h>
1517
1618 struct vhost_work;
1719 typedef void (*vhost_work_fn_t)(struct vhost_work *work);
....@@ -52,32 +54,16 @@
5254 u64 len;
5355 };
5456
55
-#define START(node) ((node)->start)
56
-#define LAST(node) ((node)->last)
57
-
58
-struct vhost_umem_node {
59
- struct rb_node rb;
60
- struct list_head link;
61
- __u64 start;
62
- __u64 last;
63
- __u64 size;
64
- __u64 userspace_addr;
65
- __u32 perm;
66
- __u32 flags_padding;
67
- __u64 __subtree_last;
68
-};
69
-
70
-struct vhost_umem {
71
- struct rb_root_cached umem_tree;
72
- struct list_head umem_list;
73
- int numem;
74
-};
75
-
7657 enum vhost_uaddr_type {
7758 VHOST_ADDR_DESC = 0,
7859 VHOST_ADDR_AVAIL = 1,
7960 VHOST_ADDR_USED = 2,
8061 VHOST_NUM_ADDRS = 3,
62
+};
63
+
64
+struct vhost_vring_call {
65
+ struct eventfd_ctx *ctx;
66
+ struct irq_bypass_producer producer;
8167 };
8268
8369 /* The virtqueue structure describes a queue attached to a device. */
....@@ -87,12 +73,12 @@
8773 /* The actual ring of buffers. */
8874 struct mutex mutex;
8975 unsigned int num;
90
- struct vring_desc __user *desc;
91
- struct vring_avail __user *avail;
92
- struct vring_used __user *used;
93
- const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS];
76
+ vring_desc_t __user *desc;
77
+ vring_avail_t __user *avail;
78
+ vring_used_t __user *used;
79
+ const struct vhost_iotlb_map *meta_iotlb[VHOST_NUM_ADDRS];
9480 struct file *kick;
95
- struct eventfd_ctx *call_ctx;
81
+ struct vhost_vring_call call_ctx;
9682 struct eventfd_ctx *error_ctx;
9783 struct eventfd_ctx *log_ctx;
9884
....@@ -101,13 +87,17 @@
10187 /* The routine to call when the Guest pings us, or timeout. */
10288 vhost_work_fn_t handle_kick;
10389
104
- /* Last available index we saw. */
90
+ /* Last available index we saw.
91
+ * Values are limited to 0x7fff, and the high bit is used as
92
+ * a wrap counter when using VIRTIO_F_RING_PACKED. */
10593 u16 last_avail_idx;
10694
10795 /* Caches available index value from user. */
10896 u16 avail_idx;
10997
110
- /* Last index we used. */
98
+ /* Last index we used.
99
+ * Values are limited to 0x7fff, and the high bit is used as
100
+ * a wrap counter when using VIRTIO_F_RING_PACKED. */
111101 u16 last_used_idx;
112102
113103 /* Used flags */
....@@ -128,14 +118,15 @@
128118 struct iovec *indirect;
129119 struct vring_used_elem *heads;
130120 /* Protected by virtqueue mutex. */
131
- struct vhost_umem *umem;
132
- struct vhost_umem *iotlb;
121
+ struct vhost_iotlb *umem;
122
+ struct vhost_iotlb *iotlb;
133123 void *private_data;
134124 u64 acked_features;
135125 u64 acked_backend_features;
136126 /* Log write descriptors */
137127 void __user *log_base;
138128 struct vhost_log *log;
129
+ struct iovec log_iov[64];
139130
140131 /* Ring endianness. Defaults to legacy native endianness.
141132 * Set to true when starting a modern virtio device. */
....@@ -164,8 +155,8 @@
164155 struct eventfd_ctx *log_ctx;
165156 struct llist_head work_list;
166157 struct task_struct *worker;
167
- struct vhost_umem *umem;
168
- struct vhost_umem *iotlb;
158
+ struct vhost_iotlb *umem;
159
+ struct vhost_iotlb *iotlb;
169160 spinlock_t iotlb_lock;
170161 struct list_head read_list;
171162 struct list_head pending_list;
....@@ -174,22 +165,29 @@
174165 int weight;
175166 int byte_weight;
176167 u64 kcov_handle;
168
+ bool use_worker;
169
+ int (*msg_handler)(struct vhost_dev *dev,
170
+ struct vhost_iotlb_msg *msg);
177171 };
178172
179173 bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);
180174 void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs,
181
- int nvqs, int iov_limit, int weight, int byte_weight);
175
+ int nvqs, int iov_limit, int weight, int byte_weight,
176
+ bool use_worker,
177
+ int (*msg_handler)(struct vhost_dev *dev,
178
+ struct vhost_iotlb_msg *msg));
182179 long vhost_dev_set_owner(struct vhost_dev *dev);
183180 bool vhost_dev_has_owner(struct vhost_dev *dev);
184181 long vhost_dev_check_owner(struct vhost_dev *);
185
-struct vhost_umem *vhost_dev_reset_owner_prepare(void);
186
-void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_umem *);
182
+struct vhost_iotlb *vhost_dev_reset_owner_prepare(void);
183
+void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *iotlb);
187184 void vhost_dev_cleanup(struct vhost_dev *);
188185 void vhost_dev_stop(struct vhost_dev *);
189186 long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
190187 long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp);
191188 bool vhost_vq_access_ok(struct vhost_virtqueue *vq);
192189 bool vhost_log_access_ok(struct vhost_dev *);
190
+void vhost_clear_msg(struct vhost_dev *dev);
193191
194192 int vhost_get_vq_desc(struct vhost_virtqueue *,
195193 struct iovec iov[], unsigned int iov_count,
....@@ -197,6 +195,7 @@
197195 struct vhost_log *log, unsigned int *log_num);
198196 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
199197
198
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
200199 int vhost_vq_init_access(struct vhost_virtqueue *);
201200 int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
202201 int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
....@@ -213,7 +212,7 @@
213212 int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
214213 unsigned int log_num, u64 len,
215214 struct iovec *iov, int count);
216
-int vq_iotlb_prefetch(struct vhost_virtqueue *vq);
215
+int vq_meta_prefetch(struct vhost_virtqueue *vq);
217216
218217 struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type);
219218 void vhost_enqueue_msg(struct vhost_dev *dev,
....@@ -221,6 +220,8 @@
221220 struct vhost_msg_node *node);
222221 struct vhost_msg_node *vhost_dequeue_msg(struct vhost_dev *dev,
223222 struct list_head *head);
223
+void vhost_set_backend_features(struct vhost_dev *dev, u64 features);
224
+
224225 __poll_t vhost_chr_poll(struct file *file, struct vhost_dev *dev,
225226 poll_table *wait);
226227 ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
....@@ -228,6 +229,9 @@
228229 ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
229230 struct iov_iter *from);
230231 int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
232
+
233
+void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
234
+ struct vhost_iotlb_map *map);
231235
232236 #define vq_err(vq, fmt, ...) do { \
233237 pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
....@@ -244,6 +248,33 @@
244248 (1ULL << VIRTIO_F_VERSION_1)
245249 };
246250
251
+/**
252
+ * vhost_vq_set_backend - Set backend.
253
+ *
254
+ * @vq Virtqueue.
255
+ * @private_data The private data.
256
+ *
257
+ * Context: Need to call with vq->mutex acquired.
258
+ */
259
+static inline void vhost_vq_set_backend(struct vhost_virtqueue *vq,
260
+ void *private_data)
261
+{
262
+ vq->private_data = private_data;
263
+}
264
+
265
+/**
266
+ * vhost_vq_get_backend - Get backend.
267
+ *
268
+ * @vq Virtqueue.
269
+ *
270
+ * Context: Need to call with vq->mutex acquired.
271
+ * Return: Private data previously set with vhost_vq_set_backend.
272
+ */
273
+static inline void *vhost_vq_get_backend(struct vhost_virtqueue *vq)
274
+{
275
+ return vq->private_data;
276
+}
277
+
247278 static inline bool vhost_has_feature(struct vhost_virtqueue *vq, int bit)
248279 {
249280 return vq->acked_features & (1ULL << bit);