diff options
Diffstat (limited to 'arch/powerpc/mm/book3s64/iommu_api.c')
-rw-r--r-- | arch/powerpc/mm/book3s64/iommu_api.c | 41 |
1 files changed, 4 insertions, 37 deletions
diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c index 90ee3a89722c..b056cae3388b 100644 --- a/arch/powerpc/mm/book3s64/iommu_api.c +++ b/arch/powerpc/mm/book3s64/iommu_api.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/hugetlb.h> | 14 | #include <linux/hugetlb.h> |
15 | #include <linux/swap.h> | 15 | #include <linux/swap.h> |
16 | #include <linux/sizes.h> | 16 | #include <linux/sizes.h> |
17 | #include <linux/mm.h> | ||
17 | #include <asm/mmu_context.h> | 18 | #include <asm/mmu_context.h> |
18 | #include <asm/pte-walk.h> | 19 | #include <asm/pte-walk.h> |
19 | #include <linux/mm_inline.h> | 20 | #include <linux/mm_inline.h> |
@@ -46,40 +47,6 @@ struct mm_iommu_table_group_mem_t { | |||
46 | u64 dev_hpa; /* Device memory base address */ | 47 | u64 dev_hpa; /* Device memory base address */ |
47 | }; | 48 | }; |
48 | 49 | ||
49 | static long mm_iommu_adjust_locked_vm(struct mm_struct *mm, | ||
50 | unsigned long npages, bool incr) | ||
51 | { | ||
52 | long ret = 0, locked, lock_limit; | ||
53 | |||
54 | if (!npages) | ||
55 | return 0; | ||
56 | |||
57 | down_write(&mm->mmap_sem); | ||
58 | |||
59 | if (incr) { | ||
60 | locked = mm->locked_vm + npages; | ||
61 | lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; | ||
62 | if (locked > lock_limit && !capable(CAP_IPC_LOCK)) | ||
63 | ret = -ENOMEM; | ||
64 | else | ||
65 | mm->locked_vm += npages; | ||
66 | } else { | ||
67 | if (WARN_ON_ONCE(npages > mm->locked_vm)) | ||
68 | npages = mm->locked_vm; | ||
69 | mm->locked_vm -= npages; | ||
70 | } | ||
71 | |||
72 | pr_debug("[%d] RLIMIT_MEMLOCK HASH64 %c%ld %ld/%ld\n", | ||
73 | current ? current->pid : 0, | ||
74 | incr ? '+' : '-', | ||
75 | npages << PAGE_SHIFT, | ||
76 | mm->locked_vm << PAGE_SHIFT, | ||
77 | rlimit(RLIMIT_MEMLOCK)); | ||
78 | up_write(&mm->mmap_sem); | ||
79 | |||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | bool mm_iommu_preregistered(struct mm_struct *mm) | 50 | bool mm_iommu_preregistered(struct mm_struct *mm) |
84 | { | 51 | { |
85 | return !list_empty(&mm->context.iommu_group_mem_list); | 52 | return !list_empty(&mm->context.iommu_group_mem_list); |
@@ -96,7 +63,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, | |||
96 | unsigned long entry, chunk; | 63 | unsigned long entry, chunk; |
97 | 64 | ||
98 | if (dev_hpa == MM_IOMMU_TABLE_INVALID_HPA) { | 65 | if (dev_hpa == MM_IOMMU_TABLE_INVALID_HPA) { |
99 | ret = mm_iommu_adjust_locked_vm(mm, entries, true); | 66 | ret = account_locked_vm(mm, entries, true); |
100 | if (ret) | 67 | if (ret) |
101 | return ret; | 68 | return ret; |
102 | 69 | ||
@@ -211,7 +178,7 @@ free_exit: | |||
211 | kfree(mem); | 178 | kfree(mem); |
212 | 179 | ||
213 | unlock_exit: | 180 | unlock_exit: |
214 | mm_iommu_adjust_locked_vm(mm, locked_entries, false); | 181 | account_locked_vm(mm, locked_entries, false); |
215 | 182 | ||
216 | return ret; | 183 | return ret; |
217 | } | 184 | } |
@@ -311,7 +278,7 @@ long mm_iommu_put(struct mm_struct *mm, struct mm_iommu_table_group_mem_t *mem) | |||
311 | unlock_exit: | 278 | unlock_exit: |
312 | mutex_unlock(&mem_list_mutex); | 279 | mutex_unlock(&mem_list_mutex); |
313 | 280 | ||
314 | mm_iommu_adjust_locked_vm(mm, unlock_entries, false); | 281 | account_locked_vm(mm, unlock_entries, false); |
315 | 282 | ||
316 | return ret; | 283 | return ret; |
317 | } | 284 | } |