fix xfs by making I/O to vmap/vmalloc areas work
Subsystems (7)
cover fix xfs by making I/O to vmap/vmalloc areas work
From: James Bottomley <[email protected]>
Here's version three of the patch. This one makes sure the invalidate works correctly. I verified it on parisc by making my system print out the virtual addresses it was invalidating and matching up with the ones that were initially flushed, but since invalidate is a nop on parisc, I can't verify live that the issue is fixed. I'd really appreciate someone from arm and sh testing here.
Thanks,
James
---
James Bottomley (6):
mm: add coherence API for DMA to vmalloc/vmap areas
parisc: add mm API for DMA to vmalloc/vmap areas
arm: add mm API for DMA to vmalloc/vmap areas
sh: add mm API for DMA to vmalloc/vmap areas
block: permit I/O to vmalloc/vmap kernel pages
xfs: fix xfs to work with Virtually Indexed architectures
arch/arm/include/asm/cacheflush.h | 10 ++++++++++ arch/parisc/include/asm/cacheflush.h | 8 ++++++++ arch/sh/include/asm/cacheflush.h | 8 ++++++++ fs/bio.c | 20 ++++++++++++++++++-- fs/xfs/linux-2.6/xfs_buf.c | 20 ++++++++++++++++++++ include/linux/highmem.h | 6 ++++++ 6 files changed, 70 insertions(+), 2 deletions(-)
PATCH 1/6 mm: add coherence API for DMA to vmalloc/vmap areas
From: James Bottomley <[email protected]>
On Virtually Indexed architectures (which don't do automatic alias resolution in their caches), we have to flush via the correct virtual address to prepare pages for DMA. On some architectures (like arm) we cannot prevent the CPU from doing data movein along the alias (and thus giving stale read data), so we not only have to introduce a flush API to push dirty cache lines out, but also an invalidate API to kill inconsistent cache lines that may have moved in before DMA changed the data
--- include/linux/highmem.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/highmem.h +6 -0
@@ -17,6 +17,12 @@ static inline void flush_anon_page(struct vm_area_struct *vma, struct page *pagestatic inline void flush_kernel_dcache_page (struct page *page) { } +static inline void flush_kernel_dcache_addr (void *vaddr) +{ +} +static inline void invalidate_kernel_dcache_addr (void *vaddr) +{ +}#endif #include <asm/kmap_types.h>
Signature · 1 line
1.6.3.3
PATCH 2/6 parisc: add mm API for DMA to vmalloc/vmap areas
From: James Bottomley <[email protected]>
We already have an API to flush a kernel page along an alias address, so use it. The TLB purge prevents the CPU from doing speculative moveins on the flushed address, so we don't need to implement and invalidate.
--- arch/parisc/include/asm/cacheflush.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/parisc/include/asm/cacheflush.h +8 -0
@@ -90,6 +90,14 @@ static inline void flush_kernel_dcache_page(struct page *page) {flush_kernel_dcache_page_addr (page_address (page)); } +static inline void flush_kernel_dcache_addr (void *addr) +{ +flush_kernel_dcache_page_addr (addr); +} +static inline void invalidate_kernel_dcache_addr (void *addr) +{ +/* nop .. the flush prevents move in until the page is touched */ +}#ifdef CONFIG_DEBUG_RODATA void mark_rodata_ro (void );
Signature · 1 line
1.6.3.3
PATCH 3/6 arm: add mm API for DMA to vmalloc/vmap areas
From: James Bottomley <[email protected]>
ARM cannot prevent cache movein, so this patch implements both the flush and invalidate pieces of the API.
--- arch/arm/include/asm/cacheflush.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
arch/arm/include/asm/cacheflush.h +10 -0
@@ -436,6 +436,16 @@ static inline void flush_kernel_dcache_page(struct page *page)if ((cache_is_vivt () ||cache_is_vipt_aliasing ()) && !PageHighMem (page))__cpuc_flush_dcache_page (page_address (page)); } +static inline void flush_kernel_dcache_addr (void *addr) +{ +if ((cache_is_vivt () ||cache_is_vipt_aliasing ())) +__cpuc_flush_dcache_page (addr); +} +static inline void invalidate_kernel_dcache_addr (void *addr) +{ +if ((cache_is_vivt () ||cache_is_vipt_aliasing ())) +__cpuc_flush_dcache_page (addr); +}#define flush_dcache_mmap_lock (mapping) \ spin_lock_irq(&(mapping)->tree_lock)
Signature · 1 line
1.6.3.3
PATCH 4/6 sh: add mm API for DMA to vmalloc/vmap areas
From: James Bottomley <[email protected]>
--- arch/sh/include/asm/cacheflush.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/sh/include/asm/cacheflush.h +8 -0
@@ -48,6 +48,14 @@ static inline void flush_kernel_dcache_page(struct page *page) {flush_dcache_page (page); } +static inline void flush_kernel_dcache_addr (void *addr) +{ +__flush_wback_region (addr,PAGE_SIZE ); +} +static inline void invalidate_kernel_dcache_addr (void *addr) +{ +__flush_invalidate_region (addr,PAGE_SIZE ); +}#if defined(CONFIG_CPU_SH4 ) && !defined(CONFIG_CACHE_OFF ) extern void copy_to_user_page(struct vm_area_struct *vma,
Signature · 1 line
1.6.3.3
PATCH 5/6 block: permit I/O to vmalloc/vmap kernel pages
From: James Bottomley <[email protected]>
This updates bio_map_kern() to check for pages in the vmalloc address range and call the new kernel flushing APIs if the are. This should allow any kernel user to pass a vmalloc/vmap area to block.
--- fs/bio.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
fs/bio.c +18 -2
@@ -1120,6 +1120,14 @@ void bio_unmap_user(struct bio *bio)static void bio_map_kern_endio (struct bio *bio,int err) { +void *kaddr = bio->bi_private; + +if (is_vmalloc_addr (kaddr)) { +int i; + +for (i =0 ; i < bio->bi_vcnt; i++) +invalidate_kernel_dcache_addr (kaddr + i *PAGE_SIZE ); + }bio_put (bio); }
@@ -1138,9 +1146,12 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,if (!bio)return ERR_PTR (-ENOMEM ); + bio->bi_private = data; + offset =offset_in_page (kaddr);for (i =0 ; i < nr_pages; i++) {unsigned int bytes =PAGE_SIZE - offset; +struct page *page;if (len <=0 )break ;
@@ -1148,8 +1159,13 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,if (bytes > len) bytes = len; -if (bio_add_pc_page (q, bio,virt_to_page (data), bytes, - offset) < bytes) +if (is_vmalloc_addr (data)) { +flush_kernel_dcache_addr (data); + page =vmalloc_to_page (data); + }else + page =virt_to_page (data); + +if (bio_add_pc_page (q, bio, page, bytes, offset) < bytes)break ; data += bytes;
Signature · 1 line
1.6.3.3
PATCH 6/6 xfs: fix xfs to work with Virtually Indexed architectures
From: James Bottomley <[email protected]>
xfs_buf.c includes what is essentially a hand rolled version of blk_rq_map_kern(). In order to work properly with the vmalloc buffers that xfs uses, this hand rolled routine must also implement the flushing API for vmap/vmalloc areas.
--- fs/xfs/linux-2.6/xfs_buf.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-)
fs/xfs/linux-2.6/xfs_buf.c +20 -0
@@ -1132,12 +1132,26 @@ xfs_buf_bio_end_io(xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private;unsigned int blocksize = bp->b_target->bt_bsize;struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt -1 ; +void *vaddr =NULL ; +int i;xfs_buf_ioerror (bp, -error); +if (is_vmalloc_addr (bp->b_addr)) +for (i =0 ; i < bp->b_page_count; i++) +if (bvec->bv_page == bp->b_pages[i]) { + vaddr = bp->b_addr + i*PAGE_SIZE ; +break ; + } + do { struct page *page = bvec->bv_page; + if (is_vmalloc_addr(bp->b_addr)) { + invalidate_kernel_dcache_addr(vaddr); + vaddr -= PAGE_SIZE; + } + ASSERT(!PagePrivate(page)); if (unlikely(bp->b_error)) { if (bp->b_flags & XBF_READ)
@@ -1202,6 +1216,9 @@ _xfs_buf_ioapply( bio->bi_end_io = xfs_buf_bio_end_io; bio->bi_private = bp; +if (is_vmalloc_addr (bp->b_addr)) +flush_kernel_dcache_addr (bp->b_addr); +bio_add_page (bio, bp->b_pages[0 ],PAGE_CACHE_SIZE ,0 ); size =0 ;
@@ -1228,6 +1245,9 @@ next_chunk:if (nbytes > size) nbytes = size; +if (is_vmalloc_addr (bp->b_addr)) +flush_kernel_dcache_addr (bp->b_addr +PAGE_SIZE *map_i); + rbytes =bio_add_page (bio, bp->b_pages[map_i], nbytes, offset);if (rbytes < nbytes)break ;
Signature · 1 line
1.6.3.3