Skip to contentSkip to conversation

mtd: fix mtd_blkdevs problem with caches on some architectures (2.6.31)

PATCH In review Ilya Loginov 4 participants 18 messages Nov 18, 2009 – Nov 25, 2009

Subsystems (17)
Arm (32-bit) x86 VFS PowerPC +13 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: fix mtd_blkdevs problem with caches on some architectures (2.6.31)

Mtdblock driver doesn't call flush_dcache_page for pages in request. This may cause problem on architectures where icache doesn't fill from
dcache or with dcache aliases.
This patch resolves this issue.

---
mtd_blkdevs.c | 7 +++++++

1 file changed, 7 insertions(+)
drivers/mtd/mtd_blkdevs.c +7 -0
index 7baba40..59d5d25 100644
@@ -46,6 +46,8 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 {
 	unsigned long block, nsect;
 	char *buf;
+	struct req_iterator iter;
+	struct bio_vec *bvec;
 
 	block = blk_rq_pos(req) << 9 >> tr->blkshift;
 	nsect = blk_rq_cur_bytes(req) >> tr->blkshift;
@@ -68,12 +70,17 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
+		rq_for_each_segment(bvec, req, iter)
+			flush_dcache_page(bvec->bv_page);
 		return 0;
 
 	case WRITE:
 		if (!tr->writesect)
 			return -EIO;
 
+		rq_for_each_segment(bvec, req, iter)
+			flush_dcache_page(bvec->bv_page);
+		
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
#1 lore raw
Quoted 31 lines · On Wed, 18 Nov 2009 17:08:10 +0300 Ilya Loginov <[email protected]> wrote:

Mtdblock driver doesn't call flush_dcache_page for pages in request. This may cause problem on architectures where icache doesn't fill from
dcache or with dcache aliases.
This patch resolves this issue.

---
mtd_blkdevs.c | 7 +++++++

1 file changed, 7 insertions(+)
drivers/mtd/mtd_blkdevs.c +4 -0
index 7baba40..59d5d25 100644
@@ -46,6 +46,8 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 {
 	unsigned long block, nsect;
 	char *buf;
+	struct req_iterator iter;
+	struct bio_vec *bvec;
 
 	block = blk_rq_pos(req) << 9 >> tr->blkshift;
 	nsect = blk_rq_cur_bytes(req) >> tr->blkshift;
@@ -68,12 +70,17 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
+		rq_for_each_segment(bvec, req, iter)
+			flush_dcache_page(bvec->bv_page);
 		return 0;
 

drivers/mtd/mtd_blkdevs.c static int do_blktrans_request(struct mtd_blktrans_ops *tr, · line 86

Quoted 10 lines
drivers/mtd/mtd_blkdevs.c +3 -0
 	case WRITE:
 		if (!tr->writesect)
 			return -EIO;
 
+		rq_for_each_segment(bvec, req, iter)
+			flush_dcache_page(bvec->bv_page);
+		
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->writesect(dev, block, buf))
 				return -EIO;

Please see the recent linux-kernel thread "prevent AoE causing cache aliases".

Your patch fixes bascially the same problem in MTD as we have in AOE. And it introduces the same problem as well - pointless empty cache-thrashing loops on architectures for which flush_dcache_page() is a no-op.

What would be better here would be for block core to add a new rq_flush_dcache_pages() and bio_flush_dcache_pages() which the drivers can call. Those functions would be a no-op on architectures which don't need them.

Jens has made noises about implementing this, but he is working on his suntan this week.

#2 lore raw
Quoted 9 lines · On Fri, 20 Nov 2009 16:37:51 -0800 Andrew Morton <[email protected]>…

Your patch fixes bascially the same problem in MTD as we have in AOE. And it introduces the same problem as well - pointless empty cache-thrashing loops on architectures for which flush_dcache_page() is a no-op.

What would be better here would be for block core to add a new rq_flush_dcache_pages() and bio_flush_dcache_pages() which the drivers can call. Those functions would be a no-op on architectures which don't need them.

Do you mean something like this?

in include/linux/bio.h

#ifdef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS extern void bio_flush_dcache_pages(struct bio *bi); #else
static inline void bio_flush_dcache_pages(struct bio *bi) {
}
#endif /* SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS */

in fs/bio.c

void bio_flush_dcache_pages(struct bio *bi)

{
	int i;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, bio, i)
		flush_dcache_page(bvec->bv_page);
}

in include/linux/blkdev.h

#ifdef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS extern void rq_flush_dcache_pages(struct request *rq); #else
static inline void rq_flush_dcache_pages(struct request *rq) {
}
#endif

in block/blk-core.c

void rq_flush_dcache_pages(struct request *rq)

{
	struct req_iterator iter;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, bio, iter)
		flush_dcache_page(bvec->bv_page);
}

And SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS should be defined in Kconfigs for each architecture that requires this fix. I think this is good solution and if you think the same I can create the patch.

Signature · 1 line
Ilya Loginov <[email protected]>
#3 lore raw
Quoted 57 lines · On Sat, 21 Nov 2009 17:04:37 +0300 Ilya Loginov <[email protected]> wrote:
Quoted 9 lines · On Fri, 20 Nov 2009 16:37:51 -0800 Andrew Morton <[email protected]>…

Your patch fixes bascially the same problem in MTD as we have in AOE. And it introduces the same problem as well - pointless empty cache-thrashing loops on architectures for which flush_dcache_page() is a no-op.

What would be better here would be for block core to add a new rq_flush_dcache_pages() and bio_flush_dcache_pages() which the drivers can call. Those functions would be a no-op on architectures which don't need them.

Do you mean something like this?

in include/linux/bio.h

#ifdef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS extern void bio_flush_dcache_pages(struct bio *bi); #else
static inline void bio_flush_dcache_pages(struct bio *bi) {
}
#endif /* SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS */

in fs/bio.c

void bio_flush_dcache_pages(struct bio *bi)

{
	int i;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, bio, i)
		flush_dcache_page(bvec->bv_page);
}

in include/linux/blkdev.h

#ifdef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS extern void rq_flush_dcache_pages(struct request *rq); #else
static inline void rq_flush_dcache_pages(struct request *rq) {
}
#endif

in block/blk-core.c

void rq_flush_dcache_pages(struct request *rq)

{
	struct req_iterator iter;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, bio, iter)
		flush_dcache_page(bvec->bv_page);
}
Quoted 2 lines

And SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS should be defined in Kconfigs for each architecture that requires this fix.

yep, that would work.

The one somewhat fragile thing is that we'll end up in a situation where an architecture could implement a real flush_dcache_page(), but would forget to set SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS. Or vice versa. To make things reliable it would be good to cause a compilation failure in that case.

One way of addressing this is to

- change every arch/*/include/asm/cacheflush.h to include asm-generic/cacheflush.h

- put #ifndef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS wrappers around all content in asm-generic/cacheflush

So it the above mistake happens, we'll get lots of duplicated definitions, or no definitions at all (I think).

Quoted 3 lines

I think
this is good solution and if you think the same I can create the patch.

Thanks.

#4 lore raw
Quoted 5 lines

The one somewhat fragile thing is that we'll end up in a situation where an architecture could implement a real flush_dcache_page(), but would forget to set SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS. Or vice versa. To make things reliable it would be good to cause a compilation failure in that case.

Yes, I do understand this.

Quoted 10 lines

One way of addressing this is to

- change every arch/*/include/asm/cacheflush.h to include asm-generic/cacheflush.h

- put #ifndef SOMETHING_LIKE_CONFIG_CPU_HAS_DCACHE_ALIAS wrappers around all content in asm-generic/cacheflush

So it the above mistake happens, we'll get lots of duplicated definitions, or no definitions at all (I think).

Actually I don't think that it is the best solution. Let me explain.

1) The problem is that flush_dcache_page is defined for a bunch of different architectures. (x86, ia64, etc). But in most of the cases flush_dcache_page is empty, but should be defined anyway. Just see the review:

h8300 -- empty. All cache defines like asm-generic, but worse
(without do {} while(0)).
blackfin -- empty for architectures which do not define
CONFIG_BFIN_EXTMEM_WRITEBACK or CONFIG_BFIN_L2_WRITEBACK.
frv
x86 -- empty. All cache defines like asm-generic, but it was
implemented throught inline.

	ia64
	sh -- in case if ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE was defined

most flash operations are empty, but there no this define anywhere in kernel.
alpha -- empty, like most cache operations.
avr32 -- empty. But many other operations are defined. arm
sparc
powerpc
m32r -- empty for all chips, like most kernel operations. microblaze -- empty.
cris -- empty. cacheflush is equal to asm-generic, except
define change_page_attr function.
s390 -- empty. cacheflush is equal to asm-generic, except
define kernel_map_pages function if CONFIG_DEBUG_PAGEALLOC was defined.
mips -- different for different boards and architectures. parisc
mn10300 -- empty. But there are functions like
mn10300_dcache_flush_page. I think this is bad.
m68k -- empty if __uClinux__ is using.
xtensa -- empty if DCACHE_WAY_SIZE < PAGE_SIZE

So you see, it is a real mess. Only in 8 of 20 architectures this call don't empty!

2) In the asm-generic/cacheflush.h also was defined a lot of functions that could have a conflict and we don't want to have this conflict anyway. So we will meet here the same problem that was described in you letter:

Quoted 2 lines

we'll get lots of duplicated
definitions, or no definitions at all

3) I want to mention that flush_dcache_page depends on the type of process and chipset as well, so in order to make such things workable developers usually set different flags in Kconfig. For example SYS_HAS_EARLY_PRINTK or DMA_NONCOHERENT. And this is the most effective way of doing this, as far as I see this.

I've just checked most of the places in the kernel where flush_dcache_page is used. See the summary:

1)
drivers/staging/rspiusb/rspiusb.c

for (i = 0; i < pdx->maplist_numPagesMapped[frameInfo]; i++)

	flush_dcache_page(maplist_p[i]);

2)(is equal to 3))
fs/reiserfs/super.c
fs/reiserfs/inode.c
fs/ufs/super.c
fs/ext2/super.c
fs/nilfs2/mdt.c
fs/jfs/super.c
fs/ocfs2/quota_global.c
fs/ext3/super.c
fs/ext4/super.c

This operation is executed into a loop (big enought). flush_dcache_page(bh->b_page);

3)
in all other cases there is

flush_dcache_page(page);

4)*
fs/bio.c
mm/bounce.c
net/sunrpc/xprtrdma/rpc_rdma.c

These files call flush_dcache_page in bio_for_each_segment. But there are another work. So we have no pointless empty loops.

I think we should select SYS_HAS_FLUSH_DCACHE_PAGE for those architectures which requires it(to fix the bug) (and implement empty flush_dcache_page throught inline like in x86(to avoid pointless do {} while(0))).

What do you think about this?

Signature · 1 line
Ilya Loginov <[email protected]>
#5 lore raw
Quoted 6 lines · On Sun, 22 Nov 2009 02:11:28 +0300 Ilya Loginov <[email protected]> wrote:

I think we should select SYS_HAS_FLUSH_DCACHE_PAGE for those architectures which requires it(to fix the bug) (and implement empty flush_dcache_page throught inline like in x86(to avoid pointless do {} while(0))).

What do you think about this?

Well, rather that defining CONFIG_SYS_HAS_FLUSH_DCACHE_PAGE in Kconfig (which is what I think your were thinking of), we could do:

arch/x86/include/asm/cacheflush.h renamed from arch/x86/include/asm/cacheflush.h~a +1 -0
@@ -13,6 +13,7 @@ static inline void flush_cache_range(str
 static inline void flush_cache_page(struct vm_area_struct *vma,
 				    unsigned long vmaddr, unsigned long pfn) { }
 static inline void flush_dcache_page(struct page *page) { }
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 static inline void flush_dcache_mmap_lock(struct address_space *mapping) { }
 static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { }
 static inline void flush_icache_range(unsigned long start,
arch/arm/include/asm/cacheflush.h renamed from arch/arm/include/asm/cacheflush.h~a +1 -0
@@ -409,6 +409,7 @@ extern void flush_ptrace_access(struct v
  * See update_mmu_cache for the user space part.
  */
 extern void flush_dcache_page(struct page *);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 
 extern void __flush_dcache_page(struct address_space *mapping, struct page *page);
 

(etc)

And then, in a .c file:

#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
#error "you lose"
#endif

and, of course:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
<implement real code>
#else
<implement empty stubs>
#endif

This way

a) the definition site for ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE is right next to the definition site for flush_dcache_page(), instead of being in some random remote file and

b) people can't forget to implement ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE.

Generally we prefer to avoid defining ARCH_HAS_FOO in header files and we prefer to control the definition in Kconfig. But it sounds like we have a special case here..

#6 lore raw
Quoted 21 lines

And then, in a .c file:

#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
#error "you lose"
#endif

and, of course:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
<implement real code>
#else
<implement empty stubs>
#endif

This way

a) the definition site for ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE is right next to the definition site for flush_dcache_page(), instead of being in some random remote file and

Quoted 7 lines

b) people can't forget to implement ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE.

Generally we prefer to avoid defining ARCH_HAS_FOO in header files and we prefer to control the definition in Kconfig. But it sounds like we have a special case here..

I agree. I think this is the best way. I will rewrite the patch. Thank you!

Signature · 1 line
Ilya Loginov <[email protected]>
#7 lore raw
In reply to Andrew Morton

What do you think about this version of patch?
Is it good enought?

---
 arch/alpha/include/asm/cacheflush.h         |    1 +
 arch/arm/include/asm/cacheflush.h           |    1 +
 arch/avr32/include/asm/cacheflush.h         |    1 +
 arch/blackfin/include/asm/cacheflush.h      |    2 ++
 arch/cris/include/asm/cacheflush.h          |    1 +
 arch/frv/include/asm/cacheflush.h           |    1 +
 arch/h8300/include/asm/cacheflush.h         |    1 +
 arch/ia64/include/asm/cacheflush.h          |    1 +
 arch/m32r/include/asm/cacheflush.h          |    3 +++
 arch/m68k/include/asm/cacheflush_mm.h       |    1 +
 arch/m68k/include/asm/cacheflush_no.h       |    1 +
 arch/microblaze/include/asm/cacheflush.h    |    1 +
 arch/mips/include/asm/cacheflush.h          |    1 +
 arch/mn10300/include/asm/cacheflush.h       |    1 +
 arch/parisc/include/asm/cacheflush.h        |    1 +
 arch/powerpc/include/asm/cacheflush.h       |    1 +
 arch/s390/include/asm/cacheflush.h          |    1 +
 arch/sh/include/asm/cacheflush.h            |    1 +
 arch/sh/include/cpu-common/cpu/cacheflush.h |    1 +
 arch/sh/include/cpu-sh2a/cpu/cacheflush.h   |    1 +
 arch/sh/include/cpu-sh3/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh4/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh5/cpu/cacheflush.h    |    1 +
 arch/sparc/include/asm/cacheflush_32.h      |    1 +
 arch/sparc/include/asm/cacheflush_64.h      |    1 +
 arch/x86/include/asm/cacheflush.h           |    1 +
 arch/xtensa/include/asm/cacheflush.h        |    2 ++
 drivers/mtd/mtd_blkdevs.c                   |    2 ++
 include/linux/bio.h                         |   19 +++++++++++++++++++
 include/linux/blkdev.h                      |   18 ++++++++++++++++++
 30 files changed, 70 insertions(+)
(quoted diff) +0 -0

b/arch/alpha/include/asm/cacheflush.h index b686cc7..01d71e1 100644

arch/alpha/include/asm/cacheflush.h +1 -0
@@ -9,6 +9,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/arm/include/asm/cacheflush.h index 1a711ea..2420f91 100644

arch/arm/include/asm/cacheflush.h +0 -0
@@ -408,6 +408,7 @@ extern void flush_ptrace_access(struct

vm_area_struct *vma, struct page *page,
* about to change to user space. This is the same method as used on
SPARC64.
* See update_mmu_cache for the user space part.
*/
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
extern void flush_dcache_page(struct page *);

extern void __flush_dcache_page(struct address_space *mapping, struct
page *page); diff --git a/arch/avr32/include/asm/cacheflush.h b/arch/avr32/include/asm/cacheflush.h index 6706747..96e5382 100644

arch/avr32/include/asm/cacheflush.h +0 -0
@@ -107,6 +107,7 @@ extern void flush_icache_page(struct vm_area_struct

*vma, struct page *page);
* do something here, but only for certain configurations. No such
* configurations exist at this time.
*/
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
#define flush_dcache_page(page) do { } while (0)
#define flush_dcache_mmap_lock(page) do { } while (0)
#define flush_dcache_mmap_unlock(page) do { } while (0)

(quoted diff) +0 -0

b/arch/blackfin/include/asm/cacheflush.h index 7e55549..0a7d14b 100644

arch/blackfin/include/asm/cacheflush.h +0 -0
@@ -89,9 +89,11 @@ do { memcpy(dst, src,

len); \ #endif
#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined
(CONFIG_BFIN_L2_WRITEBACK) # define flush_dcache_range
(start,end) blackfin_dcache_flush_range((start), (end))
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 # define flush_dcache_page
(page) blackfin_dflush_page(page_address(page)) #else

 # define flush_dcache_range(start,end)		do { } while (0)
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 # define flush_dcache_page(page)		do { } while (0)
 #endif
(quoted diff) +0 -0

b/arch/cris/include/asm/cacheflush.h index cf60e3f..36795bc 100644

arch/cris/include/asm/cacheflush.h +1 -0
@@ -12,6 +12,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/frv/include/asm/cacheflush.h index 432a69e..edbac54 100644

arch/frv/include/asm/cacheflush.h +1 -0
@@ -47,6 +47,7 @@ static inline void __flush_cache_all(void)
 }
 
 /* dcache/icache coherency... */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #ifdef CONFIG_MMU
 extern void flush_dcache_page(struct page *page);
 #else
(quoted diff) +0 -0

b/arch/h8300/include/asm/cacheflush.h index 5ffdca2..4cf2df2 100644

arch/h8300/include/asm/cacheflush.h +1 -0
@@ -15,6 +15,7 @@
 #define	flush_cache_dup_mm(mm)		do { } while (0)
 #define	flush_cache_range(vma,a,b)
 #define	flush_cache_page(vma,p,pfn)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define	flush_dcache_page(page)
 #define	flush_dcache_mmap_lock(mapping)
 #define	flush_dcache_mmap_unlock(mapping)
(quoted diff) +0 -0

b/arch/ia64/include/asm/cacheflush.h index c8ce271..429eefc 100644

arch/ia64/include/asm/cacheflush.h +1 -0
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			\
 do {						\
 	clear_bit(PG_arch_1, &(page)->flags);	\
(quoted diff) +0 -0

b/arch/m32r/include/asm/cacheflush.h index 78587c9..8e8e045 100644

arch/m32r/include/asm/cacheflush.h +3 -0
@@ -12,6 +12,7 @@ extern void _flush_cache_copyback_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -33,6 +34,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -46,6 +48,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/m68k/include/asm/cacheflush_mm.h index 16bf375..73de7c8 100644

arch/m68k/include/asm/cacheflush_mm.h +1 -0
@@ -128,6 +128,7 @@ static inline void __flush_page_to_ram(void *vaddr)
 	}
 }
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)		__flush_page_to_ram

(page_address(page)) #define flush_dcache_mmap_lock
(mapping) do { } while (0) #define
flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git
a/arch/m68k/include/asm/cacheflush_no.h b/arch/m68k/include/asm/cacheflush_no.h index c65f00a..89f1956 100644

arch/m68k/include/asm/cacheflush_no.h +0 -0
@@ -12,6 +12,7 @@
 #define flush_cache_range(vma, start, end)	__flush_cache_all()
 #define flush_cache_page(vma, vmaddr)		do { } while (0)
 #define flush_dcache_range(start,len)		__flush_cache_all

() +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
#define flush_dcache_page(page) do { } while (0)
#define flush_dcache_mmap_lock(mapping) do { } while (0)
#define flush_dcache_mmap_unlock(mapping) do { } while (0)

(quoted diff) +0 -0

b/arch/microblaze/include/asm/cacheflush.h index f989d6a..088076e 100644

arch/microblaze/include/asm/cacheflush.h +0 -0
@@ -37,6 +37,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
 
 #define flush_dcache_range(start, end)	__invalidate_dcache_range

(start, end) +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
#define flush_dcache_page(page) do { } while (0)
#define flush_dcache_mmap_lock(mapping) do { } while (0)
#define flush_dcache_mmap_unlock(mapping) do { } while (0)

(quoted diff) +0 -0

b/arch/mips/include/asm/cacheflush.h index 03b1d69..40bb9fd 100644

arch/mips/include/asm/cacheflush.h +0 -0
@@ -38,6 +38,7 @@ extern void (*flush_cache_range)(struct

vm_area_struct *vma, extern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn); extern void __flush_dcache_page(struct page *page);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
static inline void flush_dcache_page(struct page *page) {
if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)

(quoted diff) +0 -0

b/arch/mn10300/include/asm/cacheflush.h index 2db746a..4a15067 100644

arch/mn10300/include/asm/cacheflush.h +1 -0
@@ -26,6 +26,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do {} while (0)
 #define flush_cache_vmap(start, end)		do {} while (0)
 #define flush_cache_vunmap(start, end)		do {} while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do {} while (0)
 #define flush_dcache_mmap_lock(mapping)		do {} while (0)
 #define flush_dcache_mmap_unlock(mapping)	do {} while (0)
(quoted diff) +0 -0

b/arch/parisc/include/asm/cacheflush.h index 7243951..7a73b61 100644

arch/parisc/include/asm/cacheflush.h +1 -0
@@ -42,6 +42,7 @@ void flush_cache_mm(struct mm_struct *mm);
 #define flush_cache_vmap(start, end)		flush_cache_all()
 #define flush_cache_vunmap(start, end)		flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_dcache_mmap_lock(mapping) \
(quoted diff) +0 -0

b/arch/powerpc/include/asm/cacheflush.h index ba667a3..ab9e402 100644

arch/powerpc/include/asm/cacheflush.h +1 -0
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/s390/include/asm/cacheflush.h index 49d5af9..405cc97 100644

arch/s390/include/asm/cacheflush.h +1 -0
@@ -10,6 +10,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/sh/include/asm/cacheflush.h index 4c5462d..46ba64c 100644

arch/sh/include/asm/cacheflush.h +1 -0
@@ -16,6 +16,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_icache_range(start, end)		do { } while (0)
 #define flush_icache_page(vma,pg)		do { } while (0)
(quoted diff) +0 -0

b/arch/sh/include/cpu-common/cpu/cacheflush.h index c3db00b..bd508bd 100644

arch/sh/include/cpu-common/cpu/cacheflush.h +1 -0
@@ -31,6 +31,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/sh/include/cpu-sh2a/cpu/cacheflush.h index 3d3b920..56c8c88 100644

arch/sh/include/cpu-sh2a/cpu/cacheflush.h +1 -0
@@ -22,6 +22,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
(quoted diff) +0 -0

b/arch/sh/include/cpu-sh3/cpu/cacheflush.h index 1ac27aa..e03e964 100644

arch/sh/include/cpu-sh3/cpu/cacheflush.h +0 -0
@@ -26,6 +26,7 @@ void flush_cache_mm(struct mm_struct *mm);
 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
                               unsigned long end);
 void flush_cache_page(struct vm_area_struct *vma, unsigned long addr,

unsigned long pfn); +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
void flush_dcache_page(struct page *pg);
void flush_icache_range(unsigned long start, unsigned long end); void flush_icache_page(struct vm_area_struct *vma, struct page *page);

(quoted diff) +0 -0

b/arch/sh/include/cpu-sh4/cpu/cacheflush.h index 065306d..1789e3e 100644

arch/sh/include/cpu-sh4/cpu/cacheflush.h +0 -0
@@ -24,6 +24,7 @@ void flush_cache_range(struct vm_area_struct *vma,

unsigned long start, unsigned long end);
void flush_cache_page(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
void flush_dcache_page(struct page *pg);

#define flush_dcache_mmap_lock(mapping) do { } while (0)

(quoted diff) +0 -0

b/arch/sh/include/cpu-sh5/cpu/cacheflush.h index 5a11f0b..cd098a3 100644

arch/sh/include/cpu-sh5/cpu/cacheflush.h +0 -0
@@ -13,6 +13,7 @@ extern void flush_cache_sigtramp(unsigned long vaddr);
 extern void flush_cache_range(struct vm_area_struct *vma, unsigned

long start, unsigned long end);
extern void flush_cache_page(struct vm_area_struct *vma, unsigned long
addr, unsigned long pfn); +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
extern void flush_dcache_page(struct page *pg);
extern void flush_icache_range(unsigned long start, unsigned long end); extern void flush_icache_user_range(struct vm_area_struct *vma,

(quoted diff) +0 -0

b/arch/sparc/include/asm/cacheflush_32.h index 68ac109..2e46877 100644

arch/sparc/include/asm/cacheflush_32.h +0 -0
@@ -75,6 +75,7 @@ BTFIXUPDEF_CALL(void, flush_sig_insns, struct

mm_struct *, unsigned long)
extern void sparc_flush_page_to_ram(struct page *page);

+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
#define flush_dcache_page(page)
sparc_flush_page_to_ram(page) #define flush_dcache_mmap_lock
(mapping) do { } while (0) #define
flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git
a/arch/sparc/include/asm/cacheflush_64.h b/arch/sparc/include/asm/cacheflush_64.h index c433217..b953840 100644

arch/sparc/include/asm/cacheflush_64.h +0 -0
@@ -37,6 +37,7 @@ extern void flush_dcache_page_all(struct mm_struct

*mm, struct page *page); #endif

extern void __flush_dcache_range(unsigned long start, unsigned long
end); +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
extern void flush_dcache_page(struct page *page);

#define flush_icache_page(vma, pg) do { } while(0)

(quoted diff) +0 -0

b/arch/x86/include/asm/cacheflush.h index e55dfc1..7631500 100644

arch/x86/include/asm/cacheflush.h +0 -0
@@ -12,6 +12,7 @@ static inline void flush_cache_range(struct

vm_area_struct *vma, unsigned long start, unsigned long end) { }
static inline void flush_cache_page(struct vm_area_struct *vma,
unsigned long vmaddr, unsigned
long pfn) { } +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
static inline void flush_dcache_page(struct page *page) { } static inline void flush_dcache_mmap_lock(struct address_space
*mapping) { } static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { } diff --git a/arch/xtensa/include/asm/cacheflush.h b/arch/xtensa/include/asm/cacheflush.h index b7b8fbe..376cd9d 100644

arch/xtensa/include/asm/cacheflush.h +0 -0
@@ -101,6 +101,7 @@ static inline void __invalidate_icache_page_alias

(unsigned long virt, #define flush_cache_vmap(start,end) flush_cache_all() #define flush_cache_vunmap(start,end) flush_cache_all()
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
extern void flush_dcache_page(struct page*);
extern void flush_cache_range(struct vm_area_struct*, ulong, ulong); extern void flush_cache_page(struct vm_area_struct*, unsigned long,
unsigned long); @@ -114,6 +115,7 @@ extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned lon #define flush_cache_vmap
(start,end) do { } while (0) #define
flush_cache_vunmap(start,end) do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
#define flush_dcache_page(page) do { }
while (0)
#define flush_cache_page(vma,addr,pfn) do { }
while (0) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 7baba40..abddc60 100644

drivers/mtd/mtd_blkdevs.c +0 -0
@@ -68,12 +68,14 @@ static int do_blktrans_request(struct

mtd_blktrans_ops *tr, for (; nsect > 0; nsect--, block++, buf += tr->blksize) if (tr->readsect(dev, block, buf))
return -EIO;
+ rq_flush_dcache_pages(req);
return 0;

case WRITE:
if (!tr->writesect)
return -EIO;

+ rq_flush_dcache_pages(req);
for (; nsect > 0; nsect--, block++, buf += tr->blksize)
if (tr->writesect(dev, block, buf))
return -EIO;

include/linux/bio.h +0 -0
index 2892b71..ecafedc 100644
@@ -396,6 +396,25 @@ extern struct bio *bio_copy_kern(struct

request_queue *, void *, unsigned int, gfp_t, int);
extern void bio_set_pages_dirty(struct bio *bio); extern void bio_check_pages_dirty(struct bio *bio);
+
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error "You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
for your platform." +#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void bio_flush_dcache_pages(struct bio *bi) +{
+ int i;
+ struct bio_vec* bvec;
+
+ bio_for_each_segment(bvec, bi, i)
+ flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void bio_flush_dcache_pages(struct bio *bi) +{
+}
+#endif
+
extern struct bio *bio_copy_user(struct request_queue *, struct
rq_map_data *, unsigned long, unsigned int, int, gfp_t);
extern struct bio *bio_copy_user_iov(struct request_queue *,

include/linux/blkdev.h +2 -0
index 69103e0..9b5214c 100644
@@ -740,6 +740,24 @@ struct req_iterator {
 #define rq_iter_last(rq, _iter)
\ (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE

for your platform." +#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void rq_flush_dcache_pages(struct request *rq) +{
+ struct req_iterator iter;
+ struct bio_vec* bvec;
+
+ rq_for_each_segment(bvec, rq, iter)
+ flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void rq_flush_dcache_pages(struct request *rq) +{
+}
+#endif
+
extern int blk_register_queue(struct gendisk *disk); extern void blk_unregister_queue(struct gendisk *disk); extern void register_disk(struct gendisk *dev);

#8 lore raw
Quoted 5 lines · Ilya Loginov

+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
#define flush_dcache_page(page) do { } while (0)
#define flush_dcache_mmap_lock(mapping) do { } while (0)
#define flush_dcache_mmap_unlock(mapping) do { } while (0)

The thing is, having a function called flush_dcache_page() which doesn't actually flush a page of the dcache is just blatantly stupid.

It's misnamed -- it should probably be called something like 'flush_valiased_dcache_page()' or 'unalias_dcache_page()' instead, since I believe it's only supposed to cope with aliasing issues with virtually indexed caches.

If you're talking about _extending_ the existing silly name to a new ARCH_IMPLEMENTS_FOO macro or Kconfig option, perhaps this would be a good time to fix the nomenclature, rather than propagating the error?

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#10 lore raw
In reply to Ilya Loginov
Quoted 28 lines · Ilya Loginov

What do you think about this version of patch?
Is it good enought?

---
 arch/alpha/include/asm/cacheflush.h         |    1 +
 arch/arm/include/asm/cacheflush.h           |    1 +
 arch/avr32/include/asm/cacheflush.h         |    1 +
 arch/blackfin/include/asm/cacheflush.h      |    2 ++
 arch/cris/include/asm/cacheflush.h          |    1 +
 arch/frv/include/asm/cacheflush.h           |    1 +
 arch/h8300/include/asm/cacheflush.h         |    1 +
 arch/ia64/include/asm/cacheflush.h          |    1 +
 arch/m32r/include/asm/cacheflush.h          |    3 +++
 arch/m68k/include/asm/cacheflush_mm.h       |    1 +
 arch/m68k/include/asm/cacheflush_no.h       |    1 +
 arch/microblaze/include/asm/cacheflush.h    |    1 +
 arch/mips/include/asm/cacheflush.h          |    1 +
 arch/mn10300/include/asm/cacheflush.h       |    1 +
 arch/parisc/include/asm/cacheflush.h        |    1 +
 arch/powerpc/include/asm/cacheflush.h       |    1 +
 arch/s390/include/asm/cacheflush.h          |    1 +
 arch/sh/include/asm/cacheflush.h            |    1 +
 arch/sh/include/cpu-common/cpu/cacheflush.h |    1 +
 arch/sh/include/cpu-sh2a/cpu/cacheflush.h   |    1 +
 arch/sh/include/cpu-sh3/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh4/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh5/cpu/cacheflush.h    |    1 +
Quoted 8 lines
 arch/sparc/include/asm/cacheflush_32.h      |    1 +
 arch/sparc/include/asm/cacheflush_64.h      |    1 +
 arch/x86/include/asm/cacheflush.h           |    1 +
 arch/xtensa/include/asm/cacheflush.h        |    2 ++
 drivers/mtd/mtd_blkdevs.c                   |    2 ++
 include/linux/bio.h                         |   19 +++++++++++++++++++
 include/linux/blkdev.h                      |   18 ++++++++++++++++++
 30 files changed, 70 insertions(+)

patch looks mangled in the middle:

Quoted 11 lines
arch/x86/include/asm/cacheflush.h +0 -0
@@ -12,6 +12,7 @@ static inline void flush_cache_range(struct
 vm_area_struct *vma, unsigned long start, unsigned long end) { }
 static inline void flush_cache_page(struct vm_area_struct *vma,
 				    unsigned long vmaddr, unsigned

long pfn) { } +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
static inline void flush_dcache_page(struct page *page) { } static inline void flush_dcache_mmap_lock(struct address_space
*mapping) { } static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { } diff --git

Ingo

#11 lore raw
Quoted 1 line

patch looks mangled in the middle:

Oh, yeah. Thank you! I've changed my e-mail client preferences yesturday. This was bad idea...

This is right version.

---
 arch/alpha/include/asm/cacheflush.h         |    1 +
 arch/arm/include/asm/cacheflush.h           |    1 +
 arch/avr32/include/asm/cacheflush.h         |    1 +
 arch/blackfin/include/asm/cacheflush.h      |    2 ++
 arch/cris/include/asm/cacheflush.h          |    1 +
 arch/frv/include/asm/cacheflush.h           |    1 +
 arch/h8300/include/asm/cacheflush.h         |    1 +
 arch/ia64/include/asm/cacheflush.h          |    1 +
 arch/m32r/include/asm/cacheflush.h          |    3 +++
 arch/m68k/include/asm/cacheflush_mm.h       |    1 +
 arch/m68k/include/asm/cacheflush_no.h       |    1 +
 arch/microblaze/include/asm/cacheflush.h    |    1 +
 arch/mips/include/asm/cacheflush.h          |    1 +
 arch/mn10300/include/asm/cacheflush.h       |    1 +
 arch/parisc/include/asm/cacheflush.h        |    1 +
 arch/powerpc/include/asm/cacheflush.h       |    1 +
 arch/s390/include/asm/cacheflush.h          |    1 +
 arch/sh/include/asm/cacheflush.h            |    1 +
 arch/sh/include/cpu-common/cpu/cacheflush.h |    1 +
 arch/sh/include/cpu-sh2a/cpu/cacheflush.h   |    1 +
 arch/sh/include/cpu-sh3/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh4/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh5/cpu/cacheflush.h    |    1 +
 arch/sparc/include/asm/cacheflush_32.h      |    1 +
 arch/sparc/include/asm/cacheflush_64.h      |    1 +
 arch/x86/include/asm/cacheflush.h           |    1 +
 arch/xtensa/include/asm/cacheflush.h        |    2 ++
 drivers/mtd/mtd_blkdevs.c                   |    2 ++
 include/linux/bio.h                         |   19 +++++++++++++++++++
 include/linux/blkdev.h                      |   18 ++++++++++++++++++
 30 files changed, 70 insertions(+)
arch/alpha/include/asm/cacheflush.h +1 -0
index b686cc7..01d71e1 100644
@@ -9,6 +9,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/arm/include/asm/cacheflush.h +1 -0
index 1a711ea..2420f91 100644
@@ -408,6 +408,7 @@ extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  * about to change to user space.  This is the same method as used on SPARC64.
  * See update_mmu_cache for the user space part.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *);
 
 extern void __flush_dcache_page(struct address_space *mapping, struct page *page);
arch/avr32/include/asm/cacheflush.h +1 -0
index 6706747..96e5382 100644
@@ -107,6 +107,7 @@ extern void flush_icache_page(struct vm_area_struct *vma, struct page *page);
  * do something here, but only for certain configurations.  No such
  * configurations exist at this time.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(page)		do { } while (0)
 #define flush_dcache_mmap_unlock(page)		do { } while (0)
arch/blackfin/include/asm/cacheflush.h +2 -0
index 7e55549..0a7d14b 100644
@@ -89,9 +89,11 @@ do { memcpy(dst, src, len);						\
 #endif
 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
 # define flush_dcache_range(start,end)		blackfin_dcache_flush_range((start), (end))
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 # define flush_dcache_page(page)		blackfin_dflush_page(page_address(page))
 #else
 # define flush_dcache_range(start,end)		do { } while (0)
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 # define flush_dcache_page(page)		do { } while (0)
 #endif
 
arch/cris/include/asm/cacheflush.h +1 -0
index cf60e3f..36795bc 100644
@@ -12,6 +12,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/frv/include/asm/cacheflush.h +1 -0
index 432a69e..edbac54 100644
@@ -47,6 +47,7 @@ static inline void __flush_cache_all(void)
 }
 
 /* dcache/icache coherency... */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #ifdef CONFIG_MMU
 extern void flush_dcache_page(struct page *page);
 #else
arch/h8300/include/asm/cacheflush.h +1 -0
index 5ffdca2..4cf2df2 100644
@@ -15,6 +15,7 @@
 #define	flush_cache_dup_mm(mm)		do { } while (0)
 #define	flush_cache_range(vma,a,b)
 #define	flush_cache_page(vma,p,pfn)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define	flush_dcache_page(page)
 #define	flush_dcache_mmap_lock(mapping)
 #define	flush_dcache_mmap_unlock(mapping)
arch/ia64/include/asm/cacheflush.h +1 -0
index c8ce271..429eefc 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			\
 do {						\
 	clear_bit(PG_arch_1, &(page)->flags);	\
arch/m32r/include/asm/cacheflush.h +3 -0
index 78587c9..8e8e045 100644
@@ -12,6 +12,7 @@ extern void _flush_cache_copyback_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -33,6 +34,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -46,6 +48,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_mm.h +1 -0
index 16bf375..73de7c8 100644
@@ -128,6 +128,7 @@ static inline void __flush_page_to_ram(void *vaddr)
 	}
 }
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)		__flush_page_to_ram(page_address(page))
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_no.h +1 -0
index c65f00a..89f1956 100644
@@ -12,6 +12,7 @@
 #define flush_cache_range(vma, start, end)	__flush_cache_all()
 #define flush_cache_page(vma, vmaddr)		do { } while (0)
 #define flush_dcache_range(start,len)		__flush_cache_all()
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/microblaze/include/asm/cacheflush.h +1 -0
index f989d6a..088076e 100644
@@ -37,6 +37,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
 
 #define flush_dcache_range(start, end)	__invalidate_dcache_range(start, end)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/mips/include/asm/cacheflush.h +1 -0
index 03b1d69..40bb9fd 100644
@@ -38,6 +38,7 @@ extern void (*flush_cache_range)(struct vm_area_struct *vma,
 extern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn);
 extern void __flush_dcache_page(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 static inline void flush_dcache_page(struct page *page)
 {
 	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)
arch/mn10300/include/asm/cacheflush.h +1 -0
index 2db746a..4a15067 100644
@@ -26,6 +26,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do {} while (0)
 #define flush_cache_vmap(start, end)		do {} while (0)
 #define flush_cache_vunmap(start, end)		do {} while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do {} while (0)
 #define flush_dcache_mmap_lock(mapping)		do {} while (0)
 #define flush_dcache_mmap_unlock(mapping)	do {} while (0)
arch/parisc/include/asm/cacheflush.h +1 -0
index 7243951..7a73b61 100644
@@ -42,6 +42,7 @@ void flush_cache_mm(struct mm_struct *mm);
 #define flush_cache_vmap(start, end)		flush_cache_all()
 #define flush_cache_vunmap(start, end)		flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_dcache_mmap_lock(mapping) \
arch/powerpc/include/asm/cacheflush.h +1 -0
index ba667a3..ab9e402 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/s390/include/asm/cacheflush.h +1 -0
index 49d5af9..405cc97 100644
@@ -10,6 +10,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/asm/cacheflush.h +1 -0
index 4c5462d..46ba64c 100644
@@ -16,6 +16,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_icache_range(start, end)		do { } while (0)
 #define flush_icache_page(vma,pg)		do { } while (0)
arch/sh/include/cpu-common/cpu/cacheflush.h +1 -0
index c3db00b..bd508bd 100644
@@ -31,6 +31,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/cpu-sh2a/cpu/cacheflush.h +1 -0
index 3d3b920..56c8c88 100644
@@ -22,6 +22,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/cpu-sh3/cpu/cacheflush.h +1 -0
index 1ac27aa..e03e964 100644
@@ -26,6 +26,7 @@ void flush_cache_mm(struct mm_struct *mm);
 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
                               unsigned long end);
 void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 void flush_dcache_page(struct page *pg);
 void flush_icache_range(unsigned long start, unsigned long end);
 void flush_icache_page(struct vm_area_struct *vma, struct page *page);
arch/sh/include/cpu-sh4/cpu/cacheflush.h +1 -0
index 065306d..1789e3e 100644
@@ -24,6 +24,7 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
 		       unsigned long end);
 void flush_cache_page(struct vm_area_struct *vma, unsigned long addr,
 		      unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 void flush_dcache_page(struct page *pg);
 
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
arch/sh/include/cpu-sh5/cpu/cacheflush.h +1 -0
index 5a11f0b..cd098a3 100644
@@ -13,6 +13,7 @@ extern void flush_cache_sigtramp(unsigned long vaddr);
 extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
 			      unsigned long end);
 extern void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *pg);
 extern void flush_icache_range(unsigned long start, unsigned long end);
 extern void flush_icache_user_range(struct vm_area_struct *vma,
arch/sparc/include/asm/cacheflush_32.h +1 -0
index 68ac109..2e46877 100644
@@ -75,6 +75,7 @@ BTFIXUPDEF_CALL(void, flush_sig_insns, struct mm_struct *, unsigned long)
 
 extern void sparc_flush_page_to_ram(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			sparc_flush_page_to_ram(page)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sparc/include/asm/cacheflush_64.h +1 -0
index c433217..b953840 100644
@@ -37,6 +37,7 @@ extern void flush_dcache_page_all(struct mm_struct *mm, struct page *page);
 #endif
 
 extern void __flush_dcache_range(unsigned long start, unsigned long end);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_icache_page(vma, pg)	do { } while(0)
arch/x86/include/asm/cacheflush.h +1 -0
index e55dfc1..7631500 100644
@@ -12,6 +12,7 @@ static inline void flush_cache_range(struct vm_area_struct *vma,
 				     unsigned long start, unsigned long end) { }
 static inline void flush_cache_page(struct vm_area_struct *vma,
 				    unsigned long vmaddr, unsigned long pfn) { }
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 static inline void flush_dcache_page(struct page *page) { }
 static inline void flush_dcache_mmap_lock(struct address_space *mapping) { }
 static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { }
arch/xtensa/include/asm/cacheflush.h +2 -0
index b7b8fbe..376cd9d 100644
@@ -101,6 +101,7 @@ static inline void __invalidate_icache_page_alias(unsigned long virt,
 #define flush_cache_vmap(start,end)	flush_cache_all()
 #define flush_cache_vunmap(start,end)	flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page*);
 extern void flush_cache_range(struct vm_area_struct*, ulong, ulong);
 extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned long);
@@ -114,6 +115,7 @@ extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned lon
 #define flush_cache_vmap(start,end)			do { } while (0)
 #define flush_cache_vunmap(start,end)			do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)				do { } while (0)
 
 #define flush_cache_page(vma,addr,pfn)			do { } while (0)
drivers/mtd/mtd_blkdevs.c +2 -0
index 7baba40..abddc60 100644
@@ -68,12 +68,14 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
+		rq_flush_dcache_pages(req);
 		return 0;
 
 	case WRITE:
 		if (!tr->writesect)
 			return -EIO;
 
+		rq_flush_dcache_pages(req);
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
include/linux/bio.h +19 -0
index 2892b71..ecafedc 100644
@@ -396,6 +396,25 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
 				 gfp_t, int);
 extern void bio_set_pages_dirty(struct bio *bio);
 extern void bio_check_pages_dirty(struct bio *bio);
+
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+	int i;
+	struct bio_vec* bvec;
+
+	bio_for_each_segment(bvec, bi, i)
+		flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+}
+#endif
+
 extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
 				 unsigned long, unsigned int, int, gfp_t);
 extern struct bio *bio_copy_user_iov(struct request_queue *,
include/linux/blkdev.h +18 -0
index 69103e0..9b5214c 100644
@@ -740,6 +740,24 @@ struct req_iterator {
 #define rq_iter_last(rq, _iter)					\
 		(_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+	struct req_iterator iter;
+	struct bio_vec* bvec;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+}
+#endif
+
 extern int blk_register_queue(struct gendisk *disk);
 extern void blk_unregister_queue(struct gendisk *disk);
 extern void register_disk(struct gendisk *dev);
Signature · 1 line
Ilya Loginov <[email protected]>
#12 lore raw
Quoted 36 lines · On Sun, 22 Nov 2009 16:55:21 +0300 Ilya Loginov <[email protected]> wrote:
include/linux/bio.h +18 -0
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+	int i;
+	struct bio_vec* bvec;
+
+	bio_for_each_segment(bvec, bi, i)
+		flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+}
+#endif
+
 extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
 				 unsigned long, unsigned int, int, gfp_t);
 extern struct bio *bio_copy_user_iov(struct request_queue *,
include/linux/blkdev.h +7 -0
index 69103e0..9b5214c 100644
@@ -740,6 +740,24 @@ struct req_iterator {
 #define rq_iter_last(rq, _iter)					\
 		(_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+	struct req_iterator iter;

include/linux/blkdev.h struct req_iterator { · line 759

Quoted 10 lines
include/linux/blkdev.h +10 -0
+	struct bio_vec* bvec;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec->bv_page);
+}
+#else
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+}
+#endif

I don't think the non-stub versions of these should be inlined. They will generate quite a lot of code and they're pretty heavyweight. Better to implement them in block/ somewhere, and EXPORT_SYMBOL().

#9 lore raw
In reply to David Woodhouse
Quoted 2 lines · On Sun, 22 Nov 2009 09:53:50 +0000 David Woodhouse <[email protected]> wrote:

The thing is, having a function called flush_dcache_page() which doesn't actually flush a page of the dcache is just blatantly stupid.

Unfortunately, it's well-established that all architectures have these functions. Many kernel systems, for example file systems drivers (ext2, ext3, ntfs), use them.

In letter to Andrew Morton I wrote that among 20 architectures this call is not empty only for 8 of them. And it is the problem.

But some architectures really need this call. And kernel has to work reasonably with them too. Therefore it is required often to call for empty functions.

Quoted 4 lines

It's misnamed -- it should probably be called something like 'flush_valiased_dcache_page()' or 'unalias_dcache_page()' instead, since I believe it's only supposed to cope with aliasing issues with virtually indexed caches.

I don't think so. For example I had this bug on the processor, which icache don't finds for data in dcache. There was no dcache aliases.

Quoted 3 lines

If you're talking about _extending_ the existing silly name to a new ARCH_IMPLEMENTS_FOO macro or Kconfig option, perhaps this would be a good time to fix the nomenclature, rather than propagating the error?

Andrew has showed me in his first letter another topic in this mailing. It is said there that there is no reasonable infrastructure in kernel to correct such things. The first patch can fix bug in the mtd but the problem of useless cycle on many architectures is arising.

It is because there is nothing associated with the flush_dcache_page() function.

This way enable us to solve and this problem too. But I agree that it is not elegant. Have you any idea how to make it better?

Thanks!

Signature · 1 line
Ilya Loginov <[email protected]>
#13 lore raw
In reply to Andrew Morton
Quoted 3 lines · On Sun, 22 Nov 2009 10:48:16 -0800 Andrew Morton <[email protected]>…

I don't think the non-stub versions of these should be inlined. They will generate quite a lot of code and they're pretty heavyweight. Better to implement them in block/ somewhere, and EXPORT_SYMBOL().

I tried this way from the beginning, and to avoid redefinitions I enclose everything in #if #endif in *.c files. I think it is not very good. So there are two possibilities.

1. To keep it like it is now and in this way there will be quite a lot of code. But in previous letters I gave statistics on the flush_dcache_page call in a kernel. And our case is particular. There will not be generated a lot of code. Or just take away inline.

2. Or it is better to carry over normal realization to *.c file and enclose everything by one more #if #endif.

What do you consier to be better?

Signature · 1 line
Ilya Loginov <[email protected]>
#14 lore raw
Quoted 16 lines · On Sun, 22 Nov 2009 22:18:36 +0300 Ilya Loginov <[email protected]> wrote:
Quoted 3 lines · On Sun, 22 Nov 2009 10:48:16 -0800 Andrew Morton <[email protected]>…

I don't think the non-stub versions of these should be inlined. They will generate quite a lot of code and they're pretty heavyweight. Better to implement them in block/ somewhere, and EXPORT_SYMBOL().

I tried this way from the beginning, and to avoid redefinitions I enclose everything in #if #endif in *.c files. I think it is not very good. So there are two possibilities.

1. To keep it like it is now and in this way there will be quite a lot of code. But in previous letters I gave statistics on the flush_dcache_page call in a kernel. And our case is particular. There will not be generated a lot of code. Or just take away inline.

Quoted 4 lines

2. Or it is better to carry over normal realization to *.c file and enclose everything by one more #if #endif.

What do you consier to be better?

3. :)

In .h:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
extern void rq_flush_dcache_pages(struct request *rq); #else
static inline void bio_flush_dcache_pages(struct bio *bi) {
}
#endif

In .c:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
void rq_flush_dcache_pages(struct request *rq)

{
	struct req_iterator iter;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, rq, iter)
		flush_dcache_page(bvec->bv_page);
}

EXPORT_SYMBOL(rq_flush_dcache_pages);
#endif

#15 lore raw
Quoted 4 lines
Quoted 4 lines

I tried this way from the beginning, and to avoid redefinitions I enclose everything in #if #endif in *.c files. I think it is not very good. So there are two possibilities.

Ah. I think the first choice is always the best choise. =)

Quoted 21 lines

In .h:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
extern void rq_flush_dcache_pages(struct request *rq); #else
static inline void bio_flush_dcache_pages(struct bio *bi) {
}
#endif

In .c:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
void rq_flush_dcache_pages(struct request *rq)

{
	struct req_iterator iter;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, rq, iter)
		flush_dcache_page(bvec->bv_page);
}
Quoted 2 lines

EXPORT_SYMBOL(rq_flush_dcache_pages);
#endif

This is 2) =)

Thanks a lot for your help and comments!

---
 arch/alpha/include/asm/cacheflush.h         |    1 +
 arch/arm/include/asm/cacheflush.h           |    1 +
 arch/avr32/include/asm/cacheflush.h         |    1 +
 arch/blackfin/include/asm/cacheflush.h      |    2 ++
 arch/cris/include/asm/cacheflush.h          |    1 +
 arch/frv/include/asm/cacheflush.h           |    1 +
 arch/h8300/include/asm/cacheflush.h         |    1 +
 arch/ia64/include/asm/cacheflush.h          |    1 +
 arch/m32r/include/asm/cacheflush.h          |    3 +++
 arch/m68k/include/asm/cacheflush_mm.h       |    1 +
 arch/m68k/include/asm/cacheflush_no.h       |    1 +
 arch/microblaze/include/asm/cacheflush.h    |    1 +
 arch/mips/include/asm/cacheflush.h          |    1 +
 arch/mn10300/include/asm/cacheflush.h       |    1 +
 arch/parisc/include/asm/cacheflush.h        |    1 +
 arch/powerpc/include/asm/cacheflush.h       |    1 +
 arch/s390/include/asm/cacheflush.h          |    1 +
 arch/sh/include/asm/cacheflush.h            |    1 +
 arch/sh/include/cpu-common/cpu/cacheflush.h |    1 +
 arch/sh/include/cpu-sh2a/cpu/cacheflush.h   |    1 +
 arch/sh/include/cpu-sh3/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh4/cpu/cacheflush.h    |    1 +
 arch/sh/include/cpu-sh5/cpu/cacheflush.h    |    1 +
 arch/sparc/include/asm/cacheflush_32.h      |    1 +
 arch/sparc/include/asm/cacheflush_64.h      |    1 +
 arch/x86/include/asm/cacheflush.h           |    1 +
 arch/xtensa/include/asm/cacheflush.h        |    2 ++
 block/blk-core.c                            |   19 +++++++++++++++++++
 drivers/mtd/mtd_blkdevs.c                   |    2 ++
 fs/bio.c                                    |   12 ++++++++++++
 include/linux/bio.h                         |   12 ++++++++++++
 include/linux/blkdev.h                      |   11 +++++++++++
 32 files changed, 87 insertions(+)
arch/alpha/include/asm/cacheflush.h +1 -0
index b686cc7..01d71e1 100644
@@ -9,6 +9,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/arm/include/asm/cacheflush.h +1 -0
index 1a711ea..2420f91 100644
@@ -408,6 +408,7 @@ extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  * about to change to user space.  This is the same method as used on SPARC64.
  * See update_mmu_cache for the user space part.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *);
 
 extern void __flush_dcache_page(struct address_space *mapping, struct page *page);
arch/avr32/include/asm/cacheflush.h +1 -0
index 6706747..96e5382 100644
@@ -107,6 +107,7 @@ extern void flush_icache_page(struct vm_area_struct *vma, struct page *page);
  * do something here, but only for certain configurations.  No such
  * configurations exist at this time.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(page)		do { } while (0)
 #define flush_dcache_mmap_unlock(page)		do { } while (0)
arch/blackfin/include/asm/cacheflush.h +2 -0
index 7e55549..0a7d14b 100644
@@ -89,9 +89,11 @@ do { memcpy(dst, src, len);						\
 #endif
 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
 # define flush_dcache_range(start,end)		blackfin_dcache_flush_range((start), (end))
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 # define flush_dcache_page(page)		blackfin_dflush_page(page_address(page))
 #else
 # define flush_dcache_range(start,end)		do { } while (0)
+# define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 # define flush_dcache_page(page)		do { } while (0)
 #endif
 
arch/cris/include/asm/cacheflush.h +1 -0
index cf60e3f..36795bc 100644
@@ -12,6 +12,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/frv/include/asm/cacheflush.h +1 -0
index 432a69e..edbac54 100644
@@ -47,6 +47,7 @@ static inline void __flush_cache_all(void)
 }
 
 /* dcache/icache coherency... */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #ifdef CONFIG_MMU
 extern void flush_dcache_page(struct page *page);
 #else
arch/h8300/include/asm/cacheflush.h +1 -0
index 5ffdca2..4cf2df2 100644
@@ -15,6 +15,7 @@
 #define	flush_cache_dup_mm(mm)		do { } while (0)
 #define	flush_cache_range(vma,a,b)
 #define	flush_cache_page(vma,p,pfn)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define	flush_dcache_page(page)
 #define	flush_dcache_mmap_lock(mapping)
 #define	flush_dcache_mmap_unlock(mapping)
arch/ia64/include/asm/cacheflush.h +1 -0
index c8ce271..429eefc 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			\
 do {						\
 	clear_bit(PG_arch_1, &(page)->flags);	\
arch/m32r/include/asm/cacheflush.h +3 -0
index 78587c9..8e8e045 100644
@@ -12,6 +12,7 @@ extern void _flush_cache_copyback_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -33,6 +34,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -46,6 +48,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_mm.h +1 -0
index 16bf375..73de7c8 100644
@@ -128,6 +128,7 @@ static inline void __flush_page_to_ram(void *vaddr)
 	}
 }
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)		__flush_page_to_ram(page_address(page))
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_no.h +1 -0
index c65f00a..89f1956 100644
@@ -12,6 +12,7 @@
 #define flush_cache_range(vma, start, end)	__flush_cache_all()
 #define flush_cache_page(vma, vmaddr)		do { } while (0)
 #define flush_dcache_range(start,len)		__flush_cache_all()
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/microblaze/include/asm/cacheflush.h +1 -0
index f989d6a..088076e 100644
@@ -37,6 +37,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
 
 #define flush_dcache_range(start, end)	__invalidate_dcache_range(start, end)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/mips/include/asm/cacheflush.h +1 -0
index 03b1d69..40bb9fd 100644
@@ -38,6 +38,7 @@ extern void (*flush_cache_range)(struct vm_area_struct *vma,
 extern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn);
 extern void __flush_dcache_page(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 static inline void flush_dcache_page(struct page *page)
 {
 	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)
arch/mn10300/include/asm/cacheflush.h +1 -0
index 2db746a..4a15067 100644
@@ -26,6 +26,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do {} while (0)
 #define flush_cache_vmap(start, end)		do {} while (0)
 #define flush_cache_vunmap(start, end)		do {} while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do {} while (0)
 #define flush_dcache_mmap_lock(mapping)		do {} while (0)
 #define flush_dcache_mmap_unlock(mapping)	do {} while (0)
arch/parisc/include/asm/cacheflush.h +1 -0
index 7243951..7a73b61 100644
@@ -42,6 +42,7 @@ void flush_cache_mm(struct mm_struct *mm);
 #define flush_cache_vmap(start, end)		flush_cache_all()
 #define flush_cache_vunmap(start, end)		flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_dcache_mmap_lock(mapping) \
arch/powerpc/include/asm/cacheflush.h +1 -0
index ba667a3..ab9e402 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/s390/include/asm/cacheflush.h +1 -0
index 49d5af9..405cc97 100644
@@ -10,6 +10,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/asm/cacheflush.h +1 -0
index 4c5462d..46ba64c 100644
@@ -16,6 +16,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_icache_range(start, end)		do { } while (0)
 #define flush_icache_page(vma,pg)		do { } while (0)
arch/sh/include/cpu-common/cpu/cacheflush.h +1 -0
index c3db00b..bd508bd 100644
@@ -31,6 +31,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/cpu-sh2a/cpu/cacheflush.h +1 -0
index 3d3b920..56c8c88 100644
@@ -22,6 +22,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sh/include/cpu-sh3/cpu/cacheflush.h +1 -0
index 1ac27aa..e03e964 100644
@@ -26,6 +26,7 @@ void flush_cache_mm(struct mm_struct *mm);
 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
                               unsigned long end);
 void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 void flush_dcache_page(struct page *pg);
 void flush_icache_range(unsigned long start, unsigned long end);
 void flush_icache_page(struct vm_area_struct *vma, struct page *page);
arch/sh/include/cpu-sh4/cpu/cacheflush.h +1 -0
index 065306d..1789e3e 100644
@@ -24,6 +24,7 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
 		       unsigned long end);
 void flush_cache_page(struct vm_area_struct *vma, unsigned long addr,
 		      unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 void flush_dcache_page(struct page *pg);
 
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
arch/sh/include/cpu-sh5/cpu/cacheflush.h +1 -0
index 5a11f0b..cd098a3 100644
@@ -13,6 +13,7 @@ extern void flush_cache_sigtramp(unsigned long vaddr);
 extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
 			      unsigned long end);
 extern void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *pg);
 extern void flush_icache_range(unsigned long start, unsigned long end);
 extern void flush_icache_user_range(struct vm_area_struct *vma,
arch/sparc/include/asm/cacheflush_32.h +1 -0
index 68ac109..2e46877 100644
@@ -75,6 +75,7 @@ BTFIXUPDEF_CALL(void, flush_sig_insns, struct mm_struct *, unsigned long)
 
 extern void sparc_flush_page_to_ram(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			sparc_flush_page_to_ram(page)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sparc/include/asm/cacheflush_64.h +1 -0
index c433217..b953840 100644
@@ -37,6 +37,7 @@ extern void flush_dcache_page_all(struct mm_struct *mm, struct page *page);
 #endif
 
 extern void __flush_dcache_range(unsigned long start, unsigned long end);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_icache_page(vma, pg)	do { } while(0)
arch/x86/include/asm/cacheflush.h +1 -0
index e55dfc1..7631500 100644
@@ -12,6 +12,7 @@ static inline void flush_cache_range(struct vm_area_struct *vma,
 				     unsigned long start, unsigned long end) { }
 static inline void flush_cache_page(struct vm_area_struct *vma,
 				    unsigned long vmaddr, unsigned long pfn) { }
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 static inline void flush_dcache_page(struct page *page) { }
 static inline void flush_dcache_mmap_lock(struct address_space *mapping) { }
 static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { }
arch/xtensa/include/asm/cacheflush.h +2 -0
index b7b8fbe..376cd9d 100644
@@ -101,6 +101,7 @@ static inline void __invalidate_icache_page_alias(unsigned long virt,
 #define flush_cache_vmap(start,end)	flush_cache_all()
 #define flush_cache_vunmap(start,end)	flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page*);
 extern void flush_cache_range(struct vm_area_struct*, ulong, ulong);
 extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned long);
@@ -114,6 +115,7 @@ extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned lon
 #define flush_cache_vmap(start,end)			do { } while (0)
 #define flush_cache_vunmap(start,end)			do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)				do { } while (0)
 
 #define flush_cache_page(vma,addr,pfn)			do { } while (0)
block/blk-core.c +19 -0
index e3299a7..824f822 100644
@@ -2254,6 +2254,25 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
 		rq->rq_disk = bio->bi_bdev->bd_disk;
 }
 
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+/**
+ * rq_flush_dcache_pages - Helper function to flush all pages in a request
+ * @rq: the request to be flushed
+ *
+ * Description:
+ *     Flush all pages in @rq.
+ */
+void rq_flush_dcache_pages(struct request *rq)
+{
+	struct req_iterator iter;
+	struct bio_vec* bvec;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec->bv_page);
+}
+EXPORT_SYMBOL_GPL(rq_flush_dcache_pages);
+#endif
+
 /**
  * blk_lld_busy - Check if underlying low-level drivers of a device are busy
  * @q : the queue of the device being checked
drivers/mtd/mtd_blkdevs.c +2 -0
index 7baba40..abddc60 100644
@@ -68,12 +68,14 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
+		rq_flush_dcache_pages(req);
 		return 0;
 
 	case WRITE:
 		if (!tr->writesect)
 			return -EIO;
 
+		rq_flush_dcache_pages(req);
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
fs/bio.c +12 -0
index 7673800..25f79d3 100644
@@ -1376,6 +1376,18 @@ void bio_check_pages_dirty(struct bio *bio)
 	}
 }
 
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+void bio_flush_dcache_pages(struct bio *bi)
+{
+	int i;
+	struct bio_vec* bvec;
+
+	bio_for_each_segment(bvec, bi, i)
+		flush_dcache_page(bvec->bv_page);
+}
+EXPORT_SYMBOL(bio_flush_dcache_pages);
+#endif
+
 /**
  * bio_endio - end I/O on a bio
  * @bio:	bio
include/linux/bio.h +12 -0
index 2892b71..3bd12dd 100644
@@ -396,6 +396,18 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
 				 gfp_t, int);
 extern void bio_set_pages_dirty(struct bio *bio);
 extern void bio_check_pages_dirty(struct bio *bio);
+
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+extern void bio_flush_dcache_pages(struct bio *bi);
+#else
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+}
+#endif
+
 extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
 				 unsigned long, unsigned int, int, gfp_t);
 extern struct bio *bio_copy_user_iov(struct request_queue *,
include/linux/blkdev.h +11 -0
index 69103e0..ce57692 100644
@@ -740,6 +740,17 @@ struct req_iterator {
 #define rq_iter_last(rq, _iter)					\
 		(_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+extern void rq_flush_dcache_pages(struct request *rq);
+#else
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+}
+#endif
+
 extern int blk_register_queue(struct gendisk *disk);
 extern void blk_unregister_queue(struct gendisk *disk);
 extern void register_disk(struct gendisk *dev);
#16 lore raw
Quoted 31 lines · On Sun, 22 Nov 2009 23:55:39 +0300 Ilya Loginov <[email protected]> wrote:
Quoted 4 lines
Quoted 4 lines

I tried this way from the beginning, and to avoid redefinitions I enclose everything in #if #endif in *.c files. I think it is not very good. So there are two possibilities.

Ah. I think the first choice is always the best choise. =)

Quoted 21 lines

In .h:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
extern void rq_flush_dcache_pages(struct request *rq); #else
static inline void bio_flush_dcache_pages(struct bio *bi) {
}
#endif

In .c:

#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
void rq_flush_dcache_pages(struct request *rq)

{
	struct req_iterator iter;
	struct bio_vec* bvec;

	rq_for_each_segment(bvec, rq, iter)
		flush_dcache_page(bvec->bv_page);
}
Quoted 2 lines

EXPORT_SYMBOL(rq_flush_dcache_pages);
#endif

Quoted 5 lines

This is 2) =)

Thanks a lot for your help and comments!

Looks good to me, but...

Patch doesn't vaguely apply to linux-next because of arch/sh changes. I was going to fix that but afaict your assertion that sh doesn't implement flush_dcache_page() appears to be untrue in linux-next and a bit of thought is needed there.

Also, please provide a nice chagnelog whcih describes the change, and our reasons for making it.

#17 lore raw
Quoted 4 lines

Patch doesn't vaguely apply to linux-next because of arch/sh changes. I was going to fix that but afaict your assertion that sh doesn't implement flush_dcache_page() appears to be untrue in linux-next and a bit of thought is needed there.

You right. The sh architecture changed in linux-next and scope
arch was added. I created new patch and tested it on linux-next.

Quoted 2 lines

Also, please provide a nice chagnelog whcih describes the change, and our reasons for making it.

Mtdblock driver doesn't call flush_dcache_page for pages in request. So, this cause problem on architectures where icache doesn't fill from dcache or with dcache aliases. Patch fix this. The ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE symbol was introduced to avoid pointless empty cache-thrashing loops on architectures for which flush_dcache_page() is a no-op. Every architecture was provided with this #define. New functions bio_flush_dcache_pages and rq_flush_dcache_pages flush pages on architectires where ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE is equal 1 or do nothing otherwise.

See "fix mtd_blkdevs problem with caches on some architectures" discussion on LKML for more information.

---
 arch/alpha/include/asm/cacheflush.h      |    1 +
 arch/arm/include/asm/cacheflush.h        |    1 +
 arch/avr32/include/asm/cacheflush.h      |    1 +
 arch/blackfin/include/asm/cacheflush.h   |    2 ++
 arch/cris/include/asm/cacheflush.h       |    1 +
 arch/frv/include/asm/cacheflush.h        |    1 +
 arch/h8300/include/asm/cacheflush.h      |    1 +
 arch/ia64/include/asm/cacheflush.h       |    1 +
 arch/m32r/include/asm/cacheflush.h       |    3 +++
 arch/m68k/include/asm/cacheflush_mm.h    |    1 +
 arch/m68k/include/asm/cacheflush_no.h    |    1 +
 arch/microblaze/include/asm/cacheflush.h |    1 +
 arch/mips/include/asm/cacheflush.h       |    1 +
 arch/mn10300/include/asm/cacheflush.h    |    1 +
 arch/parisc/include/asm/cacheflush.h     |    1 +
 arch/powerpc/include/asm/cacheflush.h    |    1 +
 arch/s390/include/asm/cacheflush.h       |    1 +
 arch/score/include/asm/cacheflush.h      |    1 +
 arch/sh/include/asm/cacheflush.h         |    1 +
 arch/sparc/include/asm/cacheflush_32.h   |    1 +
 arch/sparc/include/asm/cacheflush_64.h   |    1 +
 arch/x86/include/asm/cacheflush.h        |    1 +
 arch/xtensa/include/asm/cacheflush.h     |    1 +
 block/blk-core.c                         |   19 +++++++++++++++++++
 drivers/mtd/mtd_blkdevs.c                |    2 ++
 fs/bio.c                                 |   12 ++++++++++++
 include/asm-generic/cacheflush.h         |    1 +
 include/linux/bio.h                      |   12 ++++++++++++
 include/linux/blkdev.h                   |   11 +++++++++++
 29 files changed, 83 insertions(+)
arch/alpha/include/asm/cacheflush.h +1 -0
index b686cc7..01d71e1 100644
@@ -9,6 +9,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/arm/include/asm/cacheflush.h +1 -0
index 9fd6d3a..73eceb8 100644
@@ -418,6 +418,7 @@ extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  * about to change to user space.  This is the same method as used on SPARC64.
  * See update_mmu_cache for the user space part.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *);
 
 static inline void __flush_icache_all(void)
arch/avr32/include/asm/cacheflush.h +1 -0
index 6706747..96e5382 100644
@@ -107,6 +107,7 @@ extern void flush_icache_page(struct vm_area_struct *vma, struct page *page);
  * do something here, but only for certain configurations.  No such
  * configurations exist at this time.
  */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(page)		do { } while (0)
 #define flush_dcache_mmap_unlock(page)		do { } while (0)
arch/blackfin/include/asm/cacheflush.h +2 -0
index af03a36..417eaac 100644
@@ -68,9 +68,11 @@ do { memcpy(dst, src, len);						\
 #endif
 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
 # define flush_dcache_range(start,end)		blackfin_dcache_flush_range((start), (end))
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 # define flush_dcache_page(page)		blackfin_dflush_page(page_address(page))
 #else
 # define flush_dcache_range(start,end)		do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 # define flush_dcache_page(page)		do { } while (0)
 #endif
 
arch/cris/include/asm/cacheflush.h +1 -0
index cf60e3f..36795bc 100644
@@ -12,6 +12,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/frv/include/asm/cacheflush.h +1 -0
index 432a69e..edbac54 100644
@@ -47,6 +47,7 @@ static inline void __flush_cache_all(void)
 }
 
 /* dcache/icache coherency... */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #ifdef CONFIG_MMU
 extern void flush_dcache_page(struct page *page);
 #else
arch/h8300/include/asm/cacheflush.h +1 -0
index 5ffdca2..4cf2df2 100644
@@ -15,6 +15,7 @@
 #define	flush_cache_dup_mm(mm)		do { } while (0)
 #define	flush_cache_range(vma,a,b)
 #define	flush_cache_page(vma,p,pfn)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define	flush_dcache_page(page)
 #define	flush_dcache_mmap_lock(mapping)
 #define	flush_dcache_mmap_unlock(mapping)
arch/ia64/include/asm/cacheflush.h +1 -0
index c8ce271..429eefc 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			\
 do {						\
 	clear_bit(PG_arch_1, &(page)->flags);	\
arch/m32r/include/asm/cacheflush.h +3 -0
index 78587c9..8e8e045 100644
@@ -12,6 +12,7 @@ extern void _flush_cache_copyback_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -33,6 +34,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
@@ -46,6 +48,7 @@ extern void smp_flush_cache_all(void);
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_mm.h +1 -0
index 16bf375..73de7c8 100644
@@ -128,6 +128,7 @@ static inline void __flush_page_to_ram(void *vaddr)
 	}
 }
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)		__flush_page_to_ram(page_address(page))
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/m68k/include/asm/cacheflush_no.h +1 -0
index c65f00a..89f1956 100644
@@ -12,6 +12,7 @@
 #define flush_cache_range(vma, start, end)	__flush_cache_all()
 #define flush_cache_page(vma, vmaddr)		do { } while (0)
 #define flush_dcache_range(start,len)		__flush_cache_all()
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/microblaze/include/asm/cacheflush.h +1 -0
index d3f3f75..1f04b91 100644
@@ -37,6 +37,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
 
 #define flush_dcache_range(start, end)	__invalidate_dcache_range(start, end)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/mips/include/asm/cacheflush.h +1 -0
index 03b1d69..40bb9fd 100644
@@ -38,6 +38,7 @@ extern void (*flush_cache_range)(struct vm_area_struct *vma,
 extern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn);
 extern void __flush_dcache_page(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 static inline void flush_dcache_page(struct page *page)
 {
 	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)
arch/mn10300/include/asm/cacheflush.h +1 -0
index 1a55d61..29e692f 100644
@@ -26,6 +26,7 @@
 #define flush_cache_page(vma, vmaddr, pfn)	do {} while (0)
 #define flush_cache_vmap(start, end)		do {} while (0)
 #define flush_cache_vunmap(start, end)		do {} while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do {} while (0)
 #define flush_dcache_mmap_lock(mapping)		do {} while (0)
 #define flush_dcache_mmap_unlock(mapping)	do {} while (0)
arch/parisc/include/asm/cacheflush.h +1 -0
index 7243951..7a73b61 100644
@@ -42,6 +42,7 @@ void flush_cache_mm(struct mm_struct *mm);
 #define flush_cache_vmap(start, end)		flush_cache_all()
 #define flush_cache_vunmap(start, end)		flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_dcache_mmap_lock(mapping) \
arch/powerpc/include/asm/cacheflush.h +1 -0
index ba667a3..ab9e402 100644
@@ -25,6 +25,7 @@
 #define flush_cache_vmap(start, end)		do { } while (0)
 #define flush_cache_vunmap(start, end)		do { } while (0)
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/s390/include/asm/cacheflush.h +1 -0
index 49d5af9..405cc97 100644
@@ -10,6 +10,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/score/include/asm/cacheflush.h +1 -0
index 07cc8fc..caaba24 100644
@@ -16,6 +16,7 @@ extern void flush_icache_range(unsigned long start, unsigned long end);
 extern void flush_dcache_range(unsigned long start, unsigned long end);
 
 #define flush_cache_dup_mm(mm)			do {} while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do {} while (0)
 #define flush_dcache_mmap_lock(mapping)		do {} while (0)
 #define flush_dcache_mmap_unlock(mapping)	do {} while (0)
arch/sh/include/asm/cacheflush.h +1 -0
index c29918f..dda96eb 100644
@@ -42,6 +42,7 @@ extern void flush_cache_page(struct vm_area_struct *vma,
 				unsigned long addr, unsigned long pfn);
 extern void flush_cache_range(struct vm_area_struct *vma,
 				 unsigned long start, unsigned long end);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 extern void flush_icache_range(unsigned long start, unsigned long end);
 extern void flush_icache_page(struct vm_area_struct *vma,
arch/sparc/include/asm/cacheflush_32.h +1 -0
index 68ac109..2e46877 100644
@@ -75,6 +75,7 @@ BTFIXUPDEF_CALL(void, flush_sig_insns, struct mm_struct *, unsigned long)
 
 extern void sparc_flush_page_to_ram(struct page *page);
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 #define flush_dcache_page(page)			sparc_flush_page_to_ram(page)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
arch/sparc/include/asm/cacheflush_64.h +1 -0
index c433217..b953840 100644
@@ -37,6 +37,7 @@ extern void flush_dcache_page_all(struct mm_struct *mm, struct page *page);
 #endif
 
 extern void __flush_dcache_range(unsigned long start, unsigned long end);
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page *page);
 
 #define flush_icache_page(vma, pg)	do { } while(0)
arch/x86/include/asm/cacheflush.h +1 -0
index eebb2cd..634c40a 100644
@@ -12,6 +12,7 @@ static inline void flush_cache_range(struct vm_area_struct *vma,
 				     unsigned long start, unsigned long end) { }
 static inline void flush_cache_page(struct vm_area_struct *vma,
 				    unsigned long vmaddr, unsigned long pfn) { }
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 static inline void flush_dcache_page(struct page *page) { }
 static inline void flush_dcache_mmap_lock(struct address_space *mapping) { }
 static inline void flush_dcache_mmap_unlock(struct address_space *mapping) { }
arch/xtensa/include/asm/cacheflush.h +1 -0
index b7b8fbe..a508f2f 100644
@@ -101,6 +101,7 @@ static inline void __invalidate_icache_page_alias(unsigned long virt,
 #define flush_cache_vmap(start,end)	flush_cache_all()
 #define flush_cache_vunmap(start,end)	flush_cache_all()
 
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
 extern void flush_dcache_page(struct page*);
 extern void flush_cache_range(struct vm_area_struct*, ulong, ulong);
 extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned long);
block/blk-core.c +19 -0
index 71da511..ae5de91 100644
@@ -2358,6 +2358,25 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
 		rq->rq_disk = bio->bi_bdev->bd_disk;
 }
 
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+/**
+ * rq_flush_dcache_pages - Helper function to flush all pages in a request
+ * @rq: the request to be flushed
+ *
+ * Description:
+ *     Flush all pages in @rq.
+ */
+void rq_flush_dcache_pages(struct request *rq)
+{
+	struct req_iterator iter;
+	struct bio_vec* bvec;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec->bv_page);
+}
+EXPORT_SYMBOL_GPL(rq_flush_dcache_pages);
+#endif
+
 /**
  * blk_lld_busy - Check if underlying low-level drivers of a device are busy
  * @q : the queue of the device being checked
drivers/mtd/mtd_blkdevs.c +2 -0
index b76d6e5..1ab47d5 100644
@@ -59,12 +59,14 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->readsect(dev, block, buf))
 				return -EIO;
+		rq_flush_dcache_pages(req);
 		return 0;
 
 	case WRITE:
 		if (!tr->writesect)
 			return -EIO;
 
+		rq_flush_dcache_pages(req);
 		for (; nsect > 0; nsect--, block++, buf += tr->blksize)
 			if (tr->writesect(dev, block, buf))
 				return -EIO;
fs/bio.c +12 -0
index 2bd671a..ca1245c 100644
@@ -1393,6 +1393,18 @@ void bio_check_pages_dirty(struct bio *bio)
 	}
 }
 
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+void bio_flush_dcache_pages(struct bio *bi)
+{
+	int i;
+	struct bio_vec* bvec;
+
+	bio_for_each_segment(bvec, bi, i)
+		flush_dcache_page(bvec->bv_page);
+}
+EXPORT_SYMBOL(bio_flush_dcache_pages);
+#endif
+
 /**
  * bio_endio - end I/O on a bio
  * @bio:	bio
include/asm-generic/cacheflush.h +1 -0
index ba4ec39..57b5c3c 100644
@@ -13,6 +13,7 @@
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	do { } while (0)
 #define flush_cache_page(vma, vmaddr, pfn)	do { } while (0)
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
 #define flush_dcache_mmap_unlock(mapping)	do { } while (0)
include/linux/bio.h +12 -0
index 474792b..5a81c8e 100644
@@ -391,6 +391,18 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
 				 gfp_t, int);
 extern void bio_set_pages_dirty(struct bio *bio);
 extern void bio_check_pages_dirty(struct bio *bio);
+
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+extern void bio_flush_dcache_pages(struct bio *bi);
+#else
+static inline void bio_flush_dcache_pages(struct bio *bi)
+{
+}
+#endif
+
 extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
 				 unsigned long, unsigned int, int, gfp_t);
 extern struct bio *bio_copy_user_iov(struct request_queue *,
include/linux/blkdev.h +11 -0
index 1cc0297..099a2db 100644
@@ -752,6 +752,17 @@ struct req_iterator {
 #define rq_iter_last(rq, _iter)					\
 		(_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+# error	"You should to define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform."
+#endif
+#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
+extern void rq_flush_dcache_pages(struct request *rq);
+#else
+static inline void rq_flush_dcache_pages(struct request *rq)
+{
+}
+#endif
+
 extern int blk_register_queue(struct gendisk *disk);
 extern void blk_unregister_queue(struct gendisk *disk);
 extern void register_disk(struct gendisk *dev);