linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <Yinghai.Lu@Sun.COM>
To: Ingo Molnar <mingo@elte.hu>
Cc: Andi Kleen <ak@suse.de>, "H. Peter Anvin" <hpa@zytor.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Jesse Barnes <jesse.barnes@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] x86_64: update e820 instead of updating end_pfn v2
Date: Sun, 20 Jan 2008 21:40:57 -0800	[thread overview]
Message-ID: <200801202140.57829.yinghai.lu@sun.com> (raw)
In-Reply-To: <200801201608.15401.ak@suse.de>

[PATCH] x86_64: update e820 instead of updating end_pfn v2

need to be applied after andi's patch for AMD tom2 wb check

when mtrr is not covering all e820 table, need to trim the ram, need to update e820

so we can reuse some code for x86_32.

need to add early_identify_cpu for x86_32, and move mtrr_bp_init early

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
@@ -624,6 +624,7 @@ static struct sysdev_driver mtrr_sysdev_
 	.resume		= mtrr_restore,
 };
 
+#ifdef CONFIG_X86_64
 static int disable_mtrr_trim;
 
 static int __init disable_mtrr_trim_setup(char *str)
@@ -633,17 +634,16 @@ static int __init disable_mtrr_trim_setu
 }
 early_param("disable_mtrr_trim", disable_mtrr_trim_setup);
 
-#ifdef CONFIG_X86_64
-
 /*
  * Newer AMD K8s and later CPUs have a special magic MSR way to force WB
  * for memory >4GB. Check for that here.
  * Note this won't check if the MTRRs < 4GB where the magic bit doesn't
  * apply to are wrong, but so far we don't know of any such case in the wild.
  */
+#define Tom2Enabled (1U << 21)
 #define Tom2ForceMemTypeWB (1U << 22)
 
-static __init int amd_special_default_mtrr(void)
+static __init int amd_special_default_mtrr(unsigned long end_pfn)
 {
 	u32 l, h;
 
@@ -661,8 +661,9 @@ static __init int amd_special_default_mt
 	 * Memory between 4GB and top of mem is forced WB by this magic bit.
 	 * Reserved before K8RevF, but should be zero there.
 	 */
-	if (l & Tom2ForceMemTypeWB)
-		return 1;
+	if (l & Tom2Enabled)
+		if (l & Tom2ForceMemTypeWB)
+			return 1;
 	return 0;
 }
 
@@ -676,10 +677,11 @@ static __init int amd_special_default_mt
  * memory off the end by adjusting end_pfn, removing it from the kernel's
  * allocation pools, warning the user with an obnoxious message.
  */
-void __init mtrr_trim_uncached_memory(void)
+int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
 	unsigned long i, base, size, highest_addr = 0, def, dummy;
 	mtrr_type type;
+	u64 trim_start, trim_size;
 
 	/*
 	 * Make sure we only trim uncachable memory on machines that
@@ -688,7 +690,7 @@ void __init mtrr_trim_uncached_memory(vo
 	rdmsr(MTRRdefType_MSR, def, dummy);
 	def &= 0xff;
 	if (!is_cpu(INTEL) || disable_mtrr_trim || def != MTRR_TYPE_UNCACHABLE)
-		return;
+		return 0;
 
 	/* Find highest cached pfn */
 	for (i = 0; i < num_var_ranges; i++) {
@@ -701,8 +703,8 @@ void __init mtrr_trim_uncached_memory(vo
 			highest_addr = base + size;
 	}
 
-	if (amd_special_default_mtrr())
-		return;
+	if (amd_special_default_mtrr(end_pfn))
+		return 0;
 
 	if ((highest_addr >> PAGE_SHIFT) < end_pfn) {
 		printk(KERN_WARNING "***************\n");
@@ -711,8 +713,18 @@ void __init mtrr_trim_uncached_memory(vo
 		       "memory, trimmed %ld pages\n", end_pfn -
 		       (highest_addr >> PAGE_SHIFT));
 		printk(KERN_WARNING "***************\n");
-		end_pfn = highest_addr >> PAGE_SHIFT;
+
+		printk(KERN_INFO "update e820 for mtrr\n");
+		trim_start = highest_addr;
+		trim_size = end_pfn;
+		trim_size <<= PAGE_SHIFT;
+		trim_size -= trim_start;
+		add_memory_region(trim_start, trim_size, E820_RESERVED);
+		update_e820();
+		return 1;
 	}
+
+	return 0;
 }
 #endif
 
Index: linux-2.6/arch/x86/kernel/setup_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup_64.c
+++ linux-2.6/arch/x86/kernel/setup_64.c
@@ -324,9 +324,12 @@ void __init setup_arch(char **cmdline_p)
 	 * we are rounding upwards:
 	 */
 	end_pfn = e820_end_of_ram();
-	/* Trim memory not covered by WB MTRRs */
+	/* update e820 for memory not covered by WB MTRRs */
 	mtrr_bp_init();
-	mtrr_trim_uncached_memory();
+	if (mtrr_trim_uncached_memory(end_pfn)) {
+		e820_register_active_regions(0, 0, -1UL);
+		end_pfn = e820_end_of_ram();
+	}
 
 	num_physpages = end_pfn;
 
Index: linux-2.6/include/asm-x86/mtrr.h
===================================================================
--- linux-2.6.orig/include/asm-x86/mtrr.h
+++ linux-2.6/include/asm-x86/mtrr.h
@@ -97,7 +97,7 @@ extern int mtrr_del_page (int reg, unsig
 extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
 extern void mtrr_ap_init(void);
 extern void mtrr_bp_init(void);
-extern void mtrr_trim_uncached_memory(void);
+extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
 #  else
 #define mtrr_save_fixed_ranges(arg) do {} while (0)
 #define mtrr_save_state() do {} while (0)
@@ -121,8 +121,9 @@ static __inline__ int mtrr_del_page (int
 {
     return -ENODEV;
 }
-static __inline__ void mtrr_trim_uncached_memory(void)
+static __inline__ int mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
+	return 0;
 }
 static __inline__ void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi) {;}
 

  reply	other threads:[~2008-01-21  5:39 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-20  4:45 [PATCH] x86: disable_mtrr_trim only need for x86_64 Yinghai Lu
2008-01-20  5:37 ` H. Peter Anvin
2008-01-20  6:55   ` Yinghai Lu
2008-01-20  8:17   ` [PATCH] x86_64: update e820 instead of updating end_pfn Yinghai Lu
2008-01-20  9:20     ` Ingo Molnar
2008-01-20 15:08       ` Andi Kleen
2008-01-21  5:40         ` Yinghai Lu [this message]
2008-01-21  5:44           ` [PATCH] x86_32: trim memory by updating e820 Yinghai Lu
2008-01-21  5:58           ` [PATCH] x86_64: update e820 instead of updating end_pfn v2 Andi Kleen
2008-01-21  6:05             ` Harvey Harrison
2008-01-21  6:08               ` Andi Kleen
2008-01-21  6:14                 ` Li Zefan
2008-01-21  6:57             ` [PATCH] x86_64: check if Tom2 is enabled Yinghai Lu
2008-01-21 17:24               ` Cyrill Gorcunov
2008-01-21 17:39                 ` H. Peter Anvin
2008-01-21 17:49                   ` Cyrill Gorcunov
2008-01-21 18:03                 ` Andi Kleen
2008-01-21 18:09                   ` Cyrill Gorcunov
2008-01-21 18:15                     ` H. Peter Anvin
2008-01-21 18:46                       ` Andi Kleen
2008-01-21  0:00       ` [PATCH] x86_64: update e820 instead of updating end_pfn Yinghai Lu
     [not found] ` <200801202255.02645.yinghai.lu@sun.com>
     [not found]   ` <200801202255.58642.yinghai.lu@sun.com>
2008-01-21  6:56     ` [PATCH] x86_32: trim memory by updating e820 v2 Yinghai Lu
2008-01-21 16:30       ` Jesse Barnes
2008-01-21 19:14         ` Justin Piszcz
2008-01-21 20:09           ` Yinghai Lu
2008-01-21 21:37             ` Justin Piszcz
2008-01-23  3:50               ` Yinghai Lu
2008-01-26  0:01                 ` Justin Piszcz
2008-01-26  0:16                   ` Yinghai Lu
2008-01-26  0:37                     ` Justin Piszcz
2008-01-28 15:09                   ` Ingo Molnar
2008-01-28 18:07                     ` Justin Piszcz
2008-01-22 16:51       ` Ingo Molnar
2008-01-23  0:23         ` [PATCH] x86_32: trim memory by updating e820 v3 Yinghai Lu
2008-04-26 10:56           ` Andrew Morton
2008-04-26 12:56             ` Gabriel C
2008-04-27  1:05               ` Yinghai Lu
2008-04-28 18:07                 ` Eric W. Biederman
2008-04-28 23:16                   ` Yinghai Lu
2008-04-29 10:31                   ` Ingo Molnar
2008-04-29 17:29                     ` Eric W. Biederman
2008-04-29 18:40                       ` Yinghai Lu
2008-04-29 19:19                         ` Eric W. Biederman
2008-04-29 19:44                           ` Yinghai Lu
2008-04-29 20:02                             ` Eric W. Biederman
2008-04-28  6:44               ` Yinghai Lu
2008-04-28  9:18                 ` Gabriel C
2008-04-28  9:34                   ` Yinghai Lu
2008-04-28  9:54                     ` Gabriel C
2008-04-28 10:03                       ` Gabriel C
2008-04-28 10:07                         ` Mika Fischer
2008-04-28 19:03                           ` Yinghai Lu
2008-04-28 13:53                       ` Ingo Molnar
2008-04-28 14:11                         ` Mika Fischer
2008-04-28 14:24                           ` Gabriel C
2008-04-28 19:06                             ` Yinghai Lu
2008-04-28 19:38                               ` Gabriel C
2008-04-28 20:45                                 ` Gabriel C
2008-04-28 21:19                                   ` Gabriel C
2008-04-28 22:03                                     ` Yinghai Lu
2008-04-28 22:56                                       ` Gabriel C
2008-04-28 23:23                                         ` Yinghai Lu
2008-04-29  1:05                                           ` Gabriel C
2008-04-29  2:41                                             ` Yinghai Lu
2008-04-29 10:34                                               ` Ingo Molnar
2008-04-29 10:42                                                 ` Yinghai Lu
2008-04-28 19:08                             ` Yinghai Lu
2008-04-28 19:46                               ` Gabriel C
2008-04-28 14:15                         ` Gabriel C
2008-04-28 16:09                         ` Jesse Barnes
2008-04-28 16:31                           ` Mika Fischer
2008-04-28 16:55                             ` Jesse Barnes
2008-04-29 10:37                           ` Ingo Molnar
2008-04-29 12:40                             ` Andrew Morton
2008-04-29 15:52                             ` Jesse Barnes
2008-04-29 22:03                               ` [patch] PCI: export resource_wc in pci sysfs Ingo Molnar
2008-04-29 22:24                                 ` Andrew Morton
2008-04-27  0:57             ` [PATCH] x86_32: trim memory by updating e820 v3 Yinghai Lu
2008-04-27  8:21               ` Mika Fischer
2008-04-27  1:22             ` Yinghai Lu
2008-04-27  8:29               ` Mika Fischer
2008-04-28  6:50             ` Yinghai Lu
2008-04-28  8:38               ` Mika Fischer
2008-04-28  9:09                 ` Yinghai Lu
2008-04-28  9:44                   ` Mika Fischer
2008-04-28  9:58                     ` Gabriel C
2008-01-21  6:57   ` [PATCH] x86_64: update e820 instead of updating end_pfn v3 Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200801202140.57829.yinghai.lu@sun.com \
    --to=yinghai.lu@sun.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jesse.barnes@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).