kernel: Copy patches from kernel 4.14 to 4.19
[openwrt/openwrt.git] / target / linux / generic / pending-4.19 / 100-MIPS-fix-cache-flushing-for-highmem-pages.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: MIPS: fix cache flushing for highmem pages
3
4 Most cache flush ops were no-op for highmem pages. This led to nasty
5 segfaults and (in the case of page_address(page) == NULL) kernel
6 crashes.
7
8 Fix this by always flushing highmem pages using kmap/kunmap_atomic
9 around the actual cache flush. This might be a bit inefficient, but at
10 least it's stable.
11
12 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 ---
14
15 --- a/arch/mips/mm/cache.c
16 +++ b/arch/mips/mm/cache.c
17 @@ -116,6 +116,13 @@ void __flush_anon_page(struct page *page
18 {
19 unsigned long addr = (unsigned long) page_address(page);
20
21 + if (PageHighMem(page)) {
22 + addr = (unsigned long)kmap_atomic(page);
23 + flush_data_cache_page(addr);
24 + __kunmap_atomic((void *)addr);
25 + return;
26 + }
27 +
28 if (pages_do_alias(addr, vmaddr)) {
29 if (page_mapcount(page) && !Page_dcache_dirty(page)) {
30 void *kaddr;