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 ee973df5b3154009d454867ae75b2686e9f84cae
Author: zhangshuai39 <[email protected]>
AuthorDate: Mon May 11 15:05:44 2026 +0800

    drivers/usrsock/usrsock_rpmsg_server: do not hold s_lock around psock_poll()
    
    usrsock_rpmsg_poll_setup() took conn->s_lock and then called
    psock_poll(), which takes the netdev lock. The network stack takes them
    the other way round (netdev lock, then s_lock), for example in
    devif_poll() -> udp_callback()/tcp_poll() on the high priority work
    queue, so the two could deadlock.
    
    Drop s_lock. Without it, usrsock_rpmsg_poll_cb() on the work queue can
    tear the poll down between the read of pfds->events and the
    psock_poll(..., false) call, which then returns -EINVAL; treat that as
    already torn down and go on with the new setup instead of dropping it.
    
    Signed-off-by: zhangshuai39 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/usrsock/usrsock_rpmsg_server.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/usrsock/usrsock_rpmsg_server.c 
b/drivers/usrsock/usrsock_rpmsg_server.c
index 5e8a893646b..bca4fb7b646 100644
--- a/drivers/usrsock/usrsock_rpmsg_server.c
+++ b/drivers/usrsock/usrsock_rpmsg_server.c
@@ -1200,7 +1200,6 @@ static void usrsock_rpmsg_poll_setup(FAR struct pollfd_s 
*pfds,
 {
   FAR struct usrsock_rpmsg_s *priv = (FAR struct usrsock_rpmsg_s *)pfds->arg;
   FAR struct socket *psock = &priv->socks[pfds->fd];
-  FAR struct socket_conn_s *conn = psock->s_conn;
   int ret = 0;
 
   /* No poll for SOCK_CTRL. */
@@ -1210,13 +1209,24 @@ static void usrsock_rpmsg_poll_setup(FAR struct 
pollfd_s *pfds,
       return;
     }
 
-  nxrmutex_lock(&conn->s_lock);
-
   if (events)
     {
       if (pfds->events)
         {
           ret = psock_poll(psock, pfds, false);
+
+          /* poll_cb running in hpwork may concurrently nest into
+           * poll_setup(pfds, 0) and tear the callback down between our
+           * read of pfds->events above and the call to psock_poll()
+           * here. When that happens udp_pollteardown()/tcp_pollteardown()
+           * return -EINVAL because fds->priv has already been cleared.
+           * Treat that as benign and proceed to setup the fresh callback.
+           */
+
+          if (ret == -EINVAL)
+            {
+              ret = 0;
+            }
         }
 
       if (ret >= 0)
@@ -1244,8 +1254,6 @@ static void usrsock_rpmsg_poll_setup(FAR struct pollfd_s 
*pfds,
            ret, psock->s_domain, psock->s_type, pfds->fd,
            pfds->events, pfds->revents);
     }
-
-  nxrmutex_unlock(&conn->s_lock);
 }
 
 static void usrsock_rpmsg_poll_cb(FAR struct pollfd_s *pfds)

Reply via email to