Article View: linux.kernel.netdev
Article #21078[PATCH] vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map()
From: Fang Xieyan
Date: Mon, 23 Nov 2026 14:33
Date: Mon, 23 Nov 2026 14:33
79 lines
11086 bytes
11086 bytes
find_vma() returns the first VMA with vm_end > uaddr; when uaddr lies
in an unmapped gap, vma->vm_start > uaddr and the offset arithmetic
offset = (vma->vm_pgoff << PAGE_SHIFT) + uaddr - vma->vm_start;
produces an incorrect file offset, potentially wrapping in u64
arithmetic.
The incorrect offset is stored in map_file->offset and passed to
the mapping backend. Meanwhile, map_size includes the gap, causing
the corresponding IOVA range to be mapped without valid backing.
Skip the gap: stop if the whole remaining request is gap, otherwise
shrink size, pin uaddr to vm_start and advance map_iova by the gap.
The gap is left unmapped without error.
Testing:
- make W=1 drivers/vhost/vdpa.o
- QEMU/KVM v7.4-rc1 with a probe vDPA parent; tested partial
gap, whole-gap and contiguous IOTLB updates.
Fixes: d8945ec41120 ("vdpa: Support transferring virtual addressing during DMA mapping")
Cc: stable@vger.kernel.org
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
drivers/vhost/vdpa.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
Reproducer: userspace model of va_map() with a mock find_vma(); shared
file-backed VMA [0x2000,0x3000) at file offset 0, unmapped gap
[0x1000,0x2000).
UPDATE iova=0x100000 uaddr=0x1000 size=0x2000 (partial gap):
without fix: ret=0, one map over the gap,
file_offset=0xfffffffffffff000
with fix: ret=0, map at iova=0x101000 uaddr=0x2000
size=0x1000 file_offset=0x0
UPDATE uaddr=0x1000 size=0x1000 (whole request in gap):
without fix: ret=0, bogus map with underflowed offset
with fix: ret=0, no mapping created
Build: make W=1 drivers/vhost/vdpa.o completed without warnings on
v7.4-rc1 (defconfig + VHOST/VDPA/VHOST_VDPA).
Runtime: On v7.4-rc1 under QEMU/KVM, a userspace test client sent
VHOST_IOTLB_UPDATE messages through the /dev/vhost-vdpa chardev to a
probe vDPA parent with use_va enabled and dma_map logging. Without
the fix the parent receives offset=0xfffffffffffff000 for gap
requests; with the fix the gap is skipped (map_iova advanced,
offset=0), an all-gap request creates no mapping, and contiguous
requests are unchanged.
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index ff7d907..4a6a946 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1109,6 +1109,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;
+ size -= gap;
+ uaddr = vma->vm_start;
+ map_iova += gap;
+ continue;
+ }
map_size = min(size, vma->vm_end - uaddr);
if (!(vma->vm_file && (vma->vm_flags & VM_SHARED) &&
!(vma->vm_flags & (VM_IO | VM_PFNMAP))))
--
2.50.1
Technical Details
Message-ID:
<20261123143318.73514-1-fangxy@xiaopeng.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369478-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369478-linux-kernel-netdev=dewy.ru
From: fangxy@xiaopeng.com (Fang Xieyan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH] vhost-vdpa: skip unmapped gap in vhost_vdpa_va_map()
Date: Mon, 23 Nov 2026 22:33:18 +0800
Organization: Usenet Network
Message-ID: <20261123143318.73514-1-fangxy@xiaopeng.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="3901954"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:kAs9BX5OcnYysVzcJLvNgGZageY= sha256:K2s2WHvhL4F01fjUah4mgo1lLl7qOyX6VVwKG0WawgM=
sha1:DJWM4UZ7yzDwFL2g+kt+FvKDlPY= sha256:bQD6kUTu7jB5vVi+s14ohbLltAJEUTihfakbOkCnfHQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id D6EBD125DB9; Mon, 23 Nov 2026 17:33:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
header.d=xiaopeng.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id uImEWve6T4GR;
Mon, 23 Nov 2026 17:33:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369478-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id BD0BD125DB7; Mon, 23 Nov 2026 17:33:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id A16702A2ED; Mon, 23 Nov 2026 14:33:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795444412;
b=Zz3bWt1DXNFAdKdcAmYFPERQtPAW78tdqy+dignKwtCswtmV3JZ9X4cGeTSOnY1YOuhF
fbeMaHVQYQvOtV/4BTmao+a5MLFCWqj2Q1t/HDw4yZX7afL1Gef569JS3L+AEGkF2J/rg
8ALyIXqz6ZaPvTNeo0DTkjvHbS3Ob++373BxXlTpwqnHSQRu18gx+X5InDPurmYDpxQtk
phE5alEdljDSo9zdD1WpU+WqKldI+0meUt7ZW/5G692XiftLdQvlwFrbP6kId61tTZQRp
hx9Wg6FQMK47Q5AiruqS9c7gB9xox1nsgkyWozvrdKKDCAHZPp4Wnh6lR8cxQtlWn4A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795444412;
h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
X-Alimail-AntiSpam:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=OCPSiHkYqSNvnClc+FUc66tTva53YlW4lXZmEaSjud0=;
b=UY6oJRiKYHYGFZsBu/FIstLZpDvJi4i1QyEzojKdQRycoT7hRlddcE2tWb6m/BwJ5khM
Zs0SO3UvqdHyJ9RLMrgFgpVODMbGkfz/MuRlUjL8AAg4ZAhDlNrVE3E8UO5F62TocYeff
YNcPhlPTWKJ3jP6jEfeJrUMPCBiWShP6D97dwFCSA6yjLK1JYtmnl0fd2pC/PIPD0h3Y8
IKcMYCVXzVQM5hwDhPICZr+5MbGP3u3pRmChtXw03pUWINy5/sL3dNAnQDYws/FyxJ3NV
KDuQLSLxhCYd2yruARzgImkImkKW7Wru3y/T/8gymDP7U+AjdT/k4TaA0zZ5xBA+tRw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=RkycBL4G;
dmarc=none header.from=xiaopeng.com;
spf=pass smtp.mailfrom=xiaopeng.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4465C606A335;
Mon, 23 Nov 2026 14:33:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=RkycBL4G
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.1
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795444411;
b=KsO5WhL66B60m+DOSx9cF7EMKzbzE52HoulPbvlb75kFGntzzArshp07zoUgY91lfinm
ep9mLnHJI5FLZrDsdJ8lm9LNBkKl7Y8gCDOmqrH7KZMda5LakgXRbf6LeIRX0snMAtXac
O2+ELSJ3qF36q7wyEdw+GPmLLaYtIKvgW29ji1I7aiECC2qYUPW8njU3I6sUnbQNoXGoW
6vDWISJPqGqUV/gfcVoEOUMeRIUeV/7AznEYCBv7DIzf2dezF1EiAodxrjhNWjcBVR30Z
55NfxioXV+0alar001NBV4xVPMS9vEC8lvtn3NcM/cGlnOixH1U0V0pm9btxPuODv6w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795444411;
h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc:
Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=OCPSiHkYqSNvnClc+FUc66tTva53YlW4lXZmEaSjud0=;
b=Vnjvlu9yDbUSJHCqyo0t5+LKaBTl0ZdNZrERAajs236gDK4l7N3DlB9VWrsXUr7z6P0P
AM+WEniYpCAlsQjI3o/0lYGOtpZLu/tjJqSjJHL5SOKKBE8rPgheH+9oAZC1vj0BPTzyP
eHSs3p6YU9NbNUzaZ54XbUxS3yqqBEdFXRyIPqPWRNlchRnCOf1jirj1Ei683e6m65JWw
gl+2o7mMJZGr48e3SxrUIZcM/Y+9zrfkrbg5QGoMD3GODgo0su+o1oQACpUQ5WwoVV2kd
LhyYWggly/mIiPJ9A/KuP5Irerw+iQUT/4lkl+PbkQWlqWaI7PP/MWD6BQx1eHUtrxw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=xiaopeng.com;
spf=pass smtp.mailfrom=xiaopeng.com;
dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=RkycBL4G;
arc=none smtp.remote-ip=115.124.28.1
X-Received: from out28-1.mail.aliyun.com (out28-1.mail.aliyun.com [115.124.28.1])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CF03606A31A;
Mon, 23 Nov 2026 14:33:28 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CF03606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=xiaopeng.com; s=default;
t=1795444400; h=From:To:Subject:Date:Message-ID:MIME-Version;
bh=OCPSiHkYqSNvnClc+FUc66tTva53YlW4lXZmEaSjud0=;
b=RkycBL4GD2EXhFYzp0KJkFi4j9vZnxYhH3VRJI9Qdrhr8JAxOmt0E2PeSnBtmCG4fwM84QAhno1JafzbyNRDPCfZXll792hP5JfMxnBhTZ+ZSI+PkBSVe+mZJalXkxYLLJb2a78JPVkFjnCVhiajTRR0vvnLNALV3DTcbtO5ChY=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04439905|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00493033-8.00282e-06-0.995062;FP=6621435113100027107|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037034017;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=9;RT=9;SR=0;TI=SMTPD_---.k8K2y1G_1795444398;
X-Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k8K2y1G_1795444398 cluster:ay29)
by smtp.aliyun-inc.com;
Mon, 23 Nov 2026 22:33:20 +0800
X-Cc: Xie Yongji <xieyongji@bytedance.com>,
stable@vger.kernel.org,
virtualization@lists.linux.dev,
kvm@vger.kernel.org,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.50.1
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list