tlb.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #define tlb_flush tlb_flush
  12. static void tlb_flush(struct mmu_gather *tlb);
  13. #include <asm-generic/tlb.h>
  14. /*
  15. * get the tlbi levels in arm64. Default value is TLBI_TTL_UNKNOWN if more than
  16. * one of cleared_* is set or neither is set - this elides the level hinting to
  17. * the hardware.
  18. */
  19. static inline int tlb_get_level(struct mmu_gather *tlb)
  20. {
  21. /* The TTL field is only valid for the leaf entry. */
  22. if (tlb->freed_tables)
  23. return TLBI_TTL_UNKNOWN;
  24. if (tlb->cleared_ptes && !(tlb->cleared_pmds ||
  25. tlb->cleared_puds ||
  26. tlb->cleared_p4ds))
  27. return 3;
  28. if (tlb->cleared_pmds && !(tlb->cleared_ptes ||
  29. tlb->cleared_puds ||
  30. tlb->cleared_p4ds))
  31. return 2;
  32. if (tlb->cleared_puds && !(tlb->cleared_ptes ||
  33. tlb->cleared_pmds ||
  34. tlb->cleared_p4ds))
  35. return 1;
  36. if (tlb->cleared_p4ds && !(tlb->cleared_ptes ||
  37. tlb->cleared_pmds ||
  38. tlb->cleared_puds))
  39. return 0;
  40. return TLBI_TTL_UNKNOWN;
  41. }
  42. static inline void tlb_flush(struct mmu_gather *tlb)
  43. {
  44. struct vm_area_struct vma = TLB_FLUSH_VMA(tlb->mm, 0);
  45. bool last_level = !tlb->freed_tables;
  46. unsigned long stride = tlb_get_unmap_size(tlb);
  47. int tlb_level = tlb_get_level(tlb);
  48. /*
  49. * If we're tearing down the address space then we only care about
  50. * invalidating the walk-cache, since the ASID allocator won't
  51. * reallocate our ASID without invalidating the entire TLB.
  52. */
  53. if (tlb->fullmm) {
  54. if (!last_level)
  55. flush_tlb_mm(tlb->mm);
  56. return;
  57. }
  58. __flush_tlb_range(&vma, tlb->start, tlb->end, stride,
  59. last_level, tlb_level);
  60. }
  61. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
  62. unsigned long addr)
  63. {
  64. struct ptdesc *ptdesc = page_ptdesc(pte);
  65. tlb_remove_ptdesc(tlb, ptdesc);
  66. }
  67. #if CONFIG_PGTABLE_LEVELS > 2
  68. static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
  69. unsigned long addr)
  70. {
  71. struct ptdesc *ptdesc = virt_to_ptdesc(pmdp);
  72. tlb_remove_ptdesc(tlb, ptdesc);
  73. }
  74. #endif
  75. #if CONFIG_PGTABLE_LEVELS > 3
  76. static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp,
  77. unsigned long addr)
  78. {
  79. struct ptdesc *ptdesc = virt_to_ptdesc(pudp);
  80. if (!pgtable_l4_enabled())
  81. return;
  82. tlb_remove_ptdesc(tlb, ptdesc);
  83. }
  84. #endif
  85. #if CONFIG_PGTABLE_LEVELS > 4
  86. static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4dp,
  87. unsigned long addr)
  88. {
  89. struct ptdesc *ptdesc = virt_to_ptdesc(p4dp);
  90. if (!pgtable_l5_enabled())
  91. return;
  92. tlb_remove_ptdesc(tlb, ptdesc);
  93. }
  94. #endif
  95. #endif