Skip to contentSkip to conversation

spi: dw: Fix missing smp_mb() in dw_spi_exec_mem_op

PATCH In review Jisheng Zhang 2 participants 3 messages Oct 10 – Oct 14 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: dw: Fix missing smp_mb() in dw_spi_exec_mem_op

Similar as commit bfda044533b2 ("spi: dw: use "smp_mb()" to avoid sending spi data error"), we also need the smp_mb() in dw_spi_exec_mem_op() after setting up the members in "dws" to ensure the data change is visible for all CPUs.

Fixes 6423207e57ea ("spi: dw: Add memory operations support")
---
 drivers/spi/spi-dw-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi-dw-core.c +3 -0
index 2d671e31413e..90af2cc9e17d 100644
@@ -842,6 +842,9 @@ static int dw_spi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
 		cfg.tmode = DW_SPI_CTRLR0_TMOD_TO;
 	}
 
+	/* Ensure the data change in dw_spi_init_mem_buf() is visible for all CPUs */
+	smp_mb();
+
 	dw_spi_enable_chip(dws, 0);
 
 	dw_spi_update_config(dws, mem->spi, &cfg, NULL);
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 4 lines · Jisheng Zhang

Similar as commit bfda044533b2 ("spi: dw: use "smp_mb()" to avoid sending spi data error"), we also need the smp_mb() in dw_spi_exec_mem_op() after setting up the members in "dws" to ensure the data change is visible for all CPUs.

Which other CPUs are we worried about here? Unlike the regular SPI path which can use DMA and interrupts for the exec_op() stuff we only do PIO and have interrupts masked during the actual transfer. If the task migrates I'd expect that to have all the required barriers, but otherwise it all looks single threaded.

#2 lore raw
Quoted 7 lines · Mark Brown
Quoted 4 lines · Jisheng Zhang

Similar as commit bfda044533b2 ("spi: dw: use "smp_mb()" to avoid sending spi data error"), we also need the smp_mb() in dw_spi_exec_mem_op() after setting up the members in "dws" to ensure the data change is visible for all CPUs.

Quoted 5 lines

Which other CPUs are we worried about here? Unlike the regular SPI path which can use DMA and interrupts for the exec_op() stuff we only do PIO and have interrupts masked during the actual transfer. If the task migrates I'd expect that to have all the required barriers, but otherwise it all looks single threaded.

You are right. This patch isn't needed. Thanks for the explaination.