vhost: add vring address setup for packed queues
[dpdk.git] / lib / librte_vhost / vhost.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _VHOST_NET_CDEV_H_
6 #define _VHOST_NET_CDEV_H_
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdbool.h>
10 #include <sys/types.h>
11 #include <sys/queue.h>
12 #include <unistd.h>
13 #include <linux/vhost.h>
14 #include <linux/virtio_net.h>
15 #include <sys/socket.h>
16 #include <linux/if.h>
17
18 #include <rte_log.h>
19 #include <rte_ether.h>
20 #include <rte_rwlock.h>
21
22 #include "rte_vhost.h"
23 #include "rte_vdpa.h"
24
25 /* Used to indicate that the device is running on a data core */
26 #define VIRTIO_DEV_RUNNING 1
27 /* Used to indicate that the device is ready to operate */
28 #define VIRTIO_DEV_READY 2
29 /* Used to indicate that the built-in vhost net device backend is enabled */
30 #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
31 /* Used to indicate that the device has its own data path and configured */
32 #define VIRTIO_DEV_VDPA_CONFIGURED 8
33
34 /* Backend value set by guest. */
35 #define VIRTIO_DEV_STOPPED -1
36
37 #define BUF_VECTOR_MAX 256
38
39 #define VHOST_LOG_CACHE_NR 32
40
41 /**
42  * Structure contains buffer address, length and descriptor index
43  * from vring to do scatter RX.
44  */
45 struct buf_vector {
46         uint64_t buf_iova;
47         uint64_t buf_addr;
48         uint32_t buf_len;
49         uint32_t desc_idx;
50 };
51
52 /*
53  * A structure to hold some fields needed in zero copy code path,
54  * mainly for associating an mbuf with the right desc_idx.
55  */
56 struct zcopy_mbuf {
57         struct rte_mbuf *mbuf;
58         uint32_t desc_idx;
59         uint16_t in_use;
60
61         TAILQ_ENTRY(zcopy_mbuf) next;
62 };
63 TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
64
65 /*
66  * Structure contains the info for each batched memory copy.
67  */
68 struct batch_copy_elem {
69         void *dst;
70         void *src;
71         uint32_t len;
72         uint64_t log_addr;
73 };
74
75 /*
76  * Structure that contains the info for batched dirty logging.
77  */
78 struct log_cache_entry {
79         uint32_t offset;
80         unsigned long val;
81 };
82
83 /**
84  * Structure contains variables relevant to RX/TX virtqueues.
85  */
86 struct vhost_virtqueue {
87         union {
88                 struct vring_desc       *desc;
89                 struct vring_packed_desc   *desc_packed;
90         };
91         struct vring_avail      *avail;
92         struct vring_used       *used;
93         uint32_t                size;
94
95         uint16_t                last_avail_idx;
96         uint16_t                last_used_idx;
97         /* Last used index we notify to front end. */
98         uint16_t                signalled_used;
99 #define VIRTIO_INVALID_EVENTFD          (-1)
100 #define VIRTIO_UNINITIALIZED_EVENTFD    (-2)
101
102         /* Backend value to determine if device should started/stopped */
103         int                     backend;
104         int                     enabled;
105         int                     access_ok;
106         rte_spinlock_t          access_lock;
107
108         /* Used to notify the guest (trigger interrupt) */
109         int                     callfd;
110         /* Currently unused as polling mode is enabled */
111         int                     kickfd;
112
113         /* Physical address of used ring, for logging */
114         uint64_t                log_guest_addr;
115
116         uint16_t                nr_zmbuf;
117         uint16_t                zmbuf_size;
118         uint16_t                last_zmbuf_idx;
119         struct zcopy_mbuf       *zmbufs;
120         struct zcopy_mbuf_list  zmbuf_list;
121
122         struct vring_used_elem  *shadow_used_ring;
123         uint16_t                shadow_used_idx;
124         struct vhost_vring_addr ring_addrs;
125
126         struct batch_copy_elem  *batch_copy_elems;
127         uint16_t                batch_copy_nb_elems;
128         bool                    used_wrap_counter;
129         bool                    avail_wrap_counter;
130
131         struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
132         uint16_t log_cache_nb_elem;
133
134         rte_rwlock_t    iotlb_lock;
135         rte_rwlock_t    iotlb_pending_lock;
136         struct rte_mempool *iotlb_pool;
137         TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
138         int                             iotlb_cache_nr;
139         TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
140 } __rte_cache_aligned;
141
142 /* Old kernels have no such macros defined */
143 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
144  #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
145 #endif
146
147 #ifndef VIRTIO_NET_F_MQ
148  #define VIRTIO_NET_F_MQ                22
149 #endif
150
151 #define VHOST_MAX_VRING                 0x100
152 #define VHOST_MAX_QUEUE_PAIRS           0x80
153
154 #ifndef VIRTIO_NET_F_MTU
155  #define VIRTIO_NET_F_MTU 3
156 #endif
157
158 #ifndef VIRTIO_F_ANY_LAYOUT
159  #define VIRTIO_F_ANY_LAYOUT            27
160 #endif
161
162 /* Declare IOMMU related bits for older kernels */
163 #ifndef VIRTIO_F_IOMMU_PLATFORM
164
165 #define VIRTIO_F_IOMMU_PLATFORM 33
166
167 struct vhost_iotlb_msg {
168         __u64 iova;
169         __u64 size;
170         __u64 uaddr;
171 #define VHOST_ACCESS_RO      0x1
172 #define VHOST_ACCESS_WO      0x2
173 #define VHOST_ACCESS_RW      0x3
174         __u8 perm;
175 #define VHOST_IOTLB_MISS           1
176 #define VHOST_IOTLB_UPDATE         2
177 #define VHOST_IOTLB_INVALIDATE     3
178 #define VHOST_IOTLB_ACCESS_FAIL    4
179         __u8 type;
180 };
181
182 #define VHOST_IOTLB_MSG 0x1
183
184 struct vhost_msg {
185         int type;
186         union {
187                 struct vhost_iotlb_msg iotlb;
188                 __u8 padding[64];
189         };
190 };
191 #endif
192
193 /*
194  * Define virtio 1.0 for older kernels
195  */
196 #ifndef VIRTIO_F_VERSION_1
197  #define VIRTIO_F_VERSION_1 32
198 #endif
199
200 /* Declare packed ring related bits for older kernels */
201 #ifndef VIRTIO_F_RING_PACKED
202
203 #define VIRTIO_F_RING_PACKED 34
204
205 #define VRING_DESC_F_NEXT       1
206 #define VRING_DESC_F_WRITE      2
207 #define VRING_DESC_F_INDIRECT   4
208
209 #define VRING_DESC_F_AVAIL      (1ULL << 7)
210 #define VRING_DESC_F_USED       (1ULL << 15)
211
212 struct vring_packed_desc {
213         uint64_t addr;
214         uint32_t len;
215         uint16_t id;
216         uint16_t flags;
217 };
218 #endif
219
220 /*
221  * Available and used descs are in same order
222  */
223 #ifndef VIRTIO_F_IN_ORDER
224 #define VIRTIO_F_IN_ORDER      35
225 #endif
226
227 /* Features supported by this builtin vhost-user net driver. */
228 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
229                                 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
230                                 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
231                                 (1ULL << VIRTIO_NET_F_CTRL_RX) | \
232                                 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
233                                 (1ULL << VIRTIO_NET_F_MQ)      | \
234                                 (1ULL << VIRTIO_F_VERSION_1)   | \
235                                 (1ULL << VHOST_F_LOG_ALL)      | \
236                                 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
237                                 (1ULL << VIRTIO_NET_F_GSO) | \
238                                 (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
239                                 (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
240                                 (1ULL << VIRTIO_NET_F_HOST_UFO) | \
241                                 (1ULL << VIRTIO_NET_F_HOST_ECN) | \
242                                 (1ULL << VIRTIO_NET_F_CSUM)    | \
243                                 (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
244                                 (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
245                                 (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
246                                 (1ULL << VIRTIO_NET_F_GUEST_UFO) | \
247                                 (1ULL << VIRTIO_NET_F_GUEST_ECN) | \
248                                 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
249                                 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \
250                                 (1ULL << VIRTIO_NET_F_MTU)  | \
251                                 (1ULL << VIRTIO_F_IN_ORDER) | \
252                                 (1ULL << VIRTIO_F_IOMMU_PLATFORM))
253
254
255 struct guest_page {
256         uint64_t guest_phys_addr;
257         uint64_t host_phys_addr;
258         uint64_t size;
259 };
260
261 /**
262  * function prototype for the vhost backend to handler specific vhost user
263  * messages prior to the master message handling
264  *
265  * @param vid
266  *  vhost device id
267  * @param msg
268  *  Message pointer.
269  * @param require_reply
270  *  If the handler requires sending a reply, this varaible shall be written 1,
271  *  otherwise 0.
272  * @param skip_master
273  *  If the handler requires skipping the master message handling, this variable
274  *  shall be written 1, otherwise 0.
275  * @return
276  *  0 on success, -1 on failure
277  */
278 typedef int (*vhost_msg_pre_handle)(int vid, void *msg,
279                 uint32_t *require_reply, uint32_t *skip_master);
280
281 /**
282  * function prototype for the vhost backend to handler specific vhost user
283  * messages after the master message handling is done
284  *
285  * @param vid
286  *  vhost device id
287  * @param msg
288  *  Message pointer.
289  * @param require_reply
290  *  If the handler requires sending a reply, this varaible shall be written 1,
291  *  otherwise 0.
292  * @return
293  *  0 on success, -1 on failure
294  */
295 typedef int (*vhost_msg_post_handle)(int vid, void *msg,
296                 uint32_t *require_reply);
297
298 /**
299  * pre and post vhost user message handlers
300  */
301 struct vhost_user_extern_ops {
302         vhost_msg_pre_handle pre_msg_handle;
303         vhost_msg_post_handle post_msg_handle;
304 };
305
306 /**
307  * Device structure contains all configuration information relating
308  * to the device.
309  */
310 struct virtio_net {
311         /* Frontend (QEMU) memory and memory region information */
312         struct rte_vhost_memory *mem;
313         uint64_t                features;
314         uint64_t                protocol_features;
315         int                     vid;
316         uint32_t                flags;
317         uint16_t                vhost_hlen;
318         /* to tell if we need broadcast rarp packet */
319         rte_atomic16_t          broadcast_rarp;
320         uint32_t                nr_vring;
321         int                     dequeue_zero_copy;
322         struct vhost_virtqueue  *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
323 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
324         char                    ifname[IF_NAME_SZ];
325         uint64_t                log_size;
326         uint64_t                log_base;
327         uint64_t                log_addr;
328         struct ether_addr       mac;
329         uint16_t                mtu;
330
331         struct vhost_device_ops const *notify_ops;
332
333         uint32_t                nr_guest_pages;
334         uint32_t                max_guest_pages;
335         struct guest_page       *guest_pages;
336
337         int                     slave_req_fd;
338         rte_spinlock_t          slave_req_lock;
339
340         /*
341          * Device id to identify a specific backend device.
342          * It's set to -1 for the default software implementation.
343          */
344         int                     vdpa_dev_id;
345
346         /* private data for virtio device */
347         void                    *extern_data;
348         /* pre and post vhost user message handlers for the device */
349         struct vhost_user_extern_ops extern_ops;
350 } __rte_cache_aligned;
351
352 static __rte_always_inline bool
353 vq_is_packed(struct virtio_net *dev)
354 {
355         return dev->features & (1ull << VIRTIO_F_RING_PACKED);
356 }
357
358 static inline bool
359 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
360 {
361         return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL) &&
362                 wrap_counter != !!(desc->flags & VRING_DESC_F_USED);
363 }
364
365 #define VHOST_LOG_PAGE  4096
366
367 /*
368  * Atomically set a bit in memory.
369  */
370 static __rte_always_inline void
371 vhost_set_bit(unsigned int nr, volatile uint8_t *addr)
372 {
373 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION < 70100)
374         /*
375          * __sync_ built-ins are deprecated, but __atomic_ ones
376          * are sub-optimized in older GCC versions.
377          */
378         __sync_fetch_and_or_1(addr, (1U << nr));
379 #else
380         __atomic_fetch_or(addr, (1U << nr), __ATOMIC_RELAXED);
381 #endif
382 }
383
384 static __rte_always_inline void
385 vhost_log_page(uint8_t *log_base, uint64_t page)
386 {
387         vhost_set_bit(page % 8, &log_base[page / 8]);
388 }
389
390 static __rte_always_inline void
391 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
392 {
393         uint64_t page;
394
395         if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
396                    !dev->log_base || !len))
397                 return;
398
399         if (unlikely(dev->log_size <= ((addr + len - 1) / VHOST_LOG_PAGE / 8)))
400                 return;
401
402         /* To make sure guest memory updates are committed before logging */
403         rte_smp_wmb();
404
405         page = addr / VHOST_LOG_PAGE;
406         while (page * VHOST_LOG_PAGE < addr + len) {
407                 vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page);
408                 page += 1;
409         }
410 }
411
412 static __rte_always_inline void
413 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
414 {
415         unsigned long *log_base;
416         int i;
417
418         if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
419                    !dev->log_base))
420                 return;
421
422         log_base = (unsigned long *)(uintptr_t)dev->log_base;
423
424         /*
425          * It is expected a write memory barrier has been issued
426          * before this function is called.
427          */
428
429         for (i = 0; i < vq->log_cache_nb_elem; i++) {
430                 struct log_cache_entry *elem = vq->log_cache + i;
431
432 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION < 70100)
433                 /*
434                  * '__sync' builtins are deprecated, but '__atomic' ones
435                  * are sub-optimized in older GCC versions.
436                  */
437                 __sync_fetch_and_or(log_base + elem->offset, elem->val);
438 #else
439                 __atomic_fetch_or(log_base + elem->offset, elem->val,
440                                 __ATOMIC_RELAXED);
441 #endif
442         }
443
444         rte_smp_wmb();
445
446         vq->log_cache_nb_elem = 0;
447 }
448
449 static __rte_always_inline void
450 vhost_log_cache_page(struct virtio_net *dev, struct vhost_virtqueue *vq,
451                         uint64_t page)
452 {
453         uint32_t bit_nr = page % (sizeof(unsigned long) << 3);
454         uint32_t offset = page / (sizeof(unsigned long) << 3);
455         int i;
456
457         for (i = 0; i < vq->log_cache_nb_elem; i++) {
458                 struct log_cache_entry *elem = vq->log_cache + i;
459
460                 if (elem->offset == offset) {
461                         elem->val |= (1UL << bit_nr);
462                         return;
463                 }
464         }
465
466         if (unlikely(i >= VHOST_LOG_CACHE_NR)) {
467                 /*
468                  * No more room for a new log cache entry,
469                  * so write the dirty log map directly.
470                  */
471                 rte_smp_wmb();
472                 vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page);
473
474                 return;
475         }
476
477         vq->log_cache[i].offset = offset;
478         vq->log_cache[i].val = (1UL << bit_nr);
479         vq->log_cache_nb_elem++;
480 }
481
482 static __rte_always_inline void
483 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
484                         uint64_t addr, uint64_t len)
485 {
486         uint64_t page;
487
488         if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) ||
489                    !dev->log_base || !len))
490                 return;
491
492         if (unlikely(dev->log_size <= ((addr + len - 1) / VHOST_LOG_PAGE / 8)))
493                 return;
494
495         page = addr / VHOST_LOG_PAGE;
496         while (page * VHOST_LOG_PAGE < addr + len) {
497                 vhost_log_cache_page(dev, vq, page);
498                 page += 1;
499         }
500 }
501
502 static __rte_always_inline void
503 vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
504                         uint64_t offset, uint64_t len)
505 {
506         vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset, len);
507 }
508
509 static __rte_always_inline void
510 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
511                      uint64_t offset, uint64_t len)
512 {
513         vhost_log_write(dev, vq->log_guest_addr + offset, len);
514 }
515
516 /* Macros for printing using RTE_LOG */
517 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
518 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
519
520 #ifdef RTE_LIBRTE_VHOST_DEBUG
521 #define VHOST_MAX_PRINT_BUFF 6072
522 #define VHOST_LOG_DEBUG(log_type, fmt, args...) \
523         RTE_LOG(DEBUG, log_type, fmt, ##args)
524 #define PRINT_PACKET(device, addr, size, header) do { \
525         char *pkt_addr = (char *)(addr); \
526         unsigned int index; \
527         char packet[VHOST_MAX_PRINT_BUFF]; \
528         \
529         if ((header)) \
530                 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
531         else \
532                 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
533         for (index = 0; index < (size); index++) { \
534                 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
535                         "%02hhx ", pkt_addr[index]); \
536         } \
537         snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
538         \
539         VHOST_LOG_DEBUG(VHOST_DATA, "%s", packet); \
540 } while (0)
541 #else
542 #define VHOST_LOG_DEBUG(log_type, fmt, args...) do {} while (0)
543 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
544 #endif
545
546 extern uint64_t VHOST_FEATURES;
547 #define MAX_VHOST_DEVICE        1024
548 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
549
550 /* Convert guest physical address to host physical address */
551 static __rte_always_inline rte_iova_t
552 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
553 {
554         uint32_t i;
555         struct guest_page *page;
556
557         for (i = 0; i < dev->nr_guest_pages; i++) {
558                 page = &dev->guest_pages[i];
559
560                 if (gpa >= page->guest_phys_addr &&
561                     gpa + size < page->guest_phys_addr + page->size) {
562                         return gpa - page->guest_phys_addr +
563                                page->host_phys_addr;
564                 }
565         }
566
567         return 0;
568 }
569
570 static __rte_always_inline struct virtio_net *
571 get_device(int vid)
572 {
573         struct virtio_net *dev = vhost_devices[vid];
574
575         if (unlikely(!dev)) {
576                 RTE_LOG(ERR, VHOST_CONFIG,
577                         "(%d) device not found.\n", vid);
578         }
579
580         return dev;
581 }
582
583 int vhost_new_device(void);
584 void cleanup_device(struct virtio_net *dev, int destroy);
585 void reset_device(struct virtio_net *dev);
586 void vhost_destroy_device(int);
587 void vhost_destroy_device_notify(struct virtio_net *dev);
588
589 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
590 void free_vq(struct vhost_virtqueue *vq);
591
592 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
593
594 void vhost_attach_vdpa_device(int vid, int did);
595 void vhost_detach_vdpa_device(int vid);
596
597 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
598 void vhost_enable_dequeue_zero_copy(int vid);
599 void vhost_set_builtin_virtio_net(int vid, bool enable);
600
601 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
602
603 /*
604  * Backend-specific cleanup.
605  *
606  * TODO: fix it; we have one backend now
607  */
608 void vhost_backend_cleanup(struct virtio_net *dev);
609
610 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
611                         uint64_t iova, uint64_t *len, uint8_t perm);
612 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
613 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
614
615 static __rte_always_inline uint64_t
616 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
617                         uint64_t iova, uint64_t *len, uint8_t perm)
618 {
619         if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
620                 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
621
622         return __vhost_iova_to_vva(dev, vq, iova, len, perm);
623 }
624
625 #define vhost_used_event(vr) \
626         (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
627
628 /*
629  * The following is used with VIRTIO_RING_F_EVENT_IDX.
630  * Assuming a given event_idx value from the other size, if we have
631  * just incremented index from old to new_idx, should we trigger an
632  * event?
633  */
634 static __rte_always_inline int
635 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
636 {
637         return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
638 }
639
640 static __rte_always_inline void
641 vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
642 {
643         /* Flush used->idx update before we read avail->flags. */
644         rte_smp_mb();
645
646         /* Don't kick guest if we don't reach index specified by guest. */
647         if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
648                 uint16_t old = vq->signalled_used;
649                 uint16_t new = vq->last_used_idx;
650
651                 VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
652                         __func__,
653                         vhost_used_event(vq),
654                         old, new);
655                 if (vhost_need_event(vhost_used_event(vq), new, old)
656                         && (vq->callfd >= 0)) {
657                         vq->signalled_used = vq->last_used_idx;
658                         eventfd_write(vq->callfd, (eventfd_t) 1);
659                 }
660         } else {
661                 /* Kick the guest if necessary. */
662                 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
663                                 && (vq->callfd >= 0))
664                         eventfd_write(vq->callfd, (eventfd_t)1);
665         }
666 }
667
668 #endif /* _VHOST_NET_CDEV_H_ */