Skip to contentSkip to conversation

mtd: rawnand: gpmi: terminate the DMA chain on completion timeout

PATCH Superseded Samarth Narang 3 participants 3 messages Oct 30

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: gpmi: terminate the DMA chain on completion timeout

When DMA completion times out in gpmi_nfc_exec_op(), the driver unmaps the operation's buffers and returns -ETIMEDOUT without stopping the APBH DMA channel. Since mxs-dma leaves the channel in DMA_IN_PROGRESS, the pending descriptor chain may resume after the timeout, while a subsequent operation can append new descriptors to the stale chain and cause the old DATA_IN transfer to execute again against an unmapped buffer.

This can result in DMA writes to memory that has already been released, including buffers freed after ONFI parameter page detection in nand_onfi_detect().

Terminate the channel with dmaengine_terminate_sync() before unmapping so that outstanding transfers are stopped and subsequent operations begin with a fresh descriptor chain.

Fixes ef347c0cfd61 ("mtd: rawnand: gpmi: Implement exec_op")
Assisted-by LLM

---
This issue was identified by a research static analyzer for DMA lifecycle ordering and has not been validated on hardware. Compile-tested only.

 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +2 -0
index 527165ccc..a8106de2c 100644
@@ -2659,6 +2659,8 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
 	if (!to) {
 		dev_err(this->dev, "DMA timeout, last DMA\n");
 		gpmi_dump_info(this);
+		/* Retire the APBH chain before its buffers are unmapped. */
+		dmaengine_terminate_sync(get_dma_chan(this));
 		ret = -ETIMEDOUT;
 		goto unmap;
 	}

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Samarth Narang

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

When DMA completion times out in gpmi_nfc_exec_op(), the driver unmaps the operation's buffers and returns -ETIMEDOUT without stopping the APBH DMA channel. Since mxs-dma leaves the channel in DMA_IN_PROGRESS, the pending descriptor chain may resume after the timeout, while a subsequent operation can append new descriptors to the stale chain and cause the old DATA_IN transfer to execute again against an unmapped buffer.

This can result in DMA writes to memory that has already been released, including buffers freed after ONFI parameter page detection in nand_onfi_detect().

Quoted 8 lines

Terminate the channel with dmaengine_terminate_sync() before unmapping so that outstanding transfers are stopped and subsequent operations begin with a fresh descriptor chain.

Fixes ef347c0cfd61 ("mtd: rawnand: gpmi: Implement exec_op")
Assisted-by LLM

---

Quoted 23 lines

This issue was identified by a research static analyzer for DMA lifecycle ordering and has not been validated on hardware. Compile-tested only.

 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +2 -0
index 527165ccc..a8106de2c 100644
@@ -2659,6 +2659,8 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
        if (!to) {
                dev_err(this->dev, "DMA timeout, last DMA\n");
                gpmi_dump_info(this);
+               /* Retire the APBH chain before its buffers are unmapped. */
+               dmaengine_terminate_sync(get_dma_chan(this));
                ret = -ETIMEDOUT;
                goto unmap;
        }

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

maintainer
#2 lore raw
In reply to Samarth Narang

Hello,

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nfc_exec_op(struct nand_chip *chip, · line 2662

Quoted 9 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
index 527165ccc..a8106de2c 100644
@@ -2659,6 +2659,8 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
 	if (!to) {
 		dev_err(this->dev, "DMA timeout, last DMA\n");
 		gpmi_dump_info(this);
+		/* Retire the APBH chain before its buffers are unmapped. */

Please drop this comment.

Otherwise fine.

Quoted 6 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
+		dmaengine_terminate_sync(get_dma_chan(this));
 		ret = -ETIMEDOUT;
 		goto unmap;
 	}

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

Thanks,
Miquèl