yangsong8-a1 commented on PR #21746:
URL: https://github.com/apache/nuttx/pull/21746#issuecomment-6912577718

   > [@xiaoxiang781216](https://github.com/xiaoxiang781216) 
[@yangsong8-a1](https://github.com/yangsong8-a1) 
[@Donny9](https://github.com/Donny9)
   > 
   > This change hangs CONFIG_CONSOLE_NETDEV (drivers/serial/netdev_console.c) 
on SMP.
   > 
   > uart_writev() (and the echo in uart_readv()) calls the DMA hook while 
holding uart_spinlock():
   > 
   > uart_writev() → uart_spinlock(dev, true) → uart_dmatxavail() → 
uart_xmitchars_dma() → netdev_console_dmasend() → psock_send()
   > 
   > psock_send() sleeps until the packet is sent, and the task can wake up on 
another CPU. netdev_console_dmasend() then calls uart_xmitchars_done() → 
uart_datasent() → uart_poll_notify() → uart_spinlock(). rspinlock_t is owned by 
the CPU, not the task. The lock is still owned by the CPU the task slept on, so 
the nested lock is not treated as recursive and the task spins forever, with 
interrupts off, on a lock it holds itself.
   > 
   > Instrumented uart_spinlock() (holder tid and caller) on qemu-intel64 shows 
exactly this:
   > 
   > SPIN cpu0 tid7 uart_poll_notify, lock owner cpu1 count 1, holder tid7 
uart_writev
   > 
   > The old enter_critical_section() was released when the task blocked and 
taken again when it resumed, so this worked before. Without CONFIG_SMP the task 
cannot change CPU, so the nested lock is always recursive and there is no hang.
   > 
   > Reproduce: qemu-intel64, CONFIG_SMP=y, CONFIG_CONSOLE_NETDEV over UDP 
(e1000). Type commands on the console; after a few dozen echoed characters the 
console hangs. Reverting 
[6b1092a](https://github.com/apache/nuttx/commit/6b1092ae3125645de72bf168eccb2ac12a75fd73)
 and 
[4289e5e](https://github.com/apache/nuttx/commit/4289e5ee5270051617baa40f9113d0cee235e65b)
 on current master fixes it.
   
   @raiden00pl  Thanks for the feedback; I’ll submit a fix.


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