1 // SPDX-License-Identifier: GPL-2.0
2 /* Simple test of virtio code, entirely in userpsace. */
6 #include <linux/kernel.h>
8 #include <linux/virtio.h>
9 #include <linux/vringh.h>
10 #include <linux/virtio_ring.h>
11 #include <linux/virtio_config.h>
12 #include <linux/uaccess.h>
13 #include <sys/types.h>
19 #define USER_MEM (1024*1024)
20 void *__user_addr_min
, *__user_addr_max
;
21 void *__kmalloc_fake
, *__kfree_ignore_start
, *__kfree_ignore_end
;
22 static u64 user_addr_offset
;
27 static bool never_notify_host(struct virtqueue
*vq
)
32 static void never_callback_guest(struct virtqueue
*vq
)
37 static bool getrange_iov(struct vringh
*vrh
, u64 addr
, struct vringh_range
*r
)
39 if (addr
< (u64
)(unsigned long)__user_addr_min
- user_addr_offset
)
41 if (addr
>= (u64
)(unsigned long)__user_addr_max
- user_addr_offset
)
44 r
->start
= (u64
)(unsigned long)__user_addr_min
- user_addr_offset
;
45 r
->end_incl
= (u64
)(unsigned long)__user_addr_max
- 1 - user_addr_offset
;
46 r
->offset
= user_addr_offset
;
50 /* We return single byte ranges. */
51 static bool getrange_slow(struct vringh
*vrh
, u64 addr
, struct vringh_range
*r
)
53 if (addr
< (u64
)(unsigned long)__user_addr_min
- user_addr_offset
)
55 if (addr
>= (u64
)(unsigned long)__user_addr_max
- user_addr_offset
)
59 r
->end_incl
= r
->start
;
60 r
->offset
= user_addr_offset
;
64 struct guest_virtio_device
{
65 struct virtio_device vdev
;
67 unsigned long notifies
;
70 static bool parallel_notify_host(struct virtqueue
*vq
)
73 struct guest_virtio_device
*gvdev
;
75 gvdev
= container_of(vq
->vdev
, struct guest_virtio_device
, vdev
);
76 rc
= write(gvdev
->to_host_fd
, "", 1);
83 static bool no_notify_host(struct virtqueue
*vq
)
88 #define NUM_XFERS (10000000)
90 /* We aim for two "distant" cpus. */
91 static void find_cpus(unsigned int *first
, unsigned int *last
)
97 for (i
= 0; i
< 4096; i
++) {
101 if (sched_setaffinity(getpid(), sizeof(set
), &set
) == 0) {
110 /* Opencoded version for fast mode */
111 static inline int vringh_get_head(struct vringh
*vrh
, u16
*head
)
116 err
= get_user(avail_idx
, &vrh
->vring
.avail
->idx
);
120 if (vrh
->last_avail_idx
== avail_idx
)
123 /* Only get avail ring entries after they have been exposed by guest. */
124 virtio_rmb(vrh
->weak_barriers
);
126 i
= vrh
->last_avail_idx
& (vrh
->vring
.num
- 1);
128 err
= get_user(*head
, &vrh
->vring
.avail
->ring
[i
]);
132 vrh
->last_avail_idx
++;
136 static int parallel_test(u64 features
,
137 bool (*getrange
)(struct vringh
*vrh
,
138 u64 addr
, struct vringh_range
*r
),
141 void *host_map
, *guest_map
;
142 int fd
, mapsize
, to_guest
[2], to_host
[2];
143 unsigned long xfers
= 0, notifies
= 0, receives
= 0;
144 unsigned int first_cpu
, last_cpu
;
148 /* Create real file to mmap. */
149 fd
= open("/tmp/vringh_test-file", O_RDWR
|O_CREAT
|O_TRUNC
, 0600);
151 err(1, "Opening /tmp/vringh_test-file");
153 /* Extra room at the end for some data, and indirects */
154 mapsize
= vring_size(RINGSIZE
, ALIGN
)
155 + RINGSIZE
* 2 * sizeof(int)
156 + RINGSIZE
* 6 * sizeof(struct vring_desc
);
157 mapsize
= (mapsize
+ getpagesize() - 1) & ~(getpagesize() - 1);
158 ftruncate(fd
, mapsize
);
160 /* Parent and child use separate addresses, to check our mapping logic! */
161 host_map
= mmap(NULL
, mapsize
, PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
162 guest_map
= mmap(NULL
, mapsize
, PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
168 find_cpus(&first_cpu
, &last_cpu
);
169 printf("Using CPUS %u and %u\n", first_cpu
, last_cpu
);
174 int status
, err
, rlen
= 0;
177 /* We are the host: never access guest addresses! */
178 munmap(guest_map
, mapsize
);
180 __user_addr_min
= host_map
;
181 __user_addr_max
= __user_addr_min
+ mapsize
;
182 user_addr_offset
= host_map
- guest_map
;
183 assert(user_addr_offset
);
188 vring_init(&vrh
.vring
, RINGSIZE
, host_map
, ALIGN
);
189 vringh_init_user(&vrh
, features
, RINGSIZE
, true,
190 vrh
.vring
.desc
, vrh
.vring
.avail
, vrh
.vring
.used
);
191 CPU_SET(first_cpu
, &cpu_set
);
192 if (sched_setaffinity(getpid(), sizeof(cpu_set
), &cpu_set
))
193 errx(1, "Could not set affinity to cpu %u", first_cpu
);
195 while (xfers
< NUM_XFERS
) {
196 struct iovec host_riov
[2], host_wiov
[2];
197 struct vringh_iov riov
, wiov
;
202 err
= vringh_get_head(&vrh
, &head
);
205 err
= vringh_need_notify_user(&vrh
);
207 errx(1, "vringh_need_notify_user: %i",
210 write(to_guest
[1], "", 1);
215 errx(1, "vringh_get_head");
219 vringh_iov_init(&riov
,
221 ARRAY_SIZE(host_riov
));
222 vringh_iov_init(&wiov
,
224 ARRAY_SIZE(host_wiov
));
226 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
,
230 err
= vringh_need_notify_user(&vrh
);
232 errx(1, "vringh_need_notify_user: %i",
235 write(to_guest
[1], "", 1);
239 if (!vringh_notify_enable_user(&vrh
))
242 /* Swallow all notifies at once. */
243 if (read(to_host
[0], buf
, sizeof(buf
)) < 1)
246 vringh_notify_disable_user(&vrh
);
251 errx(1, "vringh_getdesc_user: %i", err
);
253 /* We simply copy bytes. */
255 rlen
= vringh_iov_pull_user(&riov
, rbuf
,
258 errx(1, "vringh_iov_pull_user: %i",
260 assert(riov
.i
== riov
.used
);
263 err
= vringh_iov_push_user(&wiov
, rbuf
, rlen
);
265 errx(1, "vringh_iov_push_user: %i",
267 assert(wiov
.i
== wiov
.used
);
273 err
= vringh_complete_user(&vrh
, head
, written
);
275 errx(1, "vringh_complete_user: %i", err
);
278 err
= vringh_need_notify_user(&vrh
);
280 errx(1, "vringh_need_notify_user: %i", err
);
282 write(to_guest
[1], "", 1);
286 if (!WIFEXITED(status
))
287 errx(1, "Child died with signal %i?", WTERMSIG(status
));
288 if (WEXITSTATUS(status
) != 0)
289 errx(1, "Child exited %i?", WEXITSTATUS(status
));
290 printf("Host: notified %lu, pinged %lu\n", notifies
, receives
);
293 struct guest_virtio_device gvdev
;
294 struct virtqueue
*vq
;
296 struct vring_desc
*indirects
;
297 unsigned int finished
= 0;
299 /* We pass sg[]s pointing into here, but we need RINGSIZE+1 */
300 data
= guest_map
+ vring_size(RINGSIZE
, ALIGN
);
301 indirects
= (void *)data
+ (RINGSIZE
+ 1) * 2 * sizeof(int);
303 /* We are the guest. */
304 munmap(host_map
, mapsize
);
309 gvdev
.vdev
.features
= features
;
310 gvdev
.to_host_fd
= to_host
[1];
313 CPU_SET(first_cpu
, &cpu_set
);
314 if (sched_setaffinity(getpid(), sizeof(cpu_set
), &cpu_set
))
315 err(1, "Could not set affinity to cpu %u", first_cpu
);
317 vq
= vring_new_virtqueue(0, RINGSIZE
, ALIGN
, &gvdev
.vdev
, true,
319 fast_vringh
? no_notify_host
320 : parallel_notify_host
,
321 never_callback_guest
, "guest vq");
323 /* Don't kfree indirects. */
324 __kfree_ignore_start
= indirects
;
325 __kfree_ignore_end
= indirects
+ RINGSIZE
* 6;
327 while (xfers
< NUM_XFERS
) {
328 struct scatterlist sg
[4];
329 unsigned int num_sg
, len
;
331 bool output
= !(xfers
% 2);
334 while ((dbuf
= virtqueue_get_buf(vq
, &len
)) != NULL
) {
336 assert(*dbuf
== finished
- 1);
337 else if (!fast_vringh
)
338 assert(*dbuf
== finished
);
342 /* Produce a buffer. */
343 dbuf
= data
+ (xfers
% (RINGSIZE
+ 1));
350 switch ((xfers
/ sizeof(*dbuf
)) % 4) {
352 /* Nasty three-element sg list. */
353 sg_init_table(sg
, num_sg
= 3);
354 sg_set_buf(&sg
[0], (void *)dbuf
, 1);
355 sg_set_buf(&sg
[1], (void *)dbuf
+ 1, 2);
356 sg_set_buf(&sg
[2], (void *)dbuf
+ 3, 1);
359 sg_init_table(sg
, num_sg
= 2);
360 sg_set_buf(&sg
[0], (void *)dbuf
, 1);
361 sg_set_buf(&sg
[1], (void *)dbuf
+ 1, 3);
364 sg_init_table(sg
, num_sg
= 1);
365 sg_set_buf(&sg
[0], (void *)dbuf
, 4);
368 sg_init_table(sg
, num_sg
= 4);
369 sg_set_buf(&sg
[0], (void *)dbuf
, 1);
370 sg_set_buf(&sg
[1], (void *)dbuf
+ 1, 1);
371 sg_set_buf(&sg
[2], (void *)dbuf
+ 2, 1);
372 sg_set_buf(&sg
[3], (void *)dbuf
+ 3, 1);
376 /* May allocate an indirect, so force it to allocate
378 __kmalloc_fake
= indirects
+ (xfers
% RINGSIZE
) * 4;
380 err
= virtqueue_add_outbuf(vq
, sg
, num_sg
, dbuf
,
383 err
= virtqueue_add_inbuf(vq
, sg
, num_sg
,
386 if (err
== -ENOSPC
) {
387 if (!virtqueue_enable_cb_delayed(vq
))
389 /* Swallow all notifies at once. */
390 if (read(to_guest
[0], buf
, sizeof(buf
)) < 1)
394 virtqueue_disable_cb(vq
);
399 errx(1, "virtqueue_add_in/outbuf: %i", err
);
406 while (finished
!= xfers
) {
411 dbuf
= virtqueue_get_buf(vq
, &len
);
414 assert(*dbuf
== finished
- 1);
421 if (!virtqueue_enable_cb_delayed(vq
))
423 if (read(to_guest
[0], buf
, sizeof(buf
)) < 1)
427 virtqueue_disable_cb(vq
);
430 printf("Guest: notified %lu, pinged %lu\n",
431 gvdev
.notifies
, receives
);
432 vring_del_virtqueue(vq
);
437 int main(int argc
, char *argv
[])
439 struct virtio_device vdev
;
440 struct virtqueue
*vq
;
442 struct scatterlist guest_sg
[RINGSIZE
], *sgs
[2];
443 struct iovec host_riov
[2], host_wiov
[2];
444 struct vringh_iov riov
, wiov
;
445 struct vring_used_elem used
[RINGSIZE
];
451 bool (*getrange
)(struct vringh
*vrh
, u64 addr
, struct vringh_range
*r
);
452 bool fast_vringh
= false, parallel
= false;
454 getrange
= getrange_iov
;
458 if (strcmp(argv
[1], "--indirect") == 0)
459 __virtio_set_bit(&vdev
, VIRTIO_RING_F_INDIRECT_DESC
);
460 else if (strcmp(argv
[1], "--eventidx") == 0)
461 __virtio_set_bit(&vdev
, VIRTIO_RING_F_EVENT_IDX
);
462 else if (strcmp(argv
[1], "--virtio-1") == 0)
463 __virtio_set_bit(&vdev
, VIRTIO_F_VERSION_1
);
464 else if (strcmp(argv
[1], "--slow-range") == 0)
465 getrange
= getrange_slow
;
466 else if (strcmp(argv
[1], "--fast-vringh") == 0)
468 else if (strcmp(argv
[1], "--parallel") == 0)
471 errx(1, "Unknown arg %s", argv
[1]);
476 return parallel_test(vdev
.features
, getrange
, fast_vringh
);
478 if (posix_memalign(&__user_addr_min
, PAGE_SIZE
, USER_MEM
) != 0)
480 __user_addr_max
= __user_addr_min
+ USER_MEM
;
481 memset(__user_addr_min
, 0, vring_size(RINGSIZE
, ALIGN
));
483 /* Set up guest side. */
484 vq
= vring_new_virtqueue(0, RINGSIZE
, ALIGN
, &vdev
, true, false,
486 never_notify_host
, never_callback_guest
,
489 /* Set up host side. */
490 vring_init(&vrh
.vring
, RINGSIZE
, __user_addr_min
, ALIGN
);
491 vringh_init_user(&vrh
, vdev
.features
, RINGSIZE
, true,
492 vrh
.vring
.desc
, vrh
.vring
.avail
, vrh
.vring
.used
);
494 /* No descriptor to get yet... */
495 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
, getrange
, &head
);
497 errx(1, "vringh_getdesc_user: %i", err
);
499 /* Guest puts in a descriptor. */
500 memcpy(__user_addr_max
- 1, "a", 1);
501 sg_init_table(guest_sg
, 1);
502 sg_set_buf(&guest_sg
[0], __user_addr_max
- 1, 1);
503 sg_init_table(guest_sg
+1, 1);
504 sg_set_buf(&guest_sg
[1], __user_addr_max
- 3, 2);
505 sgs
[0] = &guest_sg
[0];
506 sgs
[1] = &guest_sg
[1];
508 /* May allocate an indirect, so force it to allocate user addr */
509 __kmalloc_fake
= __user_addr_min
+ vring_size(RINGSIZE
, ALIGN
);
510 err
= virtqueue_add_sgs(vq
, sgs
, 1, 1, &err
, GFP_KERNEL
);
512 errx(1, "virtqueue_add_sgs: %i", err
);
513 __kmalloc_fake
= NULL
;
515 /* Host retreives it. */
516 vringh_iov_init(&riov
, host_riov
, ARRAY_SIZE(host_riov
));
517 vringh_iov_init(&wiov
, host_wiov
, ARRAY_SIZE(host_wiov
));
519 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
, getrange
, &head
);
521 errx(1, "vringh_getdesc_user: %i", err
);
523 assert(riov
.used
== 1);
524 assert(riov
.iov
[0].iov_base
== __user_addr_max
- 1);
525 assert(riov
.iov
[0].iov_len
== 1);
526 if (getrange
!= getrange_slow
) {
527 assert(wiov
.used
== 1);
528 assert(wiov
.iov
[0].iov_base
== __user_addr_max
- 3);
529 assert(wiov
.iov
[0].iov_len
== 2);
531 assert(wiov
.used
== 2);
532 assert(wiov
.iov
[0].iov_base
== __user_addr_max
- 3);
533 assert(wiov
.iov
[0].iov_len
== 1);
534 assert(wiov
.iov
[1].iov_base
== __user_addr_max
- 2);
535 assert(wiov
.iov
[1].iov_len
== 1);
538 err
= vringh_iov_pull_user(&riov
, buf
, 5);
540 errx(1, "vringh_iov_pull_user: %i", err
);
541 assert(buf
[0] == 'a');
543 assert(vringh_iov_pull_user(&riov
, buf
, 5) == 0);
545 memcpy(buf
, "bcdef", 5);
546 err
= vringh_iov_push_user(&wiov
, buf
, 5);
548 errx(1, "vringh_iov_push_user: %i", err
);
549 assert(memcmp(__user_addr_max
- 3, "bc", 2) == 0);
550 assert(wiov
.i
== wiov
.used
);
551 assert(vringh_iov_push_user(&wiov
, buf
, 5) == 0);
554 err
= vringh_complete_user(&vrh
, head
, err
);
556 errx(1, "vringh_complete_user: %i", err
);
558 /* Guest should see used token now. */
559 __kfree_ignore_start
= __user_addr_min
+ vring_size(RINGSIZE
, ALIGN
);
560 __kfree_ignore_end
= __kfree_ignore_start
+ 1;
561 ret
= virtqueue_get_buf(vq
, &i
);
563 errx(1, "virtqueue_get_buf: %p", ret
);
566 /* Guest puts in a huge descriptor. */
567 sg_init_table(guest_sg
, RINGSIZE
);
568 for (i
= 0; i
< RINGSIZE
; i
++) {
569 sg_set_buf(&guest_sg
[i
],
570 __user_addr_max
- USER_MEM
/4, USER_MEM
/4);
573 /* Fill contents with recognisable garbage. */
574 for (i
= 0; i
< USER_MEM
/4; i
++)
575 ((char *)__user_addr_max
- USER_MEM
/4)[i
] = i
;
577 /* This will allocate an indirect, so force it to allocate user addr */
578 __kmalloc_fake
= __user_addr_min
+ vring_size(RINGSIZE
, ALIGN
);
579 err
= virtqueue_add_outbuf(vq
, guest_sg
, RINGSIZE
, &err
, GFP_KERNEL
);
581 errx(1, "virtqueue_add_outbuf (large): %i", err
);
582 __kmalloc_fake
= NULL
;
584 /* Host picks it up (allocates new iov). */
585 vringh_iov_init(&riov
, host_riov
, ARRAY_SIZE(host_riov
));
586 vringh_iov_init(&wiov
, host_wiov
, ARRAY_SIZE(host_wiov
));
588 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
, getrange
, &head
);
590 errx(1, "vringh_getdesc_user: %i", err
);
592 assert(riov
.max_num
& VRINGH_IOV_ALLOCATED
);
593 assert(riov
.iov
!= host_riov
);
594 if (getrange
!= getrange_slow
)
595 assert(riov
.used
== RINGSIZE
);
597 assert(riov
.used
== RINGSIZE
* USER_MEM
/4);
599 assert(!(wiov
.max_num
& VRINGH_IOV_ALLOCATED
));
600 assert(wiov
.used
== 0);
602 /* Pull data back out (in odd chunks), should be as expected. */
603 for (i
= 0; i
< RINGSIZE
* USER_MEM
/4; i
+= 3) {
604 err
= vringh_iov_pull_user(&riov
, buf
, 3);
605 if (err
!= 3 && i
+ err
!= RINGSIZE
* USER_MEM
/4)
606 errx(1, "vringh_iov_pull_user large: %i", err
);
607 assert(buf
[0] == (char)i
);
608 assert(err
< 2 || buf
[1] == (char)(i
+ 1));
609 assert(err
< 3 || buf
[2] == (char)(i
+ 2));
611 assert(riov
.i
== riov
.used
);
612 vringh_iov_cleanup(&riov
);
613 vringh_iov_cleanup(&wiov
);
615 /* Complete using multi interface, just because we can. */
618 err
= vringh_complete_multi_user(&vrh
, used
, 1);
620 errx(1, "vringh_complete_multi_user(1): %i", err
);
622 /* Free up those descriptors. */
623 ret
= virtqueue_get_buf(vq
, &i
);
625 errx(1, "virtqueue_get_buf: %p", ret
);
627 /* Add lots of descriptors. */
628 sg_init_table(guest_sg
, 1);
629 sg_set_buf(&guest_sg
[0], __user_addr_max
- 1, 1);
630 for (i
= 0; i
< RINGSIZE
; i
++) {
631 err
= virtqueue_add_outbuf(vq
, guest_sg
, 1, &err
, GFP_KERNEL
);
633 errx(1, "virtqueue_add_outbuf (multiple): %i", err
);
636 /* Now get many, and consume them all at once. */
637 vringh_iov_init(&riov
, host_riov
, ARRAY_SIZE(host_riov
));
638 vringh_iov_init(&wiov
, host_wiov
, ARRAY_SIZE(host_wiov
));
640 for (i
= 0; i
< RINGSIZE
; i
++) {
641 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
, getrange
, &head
);
643 errx(1, "vringh_getdesc_user: %i", err
);
647 /* Make sure it wraps around ring, to test! */
648 assert(vrh
.vring
.used
->idx
% RINGSIZE
!= 0);
649 err
= vringh_complete_multi_user(&vrh
, used
, RINGSIZE
);
651 errx(1, "vringh_complete_multi_user: %i", err
);
653 /* Free those buffers. */
654 for (i
= 0; i
< RINGSIZE
; i
++) {
656 assert(virtqueue_get_buf(vq
, &len
) != NULL
);
659 /* Test weird (but legal!) indirect. */
660 if (__virtio_test_bit(&vdev
, VIRTIO_RING_F_INDIRECT_DESC
)) {
661 char *data
= __user_addr_max
- USER_MEM
/4;
662 struct vring_desc
*d
= __user_addr_max
- USER_MEM
/2;
665 /* Force creation of direct, which we modify. */
666 __virtio_clear_bit(&vdev
, VIRTIO_RING_F_INDIRECT_DESC
);
667 vq
= vring_new_virtqueue(0, RINGSIZE
, ALIGN
, &vdev
, true,
668 false, __user_addr_min
,
670 never_callback_guest
,
673 sg_init_table(guest_sg
, 4);
674 sg_set_buf(&guest_sg
[0], d
, sizeof(*d
)*2);
675 sg_set_buf(&guest_sg
[1], d
+ 2, sizeof(*d
)*1);
676 sg_set_buf(&guest_sg
[2], data
+ 6, 4);
677 sg_set_buf(&guest_sg
[3], d
+ 3, sizeof(*d
)*3);
679 err
= virtqueue_add_outbuf(vq
, guest_sg
, 4, &err
, GFP_KERNEL
);
681 errx(1, "virtqueue_add_outbuf (indirect): %i", err
);
683 vring_init(&vring
, RINGSIZE
, __user_addr_min
, ALIGN
);
685 /* They're used in order, but double-check... */
686 assert(vring
.desc
[0].addr
== (unsigned long)d
);
687 assert(vring
.desc
[1].addr
== (unsigned long)(d
+2));
688 assert(vring
.desc
[2].addr
== (unsigned long)data
+ 6);
689 assert(vring
.desc
[3].addr
== (unsigned long)(d
+3));
690 vring
.desc
[0].flags
|= VRING_DESC_F_INDIRECT
;
691 vring
.desc
[1].flags
|= VRING_DESC_F_INDIRECT
;
692 vring
.desc
[3].flags
|= VRING_DESC_F_INDIRECT
;
695 d
[0].addr
= (unsigned long)data
;
697 d
[0].flags
= VRING_DESC_F_NEXT
;
699 d
[1].addr
= (unsigned long)data
+ 1;
703 /* Second indirect */
704 d
[2].addr
= (unsigned long)data
+ 3;
709 d
[3].addr
= (unsigned long)data
+ 10;
711 d
[3].flags
= VRING_DESC_F_NEXT
;
713 d
[4].addr
= (unsigned long)data
+ 15;
715 d
[4].flags
= VRING_DESC_F_NEXT
;
717 d
[5].addr
= (unsigned long)data
+ 21;
721 /* Host picks it up (allocates new iov). */
722 vringh_iov_init(&riov
, host_riov
, ARRAY_SIZE(host_riov
));
723 vringh_iov_init(&wiov
, host_wiov
, ARRAY_SIZE(host_wiov
));
725 err
= vringh_getdesc_user(&vrh
, &riov
, &wiov
, getrange
, &head
);
727 errx(1, "vringh_getdesc_user: %i", err
);
730 errx(1, "vringh_getdesc_user: head %i not 0", head
);
732 assert(riov
.max_num
& VRINGH_IOV_ALLOCATED
);
733 if (getrange
!= getrange_slow
)
734 assert(riov
.used
== 7);
736 assert(riov
.used
== 28);
737 err
= vringh_iov_pull_user(&riov
, buf
, 29);
740 /* Data should be linear. */
741 for (i
= 0; i
< err
; i
++)
743 vringh_iov_cleanup(&riov
);
746 /* Don't leak memory... */
747 vring_del_virtqueue(vq
);
748 free(__user_addr_min
);