diff options
Diffstat (limited to 'tools/virtio')
| -rw-r--r-- | tools/virtio/.gitignore | 3 | ||||
| -rw-r--r-- | tools/virtio/Makefile | 2 | ||||
| -rw-r--r-- | tools/virtio/linux/export.h | 5 | ||||
| -rw-r--r-- | tools/virtio/linux/kernel.h | 7 | ||||
| -rw-r--r-- | tools/virtio/linux/kmemleak.h | 3 | ||||
| -rw-r--r-- | tools/virtio/linux/module.h | 5 | ||||
| -rw-r--r-- | tools/virtio/linux/scatterlist.h | 16 | ||||
| -rw-r--r-- | tools/virtio/linux/types.h | 28 | ||||
| -rw-r--r-- | tools/virtio/linux/virtio.h | 25 | ||||
| -rw-r--r-- | tools/virtio/virtio_test.c | 12 | ||||
| -rw-r--r-- | tools/virtio/vringh_test.c | 43 |
11 files changed, 76 insertions, 73 deletions
diff --git a/tools/virtio/.gitignore b/tools/virtio/.gitignore new file mode 100644 index 00000000000..1cfbb0157a4 --- /dev/null +++ b/tools/virtio/.gitignore @@ -0,0 +1,3 @@ +*.d +virtio_test +vringh_test diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile index 3187c62d981..9325f469382 100644 --- a/tools/virtio/Makefile +++ b/tools/virtio/Makefile @@ -3,7 +3,7 @@ test: virtio_test vringh_test virtio_test: virtio_ring.o virtio_test.o vringh_test: vringh_test.o vringh.o virtio_ring.o -CFLAGS += -g -O2 -Wall -I. -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE +CFLAGS += -g -O2 -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE vpath %.c ../../drivers/virtio ../../drivers/vhost mod: ${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test diff --git a/tools/virtio/linux/export.h b/tools/virtio/linux/export.h deleted file mode 100644 index 7311d326894..00000000000 --- a/tools/virtio/linux/export.h +++ /dev/null @@ -1,5 +0,0 @@ -#define EXPORT_SYMBOL(sym) -#define EXPORT_SYMBOL_GPL(sym) -#define EXPORT_SYMBOL_GPL_FUTURE(sym) -#define EXPORT_UNUSED_SYMBOL(sym) -#define EXPORT_UNUSED_SYMBOL_GPL(sym) diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h index fba70596396..1e8ce6979c1 100644 --- a/tools/virtio/linux/kernel.h +++ b/tools/virtio/linux/kernel.h @@ -38,13 +38,6 @@ struct page { #define __printf(a,b) __attribute__((format(printf,a,b))) -typedef enum { - GFP_KERNEL, - GFP_ATOMIC, - __GFP_HIGHMEM, - __GFP_HIGH -} gfp_t; - #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) extern void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; diff --git a/tools/virtio/linux/kmemleak.h b/tools/virtio/linux/kmemleak.h new file mode 100644 index 00000000000..c07072270e2 --- /dev/null +++ b/tools/virtio/linux/kmemleak.h @@ -0,0 +1,3 @@ +static inline void kmemleak_ignore(const void *ptr) +{ +} diff --git a/tools/virtio/linux/module.h b/tools/virtio/linux/module.h index 3039a7e972b..28ce95a0599 100644 --- a/tools/virtio/linux/module.h +++ b/tools/virtio/linux/module.h @@ -1 +1,6 @@ #include <linux/export.h> + +#define MODULE_LICENSE(__MODULE_LICENSE_value) \ + static __attribute__((unused)) const char *__MODULE_LICENSE_name = \ + __MODULE_LICENSE_value + diff --git a/tools/virtio/linux/scatterlist.h b/tools/virtio/linux/scatterlist.h index b2cf7d0f613..68c9e2adc99 100644 --- a/tools/virtio/linux/scatterlist.h +++ b/tools/virtio/linux/scatterlist.h @@ -125,6 +125,22 @@ static inline void sg_mark_end(struct scatterlist *sg) sg->page_link &= ~0x01; } +/** + * sg_unmark_end - Undo setting the end of the scatterlist + * @sg: SG entryScatterlist + * + * Description: + * Removes the termination marker from the given entry of the scatterlist. + * + **/ +static inline void sg_unmark_end(struct scatterlist *sg) +{ +#ifdef CONFIG_DEBUG_SG + BUG_ON(sg->sg_magic != SG_MAGIC); +#endif + sg->page_link &= ~0x02; +} + static inline struct scatterlist *sg_next(struct scatterlist *sg) { #ifdef CONFIG_DEBUG_SG diff --git a/tools/virtio/linux/types.h b/tools/virtio/linux/types.h deleted file mode 100644 index f8ebb9a2b3d..00000000000 --- a/tools/virtio/linux/types.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H -#include <stdint.h> - -#define __force -#define __user -#define __must_check -#define __cold - -typedef uint64_t u64; -typedef int64_t s64; -typedef uint32_t u32; -typedef int32_t s32; -typedef uint16_t u16; -typedef int16_t s16; -typedef uint8_t u8; -typedef int8_t s8; - -typedef uint64_t __u64; -typedef int64_t __s64; -typedef uint32_t __u32; -typedef int32_t __s32; -typedef uint16_t __u16; -typedef int16_t __s16; -typedef uint8_t __u8; -typedef int8_t __s8; - -#endif /* TYPES_H */ diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h index e4af6591f5f..5a2d1f0f6bc 100644 --- a/tools/virtio/linux/virtio.h +++ b/tools/virtio/linux/virtio.h @@ -45,18 +45,25 @@ struct virtqueue { void *priv; }; -#define MODULE_LICENSE(__MODULE_LICENSE_value) \ - const char *__MODULE_LICENSE_name = __MODULE_LICENSE_value - /* Interfaces exported by virtio_ring. */ -int virtqueue_add_buf(struct virtqueue *vq, - struct scatterlist sg[], - unsigned int out_num, - unsigned int in_num, +int virtqueue_add_sgs(struct virtqueue *vq, + struct scatterlist *sgs[], + unsigned int out_sgs, + unsigned int in_sgs, void *data, gfp_t gfp); -void virtqueue_kick(struct virtqueue *vq); +int virtqueue_add_outbuf(struct virtqueue *vq, + struct scatterlist sg[], unsigned int num, + void *data, + gfp_t gfp); + +int virtqueue_add_inbuf(struct virtqueue *vq, + struct scatterlist sg[], unsigned int num, + void *data, + gfp_t gfp); + +bool virtqueue_kick(struct virtqueue *vq); void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); @@ -72,7 +79,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index, struct virtio_device *vdev, bool weak_barriers, void *pages, - void (*notify)(struct virtqueue *vq), + bool (*notify)(struct virtqueue *vq), void (*callback)(struct virtqueue *vq), const char *name); void vring_del_virtqueue(struct virtqueue *vq); diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 814ae803c87..00ea679b382 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -41,13 +41,14 @@ struct vdev_info { struct vhost_memory *mem; }; -void vq_notify(struct virtqueue *vq) +bool vq_notify(struct virtqueue *vq) { struct vq_info *info = vq->priv; unsigned long long v = 1; int r; r = write(info->kick, &v, sizeof v); assert(r == sizeof v); + return true; } void vq_callback(struct virtqueue *vq) @@ -166,12 +167,13 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, do { if (started < bufs) { sg_init_one(&sl, dev->buf, dev->buf_size); - r = virtqueue_add_buf(vq->vq, &sl, 1, 0, - dev->buf + started, - GFP_ATOMIC); + r = virtqueue_add_outbuf(vq->vq, &sl, 1, + dev->buf + started, + GFP_ATOMIC); if (likely(r == 0)) { ++started; - virtqueue_kick(vq->vq); + if (unlikely(!virtqueue_kick(vq->vq))) + r = -1; } } else r = -1; diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c index 6a48ca5c101..14a4f4cab5b 100644 --- a/tools/virtio/vringh_test.c +++ b/tools/virtio/vringh_test.c @@ -22,7 +22,7 @@ static u64 user_addr_offset; #define RINGSIZE 256 #define ALIGN 4096 -static void never_notify_host(struct virtqueue *vq) +static bool never_notify_host(struct virtqueue *vq) { abort(); } @@ -65,17 +65,22 @@ struct guest_virtio_device { unsigned long notifies; }; -static void parallel_notify_host(struct virtqueue *vq) +static bool parallel_notify_host(struct virtqueue *vq) { + int rc; struct guest_virtio_device *gvdev; gvdev = container_of(vq->vdev, struct guest_virtio_device, vdev); - write(gvdev->to_host_fd, "", 1); + rc = write(gvdev->to_host_fd, "", 1); + if (rc < 0) + return false; gvdev->notifies++; + return true; } -static void no_notify_host(struct virtqueue *vq) +static bool no_notify_host(struct virtqueue *vq) { + return true; } #define NUM_XFERS (10000000) @@ -369,11 +374,11 @@ static int parallel_test(unsigned long features, * user addr */ __kmalloc_fake = indirects + (xfers % RINGSIZE) * 4; if (output) - err = virtqueue_add_buf(vq, sg, num_sg, 0, dbuf, - GFP_KERNEL); + err = virtqueue_add_outbuf(vq, sg, num_sg, dbuf, + GFP_KERNEL); else - err = virtqueue_add_buf(vq, sg, 0, num_sg, dbuf, - GFP_KERNEL); + err = virtqueue_add_inbuf(vq, sg, num_sg, + dbuf, GFP_KERNEL); if (err == -ENOSPC) { if (!virtqueue_enable_cb_delayed(vq)) @@ -388,7 +393,7 @@ static int parallel_test(unsigned long features, } if (err) - errx(1, "virtqueue_add_buf: %i", err); + errx(1, "virtqueue_add_in/outbuf: %i", err); xfers++; virtqueue_kick(vq); @@ -431,7 +436,7 @@ int main(int argc, char *argv[]) struct virtio_device vdev; struct virtqueue *vq; struct vringh vrh; - struct scatterlist guest_sg[RINGSIZE]; + struct scatterlist guest_sg[RINGSIZE], *sgs[2]; struct iovec host_riov[2], host_wiov[2]; struct vringh_iov riov, wiov; struct vring_used_elem used[RINGSIZE]; @@ -492,12 +497,14 @@ int main(int argc, char *argv[]) sg_set_buf(&guest_sg[0], __user_addr_max - 1, 1); sg_init_table(guest_sg+1, 1); sg_set_buf(&guest_sg[1], __user_addr_max - 3, 2); + sgs[0] = &guest_sg[0]; + sgs[1] = &guest_sg[1]; /* May allocate an indirect, so force it to allocate user addr */ __kmalloc_fake = __user_addr_min + vring_size(RINGSIZE, ALIGN); - err = virtqueue_add_buf(vq, guest_sg, 1, 1, &err, GFP_KERNEL); + err = virtqueue_add_sgs(vq, sgs, 1, 1, &err, GFP_KERNEL); if (err) - errx(1, "virtqueue_add_buf: %i", err); + errx(1, "virtqueue_add_sgs: %i", err); __kmalloc_fake = NULL; /* Host retreives it. */ @@ -564,9 +571,9 @@ int main(int argc, char *argv[]) /* This will allocate an indirect, so force it to allocate user addr */ __kmalloc_fake = __user_addr_min + vring_size(RINGSIZE, ALIGN); - err = virtqueue_add_buf(vq, guest_sg, RINGSIZE, 0, &err, GFP_KERNEL); + err = virtqueue_add_outbuf(vq, guest_sg, RINGSIZE, &err, GFP_KERNEL); if (err) - errx(1, "virtqueue_add_buf (large): %i", err); + errx(1, "virtqueue_add_outbuf (large): %i", err); __kmalloc_fake = NULL; /* Host picks it up (allocates new iov). */ @@ -616,9 +623,9 @@ int main(int argc, char *argv[]) sg_init_table(guest_sg, 1); sg_set_buf(&guest_sg[0], __user_addr_max - 1, 1); for (i = 0; i < RINGSIZE; i++) { - err = virtqueue_add_buf(vq, guest_sg, 1, 0, &err, GFP_KERNEL); + err = virtqueue_add_outbuf(vq, guest_sg, 1, &err, GFP_KERNEL); if (err) - errx(1, "virtqueue_add_buf (multiple): %i", err); + errx(1, "virtqueue_add_outbuf (multiple): %i", err); } /* Now get many, and consume them all at once. */ @@ -664,9 +671,9 @@ int main(int argc, char *argv[]) sg_set_buf(&guest_sg[2], data + 6, 4); sg_set_buf(&guest_sg[3], d + 3, sizeof(*d)*3); - err = virtqueue_add_buf(vq, guest_sg, 4, 0, &err, GFP_KERNEL); + err = virtqueue_add_outbuf(vq, guest_sg, 4, &err, GFP_KERNEL); if (err) - errx(1, "virtqueue_add_buf (indirect): %i", err); + errx(1, "virtqueue_add_outbuf (indirect): %i", err); vring_init(&vring, RINGSIZE, __user_addr_min, ALIGN); |
