proc_misc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * linux/fs/proc/proc_misc.c
  3. *
  4. * linux/fs/proc/array.c
  5. * Copyright (C) 1992 by Linus Torvalds
  6. * based on ideas by Darren Senn
  7. *
  8. * This used to be the part of array.c. See the rest of history and credits
  9. * there. I took this into a separate file and switched the thing to generic
  10. * proc_file_inode_operations, leaving in array.c only per-process stuff.
  11. * Inumbers allocation made dynamic (via create_proc_entry()). AV, May 1999.
  12. *
  13. * Changes:
  14. * Fulton Green : Encapsulated position metric calculations.
  15. * <kernel@FultonGreen.com>
  16. */
  17. #include <linux/types.h>
  18. #include <linux/errno.h>
  19. #include <linux/time.h>
  20. #include <linux/kernel.h>
  21. #include <linux/kernel_stat.h>
  22. #include <linux/fs.h>
  23. #include <linux/tty.h>
  24. #include <linux/string.h>
  25. #include <linux/mman.h>
  26. #include <linux/quicklist.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/ioport.h>
  29. #include <linux/mm.h>
  30. #include <linux/mmzone.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/irq.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/swap.h>
  35. #include <linux/slab.h>
  36. #include <linux/genhd.h>
  37. #include <linux/smp.h>
  38. #include <linux/signal.h>
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/times.h>
  43. #include <linux/profile.h>
  44. #include <linux/utsname.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/hugetlb.h>
  47. #include <linux/jiffies.h>
  48. #include <linux/vmalloc.h>
  49. #include <linux/crash_dump.h>
  50. #include <linux/pid_namespace.h>
  51. #include <linux/bootmem.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/pgtable.h>
  54. #include <asm/io.h>
  55. #include <asm/tlb.h>
  56. #include <asm/div64.h>
  57. #include "internal.h"
  58. #ifdef CONFIG_PROC_PAGE_MONITOR
  59. #define KPMSIZE sizeof(u64)
  60. #define KPMMASK (KPMSIZE - 1)
  61. /* /proc/kpagecount - an array exposing page counts
  62. *
  63. * Each entry is a u64 representing the corresponding
  64. * physical page count.
  65. */
  66. static ssize_t kpagecount_read(struct file *file, char __user *buf,
  67. size_t count, loff_t *ppos)
  68. {
  69. u64 __user *out = (u64 __user *)buf;
  70. struct page *ppage;
  71. unsigned long src = *ppos;
  72. unsigned long pfn;
  73. ssize_t ret = 0;
  74. u64 pcount;
  75. pfn = src / KPMSIZE;
  76. count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
  77. if (src & KPMMASK || count & KPMMASK)
  78. return -EINVAL;
  79. while (count > 0) {
  80. ppage = NULL;
  81. if (pfn_valid(pfn))
  82. ppage = pfn_to_page(pfn);
  83. pfn++;
  84. if (!ppage)
  85. pcount = 0;
  86. else
  87. pcount = page_mapcount(ppage);
  88. if (put_user(pcount, out++)) {
  89. ret = -EFAULT;
  90. break;
  91. }
  92. count -= KPMSIZE;
  93. }
  94. *ppos += (char __user *)out - buf;
  95. if (!ret)
  96. ret = (char __user *)out - buf;
  97. return ret;
  98. }
  99. static struct file_operations proc_kpagecount_operations = {
  100. .llseek = mem_lseek,
  101. .read = kpagecount_read,
  102. };
  103. /* /proc/kpageflags - an array exposing page flags
  104. *
  105. * Each entry is a u64 representing the corresponding
  106. * physical page flags.
  107. */
  108. /* These macros are used to decouple internal flags from exported ones */
  109. #define KPF_LOCKED 0
  110. #define KPF_ERROR 1
  111. #define KPF_REFERENCED 2
  112. #define KPF_UPTODATE 3
  113. #define KPF_DIRTY 4
  114. #define KPF_LRU 5
  115. #define KPF_ACTIVE 6
  116. #define KPF_SLAB 7
  117. #define KPF_WRITEBACK 8
  118. #define KPF_RECLAIM 9
  119. #define KPF_BUDDY 10
  120. #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
  121. static ssize_t kpageflags_read(struct file *file, char __user *buf,
  122. size_t count, loff_t *ppos)
  123. {
  124. u64 __user *out = (u64 __user *)buf;
  125. struct page *ppage;
  126. unsigned long src = *ppos;
  127. unsigned long pfn;
  128. ssize_t ret = 0;
  129. u64 kflags, uflags;
  130. pfn = src / KPMSIZE;
  131. count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
  132. if (src & KPMMASK || count & KPMMASK)
  133. return -EINVAL;
  134. while (count > 0) {
  135. ppage = NULL;
  136. if (pfn_valid(pfn))
  137. ppage = pfn_to_page(pfn);
  138. pfn++;
  139. if (!ppage)
  140. kflags = 0;
  141. else
  142. kflags = ppage->flags;
  143. uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
  144. kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
  145. kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
  146. kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
  147. kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
  148. kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
  149. kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
  150. kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
  151. kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
  152. kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
  153. kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
  154. if (put_user(uflags, out++)) {
  155. ret = -EFAULT;
  156. break;
  157. }
  158. count -= KPMSIZE;
  159. }
  160. *ppos += (char __user *)out - buf;
  161. if (!ret)
  162. ret = (char __user *)out - buf;
  163. return ret;
  164. }
  165. static struct file_operations proc_kpageflags_operations = {
  166. .llseek = mem_lseek,
  167. .read = kpageflags_read,
  168. };
  169. #endif /* CONFIG_PROC_PAGE_MONITOR */
  170. struct proc_dir_entry *proc_root_kcore;
  171. void __init proc_misc_init(void)
  172. {
  173. proc_symlink("mounts", NULL, "self/mounts");
  174. /* And now for trickier ones */
  175. #ifdef CONFIG_SCHEDSTATS
  176. proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
  177. #endif
  178. #ifdef CONFIG_PROC_KCORE
  179. proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
  180. if (proc_root_kcore)
  181. proc_root_kcore->size =
  182. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  183. #endif
  184. #ifdef CONFIG_PROC_PAGE_MONITOR
  185. proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
  186. proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
  187. #endif
  188. #ifdef CONFIG_PROC_VMCORE
  189. proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
  190. #endif
  191. }