Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vhost-vdpa: inconsistent unmapped gap handling in
  vhost_vdpa_va_map()
--

commit 32b0d078e53a97a709c1be4706495eeda3a12b09
Author: Fang Xieyan <[email protected]>

vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map()

This commit skips unmapped virtual address gaps before a VMA in
vhost_vdpa_va_map() so the file offset calculation does not underflow
when uaddr lies below vma->vm_start.

> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index c912ac40ca375..091aa58d2d977 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1154,6 +1154,19 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v,
>                       ret = -EINVAL;
>                       break;
>               }
> +             /*
> +              * uaddr may lie in an unmapped gap before vma->vm_start; skip
> +              * the gap so the offset calculation below uses an address in 
> the VMA.
> +              */
> +             if (uaddr < vma->vm_start) {
> +                     u64 gap = vma->vm_start - uaddr;
> +
> +                     if (gap >= size)
> +                             break;
> +                     size -= gap;
> +                     uaddr = vma->vm_start;
> +                     map_iova += gap;
> +             }
>               map_size = min(size, vma->vm_end - uaddr);
>               if (!(vma->vm_file && (vma->vm_flags & VM_SHARED) &&
>                       !(vma->vm_flags & (VM_IO | VM_PFNMAP))))

[Severity: Medium]
Should an unmapped gap at the end of [uaddr, uaddr + size) be handled
the same way regardless of whether an unrelated VMA exists at a higher
address in dev->mm?

find_vma(dev->mm, uaddr) searches up to ULONG_MAX rather than uaddr +
size.  If an unmapped gap (either the whole request or a trailing portion
after valid VMAs) has any unrelated VMA above it in dev->mm, such as the
stack or vDSO, find_vma() returns that VMA with gap >= size and the loop
exits with ret = 0, keeping any mappings created in earlier iterations.
If no VMA exists above uaddr in dev->mm, find_vma() returns NULL,
setting ret = -EINVAL and calling vhost_vdpa_unmap() to tear down all
valid VMA mappings already established earlier in the same request.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to