CV-Bowen opened a new pull request, #21742:
URL: https://github.com/apache/nuttx/pull/21742
## Summary
There is no way to see which VirtIO devices a NuttX instance has
probed, which driver took them, or what state their virtqueues are in.
rpmsg has `rpmsg dump`; VirtIO has nothing like it.
This adds `/dev/virtio` with a `VIRTIOIOC_DUMP` ioctl that walks the
VirtIO bus and prints, for each device, its name, id, driver and
virtqueues (`virtqueue_dump()`), then calls a new optional `dump`
callback in `struct virtio_driver` for driver specific state. The
ioctl argument is an optional device name as returned by
`virtio_dev_name()` (e.g. `"Block"`); NULL or `"all"` dumps every
device. The nsh side is apache/nuttx-apps#APPS_PR (`virtio dump [type]`).
- openamp: restore the virtio_dev_name() declaration
open-amp 2025.10.0 (a399378a5d, "virtio: remove deprecated
virtio_describe() function") dropped the prototype together with
virtio_describe(), but virtio_dev_name() itself is not deprecated and
is still built. Patch 0024 puts the prototype back.
- drivers/virtio: add /dev/virtio and VIRTIOIOC_DUMP
- drivers/virtio/virtio-{blk,rng,input,serial,net,gpu}: add the dump
callback, one commit per driver
`_VIRTIOBASE` is 0x5100, the first free base after `_RPTUNBASE`.
`/dev/virtio` is registered 0200 like `/dev/rpmsg/*` and
`/dev/rptun/*`.
## Impact
- New ioctl base `_VIRTIOBASE` (0x5100) and `VIRTIOIOC_DUMP` in
`include/nuttx/fs/ioctl.h` / `include/nuttx/virtio/virtio.h`.
- `struct virtio_driver` gains a `dump` member after `remove`. The
drivers that do not set it (rpmb, rpmsg, snd) initialise the struct
positionally up to `remove`, so `dump` is NULL for them and for
out-of-tree drivers written the same way.
- New device node `/dev/virtio` when `CONFIG_DRIVERS_VIRTIO=y`.
- No Kconfig change, no behaviour change unless the ioctl is called.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
qemu-armv8a:netnsh with apache/nuttx-apps#APPS_PR, test-only overlay
`# CONFIG_LIBC_ENVPATH is not set` and `# CONFIG_BINFMT_CHECKEXEC is not set`
(current master needs it for nxinit to start nsh on qemu-armv8a), plus for
the second run:
```
CONFIG_DRIVERS_VIRTIO_SERIAL=y
CONFIG_DRIVERS_VIRTIO_INPUT=y
CONFIG_INPUT=y
CONFIG_INPUT_KEYBOARD=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_VIDEO_FB=y
CONFIG_DRIVERS_VIRTIO_GPU=y
```
QEMU 10.2.1:
```
qemu-system-aarch64 -cpu cortex-a53 -nographic \
-machine virt,virtualization=on,gic-version=3 -serial mon:stdio \
-global virtio-mmio.force-legacy=false \
-device virtio-rng-device,bus=virtio-mmio-bus.0 \
-drive file=d0.img,if=none,format=raw,id=hd0 \
-device virtio-blk-device,bus=virtio-mmio-bus.1,drive=hd0 \
-netdev user,id=u0 -device
virtio-net-device,netdev=u0,bus=virtio-mmio-bus.2 \
-chardev null,id=c0 -device virtio-serial-device,bus=virtio-mmio-bus.3 \
-device virtconsole,chardev=c0 \
-device virtio-keyboard-device,bus=virtio-mmio-bus.4 \
-device virtio-gpu-device,bus=virtio-mmio-bus.5 -display none \
-kernel nuttx
```
`virtio dump` lists every device with its driver callback output
(virtqueue lines trimmed here):
<details><summary>virtio dump</summary>
```
nsh> virtio dump
[ 0.160699] VirtIO devices:
[ 0.160923] [Entropy] id=4 vdev=0x4043edf0 driver=0x40408b58
priv=0x4043ef70
[ 0.161193] name=/dev/random
[ 0.161773] [Block] id=2 vdev=0x404430a0 driver=0x40408ac8
priv=0x40443220
[ 0.161979] BLK Info:
[ 0.162054] device : /dev/virtblk0
[ 0.162211] sectors : 32768
[ 0.162335] blksize : 512 B
[ 0.162431] capacity : 16 MB
[ 0.162554] features : ro=0 flush=1
[ 0.163102] [Network] id=1 vdev=0x404432f0 driver=0x40408b28
priv=0x40443470
[ 0.163319] name=eth0, mac=00:e0:de:ad:be:ef
[ 0.163497] bufnum=16, iob_free=48, quota: rx=0 tx=16, ipv4=10.0.2.15
[ 0.164529] [Console] id=3 vdev=0x40443608 driver=0x40408bb8
priv=0x40443788
[ 0.164768] name=/dev/ttyV0, console=0, open_count=0
[ 0.164927] xmit=0/1024 B, recv=0/1024 B
[ 0.165874] [Input] id=18 vdev=0x40443de0 driver=0x40408af8
priv=0x40467488
[ 0.166101] name=/dev/kbd0, type=keyboard, evtnum=64
[ 0.166668] [GPU] id=16 vdev=0x40467748 driver=0 priv=0
```
</details>
GPU on its own (the run above has no framebuffer driver bound to it):
```
nsh> virtio dump GPU
[ 0.220075] VirtIO devices:
[ 0.220321] [GPU] id=16 vdev=0x40440df0 driver=0x4040aaf8
priv=0x40440f70
[ 0.220598] display=0, resolution=1280x800, stride=5120 B,
fblen=8192000 B
[ 0.220807] fb_count=2, bpp=32, format=RGB32, vsync=16 ms
[ 0.221019] VQ: virtio_gpu_ctl - size=1024; free=1024; queued=0;
desc_head_idx=0; available_idx=0; avail.idx=9; used_cons_idx=9; used.idx=9;
avail.flags=0x0; used.flags=0x0
```
Type filter, bad arguments, and the virtqueue counters moving after
8 block reads (first run: rng, mmio blk, net, 9p, pci blk):
<details><summary>filter / errors / virtqueue state</summary>
```
nsh> virtio dump Foo
[ 0.264506] VirtIO devices:
[ 0.264615] No devices of type 'Foo' found
nsh> virtio bad
nsh: bad: argument invalid
nsh> dd if=/dev/virtblk0 of=/dev/null bs=512 count=8
4096 bytes (8 blocks) copied, 1051 usec, 3805 KB/s
nsh> virtio dump Block
[ 0.422823] VirtIO devices:
[ 0.422921] [Block] id=2 vdev=0x404410a0 driver=0x40406ac8
priv=0x40441220
[ 0.423148] BLK Info:
[ 0.423242] device : /dev/virtblk0
[ 0.423343] sectors : 32768
[ 0.423423] blksize : 512 B
[ 0.423509] capacity : 16 MB
[ 0.423600] features : ro=0 flush=1
[ 0.423707] VQ: virtio_blk_vq - size=1024; free=1024; queued=0;
desc_head_idx=0; available_idx=0; avail.idx=8; used_cons_idx=8; used.idx=8;
avail.flags=0x0; used.flags=0x0
[ 0.424138] [Block] id=2 vdev=0x40441b18 driver=0x40406ac8
priv=0x40441c98
[ 0.424346] BLK Info:
[ 0.424414] device : /dev/virtblk1
[ 0.424519] sectors : 32768
[ 0.424607] blksize : 512 B
[ 0.424695] capacity : 16 MB
[ 0.424784] features : ro=0 flush=1
[ 0.424934] VQ: virtio_blk_vq - size=256; free=256; queued=0;
desc_head_idx=0; available_idx=0; avail.idx=0; used_cons_idx=0; used.idx=0;
avail.flags=0x0; used.flags=0x0
```
</details>
Every commit builds with 0 warnings on qemu-armv8a:netnsh.
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). No regression in virtio: qemu-armv8a:netnsh boot and pass the
fixed virtio cases (rng, blk on mmio and pci, net, 9p; 24/24). qemu-armv8a was
built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master
needs for nxinit to start nsh there; unrelated to this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]