[dm-devel] [PATCH 2/2] dm: add memory barriers to end_io_acct and dm_wait_for_completion

Mikulas Patocka mpatocka at redhat.com
Fri Feb 18 20:10:24 UTC 2022


When one thread waits for another, we must use memory barriers, otherwise
the CPU may reorder memory accesses.

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

---
 drivers/md/dm.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Index: linux-2.6/drivers/md/dm.c
===================================================================
--- linux-2.6.orig/drivers/md/dm.c	2022-02-18 17:04:34.000000000 +0100
+++ linux-2.6/drivers/md/dm.c	2022-02-18 17:15:11.000000000 +0100
@@ -506,6 +506,8 @@ static void end_io_acct(struct mapped_de
 				    bio->bi_iter.bi_sector, bio_sectors(bio),
 				    true, duration, stats_aux);
 
+	smp_wmb();
+
 	bio_end_io_acct(bio, start_time);
 
 	/* nudge anyone waiting on suspend queue */
@@ -2170,9 +2172,8 @@ static int dm_wait_for_completion(struct
 	int r = 0;
 
 	if (!queue_is_mq(md->queue))
-		return dm_wait_for_bios_completion(md, task_state);
-
-	while (true) {
+		r = dm_wait_for_bios_completion(md, task_state);
+	else while (true) {
 		if (!blk_mq_queue_inflight(md->queue))
 			break;
 
@@ -2184,6 +2185,8 @@ static int dm_wait_for_completion(struct
 		msleep(5);
 	}
 
+	smp_rmb();
+
 	return r;
 }
 




More information about the dm-devel mailing list