1 // SPDX-License-Identifier: GPL-2.0-only
3 * Based on arch/arm/mm/flush.c
5 * Copyright (C) 1995-2002 Russell King
6 * Copyright (C) 2012 ARM Ltd.
9 #include <linux/export.h>
11 #include <linux/libnvdimm.h>
12 #include <linux/pagemap.h>
14 #include <asm/cacheflush.h>
15 #include <asm/cache.h>
16 #include <asm/tlbflush.h>
18 void sync_icache_aliases(unsigned long start, unsigned long end)
20 if (icache_is_aliasing()) {
21 dcache_clean_pou(start, end);
22 icache_inval_all_pou();
25 * Don't issue kick_all_cpus_sync() after I-cache invalidation
28 caches_clean_inval_pou(start, end);
32 static void flush_ptrace_access(struct vm_area_struct *vma, unsigned long start,
35 if (vma->vm_flags & VM_EXEC)
36 sync_icache_aliases(start, end);
40 * Copy user data from/to a page which is mapped into a different processes
41 * address space. Really, we want to allow our "user space" model to handle
44 void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
45 unsigned long uaddr, void *dst, const void *src,
48 memcpy(dst, src, len);
49 flush_ptrace_access(vma, (unsigned long)dst, (unsigned long)dst + len);
52 void __sync_icache_dcache(pte_t pte)
54 struct folio *folio = page_folio(pte_page(pte));
56 if (!test_bit(PG_dcache_clean, &folio->flags)) {
57 sync_icache_aliases((unsigned long)folio_address(folio),
58 (unsigned long)folio_address(folio) +
60 set_bit(PG_dcache_clean, &folio->flags);
63 EXPORT_SYMBOL_GPL(__sync_icache_dcache);
66 * This function is called when a page has been modified by the kernel. Mark
67 * it as dirty for later flushing when mapped in user space (if executable,
68 * see __sync_icache_dcache).
70 void flush_dcache_folio(struct folio *folio)
72 if (test_bit(PG_dcache_clean, &folio->flags))
73 clear_bit(PG_dcache_clean, &folio->flags);
75 EXPORT_SYMBOL(flush_dcache_folio);
77 void flush_dcache_page(struct page *page)
79 flush_dcache_folio(page_folio(page));
81 EXPORT_SYMBOL(flush_dcache_page);
84 * Additional functions defined in assembly.
86 EXPORT_SYMBOL(caches_clean_inval_pou);
88 #ifdef CONFIG_ARCH_HAS_PMEM_API
89 void arch_wb_cache_pmem(void *addr, size_t size)
91 /* Ensure order against any prior non-cacheable writes */
93 dcache_clean_pop((unsigned long)addr, (unsigned long)addr + size);
95 EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
97 void arch_invalidate_pmem(void *addr, size_t size)
99 dcache_inval_poc((unsigned long)addr, (unsigned long)addr + size);
101 EXPORT_SYMBOL_GPL(arch_invalidate_pmem);