tlb.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Based on arch/arm/include/asm/tlb.h
  4. *
  5. * Copyright (C) 2002 Russell King
  6. * Copyright (C) 2012 ARM Ltd.
  7. */
  8. #ifndef __ASM_TLB_H
  9. #define __ASM_TLB_H
  10. #include <linux/pagemap.h>
  11. #include <linux/swap.h>
  12. static inline void __tlb_remove_table(void *_table)
  13. {
  14. free_page_and_swap_cache((struct page *)_table);
  15. }
  16. #define tlb_flush tlb_flush
  17. static void tlb_flush(struct mmu_gather *tlb);
  18. #include <asm-generic/tlb.h>
  19. /*
  20. * get the tlbi levels in arm64. Default value is 0 if more than one
  21. * of cleared_* is set or neither is set.
  22. * Arm64 doesn't support p4ds now.
  23. */
  24. static inline int tlb_get_level(struct mmu_gather *tlb)
  25. {
  26. /* The TTL field is only valid for the leaf entry. */
  27. if (tlb->freed_tables)
  28. return 0;
  29. if (tlb->cleared_ptes && !(tlb->cleared_pmds ||
  30. tlb->cleared_puds ||
  31. tlb->cleared_p4ds))
  32. return 3;
  33. if (tlb->cleared_pmds && !(tlb->cleared_ptes ||
  34. tlb->cleared_puds ||
  35. tlb->cleared_p4ds))
  36. return 2;
  37. if (tlb->cleared_puds && !(tlb->cleared_ptes ||
  38. tlb->cleared_pmds ||
  39. tlb->cleared_p4ds))
  40. return 1;
  41. return 0;
  42. }
  43. static inline void tlb_flush(struct mmu_gather *tlb)
  44. {
  45. struct vm_area_struct vma = TLB_FLUSH_VMA(tlb->mm, 0);
  46. bool last_level = !tlb->freed_tables;
  47. unsigned long stride = tlb_get_unmap_size(tlb);
  48. int tlb_level = tlb_get_level(tlb);
  49. /*
  50. * If we're tearing down the address space then we only care about
  51. * invalidating the walk-cache, since the ASID allocator won't
  52. * reallocate our ASID without invalidating the entire TLB.
  53. */
  54. if (tlb->fullmm) {
  55. if (!last_level)
  56. flush_tlb_mm(tlb->mm);
  57. return;
  58. }
  59. __flush_tlb_range(&vma, tlb->start, tlb->end, stride,
  60. last_level, tlb_level);
  61. }
  62. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
  63. unsigned long addr)
  64. {
  65. pgtable_pte_page_dtor(pte);
  66. tlb_remove_table(tlb, pte);
  67. }
  68. #if CONFIG_PGTABLE_LEVELS > 2
  69. static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
  70. unsigned long addr)
  71. {
  72. struct page *page = virt_to_page(pmdp);
  73. pgtable_pmd_page_dtor(page);
  74. tlb_remove_table(tlb, page);
  75. }
  76. #endif
  77. #if CONFIG_PGTABLE_LEVELS > 3
  78. static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp,
  79. unsigned long addr)
  80. {
  81. tlb_remove_table(tlb, virt_to_page(pudp));
  82. }
  83. #endif
  84. #endif