vhost: handle error while adding split ranges to iotlb
authorAnirudh Rayabharam <mail@anirudhrb.com>
Sat, 12 Mar 2022 14:11:21 +0000 (19:41 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:24:12 +0000 (14:24 +0200)
commit 03a91c9af2c42ae14afafb829a4b7e6589ab5892 upstream.

vhost_iotlb_add_range_ctx() handles the range [0, ULONG_MAX] by
splitting it into two ranges and adding them separately. The return
value of adding the first range to the iotlb is currently ignored.
Check the return value and bail out in case of an error.

Signed-off-by: Anirudh Rayabharam <mail@anirudhrb.com>
Link: https://lore.kernel.org/r/20220312141121.4981-1-mail@anirudhrb.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Fixes: e2ae38cf3d91 ("vhost: fix hung thread due to erroneous iotlb entries")
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/vhost/iotlb.c

index 40b0983..5829cf2 100644 (file)
@@ -62,8 +62,12 @@ int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb,
         */
        if (start == 0 && last == ULONG_MAX) {
                u64 mid = last / 2;
+               int err = vhost_iotlb_add_range_ctx(iotlb, start, mid, addr,
+                               perm, opaque);
+
+               if (err)
+                       return err;
 
-               vhost_iotlb_add_range_ctx(iotlb, start, mid, addr, perm, opaque);
                addr += mid + 1;
                start = mid + 1;
        }