Skip to contentSkip to conversation

fix up vringh/mic sparse errors

PATCH In review Michael S. Tsirkin 2 participants 5 messages Dec 15, 2014 – Dec 19, 2014

Subsystems (6)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover fix up vringh/mic sparse errors

This fixes remaining sparse warnings in vringh and mic by using virtio 1.0 compliant wrappers.

This also needs by get_user patches to avoid getting warnings from these calls.

Tested by running vringh_test.

Rusty, I prefer fixing all these warnings for 3.19, any objections?

Michael S. Tsirkin (3):
vringh: 64 bit features
vringh: initial virtio 1.0 support
mic/host: initial virtio 1.0 support

 include/linux/vringh.h              |  37 ++++++++++-
 drivers/misc/mic/host/mic_debugfs.c |  18 ++++--
 drivers/vhost/vringh.c              | 125 ++++++++++++++++++++++--------------
 3 files changed, 123 insertions(+), 57 deletions(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/3 vringh: 64 bit features

Pass u64 everywhere.

---
 include/linux/vringh.h | 4 ++--
 drivers/vhost/vringh.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/vringh.h +2 -2
index 749cde2..f696dd0 100644
@@ -105,7 +105,7 @@ struct vringh_kiov {
 #define VRINGH_IOV_ALLOCATED 0x8000000
 
 /* Helpers for userspace vrings. */
-int vringh_init_user(struct vringh *vrh, u32 features,
+int vringh_init_user(struct vringh *vrh, u64 features,
 		     unsigned int num, bool weak_barriers,
 		     struct vring_desc __user *desc,
 		     struct vring_avail __user *avail,
@@ -167,7 +167,7 @@ bool vringh_notify_enable_user(struct vringh *vrh);
 void vringh_notify_disable_user(struct vringh *vrh);
 
 /* Helpers for kernelspace vrings. */
-int vringh_init_kern(struct vringh *vrh, u32 features,
+int vringh_init_kern(struct vringh *vrh, u64 features,
 		     unsigned int num, bool weak_barriers,
 		     struct vring_desc *desc,
 		     struct vring_avail *avail,
drivers/vhost/vringh.c +2 -2
index 5174eba..ac3fe27 100644
@@ -577,7 +577,7 @@ static inline int xfer_to_user(void *dst, void *src, size_t len)
  * Returns an error if num is invalid: you should check pointers
  * yourself!
  */
-int vringh_init_user(struct vringh *vrh, u32 features,
+int vringh_init_user(struct vringh *vrh, u64 features,
 		     unsigned int num, bool weak_barriers,
 		     struct vring_desc __user *desc,
 		     struct vring_avail __user *avail,
@@ -836,7 +836,7 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
  *
  * Returns an error if num is invalid.
  */
-int vringh_init_kern(struct vringh *vrh, u32 features,
+int vringh_init_kern(struct vringh *vrh, u64 features,
 		     unsigned int num, bool weak_barriers,
 		     struct vring_desc *desc,
 		     struct vring_avail *avail,
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH 2/3 vringh: initial virtio 1.0 support

In reply to Michael S. Tsirkin
---
 include/linux/vringh.h |  33 ++++++++++++++
 drivers/vhost/vringh.c | 121 ++++++++++++++++++++++++++++++-------------------
 2 files changed, 107 insertions(+), 47 deletions(-)
include/linux/vringh.h +33 -0
index f696dd0..a3fa537 100644
@@ -24,12 +24,16 @@
 #ifndef _LINUX_VRINGH_H
 #define _LINUX_VRINGH_H
 #include <uapi/linux/virtio_ring.h>
+#include <linux/virtio_byteorder.h>
 #include <linux/uio.h>
 #include <linux/slab.h>
 #include <asm/barrier.h>
 
 /* virtio_ring with information needed for host access. */
 struct vringh {
+	/* Everything is little endian */
+	bool little_endian;
+
 	/* Guest publishes used event idx (note: we always do). */
 	bool event_indices;
 
@@ -222,4 +226,33 @@ static inline void vringh_notify(struct vringh *vrh)
 		vrh->notify(vrh);
 }
 
+static inline u16 vringh16_to_cpu(const struct vringh *vrh, __virtio16 val)
+{
+	return __virtio16_to_cpu(vrh->little_endian, val);
+}
+
+static inline __virtio16 cpu_to_vringh16(const struct vringh *vrh, u16 val)
+{
+	return __cpu_to_virtio16(vrh->little_endian, val);
+}
+
+static inline u32 vringh32_to_cpu(const struct vringh *vrh, __virtio32 val)
+{
+	return __virtio32_to_cpu(vrh->little_endian, val);
+}
+
+static inline __virtio32 cpu_to_vringh32(const struct vringh *vrh, u32 val)
+{
+	return __cpu_to_virtio32(vrh->little_endian, val);
+}
+
+static inline u64 vringh64_to_cpu(const struct vringh *vrh, __virtio64 val)
+{
+	return __virtio64_to_cpu(vrh->little_endian, val);
+}
+
+static inline __virtio64 cpu_to_vringh64(const struct vringh *vrh, u64 val)
+{
+	return __cpu_to_virtio64(vrh->little_endian, val);
+}
 #endif /* _LINUX_VRINGH_H */
drivers/vhost/vringh.c +74 -47

313 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH 3/3 mic/host: initial virtio 1.0 support

In reply to Michael S. Tsirkin

This just makes code sparse-clean.
The new feature bit is not yet negotiated.

---
 drivers/misc/mic/host/mic_debugfs.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/misc/mic/host/mic_debugfs.c +12 -6
index 028ba5d6..687e9aa 100644
@@ -326,21 +326,27 @@ static int mic_vdev_info_show(struct seq_file *s, void *unused)
 			}
 			avail = vrh->vring.avail;
 			seq_printf(s, "avail flags 0x%x idx %d\n",
-				   avail->flags, avail->idx & (num - 1));
+				   vringh16_to_cpu(vrh, avail->flags),
+				   vringh16_to_cpu(vrh, avail->idx) & (num - 1));
 			seq_printf(s, "avail flags 0x%x idx %d\n",
-				   avail->flags, avail->idx);
+				   vringh16_to_cpu(vrh, avail->flags),
+				   vringh16_to_cpu(vrh, avail->idx));
 			for (j = 0; j < num; j++)
 				seq_printf(s, "avail ring[%d] %d\n",
 					   j, avail->ring[j]);
 			used = vrh->vring.used;
 			seq_printf(s, "used flags 0x%x idx %d\n",
-				   used->flags, used->idx & (num - 1));
+				   vringh16_to_cpu(vrh, used->flags),
+				   vringh16_to_cpu(vrh, used->idx) & (num - 1));
 			seq_printf(s, "used flags 0x%x idx %d\n",
-				   used->flags, used->idx);
+				   vringh16_to_cpu(vrh, used->flags),
+				   vringh16_to_cpu(vrh, used->idx));
 			for (j = 0; j < num; j++)
 				seq_printf(s, "used ring[%d] id %d len %d\n",
-					   j, used->ring[j].id,
-					   used->ring[j].len);
+					   j, vringh32_to_cpu(vrh,
+							      used->ring[j].id),
+					   vringh32_to_cpu(vrh,
+							   used->ring[j].len));
 		}
 	}
 	mutex_unlock(&mdev->mic_mutex);
Signature · 1 line
MST
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

This fixes remaining sparse warnings in vringh and mic by using virtio 1.0 compliant wrappers.

This also needs by get_user patches to avoid getting warnings from these calls.

Tested by running vringh_test.

Rusty, I prefer fixing all these warnings for 3.19, any objections?

OK, I've queued these too.

Cheers,
Rusty.

Quoted 12 lines

Michael S. Tsirkin (3):
vringh: 64 bit features
vringh: initial virtio 1.0 support
mic/host: initial virtio 1.0 support

 include/linux/vringh.h              |  37 ++++++++++-
 drivers/misc/mic/host/mic_debugfs.c |  18 ++++--
 drivers/vhost/vringh.c              | 125 ++++++++++++++++++++++--------------
 3 files changed, 123 insertions(+), 57 deletions(-)
Signature · 1 line
MST