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 05cfdadeb22676d7fc86a1c0b4e0de68a6c37fc2 Author: wangshaoxin <[email protected]> AuthorDate: Fri Oct 30 15:07:12 2026 +0800 net/rpmsg: do not send the SYNC on an unregistered endpoint rpmsg_socket_ns_bound() called the blocking rpmsg_send() from the rx callback. The NS_CREATE_ACK path of rpmsg_virtio sets dest_addr and takes a reference under rdev->lock, then drops the lock before calling ns_bound_cb. A higher priority task closing the socket in that window unregisters the endpoint, which clears ept->rdev while the reference keeps the object alive, so is_rpmsg_ept_ready() never becomes true and rpmsg_send() waits the whole RPMSG_TICK_COUNT. With a single rx thread no other message of that core is handled meanwhile. Reserve the tx buffer first and check is_rpmsg_ept_ready() and send with rpmsg_send_offchannel_nocopy() under recvlock, as rpmsg_socket_wakeup() does. conn->unbind is not part of the check: a stale flag left by an earlier NS_DESTROY is cleared only by the SYNC from the peer, so bailing out on it would leave a reconnecting peer without our recvbuf size. Signed-off-by: wangshaoxin <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- net/rpmsg/rpmsg_sockif.c | 53 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index 7647231565b..fbe0e37a236 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -632,15 +632,54 @@ static bool rpmsg_socket_pend_remove(FAR struct rpmsg_socket_conn_s *server, static void rpmsg_socket_ns_bound(struct rpmsg_endpoint *ept) { FAR struct rpmsg_socket_conn_s *conn = ept->priv; - struct rpmsg_socket_sync_s msg; + FAR struct rpmsg_socket_sync_s *msg; + uint32_t len = sizeof(*msg); + + if (!ept->rdev) + { + return; + } + + /* Reserve the tx buffer without holding recvlock, since it may block + * waiting for a free vring buffer. + */ - msg.cmd = RPMSG_SOCKET_CMD_SYNC; - msg.size = circbuf_size(&conn->recvbuf); - msg.pid = nxsched_getpid(); - msg.uid = getuid(); - msg.gid = getgid(); + msg = rpmsg_get_tx_payload_buffer(ept, &len, true); + if (msg == NULL) + { + return; + } - rpmsg_send(&conn->ept, &msg, sizeof(msg)); + DEBUGASSERT(len >= sizeof(*msg)); + + msg->cmd = RPMSG_SOCKET_CMD_SYNC; + msg->pid = nxsched_getpid(); + msg->uid = getuid(); + msg->gid = getgid(); + + nxmutex_lock(&conn->recvlock); + + /* This runs in the rx callback context, where a blocking rpmsg_send() + * on an endpoint unregistered meanwhile would wait the whole + * RPMSG_TICK_COUNT and stall every inbound message. + * + * conn->unbind is not checked: a stale flag left by an earlier + * NS_DESTROY is cleared only when a SYNC is received, so bailing out on + * it would leave a reconnecting peer without our recvbuf size. + */ + + if (!is_rpmsg_ept_ready(ept)) + { + nxmutex_unlock(&conn->recvlock); + rpmsg_release_tx_buffer(ept, msg); + return; + } + + msg->size = circbuf_size(&conn->recvbuf); + rpmsg_send_offchannel_nocopy(ept, ept->addr, ept->dest_addr, + msg, sizeof(*msg)); + + nxmutex_unlock(&conn->recvlock); } static void rpmsg_socket_ns_unbind(FAR struct rpmsg_endpoint *ept)
