Fix boot failure due to misaligned DMA buffer
cover Fix boot failure due to misaligned DMA buffer
Hi,
We observed the following sporadic boot failure while booting from MMC device:
=> boot
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] ** Booting bootflow '[email protected]_1' with extlinux Ignoring unknown command: �D���D��
Boot failed (err=-14)
The reason is because while allocating buffer to read a file from MMC, alignment of 1 byte is used. Thus, the buffer doesn't work for performing DMA, and garbage data is read.
While looking at this issue, I also noticed that if no alignment specified (align=0) then fs_read_alloc() is documented to use the default. But the default is no alignment. Therefore, other users of fs_read_alloc() which specify align=0 may be broken as well.
The first patch changes the default to align the buffer suitable for DMA.
The second patch changes extlinux_read_bootflow() to use the default alignment.
Nam Cao (2):
fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc()
boot: extlinux: Fix unaligned buffer for reading data from file system
boot/bootmeth_extlinux.c | 2 +- fs/fs.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.5
PATCH 1/2 fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc()
The comment above fs_read_alloc() explains:
@align: Alignment to use for memory allocation (0 for default)
However, in the actual implementation, there is no alignment when @align is zero.
This current default is probably fine for most cases. But for some block devices which transfer data via DMA, ARCH_DMA_MINALIGN is needed.
Change the default alignment to ARCH_DMA_MINALIGN.
--- fs/fs.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/fs.c +4 -0
@@ -23,6 +23,7 @@#include <semihostingfs.h> #include <ubifs_uboot.h> #include <btrfs.h> +#include <asm/cache.h> #include <asm/global_data.h> #include <asm/io.h> #include <div64.h>
@@ -1001,6 +1002,9 @@ int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp)char *buf;int ret; +if (!align) + align =ARCH_DMA_MINALIGN ; + buf =memalign (align, size +1 );if (!buf)return log_msg_ret ("buf" , -ENOMEM );
Signature · 1 line
2.39.5
PATCH 2/2 boot: extlinux: Fix unaligned buffer for reading data from file system
In reply to Nam Caoextlinux_read_bootflow() allocates a buffer to read from file system without any alignment.
But for some block devices which transfer data via DMA, ARCH_DMA_MINALIGN alignment is required. For example, due to misaligned buffer, the below boot failure is observed.
=> boot
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8]
CACHE: Misaligned operation at range [9efa25f8, 9efa27f8] ** Booting bootflow '[email protected]_1' with extlinux Ignoring unknown command: �D���D��
Boot failed (err=-14)
Change the alignment to default (which is ARCH_DMA_MINALIGN).
--- boot/bootmeth_extlinux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
boot/bootmeth_extlinux.c +1 -1
@@ -127,7 +127,7 @@ static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow)return log_msg_ret ("try" , ret); size = bflow->size; - ret =bootmeth_alloc_file (bflow,0x10000 ,1 ); + ret =bootmeth_alloc_file (bflow,0x10000 ,0 );if (ret)return log_msg_ret ("read" , ret);
Signature · 1 line
2.39.5
Re: [PATCH 2/2] boot: extlinux: Fix unaligned buffer for reading data from file system
Hi Nam,
Quoted 31 lines · Nam Cao
extlinux_read_bootflow()allocates a buffer to read from file system without any alignment.But for some block devices which transfer data via DMA,
ARCH_DMA_MINALIGNalignment is required. For example, due to misaligned buffer, the below boot failure is observed.=> boot
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8] ** Booting bootflow '[email protected]_1' with extlinux Ignoring unknown command: �D���D��
Boot failed (err=-14)Change the alignment to default (which is
ARCH_DMA_MINALIGN).Fixes 31aefaf89a5b ("bootstd: Add an implementation of distro boot")Signed-off-by Nam Cao <[email protected]>--- boot/bootmeth_extlinux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)boot/bootmeth_extlinux.c +0
-0
boot/bootmeth_extlinux.c static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow) · line 130
Quoted 5 lines
boot/bootmeth_extlinux.c +1
-1@@ -127,7 +127,7 @@ static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow)return log_msg_ret ("try" , ret); size = bflow->size; - ret =bootmeth_alloc_file (bflow,0x10000 ,1 ); + ret =bootmeth_alloc_file (bflow,0x10000 ,0 );
Can you please use ARCH_DMA_MINALIGN here? Either that or update bootmeth_script to do the same as here.
Quoted 6 lines
boot/bootmeth_extlinux.c +0
-1if (ret)return log_msg_ret ("read" , ret); --2.39.5
Regards,
Simon
Re: [PATCH 1/2] fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc()
In reply to Nam CaoHi Nam,
Quoted 11 lines · Nam Cao
The comment above
fs_read_alloc()explains:@align: Alignment to use for memory allocation (0 for default)
However, in the actual implementation, there is no alignment when @align is zero.
This current default is probably fine for most cases. But for some block devices which transfer data via DMA,
ARCH_DMA_MINALIGNis needed.
Quoted 9 lines
Change the default alignment to
ARCH_DMA_MINALIGN.Fixes de7b5a8a1ac0 ("fs: Create functions to load and allocate a file")Signed-off-by Nam Cao <[email protected]>--- fs/fs.c | 4 ++++ 1 file changed, 4 insertions(+)
Please update the function comment in fs.h to specify the default value
Regards,
Simon
Re: [PATCH 1/2] fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc()
Hi Simon,
Quoted 24 lines · Simon Glass
Hi Nam,
Quoted 11 lines · Nam Cao
The comment above
fs_read_alloc()explains:@align: Alignment to use for memory allocation (0 for default)
However, in the actual implementation, there is no alignment when @align is zero.
This current default is probably fine for most cases. But for some block devices which transfer data via DMA,
ARCH_DMA_MINALIGNis needed.Quoted 9 lines
Change the default alignment to
ARCH_DMA_MINALIGN.Fixes de7b5a8a1ac0 ("fs: Create functions to load and allocate a file")Signed-off-by Nam Cao <[email protected]>--- fs/fs.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 1 line
Please update the function comment in
fs.hto specify the default value
Sure.
Best regards,
Nam
Re: [PATCH 2/2] boot: extlinux: Fix unaligned buffer for reading data from file system
In reply to Simon GlassHi Simon,
Quoted 35 lines · Simon Glass
Quoted 34 lines · Nam Cao
extlinux_read_bootflow()allocates a buffer to read from file system without any alignment.But for some block devices which transfer data via DMA,
ARCH_DMA_MINALIGNalignment is required. For example, due to misaligned buffer, the below boot failure is observed.=> boot
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8]
CACHE: Misaligned operation at range [9efa25f8,9efa27f8] ** Booting bootflow '[email protected]_1' with extlinux Ignoring unknown command: �D���D��
Boot failed (err=-14)Change the alignment to default (which is
ARCH_DMA_MINALIGN).Fixes 31aefaf89a5b ("bootstd: Add an implementation of distro boot")Signed-off-by Nam Cao <[email protected]>--- boot/bootmeth_extlinux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)boot/bootmeth_extlinux.c +0
-0@@ -127,7 +127,7 @@ static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow)return log_msg_ret ("try" , ret); size = bflow->size;
Quoted 5 lines
boot/bootmeth_extlinux.c static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow) · line 130
Quoted 2 lines
boot/bootmeth_extlinux.c +1
-1- ret =bootmeth_alloc_file (bflow,0x10000 ,1 ); + ret =bootmeth_alloc_file (bflow,0x10000 ,0 );Can you please use
ARCH_DMA_MINALIGNhere? Either that or updatebootmeth_scriptto do the same as here.
No preference from me. Let's just use ARCH_DMA_MINALIGN here.
Thanks for the comments,
Nam