Skip to contentSkip to conversation

dm-switch: use WRITE_ONCE() in switch_region_table_write()

PATCH New Haotian Zhang 1 participant 1 message Jul 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-switch: use WRITE_ONCE() in switch_region_table_write()

switch_region_table_read() accesses the region table with READ_ONCE() and is called from the lockless switch_map() IO path. However, switch_region_table_write() stores to the same array with a plain assignment. This results in an inconsistent access pattern for a lockless shared variable and may trigger data race reports.

Use WRITE_ONCE() to pair with the existing READ_ONCE() in switch_region_table_read().

Fixes 99eb1908e643 ("dm switch: factor out switch_region_table_read")
---
 drivers/md/dm-switch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-switch.c +1 -1
index 5952f02de1e6..e5b507b4fa7b 100644
@@ -184,7 +184,7 @@ static void switch_region_table_write(struct switch_ctx *sctx, unsigned long reg
 	pte = sctx->region_table[region_index];
 	pte &= ~((((region_table_slot_t)1 << sctx->region_table_entry_bits) - 1) << bit);
 	pte |= (region_table_slot_t)value << bit;
-	sctx->region_table[region_index] = pte;
+	WRITE_ONCE(sctx->region_table[region_index], pte);
 }
 
 /*
Signature · 1 line
2.25.1