blob: 2486bee0f93e33e4a5a119fa90cc1924b056a768 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Aneesh Kumar K.V48483762016-04-29 23:26:25 +10002#include <linux/mm.h>
3#include <linux/hugetlb.h>
4#include <asm/pgtable.h>
5#include <asm/pgalloc.h>
6#include <asm/cacheflush.h>
7#include <asm/machdep.h>
8#include <asm/mman.h>
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +05309#include <asm/tlb.h>
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100010
11void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
12{
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +053013 int psize;
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100014 struct hstate *hstate = hstate_file(vma->vm_file);
15
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +053016 psize = hstate_get_psize(hstate);
17 radix__flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100018}
19
20void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
21{
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +053022 int psize;
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100023 struct hstate *hstate = hstate_file(vma->vm_file);
24
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +053025 psize = hstate_get_psize(hstate);
26 radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100027}
28
Aneesh Kumar K.V5491ae72016-07-13 15:06:43 +053029void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, unsigned long start,
30 unsigned long end)
31{
32 int psize;
33 struct hstate *hstate = hstate_file(vma->vm_file);
34
35 psize = hstate_get_psize(hstate);
36 radix__flush_tlb_range_psize(vma->vm_mm, start, end, psize);
37}
38
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100039/*
40 * A vairant of hugetlb_get_unmapped_area doing topdown search
41 * FIXME!! should we do as x86 does or non hugetlb area does ?
42 * ie, use topdown or not based on mmap_is_legacy check ?
43 */
44unsigned long
45radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
46 unsigned long len, unsigned long pgoff,
47 unsigned long flags)
48{
49 struct mm_struct *mm = current->mm;
50 struct vm_area_struct *vma;
51 struct hstate *h = hstate_file(file);
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110052 int fixed = (flags & MAP_FIXED);
53 unsigned long high_limit;
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100054 struct vm_unmapped_area_info info;
55
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110056 high_limit = DEFAULT_MAP_WINDOW;
57 if (addr >= high_limit || (fixed && (addr + len > high_limit)))
58 high_limit = TASK_SIZE;
Aneesh Kumar K.Vf4ea6dc2017-03-30 16:35:21 +053059
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100060 if (len & ~huge_page_mask(h))
61 return -EINVAL;
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110062 if (len > high_limit)
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100063 return -ENOMEM;
64
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110065 if (fixed) {
66 if (addr > high_limit - len)
67 return -ENOMEM;
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100068 if (prepare_hugepage_range(file, addr, len))
69 return -EINVAL;
70 return addr;
71 }
72
73 if (addr) {
74 addr = ALIGN(addr, huge_page_size(h));
75 vma = find_vma(mm, addr);
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110076 if (high_limit - len >= addr &&
Hugh Dickins1be71072017-06-19 04:03:24 -070077 (!vma || addr + len <= vm_start_gap(vma)))
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100078 return addr;
79 }
80 /*
81 * We are always doing an topdown search here. Slice code
82 * does that too.
83 */
84 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
85 info.length = len;
86 info.low_limit = PAGE_SIZE;
Nicholas Piggin85e3f1a2017-11-10 04:27:39 +110087 info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW);
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100088 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
89 info.align_offset = 0;
Aneesh Kumar K.Vf4ea6dc2017-03-30 16:35:21 +053090
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100091 return vm_unmapped_area(&info);
92}