hugetlbpage.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * PARISC64 Huge TLB page support.
  3. *
  4. * This parisc implementation is heavily based on the SPARC and x86 code.
  5. *
  6. * Copyright (C) 2015 Helge Deller <deller@gmx.de>
  7. */
  8. #include <linux/fs.h>
  9. #include <linux/mm.h>
  10. #include <linux/hugetlb.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/sysctl.h>
  13. #include <asm/mman.h>
  14. #include <asm/pgalloc.h>
  15. #include <asm/tlb.h>
  16. #include <asm/tlbflush.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/mmu_context.h>
  19. unsigned long
  20. hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  21. unsigned long len, unsigned long pgoff, unsigned long flags)
  22. {
  23. struct hstate *h = hstate_file(file);
  24. if (len & ~huge_page_mask(h))
  25. return -EINVAL;
  26. if (len > TASK_SIZE)
  27. return -ENOMEM;
  28. if (flags & MAP_FIXED)
  29. if (prepare_hugepage_range(file, addr, len))
  30. return -EINVAL;
  31. if (addr)
  32. addr = ALIGN(addr, huge_page_size(h));
  33. /* we need to make sure the colouring is OK */
  34. return arch_get_unmapped_area(file, addr, len, pgoff, flags);
  35. }
  36. pte_t *huge_pte_alloc(struct mm_struct *mm,
  37. unsigned long addr, unsigned long sz)
  38. {
  39. pgd_t *pgd;
  40. pud_t *pud;
  41. pmd_t *pmd;
  42. pte_t *pte = NULL;
  43. /* We must align the address, because our caller will run
  44. * set_huge_pte_at() on whatever we return, which writes out
  45. * all of the sub-ptes for the hugepage range. So we have
  46. * to give it the first such sub-pte.
  47. */
  48. addr &= HPAGE_MASK;
  49. pgd = pgd_offset(mm, addr);
  50. pud = pud_alloc(mm, pgd, addr);
  51. if (pud) {
  52. pmd = pmd_alloc(mm, pud, addr);
  53. if (pmd)
  54. pte = pte_alloc_map(mm, NULL, pmd, addr);
  55. }
  56. return pte;
  57. }
  58. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
  59. {
  60. pgd_t *pgd;
  61. pud_t *pud;
  62. pmd_t *pmd;
  63. pte_t *pte = NULL;
  64. addr &= HPAGE_MASK;
  65. pgd = pgd_offset(mm, addr);
  66. if (!pgd_none(*pgd)) {
  67. pud = pud_offset(pgd, addr);
  68. if (!pud_none(*pud)) {
  69. pmd = pmd_offset(pud, addr);
  70. if (!pmd_none(*pmd))
  71. pte = pte_offset_map(pmd, addr);
  72. }
  73. }
  74. return pte;
  75. }
  76. /* Purge data and instruction TLB entries. Must be called holding
  77. * the pa_tlb_lock. The TLB purge instructions are slow on SMP
  78. * machines since the purge must be broadcast to all CPUs.
  79. */
  80. static inline void purge_tlb_entries_huge(struct mm_struct *mm, unsigned long addr)
  81. {
  82. int i;
  83. /* We may use multiple physical huge pages (e.g. 2x1 MB) to emulate
  84. * Linux standard huge pages (e.g. 2 MB) */
  85. BUILD_BUG_ON(REAL_HPAGE_SHIFT > HPAGE_SHIFT);
  86. addr &= HPAGE_MASK;
  87. addr |= _HUGE_PAGE_SIZE_ENCODING_DEFAULT;
  88. for (i = 0; i < (1 << (HPAGE_SHIFT-REAL_HPAGE_SHIFT)); i++) {
  89. mtsp(mm->context, 1);
  90. pdtlb(addr);
  91. if (unlikely(split_tlb))
  92. pitlb(addr);
  93. addr += (1UL << REAL_HPAGE_SHIFT);
  94. }
  95. }
  96. void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  97. pte_t *ptep, pte_t entry)
  98. {
  99. unsigned long addr_start;
  100. int i;
  101. addr &= HPAGE_MASK;
  102. addr_start = addr;
  103. for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) {
  104. /* Directly write pte entry. We could call set_pte_at(mm, addr, ptep, entry)
  105. * instead, but then we get double locking on pa_tlb_lock. */
  106. *ptep = entry;
  107. ptep++;
  108. /* Drop the PAGE_SIZE/non-huge tlb entry */
  109. purge_tlb_entries(mm, addr);
  110. addr += PAGE_SIZE;
  111. pte_val(entry) += PAGE_SIZE;
  112. }
  113. purge_tlb_entries_huge(mm, addr_start);
  114. }
  115. pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  116. pte_t *ptep)
  117. {
  118. pte_t entry;
  119. entry = *ptep;
  120. set_huge_pte_at(mm, addr, ptep, __pte(0));
  121. return entry;
  122. }
  123. int pmd_huge(pmd_t pmd)
  124. {
  125. return 0;
  126. }
  127. int pud_huge(pud_t pud)
  128. {
  129. return 0;
  130. }