Commit Graph

21 Commits

Author SHA1 Message Date
wangyongrong 7508a10e20 rptun: Strip rpmsg and rptun
nuttx/driver/rpmsg: new folder, extract common rpmsg api in rptun.c to rpmsg.c.
rpmsg provide rpmsg_ops to each backend for specific implementation.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-01-16 15:58:32 +01:00
Zhe Weng 90a8e2e422 usrsock_rpmsg_server: Keep msg order in recursive call
In `drivers/rptun/rptun.c`, we have a `rptun_is_recursive` function,
which lets rptun thread run recursively. Then the `usrsock_rpmsg_ept_cb`
may be called inside `usrsock_rpmsg_ept_cb`, which can cause some
unexpected behavior, so we add a queue to keep the order of incoming
messages to reduce the complexity.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-01 10:14:18 +08:00
Zhe Weng 52fddb1f12 usrsock_rpmsg_server: Save iov and remain per endpoint
Then we may support multiple endpoints with sendto working correctly.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-01 10:14:18 +08:00
Zhe Weng e4721cef5c usrsock_rpmsg_server: Add net_lock to combine get_tx_payload and recvfrom in recvfrom_handler
A dead lock may happen before this patch:
rptun thread (usrsock_rpmsg_recvfrom_handler):
 Gets all tx payload but waiting net_lock in psock_recvfrom
net driver thread (higher priority):
 Receives a packet, holding net_lock, calling usrsock_rpmsg_send_event
 But no tx buffer left, so rpmsg_send blocks, and won't release net_lock

In short:
Rptun: Hold all `tx_payload_buffer` -> want `net_lock`
Driver: Hold `net_lock` -> want `tx_payload_buffer`

This patch use net_lock to combine get_tx_payload and recvfrom together,
then:
- If it's waiting net_lock, tx payload will not be held, other threads
  may get tx buffer and do their work.
- If net_lock is got, it won't be disturbed before finish receiving,
  then tx payload won't have chance to be blocked before releasing.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-14 14:32:40 +08:00
Zhe Weng 33da959fbc usrsock_rpmsg_server: Clear revents for POLLHUP and POLLERR
Note:
tcp_poll_eventhandler have logic after poll_notify, if we teardown poll
inside poll callback without clearing revents, use-after-free will
happen.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-12 22:12:31 +08:00
yintao 23dee24a7d nuttx/usrsock: fix rpmsg_usrsock memory leak when stop remote
1 0x826037 in host_memalign sim/posix/sim_hostmemory.c:180
2 0x82665a in host_realloc sim/posix/sim_hostmemory.c:222
3 0x6320b8 in mm_realloc sim/sim_heap.c:261
4 0x63201f in mm_malloc sim/sim_heap.c:193
5 0x632124 in mm_zalloc sim/sim_heap.c:296
6 0x62cbd2 in zalloc umm_heap/umm_zalloc.c:70
7 0x5f3548 in usrsock_rpmsg_ns_bind usrsock/usrsock_rpmsg_server.c:977
8 0x5cdb7a in rptun_ns_bind rptun/rptun.c:604
9 0x760a94 in rpmsg_virtio_ns_callback open-amp/lib/rpmsg/rpmsg_virtio.c:676
10 0x75f958 in rpmsg_virtio_rx_callback open-amp/lib/rpmsg/rpmsg_virtio.c:583
11 0x76b2c6 in virtqueue_notification open-amp/lib/virtio/virtqueue.c:711
12 0x756872 in rproc_virtio_notified open-amp/lib/remoteproc/remoteproc_virtio.c:433
13 0x751d2c in remoteproc_get_notification open-amp/lib/remoteproc/remoteproc.c:1005
14 0x5caa15 in rptun_worker rptun/rptun.c:344
15 0x5cabc7 in rptun_thread rptun/rptun.c:380
16 0x5849ca in nxtask_start task/task_start.c:129
17 0x62fd6a in pre_start sim/sim_initialstate.c:52

Signed-off-by: yintao <yintao@xiaomi.com>
2023-09-08 01:15:26 +08:00
zhanghongyu b30a389459 usrsock_server: fix coverity for recvfrom handle
req->usockid may not be in a valid range when ret less than zero and not -EAGAIN.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-01 12:30:54 +03:00
zhanghongyu dd080773cc usrsock_server: coverity fix for access invalid index
req->usockid maybe < 0 or > CONFIG_NET_USRSOCK_RPMSG_SERVER_NSOCKS,
if so , priv->pfds[req->usockid] will access invalid memory.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-11 15:29:59 +08:00
wangchen dd0f967798 usrsock_server:fix incomplete received data error
if number of bytes available for reading more than zero,set USRSOCK_EVENT_RECVFROM_AVAIL flag into the event

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-06-21 07:40:52 +03:00
zhanghongyu aa43f6ff1a usrsock_rpmsg_server: fix poll recursive when revent POLLHUP or POLLERR
the previous patch can not handle the revent is POLLHUP or POLLERR,
poll_setup needs to be executed only when the POLLIN or POLLOUT event
changes.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-13 15:33:05 +08:00
chao an 7c5d2a8bdd usrsock/dns: add sanity check before send dns event
Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-06 13:29:23 +08:00
zhanghongyu 06a10202af usrsock_server: fix issues with usrsock_rpmsg_sendto_handler
If the current poll setup only has POLLIN, adding POLLOUT does not cause the
protocol stack to refocus on flags such as TCP_ACK or UDP_POLL, the user is
not notified when flags for POLLOUT relationships appear and vice versa,
so we have to call poll_setup again.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-12 22:40:41 +08:00
Zhe Weng 7671ed9615 usrsock_server: Raise error earlier for large sendto request
It's better to raise error before client sends its (NIOVEC+1)th buffer
(and release buffers held by server), otherwise the client may stuck at
getting (NIOVEC+1)th tx buffer if NIOVEC is equal to rpmsg buffer num.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-15 21:56:03 +09:00
Zhe Weng 0d118ec214 usrsock_server: Use remain instead of iov[0] to figure out partial requests
Found a problem:

When sendto handler gets an error, it will release all its rx buffer,
then iov_base becomes NULL. But it cannot let client stop its request,
then the next data from client cannot be handled by usrsock server
correctly.

It's better to note down the remaining bytes, then we can stop at
correct time.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-15 21:56:03 +09:00
Zhe Weng 9fd4d6b767 usrsock_server: Do not poll SOCK_CTRL.
It seems that we don't need to poll the SOCK_CTRL sockets, so skip them in usrsock server.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-29 09:18:36 -03:00
zhanghongyu 0550082966 usrsock_server: add debug info for poll_setup
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-03-29 09:18:36 -03:00
Zhe Weng 9d53de374c usrsock: Add DebugAssert for poll setup result
We never check its result and assume it will success, so an assert should be better than retval.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-22 01:42:14 +08:00
Zhe Weng d3dd349649 net: Implement shutdown() for usrsock
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
梁超众 7b8ef5dc1b usrsock: only TCP data should be aggregrated for rpmsg case
non-streaming socket's rx data should not be aggregrated.

Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
2023-01-27 00:38:32 +02:00
zhanghongyu 48c9d10336 net_socket: add accept4 function
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-11 23:28:08 +08:00
梁超众 aca1a065a8 move usrsock to kernel space
Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
2023-01-11 15:14:03 +08:00