Skip to contentSkip to conversation

ide: fix invalid TRIM range abortion for macio

PATCH Applied Anton Nefedov 3 participants 5 messages Mar 2, 2018 – Mar 21, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ide: fix invalid TRIM range abortion for macio

commit 947858b0 "ide: abort TRIM operation for invalid range" is incorrect for macio; just ide_dma_error() without doing a callback is not enough for that errorpath.

Instead, pass -EINVAL to the callback and handle it there (see related motivation for read/write in 58ac32113).

It will however catch possible EINVAL from the block layer too.

---
 hw/ide/core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
hw/ide/core.c +9 -8
index 257b429..54510d4 100644
@@ -402,7 +402,6 @@ typedef struct TrimAIOCB {
     QEMUIOVector *qiov;
     BlockAIOCB *aiocb;
     int i, j;
-    bool is_invalid;
 } TrimAIOCB;
 
 static void trim_aio_cancel(BlockAIOCB *acb)
@@ -430,11 +429,8 @@ static void ide_trim_bh_cb(void *opaque)
 {
     TrimAIOCB *iocb = opaque;
 
-    if (iocb->is_invalid) {
-        ide_dma_error(iocb->s);
-    } else {
-        iocb->common.cb(iocb->common.opaque, iocb->ret);
-    }
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
     qemu_bh_delete(iocb->bh);
     iocb->bh = NULL;
     qemu_aio_unref(iocb);
@@ -462,7 +458,7 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                 }
 
                 if (!ide_sect_range_ok(s, sector, count)) {
-                    iocb->is_invalid = true;
+                    iocb->ret = -EINVAL;
                     goto done;
                 }
 
@@ -502,7 +498,6 @@ BlockAIOCB *ide_issue_trim(
     iocb->qiov = qiov;
     iocb->i = -1;
     iocb->j = 0;
-    iocb->is_invalid = false;
     ide_issue_trim_cb(iocb, 0);
     return &iocb->common;
 }
@@ -848,6 +843,12 @@ static void ide_dma_cb(void *opaque, int ret)
     if (ret == -ECANCELED) {
         return;
     }
+
+    if (ret == -EINVAL) {
+        ide_dma_error(s);
+        return;
+    }
+
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
             s->bus->dma->aiocb = NULL;
Signature · 1 line
2.7.4
Tested-by on v1 1/1
#1 lore raw
Quoted 61 lines · Anton Nefedov

commit 947858b0 "ide: abort TRIM operation for invalid range" is incorrect for macio; just ide_dma_error() without doing a callback is not enough for that errorpath.

Instead, pass -EINVAL to the callback and handle it there (see related motivation for read/write in 58ac32113).

It will however catch possible EINVAL from the block layer too.

---
  hw/ide/core.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)
hw/ide/core.c +3 -8
index 257b429..54510d4 100644
@@ -402,7 +402,6 @@ typedef struct TrimAIOCB {
      QEMUIOVector *qiov;
      BlockAIOCB *aiocb;
      int i, j;
-    bool is_invalid;
  } TrimAIOCB;
 
  static void trim_aio_cancel(BlockAIOCB *acb)
@@ -430,11 +429,8 @@ static void ide_trim_bh_cb(void *opaque)
  {
      TrimAIOCB *iocb = opaque;
 
-    if (iocb->is_invalid) {
-        ide_dma_error(iocb->s);
-    } else {
-        iocb->common.cb(iocb->common.opaque, iocb->ret);
-    }
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
      qemu_bh_delete(iocb->bh);
      iocb->bh = NULL;
      qemu_aio_unref(iocb);
@@ -462,7 +458,7 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                  }
 
                  if (!ide_sect_range_ok(s, sector, count)) {
-                    iocb->is_invalid = true;
+                    iocb->ret = -EINVAL;
                      goto done;
                  }
 
@@ -502,7 +498,6 @@ BlockAIOCB *ide_issue_trim(
      iocb->qiov = qiov;
      iocb->i = -1;
      iocb->j = 0;
-    iocb->is_invalid = false;
      ide_issue_trim_cb(iocb, 0);
      return &iocb->common;
  }
@@ -848,6 +843,12 @@ static void ide_dma_cb(void *opaque, int ret)
      if (ret == -ECANCELED) {
          return;

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

Quoted 10 lines
hw/ide/core.c +6 -0
      }
+
+    if (ret == -EINVAL) {
+        ide_dma_error(s);
+        return;
+    }
+
      if (ret < 0) {
          if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
              s->bus->dma->aiocb = NULL;

Hi Anton,

Thanks for this. I applied this patch to git master with my macio patch at https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg06076.html and it allowed to continue all the way through the Debian installer for the PPC g3beige machine so I believe it is working.

ATB,

Mark.

#2 lore raw
Quoted 72 lines · Mark Cave-Ayland
Quoted 57 lines · Anton Nefedov

commit 947858b0 "ide: abort TRIM operation for invalid range" is incorrect for macio; just ide_dma_error() without doing a callback is not enough for that errorpath.

Instead, pass -EINVAL to the callback and handle it there (see related motivation for read/write in 58ac32113).

It will however catch possible EINVAL from the block layer too.

---
  hw/ide/core.c | 17 +++++++++--------

  1 file changed, 9 insertions(+), 8 deletions(-)
hw/ide/core.c +3 -8
index 257b429..54510d4 100644
@@ -402,7 +402,6 @@ typedef struct TrimAIOCB {
       QEMUIOVector *qiov;
       BlockAIOCB *aiocb;
       int i, j;
-    bool is_invalid;
   } TrimAIOCB;
   static void trim_aio_cancel(BlockAIOCB *acb)
@@ -430,11 +429,8 @@ static void ide_trim_bh_cb(void *opaque)
   {
       TrimAIOCB *iocb = opaque;
-    if (iocb->is_invalid) {
-        ide_dma_error(iocb->s);
-    } else {
-        iocb->common.cb(iocb->common.opaque, iocb->ret);
-    }
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
       qemu_bh_delete(iocb->bh);
       iocb->bh = NULL;
       qemu_aio_unref(iocb);
@@ -462,7 +458,7 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                   }
                   if (!ide_sect_range_ok(s, sector, count)) {
-                    iocb->is_invalid = true;
+                    iocb->ret = -EINVAL;
                       goto done;
                   }
@@ -502,7 +498,6 @@ BlockAIOCB *ide_issue_trim(
       iocb->qiov = qiov;
       iocb->i = -1;
       iocb->j = 0;
-    iocb->is_invalid = false;
       ide_issue_trim_cb(iocb, 0);
       return &iocb->common;
   }
@@ -848,6 +843,12 @@ static void ide_dma_cb(void *opaque, int ret)
       if (ret == -ECANCELED) {
           return;

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

Quoted 10 lines
hw/ide/core.c +6 -0
       }
+
+    if (ret == -EINVAL) {
+        ide_dma_error(s);
+        return;
+    }
+
       if (ret < 0) {
           if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
               s->bus->dma->aiocb = NULL;

Hi Anton,

Quoted 3 lines

Thanks for this. I applied this patch to git master with my macio patch at https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg06076.html and it allowed to continue all the way through the Debian installer for the PPC g3beige machine so I believe it is working.

Hi John,

I know that you're busy, but just wondering if you have managed to review these 2 TRIM patches? They are a candidate for 2.12 since they prevent a qemu-system-ppc segfault on Mac machines when issuing IDE TRIM commands.

ATB,

Mark.

#3 lore raw
Quoted 91 lines · Mark Cave-Ayland
Quoted 73 lines · Mark Cave-Ayland
Quoted 66 lines · Anton Nefedov

commit 947858b0 "ide: abort TRIM operation for invalid range" is incorrect for macio; just ide_dma_error() without doing a callback is not enough for that errorpath.

Instead, pass -EINVAL to the callback and handle it there (see related motivation for read/write in 58ac32113).

It will however catch possible EINVAL from the block layer too.

---
  hw/ide/core.c | 17 +++++++++--------

  1 file changed, 9 insertions(+), 8 deletions(-)
hw/ide/core.c +9 -8
index 257b429..54510d4 100644
@@ -402,7 +402,6 @@ typedef struct TrimAIOCB {
       QEMUIOVector *qiov;
       BlockAIOCB *aiocb;
       int i, j;
-    bool is_invalid;
   } TrimAIOCB;
   static void trim_aio_cancel(BlockAIOCB *acb)
@@ -430,11 +429,8 @@ static void ide_trim_bh_cb(void *opaque)
   {
       TrimAIOCB *iocb = opaque;
-    if (iocb->is_invalid) {
-        ide_dma_error(iocb->s);
-    } else {
-        iocb->common.cb(iocb->common.opaque, iocb->ret);
-    }
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
       qemu_bh_delete(iocb->bh);
       iocb->bh = NULL;
       qemu_aio_unref(iocb);
@@ -462,7 +458,7 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                   }
                   if (!ide_sect_range_ok(s, sector, count)) {
-                    iocb->is_invalid = true;
+                    iocb->ret = -EINVAL;
                       goto done;
                   }
@@ -502,7 +498,6 @@ BlockAIOCB *ide_issue_trim(
       iocb->qiov = qiov;
       iocb->i = -1;
       iocb->j = 0;
-    iocb->is_invalid = false;
       ide_issue_trim_cb(iocb, 0);
       return &iocb->common;
   }
@@ -848,6 +843,12 @@ static void ide_dma_cb(void *opaque, int ret)
       if (ret == -ECANCELED) {
           return;
       }
+
+    if (ret == -EINVAL) {
+        ide_dma_error(s);
+        return;
+    }
+
       if (ret < 0) {
           if (ide_handle_rw_error(s, -ret,
 ide_dma_cmd_to_retry(s->dma_cmd))) {
Quoted 2 lines

              s->bus->dma->aiocb = NULL;

Hi Anton,

Quoted 7 lines

Thanks for this. I applied this patch to git master with my macio patch at
https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg06076.html
and it allowed to continue all the way through the Debian installer for the PPC g3beige machine so I believe it is working.

Hi John,

I know that you're busy, but just wondering if you have managed to review these 2 TRIM patches? They are a candidate for 2.12 since they prevent a qemu-system-ppc segfault on Mac machines when issuing IDE TRIM commands.

Quoted 3 lines

ATB,

Mark.

Will send a PR once it looks as if Peter Maydell has caught up with all of the last-minute PR panic for soft freeze -- they're not forgotten, I promise!

Thank you for checking in on me.

--John

Applied
#4 lore raw
In reply to Anton Nefedov
Quoted 61 lines · Anton Nefedov

commit 947858b0 "ide: abort TRIM operation for invalid range" is incorrect for macio; just ide_dma_error() without doing a callback is not enough for that errorpath.

Instead, pass -EINVAL to the callback and handle it there (see related motivation for read/write in 58ac32113).

It will however catch possible EINVAL from the block layer too.

---
 hw/ide/core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
hw/ide/core.c +3 -8
index 257b429..54510d4 100644
@@ -402,7 +402,6 @@ typedef struct TrimAIOCB {
     QEMUIOVector *qiov;
     BlockAIOCB *aiocb;
     int i, j;
-    bool is_invalid;
 } TrimAIOCB;
 
 static void trim_aio_cancel(BlockAIOCB *acb)
@@ -430,11 +429,8 @@ static void ide_trim_bh_cb(void *opaque)
 {
     TrimAIOCB *iocb = opaque;
 
-    if (iocb->is_invalid) {
-        ide_dma_error(iocb->s);
-    } else {
-        iocb->common.cb(iocb->common.opaque, iocb->ret);
-    }
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
     qemu_bh_delete(iocb->bh);
     iocb->bh = NULL;
     qemu_aio_unref(iocb);
@@ -462,7 +458,7 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                 }
 
                 if (!ide_sect_range_ok(s, sector, count)) {
-                    iocb->is_invalid = true;
+                    iocb->ret = -EINVAL;
                     goto done;
                 }
 
@@ -502,7 +498,6 @@ BlockAIOCB *ide_issue_trim(
     iocb->qiov = qiov;
     iocb->i = -1;
     iocb->j = 0;
-    iocb->is_invalid = false;
     ide_issue_trim_cb(iocb, 0);
     return &iocb->common;
 }
@@ -848,6 +843,12 @@ static void ide_dma_cb(void *opaque, int ret)
     if (ret == -ECANCELED) {
         return;

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

Quoted 10 lines
hw/ide/core.c +6 -0
     }
+
+    if (ret == -EINVAL) {
+        ide_dma_error(s);
+        return;
+    }
+
     if (ret < 0) {
         if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {
             s->bus->dma->aiocb = NULL;

Thanks, applied to my IDE tree:

https://github.com/jnsnow/qemu/commits/ide
https://github.com/jnsnow/qemu.git

--js