Skip to content

Commit c0fe478

Browse files
committed
sh: Provide __flush_anon_page().
This provides a __flush_anon_page() that handles both the aliasing and non-aliasing cases. This fixes up some crashes with heavy get_user_pages() users. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent b5eb10a commit c0fe478

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎arch/sh/include/asm/cacheflush.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __ASM_SH_CACHEFLUSH_H
22
#define __ASM_SH_CACHEFLUSH_H
33

4+
#include <linux/mm.h>
5+
46
#ifdef __KERNEL__
57

68
#ifdef CONFIG_CACHE_OFF
@@ -43,6 +45,18 @@ extern void __flush_purge_region(void *start, int size);
4345
extern void __flush_invalidate_region(void *start, int size);
4446
#endif
4547

48+
#ifdef CONFIG_MMU
49+
#define ARCH_HAS_FLUSH_ANON_PAGE
50+
extern void __flush_anon_page(struct page *page, unsigned long);
51+
52+
static inline void flush_anon_page(struct vm_area_struct *vma,
53+
struct page *page, unsigned long vmaddr)
54+
{
55+
if (boot_cpu_data.dcache.n_aliases && PageAnon(page))
56+
__flush_anon_page(page, vmaddr);
57+
}
58+
#endif
59+
4660
#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
4761
static inline void flush_kernel_dcache_page(struct page *page)
4862
{

‎arch/sh/mm/pg-mmu.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,20 @@ void __update_cache(struct vm_area_struct *vma,
157157
}
158158
}
159159
}
160+
161+
void __flush_anon_page(struct page *page, unsigned long vmaddr)
162+
{
163+
unsigned long addr = (unsigned long) page_address(page);
164+
165+
if (pages_do_alias(addr, vmaddr)) {
166+
if (boot_cpu_data.dcache.n_aliases && page_mapped(page) &&
167+
!test_bit(PG_dcache_dirty, &page->flags)) {
168+
void *kaddr;
169+
170+
kaddr = kmap_coherent(page, vmaddr);
171+
__flush_wback_region((void *)kaddr, PAGE_SIZE);
172+
kunmap_coherent();
173+
} else
174+
__flush_wback_region((void *)addr, PAGE_SIZE);
175+
}
176+
}

0 commit comments

Comments
 (0)