2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* This only handles 32bit MTRR on 32bit hosts. This is strictly wrong
|
2011-03-18 03:24:16 +08:00
|
|
|
* because MTRRs can span up to 40 bits (36bits on most modern x86)
|
2009-07-04 10:23:00 +08:00
|
|
|
*/
|
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
2009-07-04 10:23:00 +08:00
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mm.h>
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2008-01-30 20:30:39 +08:00
|
|
|
#include <asm/processor-flags.h>
|
2009-07-04 10:23:00 +08:00
|
|
|
#include <asm/cpufeature.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/tlbflush.h>
|
2009-07-04 10:23:00 +08:00
|
|
|
#include <asm/mtrr.h>
|
|
|
|
#include <asm/msr.h>
|
2008-03-19 08:00:14 +08:00
|
|
|
#include <asm/pat.h>
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "mtrr.h"
|
|
|
|
|
2007-05-03 01:27:17 +08:00
|
|
|
struct fixed_range_block {
|
2009-07-04 10:23:00 +08:00
|
|
|
int base_msr; /* start address of an MTRR block */
|
|
|
|
int ranges; /* number of MTRRs in this block */
|
2007-05-03 01:27:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct fixed_range_block fixed_range_blocks[] = {
|
2009-07-04 10:23:00 +08:00
|
|
|
{ MSR_MTRRfix64K_00000, 1 }, /* one 64k MTRR */
|
|
|
|
{ MSR_MTRRfix16K_80000, 2 }, /* two 16k MTRRs */
|
|
|
|
{ MSR_MTRRfix4K_C0000, 8 }, /* eight 4k MTRRs */
|
2007-05-03 01:27:17 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static unsigned long smp_changes_mask;
|
2008-03-19 08:00:14 +08:00
|
|
|
static int mtrr_state_set;
|
2008-04-29 18:52:33 +08:00
|
|
|
u64 mtrr_tom2;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
struct mtrr_state_type mtrr_state;
|
2008-10-09 16:01:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mtrr_state);
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
2009-03-13 00:39:37 +08:00
|
|
|
* BIOS is expected to clear MtrrFixDramModEn bit, see for example
|
|
|
|
* "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD
|
|
|
|
* Opteron Processors" (26094 Rev. 3.30 February 2006), section
|
|
|
|
* "13.2.1.2 SYSCFG Register": "The MtrrFixDramModEn bit should be set
|
|
|
|
* to 1 during BIOS initalization of the fixed MTRRs, then cleared to
|
|
|
|
* 0 for operation."
|
|
|
|
*/
|
|
|
|
static inline void k8_check_syscfg_dram_mod_en(void)
|
|
|
|
{
|
|
|
|
u32 lo, hi;
|
|
|
|
|
|
|
|
if (!((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
|
|
|
|
(boot_cpu_data.x86 >= 0x0f)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rdmsr(MSR_K8_SYSCFG, lo, hi);
|
|
|
|
if (lo & K8_MTRRFIXRANGE_DRAM_MODIFY) {
|
|
|
|
printk(KERN_ERR FW_WARN "MTRR: CPU %u: SYSCFG[MtrrFixDramModEn]"
|
|
|
|
" not cleared by BIOS, clearing this bit\n",
|
|
|
|
smp_processor_id());
|
|
|
|
lo &= ~K8_MTRRFIXRANGE_DRAM_MODIFY;
|
|
|
|
mtrr_wrmsr(MSR_K8_SYSCFG, lo, hi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 06:55:50 +08:00
|
|
|
/* Get the size of contiguous MTRR range */
|
|
|
|
static u64 get_mtrr_size(u64 mask)
|
|
|
|
{
|
|
|
|
u64 size;
|
|
|
|
|
|
|
|
mask >>= PAGE_SHIFT;
|
|
|
|
mask |= size_or_mask;
|
|
|
|
size = -mask;
|
|
|
|
size <<= PAGE_SHIFT;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2010-09-11 06:55:49 +08:00
|
|
|
/*
|
|
|
|
* Check and return the effective type for MTRR-MTRR type overlap.
|
|
|
|
* Returns 1 if the effective type is UNCACHEABLE, else returns 0
|
|
|
|
*/
|
|
|
|
static int check_type_overlap(u8 *prev, u8 *curr)
|
|
|
|
{
|
|
|
|
if (*prev == MTRR_TYPE_UNCACHABLE || *curr == MTRR_TYPE_UNCACHABLE) {
|
|
|
|
*prev = MTRR_TYPE_UNCACHABLE;
|
|
|
|
*curr = MTRR_TYPE_UNCACHABLE;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*prev == MTRR_TYPE_WRBACK && *curr == MTRR_TYPE_WRTHROUGH) ||
|
|
|
|
(*prev == MTRR_TYPE_WRTHROUGH && *curr == MTRR_TYPE_WRBACK)) {
|
|
|
|
*prev = MTRR_TYPE_WRTHROUGH;
|
|
|
|
*curr = MTRR_TYPE_WRTHROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*prev != *curr) {
|
|
|
|
*prev = MTRR_TYPE_UNCACHABLE;
|
|
|
|
*curr = MTRR_TYPE_UNCACHABLE;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-19 08:00:14 +08:00
|
|
|
/*
|
2010-09-11 06:55:50 +08:00
|
|
|
* Error/Semi-error returns:
|
|
|
|
* 0xFF - when MTRR is not enabled
|
|
|
|
* *repeat == 1 implies [start:end] spanned across MTRR range and type returned
|
|
|
|
* corresponds only to [start:*partial_end].
|
|
|
|
* Caller has to lookup again for [*partial_end:end].
|
2008-03-19 08:00:14 +08:00
|
|
|
*/
|
2010-09-11 06:55:50 +08:00
|
|
|
static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
|
2008-03-19 08:00:14 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u64 base, mask;
|
|
|
|
u8 prev_match, curr_match;
|
|
|
|
|
2010-09-11 06:55:50 +08:00
|
|
|
*repeat = 0;
|
2008-03-19 08:00:14 +08:00
|
|
|
if (!mtrr_state_set)
|
|
|
|
return 0xFF;
|
|
|
|
|
|
|
|
if (!mtrr_state.enabled)
|
|
|
|
return 0xFF;
|
|
|
|
|
|
|
|
/* Make end inclusive end, instead of exclusive */
|
|
|
|
end--;
|
|
|
|
|
|
|
|
/* Look in fixed ranges. Just return the type as per start */
|
|
|
|
if (mtrr_state.have_fixed && (start < 0x100000)) {
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if (start < 0x80000) {
|
|
|
|
idx = 0;
|
|
|
|
idx += (start >> 16);
|
|
|
|
return mtrr_state.fixed_ranges[idx];
|
|
|
|
} else if (start < 0xC0000) {
|
|
|
|
idx = 1 * 8;
|
|
|
|
idx += ((start - 0x80000) >> 14);
|
|
|
|
return mtrr_state.fixed_ranges[idx];
|
2015-05-11 16:15:52 +08:00
|
|
|
} else {
|
2008-03-19 08:00:14 +08:00
|
|
|
idx = 3 * 8;
|
|
|
|
idx += ((start - 0xC0000) >> 12);
|
|
|
|
return mtrr_state.fixed_ranges[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look in variable ranges
|
|
|
|
* Look of multiple ranges matching this address and pick type
|
|
|
|
* as per MTRR precedence
|
|
|
|
*/
|
2009-07-04 10:23:00 +08:00
|
|
|
if (!(mtrr_state.enabled & 2))
|
2008-03-19 08:00:14 +08:00
|
|
|
return mtrr_state.def_type;
|
|
|
|
|
|
|
|
prev_match = 0xFF;
|
|
|
|
for (i = 0; i < num_var_ranges; ++i) {
|
2015-05-26 16:28:05 +08:00
|
|
|
unsigned short start_state, end_state, inclusive;
|
2008-03-19 08:00:14 +08:00
|
|
|
|
|
|
|
if (!(mtrr_state.var_ranges[i].mask_lo & (1 << 11)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
base = (((u64)mtrr_state.var_ranges[i].base_hi) << 32) +
|
|
|
|
(mtrr_state.var_ranges[i].base_lo & PAGE_MASK);
|
|
|
|
mask = (((u64)mtrr_state.var_ranges[i].mask_hi) << 32) +
|
|
|
|
(mtrr_state.var_ranges[i].mask_lo & PAGE_MASK);
|
|
|
|
|
|
|
|
start_state = ((start & mask) == (base & mask));
|
|
|
|
end_state = ((end & mask) == (base & mask));
|
2015-05-26 16:28:05 +08:00
|
|
|
inclusive = ((start < base) && (end > base));
|
2010-09-11 06:55:50 +08:00
|
|
|
|
2015-05-26 16:28:05 +08:00
|
|
|
if ((start_state != end_state) || inclusive) {
|
2010-09-11 06:55:50 +08:00
|
|
|
/*
|
|
|
|
* We have start:end spanning across an MTRR.
|
2015-05-26 16:28:05 +08:00
|
|
|
* We split the region into either
|
|
|
|
*
|
|
|
|
* - start_state:1
|
|
|
|
* (start:mtrr_end)(mtrr_end:end)
|
|
|
|
* - end_state:1
|
|
|
|
* (start:mtrr_start)(mtrr_start:end)
|
|
|
|
* - inclusive:1
|
|
|
|
* (start:mtrr_start)(mtrr_start:mtrr_end)(mtrr_end:end)
|
|
|
|
*
|
2010-09-11 06:55:50 +08:00
|
|
|
* depending on kind of overlap.
|
2015-05-26 16:28:05 +08:00
|
|
|
*
|
|
|
|
* Return the type of the first region and a pointer
|
|
|
|
* to the start of next region so that caller will be
|
|
|
|
* advised to lookup again after having adjusted start
|
|
|
|
* and end.
|
|
|
|
*
|
2010-09-11 06:55:50 +08:00
|
|
|
* Note: This way we handle multiple overlaps as well.
|
|
|
|
*/
|
|
|
|
if (start_state)
|
|
|
|
*partial_end = base + get_mtrr_size(mask);
|
|
|
|
else
|
|
|
|
*partial_end = base;
|
|
|
|
|
|
|
|
if (unlikely(*partial_end <= start)) {
|
|
|
|
WARN_ON(1);
|
|
|
|
*partial_end = start + PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = *partial_end - 1; /* end is inclusive */
|
|
|
|
*repeat = 1;
|
|
|
|
}
|
2008-03-19 08:00:14 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
if ((start & mask) != (base & mask))
|
2008-03-19 08:00:14 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
curr_match = mtrr_state.var_ranges[i].base_lo & 0xff;
|
|
|
|
if (prev_match == 0xFF) {
|
|
|
|
prev_match = curr_match;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-11 06:55:49 +08:00
|
|
|
if (check_type_overlap(&prev_match, &curr_match))
|
|
|
|
return curr_match;
|
2008-03-19 08:00:14 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 18:52:33 +08:00
|
|
|
if (mtrr_tom2) {
|
|
|
|
if (start >= (1ULL<<32) && (end < mtrr_tom2))
|
2008-03-25 07:02:01 +08:00
|
|
|
return MTRR_TYPE_WRBACK;
|
|
|
|
}
|
|
|
|
|
2008-03-19 08:00:14 +08:00
|
|
|
if (prev_match != 0xFF)
|
|
|
|
return prev_match;
|
|
|
|
|
|
|
|
return mtrr_state.def_type;
|
|
|
|
}
|
|
|
|
|
2010-09-11 06:55:50 +08:00
|
|
|
/*
|
|
|
|
* Returns the effective MTRR type for the region
|
|
|
|
* Error return:
|
|
|
|
* 0xFF - when MTRR is not enabled
|
|
|
|
*/
|
|
|
|
u8 mtrr_type_lookup(u64 start, u64 end)
|
|
|
|
{
|
|
|
|
u8 type, prev_type;
|
|
|
|
int repeat;
|
|
|
|
u64 partial_end;
|
|
|
|
|
|
|
|
type = __mtrr_type_lookup(start, end, &partial_end, &repeat);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common path is with repeat = 0.
|
|
|
|
* However, we can have cases where [start:end] spans across some
|
|
|
|
* MTRR range. Do repeated lookups for that case here.
|
|
|
|
*/
|
|
|
|
while (repeat) {
|
|
|
|
prev_type = type;
|
|
|
|
start = partial_end;
|
|
|
|
type = __mtrr_type_lookup(start, end, &partial_end, &repeat);
|
|
|
|
|
|
|
|
if (check_type_overlap(&prev_type, &type))
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Get the MSR pair relating to a var range */
|
2007-06-20 18:23:39 +08:00
|
|
|
static void
|
2005-04-17 06:20:36 +08:00
|
|
|
get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr)
|
|
|
|
{
|
|
|
|
rdmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi);
|
|
|
|
rdmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Fill the MSR pair relating to a var range */
|
2008-04-29 18:52:33 +08:00
|
|
|
void fill_mtrr_var_range(unsigned int index,
|
|
|
|
u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi)
|
|
|
|
{
|
|
|
|
struct mtrr_var_range *vr;
|
|
|
|
|
|
|
|
vr = mtrr_state.var_ranges;
|
|
|
|
|
|
|
|
vr[index].base_lo = base_lo;
|
|
|
|
vr[index].base_hi = base_hi;
|
|
|
|
vr[index].mask_lo = mask_lo;
|
|
|
|
vr[index].mask_hi = mask_hi;
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
static void get_fixed_ranges(mtrr_type *frs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-04 10:23:00 +08:00
|
|
|
unsigned int *p = (unsigned int *)frs;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2009-03-13 00:39:37 +08:00
|
|
|
k8_check_syscfg_dram_mod_en();
|
|
|
|
|
2009-05-14 14:40:43 +08:00
|
|
|
rdmsr(MSR_MTRRfix64K_00000, p[0], p[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
2009-05-14 14:45:32 +08:00
|
|
|
rdmsr(MSR_MTRRfix16K_80000 + i, p[2 + i * 2], p[3 + i * 2]);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 8; i++)
|
2009-05-14 14:59:25 +08:00
|
|
|
rdmsr(MSR_MTRRfix4K_C0000 + i, p[6 + i * 2], p[7 + i * 2]);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-03 01:27:17 +08:00
|
|
|
void mtrr_save_fixed_ranges(void *info)
|
|
|
|
{
|
2007-07-02 03:06:48 +08:00
|
|
|
if (cpu_has_mtrr)
|
|
|
|
get_fixed_ranges(mtrr_state.fixed_ranges);
|
2007-05-03 01:27:17 +08:00
|
|
|
}
|
|
|
|
|
2009-03-14 05:08:49 +08:00
|
|
|
static unsigned __initdata last_fixed_start;
|
|
|
|
static unsigned __initdata last_fixed_end;
|
|
|
|
static mtrr_type __initdata last_fixed_type;
|
|
|
|
|
|
|
|
static void __init print_fixed_last(void)
|
|
|
|
{
|
|
|
|
if (!last_fixed_end)
|
|
|
|
return;
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug(" %05X-%05X %s\n", last_fixed_start,
|
|
|
|
last_fixed_end - 1, mtrr_attrib_to_str(last_fixed_type));
|
2009-03-14 05:08:49 +08:00
|
|
|
|
|
|
|
last_fixed_end = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init update_fixed_last(unsigned base, unsigned end,
|
2009-07-04 10:23:00 +08:00
|
|
|
mtrr_type type)
|
2009-03-14 05:08:49 +08:00
|
|
|
{
|
|
|
|
last_fixed_start = base;
|
|
|
|
last_fixed_end = end;
|
|
|
|
last_fixed_type = type;
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
static void __init
|
|
|
|
print_fixed(unsigned base, unsigned step, const mtrr_type *types)
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2009-03-14 05:08:49 +08:00
|
|
|
for (i = 0; i < 8; ++i, ++types, base += step) {
|
|
|
|
if (last_fixed_end == 0) {
|
|
|
|
update_fixed_last(base, base + step, *types);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (last_fixed_end == base && last_fixed_type == *types) {
|
|
|
|
last_fixed_end = base + step;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* new segments: gap or different type */
|
|
|
|
print_fixed_last();
|
|
|
|
update_fixed_last(base, base + step, *types);
|
|
|
|
}
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
}
|
|
|
|
|
2008-03-19 08:00:14 +08:00
|
|
|
static void prepare_set(void);
|
|
|
|
static void post_set(void);
|
|
|
|
|
2009-03-13 09:43:54 +08:00
|
|
|
static void __init print_mtrr_state(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int high_width;
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug("MTRR default type: %s\n",
|
|
|
|
mtrr_attrib_to_str(mtrr_state.def_type));
|
2009-03-13 09:43:54 +08:00
|
|
|
if (mtrr_state.have_fixed) {
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug("MTRR fixed ranges %sabled:\n",
|
|
|
|
mtrr_state.enabled & 1 ? "en" : "dis");
|
2009-03-13 09:43:54 +08:00
|
|
|
print_fixed(0x00000, 0x10000, mtrr_state.fixed_ranges + 0);
|
|
|
|
for (i = 0; i < 2; ++i)
|
2009-07-04 10:23:00 +08:00
|
|
|
print_fixed(0x80000 + i * 0x20000, 0x04000,
|
|
|
|
mtrr_state.fixed_ranges + (i + 1) * 8);
|
2009-03-13 09:43:54 +08:00
|
|
|
for (i = 0; i < 8; ++i)
|
2009-07-04 10:23:00 +08:00
|
|
|
print_fixed(0xC0000 + i * 0x08000, 0x01000,
|
|
|
|
mtrr_state.fixed_ranges + (i + 3) * 8);
|
2009-03-14 05:08:49 +08:00
|
|
|
|
|
|
|
/* tail */
|
|
|
|
print_fixed_last();
|
2009-03-13 09:43:54 +08:00
|
|
|
}
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug("MTRR variable ranges %sabled:\n",
|
|
|
|
mtrr_state.enabled & 2 ? "en" : "dis");
|
2012-07-06 22:20:35 +08:00
|
|
|
high_width = (__ffs64(size_or_mask) - (32 - PAGE_SHIFT) + 3) / 4;
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2009-03-13 09:43:54 +08:00
|
|
|
for (i = 0; i < num_var_ranges; ++i) {
|
|
|
|
if (mtrr_state.var_ranges[i].mask_lo & (1 << 11))
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug(" %u base %0*X%05X000 mask %0*X%05X000 %s\n",
|
|
|
|
i,
|
|
|
|
high_width,
|
|
|
|
mtrr_state.var_ranges[i].base_hi,
|
|
|
|
mtrr_state.var_ranges[i].base_lo >> 12,
|
|
|
|
high_width,
|
|
|
|
mtrr_state.var_ranges[i].mask_hi,
|
|
|
|
mtrr_state.var_ranges[i].mask_lo >> 12,
|
|
|
|
mtrr_attrib_to_str(mtrr_state.var_ranges[i].base_lo & 0xff));
|
2009-03-13 09:43:54 +08:00
|
|
|
else
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_debug(" %u disabled\n", i);
|
2009-03-13 09:43:54 +08:00
|
|
|
}
|
2009-07-04 10:23:00 +08:00
|
|
|
if (mtrr_tom2)
|
|
|
|
pr_debug("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20);
|
2009-03-13 09:43:54 +08:00
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Grab all of the MTRR state for this CPU into *state */
|
2007-07-21 23:10:39 +08:00
|
|
|
void __init get_mtrr_state(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct mtrr_var_range *vrs;
|
2008-03-19 08:00:14 +08:00
|
|
|
unsigned long flags;
|
2009-07-04 10:23:00 +08:00
|
|
|
unsigned lo, dummy;
|
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
vrs = mtrr_state.var_ranges;
|
|
|
|
|
2009-05-14 14:36:12 +08:00
|
|
|
rdmsr(MSR_MTRRcap, lo, dummy);
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
mtrr_state.have_fixed = (lo >> 8) & 1;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < num_var_ranges; i++)
|
|
|
|
get_mtrr_var_range(i, &vrs[i]);
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
if (mtrr_state.have_fixed)
|
|
|
|
get_fixed_ranges(mtrr_state.fixed_ranges);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-14 15:05:46 +08:00
|
|
|
rdmsr(MSR_MTRRdefType, lo, dummy);
|
2005-04-17 06:20:36 +08:00
|
|
|
mtrr_state.def_type = (lo & 0xff);
|
|
|
|
mtrr_state.enabled = (lo & 0xc00) >> 10;
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
|
2008-03-25 07:02:01 +08:00
|
|
|
if (amd_special_default_mtrr()) {
|
2008-05-01 02:11:51 +08:00
|
|
|
unsigned low, high;
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2008-03-25 07:02:01 +08:00
|
|
|
/* TOP_MEM2 */
|
2008-05-01 02:11:51 +08:00
|
|
|
rdmsr(MSR_K8_TOP_MEM2, low, high);
|
2008-04-29 18:52:33 +08:00
|
|
|
mtrr_tom2 = high;
|
|
|
|
mtrr_tom2 <<= 32;
|
|
|
|
mtrr_tom2 |= low;
|
2008-05-13 08:40:39 +08:00
|
|
|
mtrr_tom2 &= 0xffffff800000ULL;
|
2008-03-25 07:02:01 +08:00
|
|
|
}
|
2009-03-13 09:43:54 +08:00
|
|
|
|
|
|
|
print_mtrr_state();
|
|
|
|
|
2008-03-19 08:00:14 +08:00
|
|
|
mtrr_state_set = 1;
|
|
|
|
|
|
|
|
/* PAT setup for BP. We need to go through sync steps here */
|
|
|
|
local_irq_save(flags);
|
|
|
|
prepare_set();
|
|
|
|
|
|
|
|
pat_init();
|
|
|
|
|
|
|
|
post_set();
|
|
|
|
local_irq_restore(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Some BIOS's are messed up and don't set all MTRRs the same! */
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init mtrr_state_warn(void)
|
|
|
|
{
|
|
|
|
unsigned long mask = smp_changes_mask;
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
return;
|
|
|
|
if (mask & MTRR_CHANGE_MASK_FIXED)
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: your CPUs had inconsistent fixed MTRR settings\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mask & MTRR_CHANGE_MASK_VARIABLE)
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: your CPUs had inconsistent variable MTRR settings\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mask & MTRR_CHANGE_MASK_DEFTYPE)
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: your CPUs had inconsistent MTRRdefType settings\n");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_INFO "mtrr: probably your BIOS does not setup all CPUs.\n");
|
|
|
|
printk(KERN_INFO "mtrr: corrected configuration.\n");
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Doesn't attempt to pass an error out to MTRR users
|
|
|
|
* because it's quite complicated in some cases and probably not
|
|
|
|
* worth it because the best error handling is to ignore it.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
void mtrr_wrmsr(unsigned msr, unsigned a, unsigned b)
|
|
|
|
{
|
2009-07-04 10:23:00 +08:00
|
|
|
if (wrmsr_safe(msr, a, b) < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR
|
|
|
|
"MTRR: CPU %u: Writing MSR %x to %x:%x failed\n",
|
|
|
|
smp_processor_id(), msr, a, b);
|
2009-07-04 10:23:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-03 01:27:17 +08:00
|
|
|
/**
|
2009-07-04 10:23:00 +08:00
|
|
|
* set_fixed_range - checks & updates a fixed-range MTRR if it
|
|
|
|
* differs from the value it should have
|
2008-03-14 07:59:12 +08:00
|
|
|
* @msr: MSR address of the MTTR which should be checked and updated
|
|
|
|
* @changed: pointer which indicates whether the MTRR needed to be changed
|
|
|
|
* @msrwords: pointer to the MSR values which the MSR should have
|
2007-05-03 01:27:17 +08:00
|
|
|
*/
|
2008-01-30 20:30:31 +08:00
|
|
|
static void set_fixed_range(int msr, bool *changed, unsigned int *msrwords)
|
2007-05-03 01:27:17 +08:00
|
|
|
{
|
|
|
|
unsigned lo, hi;
|
|
|
|
|
|
|
|
rdmsr(msr, lo, hi);
|
|
|
|
|
|
|
|
if (lo != msrwords[0] || hi != msrwords[1]) {
|
|
|
|
mtrr_wrmsr(msr, msrwords[0], msrwords[1]);
|
2008-01-30 20:30:31 +08:00
|
|
|
*changed = true;
|
2007-05-03 01:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-14 07:59:12 +08:00
|
|
|
/**
|
|
|
|
* generic_get_free_region - Get a free MTRR.
|
|
|
|
* @base: The starting (base) address of the region.
|
|
|
|
* @size: The size (in bytes) of the region.
|
|
|
|
* @replace_reg: mtrr index to be replaced; set to invalid value if none.
|
|
|
|
*
|
|
|
|
* Returns: The index of the region on success, else negative on error.
|
|
|
|
*/
|
2009-07-04 10:23:00 +08:00
|
|
|
int
|
|
|
|
generic_get_free_region(unsigned long base, unsigned long size, int replace_reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
unsigned long lbase, lsize;
|
2009-07-04 10:23:00 +08:00
|
|
|
mtrr_type ltype;
|
|
|
|
int i, max;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
max = num_var_ranges;
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
if (replace_reg >= 0 && replace_reg < max)
|
|
|
|
return replace_reg;
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < max; ++i) {
|
|
|
|
mtrr_if->get(i, &lbase, &lsize, <ype);
|
|
|
|
if (lsize == 0)
|
|
|
|
return i;
|
|
|
|
}
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2005-05-01 23:59:29 +08:00
|
|
|
static void generic_get_mtrr(unsigned int reg, unsigned long *base,
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
unsigned long *size, mtrr_type *type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
u32 mask_lo, mask_hi, base_lo, base_hi;
|
|
|
|
unsigned int hi;
|
|
|
|
u64 tmp, mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-13 09:43:54 +08:00
|
|
|
/*
|
|
|
|
* get_mtrr doesn't need to update mtrr_state, also it could be called
|
|
|
|
* from any cpu, so try to print it out directly.
|
|
|
|
*/
|
2010-07-21 06:19:49 +08:00
|
|
|
get_cpu();
|
2009-03-14 03:46:07 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rdmsr(MTRRphysMask_MSR(reg), mask_lo, mask_hi);
|
2009-03-13 09:43:54 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((mask_lo & 0x800) == 0) {
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Invalid (i.e. free) range */
|
2005-04-17 06:20:36 +08:00
|
|
|
*base = 0;
|
|
|
|
*size = 0;
|
|
|
|
*type = 0;
|
2009-03-14 03:46:07 +08:00
|
|
|
goto out_put_cpu;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rdmsr(MTRRphysBase_MSR(reg), base_lo, base_hi);
|
|
|
|
|
2009-03-14 03:46:07 +08:00
|
|
|
/* Work out the shifted address mask: */
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
tmp = (u64)mask_hi << (32 - PAGE_SHIFT) | mask_lo >> PAGE_SHIFT;
|
|
|
|
mask = size_or_mask | tmp;
|
2009-03-14 03:46:07 +08:00
|
|
|
|
|
|
|
/* Expand tmp with high bits to all 1s: */
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
hi = fls64(tmp);
|
2008-08-22 11:24:24 +08:00
|
|
|
if (hi > 0) {
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
tmp |= ~((1ULL<<(hi - 1)) - 1);
|
2008-08-22 11:24:24 +08:00
|
|
|
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
if (tmp != mask) {
|
2010-02-08 18:03:17 +08:00
|
|
|
printk(KERN_WARNING "mtrr: your BIOS has configured an incorrect mask, fixing it.\n");
|
2013-01-21 14:47:39 +08:00
|
|
|
add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
mask = tmp;
|
2008-08-22 11:24:24 +08:00
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-14 03:46:07 +08:00
|
|
|
/*
|
|
|
|
* This works correctly if size is a power of two, i.e. a
|
|
|
|
* contiguous range:
|
|
|
|
*/
|
x86: Fix /proc/mtrr with base/size more than 44bits
On one sytem that mtrr range is more then 44bits, in dmesg we have
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] 00000-9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-DFFFF write-through
[ 0.000000] E0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] 0 [000080000000-0000FFFFFFFF] mask 3FFF80000000 uncachable
[ 0.000000] 1 [380000000000-38FFFFFFFFFF] mask 3F0000000000 uncachable
[ 0.000000] 2 [000099000000-000099FFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 3 [00009A000000-00009AFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 4 [381FFA000000-381FFBFFFFFF] mask 3FFFFE000000 write-through
[ 0.000000] 5 [381FFC000000-381FFC0FFFFF] mask 3FFFFFF00000 write-through
[ 0.000000] 6 [0000AD000000-0000ADFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 7 [0000BD000000-0000BDFFFFFF] mask 3FFFFF000000 write-through
[ 0.000000] 8 disabled
[ 0.000000] 9 disabled
but /proc/mtrr report wrong:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x80000000000 (8388608MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x81ffa000000 (8519584MB), size= 32MB, count=1: write-through
reg05: base=0x81ffc000000 (8519616MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
so bit 44 and bit 45 get cut off.
We have problems in arch/x86/kernel/cpu/mtrr/generic.c::generic_get_mtrr().
1. for base, we miss cast base_lo to 64bit before shifting.
Fix that by adding u64 casting.
2. for size, it only can handle 44 bits aka 32bits + page_shift
Fix that with 64bit mask instead of 32bit mask_lo, then range could be
more than 44bits.
At the same time, we need to update size_or_mask for old cpus that does
support cpuid 0x80000008 to get phys_addr. Need to set high 32bits
to all 1s, otherwise will not get correct size for them.
Also fix mtrr_add_page: it should check base and (base + size - 1)
instead of base and size, as base and size could be small but
base + size could bigger enough to be out of boundary. We can
use boot_cpu_data.x86_phys_bits directly to avoid size_or_mask.
So When are we going to have size more than 44bits? that is 16TiB.
after patch we have right ouput:
reg00: base=0x080000000 ( 2048MB), size= 2048MB, count=1: uncachable
reg01: base=0x380000000000 (58720256MB), size=1048576MB, count=1: uncachable
reg02: base=0x099000000 ( 2448MB), size= 16MB, count=1: write-through
reg03: base=0x09a000000 ( 2464MB), size= 16MB, count=1: write-through
reg04: base=0x381ffa000000 (58851232MB), size= 32MB, count=1: write-through
reg05: base=0x381ffc000000 (58851264MB), size= 1MB, count=1: write-through
reg06: base=0x0ad000000 ( 2768MB), size= 16MB, count=1: write-through
reg07: base=0x0bd000000 ( 3024MB), size= 16MB, count=1: write-through
reg08: base=0x09b000000 ( 2480MB), size= 16MB, count=1: write-combining
-v2: simply checking in mtrr_add_page according to hpa.
[ hpa: This probably wants to go into -stable only after having sat in
mainline for a bit. It is not a regression. ]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1371162815-29931-1-git-send-email-yinghai@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-06-14 06:33:35 +08:00
|
|
|
*size = -mask;
|
|
|
|
*base = (u64)base_hi << (32 - PAGE_SHIFT) | base_lo >> PAGE_SHIFT;
|
2005-04-17 06:20:36 +08:00
|
|
|
*type = base_lo & 0xff;
|
2009-03-13 09:43:54 +08:00
|
|
|
|
2009-03-14 03:46:07 +08:00
|
|
|
out_put_cpu:
|
|
|
|
put_cpu();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-03 01:27:17 +08:00
|
|
|
/**
|
2009-07-04 10:23:00 +08:00
|
|
|
* set_fixed_ranges - checks & updates the fixed-range MTRRs if they
|
|
|
|
* differ from the saved set
|
2008-03-14 07:59:12 +08:00
|
|
|
* @frs: pointer to fixed-range MTRR values, saved by get_fixed_ranges()
|
2007-05-03 01:27:17 +08:00
|
|
|
*/
|
2009-07-04 10:23:00 +08:00
|
|
|
static int set_fixed_ranges(mtrr_type *frs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-04 10:23:00 +08:00
|
|
|
unsigned long long *saved = (unsigned long long *)frs;
|
2008-01-30 20:30:31 +08:00
|
|
|
bool changed = false;
|
2009-07-04 10:23:00 +08:00
|
|
|
int block = -1, range;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-13 00:39:37 +08:00
|
|
|
k8_check_syscfg_dram_mod_en();
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
while (fixed_range_blocks[++block].ranges) {
|
|
|
|
for (range = 0; range < fixed_range_blocks[block].ranges; range++)
|
|
|
|
set_fixed_range(fixed_range_blocks[block].base_msr + range,
|
|
|
|
&changed, (unsigned int *)saved++);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Set the MSR pair relating to a var range.
|
|
|
|
* Returns true if changes are made.
|
|
|
|
*/
|
2008-01-30 20:30:31 +08:00
|
|
|
static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int lo, hi;
|
2008-01-30 20:30:31 +08:00
|
|
|
bool changed = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rdmsr(MTRRphysBase_MSR(index), lo, hi);
|
|
|
|
if ((vr->base_lo & 0xfffff0ffUL) != (lo & 0xfffff0ffUL)
|
2005-04-17 06:25:11 +08:00
|
|
|
|| (vr->base_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=
|
|
|
|
(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
mtrr_wrmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi);
|
2008-01-30 20:30:31 +08:00
|
|
|
changed = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rdmsr(MTRRphysMask_MSR(index), lo, hi);
|
|
|
|
|
|
|
|
if ((vr->mask_lo & 0xfffff800UL) != (lo & 0xfffff800UL)
|
2005-04-17 06:25:11 +08:00
|
|
|
|| (vr->mask_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=
|
|
|
|
(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
mtrr_wrmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);
|
2008-01-30 20:30:31 +08:00
|
|
|
changed = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
static u32 deftype_lo, deftype_hi;
|
|
|
|
|
2008-03-14 07:59:12 +08:00
|
|
|
/**
|
|
|
|
* set_mtrr_state - Set the MTRR state for this CPU.
|
|
|
|
*
|
|
|
|
* NOTE: The CPU must already be in a safe state for MTRR changes.
|
|
|
|
* RETURNS: 0 if no changes made, else a mask indicating what was changed.
|
|
|
|
*/
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
static unsigned long set_mtrr_state(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long change_mask = 0;
|
2009-07-04 10:23:00 +08:00
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
for (i = 0; i < num_var_ranges; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (set_mtrr_var_ranges(i, &mtrr_state.var_ranges[i]))
|
|
|
|
change_mask |= MTRR_CHANGE_MASK_VARIABLE;
|
2009-07-04 10:23:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
if (mtrr_state.have_fixed && set_fixed_ranges(mtrr_state.fixed_ranges))
|
2005-04-17 06:20:36 +08:00
|
|
|
change_mask |= MTRR_CHANGE_MASK_FIXED;
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Set_mtrr_restore restores the old value of MTRRdefType,
|
|
|
|
* so to set it we fiddle with the saved value:
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((deftype_lo & 0xff) != mtrr_state.def_type
|
|
|
|
|| ((deftype_lo & 0xc00) >> 10) != mtrr_state.enabled) {
|
2009-07-04 10:23:00 +08:00
|
|
|
|
|
|
|
deftype_lo = (deftype_lo & ~0xcff) | mtrr_state.def_type |
|
|
|
|
(mtrr_state.enabled << 10);
|
2005-04-17 06:20:36 +08:00
|
|
|
change_mask |= MTRR_CHANGE_MASK_DEFTYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return change_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
static unsigned long cr4;
|
2009-07-26 00:33:11 +08:00
|
|
|
static DEFINE_RAW_SPINLOCK(set_atomicity_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2009-07-04 10:23:00 +08:00
|
|
|
* Since we are disabling the cache don't allow any interrupts,
|
|
|
|
* they would run extremely slow and would only increase the pain.
|
|
|
|
*
|
|
|
|
* The caller must ensure that local interrupts are disabled and
|
|
|
|
* are reenabled after post_set() has been called.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-09-26 14:32:36 +08:00
|
|
|
static void prepare_set(void) __acquires(set_atomicity_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long cr0;
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Note that this is not ideal
|
|
|
|
* since the cache is only flushed/disabled for this CPU while the
|
|
|
|
* MTRRs are changed, but changing this requires more invasive
|
|
|
|
* changes to the way the kernel boots
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-26 00:33:11 +08:00
|
|
|
raw_spin_lock(&set_atomicity_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */
|
2008-01-30 20:30:39 +08:00
|
|
|
cr0 = read_cr0() | X86_CR0_CD;
|
2005-04-17 06:20:36 +08:00
|
|
|
write_cr0(cr0);
|
|
|
|
wbinvd();
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Save value of CR4 and clear Page Global Enable (bit 7) */
|
|
|
|
if (cpu_has_pge) {
|
2014-10-25 06:58:08 +08:00
|
|
|
cr4 = __read_cr4();
|
|
|
|
__write_cr4(cr4 & ~X86_CR4_PGE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */
|
2014-01-22 06:33:16 +08:00
|
|
|
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
|
2005-04-17 06:20:36 +08:00
|
|
|
__flush_tlb();
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Save MTRR state */
|
2009-05-14 15:05:46 +08:00
|
|
|
rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Disable MTRRs, and set the default type to uncached */
|
2009-05-14 15:05:46 +08:00
|
|
|
mtrr_wrmsr(MSR_MTRRdefType, deftype_lo & ~0xcff, deftype_hi);
|
2011-11-11 21:01:57 +08:00
|
|
|
wbinvd();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-09-26 14:32:36 +08:00
|
|
|
static void post_set(void) __releases(set_atomicity_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Flush TLBs (no need to flush caches - they are disabled) */
|
2014-01-22 06:33:16 +08:00
|
|
|
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
|
2005-04-17 06:20:36 +08:00
|
|
|
__flush_tlb();
|
|
|
|
|
|
|
|
/* Intel (P6) standard MTRRs */
|
2009-05-14 15:05:46 +08:00
|
|
|
mtrr_wrmsr(MSR_MTRRdefType, deftype_lo, deftype_hi);
|
2009-07-04 10:23:00 +08:00
|
|
|
|
|
|
|
/* Enable caches */
|
2013-04-28 07:22:32 +08:00
|
|
|
write_cr0(read_cr0() & ~X86_CR0_CD);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Restore value of CR4 */
|
|
|
|
if (cpu_has_pge)
|
2014-10-25 06:58:08 +08:00
|
|
|
__write_cr4(cr4);
|
2009-07-26 00:33:11 +08:00
|
|
|
raw_spin_unlock(&set_atomicity_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void generic_set_all(void)
|
|
|
|
{
|
|
|
|
unsigned long mask, count;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
prepare_set();
|
|
|
|
|
|
|
|
/* Actually set the state */
|
[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>
2006-12-07 09:14:09 +08:00
|
|
|
mask = set_mtrr_state();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-19 08:00:14 +08:00
|
|
|
/* also set PAT */
|
|
|
|
pat_init();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
post_set();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/* Use the atomic bitops to update the global mask */
|
2005-04-17 06:20:36 +08:00
|
|
|
for (count = 0; count < sizeof mask * 8; ++count) {
|
|
|
|
if (mask & 0x01)
|
|
|
|
set_bit(count, &smp_changes_mask);
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
2009-07-04 10:23:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/**
|
|
|
|
* generic_set_mtrr - set variable MTRR register on the local CPU.
|
|
|
|
*
|
|
|
|
* @reg: The register to set.
|
|
|
|
* @base: The base address of the region.
|
|
|
|
* @size: The size of the region. If this is 0 the region is disabled.
|
|
|
|
* @type: The type of the region.
|
|
|
|
*
|
|
|
|
* Returns nothing.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static void generic_set_mtrr(unsigned int reg, unsigned long base,
|
|
|
|
unsigned long size, mtrr_type type)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2005-07-08 08:56:38 +08:00
|
|
|
struct mtrr_var_range *vr;
|
|
|
|
|
|
|
|
vr = &mtrr_state.var_ranges[reg];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
prepare_set();
|
|
|
|
|
|
|
|
if (size == 0) {
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* The invalid bit is kept in the mask, so we simply
|
|
|
|
* clear the relevant mask register to disable a range.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
mtrr_wrmsr(MTRRphysMask_MSR(reg), 0, 0);
|
2005-07-08 08:56:38 +08:00
|
|
|
memset(vr, 0, sizeof(struct mtrr_var_range));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2005-07-08 08:56:38 +08:00
|
|
|
vr->base_lo = base << PAGE_SHIFT | type;
|
|
|
|
vr->base_hi = (base & size_and_mask) >> (32 - PAGE_SHIFT);
|
|
|
|
vr->mask_lo = -size << PAGE_SHIFT | 0x800;
|
|
|
|
vr->mask_hi = (-size & size_and_mask) >> (32 - PAGE_SHIFT);
|
|
|
|
|
|
|
|
mtrr_wrmsr(MTRRphysBase_MSR(reg), vr->base_lo, vr->base_hi);
|
|
|
|
mtrr_wrmsr(MTRRphysMask_MSR(reg), vr->mask_lo, vr->mask_hi);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
post_set();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
int generic_validate_add_page(unsigned long base, unsigned long size,
|
|
|
|
unsigned int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long lbase, last;
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* For Intel PPro stepping <= 7
|
|
|
|
* must be 4 MiB aligned and not touch 0x70000000 -> 0x7003FFFF
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 &&
|
|
|
|
boot_cpu_data.x86_model == 1 &&
|
|
|
|
boot_cpu_data.x86_mask <= 7) {
|
|
|
|
if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) {
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: base(0x%lx000) is not 4 MiB aligned\n", base);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-12-07 09:14:00 +08:00
|
|
|
if (!(base + size < 0x70000 || base > 0x7003F) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
(type == MTRR_TYPE_WRCOMB
|
|
|
|
|| type == MTRR_TYPE_WRBACK)) {
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: writable mtrr between 0x70000000 and 0x7003FFFF may hang the CPU.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Check upper bits of base and last are equal and lower bits are 0
|
|
|
|
* for base and 1 for last
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
last = base + size - 1;
|
|
|
|
for (lbase = base; !(lbase & 1) && (last & 1);
|
2009-07-04 10:23:00 +08:00
|
|
|
lbase = lbase >> 1, last = last >> 1)
|
|
|
|
;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lbase != last) {
|
2009-07-04 10:23:00 +08:00
|
|
|
pr_warning("mtrr: base(0x%lx000) is not aligned on a size(0x%lx000) boundary\n", base, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int generic_have_wrcomb(void)
|
|
|
|
{
|
|
|
|
unsigned long config, dummy;
|
2009-05-14 14:36:12 +08:00
|
|
|
rdmsr(MSR_MTRRcap, config, dummy);
|
2009-07-04 10:23:00 +08:00
|
|
|
return config & (1 << 10);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int positive_have_wrcomb(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-07-04 10:23:00 +08:00
|
|
|
/*
|
|
|
|
* Generic structure...
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2010-02-01 03:16:34 +08:00
|
|
|
const struct mtrr_ops generic_mtrr_ops = {
|
2009-07-04 10:23:00 +08:00
|
|
|
.use_intel_if = 1,
|
|
|
|
.set_all = generic_set_all,
|
|
|
|
.get = generic_get_mtrr,
|
|
|
|
.get_free_region = generic_get_free_region,
|
|
|
|
.set = generic_set_mtrr,
|
|
|
|
.validate_add_page = generic_validate_add_page,
|
|
|
|
.have_wrcomb = generic_have_wrcomb,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|