]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix deadlock in IO pipeline
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 16 Mar 2018 23:46:06 +0000 (16:46 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Mar 2018 23:46:06 +0000 (16:46 -0700)
In vdev_queue_aggregate() the zio_execute() bypass should not be
called under the vdev queue lock.  This can result in a deadlock
as shown in the stack traces below.

Drop the vdev queue lock then walk the parents of the aggregate IO
to determine the list of component IOs to be bypassed.  This can
be done safely without holding the io_lock since the new aggregate
IO has not yet been returned and its parents cannot change.

---  THREAD 1 ---
arc_read()
  zio_nowait()
    zio_vdev_io_start()
      vdev_queue_io() <--- mutex_enter(vq->vq_lock)
        vdev_queue_io_to_issue()
          vdev_queue_aggregate()
            zio_execute()
              zio_vdev_io_assess()
                zio_wait_for_children() <- mutex_enter(zio->io_lock)

--- THREAD 2 --- (inverse order)
arc_read()
  zio_change_priority() <- mutex_enter(zio->zio_lock)
    vdev_queue_change_io_priority() <- mutex_enter(vq->vq_lock)

Reviewed-by: Tom Caputi <tcaputi@datto.com>
Reviewed-by: Don Brady <don.brady@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #7307

module/zfs/vdev_queue.c

index f121eddc7a304314243b301c50541cbfd8359cb8..5d2c980133641c96e38f4c695ec9469286a17546 100644 (file)
@@ -517,6 +517,7 @@ static zio_t *
 vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio)
 {
        zio_t *first, *last, *aio, *dio, *mandatory, *nio;
+       zio_link_t *zl = NULL;
        uint64_t maxgap = 0;
        uint64_t size;
        uint64_t limit;
@@ -665,9 +666,18 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio)
 
                zio_add_child(dio, aio);
                vdev_queue_io_remove(vq, dio);
+       } while (dio != last);
+
+       /*
+        * We need to drop the vdev queue's lock to avoid a deadlock that we
+        * could encounter since this I/O will complete immediately.
+        */
+       mutex_exit(&vq->vq_lock);
+       while ((dio = zio_walk_parents(aio, &zl)) != NULL) {
                zio_vdev_io_bypass(dio);
                zio_execute(dio);
-       } while (dio != last);
+       }
+       mutex_enter(&vq->vq_lock);
 
        return (aio);
 }