πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25118

[PATCH v3 1/2] vhost-vdpa: reject zero-size unmap

#25118
From: Fang Xieyan
Date: Tue, 01 Dec 2026 09:17
86 lines
12268 bytes
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
Technical Details
Message-ID: <20261201091722.46805-2-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-374888-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!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374888-linux-kernel-netdev=dewy.ru
From: fangxy@xiaopeng.com (Fang Xieyan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v3 1/2] vhost-vdpa: reject zero-size unmap
Date: Tue,  1 Dec 2026 17:17:21 +0800
Organization: Usenet Network
Message-ID: <20261201091722.46805-2-fangxy@xiaopeng.com>
References: <20261201091722.46805-1-fangxy@xiaopeng.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1671826"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZUHXDYK/z+RPwWIRyNAKqaIWVYM= sha256:TwyGyFOcRau/fsMO7twbLwWd5SVtHldFlb/8BpLHUjI=
	sha1:ov65GP/x6rKs1gm1EsW0KVCivAE= sha256:nXEDI4VEfaH0rErpPsnf3ADk6cJxlRqbgbYJkBeKEOU=
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 93E0B1172F5; Tue,  1 Dec 2026 12:18:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[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 eGttyJ_HBao7;
	Tue,  1 Dec 2026 12:18:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374888-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 157921172F4; Tue,  1 Dec 2026 12:17:59 +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 586D4275B4; Tue,  1 Dec 2026 09:17:53 +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=1796116661;
	b=oJl+Ahx8R+FJb7pdpjWzS8y4GFqGn9JDkZBCh+avs0LfJsOkp1sEIZIVWk7Hs+Laobdf
	 SNMRI0p5xizejJuW2XUZjAnMhv4/9YYKoMq0R993F9ugRIrciU6740OV/kW+mMsy1j6IK
	 qnXRthH1ChA0r8kFatY1huKqyDpMZG9zDysLFtK2AjtDD2vYwEqN1zXL/0E8ka9LhAtWp
	 7mCE7KzWZksr8M3LpW5JgQZ2Kp53CR736pAg3Ga09LoJBXzSDF5AylONMtKoDe1Sw7Til
	 d8/tEGshoJQ4hahCUXwgvbW3tGzAbgmfk9NRl/OM08eDcBarV3bzfx8E/CaZxoBy32Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796116661;
	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-Type:Content-Transfer-Encoding;
	bh=3dq6Di7f9wSqov9zKmdrmsEPvO8fHacO/kcB02kKudY=;
	b=rOylStBlU4kc0JQPFlD9XjHAHPS6rknH9fsQ7oM2i/BiOTXpQsp+45FntB3DxTRxaWGh
	 5A0ilQcVNws9pUPCQN95R1UXAHQzDWM+PYWmL+Q7TenKMTE0vUOQNkrmNUU92eX8W2T6N
	 MfqJy6UJ3k8SUQ7Csb/cOZN5H5lSVg/aKarQUo87mp0G8ewCVtwbXjCXlql2PiR19mHnE
	 LAp4hp8d/5ZUaVcyg0UmSrWG3k5MNeqr621xR+0/o7atnt8JS93rLva/LHo+sOHVlGpOV
	 8sYVLhR+8ZxfXiF4Rwm0fChV2wEn+GUOYKWnxxlZunHmJefmuWb5YhldBaFRaq40a1Q==
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=MzFZhppD;
	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 8A842606A334;
	Tue,  1 Dec 2026 09:17:41 +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=MzFZhppD
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.5
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796116655;
	b=KgNUtE6j6RhNFEj0wPAUiGnoA4Sn/rfJmo+/RGglmmJDsxb75OVEu7eLBmWshCPC/8kO
	 9qS4QUqkND+SuUi78vi42pYeEloLQxOqF7QF8QfxkP+/W+GCWMCvvqra2b0QIjGZ2tTOx
	 rkJOReiHMHWpd7dtmEPyYstgoul1BoZg5H5gnOq61diY3Airt40H8drJwpDq0EtPTHBWC
	 Un941Oo/WaqrHMc0RYqG1XlTMiB7jPmESR3lRdDdTVWBfSMShHo3aC0tvWmN6Nz/UhLNV
	 Ijtm+u71VvWaH18I0oqxZytOuyG1dB7KyoGyHK5KBuB/NNrl21ZqkkKsTeFTYvqIU6A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796116655;
	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-Type:Content-Transfer-Encoding;
	bh=3dq6Di7f9wSqov9zKmdrmsEPvO8fHacO/kcB02kKudY=;
	b=0VgsfMhUyxwDI1p21yEKOkMKJz8u6POfXwcO4BGnBxecTQyKx7jI+Ct/8kujh7L5SVsT
	 LYAlS1QrLntBo42qrboX7hHQuGTAt/yrRNyMDFFXwRYAcZQ76Yza1cslnWNXyTqfWv+j+
	 njeo8D5BVdDdLnuVvj3GWaxNCvRN2bVph9wBtC7KYt0iCZ5wcY7fK72t4GFx3gsZufdRl
	 XSzKz119nxvd31Hp7MnsruE4KSBGRz3FznWG3GCeGBlGD0wsThbuLH/Qegn1oRuKwVStT
	 fpmJ9f5/QFLNIlzsdY+Zq79j7hICSipUjQ0XpVlGXf1hTVVxrii2k2al/AC+pefqZYA==
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=MzFZhppD;
	arc=none smtp.remote-ip=115.124.28.5
X-Received: from out28-5.mail.aliyun.com (out28-5.mail.aliyun.com [115.124.28.5])
	(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 88735606A31A;
	Tue,  1 Dec 2026 09:17:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88735606A31A
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=1796116645; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type;
	bh=3dq6Di7f9wSqov9zKmdrmsEPvO8fHacO/kcB02kKudY=;
	b=MzFZhppDPp+PQvG7AGgWxKXb6wg4kfbNPpy8aC2cueLm4IonQb2zSFbESuKzbibUTNtRZtyRzEortR/psrnV6RWSYTLJVev+XaUcO4mgL1hqdpJoGk1xMtiYooBumWprswuw0pTkrsJYT1S78aN1dQd5N+eI8ChMOhZz25VzcVM=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04478823|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.042023-0.000565291-0.957412;FP=12357548265074853235|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037071049;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.kE3zIlV_1796116644;
X-Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.kE3zIlV_1796116644 cluster:ay29)
          by smtp.aliyun-inc.com;
          Tue, 01 Dec 2026 17:17:25 +0800
X-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
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