hugetlbpage-radix.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/mm.h>
  3. #include <linux/hugetlb.h>
  4. #include <linux/security.h>
  5. #include <asm/pgtable.h>
  6. #include <asm/pgalloc.h>
  7. #include <asm/cacheflush.h>
  8. #include <asm/machdep.h>
  9. #include <asm/mman.h>
  10. #include <asm/tlb.h>
  11. void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  12. {
  13. int psize;
  14. struct hstate *hstate = hstate_file(vma->vm_file);
  15. psize = hstate_get_psize(hstate);
  16. radix__flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
  17. }
  18. void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  19. {
  20. int psize;
  21. struct hstate *hstate = hstate_file(vma->vm_file);
  22. psize = hstate_get_psize(hstate);
  23. radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
  24. }
  25. void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, unsigned long start,
  26. unsigned long end)
  27. {
  28. int psize;
  29. struct hstate *hstate = hstate_file(vma->vm_file);
  30. psize = hstate_get_psize(hstate);
  31. radix__flush_tlb_range_psize(vma->vm_mm, start, end, psize);
  32. }
  33. /*
  34. * A vairant of hugetlb_get_unmapped_area doing topdown search
  35. * FIXME!! should we do as x86 does or non hugetlb area does ?
  36. * ie, use topdown or not based on mmap_is_legacy check ?
  37. */
  38. unsigned long
  39. radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  40. unsigned long len, unsigned long pgoff,
  41. unsigned long flags)
  42. {
  43. struct mm_struct *mm = current->mm;
  44. struct vm_area_struct *vma;
  45. struct hstate *h = hstate_file(file);
  46. int fixed = (flags & MAP_FIXED);
  47. unsigned long high_limit;
  48. struct vm_unmapped_area_info info;
  49. high_limit = DEFAULT_MAP_WINDOW;
  50. if (addr >= high_limit || (fixed && (addr + len > high_limit)))
  51. high_limit = TASK_SIZE;
  52. if (len & ~huge_page_mask(h))
  53. return -EINVAL;
  54. if (len > high_limit)
  55. return -ENOMEM;
  56. if (fixed) {
  57. if (addr > high_limit - len)
  58. return -ENOMEM;
  59. if (prepare_hugepage_range(file, addr, len))
  60. return -EINVAL;
  61. return addr;
  62. }
  63. if (addr) {
  64. addr = ALIGN(addr, huge_page_size(h));
  65. vma = find_vma(mm, addr);
  66. if (high_limit - len >= addr && addr >= mmap_min_addr &&
  67. (!vma || addr + len <= vm_start_gap(vma)))
  68. return addr;
  69. }
  70. /*
  71. * We are always doing an topdown search here. Slice code
  72. * does that too.
  73. */
  74. info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  75. info.length = len;
  76. info.low_limit = max(PAGE_SIZE, mmap_min_addr);
  77. info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW);
  78. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  79. info.align_offset = 0;
  80. return vm_unmapped_area(&info);
  81. }