Skip to contentSkip to conversation

hw/ide: Cancel pending DMA requests before setting as inactive

RFC Superseded Philippe Mathieu-Daudé 1 participant 2 messages Jul 17, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 hw/ide: Cancel pending DMA requests before setting as inactive

libFuzzer found a case where requests are queued for later in the AIO context, but a command set the bus inactive, then when finally the requests are processed by the DMA it aborts because it is inactive:

include/hw/ide/pci.h:59: IDEState *bmdma_active_if(BMDMAState *): Assertion `bmdma->bus->retry_unit != (uint8_t)-1' failed.

Reproducer available on the BugLink.

Fix by draining the pending DMA requests before inactivating the bus.

---
RFC because I don't have much clue about block drive and IDE, so block-team please be very careful while reviewing this bug.

---
 hw/ide/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ide/core.c +2 -2
index d997a78e47..b21d28f99c 100644
@@ -804,11 +804,11 @@ void dma_buf_commit(IDEState *s, uint32_t tx_bytes)
 
 void ide_set_inactive(IDEState *s, bool more)
 {
-    s->bus->dma->aiocb = NULL;
-    ide_clear_retry(s);
     if (s->bus->dma->ops->set_inactive) {
         s->bus->dma->ops->set_inactive(s->bus->dma, more);
     }
+    ide_cancel_dma_sync(s);
+    ide_clear_retry(s);
     ide_cmd_done(s);
 }
 
Signature · 1 line
2.21.3
#1 lore raw
Quoted 25 lines · Philippe Mathieu-Daudé

libFuzzer found a case where requests are queued for later in the AIO context, but a command set the bus inactive, then when finally the requests are processed by the DMA it aborts because it is inactive:

include/hw/ide/pci.h:59: IDEState *bmdma_active_if(BMDMAState *): Assertion `bmdma->bus->retry_unit != (uint8_t)-1' failed.

Reproducer available on the BugLink.

Fix by draining the pending DMA requests before inactivating the bus.

---
RFC because I don't have much clue about block drive and IDE, so block-team please be very careful while reviewing this bug.

---
 hw/ide/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ide/core.c +0 -0
index d997a78e47..b21d28f99c 100644

hw/ide/core.c void dma_buf_commit(IDEState *s, uint32_t tx_bytes) · line 811

Quoted 10 lines
hw/ide/core.c +2 -2
@@ -804,11 +804,11 @@ void dma_buf_commit(IDEState *s, uint32_t tx_bytes)
 
 void ide_set_inactive(IDEState *s, bool more)
 {
-    s->bus->dma->aiocb = NULL;
-    ide_clear_retry(s);
     if (s->bus->dma->ops->set_inactive) {
         s->bus->dma->ops->set_inactive(s->bus->dma, more);
     }
+    ide_cancel_dma_sync(s);
+    ide_clear_retry(s);

Oops this is not the one I wanted to send. I'll send v2 shortly =)

Quoted 4 lines
hw/ide/core.c +0 -0
     ide_cmd_done(s);
 }