hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/vhost/vhost.c
....@@ -669,7 +669,7 @@
669669 }
670670 EXPORT_SYMBOL_GPL(vhost_dev_stop);
671671
672
-static void vhost_clear_msg(struct vhost_dev *dev)
672
+void vhost_clear_msg(struct vhost_dev *dev)
673673 {
674674 struct vhost_msg_node *node, *n;
675675
....@@ -687,6 +687,7 @@
687687
688688 spin_unlock(&dev->iotlb_lock);
689689 }
690
+EXPORT_SYMBOL_GPL(vhost_clear_msg);
690691
691692 void vhost_dev_cleanup(struct vhost_dev *dev)
692693 {
....@@ -1620,17 +1621,25 @@
16201621 r = -EFAULT;
16211622 break;
16221623 }
1623
- if (s.num > 0xffff) {
1624
- r = -EINVAL;
1625
- break;
1624
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {
1625
+ vq->last_avail_idx = s.num & 0xffff;
1626
+ vq->last_used_idx = (s.num >> 16) & 0xffff;
1627
+ } else {
1628
+ if (s.num > 0xffff) {
1629
+ r = -EINVAL;
1630
+ break;
1631
+ }
1632
+ vq->last_avail_idx = s.num;
16261633 }
1627
- vq->last_avail_idx = s.num;
16281634 /* Forget the cached index value. */
16291635 vq->avail_idx = vq->last_avail_idx;
16301636 break;
16311637 case VHOST_GET_VRING_BASE:
16321638 s.index = idx;
1633
- s.num = vq->last_avail_idx;
1639
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED))
1640
+ s.num = (u32)vq->last_avail_idx | ((u32)vq->last_used_idx << 16);
1641
+ else
1642
+ s.num = vq->last_avail_idx;
16341643 if (copy_to_user(argp, &s, sizeof s))
16351644 r = -EFAULT;
16361645 break;
....@@ -2041,7 +2050,7 @@
20412050 struct vhost_dev *dev = vq->dev;
20422051 struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
20432052 struct iovec *_iov;
2044
- u64 s = 0;
2053
+ u64 s = 0, last = addr + len - 1;
20452054 int ret = 0;
20462055
20472056 while ((u64)len > s) {
....@@ -2051,7 +2060,7 @@
20512060 break;
20522061 }
20532062
2054
- map = vhost_iotlb_itree_first(umem, addr, addr + len - 1);
2063
+ map = vhost_iotlb_itree_first(umem, addr, last);
20552064 if (map == NULL || map->start > addr) {
20562065 if (umem != dev->iotlb) {
20572066 ret = -EFAULT;