flush.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Based on arch/arm/mm/flush.c
  4. *
  5. * Copyright (C) 1995-2002 Russell King
  6. * Copyright (C) 2012 ARM Ltd.
  7. */
  8. #include <linux/export.h>
  9. #include <linux/mm.h>
  10. #include <linux/pagemap.h>
  11. #include <asm/cacheflush.h>
  12. #include <asm/cache.h>
  13. #include <asm/tlbflush.h>
  14. void sync_icache_aliases(void *kaddr, unsigned long len)
  15. {
  16. unsigned long addr = (unsigned long)kaddr;
  17. if (icache_is_aliasing()) {
  18. __clean_dcache_area_pou(kaddr, len);
  19. __flush_icache_all();
  20. } else {
  21. /*
  22. * Don't issue kick_all_cpus_sync() after I-cache invalidation
  23. * for user mappings.
  24. */
  25. __flush_icache_range(addr, addr + len);
  26. }
  27. }
  28. static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  29. unsigned long uaddr, void *kaddr,
  30. unsigned long len)
  31. {
  32. if (vma->vm_flags & VM_EXEC)
  33. sync_icache_aliases(kaddr, len);
  34. }
  35. /*
  36. * Copy user data from/to a page which is mapped into a different processes
  37. * address space. Really, we want to allow our "user space" model to handle
  38. * this.
  39. */
  40. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  41. unsigned long uaddr, void *dst, const void *src,
  42. unsigned long len)
  43. {
  44. memcpy(dst, src, len);
  45. flush_ptrace_access(vma, page, uaddr, dst, len);
  46. }
  47. void __sync_icache_dcache(pte_t pte)
  48. {
  49. struct page *page = pte_page(pte);
  50. if (!test_bit(PG_dcache_clean, &page->flags)) {
  51. sync_icache_aliases(page_address(page), page_size(page));
  52. set_bit(PG_dcache_clean, &page->flags);
  53. }
  54. }
  55. EXPORT_SYMBOL_GPL(__sync_icache_dcache);
  56. /*
  57. * This function is called when a page has been modified by the kernel. Mark
  58. * it as dirty for later flushing when mapped in user space (if executable,
  59. * see __sync_icache_dcache).
  60. */
  61. void flush_dcache_page(struct page *page)
  62. {
  63. if (test_bit(PG_dcache_clean, &page->flags))
  64. clear_bit(PG_dcache_clean, &page->flags);
  65. }
  66. EXPORT_SYMBOL(flush_dcache_page);
  67. /*
  68. * Additional functions defined in assembly.
  69. */
  70. EXPORT_SYMBOL(__flush_icache_range);
  71. #ifdef CONFIG_ARCH_HAS_PMEM_API
  72. void arch_wb_cache_pmem(void *addr, size_t size)
  73. {
  74. /* Ensure order against any prior non-cacheable writes */
  75. dmb(osh);
  76. __clean_dcache_area_pop(addr, size);
  77. }
  78. EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
  79. void arch_invalidate_pmem(void *addr, size_t size)
  80. {
  81. __inval_dcache_area(addr, size);
  82. }
  83. EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
  84. #endif