Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA
       [not found] ` <20261125092538.1938516-1-leeonion.muyu@gmail.com>
@ 2026-11-25  9:25   ` Ping Li
  2026-11-25  9:25   ` [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25  9:25 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_nand_read_page_hwecc()/ebu_nand_write_page_hwecc() feed the
page buffers provided by the NAND core straight to the DMA
engine, but the driver never declares NAND_USES_DMA.  Because of
this, nand_base cannot know the controller DMAs these buffers and
never bounces non-linear-map ones (see the use_bounce_buf logic
in nand_do_read_ops()/nand_do_write_ops()).

Non-linear-map buffers are not hypothetical here: mtdblock's
write cache is vmalloc'ed and UBIFS passes vmalloc'ed LPT buffers,
so such buffers can reach the controller's DMA engine, for which
they are not a valid dma_map_single() input.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, as the other DMA-capable
controllers (arasan, denali, meson, mtk, nuvoton...) already do.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index cfb4b231e067..1f493fb426d6 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -688,6 +688,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	nand = &ebu_host->chip;
 	nand->controller = &ebu_host->controller;
 	nand->controller->ops = &ebu_nand_controller_ops;
+	nand->options |= NAND_USES_DMA;
 
 	/* Scan to find existence of the device */
 	ret = nand_scan(&ebu_host->chip, 1);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
       [not found] ` <20261125092538.1938516-1-leeonion.muyu@gmail.com>
  2026-11-25  9:25   ` [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
@ 2026-11-25  9:25   ` Ping Li
  2026-11-25  9:25   ` [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
       [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
  3 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25  9:25 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_dma_start() maps the data buffer for every page transfer but
only unmaps it on the error path.  Successful transfers thus leak
the mapping, which accumulates IOVA space on IOMMU systems and
skips any cache maintenance the unmap would perform on
non-coherent platforms.  The error path has two more problems:
when the mapping itself fails it jumps to the unmap with an
invalid dma address, and the unmap is performed with
ebu_host->dev instead of the dma_dev device the buffer was
mapped with.

Return directly when the mapping fails, and unmap with dma_dev on
both the success and the error paths.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 1f493fb426d6..5eff8d7522d4 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -312,8 +312,7 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 	buf_dma = dma_map_single(dma_dev, (void *)buf, len, dir);
 	if (dma_mapping_error(dma_dev, buf_dma)) {
 		dev_err(ebu_host->dev, "Failed to map DMA buffer\n");
-		ret = -EIO;
-		goto err_unmap;
+		return -EIO;
 	}
 
 	tx = dmaengine_prep_slave_single(chan, buf_dma, len, dir, flags);
@@ -346,10 +345,12 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 		goto err_unmap;
 	}
 
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
+
 	return 0;
 
 err_unmap:
-	dma_unmap_single(ebu_host->dev, buf_dma, len, dir);
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
 
 	return ret;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA
       [not found] ` <20261125092538.1938516-1-leeonion.muyu@gmail.com>
  2026-11-25  9:25   ` [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
  2026-11-25  9:25   ` [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
@ 2026-11-25  9:25   ` Ping Li
  2026-11-25  9:48     ` Miquel Raynal
       [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
  3 siblings, 1 reply; 11+ messages in thread
From: Ping Li @ 2026-11-25  9:25 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

r852_do_dma() feeds the buffers provided by the NAND core straight
to dma_map_single(), which is only valid for linear-map addresses,
but the driver never declares NAND_USES_DMA.  Because of this,
nand_base cannot know the controller DMAs these buffers and never
bounces non-linear-map ones.  Such buffers are not hypothetical:
mtdblock's write cache is vmalloc'ed and UBIFS passes vmalloc'ed
LPT buffers.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, as the other DMA-capable
controllers do.  The existing local bounce in r852_do_dma() is
still needed for the hardware's 512-byte alignment requirement,
which the core condition (chip->buf_align, default 1) does not
cover.

Fixes: 67e054e919248 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/r852.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 92c47d351c27..f930e8cc80e6 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -640,6 +640,16 @@ static int r852_register_nand_device(struct r852_device *dev)
 	if (dev->readonly)
 		dev->chip->options |= NAND_ROM;
 
+	/*
+	 * r852_do_dma() feeds the buffers provided by the NAND core
+	 * straight to dma_map_single(), so ask nand_base to bounce
+	 * non-linear-map buffers.  The local bounce in r852_do_dma()
+	 * is still needed for the hardware's 512-byte alignment
+	 * requirement, which the core condition (chip->buf_align,
+	 * default 1) does not cover.
+	 */
+	dev->chip->options |= NAND_USES_DMA;
+
 	r852_engine_enable(dev);
 
 	if (sm_register_device(mtd, dev->sm))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA
  2026-11-25  9:25   ` [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
@ 2026-11-25  9:48     ` Miquel Raynal
  0 siblings, 0 replies; 11+ messages in thread
From: Miquel Raynal @ 2026-11-25  9:48 UTC (permalink / raw)
  To: Ping Li; +Cc: richard, vigneshr, linux-mtd, linux-kernel, stable


> +	/*
> +	 * r852_do_dma() feeds the buffers provided by the NAND core
> +	 * straight to dma_map_single(), so ask nand_base to bounce
> +	 * non-linear-map buffers.  The local bounce in r852_do_dma()
> +	 * is still needed for the hardware's 512-byte alignment
> +	 * requirement, which the core condition (chip->buf_align,
> +	 * default 1) does not cover.

Can't we change the default for this chip then?

Please drop this comment after fixing that, it is not useful, this is
information that should belong in the commit log.

> +	 */
> +	dev->chip->options |= NAND_USES_DMA;
> +
>  	r852_engine_enable(dev);
>  
>  	if (sm_register_device(mtd, dev->sm))

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/3] mtd: rawnand: intel: declare NAND_USES_DMA
       [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
@ 2026-11-25 11:51     ` Ping Li
  2026-11-25 11:51     ` [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25 11:51 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_nand_read_page_hwecc()/ebu_nand_write_page_hwecc() feed the
page buffers provided by the NAND core straight to the DMA
engine, but the driver never declares NAND_USES_DMA.  Because of
this, nand_base cannot know the controller DMAs these buffers and
never bounces non-linear-map ones (see the use_bounce_buf logic
in nand_do_read_ops()/nand_do_write_ops()).

Non-linear-map buffers are not hypothetical here: mtdblock's
write cache is vmalloc'ed and UBIFS passes vmalloc'ed LPT buffers,
so such buffers can reach the controller's DMA engine, for which
they are not a valid dma_map_single() input.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, as the other DMA-capable
controllers (arasan, denali, meson, mtk, nuvoton...) already do.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index cfb4b231e067..1f493fb426d6 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -688,6 +688,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	nand = &ebu_host->chip;
 	nand->controller = &ebu_host->controller;
 	nand->controller->ops = &ebu_nand_controller_ops;
+	nand->options |= NAND_USES_DMA;
 
 	/* Scan to find existence of the device */
 	ret = nand_scan(&ebu_host->chip, 1);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
       [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
  2026-11-25 11:51     ` [PATCH v4 1/3] mtd: rawnand: intel: " Ping Li
@ 2026-11-25 11:51     ` Ping Li
  2026-11-25 11:51     ` [PATCH v4 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
       [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
  3 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25 11:51 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_dma_start() maps the data buffer for every page transfer but
only unmaps it on the error path.  Successful transfers thus leak
the mapping, which accumulates IOVA space on IOMMU systems and
skips any cache maintenance the unmap would perform on
non-coherent platforms.  The error path has two more problems:
when the mapping itself fails it jumps to the unmap with an
invalid dma address, and the unmap is performed with
ebu_host->dev instead of the dma_dev device the buffer was
mapped with.

Return directly when the mapping fails, and unmap with dma_dev on
both the success and the error paths.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 1f493fb426d6..5eff8d7522d4 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -312,8 +312,7 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 	buf_dma = dma_map_single(dma_dev, (void *)buf, len, dir);
 	if (dma_mapping_error(dma_dev, buf_dma)) {
 		dev_err(ebu_host->dev, "Failed to map DMA buffer\n");
-		ret = -EIO;
-		goto err_unmap;
+		return -EIO;
 	}
 
 	tx = dmaengine_prep_slave_single(chan, buf_dma, len, dir, flags);
@@ -346,10 +345,12 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 		goto err_unmap;
 	}
 
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
+
 	return 0;
 
 err_unmap:
-	dma_unmap_single(ebu_host->dev, buf_dma, len, dir);
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
 
 	return ret;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v4 3/3] mtd: rawnand: r852: declare NAND_USES_DMA
       [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
  2026-11-25 11:51     ` [PATCH v4 1/3] mtd: rawnand: intel: " Ping Li
  2026-11-25 11:51     ` [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
@ 2026-11-25 11:51     ` Ping Li
       [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
  3 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25 11:51 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

r852_do_dma() feeds the buffers provided by the NAND core straight
to dma_map_single(), which is only valid for linear-map addresses,
but the driver never declares NAND_USES_DMA.  Because of this,
nand_base cannot know the controller DMAs these buffers and never
bounces non-linear-map ones.  Such buffers are not hypothetical:
mtdblock's write cache is vmalloc'ed and UBIFS passes vmalloc'ed
LPT buffers.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, and advertise the hardware's
512-byte alignment requirement through chip->buf_align so that
misaligned linear buffers are bounced as well, like the other
DMA-capable controllers do.

Fixes: 67e054e919248 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/r852.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 92c47d351c27..a68f58c81d6c 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -640,6 +640,9 @@ static int r852_register_nand_device(struct r852_device *dev)
 	if (dev->readonly)
 		dev->chip->options |= NAND_ROM;
 
+	dev->chip->options |= NAND_USES_DMA;
+	dev->chip->buf_align = R852_DMA_LEN;
+
 	r852_engine_enable(dev);
 
 	if (sm_register_device(mtd, dev->sm))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 1/3] mtd: rawnand: intel: declare NAND_USES_DMA
       [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
@ 2026-11-25 12:21       ` Ping Li
  2026-11-25 12:21       ` [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
  2026-11-25 12:21       ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
  2 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25 12:21 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_nand_read_page_hwecc()/ebu_nand_write_page_hwecc() feed the
page buffers provided by the NAND core straight to the DMA
engine, but the driver never declares NAND_USES_DMA.  Because of
this, nand_base cannot know the controller DMAs these buffers and
never bounces non-linear-map ones (see the use_bounce_buf logic
in nand_do_read_ops()/nand_do_write_ops()).

Non-linear-map buffers are not hypothetical here: mtdblock's
write cache is vmalloc'ed and UBIFS passes vmalloc'ed LPT buffers,
so such buffers can reach the controller's DMA engine, for which
they are not a valid dma_map_single() input.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, as the other DMA-capable
controllers (arasan, denali, meson, mtk, nuvoton...) already do.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index cfb4b231e067..1f493fb426d6 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -688,6 +688,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	nand = &ebu_host->chip;
 	nand->controller = &ebu_host->controller;
 	nand->controller->ops = &ebu_nand_controller_ops;
+	nand->options |= NAND_USES_DMA;
 
 	/* Scan to find existence of the device */
 	ret = nand_scan(&ebu_host->chip, 1);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
       [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
  2026-11-25 12:21       ` [PATCH v5 1/3] mtd: rawnand: intel: " Ping Li
@ 2026-11-25 12:21       ` Ping Li
  2026-11-25 12:21       ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
  2 siblings, 0 replies; 11+ messages in thread
From: Ping Li @ 2026-11-25 12:21 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

ebu_dma_start() maps the data buffer for every page transfer but
only unmaps it on the error path.  Successful transfers thus leak
the mapping, which accumulates IOVA space on IOMMU systems and
skips any cache maintenance the unmap would perform on
non-coherent platforms.  The error path has two more problems:
when the mapping itself fails it jumps to the unmap with an
invalid dma address, and the unmap is performed with
ebu_host->dev instead of the dma_dev device the buffer was
mapped with.

Return directly when the mapping fails, and unmap with dma_dev on
both the success and the error paths.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 1f493fb426d6..5eff8d7522d4 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -312,8 +312,7 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 	buf_dma = dma_map_single(dma_dev, (void *)buf, len, dir);
 	if (dma_mapping_error(dma_dev, buf_dma)) {
 		dev_err(ebu_host->dev, "Failed to map DMA buffer\n");
-		ret = -EIO;
-		goto err_unmap;
+		return -EIO;
 	}
 
 	tx = dmaengine_prep_slave_single(chan, buf_dma, len, dir, flags);
@@ -346,10 +345,12 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
 		goto err_unmap;
 	}
 
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
+
 	return 0;
 
 err_unmap:
-	dma_unmap_single(ebu_host->dev, buf_dma, len, dir);
+	dma_unmap_single(dma_dev, buf_dma, len, dir);
 
 	return ret;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA
       [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
  2026-11-25 12:21       ` [PATCH v5 1/3] mtd: rawnand: intel: " Ping Li
  2026-11-25 12:21       ` [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
@ 2026-11-25 12:21       ` Ping Li
  2026-11-25 12:55         ` Miquel Raynal
  2 siblings, 1 reply; 11+ messages in thread
From: Ping Li @ 2026-11-25 12:21 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li, stable

r852_do_dma() feeds the buffers provided by the NAND core straight
to dma_map_single(), which is only valid for linear-map addresses,
but the driver never declares NAND_USES_DMA.  Because of this,
nand_base cannot know the controller DMAs these buffers and never
bounces non-linear-map ones.  Such buffers are not hypothetical:
mtdblock's write cache is vmalloc'ed and UBIFS passes vmalloc'ed
LPT buffers.

Declare NAND_USES_DMA so that nand_base bounces non-linear-map
buffers through chip->data_buf, and advertise the hardware's
512-byte alignment requirement through chip->buf_align so that
misaligned linear buffers are bounced as well, like the other
DMA-capable controllers do.  Both only apply when the controller
actually uses DMA: the PIO fallback path does not care about
buffer addresses being linear-map or 512-byte aligned.

Fixes: 67e054e919248 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/mtd/nand/raw/r852.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 92c47d351c27..c5a3622cddf6 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -640,6 +640,11 @@ static int r852_register_nand_device(struct r852_device *dev)
 	if (dev->readonly)
 		dev->chip->options |= NAND_ROM;
 
+	if (dev->dma_usable) {
+		dev->chip->options |= NAND_USES_DMA;
+		dev->chip->buf_align = R852_DMA_LEN;
+	}
+
 	r852_engine_enable(dev);
 
 	if (sm_register_device(mtd, dev->sm))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA
  2026-11-25 12:21       ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
@ 2026-11-25 12:55         ` Miquel Raynal
  0 siblings, 0 replies; 11+ messages in thread
From: Miquel Raynal @ 2026-11-25 12:55 UTC (permalink / raw)
  To: Ping Li; +Cc: richard, vigneshr, linux-mtd, linux-kernel, stable

On 25/11/2026 at 20:21:35 +08, Ping Li <leeonion.muyu@gmail.com> wrote:

> r852_do_dma() feeds the buffers provided by the NAND core straight
> to dma_map_single(), which is only valid for linear-map addresses,
> but the driver never declares NAND_USES_DMA.  Because of this,
> nand_base cannot know the controller DMAs these buffers and never
> bounces non-linear-map ones.  Such buffers are not hypothetical:
> mtdblock's write cache is vmalloc'ed and UBIFS passes vmalloc'ed
> LPT buffers.
>
> Declare NAND_USES_DMA so that nand_base bounces non-linear-map
> buffers through chip->data_buf, and advertise the hardware's
> 512-byte alignment requirement through chip->buf_align so that
> misaligned linear buffers are bounced as well, like the other
> DMA-capable controllers do.  Both only apply when the controller
> actually uses DMA: the PIO fallback path does not care about
> buffer addresses being linear-map or 512-byte aligned.
>
> Fixes: 67e054e919248 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
> ---
>  drivers/mtd/nand/raw/r852.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
> index 92c47d351c27..c5a3622cddf6 100644
> --- a/drivers/mtd/nand/raw/r852.c
> +++ b/drivers/mtd/nand/raw/r852.c
> @@ -640,6 +640,11 @@ static int r852_register_nand_device(struct r852_device *dev)
>  	if (dev->readonly)
>  		dev->chip->options |= NAND_ROM;
>  
> +	if (dev->dma_usable) {
> +		dev->chip->options |= NAND_USES_DMA;
> +		dev->chip->buf_align = R852_DMA_LEN;
> +	}

Wasn't in this driver a bounce buffering operation that is no longer needed?

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-25 12:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261123070440.3060882-1-leeonion.muyu@gmail.com>
     [not found] ` <20261125092538.1938516-1-leeonion.muyu@gmail.com>
2026-11-25  9:25   ` [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25  9:25   ` [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25  9:25   ` [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25  9:48     ` Miquel Raynal
     [not found]   ` <20261125115108.4147741-1-leeonion.muyu@gmail.com>
2026-11-25 11:51     ` [PATCH v4 1/3] mtd: rawnand: intel: " Ping Li
2026-11-25 11:51     ` [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 11:51     ` [PATCH v4 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
     [not found]     ` <20261125122135.44696-1-leeonion.muyu@gmail.com>
2026-11-25 12:21       ` [PATCH v5 1/3] mtd: rawnand: intel: " Ping Li
2026-11-25 12:21       ` [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 12:21       ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 12:55         ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox