diff mbox series

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

Message ID alpine.LRH.2.02.2202181509310.322@file01.intranet.prod.int.rdu2.redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show
Series [1/2] dm-stats: fix a possible race condition | expand

Commit Message

Mikulas Patocka Feb. 18, 2022, 8:10 p.m. UTC
When one thread waits for another, we must use memory barriers, otherwise
the CPU may reorder memory accesses.

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

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


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

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;
 }