* [PATCH v1] mtd: rawnand: meson: fix unaligned DMA buffers handling
@ 2023-06-15 8:08 Arseniy Krasnov
2023-06-19 8:39 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Arseniy Krasnov @ 2023-06-15 8:08 UTC (permalink / raw)
To: Liang Yang, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl, Yixun Lan, Jianxin Pan
Cc: oxffffaa, kernel, Arseniy Krasnov, Stable, linux-mtd,
linux-arm-kernel, linux-amlogic, linux-kernel
Meson NAND controller requires 8 bytes alignment for DMA addresses,
otherwise it "aligns" passed address by itself thus accessing invalid
location in the provided buffer. This patch makes unaligned buffers to
be reallocated to become valid.
Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
Cc: <Stable@vger.kernel.org>
Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
drivers/mtd/nand/raw/meson_nand.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index c5628f7ac3b1..aa2b64dde74b 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -77,6 +77,7 @@
#define GENCMDIADDRH(aih, addr) ((aih) | (((addr) >> 16) & 0xffff))
#define DMA_DIR(dir) ((dir) ? NFC_CMD_N2M : NFC_CMD_M2N)
+#define DMA_ADDR_ALIGN 8
#define ECC_CHECK_RETURN_FF (-1)
@@ -1001,6 +1002,9 @@ static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf,
static bool meson_nfc_is_buffer_dma_safe(const void *buffer)
{
+ if ((uintptr_t)buffer % DMA_ADDR_ALIGN)
+ return false;
+
if (virt_addr_valid(buffer) && (!object_is_on_stack(buffer)))
return true;
return false;
--
2.35.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mtd: rawnand: meson: fix unaligned DMA buffers handling
2023-06-15 8:08 [PATCH v1] mtd: rawnand: meson: fix unaligned DMA buffers handling Arseniy Krasnov
@ 2023-06-19 8:39 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2023-06-19 8:39 UTC (permalink / raw)
To: Arseniy Krasnov, Liang Yang, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl, Yixun Lan, Jianxin Pan
Cc: oxffffaa, kernel, Stable, linux-mtd, linux-arm-kernel,
linux-amlogic, linux-kernel
On Thu, 2023-06-15 at 08:08:15 UTC, Arseniy Krasnov wrote:
> Meson NAND controller requires 8 bytes alignment for DMA addresses,
> otherwise it "aligns" passed address by itself thus accessing invalid
> location in the provided buffer. This patch makes unaligned buffers to
> be reallocated to become valid.
>
> Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
> Cc: <Stable@vger.kernel.org>
> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-19 8:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 8:08 [PATCH v1] mtd: rawnand: meson: fix unaligned DMA buffers handling Arseniy Krasnov
2023-06-19 8:39 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®