--- /dev/null
+From feb7695fe9fb83084aa29de0094774f4c9d4c9fc Mon Sep 17 00:00:00 2001
+From: Mike Snitzer <snitzer@redhat.com>
+Date: Tue, 20 Jun 2017 19:14:30 -0400
+Subject: dm io: fix duplicate bio completion due to missing ref count
+
+From: Mike Snitzer <snitzer@redhat.com>
+
+commit feb7695fe9fb83084aa29de0094774f4c9d4c9fc upstream.
+
+If only a subset of the devices associated with multiple regions support
+a given special operation (eg. DISCARD) then the dec_count() that is
+used to set error for the region must increment the io->count.
+
+Otherwise, when the dec_count() is called it can cause the dm-io
+caller's bio to be completed multiple times. As was reported against
+the dm-mirror target that had mirror legs with a mix of discard
+capabilities.
+
+Bug: https://bugzilla.kernel.org/show_bug.cgi?id=196077
+Reported-by: Zhang Yi <yizhan@redhat.com>
+Signed-off-by: Mike Snitzer <snitzer@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/md/dm-io.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/md/dm-io.c
++++ b/drivers/md/dm-io.c
+@@ -300,6 +300,7 @@ static void do_region(int rw, unsigned r
+ else if (rw & REQ_WRITE_SAME)
+ special_cmd_max_sectors = q->limits.max_write_same_sectors;
+ if ((rw & (REQ_DISCARD | REQ_WRITE_SAME)) && special_cmd_max_sectors == 0) {
++ atomic_inc(&io->count);
+ dec_count(io, region, -EOPNOTSUPP);
+ return;
+ }