diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:33:43 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:33:43 -0500 |
commit | 851339b1ffc2b215c7c4e448465e78a4c2f643f2 (patch) | |
tree | 8b41869c22118220c15818e4e9092c355e79c065 /arch/x86/mm/pageattr-test.c | |
parent | fa2d8369a1e0e5dd0fdaaba9d40ca5187f4cd20b (diff) |
x86: clean up arch/x86/mm/pageattr-test.c
fix 15 checkpatch warnings.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/mm/pageattr-test.c')
-rw-r--r-- | arch/x86/mm/pageattr-test.c | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c index 4b22eb47f23a..c58fab061762 100644 --- a/arch/x86/mm/pageattr-test.c +++ b/arch/x86/mm/pageattr-test.c | |||
@@ -4,36 +4,36 @@ | |||
4 | * Clears the global bit on random pages in the direct mapping, then reverts | 4 | * Clears the global bit on random pages in the direct mapping, then reverts |
5 | * and compares page tables forwards and afterwards. | 5 | * and compares page tables forwards and afterwards. |
6 | */ | 6 | */ |
7 | 7 | #include <linux/bootmem.h> | |
8 | #include <linux/mm.h> | ||
9 | #include <linux/random.h> | 8 | #include <linux/random.h> |
10 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
11 | #include <linux/init.h> | 10 | #include <linux/init.h> |
12 | #include <linux/bootmem.h> | 11 | #include <linux/mm.h> |
12 | |||
13 | #include <asm/cacheflush.h> | 13 | #include <asm/cacheflush.h> |
14 | #include <asm/pgtable.h> | 14 | #include <asm/pgtable.h> |
15 | #include <asm/kdebug.h> | 15 | #include <asm/kdebug.h> |
16 | 16 | ||
17 | enum { | 17 | enum { |
18 | NTEST = 400, | 18 | NTEST = 400, |
19 | #ifdef CONFIG_X86_64 | 19 | #ifdef CONFIG_X86_64 |
20 | LOWEST_LEVEL = 4, | 20 | LOWEST_LEVEL = 4, |
21 | LPS = (1 << PMD_SHIFT), | 21 | LPS = (1 << PMD_SHIFT), |
22 | #elif defined(CONFIG_X86_PAE) | 22 | #elif defined(CONFIG_X86_PAE) |
23 | LOWEST_LEVEL = 3, | 23 | LOWEST_LEVEL = 3, |
24 | LPS = (1 << PMD_SHIFT), | 24 | LPS = (1 << PMD_SHIFT), |
25 | #else | 25 | #else |
26 | LOWEST_LEVEL = 3, /* lookup_address lies here */ | 26 | LOWEST_LEVEL = 3, /* lookup_address lies here */ |
27 | LPS = (1 << 22), | 27 | LPS = (1 << 22), |
28 | #endif | 28 | #endif |
29 | GPS = (1<<30) | 29 | GPS = (1<<30) |
30 | }; | 30 | }; |
31 | 31 | ||
32 | #ifdef CONFIG_X86_64 | 32 | #ifdef CONFIG_X86_64 |
33 | #include <asm/proto.h> | 33 | # include <asm/proto.h> |
34 | #define max_mapped end_pfn_map | 34 | # define max_mapped end_pfn_map |
35 | #else | 35 | #else |
36 | #define max_mapped max_low_pfn | 36 | # define max_mapped max_low_pfn |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | struct split_state { | 39 | struct split_state { |
@@ -43,23 +43,24 @@ struct split_state { | |||
43 | 43 | ||
44 | static __init int print_split(struct split_state *s) | 44 | static __init int print_split(struct split_state *s) |
45 | { | 45 | { |
46 | int printed = 0; | ||
47 | long i, expected, missed = 0; | 46 | long i, expected, missed = 0; |
47 | int printed = 0; | ||
48 | int err = 0; | 48 | int err = 0; |
49 | 49 | ||
50 | s->lpg = s->gpg = s->spg = s->exec = 0; | 50 | s->lpg = s->gpg = s->spg = s->exec = 0; |
51 | s->min_exec = ~0UL; | 51 | s->min_exec = ~0UL; |
52 | s->max_exec = 0; | 52 | s->max_exec = 0; |
53 | for (i = 0; i < max_mapped; ) { | 53 | for (i = 0; i < max_mapped; ) { |
54 | unsigned long addr = (unsigned long)__va(i << PAGE_SHIFT); | ||
54 | int level; | 55 | int level; |
55 | pte_t *pte; | 56 | pte_t *pte; |
56 | unsigned long adr = (unsigned long)__va(i << PAGE_SHIFT); | ||
57 | 57 | ||
58 | pte = lookup_address(adr, &level); | 58 | pte = lookup_address(addr, &level); |
59 | if (!pte) { | 59 | if (!pte) { |
60 | if (!printed) { | 60 | if (!printed) { |
61 | dump_pagetable(adr); | 61 | dump_pagetable(addr); |
62 | printk("CPA %lx no pte level %d\n", adr, level); | 62 | printk(KERN_INFO "CPA %lx no pte level %d\n", |
63 | addr, level); | ||
63 | printed = 1; | 64 | printed = 1; |
64 | } | 65 | } |
65 | missed++; | 66 | missed++; |
@@ -72,8 +73,9 @@ static __init int print_split(struct split_state *s) | |||
72 | i += GPS/PAGE_SIZE; | 73 | i += GPS/PAGE_SIZE; |
73 | } else if (level != LOWEST_LEVEL) { | 74 | } else if (level != LOWEST_LEVEL) { |
74 | if (!(pte_val(*pte) & _PAGE_PSE)) { | 75 | if (!(pte_val(*pte) & _PAGE_PSE)) { |
75 | printk("%lx level %d but not PSE %Lx\n", | 76 | printk(KERN_ERR |
76 | adr, level, (u64)pte_val(*pte)); | 77 | "%lx level %d but not PSE %Lx\n", |
78 | addr, level, (u64)pte_val(*pte)); | ||
77 | err = 1; | 79 | err = 1; |
78 | } | 80 | } |
79 | s->lpg++; | 81 | s->lpg++; |
@@ -84,18 +86,20 @@ static __init int print_split(struct split_state *s) | |||
84 | } | 86 | } |
85 | if (!(pte_val(*pte) & _PAGE_NX)) { | 87 | if (!(pte_val(*pte) & _PAGE_NX)) { |
86 | s->exec++; | 88 | s->exec++; |
87 | if (adr < s->min_exec) | 89 | if (addr < s->min_exec) |
88 | s->min_exec = adr; | 90 | s->min_exec = addr; |
89 | if (adr > s->max_exec) | 91 | if (addr > s->max_exec) |
90 | s->max_exec = adr; | 92 | s->max_exec = addr; |
91 | } | 93 | } |
92 | } | 94 | } |
93 | printk("CPA mapping 4k %lu large %lu gb %lu x %lu[%lx-%lx] miss %lu\n", | 95 | printk(KERN_INFO |
96 | "CPA mapping 4k %lu large %lu gb %lu x %lu[%lx-%lx] miss %lu\n", | ||
94 | s->spg, s->lpg, s->gpg, s->exec, | 97 | s->spg, s->lpg, s->gpg, s->exec, |
95 | s->min_exec != ~0UL ? s->min_exec : 0, s->max_exec, missed); | 98 | s->min_exec != ~0UL ? s->min_exec : 0, s->max_exec, missed); |
99 | |||
96 | expected = (s->gpg*GPS + s->lpg*LPS)/PAGE_SIZE + s->spg + missed; | 100 | expected = (s->gpg*GPS + s->lpg*LPS)/PAGE_SIZE + s->spg + missed; |
97 | if (expected != i) { | 101 | if (expected != i) { |
98 | printk("CPA max_mapped %lu but expected %lu\n", | 102 | printk(KERN_ERR "CPA max_mapped %lu but expected %lu\n", |
99 | max_mapped, expected); | 103 | max_mapped, expected); |
100 | return 1; | 104 | return 1; |
101 | } | 105 | } |
@@ -105,56 +109,62 @@ static __init int print_split(struct split_state *s) | |||
105 | static __init int state_same(struct split_state *a, struct split_state *b) | 109 | static __init int state_same(struct split_state *a, struct split_state *b) |
106 | { | 110 | { |
107 | return a->lpg == b->lpg && a->gpg == b->gpg && a->spg == b->spg && | 111 | return a->lpg == b->lpg && a->gpg == b->gpg && a->spg == b->spg && |
108 | a->exec == b->exec; | 112 | a->exec == b->exec; |
109 | } | 113 | } |
110 | 114 | ||
111 | static unsigned long addr[NTEST] __initdata; | 115 | static unsigned long __initdata addr[NTEST]; |
112 | static unsigned len[NTEST] __initdata; | 116 | static unsigned int __initdata len[NTEST]; |
113 | 117 | ||
114 | /* Change the global bit on random pages in the direct mapping */ | 118 | /* Change the global bit on random pages in the direct mapping */ |
115 | static __init int exercise_pageattr(void) | 119 | static __init int exercise_pageattr(void) |
116 | { | 120 | { |
117 | int i, k; | 121 | struct split_state sa, sb, sc; |
122 | unsigned long *bm; | ||
118 | pte_t *pte, pte0; | 123 | pte_t *pte, pte0; |
124 | int failed = 0; | ||
119 | int level; | 125 | int level; |
126 | int i, k; | ||
120 | int err; | 127 | int err; |
121 | struct split_state sa, sb, sc; | ||
122 | int failed = 0; | ||
123 | unsigned long *bm; | ||
124 | 128 | ||
125 | printk("CPA exercising pageattr\n"); | 129 | printk(KERN_INFO "CPA exercising pageattr\n"); |
126 | 130 | ||
127 | bm = vmalloc((max_mapped + 7) / 8); | 131 | bm = vmalloc((max_mapped + 7) / 8); |
128 | if (!bm) { | 132 | if (!bm) { |
129 | printk("CPA Cannot vmalloc bitmap\n"); | 133 | printk(KERN_ERR "CPA Cannot vmalloc bitmap\n"); |
130 | return -ENOMEM; | 134 | return -ENOMEM; |
131 | } | 135 | } |
132 | memset(bm, 0, (max_mapped + 7) / 8); | 136 | memset(bm, 0, (max_mapped + 7) / 8); |
133 | 137 | ||
134 | failed += print_split(&sa); | 138 | failed += print_split(&sa); |
135 | srandom32(100); | 139 | srandom32(100); |
140 | |||
136 | for (i = 0; i < NTEST; i++) { | 141 | for (i = 0; i < NTEST; i++) { |
137 | unsigned long pfn = random32() % max_mapped; | 142 | unsigned long pfn = random32() % max_mapped; |
143 | |||
138 | addr[i] = (unsigned long)__va(pfn << PAGE_SHIFT); | 144 | addr[i] = (unsigned long)__va(pfn << PAGE_SHIFT); |
139 | len[i] = random32() % 100; | 145 | len[i] = random32() % 100; |
140 | len[i] = min_t(unsigned long, len[i], max_mapped - pfn - 1); | 146 | len[i] = min_t(unsigned long, len[i], max_mapped - pfn - 1); |
147 | |||
141 | if (len[i] == 0) | 148 | if (len[i] == 0) |
142 | len[i] = 1; | 149 | len[i] = 1; |
143 | 150 | ||
144 | pte = NULL; | 151 | pte = NULL; |
145 | pte0 = pfn_pte(0, __pgprot(0)); /* shut gcc up */ | 152 | pte0 = pfn_pte(0, __pgprot(0)); /* shut gcc up */ |
153 | |||
146 | for (k = 0; k < len[i]; k++) { | 154 | for (k = 0; k < len[i]; k++) { |
147 | pte = lookup_address(addr[i] + k*PAGE_SIZE, &level); | 155 | pte = lookup_address(addr[i] + k*PAGE_SIZE, &level); |
148 | if (!pte || pgprot_val(pte_pgprot(*pte)) == 0) { | 156 | if (!pte || pgprot_val(pte_pgprot(*pte)) == 0) { |
149 | addr[i] = 0; | 157 | addr[i] = 0; |
150 | break; | 158 | break; |
151 | } | 159 | } |
152 | if (k == 0) | 160 | if (k == 0) { |
153 | pte0 = *pte; | 161 | pte0 = *pte; |
154 | else if (pgprot_val(pte_pgprot(*pte)) != | 162 | } else { |
163 | if (pgprot_val(pte_pgprot(*pte)) != | ||
155 | pgprot_val(pte_pgprot(pte0))) { | 164 | pgprot_val(pte_pgprot(pte0))) { |
156 | len[i] = k; | 165 | len[i] = k; |
157 | break; | 166 | break; |
167 | } | ||
158 | } | 168 | } |
159 | if (test_bit(pfn + k, bm)) { | 169 | if (test_bit(pfn + k, bm)) { |
160 | len[i] = k; | 170 | len[i] = k; |
@@ -170,19 +180,19 @@ static __init int exercise_pageattr(void) | |||
170 | err = change_page_attr(virt_to_page(addr[i]), len[i], | 180 | err = change_page_attr(virt_to_page(addr[i]), len[i], |
171 | pte_pgprot(pte_clrhuge(pte_clrglobal(pte0)))); | 181 | pte_pgprot(pte_clrhuge(pte_clrglobal(pte0)))); |
172 | if (err < 0) { | 182 | if (err < 0) { |
173 | printk("CPA %d failed %d\n", i, err); | 183 | printk(KERN_ERR "CPA %d failed %d\n", i, err); |
174 | failed++; | 184 | failed++; |
175 | } | 185 | } |
176 | 186 | ||
177 | pte = lookup_address(addr[i], &level); | 187 | pte = lookup_address(addr[i], &level); |
178 | if (!pte || pte_global(*pte) || pte_huge(*pte)) { | 188 | if (!pte || pte_global(*pte) || pte_huge(*pte)) { |
179 | printk("CPA %lx: bad pte %Lx\n", addr[i], | 189 | printk(KERN_ERR "CPA %lx: bad pte %Lx\n", addr[i], |
180 | pte ? (u64)pte_val(*pte) : 0ULL); | 190 | pte ? (u64)pte_val(*pte) : 0ULL); |
181 | failed++; | 191 | failed++; |
182 | } | 192 | } |
183 | if (level != LOWEST_LEVEL) { | 193 | if (level != LOWEST_LEVEL) { |
184 | printk("CPA %lx: unexpected level %d\n", addr[i], | 194 | printk(KERN_ERR "CPA %lx: unexpected level %d\n", |
185 | level); | 195 | addr[i], level); |
186 | failed++; | 196 | failed++; |
187 | } | 197 | } |
188 | 198 | ||
@@ -192,26 +202,26 @@ static __init int exercise_pageattr(void) | |||
192 | 202 | ||
193 | failed += print_split(&sb); | 203 | failed += print_split(&sb); |
194 | 204 | ||
195 | printk("CPA reverting everything\n"); | 205 | printk(KERN_INFO "CPA reverting everything\n"); |
196 | for (i = 0; i < NTEST; i++) { | 206 | for (i = 0; i < NTEST; i++) { |
197 | if (!addr[i]) | 207 | if (!addr[i]) |
198 | continue; | 208 | continue; |
199 | pte = lookup_address(addr[i], &level); | 209 | pte = lookup_address(addr[i], &level); |
200 | if (!pte) { | 210 | if (!pte) { |
201 | printk("CPA lookup of %lx failed\n", addr[i]); | 211 | printk(KERN_ERR "CPA lookup of %lx failed\n", addr[i]); |
202 | failed++; | 212 | failed++; |
203 | continue; | 213 | continue; |
204 | } | 214 | } |
205 | err = change_page_attr(virt_to_page(addr[i]), len[i], | 215 | err = change_page_attr(virt_to_page(addr[i]), len[i], |
206 | pte_pgprot(pte_mkglobal(*pte))); | 216 | pte_pgprot(pte_mkglobal(*pte))); |
207 | if (err < 0) { | 217 | if (err < 0) { |
208 | printk("CPA reverting failed: %d\n", err); | 218 | printk(KERN_ERR "CPA reverting failed: %d\n", err); |
209 | failed++; | 219 | failed++; |
210 | } | 220 | } |
211 | pte = lookup_address(addr[i], &level); | 221 | pte = lookup_address(addr[i], &level); |
212 | if (!pte || !pte_global(*pte)) { | 222 | if (!pte || !pte_global(*pte)) { |
213 | printk("CPA %lx: bad pte after revert %Lx\n", addr[i], | 223 | printk(KERN_ERR "CPA %lx: bad pte after revert %Lx\n", |
214 | pte ? (u64)pte_val(*pte) : 0ULL); | 224 | addr[i], pte ? (u64)pte_val(*pte) : 0ULL); |
215 | failed++; | 225 | failed++; |
216 | } | 226 | } |
217 | 227 | ||
@@ -223,11 +233,10 @@ static __init int exercise_pageattr(void) | |||
223 | failed++; | 233 | failed++; |
224 | 234 | ||
225 | if (failed) | 235 | if (failed) |
226 | printk("CPA selftests NOT PASSED. Please report.\n"); | 236 | printk(KERN_ERR "CPA selftests NOT PASSED. Please report.\n"); |
227 | else | 237 | else |
228 | printk("CPA selftests PASSED\n"); | 238 | printk(KERN_INFO "CPA selftests PASSED\n"); |
229 | 239 | ||
230 | return 0; | 240 | return 0; |
231 | } | 241 | } |
232 | |||
233 | module_init(exercise_pageattr); | 242 | module_init(exercise_pageattr); |