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

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

commit 0900b21217a26515d1636d6cd9a0ee5f9dd2c492
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Sep 3 14:19:25 2025 +0800

    net: change conn lock from mutex to rmutex
    
    UDP and PKT will hold the dev lock and conn lock when calling back the
    protocol stack from the network dirver. At this time, if the poll_notify
    notifies usrsock_server and executes poll_teardown, a conn double lock
    will appear. so we changed the lock to a recursive lock
    
    sched_dumpstack
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/Libs/libc/sched/sched_dumpstack.c:71
    __assert
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/libs/libc/assert/lib_assert.c:49
    nxsem_wait_slow
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/semaphore/sem_wait.c:102
 (discriminator 1)
    nxmutex_lock
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/include/nuttx/mutex.h:514
    udp_pollteardown
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:278
    usrsock_rpmsg_poll_setup
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1232
    usrsock_rpmsg_poll_cb
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1299
    poll_notify
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_poll.c:296
    udp_poll_eventhandler
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:105
    devif_conn_event
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/devif_callback.c:481
    udp_callback
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_callback.c:324
    udp_input_conn
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_input.c:150
    ipv4_in
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:425
    ipv4_input
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:533
    tun_net_receive_tun
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
    tun_net_receive_tun
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
    file_writev_compat
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_write.c:89
    rpmsgdev_write_handler
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/misc/rpmsgdev_server.c:354
    rpmsg_virtio_process_rx_buffer
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:256
    rpmsg_virtio_rx_worker
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:291
    work_dispatch
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:233
    work_thread
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:293
    nxtask_start
    
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/task/task_start.c:99
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 include/nuttx/net/net.h    | 2 +-
 net/can/can_conn.c         | 2 +-
 net/can/can_sockif.c       | 2 +-
 net/icmp/icmp_conn.c       | 2 +-
 net/icmp/icmp_sockif.c     | 2 +-
 net/icmpv6/icmpv6_conn.c   | 2 +-
 net/icmpv6/icmpv6_sockif.c | 2 +-
 net/pkt/pkt_conn.c         | 2 +-
 net/pkt/pkt_sockif.c       | 2 +-
 net/tcp/tcp_conn.c         | 4 ++--
 net/udp/udp_conn.c         | 4 ++--
 net/utils/net_lock.c       | 8 ++++----
 12 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index c16c4c38f2e..760d0488dca 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -211,7 +211,7 @@ struct socket_conn_s
    * This mutex is also used to protect the list of callbacks.
    */
 
-  mutex_t       s_lock;      /* Protect the connection structure */
+  rmutex_t      s_lock;      /* Protect the connection structure */
 
   /* Socket options */
 
diff --git a/net/can/can_conn.c b/net/can/can_conn.c
index 69f41b813b0..ccee17861dc 100644
--- a/net/can/can_conn.c
+++ b/net/can/can_conn.c
@@ -138,7 +138,7 @@ void can_free(FAR struct can_conn_s *conn)
   /* Remove the connection from the active list */
 
   dq_rem(&conn->sconn.node, &g_active_can_connections);
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
 
 #ifdef CONFIG_NET_CAN_WRITE_BUFFERS
   /* Free the write queue */
diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index 5084363f0f8..f9102847722 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -236,7 +236,7 @@ static int can_setup(FAR struct socket *psock)
       conn->sndbufs = CONFIG_NET_SEND_BUFSIZE;
       nxsem_init(&conn->sndsem, 0, 0);
 #endif
-      nxmutex_init(&conn->sconn.s_lock);
+      nxrmutex_init(&conn->sconn.s_lock);
 
       /* Attach the connection instance to the socket */
 
diff --git a/net/icmp/icmp_conn.c b/net/icmp/icmp_conn.c
index 5457b0268c3..c845818e4f3 100644
--- a/net/icmp/icmp_conn.c
+++ b/net/icmp/icmp_conn.c
@@ -128,7 +128,7 @@ void icmp_free(FAR struct icmp_conn_s *conn)
   /* Remove the connection from the active list */
 
   dq_rem(&conn->sconn.node, &g_active_icmp_connections);
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
 
   /* Free the connection. */
 
diff --git a/net/icmp/icmp_sockif.c b/net/icmp/icmp_sockif.c
index 729eca45577..d637854c21b 100644
--- a/net/icmp/icmp_sockif.c
+++ b/net/icmp/icmp_sockif.c
@@ -145,7 +145,7 @@ static int icmp_setup(FAR struct socket *psock)
           conn->filter = UINT32_MAX;
         }
 
-      nxmutex_init(&conn->sconn.s_lock);
+      nxrmutex_init(&conn->sconn.s_lock);
 
       /* Save the pre-allocated connection in the socket structure */
 
diff --git a/net/icmpv6/icmpv6_conn.c b/net/icmpv6/icmpv6_conn.c
index 3cb6518b7de..71a2d493325 100644
--- a/net/icmpv6/icmpv6_conn.c
+++ b/net/icmpv6/icmpv6_conn.c
@@ -125,7 +125,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn)
   /* Remove the connection from the active list */
 
   dq_rem(&conn->sconn.node, &g_active_icmpv6_connections);
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
 
   /* Free the connection. */
 
diff --git a/net/icmpv6/icmpv6_sockif.c b/net/icmpv6/icmpv6_sockif.c
index 1aef9dff2e9..0c3954493cc 100644
--- a/net/icmpv6/icmpv6_sockif.c
+++ b/net/icmpv6/icmpv6_sockif.c
@@ -144,7 +144,7 @@ static int icmpv6_setup(FAR struct socket *psock)
           memset(&conn->filter, 0xff, sizeof(conn->filter));
         }
 
-      nxmutex_init(&conn->sconn.s_lock);
+      nxrmutex_init(&conn->sconn.s_lock);
 
       /* Save the pre-allocated connection in the socket structure */
 
diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c
index 0669cc7f8ea..9c57d4f8e2a 100644
--- a/net/pkt/pkt_conn.c
+++ b/net/pkt/pkt_conn.c
@@ -127,7 +127,7 @@ void pkt_free(FAR struct pkt_conn_s *conn)
   /* Remove the connection from the active list */
 
   dq_rem(&conn->sconn.node, &g_active_pkt_connections);
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
 
 #ifdef CONFIG_NET_PKT_WRITE_BUFFERS
   /* Free the write queue */
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index 17c2120e4f1..c130720c5b9 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -133,7 +133,7 @@ static int pkt_sockif_alloc(FAR struct socket *psock)
   nxsem_init(&conn->sndsem, 0, 0);
 #endif
 
-  nxmutex_init(&conn->sconn.s_lock);
+  nxrmutex_init(&conn->sconn.s_lock);
 
   /* Save the pre-allocated connection in the socket structure */
 
diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 0a2dc61f687..9498a2d5590 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -729,7 +729,7 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
 
       nxsem_init(&conn->snd_sem, 0, 0);
 #endif
-      nxmutex_init(&conn->sconn.s_lock);
+      nxrmutex_init(&conn->sconn.s_lock);
 
       /* Set the default value of mss to max, this field will changed when
        * receive SYN.
@@ -852,7 +852,7 @@ void tcp_free(FAR struct tcp_conn_s *conn)
       tcp_conn_list_unlock();
     }
 
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
   tcp_free_rx_buffers(conn);
 
 #ifdef CONFIG_NET_TCP_WRITE_BUFFERS
diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c
index 8cdebd41743..a8c77d6d623 100644
--- a/net/udp/udp_conn.c
+++ b/net/udp/udp_conn.c
@@ -571,7 +571,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain)
       nxsem_init(&conn->sndsem, 0, 0);
 #endif
 
-      nxmutex_init(&conn->sconn.s_lock);
+      nxrmutex_init(&conn->sconn.s_lock);
 #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
       /* Initialize the write buffer lists */
 
@@ -611,7 +611,7 @@ void udp_free(FAR struct udp_conn_s *conn)
   /* Remove the connection from the active list */
 
   dq_rem(&conn->sconn.node, &g_active_udp_connections);
-  nxmutex_destroy(&conn->sconn.s_lock);
+  nxrmutex_destroy(&conn->sconn.s_lock);
 
   /* Release any read-ahead buffers attached to the connection, NULL is ok */
 
diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c
index 0a2037ca431..0f9e0f8f9b0 100644
--- a/net/utils/net_lock.c
+++ b/net/utils/net_lock.c
@@ -476,12 +476,12 @@ FAR struct iob_s *net_ioballoc(bool throttled)
 
 void conn_lock(FAR struct socket_conn_s *sconn)
 {
-  nxmutex_lock(&sconn->s_lock);
+  nxrmutex_lock(&sconn->s_lock);
 }
 
 void conn_unlock(FAR struct socket_conn_s *sconn)
 {
-  nxmutex_unlock(&sconn->s_lock);
+  nxrmutex_unlock(&sconn->s_lock);
 }
 
 void conn_dev_lock(FAR struct socket_conn_s *sconn,
@@ -492,13 +492,13 @@ void conn_dev_lock(FAR struct socket_conn_s *sconn,
       netdev_lock(dev);
     }
 
-  nxmutex_lock(&sconn->s_lock);
+  nxrmutex_lock(&sconn->s_lock);
 }
 
 void conn_dev_unlock(FAR struct socket_conn_s *sconn,
                      FAR struct net_driver_s *dev)
 {
-  nxmutex_unlock(&sconn->s_lock);
+  nxrmutex_unlock(&sconn->s_lock);
 
   if (dev != NULL)
     {

Reply via email to