aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/cpu/mtrr/if.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@novell.com>2006-12-06 20:14:09 -0500
committerAndi Kleen <andi@basil.nowhere.org>2006-12-06 20:14:09 -0500
commit365bff806e9faba000fb4956c7486fbf3a746d96 (patch)
treecdd34beaabbc21b49a3786589679632690a84026 /arch/i386/kernel/cpu/mtrr/if.c
parenteab724e5df17af0ed0dac03da8f75aa336c31206 (diff)
[PATCH] i386: fix MTRR code
Until not so long ago, there were system log messages pointing to inconsistent MTRR setup of the video frame buffer caused by the way vesafb and X worked. While vesafb was fixed meanwhile, I believe fixing it there only hides a shortcoming in the MTRR code itself, in that that code is not symmetric with respect to the ordering of attempts to set up two (or more) regions where one contains the other. In the current shape, it permits only setting up sub-regions of pre-exisiting ones. The patch below makes this symmetric. While working on that I noticed a few more inconsistencies in that code, namely - use of 'unsigned int' for sizes in many, but not all places (the patch is converting this to use 'unsigned long' everywhere, which specifically might be necessary for x86-64 once a processor supporting more than 44 physical address bits would become available) - the code to correct inconsistent settings during secondary processor startup tried (if necessary) to correct, among other things, the value in IA32_MTRR_DEF_TYPE, however the newly computed value would never get used (i.e. stored in the respective MSR) - the generic range validation code checked that the end of the to-be-added range would be above 1MB; the value checked should have been the start of the range - when contained regions are detected, previously this was allowed only when the old region was uncacheable; this can be symmetric (i.e. the new region can also be uncacheable) and even further as per Intel's documentation write-trough and write-back for either region is also compatible with the respective opposite in the other Signed-off-by: Jan Beulich <jbeulich@novell.com> Signed-off-by: Andi Kleen <ak@suse.de>
Diffstat (limited to 'arch/i386/kernel/cpu/mtrr/if.c')
-rw-r--r--arch/i386/kernel/cpu/mtrr/if.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/arch/i386/kernel/cpu/mtrr/if.c b/arch/i386/kernel/cpu/mtrr/if.c
index 5ac051bb9d5..9753bc6a1f3 100644
--- a/arch/i386/kernel/cpu/mtrr/if.c
+++ b/arch/i386/kernel/cpu/mtrr/if.c
@@ -17,7 +17,7 @@ extern unsigned int *usage_table;
17 17
18#define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private) 18#define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private)
19 19
20static char *mtrr_strings[MTRR_NUM_TYPES] = 20static const char *const mtrr_strings[MTRR_NUM_TYPES] =
21{ 21{
22 "uncachable", /* 0 */ 22 "uncachable", /* 0 */
23 "write-combining", /* 1 */ 23 "write-combining", /* 1 */
@@ -28,7 +28,7 @@ static char *mtrr_strings[MTRR_NUM_TYPES] =
28 "write-back", /* 6 */ 28 "write-back", /* 6 */
29}; 29};
30 30
31char *mtrr_attrib_to_str(int x) 31const char *mtrr_attrib_to_str(int x)
32{ 32{
33 return (x <= 6) ? mtrr_strings[x] : "?"; 33 return (x <= 6) ? mtrr_strings[x] : "?";
34} 34}
@@ -155,6 +155,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
155{ 155{
156 int err = 0; 156 int err = 0;
157 mtrr_type type; 157 mtrr_type type;
158 unsigned long size;
158 struct mtrr_sentry sentry; 159 struct mtrr_sentry sentry;
159 struct mtrr_gentry gentry; 160 struct mtrr_gentry gentry;
160 void __user *arg = (void __user *) __arg; 161 void __user *arg = (void __user *) __arg;
@@ -235,15 +236,15 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
235 case MTRRIOC_GET_ENTRY: 236 case MTRRIOC_GET_ENTRY:
236 if (gentry.regnum >= num_var_ranges) 237 if (gentry.regnum >= num_var_ranges)
237 return -EINVAL; 238 return -EINVAL;
238 mtrr_if->get(gentry.regnum, &gentry.base, &gentry.size, &type); 239 mtrr_if->get(gentry.regnum, &gentry.base, &size, &type);
239 240
240 /* Hide entries that go above 4GB */ 241 /* Hide entries that go above 4GB */
241 if (gentry.base + gentry.size > 0x100000 242 if (gentry.base + size - 1 >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT))
242 || gentry.size == 0x100000) 243 || size >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT)))
243 gentry.base = gentry.size = gentry.type = 0; 244 gentry.base = gentry.size = gentry.type = 0;
244 else { 245 else {
245 gentry.base <<= PAGE_SHIFT; 246 gentry.base <<= PAGE_SHIFT;
246 gentry.size <<= PAGE_SHIFT; 247 gentry.size = size << PAGE_SHIFT;
247 gentry.type = type; 248 gentry.type = type;
248 } 249 }
249 250
@@ -273,8 +274,14 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
273 case MTRRIOC_GET_PAGE_ENTRY: 274 case MTRRIOC_GET_PAGE_ENTRY:
274 if (gentry.regnum >= num_var_ranges) 275 if (gentry.regnum >= num_var_ranges)
275 return -EINVAL; 276 return -EINVAL;
276 mtrr_if->get(gentry.regnum, &gentry.base, &gentry.size, &type); 277 mtrr_if->get(gentry.regnum, &gentry.base, &size, &type);
277 gentry.type = type; 278 /* Hide entries that would overflow */
279 if (size != (__typeof__(gentry.size))size)
280 gentry.base = gentry.size = gentry.type = 0;
281 else {
282 gentry.size = size;
283 gentry.type = type;
284 }
278 break; 285 break;
279 } 286 }
280 287
@@ -353,8 +360,7 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
353 char factor; 360 char factor;
354 int i, max, len; 361 int i, max, len;
355 mtrr_type type; 362 mtrr_type type;
356 unsigned long base; 363 unsigned long base, size;
357 unsigned int size;
358 364
359 len = 0; 365 len = 0;
360 max = num_var_ranges; 366 max = num_var_ranges;
@@ -373,7 +379,7 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
373 } 379 }
374 /* RED-PEN: base can be > 32bit */ 380 /* RED-PEN: base can be > 32bit */
375 len += seq_printf(seq, 381 len += seq_printf(seq,
376 "reg%02i: base=0x%05lx000 (%4liMB), size=%4i%cB: %s, count=%d\n", 382 "reg%02i: base=0x%05lx000 (%4luMB), size=%4lu%cB: %s, count=%d\n",
377 i, base, base >> (20 - PAGE_SHIFT), size, factor, 383 i, base, base >> (20 - PAGE_SHIFT), size, factor,
378 mtrr_attrib_to_str(type), usage_table[i]); 384 mtrr_attrib_to_str(type), usage_table[i]);
379 } 385 }