Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fang Xieyan" <fangxy@xiaopeng.com>
Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map()
Date: Tue, 24 Nov 2026 14:33:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-231354@kernel.org> (raw)
In-Reply-To: <20261123143318.73514-1-fangxy@xiaopeng.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] vhost-vdpa: inconsistent handling of unmapped gaps in
  vhost_vdpa_va_map()
- [Low] vhost-vdpa: redundant find_vma() call after gap skip in
  vhost_vdpa_va_map()
--

commit 47702b500dd411149b51bf05337d951339f690bc
Author: Fang Xieyan <fangxy@xiaopeng.com>

vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map()

This commit skips unmapped virtual address gaps before vma->vm_start 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..2707be470a1f6 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1154,6 +1154,20 @@ 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;

[Severity: Medium]
Does this handle an unmapped gap at the end of the address space
differently from a gap below a higher VMA?

When the remaining range [uaddr, uaddr + size) is an unmapped gap and any
unrelated VMA exists at a higher address in dev->mm, find_vma() returns
that VMA and gap >= size breaks out of the loop with ret = 0.  If the same
unmapped gap lies above the highest VMA in dev->mm, find_vma() returns
NULL, setting ret = -EINVAL and causing vhost_vdpa_unmap() to tear down
any valid VMA mappings already created earlier in the loop:

drivers/vhost/vdpa.c:vhost_vdpa_va_map() {
	...
	while (size) {
		vma = find_vma(dev->mm, uaddr);
		if (!vma) {
			ret = -EINVAL;
			break;
		}
	...
	if (ret)
		vhost_vdpa_unmap(v, iotlb, iova, map_iova - iova);
}

> +			size -= gap;
> +			uaddr = vma->vm_start;
> +			map_iova += gap;
> +			continue;
> +		}
>  		map_size = min(size, vma->vm_end - uaddr);

[Severity: Low]
Does the continue statement here cause a redundant find_vma() tree walk on
the next iteration?  Since vma already points to the VMA starting at
vma->vm_start under mmap_read_lock(dev->mm), falling through to map_size
would use vma directly without looking up vma->vm_start a second time.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123143318.73514-1-fangxy@xiaopeng.com?part=1

      reply	other threads:[~2026-11-24 14:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 14:33 [PATCH] vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map() Fang Xieyan
2026-11-24 14:33 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231354@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=fangxy@xiaopeng.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox