This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 78ee3dd0e3d5b689d4c18990653b66f4385dac33
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Nov 24 13:06:59 2026 +0800

    openamp: hold the endpoint across the ns bound callback
    
    rpmsg_virtio_ns_callback() drops rdev->lock before it calls
    ns_bound_cb() for NS_CREATE and NS_CREATE_ACK, so a concurrent close()
    can drop the last reference and free the endpoint while the callback
    still uses it. Add a patch that takes a reference around the callback,
    as the NS_DESTROY path already does around ns_unbind_cb().
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 ...o-hold-the-endpoint-across-the-ns-bound-c.patch | 63 ++++++++++++++++++++++
 openamp/open-amp.cmake                             |  2 +
 openamp/open-amp.defs                              |  1 +
 3 files changed, 66 insertions(+)

diff --git 
a/openamp/0026-rpmsg_virtio-hold-the-endpoint-across-the-ns-bound-c.patch 
b/openamp/0026-rpmsg_virtio-hold-the-endpoint-across-the-ns-bound-c.patch
new file mode 100644
index 00000000000..64387947716
--- /dev/null
+++ b/openamp/0026-rpmsg_virtio-hold-the-endpoint-across-the-ns-bound-c.patch
@@ -0,0 +1,63 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Bowen Wang <[email protected]>
+Date: Mon, 15 Jun 2026 15:06:07 +0800
+Subject: [PATCH] rpmsg_virtio: hold the endpoint across the ns bound callback
+
+rpmsg_virtio_ns_callback() drops rdev->lock before it calls
+ns_bound_cb() for NS_CREATE and NS_CREATE_ACK, so a concurrent close()
+can drop the last reference and free the endpoint while the callback
+still uses it.
+
+Take a reference around the callback, as the NS_DESTROY path already
+does around ns_unbind_cb().
+
+Signed-off-by: Bowen Wang <[email protected]>
+---
+ lib/rpmsg/rpmsg_virtio.c | 14 ++++++++++++++
+ 1 file changed, 14 insertions(+)
+
+diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c
+index 44e95ba..971543b 100644
+--- a/lib/rpmsg/rpmsg_virtio.c
++++ open-amp/lib/rpmsg/rpmsg_virtio.c
+@@ -614,12 +614,19 @@ static int rpmsg_virtio_ns_callback(struct 
rpmsg_endpoint *ept, void *data,
+                               rdev->ns_bind_cb(rdev, ns_msg.name, dest);
+               } else if (_ept->dest_addr == RPMSG_ADDR_ANY) {
+                       _ept->dest_addr = dest;
++                      if (ept_to_release)
++                              rpmsg_ept_incref(_ept);
+                       metal_mutex_release(&rdev->lock);
+                       if (_ept->name[0] && rdev->support_ack)
+                               rpmsg_send_ns_message(_ept, 
RPMSG_NS_CREATE_ACK);
+                       /* notify application that the endpoint has been bound 
*/
+                       if (_ept->ns_bound_cb)
+                               _ept->ns_bound_cb(_ept);
++                      if (ept_to_release) {
++                              metal_mutex_acquire(&rdev->lock);
++                              rpmsg_ept_decref(_ept);
++                              metal_mutex_release(&rdev->lock);
++                      }
+               }
+               else
+                       metal_mutex_release(&rdev->lock);
+@@ -627,10 +634,17 @@ static int rpmsg_virtio_ns_callback(struct 
rpmsg_endpoint *ept, void *data,
+               /* save the received destination address */
+               if (_ept && _ept->dest_addr == RPMSG_ADDR_ANY) {
+                       _ept->dest_addr = dest;
++                      if (ept_to_release)
++                              rpmsg_ept_incref(_ept);
+                       metal_mutex_release(&rdev->lock);
+                       /* notify application that the endpoint has been bound 
*/
+                       if (_ept->ns_bound_cb)
+                               _ept->ns_bound_cb(_ept);
++                      if (ept_to_release) {
++                              metal_mutex_acquire(&rdev->lock);
++                              rpmsg_ept_decref(_ept);
++                              metal_mutex_release(&rdev->lock);
++                      }
+               }
+               else
+                       metal_mutex_release(&rdev->lock);
+-- 
+2.34.1
+
diff --git a/openamp/open-amp.cmake b/openamp/open-amp.cmake
index fb1454f02c5..db372a7d430 100644
--- a/openamp/open-amp.cmake
+++ b/openamp/open-amp.cmake
@@ -88,6 +88,8 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
       
${CMAKE_CURRENT_LIST_DIR}/0024-virtio-restore-the-virtio_dev_name-declaration.patch
       && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
       
${CMAKE_CURRENT_LIST_DIR}/0025-rpmsg_virtio-add-priority-in-the-rpmsg-virtio-config.patch
+      && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
+      
${CMAKE_CURRENT_LIST_DIR}/0026-rpmsg_virtio-hold-the-endpoint-across-the-ns-bound-c.patch
     DOWNLOAD_NO_PROGRESS true
     TIMEOUT 30)
 
diff --git a/openamp/open-amp.defs b/openamp/open-amp.defs
index 37ace37b986..2d224e75087 100644
--- a/openamp/open-amp.defs
+++ b/openamp/open-amp.defs
@@ -91,6 +91,7 @@ open-amp.zip:
        $(Q) patch -p0 < 
0023-rpmsg_virtio-let-the-caller-provide-the-virtqueue-ca.patch
        $(Q) patch -p0 < 
0024-virtio-restore-the-virtio_dev_name-declaration.patch
        $(Q) patch -p0 < 
0025-rpmsg_virtio-add-priority-in-the-rpmsg-virtio-config.patch
+       $(Q) patch -p0 < 
0026-rpmsg_virtio-hold-the-endpoint-across-the-ns-bound-c.patch
 
 .openamp_headers: open-amp.zip
 else

Reply via email to