Re: [PATCH 2/2] vhost: fix range used in translate_desc()

From: Jason Wang
Date: Tue Nov 08 2022 - 22:29:56 EST


On Tue, Nov 8, 2022 at 6:34 PM Stefano Garzarella <sgarzare@xxxxxxxxxx> wrote:
>
> 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: 0bbe30668d89 ("vhost: factor out IOTLB")
> Signed-off-by: Stefano Garzarella <sgarzare@xxxxxxxxxx>
> ---
>
> I'm not sure about the fixes tag. On the one I used this patch should
> apply cleanly, but looking at the latest stable (4.9), maybe we should
> use
>
> Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree")

I think this should be the right commit to fix.

Other than this

Acked-by: Jason Wang <jasowang@xxxxxxxxxx>

Thanks

>
> Suggestions?
> ---
> drivers/vhost/vhost.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 40097826cff0..3c2359570df9 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -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;
> --
> 2.38.1
>