[PATCH 0/3] tools/virtio: exercise VHOST_*_FEATURES_ARRAY ioctls

From
rom.wang <hidden>
Date
2026-08-04 08:01:50
Also in
kvm, lkml, virtualization
Reply to
Eugenio Perez Martin, 2026-06-26
From: Yufeng Wang <redacted>

Hi Eugenio,

This series follows up on your review of the vhost/net GET_FEATURES_ARRAY
fix [1], where you asked for a switch in tools/virtio/vhost_net_test.c to
exercise VHOST_GET_FEATURES_ARRAY and VHOST_SET_FEATURES_ARRAY.  The fix
itself is unchanged from the v2 you Acked [2] and is not included here.

Patch 3 adds the requested "--features-array" switch.  When it is given,
the test programs features via VHOST_SET_FEATURES_ARRAY and then verifies
VHOST_GET_FEATURES_ARRAY by issuing it twice with the same count,
comfortably above VIRTIO_FEATURES_U64S: once into a zero-initialized
buffer and once into a buffer pre-filled with a non-zero sentinel.  The
two reads must match on every entry: the kernel fills the prefix with the
device features and clear_user()s the trailing entries it did not fill.
A clear_user() with the wrong start address clobbers the prefix instead
of the tail; the sentinel buffer then keeps non-zero data in the trailing
entries and disagrees with the clean read.  Using a count comfortably
above VIRTIO_FEATURES_U64S (rather than matching it exactly) keeps the
test correct as the kernel's feature-word count grows, so this is exactly
the path that [1] fixes and the test doubles as a regression test for it.

Patches 1-2 are build prerequisites needed for the harness to compile
against current headers: a device-id compat header (since
mod_devicetable.h was split into include/linux/device-id/) and an
__must_be_array stub (needed by struct_size(), which the new test uses).
With them, `make -C tools/virtio test` builds virtio_test, vringh_test
and vhost_net_test cleanly.

Patch 3 depends on [1] for its GET path to pass.  Tested on x86_64:
  - without [1]: ./vhost_net_test --features-array aborts in
    verify_get_features_array() (the GET clear_user bug);
  - with [1]: both ./vhost_net_test and ./vhost_net_test --features-array
    complete RX/TX with started == completed == 0x100000.

[1] https://lore.kernel.org/all/20260526080336.61296-1-r4o5m6e8o@163.com/ (local)
[2] https://lore.kernel.org/all/CAJaqyWfP7j5_PvOP0JiHuAQ8appGnoJDS3OB-qK7riBpZ_d_tQ@mail.gmail.com/ (local)

Yufeng Wang (3):
  tools/virtio: add device-id compat header for virtio
  tools/virtio: add __must_be_array stub
  tools/virtio: add --features-array switch

 tools/virtio/linux/compiler.h         |  1 +
 tools/virtio/linux/device-id/virtio.h |  1 +
 tools/virtio/vhost_net_test.c         | 70 +++++++++++++++++++++++++--
 3 files changed, 68 insertions(+), 4 deletions(-)
 create mode 100644 tools/virtio/linux/device-id/virtio.h

-- 
2.34.1


No virus found
		Checked by Hillstone Network AntiVirus
Thread (7 messages) 7 messages, 2 authors, last reply 2026-08-06
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help