🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25117

[PATCH v3 2/2] vhost-vdpa: use vma_lookup() in vhost_vdpa_va_map()

#25117
From: Fang Xieyan
Date: Tue, 01 Dec 2026 09:17
90 lines
12476 bytes
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
Technical Details
Message-ID: <20261201091722.46805-3-fangxy@xiaopeng.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374889-linux-kernel-netdev=dewy.ru
References: <20261201091722.46805-1-fangxy@xiaopeng.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374889-linux-kernel-netdev=dewy.ru
From: fangxy@xiaopeng.com (Fang Xieyan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v3 2/2] vhost-vdpa: use vma_lookup() in vhost_vdpa_va_map()
Date: Tue,  1 Dec 2026 17:17:22 +0800
Organization: Usenet Network
Message-ID: <20261201091722.46805-3-fangxy@xiaopeng.com>
References: <20261201091722.46805-1-fangxy@xiaopeng.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1671767"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZHL8rfVe6ic3NxT3S6DaKzkfIQE= sha256:4jjuIZxVphdur/UxlRISbEq42noDhyi/MsGE0HbIaQE=
	sha1:gOBy27MnnvQ3hsIPBEXwgnLoyk0= sha256:QDvb2CEvL3nrQc8hIU7noG4CFO+CCnTURbKg2gOsAj8=
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 ED58F1172F5; Tue,  1 Dec 2026 12:18:04 +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 lU6Ia0ukEwlU;
	Tue,  1 Dec 2026 12:18:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374889-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id A0E591172F1; Tue,  1 Dec 2026 12:17:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id DAC462709F; Tue,  1 Dec 2026 09:17:48 +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=1796116657;
	b=EMu9sakkBBOXeiVNzPD8q/UttyI+J8HWvSeu67LgkT1EH0IrUU0vWnNpmcnr9SQevMD7
	 FBFQj0wosp524sjrlNAqhRyAjj4WxiumvgeSHm8YDTeS0wsR1C4BuKkwbQ0UuM0AKxNY9
	 d+o4g9YkvUAvm/xWXZ+KHye+AcPkqN4JkTo1xvxQuHNd+IANRsBB0vqxqVMnTU4iaJX+q
	 xCN1EZX9teibT5gbklnNj1c35tb6R1QPhxBLIxjmh6UMx4PBTCpwmWnrgvyK0P3hgY8y6
	 V70iTWMpD7LMkWc967Pw29SpRGGVNmuWGQemFyBvSTGACX8DtJ6O2s4oRvCtzjzWrQg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796116657;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-Alimail-AntiSpam:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=RA5cRfvLgjxyN8MOK5tPDXfq4Uk3r/GIQo4k9uPncH8=;
	b=a2syXp4nS9ro7ZNxIo93ukrBUzSAwc8v5thDiKxrglyL5HxPG1WBYn1QURSy7mYcWGvz
	 27vGN8eB6qByc3/FiwiAsZ2lOwLSCKxyP8dxXdDurorsovF+qUETqEOCRpCjktaiUc9UD
	 ER5OBIE7WqMzuOtStZ3EQNHjY8Z5T4kc2koT2IO7nlDYJhK/vTiwqB1QTOJqZT6/cHnEJ
	 HyF2egVdtiLi2T8U/WxepCCp0q8nH/WV5z4/G5YH6/fwob34nHWEcmON1Kw1oluBr1Dxs
	 9C9t6K4629YGlRQwxeK237WPtZyIbweYYuGbVKCkzNfT0dMYEieTnMvwfIQ5wKZHhNQ==
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="U4/TUEpU";
	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 55F0F606A6BB;
	Tue,  1 Dec 2026 09:17:37 +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=U4/TUEpU
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.4
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796116656;
	b=on++G5MIylydTpc2SU3b34spP8tQLK4ucX2KFWh7bFwvDY9hb0pMv5Q5RDUWdZS0yZnb
	 w5BFsVjGijd3FJoAkwtk5MN/AFayd06truAkKmmt8fRBYQRwjZdf+eCM5NAiI3uBaLDED
	 Id04t3YGzXr8bepW2v1EuIJDM/FAwpy+pvS+RTliPNgbTM33sVC4sfIk1lUGTwky46iEN
	 IWSXgoVtkL+c0Q/b4NtL5kBzMv0+YovZl2nt7Y1T//LUnnOHxgTWFvt510JCISQ98S8/b
	 vkZj7vO0zghf2G5JpSRIL+OWp/5W/210BVO3JTEcFFRoLoh6wfp9DQ5C8Xz5PjUNWXw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796116656;
	h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=RA5cRfvLgjxyN8MOK5tPDXfq4Uk3r/GIQo4k9uPncH8=;
	b=2Uu5tOtG9TM+yvChKuQkSvvGKTsT/TQwK1oys+kNLdWb0ThBzlhyE/THGpuMUFJBeJJR
	 pfvDakVN8Nxhtfs/kbz4s2dN0iqJuxjNcVuORWtGGRRgpEzRBfrFuhwxMNWKMTTs0jjjx
	 0Vct/C/X/nuqVO6by8/CgUQGsb/elFXXP7PUgEQJGBe4vF6Di1ZYmkaQdl/qORaaz6tG8
	 m0qAQNIKY3CkqIDc70gSrqm8LRCd+UGF8Xp+tdXf34ThekIe1hFE6CHVpQxSRjxad5mZD
	 P6cLSOqUu/mYy0tp3RV6c6MpVYDUMv590ODSKPyz+6cVb+9f1MlImLc4dKNwPtWfPRQ==
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="U4/TUEpU";
	arc=none smtp.remote-ip=115.124.28.4
X-Received: from out28-4.mail.aliyun.com (out28-4.mail.aliyun.com [115.124.28.4])
	(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 0D2B6606A329;
	Tue,  1 Dec 2026 09:17:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0D2B6606A329
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=1796116646; h=From:To:Subject:Date:Message-ID:MIME-Version;
	bh=RA5cRfvLgjxyN8MOK5tPDXfq4Uk3r/GIQo4k9uPncH8=;
	b=U4/TUEpUqlf8TtHTzJxnUAjB3nmg8Wqt5/8STNT067LlL6AFU1HsIGTommasScL3Rrk27J2fratTkB/7EEzC1BonVk4JbNSuNkj2ZLDXfDPjgNxNeVG1MRKP/B6Ow7F3Vaik/d/FoUgOMPL8e7uw2kJTUbM7GaVS8PxQ3cS5ak0=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04534032|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00746372-0.000417409-0.992119;FP=3725831658881942771|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033068002237;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=11;RT=11;SR=0;TI=SMTPD_---.kE3zImN_1796116645;
X-Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.kE3zImN_1796116645 cluster:ay29)
          by smtp.aliyun-inc.com;
          Tue, 01 Dec 2026 17:17:26 +0800
X-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
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261201091722.46805-1-fangxy@xiaopeng.com>
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