From nobody Fri Oct 2 06:59:34 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E42E64334AC; Tue, 4 Aug 2026 08:01:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830518; cv=none; b=fEYGPja4pGprJUGPbR5Wnkr1YK4F19/CxhbyPngF6JmS/H/LJ9H6eCOhn7swwq89ith/2eBVXM0ZmviPvfK0I7j37UfhfaC8ZsSL4/odZOeo4wfjUb3CPgZRU32Z2kzq/2Jxb4pGX+c4zZEjSB4Tf0+vJBwIxDWRfH1KVIzu8zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830518; c=relaxed/simple; bh=4ltpcuRttf9/xr0mubqBbCQuLlPMdkVNmsXuyfenKso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H1QVU3P+F+huipTQTRjnvEcVG82S1RHEI1iZz6RYDOLrAjmcxZYwxsX4TJ8OOsA6RFm0D8U7prEKA4mKSKUzPg+Pnm2F6jjSUXW3KqhioBPQElocpt2HODR6ul661RwdllBet6VX+gskwswAWuaNwoX05ORchZVte7og/zqmBZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=G+XTHHrx; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="G+XTHHrx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=iL VaxcPkj4skGi7uPuGNvRNq5L8a7XcBkn06NEpQJNI=; b=G+XTHHrxtWE97Koiyz wJyEWxZmnXm971yJcSzJuLXUiE9vKpXmeVKlwzU9gdiA4lH8iwqveCHpQmWWOAAV sj35x1BVpq6r2PAbdsMwSSxgtAvIbSbG34/dmdIRuSf+fxn97EBwL5SfvDO0ilU5 S98hFbDXoOyqNUIPmYmnXFLCU= Received: from localhost.localdomain (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgA3+bZVnHFqQsQvLQ--.12248S3; Tue, 04 Aug 2026 16:01:28 +0800 (CST) From: "rom.wang" To: virtualization@lists.linux.dev Cc: eperezma@redhat.com, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yufeng Wang Subject: [PATCH 1/3] tools/virtio: add device-id compat header for virtio Date: Tue, 4 Aug 2026 16:01:23 +0800 Message-Id: <20260804080125.79403-2-r4o5m6e8o@163.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260804080125.79403-1-r4o5m6e8o@163.com> References: <20260804080125.79403-1-r4o5m6e8o@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PigvCgA3+bZVnHFqQsQvLQ--.12248S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFyDtFyftr15ZryUurW3Jrb_yoW8Gr4xpa 1DCryqk3y8Ga4fAa4fW3WY9ry2vwsrAw4Svry2gr1UKF9xtFyDXrs3CrnFgwsrZr4jyFW0 yryfWF95KrykZ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7AwxUUUUU= X-CM-SenderInfo: 3uurkzkwhy0qqrwthudrp/xtbCzhg0qWpxnFihbAAA3Z Content-Type: text/plain; charset="utf-8" From: Yufeng Wang mod_devicetable.h was split into per-subsystem headers under include/linux/device-id/ (commit ad428f5811bd "mod_devicetable.h: Split into per subsystem headers"), and include/linux/virtio.h now includes . The tools/virtio compat layer has no counterpart for this new include, so building vhost_net_test fails: ../../include/linux/virtio.h:10:10: fatal error: linux/device-id/virtio.h= : No such file or directory 10 | #include | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ Add tools/virtio/linux/device-id/virtio.h, which includes the real header, matching how the existing virtio.h compat shim reaches the kernel's include/linux/virtio.h. Signed-off-by: Yufeng Wang --- tools/virtio/linux/device-id/virtio.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/virtio/linux/device-id/virtio.h diff --git a/tools/virtio/linux/device-id/virtio.h b/tools/virtio/linux/dev= ice-id/virtio.h new file mode 100644 index 000000000000..18e3338158eb --- /dev/null +++ b/tools/virtio/linux/device-id/virtio.h @@ -0,0 +1 @@ +#include <../../include/linux/device-id/virtio.h> --=20 2.34.1 No virus found Checked by Hillstone Network AntiVirus From nobody Fri Oct 2 06:59:34 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F6864322E9; Tue, 4 Aug 2026 08:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830517; cv=none; b=nX9Y3kb+afQDY4fPl/SKusaTAzjRd8XNpm5TRiiMD/CVSWIqAu4rmsWpf3MU2Src6ayoDP8BFJUgrGbp/KYLHmH0dvRjyG9Dk7SaeovwTk9685LZSkfBhbYtAhPJHZNjpla+IGBIuvVQtHfwC7pS4eEfmSy52W9GPEi6tmGYt0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830517; c=relaxed/simple; bh=XVsZHnCudTLeRuVV1elnZGe6ET8j4KF26RMgoOqlizo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IYmf/63yb1oQ9ffCOhdh2c9excCVFzmwcfZeOsO7vQ6mAyvmNHU3fMW4vx5TAhSeaQ0P0HZdaeFqVJ5F4D0bTStDTLiz/uRJcfC5rYEli1qgxb3W6arkuadGHouTtwM2KznBpiiqPES+x01leQ0UDvR866adMJrBSK7E0/DYfPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=QBW3RmvQ; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="QBW3RmvQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=C4 R4R9pywm2EpuaFH/SxTHSerE/d1aZMpdI1LeEfYSI=; b=QBW3RmvQAPR9nGRZk+ 2UeJ/KSH1YdHfrpcIvckFby81NLQq2a1McnBNkgYBMx4iGnvR6695XsODj675AUg 7fGJ5csqHq0H2/d1MJn1rcP813LESBZzqFqMVlvQV4yga/EB0d/SB+x7xx8JEuKO VlaAvaHK0O3bmK4XvJMUWiqFs= Received: from localhost.localdomain (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgA3+bZVnHFqQsQvLQ--.12248S4; Tue, 04 Aug 2026 16:01:28 +0800 (CST) From: "rom.wang" To: virtualization@lists.linux.dev Cc: eperezma@redhat.com, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yufeng Wang Subject: [PATCH 2/3] tools/virtio: add __must_be_array stub Date: Tue, 4 Aug 2026 16:01:24 +0800 Message-Id: <20260804080125.79403-3-r4o5m6e8o@163.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260804080125.79403-1-r4o5m6e8o@163.com> References: <20260804080125.79403-1-r4o5m6e8o@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PigvCgA3+bZVnHFqQsQvLQ--.12248S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr1kWFWrXF4DAF4UXry7ZFb_yoW8Jw1xpF nrWrn8Ka18ZrnIga4fta4fur1Uuw1fAw17GF93W34UuF98Jw1IvFnFkFW3K3y3uw4vgF1I gryvqF1xGFZxZw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URwZcUUUUU= X-CM-SenderInfo: 3uurkzkwhy0qqrwthudrp/xtbC8Bg0qWpxnFjjKQAA3g Content-Type: text/plain; charset="utf-8" From: Yufeng Wang struct_size() expands to flex_array_size(), which uses __must_be_array() to assert at build time that its argument is an array. __must_be_array() is defined in the kernel's include/linux/compiler.h, but the tools/virtio compiler.h compat shim does not provide it, so any use of struct_size() in the test harness fails to build: ../include/linux/overflow.h:161:44: error: implicit declaration of functi= on '__must_be_array' [-Wimplicit-function-declaration] 161 | sizeof(*(p)->member) + __must_be_array((p)->m= ember),\ | ^~~~~~~~~~~~~~~ vhost_net_test.c:258:32: note: in expansion of macro 'struct_size' Stub __must_be_array() to 0, consistent with how BUILD_BUG_ON() and __must_check are already stubbed out in this environment. Signed-off-by: Yufeng Wang --- tools/virtio/linux/compiler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virtio/linux/compiler.h b/tools/virtio/linux/compiler.h index 0f25db473f55..3fa035296fab 100644 --- a/tools/virtio/linux/compiler.h +++ b/tools/virtio/linux/compiler.h @@ -40,5 +40,6 @@ }) =20 #define __must_check +#define __must_be_array(a) 0 =20 #endif --=20 2.34.1 No virus found Checked by Hillstone Network AntiVirus From nobody Fri Oct 2 06:59:34 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AA1F3C9880; Tue, 4 Aug 2026 08:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830522; cv=none; b=TbmlvwnA7EC4hKttH+gpnez35wg4s8hoVplctb8LZCTqqjDq9jmQKNY/ynNvelT+X3XJ8QRsfZYn6vusm6T2FPeXbcQiPT/viCVT0QlhV8I4gcB8QSZRhPacIZsMH2kFTpT4OPIjIfRwas5NnsuGcUa35Rl36elgkc0iJMD+uPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785830522; c=relaxed/simple; bh=jv/8jh4nUeoRb+P/0T3xefwTXs5/+xJ/He96kSRljGY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JRyKWtrxuz5lu2ckJEhx2eiblbDKJI3ig2Xu9NDdxav7C8zatGd+8NRtdI3Ub68X0VLehSkSuJ4XjrVoF5eCNG14uvrJTc3PGDUs4cV9k7fpFMhJn1kBYP5ce9yg5Z6aztLW+jdHNcpuT0ai8o2aekhnkYrvveHU4WtZudo+WMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=HCq1Es2X; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="HCq1Es2X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=GD XLoRKgzjKVnPrgwJcrOOcZrQyU97XBZRb6Hz6oZlY=; b=HCq1Es2XyjzlONBs2u wjs1KTefU8C1R/l72mjb6w9ZyueDEEmWlceHcp0UTFJAExFmQxlLS5bcYsnQTlA+ 9tDCPvGS6cMOAjHIdqTDdYS0RvziQ9YwXBdhzp0T1fdOmTogxKNla0CeCJ0m+QGd WbeA6uKI50m1yH+5Z+vxBA3+0= Received: from localhost.localdomain (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgA3+bZVnHFqQsQvLQ--.12248S5; Tue, 04 Aug 2026 16:01:29 +0800 (CST) From: "rom.wang" To: virtualization@lists.linux.dev Cc: eperezma@redhat.com, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yufeng Wang Subject: [PATCH 3/3] tools/virtio: add --features-array switch Date: Tue, 4 Aug 2026 16:01:25 +0800 Message-Id: <20260804080125.79403-4-r4o5m6e8o@163.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260804080125.79403-1-r4o5m6e8o@163.com> References: <20260804080125.79403-1-r4o5m6e8o@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PigvCgA3+bZVnHFqQsQvLQ--.12248S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxtr1fXrW3WF4xZrWkAF17Awb_yoW7GFy8p3 ySqF15AF43Jr1xCa13J39ruF45Gw1xAF45ArZ2y34rC3WUGFyUAFs2ka10qa9xZ3ykXFWa gFn0vr4xCFWDu3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j76p9UUUUU= X-CM-SenderInfo: 3uurkzkwhy0qqrwthudrp/xtbC8Bk0qWpxnFnjNAAA39 Content-Type: text/plain; charset="utf-8" From: Yufeng Wang Add a --features-array command-line switch that exercises the array-variant feature ioctls, VHOST_SET_FEATURES_ARRAY and VHOST_GET_FEATURES_ARRAY, instead of the legacy VHOST_SET_FEATURES. The legacy path is used when the switch is omitted, so both code paths stay covered. SET: features are programmed via VHOST_SET_FEATURES_ARRAY. GET: VHOST_GET_FEATURES_ARRAY is issued twice with a count above VIRTIO_FEATURES_U64S, once into a zero-initialized buffer and once into a sentinel-filled one; the two reads must match. This verifies the kernel fills the prefix and clear_user()s the trailing entries, and stays correct as the kernel's feature-word count grows. Signed-off-by: Yufeng Wang --- tools/virtio/vhost_net_test.c | 70 +++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/tools/virtio/vhost_net_test.c b/tools/virtio/vhost_net_test.c index 389d99a6d7c7..77191e60a7a3 100644 --- a/tools/virtio/vhost_net_test.c +++ b/tools/virtio/vhost_net_test.c @@ -26,6 +26,12 @@ #define TEST_PTYPE ETH_P_LOOPBACK #define DESC_NUM 256 =20 +/* Number of u64 entries that the kernel uses to store all currently-defin= ed + * virtio features. Must stay in sync with the kernel's VIRTIO_FEATURES_U6= 4S. */ +#define FEATURES_U64S 2 +/* Above VIRTIO_FEATURES_U64S so trailing entries hit the clear_user() tai= l. */ +#define GET_FEATURES_ARRAY_COUNT 8 + /* Used by implementation of kmalloc() in tools/virtio/linux/kernel.h */ void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; =20 @@ -205,8 +211,10 @@ static void vq_info_add(struct vdev_info *dev, int idx= , int num, int fd) assert(!r); } =20 -static void vdev_info_init(struct vdev_info *dev, unsigned long long featu= res) +static void vdev_info_init(struct vdev_info *dev, unsigned long long featu= res, + bool features_array) { + struct vhost_features_array *fa; struct ether_header *eh; int i, r; =20 @@ -248,8 +256,20 @@ static void vdev_info_init(struct vdev_info *dev, unsi= gned long long features) r =3D ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); assert(r >=3D 0); =20 - r =3D ioctl(dev->control, VHOST_SET_FEATURES, &features); - assert(r >=3D 0); + if (features_array) { + fa =3D calloc(1, struct_size(fa, features, FEATURES_U64S)); + assert(fa); + fa->count =3D FEATURES_U64S; + fa->features[0] =3D features; + + r =3D ioctl(dev->control, VHOST_SET_FEATURES_ARRAY, fa); + assert(r >=3D 0); + + free(fa); + } else { + r =3D ioctl(dev->control, VHOST_SET_FEATURES, &features); + assert(r >=3D 0); + } =20 dev->nvqs =3D 2; } @@ -455,6 +475,10 @@ static const struct option longopts[] =3D { .val =3D 'b', .has_arg =3D required_argument, }, + { + .name =3D "features-array", + .val =3D 'F', + }, { } }; @@ -467,11 +491,43 @@ static void help(int status) " [--no-virtio-1]" " [--delayed-interrupt]" " [--buf-num]" + " [--features-array]" "\n"); =20 exit(status); } =20 +static void verify_get_features_array(struct vdev_info *dev) +{ + struct vhost_features_array *clean, *dirty; + int r, i; + + clean =3D calloc(1, struct_size(clean, features, GET_FEATURES_ARRAY_COUNT= )); + assert(clean); + clean->count =3D GET_FEATURES_ARRAY_COUNT; + r =3D ioctl(dev->control, VHOST_GET_FEATURES_ARRAY, clean); + assert(r >=3D 0); + + /* Sentinel-fill so the kernel's clear_user() of the tail is visible. */ + dirty =3D calloc(1, struct_size(dirty, features, GET_FEATURES_ARRAY_COUNT= )); + assert(dirty); + dirty->count =3D GET_FEATURES_ARRAY_COUNT; + memset(dirty->features, 0xa5, GET_FEATURES_ARRAY_COUNT * sizeof(dirty->fe= atures[0])); + r =3D ioctl(dev->control, VHOST_GET_FEATURES_ARRAY, dirty); + assert(r >=3D 0); + + /* Must match; a wrong clear_user() start would leave them unequal. */ + for (i =3D 0; i < GET_FEATURES_ARRAY_COUNT; i++) + assert(clean->features[i] =3D=3D dirty->features[i]); + + printf("GET_FEATURES_ARRAY: 0x%llx 0x%llx (tail zeroed) OK\n", + (unsigned long long)clean->features[0], + (unsigned long long)clean->features[1]); + + free(clean); + free(dirty); +} + int main(int argc, char **argv) { unsigned long long features =3D (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | @@ -480,6 +536,7 @@ int main(int argc, char **argv) long nbufs =3D 0x100000; struct vdev_info dev; bool delayed =3D false; + bool features_array =3D false; int o, fd; =20 for (;;) { @@ -503,6 +560,9 @@ int main(int argc, char **argv) case 'D': delayed =3D true; break; + case 'F': + features_array =3D true; + break; case 'n': nbufs =3D strtol(optarg, NULL, 10); assert(nbufs > 0); @@ -520,7 +580,9 @@ int main(int argc, char **argv) fd =3D tun_alloc(&dev, tun_name); assert(fd >=3D 0); =20 - vdev_info_init(&dev, features); + vdev_info_init(&dev, features, features_array); + if (features_array) + verify_get_features_array(&dev); vq_info_add(&dev, 0, DESC_NUM, fd); vq_info_add(&dev, 1, DESC_NUM, fd); vdev_create_socket(&dev, tun_name); --=20 2.34.1