vhost: fix ranges when call vhost_iotlb_itree_first()
Subsystems (5)
v2 cover vhost: fix ranges when call vhost_iotlb_itree_first()
v2:
- Patch 2: Replaced Fixes tag with the right one [Jason]
v1: https://lore.kernel.org/virtualization/[email protected]/
While I was working on vringh to support VA in vringh_*_iotlb() I saw that the range we use in iotlb_translate() when we call vhost_iotlb_itree_first() was not correct IIUC.
So I looked at all the calls and found that in vhost.c as well.
I didn't observe a failure and I don't have a reproducer because I noticed the problem by looking at the code.
Maybe we didn't have a problem, because a shorter range was being returned anyway and the loop stopped taking into account the total amount of bytes translated, but I think it's better to fix.
Thanks,
Stefano
Stefano Garzarella (2):
vringh: fix range used in iotlb_translate()
vhost: fix range used in translate_desc()
drivers/vhost/vhost.c | 4 ++-- drivers/vhost/vringh.c | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-)
Signature · 6 lines
2.38.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 1/2 vringh: fix range used in iotlb_translate()
vhost_iotlb_itree_first() requires start and last parameters to search for a mapping that overlaps the range.
In iotlb_translate() 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.
--- drivers/vhost/vringh.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/vhost/vringh.c +2 -3
@@ -1102,7 +1102,7 @@ static int iotlb_translate(const struct vringh *vrh,struct vhost_iotlb_map *map;struct vhost_iotlb *iotlb = vrh->iotlb;int ret =0 ; -u64 s =0 ; +u64 s =0 , last = addr + len -1 ;spin_lock (vrh->iotlb_lock);
@@ -1114,8 +1114,7 @@ static int iotlb_translate(const struct vringh *vrh,break ; } - map =vhost_iotlb_itree_first (iotlb, addr, - addr + len -1 ); + map =vhost_iotlb_itree_first (iotlb, addr, last);if (!map || map->start > addr) { ret = -EINVAL ;break ;
Signature · 6 lines
2.38.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 2/2 vhost: fix range used in translate_desc()
In reply to Stefano Garzarellavhost_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.
---
v2:
- Replaced Fixes tag with the right one [Jason]
--- drivers/vhost/vhost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +2 -2
@@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,struct vhost_dev *dev = vq->dev;struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;struct iovec *_iov; -u64 s =0 ; +u64 s =0 , last = addr + len -1 ;int ret =0 ;while ((u64 )len > s) {
@@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,break ; } - map =vhost_iotlb_itree_first (umem, addr, addr + len -1 ); + map =vhost_iotlb_itree_first (umem, addr, last);if (map ==NULL || map->start > addr) {if (umem != dev->iotlb) { ret = -EFAULT ;
Signature · 6 lines
2.38.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization