This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a69622c6303a23520c6e9e8e7044938b4f6fe3e4 Author: Yongrong Wang <[email protected]> AuthorDate: Mon Sep 8 00:00:00 2025 +0800 openamp: publish a virtqueue only after it is initialized Patch 0015 ("optimize virtqueue_notification() called condition") made rproc_virtio_notified() read the vring of every non-NULL vring_info->vq, via virtqueue_nused()/virtqueue_navail(), to skip notifications without buffers. But rproc_virtio_create_virtqueue() stores the virtqueue in vring_info->vq before virtqueue_create() has set it up, so a notification in that window, which the rptun doorbell poll delivers from interrupt context, reads an uninitialized vring. On qemu-armv8a:rpproxy it shows up while vhost-rng creates its virtqueues: Assertion failed !up_interrupt_context(): at file: /arch/arm64/src/common/arm64_fatal.c:637 task: rptun process: Kernel ELR: virtqueue_navail at openamp/open-amp/lib/virtio/virtqueue.c:429 rproc_virtio_notified at lib/remoteproc/remoteproc_virtio.c:422 remoteproc_get_notification at lib/remoteproc/remoteproc.c:1060 rptun_callback at drivers/rptun/rptun.c:978 rptun_ivshmem_wdog at drivers/rptun/rptun_ivshmem.c:762 ... rproc_virtio_create_virtqueue at lib/remoteproc/remoteproc_virtio.c:64 vhost_rng_probe at drivers/vhost/vhost-rng.c:153 Extend patch 0015: build the virtqueue in a local variable, free it if virtqueue_create() fails, and store it in vring_info->vq only once it is complete. Signed-off-by: Yongrong Wang <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- ...roc_virtio-optimize-virtqueue_notificatio.patch | 61 ++++++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/openamp/0015-lib-remoteproc_virtio-optimize-virtqueue_notificatio.patch b/openamp/0015-lib-remoteproc_virtio-optimize-virtqueue_notificatio.patch index 78f5390365d..41e038a224a 100644 --- a/openamp/0015-lib-remoteproc_virtio-optimize-virtqueue_notificatio.patch +++ b/openamp/0015-lib-remoteproc_virtio-optimize-virtqueue_notificatio.patch @@ -13,16 +13,67 @@ virtqueue created in the virtio/vhost driver but the virtio devices has been added to the remoteproc virtio devices list after the remoteproc transport layer create the virtio devices. +3. store the virtqueue in vring_info->vq only after virtqueue_create() +has initialized it, because rproc_virtio_notified() now reads the vring +of every non-NULL vring_info->vq and may run from an interrupt while +rproc_virtio_create_virtqueue() is still in progress. + Signed-off-by: Bowen Wang <[email protected]> +Signed-off-by: Yongrong Wang <[email protected]> --- - lib/remoteproc/remoteproc_virtio.c | 13 ++++++++++--- - 1 file changed, 10 insertions(+), 3 deletions(-) + lib/remoteproc/remoteproc_virtio.c | 29 ++++++++++++++++++++--------- + 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/remoteproc/remoteproc_virtio.c open-amp/lib/remoteproc/remoteproc_virtio.c -index 7dee1354e0..2470454377 100644 --- a/lib/remoteproc/remoteproc_virtio.c +++ open-amp/lib/remoteproc/remoteproc_virtio.c -@@ -403,6 +403,7 @@ int rproc_virtio_notified(struct virtio_device *vdev, uint32_t notifyid) +@@ -41,6 +41,7 @@ + struct virtio_vring_info *vring_info; + struct vring_alloc_info *vring_alloc; + struct remoteproc_virtio *rpvdev; ++ struct virtqueue *vq; + int ret; + (void)flags; + +@@ -53,8 +54,8 @@ + return ERROR_VQUEUE_INVLD_PARAM; + + /* Alloc the virtqueue and init it */ +- vring_info->vq = virtqueue_allocate(vring_alloc->num_descs); +- if (!vring_info->vq) ++ vq = virtqueue_allocate(vring_alloc->num_descs); ++ if (!vq) + return ERROR_NO_MEM; + + if (VIRTIO_ROLE_IS_DRIVER(vdev)) { +@@ -65,19 +66,22 @@ + } + + ret = virtqueue_create(vdev, idx, name, vring_alloc, callback, +- vdev->func->notify, vring_info->vq); +- if (ret) ++ vdev->func->notify, vq); ++ if (ret) { ++ virtqueue_free(vq); + return ret; ++ } + + /* + * If vq->shm_io is uninitialized, init it here. Now only rpmsg device + * init the shm_io specially instead of by transport layer. + */ +- if (!vring_info->vq->shm_io) { ++ if (!vq->shm_io) { + rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev); +- virtqueue_set_shmem_io(vring_info->vq, rpvdev->shm_io); ++ virtqueue_set_shmem_io(vq, rpvdev->shm_io); + } + ++ vring_info->vq = vq; + return 0; + } + +@@ -403,6 +407,7 @@ unsigned int num_vrings, i; struct virtio_vring_info *vring_info; struct virtqueue *vq; @@ -30,7 +81,7 @@ index 7dee1354e0..2470454377 100644 if (!vdev) return -RPROC_EINVAL; -@@ -412,9 +413,15 @@ int rproc_virtio_notified(struct virtio_device *vdev, uint32_t notifyid) +@@ -412,9 +417,15 @@ num_vrings = vdev->vrings_num; for (i = 0; i < num_vrings; i++) { vring_info = &vdev->vrings_info[i];
