CV-Bowen opened a new pull request, #22234:
URL: https://github.com/apache/nuttx/pull/22234

   ## Summary
   
   Part 2 of 3 of the rpmsg character device changes, stacked on part 1
   (see apache/nuttx#22142 for the overview):
   
   1. blocking server reads: apache/nuttx#22142
   2. this PR: split reads, request buffers, `rpmsgdev_unregister()`
   3. preallocated opens: apache/nuttx#P3
   
   Depends on apache/nuttx#22142
   
   Reads larger than one rpmsg buffer (writes are split since part 1):
   
   - `split large reads again`, `fix split reads`, `read the device once
     per reply buffer`: a read larger than one buffer is split again, and
     the server calls `file_read()` once per reply buffer.
   - `do not clear the pending read`, `reply once to a blocking read`
     (server): the read state is no longer wiped while its work item may
     still be queued, and the read work is queued only once, so the client
     gets one reply per read.
   
   Request buffers:
   
   - `allocate request messages from the rpmsg pool`, `keep request buffers
     off the stack with stack protection`: with `CONFIG_RPMSG_POOL_COUNT >
     0` the requests and cookies came from the rpmsg pool, so that the rpmsg
     work queue never writes another task's stack.
   - `keep request messages on the stack again`: a pending blocking read
     held two pool blocks, so a few idle readers exhausted the pool; the
     requests go back on the caller's stack and rpmsgdev no longer uses the
     pool. It is moved up from later in the history so that this PR does
     not leave the pool exhaustion behind; the pool commits stay because
     the read commits in between are built on them.
   - `wait for the endpoint in every operation`.
   
   Interface:
   
   - `forward a private ioctl with a variable payload`: new
     `RPMSGDEV_PRIVATE_IOCTL` + `struct rpmsgdev_private_ioctl`.
   - `add rpmsgdev_unregister()`.
   
   No API, protocol or Kconfig default change breaks existing users.
   
   ## Impact
   
   - New `rpmsgdev_unregister()`, `RPMSGDEV_PRIVATE_IOCTL`.
   - Reads larger than one rpmsg buffer are no longer capped at one buffer.
   - Net, rpmsgdev does not use the rpmsg pool.
   - Only `drivers/misc/rpmsgdev*` and `include/nuttx/drivers/rpmsgdev.h`
     are touched.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU 
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
   
   Every commit of the three parts builds sim:rpserver, sim:rpproxy (with
   `RPMSGDEV_TEST` from the commit that drops the `flags` argument),
   qemu-armv8a:rpserver (+ `DEV_RPMSG_SERVER`) and qemu-armv8a:rpproxy
   (+ `DEV_RPMSG`) with 0 warnings.
   
   Runtime setup (test-only board changes, not part of this PR): the
   server creates three FIFOs `/dev/p126fifo0..2` and keeps a writer open
   on each, so a reader blocks until data is written; the proxy registers
   them as `/dev/server-fifo0..2`, plus `/dev/zero` as `/dev/server-zero`.
   Both sides use `CONFIG_RPMSG_POOL_COUNT=4`; sim also has `MM_KASAN`. 
qemu-armv8a runs
   rpserver + rpproxy as two QEMU instances over ivshmem.
   
   The same cases run on the head of each part, on both targets:
   
   | Case | part 1 | part 2 | part 3 |
   |---|---|---|---|
   | `dd if=/dev/server-zero bs=8192 count=4` (sim time) | 32768 bytes, 239967 
usec | 32768 bytes, 70225 usec | 32768 bytes, 40294 usec |
   | blocking read of `/dev/server-fifo0`, then `echo p126blk > /dev/p126fifo0` 
on the server | waits, gets the data | same | same |
   | three idle blocking readers, then more rpmsgdev I/O and `rpmsg ping` | all 
wait, I/O and ping work | same | same |
   | server `rptun stop` while the proxy has a blocking read pending | server 
alive, the proxy's read returns -ENOTCONN (107) | same | same |
   
   (The test harness flags the proxy's `nsh: cat: read failed: 107` line
   as an error; it is the expected -ENOTCONN. Part 1 reads at most one
   rpmsg buffer per call, hence the slower `dd`.)
   
   Without the fixes (on earlier splits of this series that did not have
   the fix yet):
   
   - `rptun stop` with a read pending: qemu server crashes in
     `rpmsgdev_read_work()`, sim: KASAN read error in `work_dispatch()`.
   - three idle readers with the pool (before `keep request messages on
     the stack again`): the qemu proxy crashes in `rpmsgdev_open()` on the
     NULL pool block, the sim proxy hangs.
   
   <details>
   <summary>qemu-armv8a, before `keep request messages on the stack again`: 3rd 
idle reader with a 4-block pool</summary>
   
   ```
   proxy> cat /dev/server-fifo2 > /dev/null &
   sh [15:100]
   [   20.881482] [15] [ EMERG] [proxy] dump_assert_info: Assertion failed 
panic: at file: /arch/arm64/src/common/arm64_fatal.c:696 task: sh process: sh 
0x40523770
   [   20.890325] [15] [ ALERT] [proxy] up_dump_register: ELR:       0x404806d4
   
   $ aarch64-none-elf-addr2line -fipe qemu-armv8a_rpproxy/nuttx 0x404806cc 
0x404cf294 0x404ce06c
   memset at libs/libc/machine/arm64/arch_memset.S:121
   rpmsgdev_send_recv at drivers/misc/rpmsgdev.c:955
   rpmsgdev_open at drivers/misc/rpmsgdev.c:233
   ```
   
   </details>
   
   No regression in rpmsg: on the head of this PR sim:rpserver/rpproxy and 
qemu-armv8a:rpserver/rpproxy pass the fixed rpmsg cases (dump, ping, rpmsgfs) 
plus the rpmsgdev cases on the unchanged sim configs (console, null, a 16 KB 
write in 4 KB blocks, small reads), 21/21. qemu-armv8a was built with 
LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for 
nxinit to start nsh there; unrelated to this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to