[patch 07/42] x86: work around MTRR mask setting

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg KH
Date: Wednesday, September 3, 2008 - 10:25 am

2.6.26-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Yinghai Lu <yhlu.kernel@gmail.com>

commit 38cc1c3df77c1bb739a4766788eb9fa49f16ffdf upstream

Joshua Hoblitt reported that only 3 GB of his 16 GB of RAM is
usable. Booting with mtrr_show showed us the BIOS-initialized
MTRR settings - which are all wrong.

So the root cause is that the BIOS has not set the mask correctly:


So detect this borkage and add the prefix 111.

Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 arch/x86/kernel/cpu/mtrr/generic.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -365,6 +365,7 @@ static void generic_get_mtrr(unsigned in
 			     unsigned long *size, mtrr_type *type)
 {
 	unsigned int mask_lo, mask_hi, base_lo, base_hi;
+	unsigned int tmp, hi;
 
 	rdmsr(MTRRphysMask_MSR(reg), mask_lo, mask_hi);
 	if ((mask_lo & 0x800) == 0) {
@@ -378,8 +379,18 @@ static void generic_get_mtrr(unsigned in
 	rdmsr(MTRRphysBase_MSR(reg), base_lo, base_hi);
 
 	/* Work out the shifted address mask. */
-	mask_lo = size_or_mask | mask_hi << (32 - PAGE_SHIFT)
-	    | mask_lo >> PAGE_SHIFT;
+	tmp = mask_hi << (32 - PAGE_SHIFT) | mask_lo >> PAGE_SHIFT;
+	mask_lo = size_or_mask | tmp;
+	/* Expand tmp with high bits to all 1s*/
+	hi = fls(tmp);
+	if (hi > 0) {
+		tmp |= ~((1<<(hi - 1)) - 1);
+
+		if (tmp != mask_lo) {
+			WARN_ON("mtrr: your BIOS has set up an incorrect mask, fixing it up.\n");
+			mask_lo = tmp;
+		}
+	}
 
 	/* This works correctly if size is a power of two, i.e. a
 	   contiguous range. */

-- 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/42] 2.6.26-stable review, Greg KH, (Wed Sep 3, 10:24 am)
[patch 01/42] cramfs: fix named-pipe handling, Greg KH, (Wed Sep 3, 10:25 am)
[patch 03/42] eeepc-laptop: fix use after free, Greg KH, (Wed Sep 3, 10:25 am)
[patch 07/42] x86: work around MTRR mask setting, Greg KH, (Wed Sep 3, 10:25 am)
[patch 13/42] forcedeth: fix checksum flag, Greg KH, (Wed Sep 3, 10:25 am)
[patch 14/42] atl1: disable TSO by default, Greg KH, (Wed Sep 3, 10:25 am)
[patch 24/42] pkt_sched: Fix actions referencing, Greg KH, (Wed Sep 3, 10:26 am)
[patch 36/42] tg3: Fix firmware event timeouts, Greg KH, (Wed Sep 3, 10:26 am)
[patch 41/42] KVM: MMU: Fix torn shadow pte, Greg KH, (Wed Sep 3, 10:26 am)
Re: [patch 29/42] net: Unbreak userspace which includes li ..., Stefan Lippers-Hollmann, (Wed Sep 3, 12:16 pm)
Re: [patch 00/42] 2.6.26-stable review, Henrique de Moraes H ..., (Wed Sep 3, 7:39 pm)
Re: [patch 00/42] 2.6.26-stable review, Andi Kleen, (Thu Sep 4, 5:21 am)
Re: [patch 00/42] 2.6.26-stable review, Milan Broz, (Thu Sep 4, 5:28 am)
Re: [patch 00/42] 2.6.26-stable review, Andi Kleen, (Thu Sep 4, 6:58 am)
Re: [patch 00/42] 2.6.26-stable review, Pavel Machek, (Fri Sep 12, 7:22 am)
Re: [patch 00/42] 2.6.26-stable review, Andi Kleen, (Fri Sep 12, 8:37 am)
Re: [patch 00/42] 2.6.26-stable review, Henrique de Moraes H ..., (Fri Sep 12, 12:46 pm)
Re: [patch 00/42] 2.6.26-stable review, Pavel Machek, (Sat Sep 13, 9:56 am)