jingfei195887 opened a new pull request, #21725:
URL: https://github.com/apache/nuttx/pull/21725

   ## Summary
   
   Two fixes for an aiocb that the worker thread touches after its owner has
   let it go.
   
   - **fs/aio: unlink lio_listio entries before waking the submitter.**
     `aio_signal()` sends the per-request notification and SIGPOLL first, and
     only then checks and unlinks `aiocbp->lio_link`. Either signal can wake an
     `lio_listio(LIO_WAIT)` caller, which may return and release the aiocb
     list, usually on its stack, while the worker still touches `lio_link`.
     The entry is now unlinked before any notification; the notification order
     is unchanged.
   - **fs/aio: cancel outstanding requests when the process exits.** A request
     that is still queued or running on the low priority worker when its
     process exits keeps a container pointing at the process's aiocb, which
     usually lives on a stack that is about to be freed. The worker later
     writes `aio_result` and `lio_link` into that memory. POSIX cancels the
     outstanding requests of a terminating process. `aio_cleanup()`, called
     from `nxtask_exithook()` before `group_leave()`, takes the process's
     containers off the pending list, cancels queued work, waits for work that
     is already running, and frees the containers.
   
   ## Impact
   
   When a process exits, its queued AIO requests are cancelled and a running
   one is waited for; no completion notification is sent to the exited
   process. `aioc_pid` holds the process ID, so the cleanup runs when the main
   thread exits, not when another thread of the process exits.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
59cb24ea20, `sim:nsh` with
   `CONFIG_FS_AIO`, `CONFIG_SCHED_LPWORK`, `CONFIG_SCHED_LPNTHREADS=2`,
   `CONFIG_PIPES` and `CONFIG_FS_TMPFS`. A small test program:
   
   1. Starts a child task that calls `aio_read()` on an empty FIFO, so the
      request is running on a worker, and then exits.
   2. Writes one byte to the FIFO, so the worker completes that read.
   3. Submits two writes with `lio_listio(LIO_WAIT)` on a tmpfs file.
   
   | | master | this PR |
   |---|---|---|
   | step 2 | sim crashes with SIGSEGV: the worker writes the result into the 
exited child's stack | continues |
   | step 3 | not reached | returns 0, both requests report 0, file size 12 |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - `sim:nsh` with `CONFIG_FS_AIO`, `CONFIG_SCHED_LPWORK` and `CONFIG_PIPES`:
     make and CMake builds pass; `ostest` exits with status 0.
   


-- 
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