Skip to contentSkip to conversation

ext4: cache-align buffers so the invalidation works

PATCH New Stephen Warren 2 participants 2 messages Sep 18, 2012 – Sep 20, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: cache-align buffers so the invalidation works

From: Stephen Warren <[email protected]>

DMA buffer cache invalidation requires that buffers have cache-aligned buffer locations and sizes. Use memalign() and ALLOC_CACHE_ALIGN_BUFFER() to ensure this.

On Tegra at least, without this fix, the following fail commands fail in u-boot-master/ext4, but succeeded at the branch's branch point in u-boot/master. With this fix, the commands work again:

ext2ls mmc 0:1 /
ext2load mmc 0:1 /boot/zImage

Cc Uma Shankar <[email protected]>
Cc Manjunatha C Achar <[email protected]>
Cc Iqbal Shareef <[email protected]>
Cc Hakgoo Lee <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Tom Rini <[email protected]>

---
This patch is for branch u-boot/ext4.

 fs/ext4/dev.c         |    4 ++--
 fs/ext4/ext4_common.c |    2 +-
 fs/ext4/ext4_common.h |    7 ++++++-
 3 files changed, 9 insertions(+), 4 deletions(-)
fs/ext4/dev.c +2 -2
index fb62f24..9e85228 100644
@@ -62,7 +62,7 @@ int ext4fs_set_blk_dev(block_dev_desc_t *rbdd, int part)
 
 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 {
-	char sec_buf[SECTOR_SIZE];
+	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, SECTOR_SIZE);
 	unsigned block_len;
 
 	/* Check partition boundaries */
@@ -107,7 +107,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
 	block_len = byte_len & ~(SECTOR_SIZE - 1);
 
 	if (block_len == 0) {
-		u8 p[SECTOR_SIZE];
+		ALLOC_CACHE_ALIGN_BUFFER(u8, p, SECTOR_SIZE);
 
 		block_len = SECTOR_SIZE;
 		ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev,
fs/ext4/ext4_common.c +1 -1
index 083e45e..3deffd5 100644
@@ -71,7 +71,7 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
 	uint64_t startblock;
 	uint64_t remainder;
 	unsigned char *temp_ptr = NULL;
-	unsigned char sec_buf[SECTOR_SIZE];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, SECTOR_SIZE);
 	struct ext_filesystem *fs = get_fs();
 
 	startblock = off / (uint64_t)SECTOR_SIZE;
fs/ext4/ext4_common.h +6 -1
index 801b8b8..0af625d 100644
@@ -55,7 +55,12 @@
 #define SUPERBLOCK_SIZE	1024
 #define F_FILE			1
 
-#define zalloc(size) calloc(1, size)
+static inline void *zalloc(size_t size)
+{
+	void *p = memalign(ARCH_DMA_MINALIGN, size);
+	memset(p, 0, size);
+	return p;
+}
 
 extern unsigned long part_offset;
 int ext4fs_read_inode(struct ext2_data *data, int ino,
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/1 ext4: cache-align buffers so the invalidation works

Quoted 13 lines · Stephen Warren

From: Stephen Warren <[email protected]>

DMA buffer cache invalidation requires that buffers have cache-aligned buffer locations and sizes. Use memalign() and ALLOC_CACHE_ALIGN_BUFFER() to ensure this.

On Tegra at least, without this fix, the following fail commands fail in u-boot-master/ext4, but succeeded at the branch's branch point in u-boot/master. With this fix, the commands work again:

ext2ls mmc 0:1 /
ext2load mmc 0:1 /boot/zImage

Quoted 7 lines
Cc Uma Shankar <[email protected]>
Cc Manjunatha C Achar <[email protected]>
Cc Iqbal Shareef <[email protected]>
Cc Hakgoo Lee <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120920/bee22072/attachment.pgp>