[dm-devel] [PATCH 1/2] dm-stats: fix a possible race condition

Mikulas Patocka mpatocka at redhat.com
Fri Feb 18 20:09:29 UTC 2022


When bio_end_io_acct ends, the count of in-progress I/Os may reach zero
and the device may be suspended. There is a possibility that the suspend
races with dm_stats_account_io. We need to call dm_stats_account_io before
bio_end_io_acct.

Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>
Cc: stable at vger.kernel.org

---
 drivers/md/dm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/md/dm.c
===================================================================
--- linux-2.6.orig/drivers/md/dm.c	2022-02-18 17:03:51.000000000 +0100
+++ linux-2.6/drivers/md/dm.c	2022-02-18 17:04:34.000000000 +0100
@@ -501,13 +501,13 @@ static void end_io_acct(struct mapped_de
 {
 	unsigned long duration = jiffies - start_time;
 
-	bio_end_io_acct(bio, start_time);
-
 	if (unlikely(dm_stats_used(&md->stats)))
 		dm_stats_account_io(&md->stats, bio_data_dir(bio),
 				    bio->bi_iter.bi_sector, bio_sectors(bio),
 				    true, duration, stats_aux);
 
+	bio_end_io_acct(bio, start_time);
+
 	/* nudge anyone waiting on suspend queue */
 	if (unlikely(wq_has_sleeper(&md->wait)))
 		wake_up(&md->wait);




More information about the dm-devel mailing list