Skip to contentSkip to conversation

vhost test fixes

PATCH In review Michael S. Tsirkin 2 participants 8 messages Sep 10, 2015

Subsystems (6)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover vhost test fixes

This fixes up virtio tests, broken by recent changes to core.

Michael S. Tsirkin (4):
tools/virtio: fix build after 4.2 changes
vhost: move features to core
tools/virtio: propagate V=X to kernel build
virtio: introduce avail cache

 drivers/vhost/vhost.h        |  4 +++-
 tools/virtio/asm/barrier.h   |  2 ++
 tools/virtio/linux/export.h  |  3 +++
 tools/virtio/linux/kernel.h  |  8 ++++++++
 drivers/vhost/net.c          |  3 +--
 drivers/vhost/scsi.c         |  4 +---
 drivers/vhost/test.c         |  3 +++
 drivers/virtio/virtio_ring.c | 11 ++++++++++-
 tools/virtio/Makefile        |  2 +-
 9 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 tools/virtio/linux/export.h
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/4 tools/virtio: fix build after 4.2 changes

more stubs, mostly

---
 tools/virtio/asm/barrier.h  | 2 ++
 tools/virtio/linux/export.h | 3 +++
 tools/virtio/linux/kernel.h | 8 ++++++++
 3 files changed, 13 insertions(+)
 create mode 100644 tools/virtio/linux/export.h
tools/virtio/asm/barrier.h +2 -0
index aff61e1..26b7926 100644
@@ -3,6 +3,8 @@
 #define mb() __sync_synchronize()
 
 #define smp_mb()	mb()
+# define dma_rmb()	barrier()
+# define dma_wmb()	barrier()
 # define smp_rmb()	barrier()
 # define smp_wmb()	barrier()
 /* Weak barriers should be used. If not - it's a bug */
tools/virtio/linux/export.h new file +3 -0
new file mode 100644
index 0000000..416875e
@@ -0,0 +1,3 @@
+#define EXPORT_SYMBOL_GPL(sym) extern typeof(sym) sym
+#define EXPORT_SYMBOL(sym) extern typeof(sym) sym
+
tools/virtio/linux/kernel.h +8 -0
index 1e8ce69..0a3da64 100644
@@ -22,6 +22,7 @@
 
 typedef unsigned long long dma_addr_t;
 typedef size_t __kernel_size_t;
+typedef unsigned int __wsum;
 
 struct page {
 	unsigned long long dummy;
@@ -47,6 +48,13 @@ static inline void *kmalloc(size_t s, gfp_t gfp)
 		return __kmalloc_fake;
 	return malloc(s);
 }
+static inline void *kzalloc(size_t s, gfp_t gfp)
+{
+	void *p = kmalloc(s, gfp);
+
+	memset(p, 0, s);
+	return p;
+}
 
 static inline void kfree(void *p)
 {
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH 2/4 vhost: move features to core

In reply to Michael S. Tsirkin

virtio 1 and any layout are core features, move them there. This fixes vhost test.

---
 drivers/vhost/vhost.h | 4 +++-
 drivers/vhost/net.c   | 3 +--
 drivers/vhost/scsi.c  | 4 +---
 drivers/vhost/test.c  | 3 +++
 4 files changed, 8 insertions(+), 6 deletions(-)
drivers/vhost/vhost.h +3 -1
index ce6f6da..4772862 100644
@@ -173,7 +173,9 @@ enum {
 	VHOST_FEATURES = (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |
 			 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
 			 (1ULL << VIRTIO_RING_F_EVENT_IDX) |
-			 (1ULL << VHOST_F_LOG_ALL),
+			 (1ULL << VHOST_F_LOG_ALL) |
+			 (1ULL << VIRTIO_F_ANY_LAYOUT) |
+			 (1ULL << VIRTIO_F_VERSION_1)
 };
 
 static inline bool vhost_has_feature(struct vhost_virtqueue *vq, int bit)
drivers/vhost/net.c +1 -2
index 7d137a4..fa68bc9 100644
@@ -61,8 +61,7 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
 enum {
 	VHOST_NET_FEATURES = VHOST_FEATURES |
 			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
-			 (1ULL << VIRTIO_NET_F_MRG_RXBUF) |
-			 (1ULL << VIRTIO_F_VERSION_1),
+			 (1ULL << VIRTIO_NET_F_MRG_RXBUF);
 };
 
 enum {
drivers/vhost/scsi.c +1 -3
index dfcc02c..0321fc4 100644
@@ -166,9 +166,7 @@ enum {
 /* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */
 enum {
 	VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) |
-					       (1ULL << VIRTIO_SCSI_F_T10_PI) |
-					       (1ULL << VIRTIO_F_ANY_LAYOUT) |
-					       (1ULL << VIRTIO_F_VERSION_1)
+					       (1ULL << VIRTIO_SCSI_F_T10_PI);
 };
 
 #define VHOST_SCSI_MAX_TARGET	256
drivers/vhost/test.c +3 -0
index d9c501e..f2882ac 100644
@@ -277,10 +277,13 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
 			return -EFAULT;
 		return 0;
 	case VHOST_SET_FEATURES:
+		printk(KERN_ERR "1\n");
 		if (copy_from_user(&features, featurep, sizeof features))
 			return -EFAULT;
+		printk(KERN_ERR "2\n");
 		if (features & ~VHOST_FEATURES)
 			return -EOPNOTSUPP;
+		printk(KERN_ERR "3\n");
 		return vhost_test_set_features(n, features);
 	case VHOST_RESET_OWNER:
 		return vhost_test_reset_owner(n);
Signature · 1 line
MST
#3 lore raw

Re: [PATCH 2/4] vhost: move features to core

Hello.

Quoted 4 lines · Michael S. Tsirkin

virtio 1 and any layout are core features, move them there. This fixes vhost test.

[...]

Quoted 8 lines
drivers/vhost/test.c +0 -0
index d9c501e..f2882ac 100644
@@ -277,10 +277,13 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
  			return -EFAULT;
  		return 0;
  	case VHOST_SET_FEATURES:

drivers/vhost/test.c static long vhost_test_ioctl(struct file *f, unsigned int ioctl, · line 289

Quoted 10 lines
drivers/vhost/test.c +3 -0
+		printk(KERN_ERR "1\n");
  		if (copy_from_user(&features, featurep, sizeof features))
  			return -EFAULT;
+		printk(KERN_ERR "2\n");
  		if (features & ~VHOST_FEATURES)
  			return -EOPNOTSUPP;
+		printk(KERN_ERR "3\n");
  		return vhost_test_set_features(n, features);
  	case VHOST_RESET_OWNER:
  		return vhost_test_reset_owner(n);

Debugging printk's remained?

MBR, Sergei

author maintainer
#4 lore raw

PATCH 3/4 tools/virtio: propagate V=X to kernel build

In reply to Michael S. Tsirkin
---
 tools/virtio/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtio/Makefile +1 -1
index 505ad51..39c89a5 100644
@@ -6,7 +6,7 @@ vringh_test: vringh_test.o vringh.o virtio_ring.o
 CFLAGS += -g -O2 -Werror -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
+	${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test V=${V}
 .PHONY: all test mod clean
 clean:
 	${RM} *.o vringh_test virtio_test vhost_test/*.o vhost_test/.*.cmd \
Signature · 1 line
MST
author maintainer
#5 lore raw

PATCH 3/4 tools/virtio: propagate V=X to kernel build

In reply to Michael S. Tsirkin
---
 tools/virtio/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtio/Makefile +1 -1
index 505ad51..39c89a5 100644
@@ -6,7 +6,7 @@ vringh_test: vringh_test.o vringh.o virtio_ring.o
 CFLAGS += -g -O2 -Werror -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
+	${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test V=${V}
 .PHONY: all test mod clean
 clean:
 	${RM} *.o vringh_test virtio_test vhost_test/*.o vhost_test/.*.cmd \
Signature · 1 line
MST
author maintainer
#6 lore raw

PATCH 4/4 virtio: introduce avail cache

In reply to Michael S. Tsirkin

This allows skipping avail ring writes when they
don't need to change. Good for cache locality.

---
 drivers/virtio/virtio_ring.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +10 -1
index 096b857..14e7ce9 100644
@@ -91,6 +91,7 @@ struct vring_virtqueue {
 	bool last_add_time_valid;
 	ktime_t last_add_time;
 #endif
+	u16 *avail;
 
 	/* Tokens for callbacks. */
 	void *data[];
@@ -236,7 +237,10 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	/* Put entry in available array (but don't update avail->idx until they
 	 * do sync). */
 	avail = virtio16_to_cpu(_vq->vdev, vq->vring.avail->idx) & (vq->vring.num - 1);
-	vq->vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head);
+	if (vq->avail[avail] != head) {
+		vq->avail[avail] = head;
+		vq->vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head);
+	}
 
 	/* Descriptors and available array need to be set before we expose the
 	 * new available array entries. */
@@ -724,6 +728,11 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 	vq = kmalloc(sizeof(*vq) + sizeof(void *)*num, GFP_KERNEL);
 	if (!vq)
 		return NULL;
+	vq->avail = kzalloc(sizeof (*vq->avail) * num, GFP_KERNEL);
+	if (!vq->avail) {
+		kfree(vq);
+		return NULL;
+	}
 
 	vring_init(&vq->vring, num, pages, vring_align);
 	vq->vq.callback = callback;
Signature · 1 line
MST
author maintainer
#7 lore raw

PATCH 4/4 virtio: introduce avail cache

In reply to Michael S. Tsirkin

This allows skipping avail ring writes when they
don't need to change. Good for cache locality.

---
 drivers/virtio/virtio_ring.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +10 -1
index 096b857..14e7ce9 100644
@@ -91,6 +91,7 @@ struct vring_virtqueue {
 	bool last_add_time_valid;
 	ktime_t last_add_time;
 #endif
+	u16 *avail;
 
 	/* Tokens for callbacks. */
 	void *data[];
@@ -236,7 +237,10 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	/* Put entry in available array (but don't update avail->idx until they
 	 * do sync). */
 	avail = virtio16_to_cpu(_vq->vdev, vq->vring.avail->idx) & (vq->vring.num - 1);
-	vq->vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head);
+	if (vq->avail[avail] != head) {
+		vq->avail[avail] = head;
+		vq->vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head);
+	}
 
 	/* Descriptors and available array need to be set before we expose the
 	 * new available array entries. */
@@ -724,6 +728,11 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 	vq = kmalloc(sizeof(*vq) + sizeof(void *)*num, GFP_KERNEL);
 	if (!vq)
 		return NULL;
+	vq->avail = kzalloc(sizeof (*vq->avail) * num, GFP_KERNEL);
+	if (!vq->avail) {
+		kfree(vq);
+		return NULL;
+	}
 
 	vring_init(&vq->vring, num, pages, vring_align);
 	vq->vq.callback = callback;
Signature · 1 line
MST