Skip to content

Commit 75686c4

Browse files
Christophe Kerellogregkh
authored andcommitted
mtd: rawnand: stm32_fmc2: avoid overlapping mappings on ECC buffer
commit 513c40e upstream. Avoid below overlapping mappings by using a contiguous non-cacheable buffer. [ 4.077708] DMA-API: stm32_fmc2_nfc 48810000.nand-controller: cacheline tracking EEXIST, overlapping mappings aren't supported [ 4.089103] WARNING: CPU: 1 PID: 44 at kernel/dma/debug.c:568 add_dma_entry+0x23c/0x300 [ 4.097071] Modules linked in: [ 4.100101] CPU: 1 PID: 44 Comm: kworker/u4:2 Not tainted 6.1.82 #1 [ 4.106346] Hardware name: STMicroelectronics STM32MP257F VALID1 SNOR / MB1704 (LPDDR4 Power discrete) + MB1703 + MB1708 (SNOR MB1730) (DT) [ 4.118824] Workqueue: events_unbound deferred_probe_work_func [ 4.124674] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 4.131624] pc : add_dma_entry+0x23c/0x300 [ 4.135658] lr : add_dma_entry+0x23c/0x300 [ 4.139792] sp : ffff800009dbb490 [ 4.143016] x29: ffff800009dbb4a0 x28: 0000000004008022 x27: ffff8000098a6000 [ 4.150174] x26: 0000000000000000 x25: ffff8000099e7000 x24: ffff8000099e7de8 [ 4.157231] x23: 00000000ffffffff x22: 0000000000000000 x21: ffff8000098a6a20 [ 4.164388] x20: ffff000080964180 x19: ffff800009819ba0 x18: 0000000000000006 [ 4.171545] x17: 6361727420656e69 x16: 6c6568636163203a x15: 72656c6c6f72746e [ 4.178602] x14: 6f632d646e616e2e x13: ffff800009832f58 x12: 00000000000004ec [ 4.185759] x11: 00000000000001a4 x10: ffff80000988af58 x9 : ffff800009832f58 [ 4.192916] x8 : 00000000ffffefff x7 : ffff80000988af58 x6 : 80000000fffff000 [ 4.199972] x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 [ 4.207128] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0000812d2c40 [ 4.214185] Call trace: [ 4.216605] add_dma_entry+0x23c/0x300 [ 4.220338] debug_dma_map_sg+0x198/0x350 [ 4.224373] __dma_map_sg_attrs+0xa0/0x110 [ 4.228411] dma_map_sg_attrs+0x10/0x2c [ 4.232247] stm32_fmc2_nfc_xfer.isra.0+0x1c8/0x3fc [ 4.237088] stm32_fmc2_nfc_seq_read_page+0xc8/0x174 [ 4.242127] nand_read_oob+0x1d4/0x8e0 [ 4.245861] mtd_read_oob_std+0x58/0x84 [ 4.249596] mtd_read_oob+0x90/0x150 [ 4.253231] mtd_read+0x68/0xac Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com> Cc: stable@vger.kernel.org Fixes: 2cd457f ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 20f8928 commit 75686c4

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

drivers/mtd/nand/raw/stm32_fmc2_nand.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct stm32_fmc2_nfc {
263263
struct sg_table dma_data_sg;
264264
struct sg_table dma_ecc_sg;
265265
u8 *ecc_buf;
266+
dma_addr_t dma_ecc_addr;
266267
int dma_ecc_len;
267268

268269
struct completion complete;
@@ -885,17 +886,10 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
885886

886887
if (!write_data && !raw) {
887888
/* Configure DMA ECC status */
888-
p = nfc->ecc_buf;
889889
for_each_sg(nfc->dma_ecc_sg.sgl, sg, eccsteps, s) {
890-
sg_set_buf(sg, p, nfc->dma_ecc_len);
891-
p += nfc->dma_ecc_len;
892-
}
893-
894-
ret = dma_map_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
895-
eccsteps, dma_data_dir);
896-
if (!ret) {
897-
ret = -EIO;
898-
goto err_unmap_data;
890+
sg_dma_address(sg) = nfc->dma_ecc_addr +
891+
s * nfc->dma_ecc_len;
892+
sg_dma_len(sg) = nfc->dma_ecc_len;
899893
}
900894

901895
desc_ecc = dmaengine_prep_slave_sg(nfc->dma_ecc_ch,
@@ -904,15 +898,15 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
904898
DMA_PREP_INTERRUPT);
905899
if (!desc_ecc) {
906900
ret = -ENOMEM;
907-
goto err_unmap_ecc;
901+
goto err_unmap_data;
908902
}
909903

910904
reinit_completion(&nfc->dma_ecc_complete);
911905
desc_ecc->callback = stm32_fmc2_nfc_dma_callback;
912906
desc_ecc->callback_param = &nfc->dma_ecc_complete;
913907
ret = dma_submit_error(dmaengine_submit(desc_ecc));
914908
if (ret)
915-
goto err_unmap_ecc;
909+
goto err_unmap_data;
916910

917911
dma_async_issue_pending(nfc->dma_ecc_ch);
918912
}
@@ -932,7 +926,7 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
932926
if (!write_data && !raw)
933927
dmaengine_terminate_all(nfc->dma_ecc_ch);
934928
ret = -ETIMEDOUT;
935-
goto err_unmap_ecc;
929+
goto err_unmap_data;
936930
}
937931

938932
/* Wait DMA data transfer completion */
@@ -952,11 +946,6 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
952946
}
953947
}
954948

955-
err_unmap_ecc:
956-
if (!write_data && !raw)
957-
dma_unmap_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
958-
eccsteps, dma_data_dir);
959-
960949
err_unmap_data:
961950
dma_unmap_sg(nfc->dev, nfc->dma_data_sg.sgl, eccsteps, dma_data_dir);
962951

@@ -1582,7 +1571,8 @@ static int stm32_fmc2_nfc_dma_setup(struct stm32_fmc2_nfc *nfc)
15821571
return ret;
15831572

15841573
/* Allocate a buffer to store ECC status registers */
1585-
nfc->ecc_buf = devm_kzalloc(nfc->dev, FMC2_MAX_ECC_BUF_LEN, GFP_KERNEL);
1574+
nfc->ecc_buf = dmam_alloc_coherent(nfc->dev, FMC2_MAX_ECC_BUF_LEN,
1575+
&nfc->dma_ecc_addr, GFP_KERNEL);
15861576
if (!nfc->ecc_buf)
15871577
return -ENOMEM;
15881578

0 commit comments

Comments
 (0)