CV-Bowen opened a new pull request, #21813:
URL: https://github.com/apache/nuttx/pull/21813
## Summary
The device side has no counterpart to `/dev/virtio` (#21742): there is
no way to see which vhost devices a NuttX instance serves, which driver
took them, or the state of their virtqueues.
Register `/dev/vhost` with a `VHOSTIOC_DUMP` ioctl that walks the vhost
bus, both bound and deferred devices, and prints each device's name, id,
driver and virtqueues (`virtqueue_dump()`), then calls a new optional
`dump` callback in `struct vhost_driver`. The argument is an optional
device name as returned by `virtio_dev_name()` (e.g. `"Entropy"`); NULL
or `"all"` dumps every device. The nsh side is
apache/nuttx-apps#APPS_PR (`vhost dump [type]`).
`VHOSTIOC_DUMP` has the same value as `VIRTIOIOC_DUMP`, so one command
number drives both nodes and no new ioctl base is needed. `/dev/vhost`
is registered 0200 like `/dev/virtio`.
## Impact
- New `VHOSTIOC_DUMP` in `include/nuttx/vhost/vhost.h` (alias of
`VIRTIOIOC_DUMP`), which now includes `<nuttx/virtio/virtio.h>`.
- `struct vhost_driver` gains a `dump` member after `remove`. In-tree
vhost drivers initialise the struct positionally up to `remove`, so
`dump` is NULL for them.
- New device node `/dev/vhost` when `CONFIG_DRIVERS_VHOST=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:rpserver + qemu-armv8a:rpproxy with apache/nuttx-apps#APPS_PR;
the proxy serves two vhost-rng devices over rptun ivshmem. Test-only
overlay `# CONFIG_LIBC_ENVPATH is not set`,
`# CONFIG_BINFMT_CHECKEXEC is not set` (current master needs it for
nxinit to start nsh on qemu-armv8a). On the proxy:
<details><summary>vhost -h / dump / dump Entropy / dump Foo</summary>
```
### proxy>: vhost -h
Usage:
vhost dump [type] - Dump device info
vhost -h - Show this help message
Supported types:
all - Dump all devices (default)
Network - Network devices
Block - Block devices
Console - Console devices
Entropy - Entropy/RNG devices
RPMSG - RPMSG devices
Serial - Serial devices
GPU - GPU devices
Input - Input devices
Vsock - Vsock devices
Crypto - Crypto devices
Sound - Sound devices
RPMB - RPMB devices
Description:
Display information about registered vhost
devices. Output is sent to syslog.proxy>
### proxy>: vhost dump
[ 4.504556] [ 9] [ EMERG] [proxy] VHost devices:
[ 4.505240] [ 9] [ EMERG] [proxy] [Entropy] id=4 hdev=0x406b3e30
driver=0x4069a0f0 priv=0x406b3ea0
[ 4.506048] [ 9] [ EMERG] [proxy] VQ: virtio_rng - size=8; free=8;
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
[ 4.507107] [ 9] [ EMERG] [proxy] [Entropy] id=4 hdev=0x406b3f08
driver=0x4069a0f0 priv=0x406c6e30
[ 4.507666] [ 9] [ EMERG] [proxy] VQ: virtio_rng - size=8; free=8;
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
### proxy>: vhost dump Entropy
[ 5.761842] [ 9] [ EMERG] [proxy] VHost devices:
[ 5.762177] [ 9] [ EMERG] [proxy] [Entropy] id=4 hdev=0x406b3e30
driver=0x4069a0f0 priv=0x406b3ea0
[ 5.762641] [ 9] [ EMERG] [proxy] VQ: virtio_rng - size=8; free=8;
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
[ 5.763446] [ 9] [ EMERG] [proxy] [Entropy] id=4 hdev=0x406b3f08
driver=0x4069a0f0 priv=0x406c6e30
[ 5.763892] [ 9] [ EMERG] [proxy] VQ: virtio_rng - size=8; free=8;
queued=0; desc_head_idx=0; available_idx=0; avail.idx=0; used_cons_idx=0;
used.idx=0; avail.flags=0x0; used.flags=0x0proxy>
### proxy>: vhost dump Foo
[ 7.017901] [ 9] [ EMERG] [proxy] VHost devices:
[ 7.018238] [ 9] [ EMERG] [proxy] No devices of type 'Foo' foundproxy>
```
</details>
Builds with 0 warnings on qemu-armv8a:rpserver and rpproxy.
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]