summary refs log tree commit diff stats
path: root/hw/dma.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2011-10-28 05:28:13 -0400
committerKevin Wolf <kwolf@redhat.com>2011-11-04 14:23:58 +0100
commitacae6f1c4c1dae1b7e059751347ca4225b01a391 (patch)
tree971c2671b8fa18543ae97d9aeef1b3115271d728 /hw/dma.c
parent67403dbba76fb294fb3a2317227f4b77037145cc (diff)
downloadfocaccia-qemu-acae6f1c4c1dae1b7e059751347ca4225b01a391.tar.gz
focaccia-qemu-acae6f1c4c1dae1b7e059751347ca4225b01a391.zip
dma: Avoid reentrancy in DMA transfer handlers
With the conversion of the block layer to coroutines, bdrv_read/write
have changed to run a nested event loop that calls qemu_bh_poll.
Consequently a scheduled BH can be called while a DMA transfer handler
runs and this means that DMA_run becomes reentrant.

Devices haven't been designed to cope with that, so instead of running a
nested transfer handler just wait for the next invocation of the BH from the
main loop.

This fixes some problems with the floppy device.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/dma.c')
-rw-r--r--hw/dma.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/hw/dma.c b/hw/dma.c
index 8a7302a42f..0a9322daa3 100644
--- a/hw/dma.c
+++ b/hw/dma.c
@@ -358,6 +358,14 @@ static void DMA_run (void)
     struct dma_cont *d;
     int icont, ichan;
     int rearm = 0;
+    static int running = 0;
+
+    if (running) {
+        rearm = 1;
+        goto out;
+    } else {
+        running = 1;
+    }
 
     d = dma_controllers;
 
@@ -374,6 +382,8 @@ static void DMA_run (void)
         }
     }
 
+    running = 0;
+out:
     if (rearm)
         qemu_bh_schedule_idle(dma_bh);
 }