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

   ## Summary
   
   `addrenv_switch()` dropped the reference to the old address environment 
while it held `g_addrenv_lock`. When that was the last reference, 
`addrenv_drop()` queued the destruction on the work queue, and `work_queue()` 
enters the critical section. With SMP, another CPU could hold the critical 
section during a context switch and wait for `g_addrenv_lock` in 
`addrenv_switch()`: both CPUs spun for ever.
   
   This PR drops the reference after the lock is released; the old address 
environment is no longer installed on this CPU at that point. A first commit 
fixes the old nxstyle errors in the file.
   
   ## Impact
   
   SMP builds with `CONFIG_ARCH_ADDRENV`: removes a deadlock between two CPUs.
   
   ## Testing
   
   Builds: `qemu-armv8a:nsh`, `qemu-armv8a:knsh`, `lm3s6965-ek:qemu-flat`.
   
   Runtime, QEMU 11 with HVF on an Apple M4: `ostest` on `qemu-armv8a:knsh` 
(kernel build) and `qemu-armv8a:nsh` (flat build) ends with `ostest_main: 
Exiting with status 0`.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   
   The deadlock was found on `qemu-armv8a:knsh` with 4 CPUs and 4 shells that 
start short processes in a loop: two CPUs spun for ever, one on 
`g_addrenv_lock`, one on the critical section. With the change, 20 of 20 runs 
of that load complete.
   


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