Skip to content

Commit 9804731

Browse files
stefano-garzarellamstsirkin
authored andcommitted
vhost: fix range used in translate_desc()
vhost_iotlb_itree_first() requires `start` and `last` parameters to search for a mapping that overlaps the range. In translate_desc() we cyclically call vhost_iotlb_itree_first(), incrementing `addr` by the amount already translated, so rightly we move the `start` parameter passed to vhost_iotlb_itree_first(), but we should hold the `last` parameter constant. Let's fix it by saving the `last` parameter value before incrementing `addr` in the loop. Fixes: a9709d6 ("vhost: convert pre sorted vhost memory array to interval tree") Acked-by: Jason Wang <[email protected]> Signed-off-by: Stefano Garzarella <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent f85efa9 commit 9804731

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/vhost/vhost.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
20532053
struct vhost_dev *dev = vq->dev;
20542054
struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
20552055
struct iovec *_iov;
2056-
u64 s = 0;
2056+
u64 s = 0, last = addr + len - 1;
20572057
int ret = 0;
20582058

20592059
while ((u64)len > s) {
@@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
20632063
break;
20642064
}
20652065

2066-
map = vhost_iotlb_itree_first(umem, addr, addr + len - 1);
2066+
map = vhost_iotlb_itree_first(umem, addr, last);
20672067
if (map == NULL || map->start > addr) {
20682068
if (umem != dev->iotlb) {
20692069
ret = -EFAULT;

0 commit comments

Comments
 (0)