Skip to contentSkip to conversation

ide: fix halted IO segfault at reset

PATCH Superseded John Snow 3 participants 9 messages Jul 26, 2016 – Aug 2, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

cover ide: fix halted IO segfault at reset

________________________________________________________________________________

For convenience, this branch is available at:
https://github.com/jnsnow/qemu.git branch ide-reset-segfault
https://github.com/jnsnow/qemu/tree/ide-reset-segfault

This version is tagged ide-reset-segfault-v1:
https://github.com/jnsnow/qemu/releases/tag/ide-reset-segfault-v1

John Snow (1):
ide: fix halted IO segfault at reset

 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/1 ide: fix halted IO segfault at reset

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +1 -0
index 081c9eb..d117b7c 100644
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#2 lore raw
Quoted 21 lines · John Snow

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +0 -0
index 081c9eb..d117b7c 100644

hw/ide/core.c static void ide_dma_cb(void *opaque, int ret) · line 829

Quoted 7 lines
hw/ide/core.c +1 -0
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }

Should this be a candidate for 2.6 stable?

Thanks
Laszlo

author
#3 lore raw
Quoted 8 lines · Laszlo Ersek
Quoted 7 lines · John Snow

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

s|free them|null them| ... will fix on commit.

Quoted 24 lines
Quoted 14 lines

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +0 -0
index 081c9eb..d117b7c 100644

hw/ide/core.c static void ide_dma_cb(void *opaque, int ret) · line 829

Quoted 7 lines
hw/ide/core.c +1 -0
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }
Quoted 5 lines

Should this be a candidate for 2.6 stable?

Thanks
Laszlo

You're right. I'll do a [RESEND] to -stable, thanks.

And since I neglected to mention it in the commit message, thanks to Laszlo Ersek here for an excellent diagnostic on the cause of the segfault.

--js

#4 lore raw
In reply to John Snow
Quoted 21 lines · John Snow

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +0 -0
index 081c9eb..d117b7c 100644

hw/ide/core.c static void ide_dma_cb(void *opaque, int ret) · line 829

Quoted 7 lines
hw/ide/core.c +1 -0
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }

The patch is (was, since it's committed :)) okay, but I think there is another bug in the REPORT case, where ide_rw_error and ide_atapi_io_error are not calling ide_set_inactive and thus are leaving s->bus->dma->aiocb non-NULL.

Paolo

author
#5 lore raw
Quoted 37 lines · Paolo Bonzini
Quoted 21 lines · John Snow

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +0 -0
index 081c9eb..d117b7c 100644

hw/ide/core.c static void ide_dma_cb(void *opaque, int ret) · line 829

Quoted 7 lines
hw/ide/core.c +1 -0
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }

The patch is (was, since it's committed :)) okay, but I think there is another bug in the REPORT case, where ide_rw_error and ide_atapi_io_error are not calling ide_set_inactive and thus are leaving s->bus->dma->aiocb non-NULL.

Quoted 2 lines

Paolo

...Aha. Good eye.

I can probably just shift the aiocb nulling up a bit, but leave it in ide_dma_cb.

#6 lore raw
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
hw/ide/core.c +1 -0
index 081c9eb..d117b7c 100644
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret,
         ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
Quoted 8 lines
Quoted 3 lines
hw/ide/core.c +0 -0
         }
     }

The patch is (was, since it's committed :)) okay, but I think there is another bug in the REPORT case, where ide_rw_error and ide_atapi_io_error are not calling ide_set_inactive and thus are leaving s->bus->dma->aiocb non-NULL.

Quoted 2 lines

I can probably just shift the aiocb nulling up a bit, but leave it in ide_dma_cb.

ATAPI is ide_atapi_cmd_read_dma_cb, you can do the same fix there that you did in this patch.

Paolo

author
#7 lore raw
In reply to Paolo Bonzini
Quoted 37 lines · Paolo Bonzini
Quoted 21 lines · John Snow

If one attempts to perform a system_reset after a failed IO request that causes the VM to enter a paused state, QEMU will segfault trying to free up the pending IO requests.

These requests have already been completed and freed, though, so all we need to do is free them before we enter the paused state.

Existing AHCI tests verify that halted requests are still resumed successfully after a STOP event.

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +0 -0
index 081c9eb..d117b7c 100644

hw/ide/core.c static void ide_dma_cb(void *opaque, int ret) · line 829

Quoted 7 lines
hw/ide/core.c +1 -0
@@ -823,6 +823,7 @@ static void ide_dma_cb(void *opaque, int ret)
     }
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
+            s->bus->dma->aiocb = NULL;
             return;
         }
     }

The patch is (was, since it's committed :)) okay, but I think there is another bug in the REPORT case, where ide_rw_error and ide_atapi_io_error are not calling ide_set_inactive and thus are leaving s->bus->dma->aiocb non-NULL.

Quoted 2 lines

Paolo

Actually, won't we hit ide_dma_error on REPORT which calls ide_set_inactive? I think this might be OK, but I have to audit a little more carefully -- I will do so tomorrow.

I think the ide_rw_error case is likely OK, but I always manage to forget exactly how the ATAPI DMA looks.

#8 lore raw
Quoted 9 lines
Quoted 8 lines

The patch is (was, since it's committed :)) okay, but I think there is another bug in the REPORT case, where ide_rw_error and ide_atapi_io_error are not calling ide_set_inactive and thus are leaving s->bus->dma->aiocb non-NULL.

Paolo

Quoted 6 lines

Actually, won't we hit ide_dma_error on REPORT which calls ide_set_inactive? I think this might be OK, but I have to audit a little more carefully -- I will do so tomorrow.

I think the ide_rw_error case is likely OK, but I always manage to forget exactly how the ATAPI DMA looks.

Indeed ide_rw_error is okay because ide_sector_read and ide_sector_write do reset pio_aiocb early enough; ATAPI is wrong because IDE_RETRY_ATAPI does not pass IS_IDE_RETRY_DMA.

Paolo