From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKw5Q-0002Kr-27 for qemu-devel@nongnu.org; Mon, 31 Oct 2011 13:55:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKw5P-0002oa-2L for qemu-devel@nongnu.org; Mon, 31 Oct 2011 13:55:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64909) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKw5O-0002oJ-Mq for qemu-devel@nongnu.org; Mon, 31 Oct 2011 13:55:51 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9VHtWQC006101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 31 Oct 2011 13:55:50 -0400 From: Kevin Wolf Date: Mon, 31 Oct 2011 17:44:15 +0100 Message-Id: <1320079455-15991-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2] dma: Avoid reentrancy in DMA transfer handlers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com 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 --- hw/dma.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/hw/dma.c b/hw/dma.c index 8a7302a..0a9322d 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); } -- 1.7.6.4