summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSumit Semwal <sumit.semwal@linaro.org>2020-08-21 17:05:27 +0530
committerSumit Semwal <sumit.semwal@linaro.org>2020-08-31 18:40:23 +0530
commitc80d26c88435ee1ab3475736ed3f39df80fd5694 (patch)
treec80b7d643bc527c39a9103a0c4f7ee4b7f4bdac3
parentbc1b06ef99058236e3cacb199d18b854d5c6fd2a (diff)
Revert "ANDROID: mm: add a field to store names for private anonymous memory"
This reverts commit d5cd22fded2b47e46ac02744c118d25070d5bc09.
-rw-r--r--Documentation/filesystems/proc.rst6
-rw-r--r--fs/proc/task_mmu.c64
-rw-r--r--fs/userfaultfd.c9
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/mm_types.h24
-rw-r--r--include/uapi/linux/prctl.h3
-rw-r--r--kernel/sys.c152
-rw-r--r--mm/madvise.c2
-rw-r--r--mm/mempolicy.c3
-rw-r--r--mm/mlock.c2
-rw-r--r--mm/mmap.c39
-rw-r--r--mm/mprotect.c2
12 files changed, 28 insertions, 280 deletions
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 6016b0b60321..533c79e8d2cd 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -429,8 +429,6 @@ is not associated with a file:
[stack] the stack of the main process
[vdso] the "virtual dynamic shared object",
the kernel system call handler
- [anon:<name>] an anonymous mapping that has been
- named by userspace
======= ====================================
or if empty, the mapping is anonymous.
@@ -464,7 +462,6 @@ Memory Area, or VMA) there is a series of lines such as the following::
Locked: 0 kB
THPeligible: 0
VmFlags: rd ex mr mw me dw
- Name: name from userspace
The first of these lines shows the same information as is displayed for the
mapping in /proc/PID/maps. Following lines show the size of the mapping
@@ -557,9 +554,6 @@ be vanished or the reverse -- new added. Interpretation of their meaning
might change in future as well. So each consumer of these flags has to
follow each specific kernel version for the exact semantic.
-The "Name" field will only be present on a mapping that has been named by
-userspace, and will show the name passed in by userspace.
-
This file is only present if the CONFIG_MMU kernel configuration option is
enabled.
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index b5b31f8dd887..5066b0251ed8 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -123,56 +123,6 @@ static void release_task_mempolicy(struct proc_maps_private *priv)
}
#endif
-static void seq_print_vma_name(struct seq_file *m, struct vm_area_struct *vma)
-{
- const char __user *name = vma_get_anon_name(vma);
- struct mm_struct *mm = vma->vm_mm;
-
- unsigned long page_start_vaddr;
- unsigned long page_offset;
- unsigned long num_pages;
- unsigned long max_len = NAME_MAX;
- int i;
-
- page_start_vaddr = (unsigned long)name & PAGE_MASK;
- page_offset = (unsigned long)name - page_start_vaddr;
- num_pages = DIV_ROUND_UP(page_offset + max_len, PAGE_SIZE);
-
- seq_puts(m, "[anon:");
-
- for (i = 0; i < num_pages; i++) {
- int len;
- int write_len;
- const char *kaddr;
- long pages_pinned;
- struct page *page;
-
- pages_pinned = get_user_pages_remote(current, mm,
- page_start_vaddr, 1, 0, &page, NULL, NULL);
- if (pages_pinned < 1) {
- seq_puts(m, "<fault>]");
- return;
- }
-
- kaddr = (const char *)kmap(page);
- len = min(max_len, PAGE_SIZE - page_offset);
- write_len = strnlen(kaddr + page_offset, len);
- seq_write(m, kaddr + page_offset, write_len);
- kunmap(page);
- put_page(page);
-
- /* if strnlen hit a null terminator then we're done */
- if (write_len != len)
- break;
-
- max_len -= len;
- page_offset = 0;
- page_start_vaddr += PAGE_SIZE;
- }
-
- seq_putc(m, ']');
-}
-
static void *m_start(struct seq_file *m, loff_t *ppos)
{
struct proc_maps_private *priv = m->private;
@@ -369,15 +319,8 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
goto done;
}
- if (is_stack(vma)) {
+ if (is_stack(vma))
name = "[stack]";
- goto done;
- }
-
- if (vma_get_anon_name(vma)) {
- seq_pad(m, ' ');
- seq_print_vma_name(m, vma);
- }
}
done:
@@ -865,11 +808,6 @@ static int show_smap(struct seq_file *m, void *v)
smap_gather_stats(vma, &mss);
show_map_vma(m, vma);
- if (vma_get_anon_name(vma)) {
- seq_puts(m, "Name: ");
- seq_print_vma_name(m, vma);
- seq_putc(m, '\n');
- }
SEQ_PUT_DEC("Size: ", vma->vm_end - vma->vm_start);
SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma));
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 2b6233baf7c3..0e4a3837da52 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -874,8 +874,7 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
new_flags, vma->anon_vma,
vma->vm_file, vma->vm_pgoff,
vma_policy(vma),
- NULL_VM_UFFD_CTX,
- vma_get_anon_name(vma));
+ NULL_VM_UFFD_CTX);
if (prev)
vma = prev;
else
@@ -1426,8 +1425,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
prev = vma_merge(mm, prev, start, vma_end, new_flags,
vma->anon_vma, vma->vm_file, vma->vm_pgoff,
vma_policy(vma),
- ((struct vm_userfaultfd_ctx){ ctx }),
- vma_get_anon_name(vma));
+ ((struct vm_userfaultfd_ctx){ ctx }));
if (prev) {
vma = prev;
goto next;
@@ -1599,8 +1597,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
prev = vma_merge(mm, prev, start, vma_end, new_flags,
vma->anon_vma, vma->vm_file, vma->vm_pgoff,
vma_policy(vma),
- NULL_VM_UFFD_CTX,
- vma_get_anon_name(vma));
+ NULL_VM_UFFD_CTX);
if (prev) {
vma = prev;
goto next;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index a0f1e361f31d..ca6e6a81576b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2489,7 +2489,7 @@ static inline int vma_adjust(struct vm_area_struct *vma, unsigned long start,
extern struct vm_area_struct *vma_merge(struct mm_struct *,
struct vm_area_struct *prev, unsigned long addr, unsigned long end,
unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,
- struct mempolicy *, struct vm_userfaultfd_ctx, const char __user *);
+ struct mempolicy *, struct vm_userfaultfd_ctx);
extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);
extern int __split_vma(struct mm_struct *, struct vm_area_struct *,
unsigned long addr, int new_below);
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 9103b83eb1b0..496c3ff97cce 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -336,18 +336,11 @@ struct vm_area_struct {
/*
* For areas with an address space and backing store,
* linkage into the address_space->i_mmap interval tree.
- *
- * For private anonymous mappings, a pointer to a null terminated string
- * in the user process containing the name given to the vma, or NULL
- * if unnamed.
*/
- union {
- struct {
- struct rb_node rb;
- unsigned long rb_subtree_last;
- } shared;
- const char __user *anon_name;
- };
+ struct {
+ struct rb_node rb;
+ unsigned long rb_subtree_last;
+ } shared;
/*
* A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
@@ -779,13 +772,4 @@ typedef struct {
unsigned long val;
} swp_entry_t;
-/* Return the name for an anonymous mapping or NULL for a file-backed mapping */
-static inline const char __user *vma_get_anon_name(struct vm_area_struct *vma)
-{
- if (vma->vm_file)
- return NULL;
-
- return vma->anon_name;
-}
-
#endif /* _LINUX_MM_TYPES_H */
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 10773270f67b..07b4f8131e36 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -238,7 +238,4 @@ struct prctl_mm_map {
#define PR_SET_IO_FLUSHER 57
#define PR_GET_IO_FLUSHER 58
-#define PR_SET_VMA 0x53564d41
-# define PR_SET_VMA_ANON_NAME 0
-
#endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sys.c b/kernel/sys.c
index a29a9e240ff2..ab6c409b1159 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -42,8 +42,6 @@
#include <linux/syscore_ops.h>
#include <linux/version.h>
#include <linux/ctype.h>
-#include <linux/mm.h>
-#include <linux/mempolicy.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
@@ -2280,153 +2278,6 @@ int __weak arch_prctl_spec_ctrl_set(struct task_struct *t, unsigned long which,
return -EINVAL;
}
-#ifdef CONFIG_MMU
-static int prctl_update_vma_anon_name(struct vm_area_struct *vma,
- struct vm_area_struct **prev,
- unsigned long start, unsigned long end,
- const char __user *name_addr)
-{
- struct mm_struct *mm = vma->vm_mm;
- int error = 0;
- pgoff_t pgoff;
-
- if (name_addr == vma_get_anon_name(vma)) {
- *prev = vma;
- goto out;
- }
-
- pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
- *prev = vma_merge(mm, *prev, start, end, vma->vm_flags, vma->anon_vma,
- vma->vm_file, pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, name_addr);
- if (*prev) {
- vma = *prev;
- goto success;
- }
-
- *prev = vma;
-
- if (start != vma->vm_start) {
- error = split_vma(mm, vma, start, 1);
- if (error)
- goto out;
- }
-
- if (end != vma->vm_end) {
- error = split_vma(mm, vma, end, 0);
- if (error)
- goto out;
- }
-
-success:
- if (!vma->vm_file)
- vma->anon_name = name_addr;
-
-out:
- if (error == -ENOMEM)
- error = -EAGAIN;
- return error;
-}
-
-static int prctl_set_vma_anon_name(unsigned long start, unsigned long end,
- unsigned long arg)
-{
- unsigned long tmp;
- struct vm_area_struct *vma, *prev;
- int unmapped_error = 0;
- int error = -EINVAL;
-
- /*
- * If the interval [start,end) covers some unmapped address
- * ranges, just ignore them, but return -ENOMEM at the end.
- * - this matches the handling in madvise.
- */
- vma = find_vma_prev(current->mm, start, &prev);
- if (vma && start > vma->vm_start)
- prev = vma;
-
- for (;;) {
- /* Still start < end. */
- error = -ENOMEM;
- if (!vma)
- return error;
-
- /* Here start < (end|vma->vm_end). */
- if (start < vma->vm_start) {
- unmapped_error = -ENOMEM;
- start = vma->vm_start;
- if (start >= end)
- return error;
- }
-
- /* Here vma->vm_start <= start < (end|vma->vm_end) */
- tmp = vma->vm_end;
- if (end < tmp)
- tmp = end;
-
- /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */
- error = prctl_update_vma_anon_name(vma, &prev, start, tmp,
- (const char __user *)arg);
- if (error)
- return error;
- start = tmp;
- if (prev && start < prev->vm_end)
- start = prev->vm_end;
- error = unmapped_error;
- if (start >= end)
- return error;
- if (prev)
- vma = prev->vm_next;
- else /* madvise_remove dropped mmap_sem */
- vma = find_vma(current->mm, start);
- }
-}
-
-static int prctl_set_vma(unsigned long opt, unsigned long start,
- unsigned long len_in, unsigned long arg)
-{
- struct mm_struct *mm = current->mm;
- int error;
- unsigned long len;
- unsigned long end;
-
- if (start & ~PAGE_MASK)
- return -EINVAL;
- len = (len_in + ~PAGE_MASK) & PAGE_MASK;
-
- /* Check to see whether len was rounded up from small -ve to zero */
- if (len_in && !len)
- return -EINVAL;
-
- end = start + len;
- if (end < start)
- return -EINVAL;
-
- if (end == start)
- return 0;
-
- mmap_write_lock(mm);
-
- switch (opt) {
- case PR_SET_VMA_ANON_NAME:
- error = prctl_set_vma_anon_name(start, end, arg);
- break;
- default:
- error = -EINVAL;
- }
-
- mmap_write_unlock(mm);
-
- return error;
-}
-#else /* CONFIG_MMU */
-static int prctl_set_vma(unsigned long opt, unsigned long start,
- unsigned long len_in, unsigned long arg)
-{
- return -EINVAL;
-}
-#endif
-
#define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE)
SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
@@ -2641,9 +2492,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
return -EINVAL;
error = arch_prctl_spec_ctrl_set(me, arg2, arg3);
break;
- case PR_SET_VMA:
- error = prctl_set_vma(arg2, arg3, arg4, arg5);
- break;
case PR_PAC_RESET_KEYS:
if (arg3 || arg4 || arg5)
return -EINVAL;
diff --git a/mm/madvise.c b/mm/madvise.c
index 3fd89037f472..dd1d43cf026d 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -135,7 +135,7 @@ static long madvise_behavior(struct vm_area_struct *vma,
pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
*prev = vma_merge(mm, *prev, start, end, new_flags, vma->anon_vma,
vma->vm_file, pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, vma_get_anon_name(vma));
+ vma->vm_userfaultfd_ctx);
if (*prev) {
vma = *prev;
goto success;
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 133ec4a89faf..eddbe4e56c73 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -829,8 +829,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
((vmstart - vma->vm_start) >> PAGE_SHIFT);
prev = vma_merge(mm, prev, vmstart, vmend, vma->vm_flags,
vma->anon_vma, vma->vm_file, pgoff,
- new_pol, vma->vm_userfaultfd_ctx,
- vma_get_anon_name(vma));
+ new_pol, vma->vm_userfaultfd_ctx);
if (prev) {
vma = prev;
next = vma->vm_next;
diff --git a/mm/mlock.c b/mm/mlock.c
index b845a66d421b..93ca2bf30b4f 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -534,7 +534,7 @@ static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
*prev = vma_merge(mm, *prev, start, end, newflags, vma->anon_vma,
vma->vm_file, pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, vma_get_anon_name(vma));
+ vma->vm_userfaultfd_ctx);
if (*prev) {
vma = *prev;
goto success;
diff --git a/mm/mmap.c b/mm/mmap.c
index 2260a9ad9f78..40248d84ad5f 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -987,8 +987,7 @@ again:
*/
static inline int is_mergeable_vma(struct vm_area_struct *vma,
struct file *file, unsigned long vm_flags,
- struct vm_userfaultfd_ctx vm_userfaultfd_ctx,
- const char __user *anon_name)
+ struct vm_userfaultfd_ctx vm_userfaultfd_ctx)
{
/*
* VM_SOFTDIRTY should not prevent from VMA merging, if we
@@ -1006,8 +1005,6 @@ static inline int is_mergeable_vma(struct vm_area_struct *vma,
return 0;
if (!is_mergeable_vm_userfaultfd_ctx(vma, vm_userfaultfd_ctx))
return 0;
- if (vma_get_anon_name(vma) != anon_name)
- return 0;
return 1;
}
@@ -1040,10 +1037,9 @@ static int
can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
struct anon_vma *anon_vma, struct file *file,
pgoff_t vm_pgoff,
- struct vm_userfaultfd_ctx vm_userfaultfd_ctx,
- const char __user *anon_name)
+ struct vm_userfaultfd_ctx vm_userfaultfd_ctx)
{
- if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) &&
+ if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx) &&
is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
if (vma->vm_pgoff == vm_pgoff)
return 1;
@@ -1062,10 +1058,9 @@ static int
can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
struct anon_vma *anon_vma, struct file *file,
pgoff_t vm_pgoff,
- struct vm_userfaultfd_ctx vm_userfaultfd_ctx,
- const char __user *anon_name)
+ struct vm_userfaultfd_ctx vm_userfaultfd_ctx)
{
- if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) &&
+ if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx) &&
is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
pgoff_t vm_pglen;
vm_pglen = vma_pages(vma);
@@ -1076,9 +1071,9 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
}
/*
- * Given a mapping request (addr,end,vm_flags,file,pgoff,anon_name),
- * figure out whether that can be merged with its predecessor or its
- * successor. Or both (it neatly fills a hole).
+ * Given a mapping request (addr,end,vm_flags,file,pgoff), figure out
+ * whether that can be merged with its predecessor or its successor.
+ * Or both (it neatly fills a hole).
*
* In most cases - when called for mmap, brk or mremap - [addr,end) is
* certain not to be mapped by the time vma_merge is called; but when
@@ -1123,8 +1118,7 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
unsigned long end, unsigned long vm_flags,
struct anon_vma *anon_vma, struct file *file,
pgoff_t pgoff, struct mempolicy *policy,
- struct vm_userfaultfd_ctx vm_userfaultfd_ctx,
- const char __user *anon_name)
+ struct vm_userfaultfd_ctx vm_userfaultfd_ctx)
{
pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
struct vm_area_struct *area, *next;
@@ -1157,8 +1151,7 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
mpol_equal(vma_policy(prev), policy) &&
can_vma_merge_after(prev, vm_flags,
anon_vma, file, pgoff,
- vm_userfaultfd_ctx,
- anon_name)) {
+ vm_userfaultfd_ctx)) {
/*
* OK, it can. Can we now merge in the successor as well?
*/
@@ -1167,8 +1160,7 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
can_vma_merge_before(next, vm_flags,
anon_vma, file,
pgoff+pglen,
- vm_userfaultfd_ctx,
- anon_name) &&
+ vm_userfaultfd_ctx) &&
is_mergeable_anon_vma(prev->anon_vma,
next->anon_vma, NULL)) {
/* cases 1, 6 */
@@ -1191,8 +1183,7 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
mpol_equal(policy, vma_policy(next)) &&
can_vma_merge_before(next, vm_flags,
anon_vma, file, pgoff+pglen,
- vm_userfaultfd_ctx,
- anon_name)) {
+ vm_userfaultfd_ctx)) {
if (prev && addr < prev->vm_end) /* case 4 */
err = __vma_adjust(prev, prev->vm_start,
addr, prev->vm_pgoff, NULL, next);
@@ -1740,7 +1731,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
* Can we just expand an old mapping?
*/
vma = vma_merge(mm, prev, addr, addr + len, vm_flags,
- NULL, file, pgoff, NULL, NULL_VM_UFFD_CTX, NULL);
+ NULL, file, pgoff, NULL, NULL_VM_UFFD_CTX);
if (vma)
goto out;
@@ -3072,7 +3063,7 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla
/* Can we just expand an old private anonymous mapping? */
vma = vma_merge(mm, prev, addr, addr + len, flags,
- NULL, NULL, pgoff, NULL, NULL_VM_UFFD_CTX, NULL);
+ NULL, NULL, pgoff, NULL, NULL_VM_UFFD_CTX);
if (vma)
goto out;
@@ -3271,7 +3262,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
return NULL; /* should never get here */
new_vma = vma_merge(mm, prev, addr, addr + len, vma->vm_flags,
vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, vma_get_anon_name(vma));
+ vma->vm_userfaultfd_ctx);
if (new_vma) {
/*
* Source vma may have been merged into new_vma
diff --git a/mm/mprotect.c b/mm/mprotect.c
index 97529ba11a3b..ce8b8a5eacbb 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -454,7 +454,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
*pprev = vma_merge(mm, *pprev, start, end, newflags,
vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, vma_get_anon_name(vma));
+ vma->vm_userfaultfd_ctx);
if (*pprev) {
vma = *pprev;
VM_WARN_ON((vma->vm_flags ^ newflags) & ~VM_SOFTDIRTY);