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