Skip to content

drivers/rptun/rptun_ivshmem: vsock and net entries, vendor resource tables - #21818

Merged
xiaoxiang781216 merged 11 commits into
apache:masterfrom
CV-Bowen:up/P84-rptun-ivshmem-vsock
Nov 14, 2026
Merged

xiaoxiang781216 merged 11 commits into
apache:masterfrom
CV-Bowen:up/P84-rptun-ivshmem-vsock

Conversation

@CV-Bowen

@CV-Bowen CV-Bowen commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The rptun ivshmem resource table only carries two rng devices and one
rpmsg device, fixed at compile time, so a vhost vsock or vhost-net
backend on one side has no vdev to bind to, and a board cannot supply
its own table.

  • drivers/rptun/rptun_ivshmem: add a vsock device to the resource table
  • drivers/rptun/rptun_ivshmem: offer VIRTIO_VSOCK_F_HOST_CID
  • drivers/rptun/rptun_ivshmem: enlarge the vsock carveout
  • drivers/rptun/rptun_ivshmem: derive the vsock cids from the cpu names
    • guest_cid / host_cid are the first four bytes of the peer and local
      cpu names, so several instances get distinct cids.
  • drivers/rptun/rptun_ivshmem: add the rng entries only with vhost-rng
  • drivers/rptun/rptun_ivshmem: order the table writes before hdr.ver
  • drivers/rptun/rptun_ivshmem: support a vendor resource table
    • pci_register_rptun_ivshmem_slave_driver(cpuname, drvid, rsc_table, rsc_size) lets a slave register its own table; the built-in one
      becomes a const g_rsc_table copied into shared memory.
  • drivers/rptun/rptun_ivshmem: fill the rpmsg cpu names at run time
  • drivers/rptun/rptun_ivshmem: set the vsock cids in the built-in table
  • drivers/rptun/rptun_ivshmem: gate the table entries by vhost config
    • Each vdev entry (rng, rpmsg, vsock) is built only with its vhost
      Kconfig, and the vdev count follows.
  • drivers/rptun/rptun_ivshmem: add a virtio-net device to the table

These are kept as separate commits in the order they were made; the
later ones rework the table the earlier ones extend.

Impact

  • The slave side (the one that writes the table) now offers a vdev only
    for each vhost backend it enables: CONFIG_DRIVERS_VHOST_RNG,
    CONFIG_DRIVERS_VHOST_RPMSG, CONFIG_NET_VSOCK_VHOST,
    CONFIG_DRIVERS_VHOST_NET. qemu-armv8a:rpproxy enables rng and rpmsg,
    so its table keeps one rng device (was two) and the rpmsg device.
  • New pci_register_rptun_ivshmem_slave_driver() in
    include/nuttx/rptun/rptun_ivshmem.h.
  • No Kconfig added or removed.

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

Each commit builds with 0 warnings on qemu-armv8a:rpserver,
qemu-armv8a:rpproxy, both with the vsock overlay below, and
qemu-armv8a:rpproxy with CONFIG_NET + CONFIG_DRIVERS_VHOST_NET.

vsock between the two instances over ivshmem. Overlay on
qemu-armv8a:rpserver and rpproxy: CONFIG_NET, CONFIG_NET_SOCKOPTS,
CONFIG_NET_VSOCK; rpproxy (writes the table) adds
CONFIG_DRIVERS_VHOST + CONFIG_NET_VSOCK_VHOST, rpserver adds
CONFIG_DRIVERS_VIRTIO + CONFIG_NET_VSOCK_VIRTIO. The vsock test
client is apps/examples/vsock from apache/nuttx-apps#4045.
Echo server on the proxy, client on the server connecting to the
proxy's cid "prox" (0x786f7270):

proxy>  vsock -t data -p 28065 -i 1024 -n 64 &
server> vsock -c 2020569712 -t data -p 28065 -i 1024 -n 64
master this PR
vsock vdev on the server none bound, cids from the cpu names
64 x 1 KiB echo connect fails, -ENOTSUP (no transport) 65536 bytes, 10/10 runs
this PR
[    3.407939] [ 9] [ EMERG] [server]   [Vsock Transport] id=19 vdev=0x404bcbc0 driver=0x404a0290 priv=0x404bcf98

[    3.408572] [ 9] [ EMERG] [server]     guest_cid=1987208563, host_cid=2020569712, pkt_bufsize=2092 B (hdr=44 + data=2048)

[    3.409788] [ 9] [ EMERG] [server]   Vsock Connections:

proxy> Vsock server test, port=28065, size=1024, cid=4294967295

Vsock client test, port=28065, size=1024, count=64, cid=2020569712

Connect, s=3

Send finish, sendlen=65536

Close

server> Accept peer_fd=4

Close

master
proxy> Vsock server test, port=28065, size=1024, cid=4294967295

Vsock client test, port=28065, size=1024, count=64, cid=2020569712

Connect, s=3

Connect failed, ret=18446744073709551478   (-ENOTSUP)

Close

One of 12 runs crashed at proxy boot in rptun_ivshmem_wdog() ->
rptun_callback() -> remoteproc_get_notification() ->
virtqueue.c:429, before any vsock traffic: the polling wdog fires
while the vring is still being created. The same race shows on master
with the default rpproxy config (seen in #21757 and #21813 testing);
this PR does not touch that path.

No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 15/15). 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.

@github-actions github-actions Bot added Area: Drivers Drivers issues Size: L The size of the change in this PR is large labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@CV-Bowen
CV-Bowen force-pushed the up/P84-rptun-ivshmem-vsock branch from 0ba428b to 22bacfa Compare November 13, 2026 09:02
CV-Bowen and others added 11 commits November 13, 2026 21:27
Add a virtio-vsock vdev with its three vrings, config space and a
carveout to the ivshmem resource table, so the rptun peer can bind
vsock over the same shared memory as the rng and rpmsg devices.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Advertise VIRTIO_VSOCK_F_HOST_CID and fill host_cid in the vsock
config space, so the driver side learns the cid of the device side
instead of assuming VMADDR_CID_HOST.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Grow the vsock carveout from two to eight shared memory blocks, so
the vsock buffers do not run out of shared memory.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Fixed cids 2 and 3 collide when one instance talks to several peers.
Set guest_cid from the peer cpu name and host_cid from
CONFIG_RPMSG_LOCAL_CPUNAME, using the first four bytes of each.

Signed-off-by: hongfengchen <hongfengchen@xiaomi.com>
Build the two rng vdevs into the resource table only when
CONFIG_DRIVERS_VHOST_RNG is enabled, and number the resource offsets
and carveout names sequentially so the table stays consistent when
they are left out.

Signed-off-by: zhangbo56 <zhangbo56@xiaomi.com>
The master side polls hdr.ver to know the slave has written the
resource table. Add a barrier so the table contents are visible
before hdr.num and hdr.ver are set.

Signed-off-by: wangshaoxin <wangshaoxin@xiaomi.com>
Let a slave register its own resource table with
pci_register_rptun_ivshmem_slave_driver() instead of the built-in one.
The built-in table becomes a const g_rsc_table that is copied into
shared memory, and a NULL table marks the master side.

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
g_rsc_table hard-coded "server" and "proxy" as the rpmsg cpu names.
Use CONFIG_RPMSG_LOCAL_CPUNAME for the remote name and copy the peer
name into host_cpuname when the built-in table is used.

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
The const g_rsc_table lost the run-time cid setup; fill guest_cid and
host_cid from the cpu names again when the built-in table is copied to
shared memory.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Derive RPTUN_IVSHMEM_VIRTIO_NUM from the enabled vhost devices (rng,
rpmsg, vsock) instead of hard-coding it, and guard each vdev entry
with its own Kconfig. Drop the second rng vdev and generate the
"vdevNbuffer" carveout names in order at run time.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Add a virtio-net vdev with its rx/tx vrings and carveout, gated by
CONFIG_DRIVERS_VHOST_NET, so the vhost-net backend can serve the peer.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
@CV-Bowen
CV-Bowen force-pushed the up/P84-rptun-ivshmem-vsock branch from 22bacfa to 8443640 Compare November 13, 2026 13:28
@xiaoxiang781216
xiaoxiang781216 merged commit 49bec82 into apache:master Nov 14, 2026
51 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants