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 69bf46cfe6d0f98c7a4ba2b651482f6b78c15051
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Nov 24 17:04:35 2026 +0800

    openamp: hand the announced extra data to the bind callbacks
    
    Add a patch with ns_bound_extra_cb on the endpoint and ns_bind_extra_cb
    on the device, which receive the extra data of an announcement and are
    called instead of ns_bound_cb and ns_bind_cb when set.
    rpmsg_ns_handle_msg() takes the message length, and rpmsg_virtio
    accepts an announcement longer than struct rpmsg_ns_msg.
    
    rpmsg_port calls rpmsg_ns_handle_msg() too, so update it in the same
    commit: accept an announcement longer than struct rpmsg_ns_msg, copy it
    into a struct rpmsg_ns_msg_max and pass its length on. A peer that
    announces more than that buffer holds is dropped instead of
    overflowing it.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port.c                         |  10 +-
 ...the-announced-extra-data-to-the-bound-and.patch | 186 +++++++++++++++++++++
 openamp/open-amp.cmake                             |   2 +
 openamp/open-amp.defs                              |   1 +
 4 files changed, 195 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c
index 9fe477abc55..a840a8c8d7a 100644
--- a/drivers/rpmsg/rpmsg_port.c
+++ b/drivers/rpmsg/rpmsg_port.c
@@ -503,9 +503,11 @@ static int rpmsg_port_ns_callback(FAR struct 
rpmsg_endpoint *ept,
 {
   FAR struct rpmsg_port_s *port = priv;
   FAR struct rpmsg_device *rdev = &port->rdev;
-  struct rpmsg_ns_msg msg;
+  struct rpmsg_ns_msg_max msg;
 
-  if (len != sizeof(msg))
+  /* The announcement has to be there and to fit in the local message */
+
+  if (len < sizeof(struct rpmsg_ns_msg) || len > sizeof(msg))
     {
       return RPMSG_SUCCESS;
     }
@@ -514,10 +516,10 @@ static int rpmsg_port_ns_callback(FAR struct 
rpmsg_endpoint *ept,
    * improve the buffer utilization.
    */
 
-  memcpy(&msg, data, sizeof(msg));
+  memcpy(&msg, data, len);
   rpmsg_port_release_rx_buffer(rdev, data);
 
-  rpmsg_ns_handle_msg(rdev, &msg);
+  rpmsg_ns_handle_msg(rdev, (FAR struct rpmsg_ns_msg *)&msg, len);
 
   return RPMSG_SUCCESS_BUFFER_RELEASED;
 }
diff --git 
a/openamp/0032-rpmsg-hand-the-announced-extra-data-to-the-bound-and.patch 
b/openamp/0032-rpmsg-hand-the-announced-extra-data-to-the-bound-and.patch
new file mode 100644
index 00000000000..f5355c63f42
--- /dev/null
+++ b/openamp/0032-rpmsg-hand-the-announced-extra-data-to-the-bound-and.patch
@@ -0,0 +1,186 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Bowen Wang <[email protected]>
+Date: Fri, 4 Sep 2026 22:25:07 +0800
+Subject: [PATCH] rpmsg: hand the announced extra data to the bound and bind
+ callbacks
+
+The receiving side has to get the extra data that a name service
+announcement now carries. Add ns_bound_extra_cb to the endpoint and
+ns_bind_extra_cb to the device, with the arguments of the callbacks
+they mirror plus the data, and call them instead when they are set.
+rpmsg_ns_bound_cb and rpmsg_ns_bind_cb are left alone because
+rpmsg_ns_bind_cb is a parameter type of rpmsg_init_vdev().
+
+rpmsg_ns_handle_msg() now takes the message length and passes the data
+past struct rpmsg_ns_msg to the callbacks, valid only during the call.
+
+The virtio callback copies the announcement into a fixed size buffer
+and drops one longer than that buffer.
+
+Signed-off-by: Bowen Wang <[email protected]>
+---
+ lib/include/openamp/rpmsg.h | 28 ++++++++++++++++++++++++++++
+ lib/rpmsg/rpmsg_internal.h  |  3 ++-
+ lib/rpmsg/rpmsg_ns.c        | 17 +++++++++++++----
+ lib/rpmsg/rpmsg_virtio.c    | 10 +++++-----
+ 4 files changed, 48 insertions(+), 10 deletions(-)
+
+diff --git a/lib/include/openamp/rpmsg.h open-amp/lib/include/openamp/rpmsg.h
+index 654185b..db0880d 100644
+--- a/lib/include/openamp/rpmsg.h
++++ open-amp/lib/include/openamp/rpmsg.h
+@@ -72,6 +72,22 @@ typedef void (*rpmsg_ns_unbind_cb)(struct rpmsg_endpoint 
*ept);
+ typedef void (*rpmsg_ns_bind_cb)(struct rpmsg_device *rdev,
+                                const char *name, uint32_t dest);
+ 
++/*
++ * The two callbacks below deliver the extra data announced by the remote
++ * side. They are added next to rpmsg_ns_bound_cb and rpmsg_ns_bind_cb, so
++ * users which do not need the extra data keep working unchanged. When both
++ * are set only the extra variant is called, so it has to do everything the
++ * plain one would.
++ *
++ * extra is only valid for the duration of the call, copy what is needed,
++ * and NULL when no extra data was announced.
++ */
++typedef void (*rpmsg_ns_bound_extra_cb)(struct rpmsg_endpoint *ept,
++                                      const void *extra, size_t extra_len);
++typedef void (*rpmsg_ns_bind_extra_cb)(struct rpmsg_device *rdev,
++                                     const char *name, uint32_t dest,
++                                     const void *extra, size_t extra_len);
++
+ /*
+  * Called when building a name service announcement, to let the service
+  * provide the extra data carried along with it.
+@@ -116,6 +132,12 @@ struct rpmsg_endpoint {
+       /** Endpoint service bound callback, called when remote ept address is 
received */
+       rpmsg_ns_bound_cb ns_bound_cb;
+ 
++      /**
++       * Same as ns_bound_cb, but also receives the extra data announced by
++       * the remote side. Takes precedence over ns_bound_cb when set.
++       */
++      rpmsg_ns_bound_extra_cb ns_bound_extra_cb;
++
+       /**
+        * Called when building a name service announcement for this endpoint,
+        * to let the service provide its extra data
+@@ -187,6 +209,12 @@ struct rpmsg_device {
+       /** Callback handler for name service announcement without local epts 
waiting to bind */
+       rpmsg_ns_bind_cb ns_bind_cb;
+ 
++      /**
++       * Same as ns_bind_cb, but also receives the extra data announced by
++       * the remote side. Takes precedence over ns_bind_cb when set.
++       */
++      rpmsg_ns_bind_extra_cb ns_bind_extra_cb;
++
+       /** Callback handler for name service announcement, called when remote 
ept is destroyed */
+       rpmsg_ns_bind_cb ns_unbind_cb;
+ 
+diff --git a/lib/rpmsg/rpmsg_internal.h open-amp/lib/rpmsg/rpmsg_internal.h
+index 173c44e..58ac2b1 100644
+--- a/lib/rpmsg/rpmsg_internal.h
++++ open-amp/lib/rpmsg/rpmsg_internal.h
+@@ -168,9 +168,10 @@ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, 
unsigned long flags);
+  *
+  * @param rdev                Pointer to the rpmsg device
+  * @param ns_msg      Pointer to the received name service message
++ * @param len         Length of the message, at least sizeof(*ns_msg)
+  */
+ void rpmsg_ns_handle_msg(struct rpmsg_device *rdev,
+-                       const struct rpmsg_ns_msg *ns_msg);
++                       const struct rpmsg_ns_msg *ns_msg, size_t len);
+ 
+ struct rpmsg_endpoint *rpmsg_get_endpoint(struct rpmsg_device *rvdev,
+                                         const char *name, uint32_t addr,
+diff --git a/lib/rpmsg/rpmsg_ns.c open-amp/lib/rpmsg/rpmsg_ns.c
+index 7e6831b..80795b3 100644
+--- a/lib/rpmsg/rpmsg_ns.c
++++ open-amp/lib/rpmsg/rpmsg_ns.c
+@@ -13,11 +13,13 @@
+ #include "rpmsg_internal.h"
+ 
+ void rpmsg_ns_handle_msg(struct rpmsg_device *rdev,
+-                       const struct rpmsg_ns_msg *ns_msg)
++                       const struct rpmsg_ns_msg *ns_msg, size_t len)
+ {
+       struct rpmsg_endpoint *ept;
+       uint32_t dest = ns_msg->addr;
+       bool ept_to_release;
++      size_t extra_len = len - sizeof(*ns_msg);
++      const void *extra = extra_len ? ns_msg->extra : NULL;
+ 
+       /* check if a Ept has been locally registered */
+       metal_mutex_acquire(&rdev->lock);
+@@ -48,7 +50,10 @@ void rpmsg_ns_handle_msg(struct rpmsg_device *rdev,
+                        * - just ignore the request as service not supported.
+                        */
+                       metal_mutex_release(&rdev->lock);
+-                      if (rdev->ns_bind_cb)
++                      if (rdev->ns_bind_extra_cb)
++                              rdev->ns_bind_extra_cb(rdev, ns_msg->name,
++                                                     dest, extra, extra_len);
++                      else if (rdev->ns_bind_cb)
+                               rdev->ns_bind_cb(rdev, ns_msg->name, dest);
+               } else if (ept->dest_addr == RPMSG_ADDR_ANY) {
+                       ept->dest_addr = dest;
+@@ -56,7 +61,9 @@ void rpmsg_ns_handle_msg(struct rpmsg_device *rdev,
+                       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)
++                      if (ept->ns_bound_extra_cb)
++                              ept->ns_bound_extra_cb(ept, extra, extra_len);
++                      else if (ept->ns_bound_cb)
+                               ept->ns_bound_cb(ept);
+               }
+               else
+@@ -67,7 +74,9 @@ void rpmsg_ns_handle_msg(struct rpmsg_device *rdev,
+                       ept->dest_addr = dest;
+                       metal_mutex_release(&rdev->lock);
+                       /* notify application that the endpoint has been bound 
*/
+-                      if (ept->ns_bound_cb)
++                      if (ept->ns_bound_extra_cb)
++                              ept->ns_bound_extra_cb(ept, extra, extra_len);
++                      else if (ept->ns_bound_cb)
+                               ept->ns_bound_cb(ept);
+               }
+               else
+diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c
+index 8fd79ef..6a5326c 100644
+--- a/lib/rpmsg/rpmsg_virtio.c
++++ open-amp/lib/rpmsg/rpmsg_virtio.c
+@@ -554,13 +554,13 @@ static int rpmsg_virtio_ns_callback(struct 
rpmsg_endpoint *ept, void *data,
+                                                              struct 
rpmsg_virtio_device,
+                                                              rdev);
+       struct metal_io_region *io = rvdev->shbuf_io;
+-      struct rpmsg_ns_msg ns_msg;
++      struct rpmsg_ns_msg_max ns_msg;
+ 
+       (void)ept;
+       (void)src;
+ 
+-      if (len != sizeof(ns_msg))
+-              /* Returns as the message is corrupted */
++      /* the announcement has to be there and to fit in the local message */
++      if (len < sizeof(struct rpmsg_ns_msg) || len > sizeof(ns_msg))
+               return RPMSG_SUCCESS;
+ 
+       /*
+@@ -568,10 +568,10 @@ static int rpmsg_virtio_ns_callback(struct 
rpmsg_endpoint *ept, void *data,
+        * improve the buffer utilization.
+        */
+       metal_io_block_read(io, metal_io_virt_to_offset(io, data),
+-                          &ns_msg, sizeof(ns_msg));
++                          &ns_msg, len);
+       rpmsg_virtio_release_rx_buffer(rdev, data);
+ 
+-      rpmsg_ns_handle_msg(rdev, &ns_msg);
++      rpmsg_ns_handle_msg(rdev, (struct rpmsg_ns_msg *)&ns_msg, len);
+ 
+       return RPMSG_SUCCESS_BUFFER_RELEASED;
+ }
+-- 
+2.34.1
+
diff --git a/openamp/open-amp.cmake b/openamp/open-amp.cmake
index 512af5956c5..3a1e7040073 100644
--- a/openamp/open-amp.cmake
+++ b/openamp/open-amp.cmake
@@ -100,6 +100,8 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
       
${CMAKE_CURRENT_LIST_DIR}/0030-rpmsg-export-rpmsg_unregister_endpoint.patch
       && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
       
${CMAKE_CURRENT_LIST_DIR}/0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
+      && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
+      
${CMAKE_CURRENT_LIST_DIR}/0032-rpmsg-hand-the-announced-extra-data-to-the-bound-and.patch
     DOWNLOAD_NO_PROGRESS true
     TIMEOUT 30)
 
diff --git a/openamp/open-amp.defs b/openamp/open-amp.defs
index 64b566f0496..a1685feaca1 100644
--- a/openamp/open-amp.defs
+++ b/openamp/open-amp.defs
@@ -98,6 +98,7 @@ open-amp.zip:
        $(Q) patch -p0 < 
0029-rpmsg-let-a-reference-outlive-the-endpoint-s-registr.patch
        $(Q) patch -p0 < 0030-rpmsg-export-rpmsg_unregister_endpoint.patch
        $(Q) patch -p0 < 
0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
+       $(Q) patch -p0 < 
0032-rpmsg-hand-the-announced-extra-data-to-the-bound-and.patch
 
 .openamp_headers: open-amp.zip
 else

Reply via email to