diff mbox

[U-Boot] ext2: Cache line aligned partial sector bounce buffer

Message ID 1314043438-21590-1-git-send-email-robotboy@chromium.org
State Superseded
Headers show

Commit Message

Anton staaf Aug. 22, 2011, 8:03 p.m. UTC
Currently, if a device read request is done that does not begin or end
on a sector boundary a stack allocated bounce buffer is used to perform
the read, and then just the part of the sector that is needed is copied
into the users buffer.  This stack allocation can mean that the bounce
buffer will not be aligned to the dcache line size.  This is a problem
when caches are enabled because unaligned cache invalidates are not
safe.

This patch allocates a cache line size aligned sector sized bounce
buffer the first time that ext2fs_devread is called.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Dave Liu <r63238@freescale.com>
Cc: Andy Fleming <afleming@gmail.com>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
---

This patch depends on Lukasz Majewski's dcache line size patch sent to the
list in: http://patchwork.ozlabs.org/patch/110501/

 fs/ext2/dev.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

Comments

Anton Staaf Aug. 22, 2011, 8:08 p.m. UTC | #1
Ooops, expect a follow up without that last minute addition of a C++
style comment about ENOMEM, sorry...

-Anton

On Mon, Aug 22, 2011 at 1:03 PM, Anton Staaf <robotboy@chromium.org> wrote:
> Currently, if a device read request is done that does not begin or end
> on a sector boundary a stack allocated bounce buffer is used to perform
> the read, and then just the part of the sector that is needed is copied
> into the users buffer.  This stack allocation can mean that the bounce
> buffer will not be aligned to the dcache line size.  This is a problem
> when caches are enabled because unaligned cache invalidates are not
> safe.
>
> This patch allocates a cache line size aligned sector sized bounce
> buffer the first time that ext2fs_devread is called.
>
> Signed-off-by: Anton Staaf <robotboy@chromium.org>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Mike Frysinger <vapier@gentoo.org>
> Cc: Dave Liu <r63238@freescale.com>
> Cc: Andy Fleming <afleming@gmail.com>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>
> This patch depends on Lukasz Majewski's dcache line size patch sent to the
> list in: http://patchwork.ozlabs.org/patch/110501/
>
>  fs/ext2/dev.c |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/fs/ext2/dev.c b/fs/ext2/dev.c
> index 78851d0..4b2aeef 100644
> --- a/fs/ext2/dev.c
> +++ b/fs/ext2/dev.c
> @@ -26,6 +26,7 @@
>
>  #include <common.h>
>  #include <config.h>
> +#include <malloc.h>
>  #include <ext2fs.h>
>
>  static block_dev_desc_t *ext2fs_block_dev_desc;
> @@ -52,9 +53,15 @@ int ext2fs_set_blk_dev(block_dev_desc_t *rbdd, int part)
>
>  int ext2fs_devread(int sector, int byte_offset, int byte_len, char *buf)
>  {
> -       char sec_buf[SECTOR_SIZE];
> +       static char *sec_buf;
>        unsigned sectors;
>
> +       if (sec_buf == NULL)
> +               sec_buf = memalign(get_dcache_line_size(), SECTOR_SIZE);
> +
> +       if (sec_buf == NULL)
> +               return 0; //-ENOMEM
> +
>        /*
>         *  Check partition boundaries
>         */
> --
> 1.7.3.1
>
>
diff mbox

Patch

diff --git a/fs/ext2/dev.c b/fs/ext2/dev.c
index 78851d0..4b2aeef 100644
--- a/fs/ext2/dev.c
+++ b/fs/ext2/dev.c
@@ -26,6 +26,7 @@ 
 
 #include <common.h>
 #include <config.h>
+#include <malloc.h>
 #include <ext2fs.h>
 
 static block_dev_desc_t *ext2fs_block_dev_desc;
@@ -52,9 +53,15 @@  int ext2fs_set_blk_dev(block_dev_desc_t *rbdd, int part)
 
 int ext2fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 {
-	char sec_buf[SECTOR_SIZE];
+	static char *sec_buf;
 	unsigned sectors;
 
+	if (sec_buf == NULL)
+		sec_buf = memalign(get_dcache_line_size(), SECTOR_SIZE);
+
+	if (sec_buf == NULL)
+		return 0; //-ENOMEM
+
 	/*
 	 *  Check partition boundaries
 	 */