From: Fang Xieyan <fangxy@xiaopeng.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
jasowangio@gmail.com, eperezma@redhat.com
Cc: stable@vger.kernel.org, fan.jiaming@hotmail.com,
xiongweimin@kylinos.cn, xieyongji@bytedance.com,
virtualization@lists.linux.dev, kvm@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] vhost-vdpa: use vma_lookup() in vhost_vdpa_va_map()
Date: Tue, 1 Dec 2026 17:17:22 +0800 [thread overview]
Message-ID: <20261201091722.46805-3-fangxy@xiaopeng.com> (raw)
In-Reply-To: <20261201091722.46805-1-fangxy@xiaopeng.com>
find_vma() returns the first VMA whose vm_end is past the address and
says nothing about vm_start. When uaddr lies in an unmapped gap,
vhost_vdpa_va_map() uses that VMA anyway: uaddr - vma->vm_start
wraps in u64 arithmetic, so map_file->offset becomes a file offset
that belongs to no VMA, and map_size counts the gap towards it.
Measured on v7.4-rc5: a request whose uaddr lies in a gap below a
file-backed VMA reaches the parent as dma_map with
offset=0xfffffffffffff000, and vhost_vdpa_map() has already added the
range to the IOTLB at that point, so the address space ends up
mapping bytes that no VMA backs.
Use vma_lookup(), which returns a VMA only when it holds the address:
unmapped bytes then fail the request with -EINVAL, as they do on the
physical address path, where pin_user_pages() cannot pin what no VMA
covers. When the first lookup fails, map_iova is still iova, so the
rollback calls vhost_vdpa_unmap() with size 0: that is what the
previous patch of this series closes.
Fixes: d8945ec41120 ("vdpa: Support transferring virtual addressing during DMA mapping")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20261126072414.97199-1-fangxy@xiaopeng.com/
Suggested-by: Jiaming Fan <fan.jiaming@hotmail.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
Base: v7.4-rc5.
Changes since v2:
- use vma_lookup() instead of skipping the gap, following Jiaming
Fan: skipping leaves a request with a hole in the middle partly
mapped, and userspace has no way to tell that from a request that
was mapped in full.
- drop the check for a gap covering the whole request, since
vma_lookup() cannot return a VMA starting above uaddr.
- the zero-size rollback is no longer left to another thread: it is
patch 1 of this series and it has to come first.
Boundary analysis:
- vma_lookup() returns a VMA only for vm_start <= uaddr < vm_end,
so uaddr - vm_start stays in [0, vm_end - vm_start) and cannot
wrap, and map_size = min(size, vm_end - uaddr) is between 1 and
size: the loop still advances on every iteration.
- a VMA that begins exactly at uaddr is returned, so a request
spanning two adjacent VMAs is still mapped as two segments, each
with the file offset of its own VMA.
- the lookup runs under the mmap_read_lock that the function
already takes.
- for a request that lies inside one VMA nothing changes at all.
- behaviour change: a request whose remaining bytes fall in a gap
now fails as a whole with -EINVAL instead of succeeding with the
gap left out. Measured on v7.4-rc5 with patch 1 applied: a one
page UPDATE with uaddr 0x1000 below a shared file-backed VMA was
mapped at file offset 0xfffffffffffff000, and a three page UPDATE
spanning VMA-gap-VMA was mapped in two segments, the second one at
that offset; both now return -EINVAL, and the segment mapped
before the gap is rolled back with its real size.
Testing:
- QEMU/KVM, the same four vhost_vdpa.ko states as in patch 1: the
underflowed file offset (offset=0xfffffffffffff000) shows up in
the parent's dma_map calls twice without this patch and not at all
with it.
- a request that spans two adjacent VMAs is still mapped as two
segments, each with the offset of its own VMA, unchanged in all
four states.
- patch 1 has to precede this one: with this patch alone, the
request that fails on a gap takes every mapping of the address
space with it, which is what patch 1 prevents.
- the defect is silent: the states without this patch show it with
no WARNING, BUG or Oops, and the fix adds none.
drivers/vhost/vdpa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 6cddd50..ac67e7e 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1152,7 +1152,7 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v,
mmap_read_lock(dev->mm);
while (size) {
- vma = find_vma(dev->mm, uaddr);
+ vma = vma_lookup(dev->mm, uaddr);
if (!vma) {
ret = -EINVAL;
break;
--
2.50.1
prev parent reply other threads:[~2026-12-01 9:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:17 [PATCH v3 0/2] vhost-vdpa: reject mappings over unmapped VA gaps Fang Xieyan
2026-12-01 9:17 ` [PATCH v3 1/2] vhost-vdpa: reject zero-size unmap Fang Xieyan
2026-12-01 9:17 ` Fang Xieyan [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=20261201091722.46805-3-fangxy@xiaopeng.com \
--to=fangxy@xiaopeng.com \
--cc=eperezma@redhat.com \
--cc=fan.jiaming@hotmail.com \
--cc=jasowangio@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=xieyongji@bytedance.com \
--cc=xiongweimin@kylinos.cn \
/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
all inboxes | Powered by JetHome®