Skip to contentSkip to conversation

virtio: sparse fixes

PATCH In review Michael S. Tsirkin 5 participants 42 messages Dec 6, 2016 – Dec 12, 2016

Subsystems (22)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover virtio: sparse fixes

I run latest sparse from git on virtio drivers (turns out the version I had was rather outdated). This patchset fixes a couple of bugs this uncovered, and adds some annotations to make it sparse-clean. In particular, endian-ness is often tricky, so this patchset enabled endian-ness checks for sparse builds.

Michael S. Tsirkin (10):
virtio_console: drop unused config fields drm/virtio: fix endianness in primary_plane_update drm/virtio: fix lock context imbalance drm/virtio: annotate virtio_gpu_queue_ctrl_buffer_locked
vhost: make interval tree static inline
vhost: add missing __user annotations vsock/virtio: add a missing __le annotation vsock/virtio: mark an internal function static vsock/virtio: fix src/dst cid format
virtio: enable endian checks for sparse builds

 drivers/char/virtio_console.c           | 14 +++++++-------
 drivers/gpu/drm/virtio/virtgpu_plane.c  |  4 ++--
 drivers/gpu/drm/virtio/virtgpu_vq.c     |  6 +++++-
 drivers/vhost/vhost.c                   | 12 ++++++------
 net/vmw_vsock/virtio_transport.c        |  2 +-
 net/vmw_vsock/virtio_transport_common.c | 16 ++++++++--------
 drivers/block/Makefile                  |  1 +
 drivers/char/Makefile                   |  1 +
 drivers/char/hw_random/Makefile         |  2 ++
 drivers/gpu/drm/virtio/Makefile         |  1 +
 drivers/net/Makefile                    |  3 +++
 drivers/net/caif/Makefile               |  1 +
 drivers/rpmsg/Makefile                  |  1 +
 drivers/s390/virtio/Makefile            |  2 ++
 drivers/scsi/Makefile                   |  1 +
 drivers/vhost/Makefile                  |  1 +
 drivers/virtio/Makefile                 |  3 +++
 net/9p/Makefile                         |  1 +
 net/packet/Makefile                     |  1 +
 net/vmw_vsock/Makefile                  |  2 ++
 20 files changed, 50 insertions(+), 25 deletions(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/10 virtio_console: drop unused config fields

struct ports_device includes a config field including the whole virtio_console_config, but only max_nr_ports in there is ever updated or used. The rest is unused and in fact does not even mirror the device config. Drop everything except max_nr_ports,
saving some memory.

---
 drivers/char/virtio_console.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +7 -7
index 5649234..8b00e79 100644
@@ -152,8 +152,8 @@ struct ports_device {
 	spinlock_t c_ivq_lock;
 	spinlock_t c_ovq_lock;
 
-	/* The current config space is stored here */
-	struct virtio_console_config config;
+	/* max. number of ports this device can hold */
+	u32 max_nr_ports;
 
 	/* The virtio device we're associated with */
 	struct virtio_device *vdev;
@@ -1649,11 +1649,11 @@ static void handle_control_message(struct virtio_device *vdev,
 			break;
 		}
 		if (virtio32_to_cpu(vdev, cpkt->id) >=
-		    portdev->config.max_nr_ports) {
+		    portdev->max_nr_ports) {
 			dev_warn(&portdev->vdev->dev,
 				"Request for adding port with "
 				"out-of-bound id %u, max. supported id: %u\n",
-				cpkt->id, portdev->config.max_nr_ports - 1);
+				cpkt->id, portdev->max_nr_ports - 1);
 			break;
 		}
 		add_port(portdev, virtio32_to_cpu(vdev, cpkt->id));
@@ -1894,7 +1894,7 @@ static int init_vqs(struct ports_device *portdev)
 	u32 i, j, nr_ports, nr_queues;
 	int err;
 
-	nr_ports = portdev->config.max_nr_ports;
+	nr_ports = portdev->max_nr_ports;
 	nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
 
 	vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
@@ -2047,13 +2047,13 @@ static int virtcons_probe(struct virtio_device *vdev)
 	}
 
 	multiport = false;
-	portdev->config.max_nr_ports = 1;
+	portdev->max_nr_ports = 1;
 
 	/* Don't test MULTIPORT at all if we're rproc: not a valid feature! */
 	if (!is_rproc_serial(vdev) &&
 	    virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT,
 				 struct virtio_console_config, max_nr_ports,
-				 &portdev->config.max_nr_ports) == 0) {
+				 &portdev->max_nr_ports) == 0) {
 		multiport = true;
 	}
 
Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH 2/10 drm/virtio: fix endianness in primary_plane_update

In reply to Michael S. Tsirkin

virtio_gpu_cmd_transfer_to_host_2d expects x and y parameters in LE, but virtio_gpu_primary_plane_update passes in the CPU format instead.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -2
index ba28c0f..1fda965 100644
@@ -88,8 +88,8 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane,
 				(vgdev, handle, 0,
 				 cpu_to_le32(plane->state->src_w >> 16),
 				 cpu_to_le32(plane->state->src_h >> 16),
-				 plane->state->src_x >> 16,
-				 plane->state->src_y >> 16, NULL);
+				 cpu_to_le32(plane->state->src_x >> 16),
+				 cpu_to_le32(plane->state->src_y >> 16), NULL);
 		}
 	} else {
 		handle = 0;
Signature · 1 line
MST
author maintainer
#5 lore raw

PATCH 2/10 drm/virtio: fix endianness in primary_plane_update

In reply to Michael S. Tsirkin

virtio_gpu_cmd_transfer_to_host_2d expects x and y parameters in LE, but virtio_gpu_primary_plane_update passes in the CPU format instead.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -2
index ba28c0f..1fda965 100644
@@ -88,8 +88,8 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane,
 				(vgdev, handle, 0,
 				 cpu_to_le32(plane->state->src_w >> 16),
 				 cpu_to_le32(plane->state->src_h >> 16),
-				 plane->state->src_x >> 16,
-				 plane->state->src_y >> 16, NULL);
+				 cpu_to_le32(plane->state->src_x >> 16),
+				 cpu_to_le32(plane->state->src_y >> 16), NULL);
 		}
 	} else {
 		handle = 0;
Signature · 1 line
MST
author maintainer
#6 lore raw

PATCH 3/10 drm/virtio: fix lock context imbalance

In reply to Michael S. Tsirkin

When virtio_gpu_free_vbufs exits due to list empty, it does not drop the free_vbufs lock that it took.
list empty is not expected to happen anyway, but it can't hurt to fix this and drop the lock.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +3 -1
index 5a0f8a7..2f0c2f9 100644
@@ -109,8 +109,10 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
 
 	spin_lock(&vgdev->free_vbufs_lock);
 	for (i = 0; i < count; i++) {
-		if (WARN_ON(list_empty(&vgdev->free_vbufs)))
+		if (WARN_ON(list_empty(&vgdev->free_vbufs))) {
+			spin_unlock(&vgdev->free_vbufs_lock);
 			return;
+		}
 		vbuf = list_first_entry(&vgdev->free_vbufs,
 					struct virtio_gpu_vbuffer, list);
 		list_del(&vbuf->list);
Signature · 1 line
MST
author maintainer
#7 lore raw

PATCH 3/10 drm/virtio: fix lock context imbalance

In reply to Michael S. Tsirkin

When virtio_gpu_free_vbufs exits due to list empty, it does not drop the free_vbufs lock that it took.
list empty is not expected to happen anyway, but it can't hurt to fix this and drop the lock.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +3 -1
index 5a0f8a7..2f0c2f9 100644
@@ -109,8 +109,10 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
 
 	spin_lock(&vgdev->free_vbufs_lock);
 	for (i = 0; i < count; i++) {
-		if (WARN_ON(list_empty(&vgdev->free_vbufs)))
+		if (WARN_ON(list_empty(&vgdev->free_vbufs))) {
+			spin_unlock(&vgdev->free_vbufs_lock);
 			return;
+		}
 		vbuf = list_first_entry(&vgdev->free_vbufs,
 					struct virtio_gpu_vbuffer, list);
 		list_del(&vbuf->list);
Signature · 6 lines
MST

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#9 lore raw

PATCH 4/10 drm/virtio: annotate virtio_gpu_queue_ctrl_buffer_locked

In reply to Michael S. Tsirkin

virtio_gpu_queue_ctrl_buffer_locked is called with ctrlq.qlock taken, it releases and acquires this lock. This causes a sparse warning. Add appropriate annotations for sparse context checking.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -0
index 2f0c2f9..a6e2ce4 100644
@@ -297,6 +297,8 @@ void virtio_gpu_dequeue_cursor_func(struct work_struct *work)
 
 static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
 					       struct virtio_gpu_vbuffer *vbuf)
+		__releases(&vgdev->ctrlq.qlock)
+		__acquires(&vgdev->ctrlq.qlock)
 {
 	struct virtqueue *vq = vgdev->ctrlq.vq;
 	struct scatterlist *sgs[3], vcmd, vout, vresp;
Signature · 1 line
MST
author maintainer
#12 lore raw

PATCH 5/10 vhost: make interval tree static inline

In reply to Michael S. Tsirkin

vhost_umem_interval_tree is only used locally within vhost.c, mark it static. As some functions generated go unused, this triggers warnings unless we also mark it inline.

---
 drivers/vhost/vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vhost.c +1 -1
index c6f2d89..7331ef3 100644
@@ -49,7 +49,7 @@ enum {
 
 INTERVAL_TREE_DEFINE(struct vhost_umem_node,
 		     rb, __u64, __subtree_last,
-		     START, LAST, , vhost_umem_interval_tree);
+		     START, LAST, static inline, vhost_umem_interval_tree);
 
 #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
 static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)
Signature · 1 line
MST
author maintainer
#10 lore raw

PATCH 4/10 drm/virtio: annotate virtio_gpu_queue_ctrl_buffer_locked

In reply to Michael S. Tsirkin

virtio_gpu_queue_ctrl_buffer_locked is called with ctrlq.qlock taken, it releases and acquires this lock. This causes a sparse warning. Add appropriate annotations for sparse context checking.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -0
index 2f0c2f9..a6e2ce4 100644
@@ -297,6 +297,8 @@ void virtio_gpu_dequeue_cursor_func(struct work_struct *work)
 
 static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
 					       struct virtio_gpu_vbuffer *vbuf)
+		__releases(&vgdev->ctrlq.qlock)
+		__acquires(&vgdev->ctrlq.qlock)
 {
 	struct virtqueue *vq = vgdev->ctrlq.vq;
 	struct scatterlist *sgs[3], vcmd, vout, vresp;
Signature · 6 lines
MST

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#14 lore raw

PATCH 6/10 vhost: add missing __user annotations

In reply to Michael S. Tsirkin

Several vhost functions were missing __user annotations on pointers, causing sparse warnings. Fix this up.

---
 drivers/vhost/vhost.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/vhost.c +5 -5
index 7331ef3..ba7db68 100644
@@ -719,7 +719,7 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_umem *umem,
 static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 			  struct iovec iov[], int iov_size, int access);
 
-static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
+static int vhost_copy_to_user(struct vhost_virtqueue *vq, void __user *to,
 			      const void *from, unsigned size)
 {
 	int ret;
@@ -749,7 +749,7 @@ static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
 }
 
 static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
-				void *from, unsigned size)
+				void __user *from, unsigned size)
 {
 	int ret;
 
@@ -783,7 +783,7 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
 }
 
 static void __user *__vhost_get_user(struct vhost_virtqueue *vq,
-				     void *addr, unsigned size)
+				     void __user *addr, unsigned size)
 {
 	int ret;
 
@@ -934,8 +934,8 @@ static int umem_access_ok(u64 uaddr, u64 size, int access)
 	return 0;
 }
 
-int vhost_process_iotlb_msg(struct vhost_dev *dev,
-			    struct vhost_iotlb_msg *msg)
+static int vhost_process_iotlb_msg(struct vhost_dev *dev,
+				   struct vhost_iotlb_msg *msg)
 {
 	int ret = 0;
 
Signature · 1 line
MST
author maintainer
#16 lore raw

PATCH 6/10 vhost: add missing __user annotations

In reply to Michael S. Tsirkin

Several vhost functions were missing __user annotations on pointers, causing sparse warnings. Fix this up.

---
 drivers/vhost/vhost.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/vhost.c +5 -5
index 7331ef3..ba7db68 100644
@@ -719,7 +719,7 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_umem *umem,
 static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 			  struct iovec iov[], int iov_size, int access);
 
-static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
+static int vhost_copy_to_user(struct vhost_virtqueue *vq, void __user *to,
 			      const void *from, unsigned size)
 {
 	int ret;
@@ -749,7 +749,7 @@ static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
 }
 
 static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
-				void *from, unsigned size)
+				void __user *from, unsigned size)
 {
 	int ret;
 
@@ -783,7 +783,7 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
 }
 
 static void __user *__vhost_get_user(struct vhost_virtqueue *vq,
-				     void *addr, unsigned size)
+				     void __user *addr, unsigned size)
 {
 	int ret;
 
@@ -934,8 +934,8 @@ static int umem_access_ok(u64 uaddr, u64 size, int access)
 	return 0;
 }
 
-int vhost_process_iotlb_msg(struct vhost_dev *dev,
-			    struct vhost_iotlb_msg *msg)
+static int vhost_process_iotlb_msg(struct vhost_dev *dev,
+				   struct vhost_iotlb_msg *msg)
 {
 	int ret = 0;
 
Signature · 1 line
MST
author maintainer
#17 lore raw

PATCH 7/10 vsock/virtio: add a missing __le annotation

In reply to Michael S. Tsirkin

guest cid is read from config space, therefore it's in little endian format and is treated as such, annotate it accordingly.

---
 net/vmw_vsock/virtio_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport.c +1 -1
index 936d7ee..90096b9 100644
@@ -336,7 +336,7 @@ static void virtio_vsock_reset_sock(struct sock *sk)
 static void virtio_vsock_update_guest_cid(struct virtio_vsock *vsock)
 {
 	struct virtio_device *vdev = vsock->vdev;
-	u64 guest_cid;
+	__le64 guest_cid;
 
 	vdev->config->get(vdev, offsetof(struct virtio_vsock_config, guest_cid),
 			  &guest_cid, sizeof(guest_cid));
Signature · 1 line
MST
author maintainer
#20 lore raw

PATCH 8/10 vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
 net/vmw_vsock/virtio_transport_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +1 -1
index a53b3a1..6120384 100644
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
 	return container_of(t, struct virtio_transport, transport);
 }
 
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
 virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
 			   size_t len,
 			   u32 src_cid,
Signature · 1 line
MST
author maintainer
#26 lore raw

PATCH 8/10 vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
 net/vmw_vsock/virtio_transport_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +1 -1
index a53b3a1..6120384 100644
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
 	return container_of(t, struct virtio_transport, transport);
 }
 
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
 virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
 			   size_t len,
 			   u32 src_cid,
Signature · 1 line
MST
author maintainer
#27 lore raw

PATCH 9/10 vsock/virtio: fix src/dst cid format

In reply to Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
 net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/vmw_vsock/virtio_transport_common.c +7 -7
index 6120384..22e99c4 100644
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
 		return 0;
 
 	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
 					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
 					 le32_to_cpu(pkt->hdr.src_port));
 	if (!pkt)
 		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
 	struct virtio_vsock_pkt_info info = {
 		.op = VIRTIO_VSOCK_OP_RESPONSE,
 		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
 		.remote_port = le32_to_cpu(pkt->hdr.src_port),
 		.reply = true,
 	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
 	child->sk_state = SS_CONNECTED;
 
 	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
 			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
 			le32_to_cpu(pkt->hdr.src_port));
 
 	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
 	struct sock *sk;
 	bool space_available;
 
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
 			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
 			le32_to_cpu(pkt->hdr.dst_port));
 
 	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
Signature · 1 line
MST
author maintainer
#33 lore raw

PATCH 9/10 vsock/virtio: fix src/dst cid format

In reply to Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
 net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/vmw_vsock/virtio_transport_common.c +7 -7
index 6120384..22e99c4 100644
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
 		return 0;
 
 	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
 					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
 					 le32_to_cpu(pkt->hdr.src_port));
 	if (!pkt)
 		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
 	struct virtio_vsock_pkt_info info = {
 		.op = VIRTIO_VSOCK_OP_RESPONSE,
 		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
 		.remote_port = le32_to_cpu(pkt->hdr.src_port),
 		.reply = true,
 	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
 	child->sk_state = SS_CONNECTED;
 
 	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
 			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
 			le32_to_cpu(pkt->hdr.src_port));
 
 	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
 	struct sock *sk;
 	bool space_available;
 
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
 			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
 			le32_to_cpu(pkt->hdr.dst_port));
 
 	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
Signature · 1 line
MST
author maintainer
#34 lore raw

PATCH 10/10 virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

---

It seems that there should be a better way to do it, but this works too.

 drivers/block/Makefile          | 1 +
 drivers/char/Makefile           | 1 +
 drivers/char/hw_random/Makefile | 2 ++
 drivers/gpu/drm/virtio/Makefile | 1 +
 drivers/net/Makefile            | 3 +++
 drivers/net/caif/Makefile       | 1 +
 drivers/rpmsg/Makefile          | 1 +
 drivers/s390/virtio/Makefile    | 2 ++
 drivers/scsi/Makefile           | 1 +
 drivers/vhost/Makefile          | 1 +
 drivers/virtio/Makefile         | 3 +++
 net/9p/Makefile                 | 1 +
 net/packet/Makefile             | 1 +
 net/vmw_vsock/Makefile          | 2 ++
 14 files changed, 21 insertions(+)
drivers/block/Makefile +1 -0
index 1e9661e..597481c 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_BLK_DEV_OSD)	+= osdblk.o
 obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
 obj-$(CONFIG_BLK_DEV_NBD)	+= nbd.o
 obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o
+CFLAGS_virtio_blk.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_BLK)	+= virtio_blk.o
 
 obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
drivers/char/Makefile +1 -0
index 6e6c244..a99467d 100644
@@ -6,6 +6,7 @@ obj-y				+= mem.o random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
 obj-y				+= misc.o
 obj-$(CONFIG_ATARI_DSP56K)	+= dsp56k.o
+CFLAGS_virtio_console.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
 obj-$(CONFIG_RAW_DRIVER)	+= raw.o
 obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
drivers/char/hw_random/Makefile +2 -0
index 5f52b1e..a2b0931 100644
@@ -17,6 +17,8 @@ obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
 obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
 obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
 obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio-rng.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
 obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
 obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
drivers/gpu/drm/virtio/Makefile +1 -0
index 3fb8eac..1162366 100644
@@ -3,6 +3,7 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 ccflags-y := -Iinclude/drm
+ccflags-y += -D__CHECK_ENDIAN__
 
 virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_drm_bus.o virtgpu_gem.o \
 	virtgpu_fb.o virtgpu_display.o virtgpu_vq.o virtgpu_ttm.o \
drivers/net/Makefile +3 -0
index 7336cbd..3f587de 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_EQUALIZER) += eql.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACSEC) += macsec.o
 obj-$(CONFIG_MACVLAN) += macvlan.o
+CFLAGS_macvtap.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_MACVTAP) += macvtap.o
 obj-$(CONFIG_MII) += mii.o
 obj-$(CONFIG_MDIO) += mdio.o
@@ -20,8 +21,10 @@ obj-$(CONFIG_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_PHYLIB) += phy/
 obj-$(CONFIG_RIONET) += rionet.o
 obj-$(CONFIG_NET_TEAM) += team/
+CFLAGS_tun.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_TUN) += tun.o
 obj-$(CONFIG_VETH) += veth.o
+CFLAGS_virtio_net.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VXLAN) += vxlan.o
 obj-$(CONFIG_GENEVE) += geneve.o
drivers/net/caif/Makefile +1 -0
index 9bbd453..d1a922c 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_CAIF_HSI) += caif_hsi.o
 
 # Virtio interface
 obj-$(CONFIG_CAIF_VIRTIO) += caif_virtio.o
+CFLAGS_caif_virtio.o += -D__CHECK_ENDIAN__
drivers/rpmsg/Makefile +1 -0
index ae9c913..23c8b66 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
 obj-$(CONFIG_RPMSG_QCOM_SMD)	+= qcom_smd.o
 obj-$(CONFIG_RPMSG_VIRTIO)	+= virtio_rpmsg_bus.o
+CFLAGS_virtio_rpmsg_bus.o	+= -D__CHECK_ENDIAN__
drivers/s390/virtio/Makefile +2 -0
index df40692..270ada5 100644
@@ -6,6 +6,8 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
+CFLAGS_virtio_ccw.o += -D__CHECK_ENDIAN__
+CFLAGS_kvm_virtio.o += -D__CHECK_ENDIAN__
 s390-virtio-objs := virtio_ccw.o
 ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
 s390-virtio-objs += kvm_virtio.o
drivers/scsi/Makefile +1 -0
index 38d938d..9f70d46 100644
@@ -135,6 +135,7 @@ obj-$(CONFIG_SCSI_BNX2_ISCSI)	+= libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI)		+= libiscsi.o be2iscsi/
 obj-$(CONFIG_SCSI_ESAS2R)	+= esas2r/
 obj-$(CONFIG_SCSI_PMCRAID)	+= pmcraid.o
+CFLAGS_virtio_scsi.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_SCSI_VIRTIO)	+= virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)	+= vmw_pvscsi.o
 obj-$(CONFIG_XEN_SCSI_FRONTEND)	+= xen-scsifront.o
drivers/vhost/Makefile +1 -0
index 6b012b9..619e2cd 100644
@@ -1,3 +1,4 @@
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_VHOST_NET) += vhost_net.o
 vhost_net-y := net.o
 
drivers/virtio/Makefile +3 -0
index 41e30e3..d331f19 100644
@@ -1,3 +1,6 @@
+#virtio must be kept clean wrt endian tags,
+#otherwise we'll get to maintain broken host/guest ABIs
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
net/9p/Makefile +1 -0
index a0874cc..acf1225 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o
 	trans_fd.o \
 	trans_common.o \
 
+CFLAGS_trans_virtio.o += -D__CHECK_ENDIAN__
 9pnet_virtio-objs := \
 	trans_virtio.o \
 
net/packet/Makefile +1 -0
index 9df6134..a13bcb3 100644
@@ -2,6 +2,7 @@
 # Makefile for the packet AF.
 #
 
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_PACKET) += af_packet.o
 obj-$(CONFIG_PACKET_DIAG) += af_packet_diag.o
 af_packet_diag-y += diag.o
net/vmw_vsock/Makefile +2 -0
index bc27c70..a61eccb 100644
@@ -8,6 +8,8 @@ vsock-y += af_vsock.o vsock_addr.o
 vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
 	vmci_transport_notify_qstate.o
 
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio_transport_common.o += -D__CHECK_ENDIAN__
 vmw_vsock_virtio_transport-y += virtio_transport.o
 
 vmw_vsock_virtio_transport_common-y += virtio_transport_common.o
Signature · 6 lines
MST

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#41 lore raw

PATCH 10/10 virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

---

It seems that there should be a better way to do it, but this works too.

 drivers/block/Makefile          | 1 +
 drivers/char/Makefile           | 1 +
 drivers/char/hw_random/Makefile | 2 ++
 drivers/gpu/drm/virtio/Makefile | 1 +
 drivers/net/Makefile            | 3 +++
 drivers/net/caif/Makefile       | 1 +
 drivers/rpmsg/Makefile          | 1 +
 drivers/s390/virtio/Makefile    | 2 ++
 drivers/scsi/Makefile           | 1 +
 drivers/vhost/Makefile          | 1 +
 drivers/virtio/Makefile         | 3 +++
 net/9p/Makefile                 | 1 +
 net/packet/Makefile             | 1 +
 net/vmw_vsock/Makefile          | 2 ++
 14 files changed, 21 insertions(+)
drivers/block/Makefile +1 -0
index 1e9661e..597481c 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_BLK_DEV_OSD)	+= osdblk.o
 obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
 obj-$(CONFIG_BLK_DEV_NBD)	+= nbd.o
 obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o
+CFLAGS_virtio_blk.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_BLK)	+= virtio_blk.o
 
 obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
drivers/char/Makefile +1 -0
index 6e6c244..a99467d 100644
@@ -6,6 +6,7 @@ obj-y				+= mem.o random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
 obj-y				+= misc.o
 obj-$(CONFIG_ATARI_DSP56K)	+= dsp56k.o
+CFLAGS_virtio_console.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
 obj-$(CONFIG_RAW_DRIVER)	+= raw.o
 obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
drivers/char/hw_random/Makefile +2 -0
index 5f52b1e..a2b0931 100644
@@ -17,6 +17,8 @@ obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
 obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
 obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
 obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio-rng.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
 obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
 obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
drivers/gpu/drm/virtio/Makefile +1 -0
index 3fb8eac..1162366 100644
@@ -3,6 +3,7 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 ccflags-y := -Iinclude/drm
+ccflags-y += -D__CHECK_ENDIAN__
 
 virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_drm_bus.o virtgpu_gem.o \
 	virtgpu_fb.o virtgpu_display.o virtgpu_vq.o virtgpu_ttm.o \
drivers/net/Makefile +3 -0
index 7336cbd..3f587de 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_EQUALIZER) += eql.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACSEC) += macsec.o
 obj-$(CONFIG_MACVLAN) += macvlan.o
+CFLAGS_macvtap.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_MACVTAP) += macvtap.o
 obj-$(CONFIG_MII) += mii.o
 obj-$(CONFIG_MDIO) += mdio.o
@@ -20,8 +21,10 @@ obj-$(CONFIG_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_PHYLIB) += phy/
 obj-$(CONFIG_RIONET) += rionet.o
 obj-$(CONFIG_NET_TEAM) += team/
+CFLAGS_tun.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_TUN) += tun.o
 obj-$(CONFIG_VETH) += veth.o
+CFLAGS_virtio_net.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VXLAN) += vxlan.o
 obj-$(CONFIG_GENEVE) += geneve.o
drivers/net/caif/Makefile +1 -0
index 9bbd453..d1a922c 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_CAIF_HSI) += caif_hsi.o
 
 # Virtio interface
 obj-$(CONFIG_CAIF_VIRTIO) += caif_virtio.o
+CFLAGS_caif_virtio.o += -D__CHECK_ENDIAN__
drivers/rpmsg/Makefile +1 -0
index ae9c913..23c8b66 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
 obj-$(CONFIG_RPMSG_QCOM_SMD)	+= qcom_smd.o
 obj-$(CONFIG_RPMSG_VIRTIO)	+= virtio_rpmsg_bus.o
+CFLAGS_virtio_rpmsg_bus.o	+= -D__CHECK_ENDIAN__
drivers/s390/virtio/Makefile +2 -0
index df40692..270ada5 100644
@@ -6,6 +6,8 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
+CFLAGS_virtio_ccw.o += -D__CHECK_ENDIAN__
+CFLAGS_kvm_virtio.o += -D__CHECK_ENDIAN__
 s390-virtio-objs := virtio_ccw.o
 ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
 s390-virtio-objs += kvm_virtio.o
drivers/scsi/Makefile +1 -0
index 38d938d..9f70d46 100644
@@ -135,6 +135,7 @@ obj-$(CONFIG_SCSI_BNX2_ISCSI)	+= libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI)		+= libiscsi.o be2iscsi/
 obj-$(CONFIG_SCSI_ESAS2R)	+= esas2r/
 obj-$(CONFIG_SCSI_PMCRAID)	+= pmcraid.o
+CFLAGS_virtio_scsi.o += -D__CHECK_ENDIAN__
 obj-$(CONFIG_SCSI_VIRTIO)	+= virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)	+= vmw_pvscsi.o
 obj-$(CONFIG_XEN_SCSI_FRONTEND)	+= xen-scsifront.o
drivers/vhost/Makefile +1 -0
index 6b012b9..619e2cd 100644
@@ -1,3 +1,4 @@
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_VHOST_NET) += vhost_net.o
 vhost_net-y := net.o
 
drivers/virtio/Makefile +3 -0
index 41e30e3..d331f19 100644
@@ -1,3 +1,6 @@
+#virtio must be kept clean wrt endian tags,
+#otherwise we'll get to maintain broken host/guest ABIs
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
net/9p/Makefile +1 -0
index a0874cc..acf1225 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o
 	trans_fd.o \
 	trans_common.o \
 
+CFLAGS_trans_virtio.o += -D__CHECK_ENDIAN__
 9pnet_virtio-objs := \
 	trans_virtio.o \
 
net/packet/Makefile +1 -0
index 9df6134..a13bcb3 100644
@@ -2,6 +2,7 @@
 # Makefile for the packet AF.
 #
 
+ccflags-y := -D__CHECK_ENDIAN__
 obj-$(CONFIG_PACKET) += af_packet.o
 obj-$(CONFIG_PACKET_DIAG) += af_packet_diag.o
 af_packet_diag-y += diag.o
net/vmw_vsock/Makefile +2 -0
index bc27c70..a61eccb 100644
@@ -8,6 +8,8 @@ vsock-y += af_vsock.o vsock_addr.o
 vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
 	vmci_transport_notify_qstate.o
 
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio_transport_common.o += -D__CHECK_ENDIAN__
 vmw_vsock_virtio_transport-y += virtio_transport.o
 
 vmw_vsock_virtio_transport_common-y += virtio_transport_common.o
Signature · 1 line
MST
Reviewed-by on v1 1/10
#2 lore raw

Re: [PATCH 01/10] virtio_console: drop unused config fields

In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin

struct ports_device includes a config field including the whole virtio_console_config, but only max_nr_ports in there is ever updated or used. The rest is unused and in fact does not even mirror the device config. Drop everything except max_nr_ports,
saving some memory.

---
  drivers/char/virtio_console.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 45 lines
drivers/char/virtio_console.c +6 -6
index 5649234..8b00e79 100644
@@ -152,8 +152,8 @@ struct ports_device {
  	spinlock_t c_ivq_lock;
  	spinlock_t c_ovq_lock;
 
-	/* The current config space is stored here */
-	struct virtio_console_config config;
+	/* max. number of ports this device can hold */
+	u32 max_nr_ports;
 
  	/* The virtio device we're associated with */
  	struct virtio_device *vdev;
@@ -1649,11 +1649,11 @@ static void handle_control_message(struct virtio_device *vdev,
  			break;
  		}
  		if (virtio32_to_cpu(vdev, cpkt->id) >=
-		    portdev->config.max_nr_ports) {
+		    portdev->max_nr_ports) {
  			dev_warn(&portdev->vdev->dev,
  				"Request for adding port with "
  				"out-of-bound id %u, max. supported id: %u\n",
-				cpkt->id, portdev->config.max_nr_ports - 1);
+				cpkt->id, portdev->max_nr_ports - 1);
  			break;
  		}
  		add_port(portdev, virtio32_to_cpu(vdev, cpkt->id));
@@ -1894,7 +1894,7 @@ static int init_vqs(struct ports_device *portdev)
  	u32 i, j, nr_ports, nr_queues;
  	int err;
 
-	nr_ports = portdev->config.max_nr_ports;
+	nr_ports = portdev->max_nr_ports;
  	nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
 
  	vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
@@ -2047,13 +2047,13 @@ static int virtcons_probe(struct virtio_device *vdev)
  	}
 
  	multiport = false;
-	portdev->config.max_nr_ports = 1;
+	portdev->max_nr_ports = 1;

drivers/char/virtio_console.c static int virtcons_probe(struct virtio_device *vdev) · line 2059

Quoted 10 lines
drivers/char/virtio_console.c +1 -1
 
  	/* Don't test MULTIPORT at all if we're rproc: not a valid feature! */
  	if (!is_rproc_serial(vdev) &&
  	    virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT,
  				 struct virtio_console_config, max_nr_ports,
-				 &portdev->config.max_nr_ports) == 0) {
+				 &portdev->max_nr_ports) == 0) {
  		multiport = true;
  	}
 

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 2/10
#4 lore raw

Re: [PATCH 02/10] drm/virtio: fix endianness in primary_plane_update

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

virtio_gpu_cmd_transfer_to_host_2d expects x and y parameters in LE, but virtio_gpu_primary_plane_update passes in the CPU format instead.

---
  drivers/gpu/drm/virtio/virtgpu_plane.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +0 -0
index ba28c0f..1fda965 100644

drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_primary_plane_update(struct drm_plane *plane, · line 95

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -2
@@ -88,8 +88,8 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane,
  				(vgdev, handle, 0,
  				 cpu_to_le32(plane->state->src_w >> 16),
  				 cpu_to_le32(plane->state->src_h >> 16),
-				 plane->state->src_x >> 16,
-				 plane->state->src_y >> 16, NULL);
+				 cpu_to_le32(plane->state->src_x >> 16),
+				 cpu_to_le32(plane->state->src_y >> 16), NULL);
  		}
  	} else {
  		handle = 0;

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 3/10
#8 lore raw

Re: [PATCH 03/10] drm/virtio: fix lock context imbalance

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

When virtio_gpu_free_vbufs exits due to list empty, it does not drop the free_vbufs lock that it took.
list empty is not expected to happen anyway, but it can't hurt to fix this and drop the lock.

---
  drivers/gpu/drm/virtio/virtgpu_vq.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +0 -0
index 5a0f8a7..2f0c2f9 100644
@@ -109,8 +109,10 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
 

drivers/gpu/drm/virtio/virtgpu_vq.c void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev) · line 118

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +3 -1
  	spin_lock(&vgdev->free_vbufs_lock);
  	for (i = 0; i < count; i++) {
-		if (WARN_ON(list_empty(&vgdev->free_vbufs)))
+		if (WARN_ON(list_empty(&vgdev->free_vbufs))) {
+			spin_unlock(&vgdev->free_vbufs_lock);
  			return;
+		}
  		vbuf = list_first_entry(&vgdev->free_vbufs,
  					struct virtio_gpu_vbuffer, list);
  		list_del(&vbuf->list);

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 4/10
#11 lore raw

Re: [PATCH 04/10] drm/virtio: annotate virtio_gpu_queue_ctrl_buffer_locked

In reply to Michael S. Tsirkin
Quoted 14 lines · Michael S. Tsirkin

virtio_gpu_queue_ctrl_buffer_locked is called with ctrlq.qlock taken, it releases and acquires this lock. This causes a sparse warning. Add appropriate annotations for sparse context checking.

---
  drivers/gpu/drm/virtio/virtgpu_vq.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/virtio/virtgpu_vq.c +0 -0
index 2f0c2f9..a6e2ce4 100644

drivers/gpu/drm/virtio/virtgpu_vq.c void virtio_gpu_dequeue_cursor_func(struct work_struct *work) · line 304

Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -0
@@ -297,6 +297,8 @@ void virtio_gpu_dequeue_cursor_func(struct work_struct *work)
 
  static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
  					       struct virtio_gpu_vbuffer *vbuf)
+		__releases(&vgdev->ctrlq.qlock)
+		__acquires(&vgdev->ctrlq.qlock)
  {
  	struct virtqueue *vq = vgdev->ctrlq.vq;
  	struct scatterlist *sgs[3], vcmd, vout, vresp;

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 5/10
#13 lore raw

Re: [PATCH 05/10] vhost: make interval tree static inline

In reply to Michael S. Tsirkin
Quoted 14 lines · Michael S. Tsirkin

vhost_umem_interval_tree is only used locally within vhost.c, mark it static. As some functions generated go unused, this triggers warnings unless we also mark it inline.

---
  drivers/vhost/vhost.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vhost.c +0 -0
index c6f2d89..7331ef3 100644

drivers/vhost/vhost.c enum { · line 55

Quoted 8 lines
drivers/vhost/vhost.c +1 -1
@@ -49,7 +49,7 @@ enum {
 
  INTERVAL_TREE_DEFINE(struct vhost_umem_node,
  		     rb, __u64, __subtree_last,
-		     START, LAST, , vhost_umem_interval_tree);
+		     START, LAST, static inline, vhost_umem_interval_tree);
 
  #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
  static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#15 lore raw

Re: [PATCH 06/10] vhost: add missing __user annotations

In reply to Michael S. Tsirkin
Quoted 40 lines · Michael S. Tsirkin

Several vhost functions were missing __user annotations on pointers, causing sparse warnings. Fix this up.

---
  drivers/vhost/vhost.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/vhost.c +3 -3
index 7331ef3..ba7db68 100644
@@ -719,7 +719,7 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_umem *umem,
  static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
  			  struct iovec iov[], int iov_size, int access);
 
-static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
+static int vhost_copy_to_user(struct vhost_virtqueue *vq, void __user *to,
  			      const void *from, unsigned size)
  {
  	int ret;
@@ -749,7 +749,7 @@ static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to,
  }
 
  static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
-				void *from, unsigned size)
+				void __user *from, unsigned size)
  {
  	int ret;
 
@@ -783,7 +783,7 @@ static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
  }
 
  static void __user *__vhost_get_user(struct vhost_virtqueue *vq,
-				     void *addr, unsigned size)
+				     void __user *addr, unsigned size)
  {
  	int ret;
 

drivers/vhost/vhost.c static int umem_access_ok(u64 uaddr, u64 size, int access) · line 941

Quoted 10 lines
drivers/vhost/vhost.c +2 -2
@@ -934,8 +934,8 @@ static int umem_access_ok(u64 uaddr, u64 size, int access)
  	return 0;
  }
 
-int vhost_process_iotlb_msg(struct vhost_dev *dev,
-			    struct vhost_iotlb_msg *msg)
+static int vhost_process_iotlb_msg(struct vhost_dev *dev,
+				   struct vhost_iotlb_msg *msg)
  {
  	int ret = 0;
 

Patch looks good but this looks like another static conversion not __user annotations.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 7/10
#18 lore raw

Re: [PATCH 07/10] vsock/virtio: add a missing __le annotation

In reply to Michael S. Tsirkin
Quoted 13 lines · Michael S. Tsirkin

guest cid is read from config space, therefore it's in little endian format and is treated as such, annotate it accordingly.

---
  net/vmw_vsock/virtio_transport.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport.c +0 -0
index 936d7ee..90096b9 100644

net/vmw_vsock/virtio_transport.c static void virtio_vsock_reset_sock(struct sock *sk) · line 342

Quoted 8 lines
net/vmw_vsock/virtio_transport.c +1 -1
@@ -336,7 +336,7 @@ static void virtio_vsock_reset_sock(struct sock *sk)
  static void virtio_vsock_update_guest_cid(struct virtio_vsock *vsock)
  {
  	struct virtio_device *vdev = vsock->vdev;
-	u64 guest_cid;
+	__le64 guest_cid;
 
  	vdev->config->get(vdev, offsetof(struct virtio_vsock_config, guest_cid),
  			  &guest_cid, sizeof(guest_cid));

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#21 lore raw

Re: [PATCH 08/10] vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
  net/vmw_vsock/virtio_transport_common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index a53b3a1..6120384 100644

net/vmw_vsock/virtio_transport_common.c static const struct virtio_transport *virtio_transport_get_ops(void) · line 38

Quoted 8 lines
net/vmw_vsock/virtio_transport_common.c +1 -1
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
  	return container_of(t, struct virtio_transport, transport);
  }
 
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
  virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
  			   size_t len,
  			   u32 src_cid,

Git grep shows it was used by tracing.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#28 lore raw

Re: [PATCH 09/10] vsock/virtio: fix src/dst cid format

In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
  net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index 6120384..22e99c4 100644

net/vmw_vsock/virtio_transport_common.c static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt) · line 612

Quoted 9 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
  		return 0;
 
  	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
  					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
  					 le32_to_cpu(pkt->hdr.src_port));

Looking at sockaddr_vm, svm_cid is "unsigned int", do we really want 64 bit here?

Quoted 35 lines
net/vmw_vsock/virtio_transport_common.c +5 -5
  	if (!pkt)
  		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
  	struct virtio_vsock_pkt_info info = {
  		.op = VIRTIO_VSOCK_OP_RESPONSE,
  		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
  		.remote_port = le32_to_cpu(pkt->hdr.src_port),
  		.reply = true,
  	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
  	child->sk_state = SS_CONNECTED;
 
  	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
 
  	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
  	struct sock *sk;
  	bool space_available;
 
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
 
  	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
#31 lore raw

Re: [PATCH 09/10] vsock/virtio: fix src/dst cid format

In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
  net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index 6120384..22e99c4 100644

net/vmw_vsock/virtio_transport_common.c static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt) · line 612

Quoted 9 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
  		return 0;
 
  	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
  					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
  					 le32_to_cpu(pkt->hdr.src_port));

Looking at sockaddr_vm, svm_cid is "unsigned int", do we really want 64 bit here?

Quoted 25 lines
net/vmw_vsock/virtio_transport_common.c +3 -3
  	if (!pkt)
  		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
  	struct virtio_vsock_pkt_info info = {
  		.op = VIRTIO_VSOCK_OP_RESPONSE,
  		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
  		.remote_port = le32_to_cpu(pkt->hdr.src_port),
  		.reply = true,
  	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
  	child->sk_state = SS_CONNECTED;
 
  	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
 
  	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
  	struct sock *sk;

net/vmw_vsock/virtio_transport_common.c void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt) · line 912

Quoted 10 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
  	bool space_available;
 
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
 
  	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 10/10
#35 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

---

It seems that there should be a better way to do it, but this works too.

Quoted 181 lines
  drivers/block/Makefile          | 1 +
  drivers/char/Makefile           | 1 +
  drivers/char/hw_random/Makefile | 2 ++
  drivers/gpu/drm/virtio/Makefile | 1 +
  drivers/net/Makefile            | 3 +++
  drivers/net/caif/Makefile       | 1 +
  drivers/rpmsg/Makefile          | 1 +
  drivers/s390/virtio/Makefile    | 2 ++
  drivers/scsi/Makefile           | 1 +
  drivers/vhost/Makefile          | 1 +
  drivers/virtio/Makefile         | 3 +++
  net/9p/Makefile                 | 1 +
  net/packet/Makefile             | 1 +
  net/vmw_vsock/Makefile          | 2 ++
  14 files changed, 21 insertions(+)
drivers/block/Makefile +1 -0
index 1e9661e..597481c 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_BLK_DEV_OSD)	+= osdblk.o
  obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
  obj-$(CONFIG_BLK_DEV_NBD)	+= nbd.o
  obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o
+CFLAGS_virtio_blk.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_VIRTIO_BLK)	+= virtio_blk.o
 
  obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
drivers/char/Makefile +1 -0
index 6e6c244..a99467d 100644
@@ -6,6 +6,7 @@ obj-y				+= mem.o random.o
  obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
  obj-y				+= misc.o
  obj-$(CONFIG_ATARI_DSP56K)	+= dsp56k.o
+CFLAGS_virtio_console.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
  obj-$(CONFIG_RAW_DRIVER)	+= raw.o
  obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
drivers/char/hw_random/Makefile +2 -0
index 5f52b1e..a2b0931 100644
@@ -17,6 +17,8 @@ obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
  obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
  obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
  obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio-rng.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
  obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
  obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
drivers/gpu/drm/virtio/Makefile +1 -0
index 3fb8eac..1162366 100644
@@ -3,6 +3,7 @@
  # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
  ccflags-y := -Iinclude/drm
+ccflags-y += -D__CHECK_ENDIAN__
 
  virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_drm_bus.o virtgpu_gem.o \
  	virtgpu_fb.o virtgpu_display.o virtgpu_vq.o virtgpu_ttm.o \
drivers/net/Makefile +3 -0
index 7336cbd..3f587de 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_EQUALIZER) += eql.o
  obj-$(CONFIG_IFB) += ifb.o
  obj-$(CONFIG_MACSEC) += macsec.o
  obj-$(CONFIG_MACVLAN) += macvlan.o
+CFLAGS_macvtap.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_MACVTAP) += macvtap.o
  obj-$(CONFIG_MII) += mii.o
  obj-$(CONFIG_MDIO) += mdio.o
@@ -20,8 +21,10 @@ obj-$(CONFIG_NETCONSOLE) += netconsole.o
  obj-$(CONFIG_PHYLIB) += phy/
  obj-$(CONFIG_RIONET) += rionet.o
  obj-$(CONFIG_NET_TEAM) += team/
+CFLAGS_tun.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_TUN) += tun.o
  obj-$(CONFIG_VETH) += veth.o
+CFLAGS_virtio_net.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
  obj-$(CONFIG_VXLAN) += vxlan.o
  obj-$(CONFIG_GENEVE) += geneve.o
drivers/net/caif/Makefile +1 -0
index 9bbd453..d1a922c 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_CAIF_HSI) += caif_hsi.o
 
  # Virtio interface
  obj-$(CONFIG_CAIF_VIRTIO) += caif_virtio.o
+CFLAGS_caif_virtio.o += -D__CHECK_ENDIAN__
drivers/rpmsg/Makefile +1 -0
index ae9c913..23c8b66 100644
@@ -1,3 +1,4 @@
  obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
  obj-$(CONFIG_RPMSG_QCOM_SMD)	+= qcom_smd.o
  obj-$(CONFIG_RPMSG_VIRTIO)	+= virtio_rpmsg_bus.o
+CFLAGS_virtio_rpmsg_bus.o	+= -D__CHECK_ENDIAN__
drivers/s390/virtio/Makefile +2 -0
index df40692..270ada5 100644
@@ -6,6 +6,8 @@
  # it under the terms of the GNU General Public License (version 2 only)
  # as published by the Free Software Foundation.
 
+CFLAGS_virtio_ccw.o += -D__CHECK_ENDIAN__
+CFLAGS_kvm_virtio.o += -D__CHECK_ENDIAN__
  s390-virtio-objs := virtio_ccw.o
  ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
  s390-virtio-objs += kvm_virtio.o
drivers/scsi/Makefile +1 -0
index 38d938d..9f70d46 100644
@@ -135,6 +135,7 @@ obj-$(CONFIG_SCSI_BNX2_ISCSI)	+= libiscsi.o bnx2i/
  obj-$(CONFIG_BE2ISCSI)		+= libiscsi.o be2iscsi/
  obj-$(CONFIG_SCSI_ESAS2R)	+= esas2r/
  obj-$(CONFIG_SCSI_PMCRAID)	+= pmcraid.o
+CFLAGS_virtio_scsi.o += -D__CHECK_ENDIAN__
  obj-$(CONFIG_SCSI_VIRTIO)	+= virtio_scsi.o
  obj-$(CONFIG_VMWARE_PVSCSI)	+= vmw_pvscsi.o
  obj-$(CONFIG_XEN_SCSI_FRONTEND)	+= xen-scsifront.o
drivers/vhost/Makefile +1 -0
index 6b012b9..619e2cd 100644
@@ -1,3 +1,4 @@
+ccflags-y := -D__CHECK_ENDIAN__
  obj-$(CONFIG_VHOST_NET) += vhost_net.o
  vhost_net-y := net.o
 
drivers/virtio/Makefile +3 -0
index 41e30e3..d331f19 100644
@@ -1,3 +1,6 @@
+#virtio must be kept clean wrt endian tags,
+#otherwise we'll get to maintain broken host/guest ABIs
+ccflags-y := -D__CHECK_ENDIAN__
  obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
  obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
  obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
net/9p/Makefile +1 -0
index a0874cc..acf1225 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o
  	trans_fd.o \
  	trans_common.o \
 
+CFLAGS_trans_virtio.o += -D__CHECK_ENDIAN__
  9pnet_virtio-objs := \
  	trans_virtio.o \
 
net/packet/Makefile +1 -0
index 9df6134..a13bcb3 100644
@@ -2,6 +2,7 @@
  # Makefile for the packet AF.
  #
 
+ccflags-y := -D__CHECK_ENDIAN__
  obj-$(CONFIG_PACKET) += af_packet.o
  obj-$(CONFIG_PACKET_DIAG) += af_packet_diag.o
  af_packet_diag-y += diag.o
net/vmw_vsock/Makefile +0 -0
index bc27c70..a61eccb 100644

net/vmw_vsock/Makefile vsock-y += af_vsock.o vsock_addr.o · line 15

Quoted 8 lines
net/vmw_vsock/Makefile +2 -0
@@ -8,6 +8,8 @@ vsock-y += af_vsock.o vsock_addr.o
  vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
  	vmci_transport_notify_qstate.o
 
+CFLAGS_virtio_transport.o += -D__CHECK_ENDIAN__
+CFLAGS_virtio_transport_common.o += -D__CHECK_ENDIAN__
  vmw_vsock_virtio_transport-y += virtio_transport.o
 
  vmw_vsock_virtio_transport_common-y += virtio_transport_common.o

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#36 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin
Quoted 2 lines · Michael S. Tsirkin

It seems that there should be a better way to do it, but this works too.

In some cases there might be:

Quoted 9 lines
drivers/s390/virtio/Makefile +0 -0
@@ -6,6 +6,8 @@
  # it under the terms of the GNU General Public License (version 2
 only)
  # as published by the Free Software Foundation.

drivers/s390/virtio/Makefile +2 -0
+CFLAGS_virtio_ccw.o += -D__CHECK_ENDIAN__
+CFLAGS_kvm_virtio.o += -D__CHECK_ENDIAN__
Quoted 3 lines

 s390-virtio-objs := virtio_ccw.o
 ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
 s390-virtio-objs += kvm_virtio.o

Here you could use

ccflags-y += -D__CHECK_ENDIAN__

for example, or even

subdir-ccflags-y += -D__CHECK_ENDIAN__

(in case any subdirs ever get added here)

drivers/vhost/Makefile line 1

Quoted 4 lines
drivers/vhost/Makefile +1 -0
@@ -1,3 +1,4 @@
+ccflags-y := -D__CHECK_ENDIAN__

Looks like you did that here and in some other places though - so perhaps the s390 one was intentionally different?

Quoted 7 lines
net/packet/Makefile +0 -0
@@ -2,6 +2,7 @@
  # Makefile for the packet AF.
  #


+ccflags-y := -D__CHECK_ENDIAN__

Technically this is slightly more than advertised, but I guess that still makes sense if it's clean now.

johannes

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#38 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

Nah. Please just enable it globally when using sparse. I actually had a chat with Linus about that a while ago and he seemed generally fine with it, I just didn't manage to actually do it..

#39 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

Nah. Please just enable it globally when using sparse. I actually had a chat with Linus about that a while ago and he seemed generally fine with it, I just didn't manage to actually do it..

author maintainer
#37 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Johannes Berg
Quoted 22 lines · Johannes Berg
Quoted 2 lines · Michael S. Tsirkin

It seems that there should be a better way to do it, but this works too.

In some cases there might be:

Quoted 9 lines
drivers/s390/virtio/Makefile +0 -0
@@ -6,6 +6,8 @@
  # it under the terms of the GNU General Public License (version 2
 only)
  # as published by the Free Software Foundation.

drivers/s390/virtio/Makefile +2 -0
+CFLAGS_virtio_ccw.o += -D__CHECK_ENDIAN__
+CFLAGS_kvm_virtio.o += -D__CHECK_ENDIAN__
Quoted 3 lines

 s390-virtio-objs := virtio_ccw.o
 ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
 s390-virtio-objs += kvm_virtio.o

Here you could use

Quoted 7 lines

ccflags-y += -D__CHECK_ENDIAN__

for example, or even

subdir-ccflags-y += -D__CHECK_ENDIAN__

(in case any subdirs ever get added here)

Oh right. I forgot this directory only has virtio stuff.

Quoted 20 lines

drivers/vhost/Makefile line 1

Quoted 4 lines
drivers/vhost/Makefile +1 -0
@@ -1,3 +1,4 @@
+ccflags-y := -D__CHECK_ENDIAN__

Looks like you did that here and in some other places though - so perhaps the s390 one was intentionally different?

Quoted 7 lines
net/packet/Makefile +0 -0
@@ -2,6 +2,7 @@
  # Makefile for the packet AF.
  #


+ccflags-y := -D__CHECK_ENDIAN__

Technically this is slightly more than advertised, but I guess that still makes sense if it's clean now.

johannes

maintainer Reviewed-by on v1 7/10
#19 lore raw

Re: [PATCH 07/10] vsock/virtio: add a missing __le annotation

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin

guest cid is read from config space, therefore it's in little endian format and is treated as such, annotate it accordingly.

---
 net/vmw_vsock/virtio_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

maintainer Reviewed-by on v1 8/10
#25 lore raw

Re: [PATCH 08/10] vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
 net/vmw_vsock/virtio_transport_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

maintainer Reviewed-by on v1 9/10
#32 lore raw

Re: [PATCH 09/10] vsock/virtio: fix src/dst cid format

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
 net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

maintainer Reviewed-by on v1 10/10
#40 lore raw

Re: [PATCH 10/10] virtio: enable endian checks for sparse builds

In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin

__CHECK_ENDIAN__ isn't on by default presumably because it triggers too many sparse warnings for correct code. But virtio is now clean of these warnings, and we want to keep it this way - enable this for sparse builds.

---

It seems that there should be a better way to do it, but this works too.

Quoted 15 lines
 drivers/block/Makefile          | 1 +
 drivers/char/Makefile           | 1 +
 drivers/char/hw_random/Makefile | 2 ++
 drivers/gpu/drm/virtio/Makefile | 1 +
 drivers/net/Makefile            | 3 +++
 drivers/net/caif/Makefile       | 1 +
 drivers/rpmsg/Makefile          | 1 +
 drivers/s390/virtio/Makefile    | 2 ++
 drivers/scsi/Makefile           | 1 +
 drivers/vhost/Makefile          | 1 +
 drivers/virtio/Makefile         | 3 +++
 net/9p/Makefile                 | 1 +
 net/packet/Makefile             | 1 +
 net/vmw_vsock/Makefile          | 2 ++
 14 files changed, 21 insertions(+)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author maintainer
#22 lore raw

Re: [PATCH 08/10] vsock/virtio: mark an internal function static

In reply to Jason Wang
Quoted 10 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
  net/vmw_vsock/virtio_transport_common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

net/vmw_vsock/virtio_transport_common.c static const struct virtio_transport *virtio_transport_get_ops(void) · line 37

Quoted 12 lines
net/vmw_vsock/virtio_transport_common.c +1 -1
index a53b3a1..6120384 100644
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
  	return container_of(t, struct virtio_transport, transport);
  }
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
  virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
  			   size_t len,
  			   u32 src_cid,

Git grep shows it was used by tracing.

True but trace_virtio_transport_alloc_pkt is also local to virtio_transport_common.c

Signature · 5 lines
MST
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author maintainer
#29 lore raw

Re: [PATCH 09/10] vsock/virtio: fix src/dst cid format

In reply to Jason Wang
Quoted 13 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
  net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 16 lines

net/vmw_vsock/virtio_transport_common.c static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt) · line 611

Quoted 13 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
index 6120384..22e99c4 100644
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
  		return 0;
  	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
  					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
  					 le32_to_cpu(pkt->hdr.src_port));

Looking at sockaddr_vm, svm_cid is "unsigned int", do we really want 64 bit here?

Can't change the protocol at this point.

Quoted 31 lines
Quoted 31 lines
net/vmw_vsock/virtio_transport_common.c +5 -5
  	if (!pkt)
  		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
  	struct virtio_vsock_pkt_info info = {
  		.op = VIRTIO_VSOCK_OP_RESPONSE,
  		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
  		.remote_port = le32_to_cpu(pkt->hdr.src_port),
  		.reply = true,
  	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
  	child->sk_state = SS_CONNECTED;
  	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
  	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
  	struct sock *sk;
  	bool space_available;
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
  	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
author maintainer
#30 lore raw

Re: [PATCH 09/10] vsock/virtio: fix src/dst cid format

In reply to Jason Wang
Quoted 13 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin

These fields are 64 bit, using le32_to_cpu and friends on these will not do the right thing.
Fix this up.

---
  net/vmw_vsock/virtio_transport_common.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 16 lines

net/vmw_vsock/virtio_transport_common.c static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt) · line 611

Quoted 13 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
index 6120384..22e99c4 100644
@@ -606,9 +606,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
  		return 0;
  	pkt = virtio_transport_alloc_pkt(&info, 0,
-					 le32_to_cpu(pkt->hdr.dst_cid),
+					 le64_to_cpu(pkt->hdr.dst_cid),
  					 le32_to_cpu(pkt->hdr.dst_port),
-					 le32_to_cpu(pkt->hdr.src_cid),
+					 le64_to_cpu(pkt->hdr.src_cid),
  					 le32_to_cpu(pkt->hdr.src_port));

Looking at sockaddr_vm, svm_cid is "unsigned int", do we really want 64 bit here?

Can't change the protocol at this point.

Quoted 23 lines
Quoted 23 lines
net/vmw_vsock/virtio_transport_common.c +3 -3
  	if (!pkt)
  		return -ENOMEM;
@@ -823,7 +823,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
  	struct virtio_vsock_pkt_info info = {
  		.op = VIRTIO_VSOCK_OP_RESPONSE,
  		.type = VIRTIO_VSOCK_TYPE_STREAM,
-		.remote_cid = le32_to_cpu(pkt->hdr.src_cid),
+		.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
  		.remote_port = le32_to_cpu(pkt->hdr.src_port),
  		.reply = true,
  	};
@@ -863,9 +863,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
  	child->sk_state = SS_CONNECTED;
  	vchild = vsock_sk(child);
-	vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
-	vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
  	vsock_insert_connected(vchild);
@@ -904,9 +904,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
  	struct sock *sk;
Quoted 8 lines

net/vmw_vsock/virtio_transport_common.c void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt) · line 912

Quoted 8 lines
net/vmw_vsock/virtio_transport_common.c +2 -2
  	bool space_available;
-	vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid),
+	vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
  			le32_to_cpu(pkt->hdr.src_port));
-	vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid),
+	vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
  			le32_to_cpu(pkt->hdr.dst_port));
  	trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#23 lore raw

Re: [PATCH 08/10] vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin
Quoted 23 lines · Michael S. Tsirkin
Quoted 9 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
   net/vmw_vsock/virtio_transport_common.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

net/vmw_vsock/virtio_transport_common.c static const struct virtio_transport *virtio_transport_get_ops(void) · line 37

Quoted 12 lines
net/vmw_vsock/virtio_transport_common.c +1 -1
index a53b3a1..6120384 100644
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
   	return container_of(t, struct virtio_transport, transport);
   }
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
   virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
   			   size_t len,
   			   u32 src_cid,

Git grep shows it was used by tracing.

Quoted 3 lines

True but trace_virtio_transport_alloc_pkt is also local to virtio_transport_common.c

I see, so let's remove the EXPORT_SYMBOL_GPL() too?

#24 lore raw

Re: [PATCH 08/10] vsock/virtio: mark an internal function static

In reply to Michael S. Tsirkin
Quoted 23 lines · Michael S. Tsirkin
Quoted 9 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin

virtio_transport_alloc_pkt is only used locally, make it static.

---
   net/vmw_vsock/virtio_transport_common.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

net/vmw_vsock/virtio_transport_common.c static const struct virtio_transport *virtio_transport_get_ops(void) · line 37

Quoted 12 lines
net/vmw_vsock/virtio_transport_common.c +1 -1
index a53b3a1..6120384 100644
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
   	return container_of(t, struct virtio_transport, transport);
   }
-struct virtio_vsock_pkt *
+static struct virtio_vsock_pkt *
   virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
   			   size_t len,
   			   u32 src_cid,

Git grep shows it was used by tracing.

Quoted 3 lines

True but trace_virtio_transport_alloc_pkt is also local to virtio_transport_common.c

I see, so let's remove the EXPORT_SYMBOL_GPL() too?
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization