Skip to contentSkip to conversation

hw/nvme: fix control flow statement

PATCH In review Dmitry Tikhov 3 participants 5 messages Apr 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/nvme: fix control flow statement

Since there is no else after nvme_dsm_cb invocation, metadata associated with non-zero block range is currently zeroed. Also this behaviour leads to segfault since we schedule iocb->bh two times. First when entering nvme_dsm_cb with iocb->idx == iocb->nr and second on call stack unwinding by calling blk_aio_pwrite_zeroes and subsequent nvme_dsm_cb callback because of missing else statement.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +4 -3
index 03760ddeae..7ebd2aa326 100644
@@ -2372,11 +2372,12 @@ static void nvme_dsm_md_cb(void *opaque, int ret)
         }
 
         nvme_dsm_cb(iocb, 0);
+    } else {
+        iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
+                                            nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
+                                            nvme_dsm_cb, iocb);
     }
 
-    iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
-                                        nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
-                                        nvme_dsm_cb, iocb);
     return;
 
 done:
Signature · 1 line
2.35.1
#1 lore raw
Quoted 17 lines · Dmitry Tikhov

Since there is no else after nvme_dsm_cb invocation, metadata associated with non-zero block range is currently zeroed. Also this behaviour leads to segfault since we schedule iocb->bh two times. First when entering nvme_dsm_cb with iocb->idx == iocb->nr and second on call stack unwinding by calling blk_aio_pwrite_zeroes and subsequent nvme_dsm_cb callback because of missing else statement.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +0 -0
index 03760ddeae..7ebd2aa326 100644

hw/nvme/ctrl.c static void nvme_dsm_md_cb(void *opaque, int ret) · line 2379

Quoted 8 lines
hw/nvme/ctrl.c +4 -0
@@ -2372,11 +2372,12 @@ static void nvme_dsm_md_cb(void *opaque, int ret)
         }
 
         nvme_dsm_cb(iocb, 0);
+    } else {
+        iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
+                                            nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
+                                            nvme_dsm_cb, iocb);
     }

Instead of the 'else', just insert an early 'return;' after nvme_dsm_cb() like the earlier condition above here. Otherwise, looks good, and thanks for the fix.

#2 lore raw
Quoted 20 lines · Keith Busch
Quoted 19 lines · Dmitry Tikhov

Since there is no else after nvme_dsm_cb invocation, metadata associated with non-zero block range is currently zeroed. Also this behaviour leads to segfault since we schedule iocb->bh two times. First when entering nvme_dsm_cb with iocb->idx == iocb->nr and second on call stack unwinding by calling blk_aio_pwrite_zeroes and subsequent nvme_dsm_cb callback because of missing else statement.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +0 -0
index 03760ddeae..7ebd2aa326 100644
@@ -2372,11 +2372,12 @@ static void nvme_dsm_md_cb(void *opaque, int ret)
         }
 
Quoted 10 lines

hw/nvme/ctrl.c static void nvme_dsm_md_cb(void *opaque, int ret) · line 2379

Quoted 6 lines
hw/nvme/ctrl.c +4 -0
         nvme_dsm_cb(iocb, 0);
+    } else {
+        iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
+                                            nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
+                                            nvme_dsm_cb, iocb);
     }

Instead of the 'else', just insert an early 'return;' after nvme_dsm_cb() like the earlier condition above here. Otherwise, looks good, and thanks for the fix.

Dmitry,

Agree with Keith - also, please add

Fixes d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation")

Thanks again!

#3 lore raw
Quoted 32 lines · Klaus Jensen
Quoted 20 lines · Keith Busch
Quoted 19 lines · Dmitry Tikhov

Since there is no else after nvme_dsm_cb invocation, metadata associated with non-zero block range is currently zeroed. Also this behaviour leads to segfault since we schedule iocb->bh two times. First when entering nvme_dsm_cb with iocb->idx == iocb->nr and second on call stack unwinding by calling blk_aio_pwrite_zeroes and subsequent nvme_dsm_cb callback because of missing else statement.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +0 -0
index 03760ddeae..7ebd2aa326 100644
@@ -2372,11 +2372,12 @@ static void nvme_dsm_md_cb(void *opaque, int ret)
         }
 
Quoted 10 lines

hw/nvme/ctrl.c static void nvme_dsm_md_cb(void *opaque, int ret) · line 2379

Quoted 6 lines
hw/nvme/ctrl.c +4 -0
         nvme_dsm_cb(iocb, 0);
+    } else {
+        iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
+                                            nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
+                                            nvme_dsm_cb, iocb);
     }

Instead of the 'else', just insert an early 'return;' after nvme_dsm_cb() like the earlier condition above here. Otherwise, looks good, and thanks for the fix.

Quoted 7 lines

Dmitry,

Agree with Keith - also, please add

Fixes d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation")

Thanks again!

Ok, will do. Can i change patch subject text or it should stay the same between submissions?

#4 lore raw
Quoted 35 lines · Dmitry Tikhov
Quoted 34 lines · Klaus Jensen
Quoted 20 lines · Keith Busch
Quoted 19 lines · Dmitry Tikhov

Since there is no else after nvme_dsm_cb invocation, metadata associated with non-zero block range is currently zeroed. Also this behaviour leads to segfault since we schedule iocb->bh two times. First when entering nvme_dsm_cb with iocb->idx == iocb->nr and second on call stack unwinding by calling blk_aio_pwrite_zeroes and subsequent nvme_dsm_cb callback because of missing else statement.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +0 -0
index 03760ddeae..7ebd2aa326 100644
@@ -2372,11 +2372,12 @@ static void nvme_dsm_md_cb(void *opaque, int ret)
         }
 
Quoted 10 lines

hw/nvme/ctrl.c static void nvme_dsm_md_cb(void *opaque, int ret) · line 2379

Quoted 6 lines
hw/nvme/ctrl.c +4 -0
         nvme_dsm_cb(iocb, 0);
+    } else {
+        iocb->aiocb = blk_aio_pwrite_zeroes(ns->blkconf.blk, nvme_moff(ns, slba),
+                                            nvme_m2b(ns, nlb), BDRV_REQ_MAY_UNMAP,
+                                            nvme_dsm_cb, iocb);
     }

Instead of the 'else', just insert an early 'return;' after nvme_dsm_cb() like the earlier condition above here. Otherwise, looks good, and thanks for the fix.

Dmitry,

Quoted 8 lines
Quoted 5 lines

Agree with Keith - also, please add

Fixes d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation")

Thanks again!

Ok, will do. Can i change patch subject text or it should stay the same between submissions?

Changing it is ok :)