This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 2ee07c6fcef0cee0e0b641672018b81de37cc6e1
Author: wangjianyu3 <[email protected]>
AuthorDate: Sat Aug 29 23:02:55 2026 +0800

    drivers/virtio: poll to unstick the serial TX ring from interrupt context
    
    virtio_serial_txready() decided the xmit ring was full from dev->xmit's
    software pointers alone, relying on the interrupt-driven
    virtio_serial_txdone() to drain the TX virtqueue and advance them. When
    uart_write() is reached from interrupt/wdog context, uart_putchars()
    busy-waits with this CPU's interrupts disabled, so that completion
    interrupt can never fire and the CPU deadlocks once dev->xmit fills up.
    
    Poll inline in virtio_serial_txready()'s busy-wait when the ring looks
    full: kick off a queued submission if the DMA engine is idle, otherwise
    call virtio_serial_txdone() to reap the in-flight completion through the
    same path the interrupt would take.  uart_spinlock() is recursive on
    this CPU, so txdone() re-taking it does not self-deadlock.
    
    Guard virtio_serial_txdone() with if (len != 0) so this new poll path
    (and a stale interrupt after the poll already reaped) skips the
    notification instead of writing nbytes=0 and spuriously running
    uart_xmitchars_done().
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 drivers/virtio/virtio-serial.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/virtio-serial.c b/drivers/virtio/virtio-serial.c
index c1f61a19be9..c28abc301c5 100644
--- a/drivers/virtio/virtio-serial.c
+++ b/drivers/virtio/virtio-serial.c
@@ -304,6 +304,25 @@ static bool virtio_serial_txready(FAR struct uart_dev_s 
*dev)
       nexthead = 0;
     }
 
+  if (nexthead == dev->xmit.tail)
+    {
+      FAR struct virtio_serial_priv_s *priv = dev->priv;
+      FAR struct virtqueue *vq =
+        priv->vdev->vrings_info[VIRTIO_SERIAL_TX].vq;
+      irqstate_t flags = uart_spinlock(dev, true);
+
+      if (dev->dmatx.length == 0)
+        {
+          uart_dmatxavail(dev);
+        }
+      else
+        {
+          virtio_serial_txdone(vq);
+        }
+
+      uart_spinunlock(dev, true, flags);
+    }
+
   return nexthead != dev->xmit.tail;
 }
 
@@ -472,10 +491,13 @@ static void virtio_serial_txdone(FAR struct virtqueue *vq)
   /* Call uart_xmitchars_done to notify the upperhalf */
 
   len = (uintptr_t)virtqueue_get_buffer(vq, NULL, NULL);
+  if (len != 0)
+    {
+      udev->dmatx.nbytes = len;
+      uart_xmitchars_done(udev);
+      uart_dmatxavail(udev);
+    }
 
-  udev->dmatx.nbytes = len;
-  uart_xmitchars_done(udev);
-  uart_dmatxavail(udev);
   uart_spinunlock(udev, true, flags);
 }
 

Reply via email to