Commit e07a4b9217d1e97d2f3a62b6b070efdc61212110
Committed by
Alexey Dobriyan
1 parent
f7e603ad8f
Exists in
master
and in
7 other branches
proc: fix PG_locked reporting in /proc/kpageflags
Expr always evaluates to zero. Cc: Matt Mackall <mpm@selenic.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
fs/proc/page.c
1 | #include <linux/bootmem.h> | 1 | #include <linux/bootmem.h> |
2 | #include <linux/compiler.h> | 2 | #include <linux/compiler.h> |
3 | #include <linux/fs.h> | 3 | #include <linux/fs.h> |
4 | #include <linux/init.h> | 4 | #include <linux/init.h> |
5 | #include <linux/mm.h> | 5 | #include <linux/mm.h> |
6 | #include <linux/mmzone.h> | 6 | #include <linux/mmzone.h> |
7 | #include <linux/proc_fs.h> | 7 | #include <linux/proc_fs.h> |
8 | #include <linux/seq_file.h> | 8 | #include <linux/seq_file.h> |
9 | #include <asm/uaccess.h> | 9 | #include <asm/uaccess.h> |
10 | #include "internal.h" | 10 | #include "internal.h" |
11 | 11 | ||
12 | #define KPMSIZE sizeof(u64) | 12 | #define KPMSIZE sizeof(u64) |
13 | #define KPMMASK (KPMSIZE - 1) | 13 | #define KPMMASK (KPMSIZE - 1) |
14 | /* /proc/kpagecount - an array exposing page counts | 14 | /* /proc/kpagecount - an array exposing page counts |
15 | * | 15 | * |
16 | * Each entry is a u64 representing the corresponding | 16 | * Each entry is a u64 representing the corresponding |
17 | * physical page count. | 17 | * physical page count. |
18 | */ | 18 | */ |
19 | static ssize_t kpagecount_read(struct file *file, char __user *buf, | 19 | static ssize_t kpagecount_read(struct file *file, char __user *buf, |
20 | size_t count, loff_t *ppos) | 20 | size_t count, loff_t *ppos) |
21 | { | 21 | { |
22 | u64 __user *out = (u64 __user *)buf; | 22 | u64 __user *out = (u64 __user *)buf; |
23 | struct page *ppage; | 23 | struct page *ppage; |
24 | unsigned long src = *ppos; | 24 | unsigned long src = *ppos; |
25 | unsigned long pfn; | 25 | unsigned long pfn; |
26 | ssize_t ret = 0; | 26 | ssize_t ret = 0; |
27 | u64 pcount; | 27 | u64 pcount; |
28 | 28 | ||
29 | pfn = src / KPMSIZE; | 29 | pfn = src / KPMSIZE; |
30 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); | 30 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); |
31 | if (src & KPMMASK || count & KPMMASK) | 31 | if (src & KPMMASK || count & KPMMASK) |
32 | return -EINVAL; | 32 | return -EINVAL; |
33 | 33 | ||
34 | while (count > 0) { | 34 | while (count > 0) { |
35 | ppage = NULL; | 35 | ppage = NULL; |
36 | if (pfn_valid(pfn)) | 36 | if (pfn_valid(pfn)) |
37 | ppage = pfn_to_page(pfn); | 37 | ppage = pfn_to_page(pfn); |
38 | pfn++; | 38 | pfn++; |
39 | if (!ppage) | 39 | if (!ppage) |
40 | pcount = 0; | 40 | pcount = 0; |
41 | else | 41 | else |
42 | pcount = page_mapcount(ppage); | 42 | pcount = page_mapcount(ppage); |
43 | 43 | ||
44 | if (put_user(pcount, out++)) { | 44 | if (put_user(pcount, out++)) { |
45 | ret = -EFAULT; | 45 | ret = -EFAULT; |
46 | break; | 46 | break; |
47 | } | 47 | } |
48 | 48 | ||
49 | count -= KPMSIZE; | 49 | count -= KPMSIZE; |
50 | } | 50 | } |
51 | 51 | ||
52 | *ppos += (char __user *)out - buf; | 52 | *ppos += (char __user *)out - buf; |
53 | if (!ret) | 53 | if (!ret) |
54 | ret = (char __user *)out - buf; | 54 | ret = (char __user *)out - buf; |
55 | return ret; | 55 | return ret; |
56 | } | 56 | } |
57 | 57 | ||
58 | static const struct file_operations proc_kpagecount_operations = { | 58 | static const struct file_operations proc_kpagecount_operations = { |
59 | .llseek = mem_lseek, | 59 | .llseek = mem_lseek, |
60 | .read = kpagecount_read, | 60 | .read = kpagecount_read, |
61 | }; | 61 | }; |
62 | 62 | ||
63 | /* /proc/kpageflags - an array exposing page flags | 63 | /* /proc/kpageflags - an array exposing page flags |
64 | * | 64 | * |
65 | * Each entry is a u64 representing the corresponding | 65 | * Each entry is a u64 representing the corresponding |
66 | * physical page flags. | 66 | * physical page flags. |
67 | */ | 67 | */ |
68 | 68 | ||
69 | /* These macros are used to decouple internal flags from exported ones */ | 69 | /* These macros are used to decouple internal flags from exported ones */ |
70 | 70 | ||
71 | #define KPF_LOCKED 0 | 71 | #define KPF_LOCKED 0 |
72 | #define KPF_ERROR 1 | 72 | #define KPF_ERROR 1 |
73 | #define KPF_REFERENCED 2 | 73 | #define KPF_REFERENCED 2 |
74 | #define KPF_UPTODATE 3 | 74 | #define KPF_UPTODATE 3 |
75 | #define KPF_DIRTY 4 | 75 | #define KPF_DIRTY 4 |
76 | #define KPF_LRU 5 | 76 | #define KPF_LRU 5 |
77 | #define KPF_ACTIVE 6 | 77 | #define KPF_ACTIVE 6 |
78 | #define KPF_SLAB 7 | 78 | #define KPF_SLAB 7 |
79 | #define KPF_WRITEBACK 8 | 79 | #define KPF_WRITEBACK 8 |
80 | #define KPF_RECLAIM 9 | 80 | #define KPF_RECLAIM 9 |
81 | #define KPF_BUDDY 10 | 81 | #define KPF_BUDDY 10 |
82 | 82 | ||
83 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) | 83 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) |
84 | 84 | ||
85 | static ssize_t kpageflags_read(struct file *file, char __user *buf, | 85 | static ssize_t kpageflags_read(struct file *file, char __user *buf, |
86 | size_t count, loff_t *ppos) | 86 | size_t count, loff_t *ppos) |
87 | { | 87 | { |
88 | u64 __user *out = (u64 __user *)buf; | 88 | u64 __user *out = (u64 __user *)buf; |
89 | struct page *ppage; | 89 | struct page *ppage; |
90 | unsigned long src = *ppos; | 90 | unsigned long src = *ppos; |
91 | unsigned long pfn; | 91 | unsigned long pfn; |
92 | ssize_t ret = 0; | 92 | ssize_t ret = 0; |
93 | u64 kflags, uflags; | 93 | u64 kflags, uflags; |
94 | 94 | ||
95 | pfn = src / KPMSIZE; | 95 | pfn = src / KPMSIZE; |
96 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); | 96 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); |
97 | if (src & KPMMASK || count & KPMMASK) | 97 | if (src & KPMMASK || count & KPMMASK) |
98 | return -EINVAL; | 98 | return -EINVAL; |
99 | 99 | ||
100 | while (count > 0) { | 100 | while (count > 0) { |
101 | ppage = NULL; | 101 | ppage = NULL; |
102 | if (pfn_valid(pfn)) | 102 | if (pfn_valid(pfn)) |
103 | ppage = pfn_to_page(pfn); | 103 | ppage = pfn_to_page(pfn); |
104 | pfn++; | 104 | pfn++; |
105 | if (!ppage) | 105 | if (!ppage) |
106 | kflags = 0; | 106 | kflags = 0; |
107 | else | 107 | else |
108 | kflags = ppage->flags; | 108 | kflags = ppage->flags; |
109 | 109 | ||
110 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | | 110 | uflags = kpf_copy_bit(kflags, KPF_LOCKED, PG_locked) | |
111 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | | 111 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | |
112 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | | 112 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | |
113 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | | 113 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | |
114 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | | 114 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | |
115 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | | 115 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | |
116 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | | 116 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | |
117 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | | 117 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | |
118 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | | 118 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | |
119 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | | 119 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | |
120 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); | 120 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); |
121 | 121 | ||
122 | if (put_user(uflags, out++)) { | 122 | if (put_user(uflags, out++)) { |
123 | ret = -EFAULT; | 123 | ret = -EFAULT; |
124 | break; | 124 | break; |
125 | } | 125 | } |
126 | 126 | ||
127 | count -= KPMSIZE; | 127 | count -= KPMSIZE; |
128 | } | 128 | } |
129 | 129 | ||
130 | *ppos += (char __user *)out - buf; | 130 | *ppos += (char __user *)out - buf; |
131 | if (!ret) | 131 | if (!ret) |
132 | ret = (char __user *)out - buf; | 132 | ret = (char __user *)out - buf; |
133 | return ret; | 133 | return ret; |
134 | } | 134 | } |
135 | 135 | ||
136 | static const struct file_operations proc_kpageflags_operations = { | 136 | static const struct file_operations proc_kpageflags_operations = { |
137 | .llseek = mem_lseek, | 137 | .llseek = mem_lseek, |
138 | .read = kpageflags_read, | 138 | .read = kpageflags_read, |
139 | }; | 139 | }; |
140 | 140 | ||
141 | static int __init proc_page_init(void) | 141 | static int __init proc_page_init(void) |
142 | { | 142 | { |
143 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); | 143 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); |
144 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); | 144 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | module_init(proc_page_init); | 147 | module_init(proc_page_init); |
148 | 148 |