1 #include <linux/mm.h>
2 #include <linux/hugetlb.h>
3 #include <linux/mount.h>
4 #include <linux/seq_file.h>
5 #include <linux/highmem.h>
6 #include <linux/ptrace.h>
7 #include <linux/pagemap.h>
8 #include <linux/ptrace.h>
9 #include <linux/mempolicy.h>
10 #include <linux/swap.h>
11 #include <linux/swapops.h>
12 #include <linux/seq_file.h>
13
14 #include <asm/elf.h>
15 #include <asm/uaccess.h>
16 #include <asm/tlbflush.h>
17 #include "internal.h"
18
19 void task_mem(struct seq_file *m, struct mm_struct *mm)
20 {
21 unsigned long data, text, lib;
22 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss;
23
24 /*
25 * Note: to minimize their overhead, mm maintains hiwater_vm and
26 * hiwater_rss only when about to *lower* total_vm or rss. Any
27 * collector of these hiwater stats must therefore get total_vm
28 * and rss too, which will usually be the higher. Barriers? not
29 * worth the effort, such snapshots can always be inconsistent.
30 */
31 hiwater_vm = total_vm = mm->total_vm;
32 if (hiwater_vm < mm->hiwater_vm)
33 hiwater_vm = mm->hiwater_vm;
34 hiwater_rss = total_rss = get_mm_rss(mm);
35 if (hiwater_rss < mm->hiwater_rss)
36 hiwater_rss = mm->hiwater_rss;
37
38 data = mm->total_vm - mm->shared_vm - mm->stack_vm;
39 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
40 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
41 seq_printf(m,
42 "VmPeak:\t%8lu kB\n"
43 "VmSize:\t%8lu kB\n"
44 "VmLck:\t%8lu kB\n"
45 "VmHWM:\t%8lu kB\n"
46 "VmRSS:\t%8lu kB\n"
47 "VmData:\t%8lu kB\n"
48 "VmStk:\t%8lu kB\n"
49 "VmExe:\t%8lu kB\n"
50 "VmLib:\t%8lu kB\n"
51 "VmPTE:\t%8lu kB\n",
52 hiwater_vm << (PAGE_SHIFT-10),
53 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
54 mm->locked_vm << (PAGE_SHIFT-10),
55 hiwater_rss << (PAGE_SHIFT-10),
56 total_rss << (PAGE_SHIFT-10),
57 data << (PAGE_SHIFT-10),
58 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
60 }
61
62 unsigned long task_vsize(struct mm_struct *mm)
63 {
64 return PAGE_SIZE * mm->total_vm;
65 }
66
67 int task_statm(struct mm_struct *mm, int *shared, int *text,
68 int *data, int *resident)
69 {
70 *shared = get_mm_counter(mm, file_rss);
71 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
72 >> PAGE_SHIFT;
73 *data = mm->total_vm - mm->shared_vm;
74 *resident = *shared + get_mm_counter(mm, anon_rss);
75 return mm->total_vm;
76 }
77
78 int proc_exe_link(struct inode *inode, struct path *path)
79 {
80 struct vm_area_struct * vma;
81 int result = -ENOENT;
82 struct task_struct *task = get_proc_task(inode);
83 struct mm_struct * mm = NULL;
84
85 if (task) {
86 mm = get_task_mm(task);
87 put_task_struct(task);
88 }
89 if (!mm)
90 goto out;
91 down_read(&mm->mmap_sem);
92
93 vma = mm->mmap;
94 while (vma) {
95 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
96 break;
97 vma = vma->vm_next;
98 }
99
100 if (vma) {
101 *path = vma->vm_file->f_path;
102 path_get(&vma->vm_file->f_path);
103 result = 0;
104 }
105
106 up_read(&mm->mmap_sem);
107 mmput(mm);
108 out:
109 return result;
110 }
111
112 static void pad_len_spaces(struct seq_file *m, int len)
113 {
114 len = 25 + sizeof(void*) * 6 - len;
115 if (len < 1)
116 len = 1;
117 seq_printf(m, "%*c", len, ' ');
118 }
119
120 static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
121 {
122 if (vma && vma != priv->tail_vma) {
123 struct mm_struct *mm = vma->vm_mm;
124 up_read(&mm->mmap_sem);
125 mmput(mm);
126 }
127 }
128
129 static void *m_start(struct seq_file *m, loff_t *pos)
130 {
131 struct proc_maps_private *priv = m->private;
132 unsigned long last_addr = m->version;
133 struct mm_struct *mm;
134 struct vm_area_struct *vma, *tail_vma = NULL;
135 loff_t l = *pos;
136
137 /* Clear the per syscall fields in priv */
138 priv->task = NULL;
139 priv->tail_vma = NULL;
140
141 /*
142 * We remember last_addr rather than next_addr to hit with
143 * mmap_cache most of the time. We have zero last_addr at
144 * the beginning and also after lseek. We will have -1 last_addr
145 * after the end of the vmas.
146 */
147
148 if (last_addr == -1UL)
149 return NULL;
150
151 priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
152 if (!priv->task)
153 return NULL;
154
155 mm = mm_for_maps(priv->task);
156 if (!mm)
157 return NULL;
158
159 tail_vma = get_gate_vma(priv->task);
160 priv->tail_vma = tail_vma;
161
162 /* Start with last addr hint */
163 vma = find_vma(mm, last_addr);
164 if (last_addr && vma) {
165 vma = vma->vm_next;
166 goto out;
167 }
168
169 /*
170 * Check the vma index is within the range and do
171 * sequential scan until m_index.
172 */
173 vma = NULL;
174 if ((unsigned long)l < mm->map_count) {
175 vma = mm->mmap;
176 while (l-- && vma) {
177 vma = vma->vm_next;
178 cond_resched();
179 }
180 goto out;
181 }
182
183 if (l != mm->map_count)
184 tail_vma = NULL; /* After gate vma */
185
186 out:
187 if (vma)
188 return vma;
189
190 /* End of vmas has been reached */
191 m->version = (tail_vma != NULL)? 0: -1UL;
192 up_read(&mm->mmap_sem);
193 mmput(mm);
194 return tail_vma;
195 }
196
197 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
198 {
199 struct proc_maps_private *priv = m->private;
200 struct vm_area_struct *vma = v;
201 struct vm_area_struct *tail_vma = priv->tail_vma;
202
203 (*pos)++;
204 if (vma && (vma != tail_vma) && vma->vm_next)
205 return vma->vm_next;
206 vma_stop(priv, vma);
207 return (vma != tail_vma)? tail_vma: NULL;
208 }
209
210 static void m_stop(struct seq_file *m, void *v)
211 {
212 struct proc_maps_private *priv = m->private;
213 struct vm_area_struct *vma = v;
214
215 vma_stop(priv, vma);
216 if (priv->task)
217 put_task_struct(priv->task);
218 }
219
220 static int do_maps_open(struct inode *inode, struct file *file,
221 const struct seq_operations *ops)
222 {
223 struct proc_maps_private *priv;
224 int ret = -ENOMEM;
225 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
226 if (priv) {
227 priv->pid = proc_pid(inode);
228 ret = seq_open(file, ops);
229 if (!ret) {
230 struct seq_file *m = file->private_data;
231 m->private = priv;
232 } else {
233 kfree(priv);
234 }
235 }
236 return ret;
237 }
238
239 static int show_map(struct seq_file *m, void *v)
240 {
241 struct proc_maps_private *priv = m->private;
242 struct task_struct *task = priv->task;
243 struct vm_area_struct *vma = v;
244 struct mm_struct *mm = vma->vm_mm;
245 struct file *file = vma->vm_file;
246 int flags = vma->vm_flags;
247 unsigned long ino = 0;
248 dev_t dev = 0;
249 int len;
250
251 if (maps_protect && !ptrace_may_attach(task))
252 return -EACCES;
253
254 if (file) {
255 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
256 dev = inode->i_sb->s_dev;
257 ino = inode->i_ino;
258 }
259
260 seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n",
261 vma->vm_start,
262 vma->vm_end,
263 flags & VM_READ ? 'r' : '-',
264 flags & VM_WRITE ? 'w' : '-',
265 flags & VM_EXEC ? 'x' : '-',
266 flags & VM_MAYSHARE ? 's' : 'p',
267 vma->vm_pgoff << PAGE_SHIFT,
268 MAJOR(dev), MINOR(dev), ino, &len);
269
270 /*
271 * Print the dentry name for named mappings, and a
272 * special [heap] marker for the heap:
273 */
274 if (file) {
275 pad_len_spaces(m, len);
276 seq_path(m, &file->f_path, "\n");
277 } else {
278 const char *name = arch_vma_name(vma);
279 if (!name) {
280 if (mm) {
281 if (vma->vm_start <= mm->start_brk &&
282 vma->vm_end >= mm->brk) {
283 name = "[heap]";
284 } else if (vma->vm_start <= mm->start_stack &&
285 vma->vm_end >= mm->start_stack) {
286 name = "[stack]";
287 }
288 } else {
289 name = "[vdso]";
290 }
291 }
292 if (name) {
293 pad_len_spaces(m, len);
294 seq_puts(m, name);
295 }
296 }
297 seq_putc(m, '\n');
298
299 if (m->count < m->size) /* vma is copied successfully */
300 m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
301 return 0;
302 }
303
304 static const struct seq_operations proc_pid_maps_op = {
305 .start = m_start,
306 .next = m_next,
307 .stop = m_stop,
308 .show = show_map
309 };
310
311 static int maps_open(struct inode *inode, struct file *file)
312 {
313 return do_maps_open(inode, file, &proc_pid_maps_op);
314 }
315
316 const struct file_operations proc_maps_operations = {
317 .open = maps_open,
318 .read = seq_read,
319 .llseek = seq_lseek,
320 .release = seq_release_private,
321 };
322
323 /*
324 * Proportional Set Size(PSS): my share of RSS.
325 *
326 * PSS of a process is the count of pages it has in memory, where each
327 * page is divided by the number of processes sharing it. So if a
328 * process has 1000 pages all to itself, and 1000 shared with one other
329 * process, its PSS will be 1500.
330 *
331 * To keep (accumulated) division errors low, we adopt a 64bit
332 * fixed-point pss counter to minimize division errors. So (pss >>
333 * PSS_SHIFT) would be the real byte count.
334 *
335 * A shift of 12 before division means (assuming 4K page size):
336 * - 1M 3-user-pages add up to 8KB errors;
337 * - supports mapcount up to 2^24, or 16M;
338 * - supports PSS up to 2^52 bytes, or 4PB.
339 */
340 #define PSS_SHIFT 12
341
342 #ifdef CONFIG_PROC_PAGE_MONITOR
343 struct mem_size_stats
344 {
345 struct vm_area_struct *vma;
346 unsigned long resident;
347 unsigned long shared_clean;
348 unsigned long shared_dirty;
349 unsigned long private_clean;
350 unsigned long private_dirty;
351 unsigned long referenced;
352 u64 pss;
353 };
354
355 static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
356 void *private)
357 {
358 struct mem_size_stats *mss = private;
359 struct vm_area_struct *vma = mss->vma;
360 pte_t *pte, ptent;
361 spinlock_t *ptl;
362 struct page *page;
363 int mapcount;
364
365 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
366 for (; addr != end; pte++, addr += PAGE_SIZE) {
367 ptent = *pte;
368 if (!pte_present(ptent))
369 continue;
370
371 mss->resident += PAGE_SIZE;
372
373 page = vm_normal_page(vma, addr, ptent);
374 if (!page)
375 continue;
376
377 /* Accumulate the size in pages that have been accessed. */
378 if (pte_young(ptent) || PageReferenced(page))
379 mss->referenced += PAGE_SIZE;
380 mapcount = page_mapcount(page);
381 if (mapcount >= 2) {
382 if (pte_dirty(ptent))
383 mss->shared_dirty += PAGE_SIZE;
384 else
385 mss->shared_clean += PAGE_SIZE;
386 mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
387 } else {
388 if (pte_dirty(ptent))
389 mss->private_dirty += PAGE_SIZE;
390 else
391 mss->private_clean += PAGE_SIZE;
392 mss->pss += (PAGE_SIZE << PSS_SHIFT);
393 }
394 }
395 pte_unmap_unlock(pte - 1, ptl);
396 cond_resched();
397 return 0;
398 }
399
400 static struct mm_walk smaps_walk = { .pmd_entry = smaps_pte_range };
401
402 static int show_smap(struct seq_file *m, void *v)
403 {
404 struct vm_area_struct *vma = v;
405 struct mem_size_stats mss;
406 int ret;
407
408 memset(&mss, 0, sizeof mss);
409 mss.vma = vma;
410 if (vma->vm_mm && !is_vm_hugetlb_page(vma))
411 walk_page_range(vma->vm_mm, vma->vm_start, vma->vm_end,
412 &smaps_walk, &mss);
413
414 ret = show_map(m, v);
415 if (ret)
416 return ret;
417
418 seq_printf(m,
419 "Size: %8lu kB\n"
420 "Rss: %8lu kB\n"
421 "Pss: %8lu kB\n"
422 "Shared_Clean: %8lu kB\n"
423 "Shared_Dirty: %8lu kB\n"
424 "Private_Clean: %8lu kB\n"
425 "Private_Dirty: %8lu kB\n"
426 "Referenced: %8lu kB\n",
427 (vma->vm_end - vma->vm_start) >> 10,
428 mss.resident >> 10,
429 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
430 mss.shared_clean >> 10,
431 mss.shared_dirty >> 10,
432 mss.private_clean >> 10,
433 mss.private_dirty >> 10,
434 mss.referenced >> 10);
435
436 return ret;
437 }
438
439 static const struct seq_operations proc_pid_smaps_op = {
440 .start = m_start,
441 .next = m_next,
442 .stop = m_stop,
443 .show = show_smap
444 };
445
446 static int smaps_open(struct inode *inode, struct file *file)
447 {
448 return do_maps_open(inode, file, &proc_pid_smaps_op);
449 }
450
451 const struct file_operations proc_smaps_operations = {
452 .open = smaps_open,
453 .read = seq_read,
454 .llseek = seq_lseek,
455 .release = seq_release_private,
456 };
457
458 static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
459 unsigned long end, void *private)
460 {
461 struct vm_area_struct *vma = private;
462 pte_t *pte, ptent;
463 spinlock_t *ptl;
464 struct page *page;
465
466 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
467 for (; addr != end; pte++, addr += PAGE_SIZE) {
468 ptent = *pte;
469 if (!pte_present(ptent))
470 continue;
471
472 page = vm_normal_page(vma, addr, ptent);
473 if (!page)
474 continue;
475
476 /* Clear accessed and referenced bits. */
477 ptep_test_and_clear_young(vma, addr, pte);
478 ClearPageReferenced(page);
479 }
480 pte_unmap_unlock(pte - 1, ptl);
481 cond_resched();
482 return 0;
483 }
484
485 static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range };
486
487 static ssize_t clear_refs_write(struct file *file, const char __user *buf,
488 size_t count, loff_t *ppos)
489 {
490 struct task_struct *task;
491 char buffer[PROC_NUMBUF], *end;
492 struct mm_struct *mm;
493 struct vm_area_struct *vma;
494
495 memset(buffer, 0, sizeof(buffer));
496 if (count > sizeof(buffer) - 1)
497 count = sizeof(buffer) - 1;
498 if (copy_from_user(buffer, buf, count))
499 return -EFAULT;
500 if (!simple_strtol(buffer, &end, 0))
501 return -EINVAL;
502 if (*end == '\n')
503 end++;
504 task = get_proc_task(file->f_path.dentry->d_inode);
505 if (!task)
506 return -ESRCH;
507 mm = get_task_mm(task);
508 if (mm) {
509 down_read(&mm->mmap_sem);
510 for (vma = mm->mmap; vma; vma = vma->vm_next)
511 if (!is_vm_hugetlb_page(vma))
512 walk_page_range(mm, vma->vm_start, vma->vm_end,
513 &clear_refs_walk, vma);
514 flush_tlb_mm(mm);
515 up_read(&mm->mmap_sem);
516 mmput(mm);
517 }
518 put_task_struct(task);
519 if (end - buffer == 0)
520 return -EIO;
521 return end - buffer;
522 }
523
524 const struct file_operations proc_clear_refs_operations = {
525 .write = clear_refs_write,
526 };
527
528 struct pagemapread {
529 u64 __user *out, *end;
530 };
531
532 #define PM_ENTRY_BYTES sizeof(u64)
533 #define PM_STATUS_BITS 3
534 #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS)
535 #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET)
536 #define PM_STATUS(nr) (((nr) << PM_STATUS_OFFSET) & PM_STATUS_MASK)
537 #define PM_PSHIFT_BITS 6
538 #define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS)
539 #define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET)
540 #define PM_PSHIFT(x) (((u64) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK)
541 #define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1)
542 #define PM_PFRAME(x) ((x) & PM_PFRAME_MASK)
543
544 #define PM_PRESENT PM_STATUS(4LL)
545 #define PM_SWAP PM_STATUS(2LL)
546 #define PM_NOT_PRESENT PM_PSHIFT(PAGE_SHIFT)
547 #define PM_END_OF_BUFFER 1
548
549 static int add_to_pagemap(unsigned long addr, u64 pfn,
550 struct pagemapread *pm)
551 {
552 if (put_user(pfn, pm->out))
553 return -EFAULT;
554 pm->out++;
555 if (pm->out >= pm->end)
556 return PM_END_OF_BUFFER;
557 return 0;
558 }
559
560 static int pagemap_pte_hole(unsigned long start, unsigned long end,
561 void *private)
562 {
563 struct pagemapread *pm = private;
564 unsigned long addr;
565 int err = 0;
566 for (addr = start; addr < end; addr += PAGE_SIZE) {
567 err = add_to_pagemap(addr, PM_NOT_PRESENT, pm);
568 if (err)
569 break;
570 }
571 return err;
572 }
573
574 u64 swap_pte_to_pagemap_entry(pte_t pte)
575 {
576 swp_entry_t e = pte_to_swp_entry(pte);
577 return swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT);
578 }
579
580 static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
581 void *private)
582 {
583 struct pagemapread *pm = private;
584 pte_t *pte;
585 int err = 0;
586
587 for (; addr != end; addr += PAGE_SIZE) {
588 u64 pfn = PM_NOT_PRESENT;
589 pte = pte_offset_map(pmd, addr);
590 if (is_swap_pte(*pte))
591 pfn = PM_PFRAME(swap_pte_to_pagemap_entry(*pte))
592 | PM_PSHIFT(PAGE_SHIFT) | PM_SWAP;
593 else if (pte_present(*pte))
594 pfn = PM_PFRAME(pte_pfn(*pte))
595 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT;
596 /* unmap so we're not in atomic when we copy to userspace */
597 pte_unmap(pte);
598 err = add_to_pagemap(addr, pfn, pm);
599 if (err)
600 return err;
601 }
602
603 cond_resched();
604
605 return err;
606 }
607
608 static struct mm_walk pagemap_walk = {
609 .pmd_entry = pagemap_pte_range,
610 .pte_hole = pagemap_pte_hole
611 };
612
613 /*
614 * /proc/pid/pagemap - an array mapping virtual pages to pfns
615 *
616 * For each page in the address space, this file contains one 64-bit entry
617 * consisting of the following:
618 *
619 * Bits 0-55 page frame number (PFN) if present
620 * Bits 0-4 swap type if swapped
621 * Bits 5-55 swap offset if swapped
622 * Bits 55-60 page shift (page size = 1<<page shift)
623 * Bit 61 reserved for future use
624 * Bit 62 page swapped
625 * Bit 63 page present
626 *
627 * If the page is not present but in swap, then the PFN contains an
628 * encoding of the swap file number and the page's offset into the
629 * swap. Unmapped pages return a null PFN. This allows determining
630 * precisely which pages are mapped (or in swap) and comparing mapped
631 * pages between processes.
632 *
633 * Efficient users of this interface will use /proc/pid/maps to
634 * determine which areas of memory are actually mapped and llseek to
635 * skip over unmapped regions.
636 */
637 static ssize_t pagemap_read(struct file *file, char __user *buf,
638 size_t count, loff_t *ppos)
639 {
640 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
641 struct page **pages, *page;
642 unsigned long uaddr, uend;
643 struct mm_struct *mm;
644 struct pagemapread pm;
645 int pagecount;
646 int ret = -ESRCH;
647
648 if (!task)
649 goto out;
650
651 ret = -EACCES;
652 if (!ptrace_may_attach(task))
653 goto out_task;
654
655 ret = -EINVAL;
656 /* file position must be aligned */
657 if ((*ppos % PM_ENTRY_BYTES) || (count % PM_ENTRY_BYTES))
658 goto out_task;
659
660 ret = 0;
661 mm = get_task_mm(task);
662 if (!mm)
663 goto out_task;
664
665 ret = -ENOMEM;
666 uaddr = (unsigned long)buf & PAGE_MASK;
667 uend = (unsigned long)(buf + count);
668 pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
669 pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
670 if (!pages)
671 goto out_mm;
672
673 down_read(¤t->mm->mmap_sem);
674 ret = get_user_pages(current, current->mm, uaddr, pagecount,
675 1, 0, pages, NULL);
676 up_read(¤t->mm->mmap_sem);
677
678 if (ret < 0)
679 goto out_free;
680
681 if (ret != pagecount) {
682 pagecount = ret;
683 ret = -EFAULT;
684 goto out_pages;
685 }
686
687 pm.out = (u64 *)buf;
688 pm.end = (u64 *)(buf + count);
689
690 if (!ptrace_may_attach(task)) {
691 ret = -EIO;
692 } else {
693 unsigned long src = *ppos;
694 unsigned long svpfn = src / PM_ENTRY_BYTES;
695 unsigned long start_vaddr = svpfn << PAGE_SHIFT;
696 unsigned long end_vaddr = TASK_SIZE_OF(task);
697
698 /* watch out for wraparound */
699 if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT)
700 start_vaddr = end_vaddr;
701
702 /*
703 * The odds are that this will stop walking way
704 * before end_vaddr, because the length of the
705 * user buffer is tracked in "pm", and the walk
706 * will stop when we hit the end of the buffer.
707 */
708 ret = walk_page_range(mm, start_vaddr, end_vaddr,
709 &pagemap_walk, &pm);
710 if (ret == PM_END_OF_BUFFER)
711 ret = 0;
712 /* don't need mmap_sem for these, but this looks cleaner */
713 *ppos += (char *)pm.out - buf;
714 if (!ret)
715 ret = (char *)pm.out - buf;
716 }
717
718 out_pages:
719 for (; pagecount; pagecount--) {
720 page = pages[pagecount-1];
721 if (!PageReserved(page))
722 SetPageDirty(page);
723 page_cache_release(page);
724 }
725 out_free:
726 kfree(pages);
727 out_mm:
728 mmput(mm);
729 out_task:
730 put_task_struct(task);
731 out:
732 return ret;
733 }
734
735 const struct file_operations proc_pagemap_operations = {
736 .llseek = mem_lseek, /* borrow this */
737 .read = pagemap_read,
738 };
739 #endif /* CONFIG_PROC_PAGE_MONITOR */
740
741 #ifdef CONFIG_NUMA
742 extern int show_numa_map(struct seq_file *m, void *v);
743
744 static int show_numa_map_checked(struct seq_file *m, void *v)
745 {
746 struct proc_maps_private *priv = m->private;
747 struct task_struct *task = priv->task;
748
749 if (maps_protect && !ptrace_may_attach(task))
750 return -EACCES;
751
752 return show_numa_map(m, v);
753 }
754
755 static const struct seq_operations proc_pid_numa_maps_op = {
756 .start = m_start,
757 .next = m_next,
758 .stop = m_stop,
759 .show = show_numa_map_checked
760 };
761
762 static int numa_maps_open(struct inode *inode, struct file *file)
763 {
764 return do_maps_open(inode, file, &proc_pid_numa_maps_op);
765 }
766
767 const struct file_operations proc_numa_maps_operations = {
768 .open = numa_maps_open,
769 .read = seq_read,
770 .llseek = seq_lseek,
771 .release = seq_release_private,
772 };
773 #endif
774
|
This page was automatically generated by the
LXR engine.
|