Skip to contentSkip to conversation

ide: PRDT error handling fixes

PATCH Applied Kevin Wolf 2 participants 4 messages Nov 20, 2012 – Nov 21, 2012

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

cover ide: PRDT error handling fixes

qtest cases for this exist, but they rely on prototype infrastructure that isn't mergable. I'll submit them as soon as libqos is there and I've changed the test to use it.

Kevin Wolf (2):
ide: Fix crash with too long PRD
ide: Fix status register after short PRDs

 hw/ide/core.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.6.5
author
#1 lore raw

PATCH 1/2 ide: Fix crash with too long PRD

Without this, s->nsector can become negative and badness happens (trying to malloc huge amount of memory and glib calls abort())

---
 hw/ide/core.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/ide/core.c +12 -0
index 7d6b0fa..c2ab787 100644
@@ -579,6 +579,7 @@ void ide_dma_cb(void *opaque, int ret)
     IDEState *s = opaque;
     int n;
     int64_t sector_num;
+    bool stay_active = false;
 
     if (ret < 0) {
         int op = BM_STATUS_DMA_RETRY;
@@ -594,6 +595,14 @@ void ide_dma_cb(void *opaque, int ret)
     }
 
     n = s->io_buffer_size >> 9;
+    if (n > s->nsector) {
+        /* The PRDs were longer than needed for this request. Shorten them so
+         * we don't get a negative remainder. The Active bit must remain set
+         * after the request completes. */
+        n = s->nsector;
+        stay_active = true;
+    }
+
     sector_num = ide_get_sector(s);
     if (n > 0) {
         dma_buf_commit(s);
@@ -646,6 +655,9 @@ eot:
         bdrv_acct_done(s->bs, &s->acct);
     }
     ide_set_inactive(s);
+    if (stay_active) {
+        s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_DMAING);
+    }
 }
 
 static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
Signature · 1 line
1.7.6.5
author
#2 lore raw

PATCH 2/2 ide: Fix status register after short PRDs

In reply to Kevin Wolf

When failing a request because the length of the regions described by the PRDT was too short for the requested number of sectors, the IDE emulation forgot to update the status register, so that the device would keep the BSY flag set indefinitely.

---
 hw/ide/core.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/ide/core.c +1 -0
index c2ab787..8da894f 100644
@@ -625,6 +625,7 @@ void ide_dma_cb(void *opaque, int ret)
     if (s->bus->dma->ops->prepare_buf(s->bus->dma, ide_cmd_is_read(s)) == 0) {
         /* The PRDs were too short. Reset the Active bit, but don't raise an
          * interrupt. */
+        s->status = READY_STAT | SEEK_STAT;
         goto eot;
     }
 
Signature · 1 line
1.7.6.5
#3 lore raw
In reply to Kevin Wolf
Quoted 4 lines · Kevin Wolf

qtest cases for this exist, but they rely on prototype infrastructure that isn't mergable. I'll submit them as soon as libqos is there and I've changed the test to use it.

Quoted 11 lines

Kevin Wolf (2):
ide: Fix crash with too long PRD
ide: Fix status register after short PRDs

 hw/ide/core.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.6.5

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan