[PATCH] x86: trim ram need to check if mtrr is there v3

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Jeremy Fitzhardinge <jeremy@...>
Cc: H. Peter Anvin <hpa@...>, Ingo Molnar <mingo@...>, Linux Kernel Mailing List <linux-kernel@...>
Date: Friday, January 25, 2008 - 4:42 am

[PATCH] x86: trim ram need to check if mtrr is there v3


so more strict check if mtrr is there really.
bail out if mtrr all blank when qemu cpu model is used

and check if is AMD as early
also remove 4G less check, according to hpa.

Signed-off-by: Yinghai Lu <yinghai.lu@sun.com>

Index: linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/main.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
@@ -642,13 +642,10 @@ early_param("disable_mtrr_trim", disable
 #define Tom2Enabled (1U << 21)
 #define Tom2ForceMemTypeWB (1U << 22)
 
-static __init int amd_special_default_mtrr(unsigned long end_pfn)
+static __init int amd_special_default_mtrr(void)
 {
 	u32 l, h;
 
-	/* Doesn't apply to memory < 4GB */
-	if (end_pfn <= (0xffffffff >> PAGE_SHIFT))
-		return 0;
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
 		return 0;
 	if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
@@ -686,9 +683,14 @@ int __init mtrr_trim_uncached_memory(uns
 	 * Make sure we only trim uncachable memory on machines that
 	 * support the Intel MTRR architecture:
 	 */
+	if (!is_cpu(INTEL) || disable_mtrr_trim)
+		return 0;
 	rdmsr(MTRRdefType_MSR, def, dummy);
 	def &= 0xff;
-	if (!is_cpu(INTEL) || disable_mtrr_trim || def != MTRR_TYPE_UNCACHABLE)
+	if (def != MTRR_TYPE_UNCACHABLE)
+		return 0;
+
+	if (amd_special_default_mtrr())
 		return 0;
 
 	/* Find highest cached pfn */
@@ -702,8 +704,14 @@ int __init mtrr_trim_uncached_memory(uns
 			highest_addr = base + size;
 	}
 
-	if (amd_special_default_mtrr(end_pfn))
+	/* kvm/qemu doesn't have mtrr set right, don't trim them all */
+	if (!highest_addr) {
+		printk(KERN_WARNING "***************\n");
+		printk(KERN_WARNING "**** WARNING: likely strange cpu\n");
+		printk(KERN_WARNING "**** MTRRs all blank, cpu in qemu?\n");
+		printk(KERN_WARNING "***************\n");
 		return 0;
+	}
 
 	if ((highest_addr >> PAGE_SHIFT) < end_pfn) {
 		printk(KERN_WARNING "***************\n");
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
x86.git: mtrr trimming removes all memory under kvm, Jeremy Fitzhardinge, (Thu Jan 24, 9:44 pm)
Re: x86.git: mtrr trimming removes all memory under kvm, H. Peter Anvin, (Thu Jan 24, 9:49 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v2, Jeremy Fitzhardinge, (Fri Jan 25, 3:43 am)
[PATCH] x86: trim ram need to check if mtrr is there v3, Yinghai Lu, (Fri Jan 25, 4:42 am)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, H. Peter Anvin, (Fri Jan 25, 11:57 am)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 2:59 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 2:55 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 3:04 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 3:01 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 3:27 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 3:39 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v2, H. Peter Anvin, (Fri Jan 25, 11:47 am)