aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYinghai Lu <yinghai.lu@sun.com>2008-02-06 16:39:45 -0500
committerIngo Molnar <mingo@elte.hu>2008-02-06 16:39:45 -0500
commit20651af9ac60fd6e31360688ad44861a7d05256a (patch)
treea5081b8ffddf2d2d931c16ae2528fd3679ba9760
parent971a52d66a3e87d4d2f5d3455e62680447cdb8e9 (diff)
x86: fix mttr trimming
Pavel Emelyanov reported that his networking card did not work and bisected it down to: " The commit 093af8d7f0ba3c6be1485973508584ef081e9f93 x86_32: trim memory by updating e820 broke my e1000 card: on loading driver says that e1000: probe of 0000:04:03.0 failed with error -5 and the interface doesn't appear. " on a 32-bit kernel, base will overflow when try to do PAGE_SHIFT, and highest_addr will always less 4G. So use pfn instead of address to avoid the overflow when more than 4g RAM is installed on a 32-bit kernel. Many thanks to Pavel Emelyanov for reporting and testing it. Bisected-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Yinghai Lu <yinghai.lu@sun.com> Tested-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/cpu/mtrr/main.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
index 1e27b69a7a0e..b6e136f23d3d 100644
--- a/arch/x86/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
@@ -659,7 +659,7 @@ static __init int amd_special_default_mtrr(void)
659 */ 659 */
660int __init mtrr_trim_uncached_memory(unsigned long end_pfn) 660int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
661{ 661{
662 unsigned long i, base, size, highest_addr = 0, def, dummy; 662 unsigned long i, base, size, highest_pfn = 0, def, dummy;
663 mtrr_type type; 663 mtrr_type type;
664 u64 trim_start, trim_size; 664 u64 trim_start, trim_size;
665 665
@@ -682,28 +682,27 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
682 mtrr_if->get(i, &base, &size, &type); 682 mtrr_if->get(i, &base, &size, &type);
683 if (type != MTRR_TYPE_WRBACK) 683 if (type != MTRR_TYPE_WRBACK)
684 continue; 684 continue;
685 base <<= PAGE_SHIFT; 685 if (highest_pfn < base + size)
686 size <<= PAGE_SHIFT; 686 highest_pfn = base + size;
687 if (highest_addr < base + size)
688 highest_addr = base + size;
689 } 687 }
690 688
691 /* kvm/qemu doesn't have mtrr set right, don't trim them all */ 689 /* kvm/qemu doesn't have mtrr set right, don't trim them all */
692 if (!highest_addr) { 690 if (!highest_pfn) {
693 printk(KERN_WARNING "WARNING: strange, CPU MTRRs all blank?\n"); 691 printk(KERN_WARNING "WARNING: strange, CPU MTRRs all blank?\n");
694 WARN_ON(1); 692 WARN_ON(1);
695 return 0; 693 return 0;
696 } 694 }
697 695
698 if ((highest_addr >> PAGE_SHIFT) < end_pfn) { 696 if (highest_pfn < end_pfn) {
699 printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover" 697 printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover"
700 " all of memory, losing %LdMB of RAM.\n", 698 " all of memory, losing %luMB of RAM.\n",
701 (((u64)end_pfn << PAGE_SHIFT) - highest_addr) >> 20); 699 (end_pfn - highest_pfn) >> (20 - PAGE_SHIFT));
702 700
703 WARN_ON(1); 701 WARN_ON(1);
704 702
705 printk(KERN_INFO "update e820 for mtrr\n"); 703 printk(KERN_INFO "update e820 for mtrr\n");
706 trim_start = highest_addr; 704 trim_start = highest_pfn;
705 trim_start <<= PAGE_SHIFT;
707 trim_size = end_pfn; 706 trim_size = end_pfn;
708 trim_size <<= PAGE_SHIFT; 707 trim_size <<= PAGE_SHIFT;
709 trim_size -= trim_start; 708 trim_size -= trim_start;