Skip to contentSkip to conversation

vringh

PATCH In review Rusty Russell 3 participants 14 messages Feb 18, 2013 – Feb 28, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover vringh

This introduces vringh, which are generic accessors for virtio rings (host side). There's a host-side implementation in vhost, but it assumes that the rings are in userspace, and is tied to the vhost implementation. I have patches to adapt it to use vringh, but I'm pushing this in the next merge window for Sjur, who has CAIF patches which need it.

This also includes a test program in tools/virtio. There's a fixup patch for the current tools, since they didn't compile for me. MST?

Review and comments welcome!
Rusty.

#1 lore raw

PATCH 1/5 virtio_ring: expose virtio barriers for use in vringh.

The host side of ring needs this logic too.

---
 drivers/virtio/virtio_ring.c |   33 +++++-------------------
 include/linux/virtio_ring.h  |   57 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 27 deletions(-)
drivers/virtio/virtio_ring.c +6 -27
index ffd7e7d..245177c 100644
@@ -24,27 +24,6 @@
 #include <linux/module.h>
 #include <linux/hrtimer.h>
 
-/* virtio guest is communicating with a virtual "device" that actually runs on
- * a host processor.  Memory barriers are used to control SMP effects. */
-#ifdef CONFIG_SMP
-/* Where possible, use SMP barriers which are more lightweight than mandatory
- * barriers, because mandatory barriers control MMIO effects on accesses
- * through relaxed memory I/O windows (which virtio-pci does not use). */
-#define virtio_mb(vq) \
-	do { if ((vq)->weak_barriers) smp_mb(); else mb(); } while(0)
-#define virtio_rmb(vq) \
-	do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0)
-#define virtio_wmb(vq) \
-	do { if ((vq)->weak_barriers) smp_wmb(); else wmb(); } while(0)
-#else
-/* We must force memory ordering even if guest is UP since host could be
- * running on another CPU, but SMP barriers are defined to barrier() in that
- * configuration. So fall back to mandatory barriers instead. */
-#define virtio_mb(vq) mb()
-#define virtio_rmb(vq) rmb()
-#define virtio_wmb(vq) wmb()
-#endif
-
 #ifdef DEBUG
 /* For development, we want to crash whenever the ring is screwed. */
 #define BAD_RING(_vq, fmt, args...)				\
@@ -276,7 +255,7 @@ add_head:
 
 	/* Descriptors and available array need to be set before we expose the
 	 * new available array entries. */
-	virtio_wmb(vq);
+	virtio_wmb(vq->weak_barriers);
 	vq->vring.avail->idx++;
 	vq->num_added++;
 
@@ -312,7 +291,7 @@ bool virtqueue_kick_prepare(struct virtqueue *_vq)
 	START_USE(vq);
 	/* We need to expose available array entries before checking avail
 	 * event. */
-	virtio_mb(vq);
+	virtio_mb(vq->weak_barriers);
 
 	old = vq->vring.avail->idx - vq->num_added;
 	new = vq->vring.avail->idx;
@@ -436,7 +415,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 	}
 
 	/* Only get used array entries after they have been exposed by host. */
-	virtio_rmb(vq);
+	virtio_rmb(vq->weak_barriers);
 
 	last_used = (vq->last_used_idx & (vq->vring.num - 1));
 	i = vq->vring.used->ring[last_used].id;
@@ -460,7 +439,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 	 * the read in the next get_buf call. */
 	if (!(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) {
 		vring_used_event(&vq->vring) = vq->last_used_idx;
-		virtio_mb(vq);
+		virtio_mb(vq->weak_barriers);
 	}
 
 #ifdef DEBUG
@@ -513,7 +492,7 @@ bool virtqueue_enable_cb(struct virtqueue *_vq)
 	 * entry. Always do both to keep code simple. */
 	vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
 	vring_used_event(&vq->vring) = vq->last_used_idx;
-	virtio_mb(vq);
+	virtio_mb(vq->weak_barriers);
 	if (unlikely(more_used(vq))) {
 		END_USE(vq);
 		return false;
@@ -553,7 +532,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
 	/* TODO: tune this threshold */
 	bufs = (u16)(vq->vring.avail->idx - vq->last_used_idx) * 3 / 4;
 	vring_used_event(&vq->vring) = vq->last_used_idx + bufs;
-	virtio_mb(vq);
+	virtio_mb(vq->weak_barriers);
 	if (unlikely((u16)(vq->vring.used->idx - vq->last_used_idx) > bufs)) {
 		END_USE(vq);
 		return false;
include/linux/virtio_ring.h +57 -0

63 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/5 vringh: host-side implementation of virtio rings.

In reply to Rusty Russell

Getting use of virtio rings correct is tricky, and a recent patch saw an implementation of in-kernel rings (as separate from userspace).

This abstracts the business of dealing with the virtio ring layout from the access (userspace or direct); to do this, we use function pointers, which gcc inlines correctly.

There are patches pending to make vhost use this interface, but it's being merged now for the CAIF virtio patches, which want it immediately.

---
 drivers/Makefile          |    2 +-
 drivers/vhost/Kconfig     |    8 +
 drivers/vhost/Kconfig.tcm |    1 +
 drivers/vhost/Makefile    |    2 +
 drivers/vhost/vringh.c    | 1012 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/vringh.h    |  185 +++++++++
 6 files changed, 1209 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vhost/vringh.c
 create mode 100644 include/linux/vringh.h
drivers/Makefile +1 -1
index 7863b9f..351a34f 100644
@@ -123,7 +123,7 @@ obj-$(CONFIG_PPC_PS3)		+= ps3/
 obj-$(CONFIG_OF)		+= of/
 obj-$(CONFIG_SSB)		+= ssb/
 obj-$(CONFIG_BCMA)		+= bcma/
-obj-$(CONFIG_VHOST_NET)		+= vhost/
+obj-$(CONFIG_VHOST_RING)	+= vhost/
 obj-$(CONFIG_VLYNQ)		+= vlynq/
 obj-$(CONFIG_STAGING)		+= staging/
 obj-y				+= platform/
drivers/vhost/Kconfig +8 -0
index 202bba6..613b074 100644
@@ -1,6 +1,7 @@
 config VHOST_NET
 	tristate "Host kernel accelerator for virtio net (EXPERIMENTAL)"
 	depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP) && EXPERIMENTAL
+	select VHOST_RING
 	---help---
 	  This kernel module can be loaded in host kernel to accelerate
 	  guest networking with virtio_net. Not to be confused with virtio_net
@@ -12,3 +13,10 @@ config VHOST_NET
 if STAGING
 source "drivers/vhost/Kconfig.tcm"
 endif
+
+config VHOST_RING
+	tristate
+	---help---
+	  This option is selected by any driver which needs to access
+	  the host side of a virtio ring.
+
drivers/vhost/Kconfig.tcm +1 -0
index a9c6f76..0218f77 100644
@@ -1,6 +1,7 @@
 config TCM_VHOST
 	tristate "TCM_VHOST fabric module (EXPERIMENTAL)"
 	depends on TARGET_CORE && EVENTFD && EXPERIMENTAL && m
+	select VHOST_RING
 	default n
 	---help---
 	Say M here to enable the TCM_VHOST fabric module for use with virtio-scsi guests
drivers/vhost/Makefile +2 -0
index a27b053..1d37f5e 100644
@@ -2,3 +2,5 @@ obj-$(CONFIG_VHOST_NET) += vhost_net.o
 vhost_net-y := vhost.o net.o
 
 obj-$(CONFIG_TCM_VHOST) += tcm_vhost.o
+
+obj-$(CONFIG_VHOST_RING) += vringh.o
drivers/vhost/vringh.c new file +1012 -0

1,012 lines not on this page · raw message

include/linux/vringh.h new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/5 tools/virtio: fix compile.

In reply to Rusty Russell

Didn't test that it actually works, mind you!

---
 tools/virtio/linux/virtio.h |    9 ++++++++-
 tools/virtio/virtio_test.c  |    6 +++---
 2 files changed, 11 insertions(+), 4 deletions(-)
tools/virtio/linux/virtio.h +8 -1
index 81847dd..ccfc901 100644
@@ -86,6 +86,10 @@ typedef enum {
 	GFP_KERNEL,
 	GFP_ATOMIC,
 } gfp_t;
+
+#define __GFP_HIGHMEM 0
+#define __GFP_HIGH 0
+
 typedef enum {
 	IRQ_NONE,
 	IRQ_HANDLED
@@ -163,6 +167,8 @@ struct virtqueue {
 	void (*callback)(struct virtqueue *vq);
 	const char *name;
 	struct virtio_device *vdev;
+	unsigned int index;
+	unsigned int num_free;
 	void *priv;
 };
 
@@ -206,7 +212,8 @@ bool virtqueue_enable_cb(struct virtqueue *vq);
 bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
 
 void *virtqueue_detach_unused_buf(struct virtqueue *vq);
-struct virtqueue *vring_new_virtqueue(unsigned int num,
+struct virtqueue *vring_new_virtqueue(unsigned int index,
+				      unsigned int num,
 				      unsigned int vring_align,
 				      struct virtio_device *vdev,
 				      bool weak_barriers,
tools/virtio/virtio_test.c +3 -3
index fcc9aa2..a07142c 100644
@@ -81,7 +81,7 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_info *info)
 	assert(r >= 0);
 }
 
-static void vq_info_add(struct vdev_info *dev, int num)
+static void vq_info_add(struct vdev_info *dev, int idx, int num)
 {
 	struct vq_info *info = &dev->vqs[dev->nvqs];
 	int r;
@@ -92,7 +92,7 @@ static void vq_info_add(struct vdev_info *dev, int num)
 	assert(r >= 0);
 	memset(info->ring, 0, vring_size(num, 4096));
 	vring_init(&info->vring, num, info->ring, 4096);
-	info->vq = vring_new_virtqueue(info->vring.num, 4096, &dev->vdev,
+	info->vq = vring_new_virtqueue(idx, info->vring.num, 4096, &dev->vdev,
 				       true, info->ring,
 				       vq_notify, vq_callback, "test");
 	assert(info->vq);
@@ -277,7 +277,7 @@ int main(int argc, char **argv)
 
 done:
 	vdev_info_init(&dev, features);
-	vq_info_add(&dev, 256);
+	vq_info_add(&dev, 0, 256);
 	run_test(&dev, &dev.vqs[0], delayed, 0x100000);
 	return 0;
 }
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/5 tools/virtio: separate headers more.

In reply to Rusty Russell

This makes them a bit more like the kernel headers, so we can include more real kernel headers in our tests.

---
 tools/virtio/asm/barrier.h              |   14 +++
 tools/virtio/linux/bug.h                |   10 ++
 tools/virtio/linux/err.h                |   26 +++++
 tools/virtio/linux/export.h             |    5 +
 tools/virtio/linux/irqreturn.h          |    1 +
 tools/virtio/linux/kernel.h             |  113 ++++++++++++++++++++
 tools/virtio/linux/module.h             |    1 +
 tools/virtio/linux/printk.h             |    4 +
 tools/virtio/linux/ratelimit.h          |    4 +
 tools/virtio/linux/scatterlist.h        |  173 +++++++++++++++++++++++++++++++
 tools/virtio/linux/types.h              |   28 +++++
 tools/virtio/linux/uaccess.h            |   37 +++++++
 tools/virtio/linux/uio.h                |    1 +
 tools/virtio/linux/virtio.h             |  152 +--------------------------
 tools/virtio/linux/virtio_config.h      |    6 ++
 tools/virtio/linux/virtio_ring.h        |    1 +
 tools/virtio/linux/vringh.h             |    1 +
 tools/virtio/uapi/linux/uio.h           |    1 +
 tools/virtio/uapi/linux/virtio_config.h |    1 +
 tools/virtio/uapi/linux/virtio_ring.h   |    4 +
 tools/virtio/virtio_test.c              |    4 +
 21 files changed, 438 insertions(+), 149 deletions(-)
 create mode 100644 tools/virtio/asm/barrier.h
 create mode 100644 tools/virtio/linux/bug.h
 create mode 100644 tools/virtio/linux/err.h
 create mode 100644 tools/virtio/linux/export.h
 create mode 100644 tools/virtio/linux/irqreturn.h
 create mode 100644 tools/virtio/linux/kernel.h
 create mode 100644 tools/virtio/linux/printk.h
 create mode 100644 tools/virtio/linux/ratelimit.h
 create mode 100644 tools/virtio/linux/scatterlist.h
 create mode 100644 tools/virtio/linux/types.h
 create mode 100644 tools/virtio/linux/uaccess.h
 create mode 100644 tools/virtio/linux/uio.h
 create mode 100644 tools/virtio/linux/virtio_config.h
 create mode 100644 tools/virtio/linux/virtio_ring.h
 create mode 100644 tools/virtio/linux/vringh.h
 create mode 100644 tools/virtio/uapi/linux/uio.h
 create mode 100644 tools/virtio/uapi/linux/virtio_config.h
 create mode 100644 tools/virtio/uapi/linux/virtio_ring.h
tools/virtio/asm/barrier.h new file +14 -0
new file mode 100644
index 0000000..aff61e1
@@ -0,0 +1,14 @@
+#if defined(__i386__) || defined(__x86_64__)
+#define barrier() asm volatile("" ::: "memory")
+#define mb() __sync_synchronize()
+
+#define smp_mb()	mb()
+# define smp_rmb()	barrier()
+# define smp_wmb()	barrier()
+/* Weak barriers should be used. If not - it's a bug */
+# define rmb()	abort()
+# define wmb()	abort()
+#else
+#error Please fill in barrier macros
+#endif
+
tools/virtio/linux/bug.h new file +10 -0
new file mode 100644
index 0000000..fb94f07
@@ -0,0 +1,10 @@
+#ifndef BUG_H
+#define BUG_H
+
+#define BUG_ON(__BUG_ON_cond) assert(!(__BUG_ON_cond))
+
+#define BUILD_BUG_ON(x)
+
+#define BUG() abort()
+
+#endif /* BUG_H */
tools/virtio/linux/err.h new file +26 -0
new file mode 100644
index 0000000..e32eff8
@@ -0,0 +1,26 @@
+#ifndef ERR_H
+#define ERR_H
+#define MAX_ERRNO	4095
+
+#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
+
+static inline void * __must_check ERR_PTR(long error)
+{
+	return (void *) error;
+}
+
+static inline long __must_check PTR_ERR(const void *ptr)
+{
+	return (long) ptr;
+}
+
+static inline long __must_check IS_ERR(const void *ptr)
+{
+	return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
+{
+	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+}
+#endif /* ERR_H */
tools/virtio/linux/export.h new file +5 -0
new file mode 100644
index 0000000..7311d32
@@ -0,0 +1,5 @@
+#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)
tools/virtio/linux/irqreturn.h new file +1 -0
new file mode 100644
index 0000000..a3c4e7b
@@ -0,0 +1 @@
+#include "../../../include/linux/irqreturn.h"
tools/virtio/linux/kernel.h new file +113 -0

113 lines not on this page · raw message

tools/virtio/linux/module.h +1 -0
index e69de29..3039a7e 100644
@@ -0,0 +1 @@
+#include <linux/export.h>
tools/virtio/linux/printk.h new file +4 -0
new file mode 100644
index 0000000..9f2423b
@@ -0,0 +1,4 @@
+#include "../../../include/linux/kern_levels.h"
+
+#define printk printf
+#define vprintk vprintf
tools/virtio/linux/ratelimit.h new file +4 -0
new file mode 100644
index 0000000..dcce172
@@ -0,0 +1,4 @@
+#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init)	int name = 0
+
+#define __ratelimit(x) (*(x))
+
tools/virtio/linux/scatterlist.h new file +173 -0

173 lines not on this page · raw message

tools/virtio/linux/types.h new file +28 -0
new file mode 100644
index 0000000..f8ebb9a
@@ -0,0 +1,28 @@
+#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 */
tools/virtio/linux/uaccess.h new file +37 -0
new file mode 100644
index 0000000..5874786
@@ -0,0 +1,37 @@
+#ifndef UACCESS_H
+#define UACCESS_H
+extern void *__user_addr_min, *__user_addr_max;
+
+#define get_user(dst, uptr) get_user_func(&(dst), (uptr), sizeof(*uptr))
+#define put_user(val, uptr) put_user_func(&(val), (uptr), sizeof(*uptr))
+
+static inline int get_user_func(void *dst, void *src, size_t size)
+{
+	assert(src >= __user_addr_min && src + size <= __user_addr_max);
+	memcpy(dst, src, size);
+	return 0;
+}
+
+static inline int put_user_func(void *val, void *dst, size_t size)
+{
+	assert(dst >= __user_addr_min && dst + size <= __user_addr_max);
+	memcpy(dst, val, size);
+	return 0;
+}
+
+static inline int copy_from_user(void *to, const void __user *from,
+				 unsigned long n)
+{
+	assert(from >= __user_addr_min && from + n <= __user_addr_max);
+	memcpy(to, from, n);
+	return 0;
+}
+
+static inline int copy_to_user(void __user *to, const void *from,
+			       unsigned long n)
+{
+	assert(to >= __user_addr_min && to + n <= __user_addr_max);
+	memcpy(to, from, n);
+	return 0;
+}
+#endif /* UACCESS_H */
tools/virtio/linux/uio.h new file +1 -0
new file mode 100644
index 0000000..ecbdf92
@@ -0,0 +1 @@
+#include "../../../include/linux/uio.h"
tools/virtio/linux/virtio.h +3 -149

178 lines not on this page · raw message

tools/virtio/linux/virtio_config.h new file +6 -0
new file mode 100644
index 0000000..5049967
@@ -0,0 +1,6 @@
+#define VIRTIO_TRANSPORT_F_START	28
+#define VIRTIO_TRANSPORT_F_END		32
+
+#define virtio_has_feature(dev, feature) \
+	test_bit((feature), (dev)->features)
+
tools/virtio/linux/virtio_ring.h new file +1 -0
new file mode 100644
index 0000000..8949c4e
@@ -0,0 +1 @@
+#include "../../../include/linux/virtio_ring.h"
tools/virtio/linux/vringh.h new file +1 -0
new file mode 100644
index 0000000..9348957
@@ -0,0 +1 @@
+#include "../../../include/linux/vringh.h"
tools/virtio/uapi/linux/uio.h new file +1 -0
new file mode 100644
index 0000000..7230e90
@@ -0,0 +1 @@
+#include <sys/uio.h>
tools/virtio/uapi/linux/virtio_config.h new file +1 -0
new file mode 100644
index 0000000..4c86675
@@ -0,0 +1 @@
+#include "../../../../include/uapi/linux/virtio_config.h"
tools/virtio/uapi/linux/virtio_ring.h new file +4 -0
new file mode 100644
index 0000000..4d99c78
@@ -0,0 +1,4 @@
+#ifndef VIRTIO_RING_H
+#define VIRTIO_RING_H
+#include "../../../../include/uapi/linux/virtio_ring.h"
+#endif /* VIRTIO_RING_H */
tools/virtio/virtio_test.c +4 -0
index a07142c..c613f25 100644
@@ -10,11 +10,15 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <linux/vhost.h>
 #include <linux/virtio.h>
 #include <linux/virtio_ring.h>
 #include "../../drivers/vhost/test.h"
 
+/* Unused */
+void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
+
 struct vq_info {
 	int kick;
 	int call;
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/5 tools/virtio: add vring_test.

In reply to Rusty Russell

This is mainly to test the drivers/vhost/vringh.c code, but it also uses the drivers/virtio/virtio_ring.c code for the guest side.

Usage for testing the basic implementation:

	./vringh_test
	# Test with indirect descriptors
	./vringh_test --indirect
	# Test with indirect descriptors and event indexex
	./vringh_test --indirect --eventidx

You can run a parallel stress test by adding --parallel to any of the above options.

eg ./vringh_test --parallel:

	Using CPUS 0 and 3
	Guest: notified 10107974, pinged 107970
	Host: notified 108158, pinged 3172148
	Time: R=17.659 U=6.640 S=6.640

./vringh_test --eventidx --parallel:

	Using CPUS 0 and 3
	Guest: notified 156357, pinged 156251
	Host: notified 156251, pinged 78179
	Time: R=4.518 U=3.536 S=3.536
---
 tools/virtio/Makefile      |    6 +-
 tools/virtio/vringh_test.c |  659 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 662 insertions(+), 3 deletions(-)
 create mode 100644 tools/virtio/vringh_test.c
tools/virtio/Makefile +3 -3
index d1d442e..e961545 100644
@@ -1,12 +1,12 @@
 all: test mod
-test: virtio_test
+test: virtio_test vringh_test
 virtio_test: virtio_ring.o virtio_test.o
-CFLAGS += -g -O2 -Wall -I. -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow  -MMD
+CFLAGS += -g -O2 -Wall -I. -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -Wno-unused-result -MMD
 vpath %.c ../../drivers/virtio
 mod:
 	${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test
 .PHONY: all test mod clean
 clean:
-	${RM} *.o vhost_test/*.o vhost_test/.*.cmd \
+	${RM} *.o vringh_test virtio_test vhost_test/*.o vhost_test/.*.cmd \
               vhost_test/Module.symvers vhost_test/modules.order *.d
 -include *.d
tools/virtio/vringh_test.c new file +659 -0

659 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#6 lore raw
In reply to Rusty Russell
Quoted 11 lines · Rusty Russell

This introduces vringh, which are generic accessors for virtio rings (host side). There's a host-side implementation in vhost, but it assumes that the rings are in userspace, and is tied to the vhost implementation. I have patches to adapt it to use vringh, but I'm pushing this in the next merge window for Sjur, who has CAIF patches which need it.

This also includes a test program in tools/virtio. There's a fixup patch for the current tools, since they didn't compile for me. MST?

Review and comments welcome!
Rusty.

Will review, thanks.
Okay so the plan is to merge this changeset for 3.9 and rework vhost for 3.10?

Signature · 1 line
MST
#7 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Rusty Russell

This introduces vringh, which are generic accessors for virtio rings (host side). There's a host-side implementation in vhost, but it assumes that the rings are in userspace, and is tied to the vhost implementation. I have patches to adapt it to use vringh, but I'm pushing this in the next merge window for Sjur, who has CAIF patches which need it.

This also includes a test program in tools/virtio. There's a fixup patch for the current tools, since they didn't compile for me. MST?

Quoted 6 lines
Quoted 2 lines

Review and comments welcome!
Rusty.

Will review, thanks.
Okay so the plan is to merge this changeset for 3.9 and rework vhost for 3.10?

I hope so, yes.

Thanks,
Rusty.

maintainer Acked-by on the v1 series
#8 lore raw
In reply to Rusty Russell
Quoted 11 lines · Rusty Russell

This introduces vringh, which are generic accessors for virtio rings (host side). There's a host-side implementation in vhost, but it assumes that the rings are in userspace, and is tied to the vhost implementation. I have patches to adapt it to use vringh, but I'm pushing this in the next merge window for Sjur, who has CAIF patches which need it.

This also includes a test program in tools/virtio. There's a fixup patch for the current tools, since they didn't compile for me. MST?

Review and comments welcome!
Rusty.

#9 lore raw

PATCH 1/1 tools/virtio: add sg_unmark_end to scatterlist.h

In reply to Rusty Russell

Add sg_unmark_end to scatterlist.h to fix compile.

---
 tools/virtio/linux/scatterlist.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/virtio/linux/scatterlist.h +16 -0
index b2cf7d0..68c9e2a 100644
@@ -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
Signature · 1 line
1.8.1
#11 lore raw

Re: [PATCH] tools/virtio: add sg_unmark_end to scatterlist.h

Quoted 9 lines · Rusty Russell
Quoted 3 lines · Wanlong Gao

Add sg_unmark_end to scatterlist.h to fix compile.

Thanks, I have the same patch in my series, which is in flux, but can be found in my pending-rebases branch:

https://git.kernel.org/?p=linux/kernel/git/rusty/linux.git;a=shortlog;h=refs/heads/pending-rebases

Nop, this patch is based on your pending-rebase actually, I didn't find it in this branch. Missing something?

Thanks,
Wanlong Gao

Quoted 4 lines

Cheers,
Rusty.

#12 lore raw

Re: [PATCH] tools/virtio: add sg_unmark_end to scatterlist.h

Quoted 6 lines · Wanlong Gao
Quoted 5 lines · Rusty Russell
Quoted 3 lines · Wanlong Gao

Add sg_unmark_end to scatterlist.h to fix compile.

Quoted 7 lines
Quoted 4 lines

Thanks, I have the same patch in my series, which is in flux, but can be found in my pending-rebases branch:

https://git.kernel.org/?p=linux/kernel/git/rusty/linux.git;a=shortlog;h=refs/heads/pending-rebases

Nop, this patch is based on your pending-rebase actually, I didn't find it in this branch. Missing something?

Looks like I pushed it just after you sent your original mail?

Thanks,
Rusty.

#13 lore raw

Re: [PATCH] tools/virtio: add sg_unmark_end to scatterlist.h

Quoted 11 lines · Rusty Russell
Quoted 9 lines · Wanlong Gao
Quoted 8 lines · Rusty Russell
Quoted 3 lines · Wanlong Gao

Add sg_unmark_end to scatterlist.h to fix compile.

Thanks, I have the same patch in my series, which is in flux, but can be found in my pending-rebases branch:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

https://git.kernel.org/?p=linux/kernel/git/rusty/linux.git;a=shortlog;h=refs/heads/pending-rebases

Nop, this patch is based on your pending-rebase actually, I didn't find it in this branch. Missing something?

Looks like I pushed it just after you sent your original mail?

Now, compiled, I find this commit 76fa98d7. Thank you for your time. ;)

Thanks,
Wanlong Gao

Quoted 4 lines

Thanks,
Rusty.