net: change conn lock from mutex to rmutex
Build Documentation / build-html (push) Has been cancelled

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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-09-03 14:19:25 +08:00
committed by Xiang Xiao
parent 3e18d72661
commit 0900b21217
12 changed files with 17 additions and 17 deletions
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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. */
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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. */
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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 */
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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 */
+4 -4
View File
@@ -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)
{