diff mbox series

fs: ext4: Fix alignment of cache buffers

Message ID c2b25bd8-8f9a-c95d-a309-d18ac755f611@siemens.com
State Accepted
Commit 7b83060b1eab4456b3dfaef636dfd5c0ff705b17
Headers show
Series fs: ext4: Fix alignment of cache buffers | expand

Commit Message

Jan Kiszka March 25, 2020, 8:27 p.m. UTC
From: Jan Kiszka <jan.kiszka at siemens.com>

We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid
access errors like

CACHE: Misaligned operation at range [be0231e0, be0235e0]

seen on the MCIMX7SABRE.

Fixes: d5aee659f217 ("fs: ext4: cache extent data")
Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini March 25, 2020, 8:31 p.m. UTC | #1
On Wed, Mar 25, 2020 at 09:27:51PM +0100, Jan Kiszka wrote:

> From: Jan Kiszka <jan.kiszka at siemens.com>
> 
> We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid
> access errors like
> 
> CACHE: Misaligned operation at range [be0231e0, be0235e0]
> 
> seen on the MCIMX7SABRE.
> 
> Fixes: d5aee659f217 ("fs: ext4: cache extent data")
> Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
> ---
>  fs/ext4/ext4fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
> index 1c616a26a2..966b427a97 100644
> --- a/fs/ext4/ext4fs.c
> +++ b/fs/ext4/ext4fs.c
> @@ -288,7 +288,7 @@ int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size)
>  	if (cache->buf && cache->block == block && cache->size == size)
>  		return 1;
>  	ext_cache_fini(cache);
> -	cache->buf = malloc(size);
> +	cache->buf = memalign(ARCH_DMA_MINALIGN, size);
>  	if (!cache->buf)
>  		return 0;
>  	if (!ext4fs_devread(block, 0, size, cache->buf)) {

Thanks for digging in to this.

Reviewed-by: Tom Rini <trini at konsulko.com>
Stephen Warren March 25, 2020, 8:35 p.m. UTC | #2
On 3/25/20 2:27 PM, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka at siemens.com>
> 
> We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid
> access errors like
> 
> CACHE: Misaligned operation at range [be0231e0, be0235e0]
> 
> seen on the MCIMX7SABRE.
> 
> Fixes: d5aee659f217 ("fs: ext4: cache extent data")
> Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>

Reviewed-by: Stephen Warren <swarren at nvidia.com>

It's probably just a fluke that this happens to show up on some
SoCs/boards/configurations but not others. Or perhaps the MINALIGN value
differs?
Peter Robinson March 26, 2020, 11:38 a.m. UTC | #3
On Wed, Mar 25, 2020 at 8:28 PM Jan Kiszka <jan.kiszka at siemens.com> wrote:
>
> From: Jan Kiszka <jan.kiszka at siemens.com>
>
> We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid
> access errors like
>
> CACHE: Misaligned operation at range [be0231e0, be0235e0]
>
> seen on the MCIMX7SABRE.

I've also seen this on some i.MX6 devices such as Wandboard,
Hummingboard Edge and the UDOO Neo. Tested on the later two, thanks
for this fix.

Tested-by: Peter Robinson <pbrobinson at gmail.com>

> Fixes: d5aee659f217 ("fs: ext4: cache extent data")
> Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
> ---
>  fs/ext4/ext4fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
> index 1c616a26a2..966b427a97 100644
> --- a/fs/ext4/ext4fs.c
> +++ b/fs/ext4/ext4fs.c
> @@ -288,7 +288,7 @@ int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size)
>         if (cache->buf && cache->block == block && cache->size == size)
>                 return 1;
>         ext_cache_fini(cache);
> -       cache->buf = malloc(size);
> +       cache->buf = memalign(ARCH_DMA_MINALIGN, size);
>         if (!cache->buf)
>                 return 0;
>         if (!ext4fs_devread(block, 0, size, cache->buf)) {
> --
> 2.16.4
>
>
> --
> Siemens AG, Corporate Technology, CT RDA IOT SES-DE
> Corporate Competence Center Embedded Linux
Tom Rini March 27, 2020, 9:55 p.m. UTC | #4
On Wed, Mar 25, 2020 at 09:27:51PM +0100, Jan Kiszka wrote:

> From: Jan Kiszka <jan.kiszka at siemens.com>
> 
> We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid
> access errors like
> 
> CACHE: Misaligned operation at range [be0231e0, be0235e0]
> 
> seen on the MCIMX7SABRE.
> 
> Fixes: d5aee659f217 ("fs: ext4: cache extent data")
> Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
> Reviewed-by: Tom Rini <trini at konsulko.com>
> Reviewed-by: Stephen Warren <swarren at nvidia.com>
> Tested-by: Peter Robinson <pbrobinson at gmail.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 1c616a26a2..966b427a97 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -288,7 +288,7 @@  int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size)
 	if (cache->buf && cache->block == block && cache->size == size)
 		return 1;
 	ext_cache_fini(cache);
-	cache->buf = malloc(size);
+	cache->buf = memalign(ARCH_DMA_MINALIGN, size);
 	if (!cache->buf)
 		return 0;
 	if (!ext4fs_devread(block, 0, size, cache->buf)) {