On 2018年08月03日 15:59, Michael S. Tsirkin wrote:
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index a502f1a..6f6c42d 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -315,6 +315,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
        vq->log_addr = -1ull;
        vq->private_data = NULL;
        vq->acked_features = 0;
+       vq->acked_backend_features = 0;
        vq->log_base = NULL;
        vq->error_ctx = NULL;
        vq->kick = NULL;
@@ -1027,28 +1028,40 @@ static int vhost_process_iotlb_msg(struct vhost_dev 
*dev,
  ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
                             struct iov_iter *from)
  {
-       struct vhost_msg_node node;
-       unsigned size = sizeof(struct vhost_msg);
-       size_t ret;
-       int err;
+       struct vhost_iotlb_msg msg;
+       size_t offset;
+       int type, ret;
- if (iov_iter_count(from) < size)
-               return 0;
-       ret = copy_from_iter(&node.msg, size, from);
-       if (ret != size)
+       ret = copy_from_iter(&type, sizeof(type), from);
+       if (ret != sizeof(type))
                goto done;
- switch (node.msg.type) {
+       switch (type) {
        case VHOST_IOTLB_MSG:
-               err = vhost_process_iotlb_msg(dev, &node.msg.iotlb);
-               if (err)
-                       ret = err;
+               /* There maybe a hole after type for V1 message type,
+                * so skip it here.
+                */
+               offset = offsetof(struct vhost_msg, iotlb) - sizeof(int);
+               break;
+       case VHOST_IOTLB_MSG_V2:
+               offset = sizeof(__u32);
                break;
        default:
                ret = -EINVAL;
-               break;
+               goto done;
+       }
+
+       iov_iter_advance(from, offset);
+       ret = copy_from_iter(&msg, sizeof(msg), from);
+       if (ret != sizeof(msg))
+               goto done;
+       if (vhost_process_iotlb_msg(dev, &msg)) {
+               ret = -EFAULT;
+               goto done;
        }
+ ret = (type == VHOST_IOTLB_MSG) ? sizeof(struct vhost_msg) :
+             sizeof(struct vhost_msg_v2);
  done:
        return ret;
  }
We can actually fix 32 bit apps too, checking the mode for v1.
But that can wait for another patch.


Yes, let me do it on top.

Thanks

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

Reply via email to