diff options
Diffstat (limited to 'fs/proc/task_mmu.c')
-rw-r--r-- | fs/proc/task_mmu.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index abc44f39f1d6..fcdbd233f252 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -323,19 +323,47 @@ static int show_smap(struct seq_file *m, void *v) static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range }; -void clear_refs_smap(struct mm_struct *mm) +static ssize_t clear_refs_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) { + struct task_struct *task; + char buffer[PROC_NUMBUF], *end; + struct mm_struct *mm; struct vm_area_struct *vma; - down_read(&mm->mmap_sem); - for (vma = mm->mmap; vma; vma = vma->vm_next) - if (vma->vm_mm && !is_vm_hugetlb_page(vma)) - walk_page_range(vma->vm_mm, vma->vm_start, vma->vm_end, - &clear_refs_walk, vma); - flush_tlb_mm(mm); - up_read(&mm->mmap_sem); + memset(buffer, 0, sizeof(buffer)); + if (count > sizeof(buffer) - 1) + count = sizeof(buffer) - 1; + if (copy_from_user(buffer, buf, count)) + return -EFAULT; + if (!simple_strtol(buffer, &end, 0)) + return -EINVAL; + if (*end == '\n') + end++; + task = get_proc_task(file->f_path.dentry->d_inode); + if (!task) + return -ESRCH; + mm = get_task_mm(task); + if (mm) { + down_read(&mm->mmap_sem); + for (vma = mm->mmap; vma; vma = vma->vm_next) + if (!is_vm_hugetlb_page(vma)) + walk_page_range(mm, vma->vm_start, vma->vm_end, + &clear_refs_walk, vma); + flush_tlb_mm(mm); + up_read(&mm->mmap_sem); + mmput(mm); + } + put_task_struct(task); + if (end - buffer == 0) + return -EIO; + return end - buffer; } +const struct file_operations proc_clear_refs_operations = { + .write = clear_refs_write, +}; + static void *m_start(struct seq_file *m, loff_t *pos) { struct proc_maps_private *priv = m->private; |