From: Fang Xieyan <fangxy@xiaopeng.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
jasowangio@gmail.com, eperezma@redhat.com
Cc: xiongweimin <xiongweimin@kylinos.cn>,
fan.jiaming@hotmail.com, xieyongji@bytedance.com,
virtualization@lists.linux.dev, kvm@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/2] vhost-vdpa: reject zero-size unmap
Date: Tue, 1 Dec 2026 17:17:21 +0800 [thread overview]
Message-ID: <20261201091722.46805-2-fangxy@xiaopeng.com> (raw)
In-Reply-To: <20261201091722.46805-1-fangxy@xiaopeng.com>
From: xiongweimin <xiongweimin@kylinos.cn>
Reject unmap requests with size == 0 to prevent iova + size - 1
from underflowing to U64_MAX, which would incorrectly unmap the
entire IOTLB range.
This fix also covers the error rollback path in vhost_vdpa_va_map:
when the first VMA lookup fails, map_iova equals iova, resulting
in a zero-size unmap that would otherwise clear the whole IOTLB.
Fixes: 4c8cf31885f6 ("vhost: introduce vDPA-based backend")
Link: https://lore.kernel.org/all/20260716030238.124368-1-xiongwm2026@163.com/
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: xiongweimin <xiongweimin@kylinos.cn>
[Fang Xieyan: acbf36deb53d ("vdpa: invalidate DMA mappings before
releasing memory") made vhost_vdpa_unmap() return an int and
moved the set_map branch below the range calculation, so the
guard returns 0 now and sits after the declarations. Added the
Fixes tag. No other change.]
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
Base: v7.4-rc5.
Resend of Weimin Xiong's 2026-07-16 patch with his authorship and
Eugenio's Acked-by kept, so that patch 2 has something to build on.
The v3 numbers the series; the change itself is posted for the first
time since July. acbf36deb53d ("vdpa: invalidate DMA mappings before
releasing memory", v7.4-rc2) made vhost_vdpa_unmap() return int, so
the July hunk no longer applies, and dropped into v7.4-rc5 unchanged
it does not compile:
drivers/vhost/vdpa.c:1122:3: error: 'return' with no value, in
function returning non-void [-Werror=return-type]
Still open on v7.4-rc5: the userspace entry point is covered,
vhost_vdpa_process_iotlb_msg() rejects a zero-size INVALIDATE at
vdpa.c:1385, but the error rollback of vhost_vdpa_va_map() reaches
the sink at vdpa.c:1183 and passes size 0 whenever the first lookup
fails, which is also what a VDUSE-shaped set_map-only parent sees.
No Cc stable: ca50ec377c2e9 ("vhost: Allow null msg.size on
VHOST_IOTLB_INVALIDATE", v6.6, Cc stable # v5.17+) restored the null
size as the supported way to invalidate a whole range, and until
acbf36deb53d the INVALIDATE case hands msg->size to
vhost_vdpa_unmap() unchecked, so the wrap to U64_MAX is what
qemu/smmuv3/vhost relies on there. A guard at the sink would take
that away from v6.6 and the trees ca50ec377c2e9 reached, where the
check belongs at the rollback call site instead. From v7.4-rc2 on no
caller has a use for size 0 here: the INVALIDATE case rejects it
before the call and vhost_vdpa_remove_as() asks for the whole range.
Testing:
- QEMU/KVM on v7.4-rc5: one kernel image, two probe vdpa devices,
four vhost_vdpa.ko states built from the shipped .patch files
(pristine, this patch, patch 2, this patch + patch 2).
- A one page UPDATE with iova 0 whose first VMA lookup fails is
rejected with -EINVAL and, without this patch, removes every
mapping of the address space: two mappings the request does not
name are gone (re-adding them succeeds), the parent gets two
dma_unmap calls for them, and the set_map-only parent is
reprogrammed with an empty IOTLB (set_map, nmaps 0). With this
patch the same request only fails.
- An INVALIDATE with a real size still unmaps what it names.
- The wipe is silent: the states without this patch lose those
mappings with no WARNING, BUG or Oops, and the fix adds none.
drivers/vhost/vdpa.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index c912ac4..6cddd50 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1113,6 +1113,9 @@ static int vhost_vdpa_unmap(struct vhost_vdpa *v,
u64 last = iova + size - 1;
int ret;
+ if (!size)
+ return 0;
+
if (ops->set_map && !ops->dma_map) {
vhost_iotlb_init(&new_iotlb, iotlb->limit, iotlb->flags);
list_for_each_entry(map, &iotlb->list, link) {
--
2.50.1
next 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 ` Fang Xieyan [this message]
2026-12-01 9:17 ` [PATCH v3 2/2] vhost-vdpa: use vma_lookup() in vhost_vdpa_va_map() Fang Xieyan
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-2-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=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®