]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[ARM] prevent crashing when too much RAM installed
authorLennert Buytenhek <buytenh@wantstofly.org>
Mon, 4 Aug 2008 23:56:13 +0000 (01:56 +0200)
committerLennert Buytenhek <buytenh@marvell.com>
Sat, 9 Aug 2008 13:38:15 +0000 (15:38 +0200)
This patch will truncate and/or ignore memory banks if their kernel
direct mappings would (partially) overlap with the vmalloc area or
the mappings between the vmalloc area and the address space top, to
prevent crashing during early boot if there happens to be more RAM
installed than we are expecting.

Since the start of the vmalloc area is not at a fixed address (but
the vmalloc end address is, via the per-platform VMALLOC_END define),
a default area of 128M is reserved for vmalloc mappings, which can
be shrunk or enlarged by passing an appropriate vmalloc= command line
option as it is done on x86.

On a board with a 3:1 user:kernel split, VMALLOC_END at 0xfe000000,
two 512M RAM banks and vmalloc=128M (the default), this patch gives:

Truncating RAM at 20000000-3fffffff to -35ffffff (vmalloc region overlap).
Memory: 512MB 352MB = 864MB total

On a board with a 3:1 user:kernel split, VMALLOC_END at 0xfe800000,
two 256M RAM banks and vmalloc=768M, this patch gives:

Truncating RAM at 00000000-0fffffff to -0e7fffff (vmalloc region overlap).
Ignoring RAM at 10000000-1fffffff (vmalloc region overlap).

Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Tested-by: Riku Voipio <riku.voipio@iki.fi>
arch/arm/include/asm/memory.h
arch/arm/kernel/setup.c
arch/arm/mm/mmu.c

index 1e070a2b561aa3390a02abf4ce0263b06a9055f0..7bcd69a9a88c85df35e6b31ef60c322d545691d2 100644 (file)
 #define arch_adjust_zones(node,size,holes) do { } while (0)
 #endif
 
+/*
+ * Amount of memory reserved for the vmalloc() area, and minimum
+ * address for vmalloc mappings.
+ */
+extern unsigned long vmalloc_reserve;
+
+#define VMALLOC_MIN            (void *)(VMALLOC_END - vmalloc_reserve)
+
 /*
  * PFNs are used to describe any physical page; this means
  * PFN 0 == physical address 0.
index 38f0e7940a132b1c9e0458bc10e9d1dc3f2401ee..2ca7038b67a7bf105df3529491e0f9858220ca76 100644 (file)
@@ -81,6 +81,8 @@ EXPORT_SYMBOL(system_serial_high);
 unsigned int elf_hwcap;
 EXPORT_SYMBOL(elf_hwcap);
 
+unsigned long __initdata vmalloc_reserve = 128 << 20;
+
 
 #ifdef MULTI_CPU
 struct processor processor;
@@ -500,6 +502,17 @@ static void __init early_mem(char **p)
 }
 __early_param("mem=", early_mem);
 
+/*
+ * vmalloc=size forces the vmalloc area to be exactly 'size'
+ * bytes. This can be used to increase (or decrease) the vmalloc
+ * area - the default is 128m.
+ */
+static void __init early_vmalloc(char **arg)
+{
+       vmalloc_reserve = memparse(*arg, arg);
+}
+__early_param("vmalloc=", early_vmalloc);
+
 /*
  * Initial parsing of the command line.
  */
index 2d6d682c206a814e5b7c41d7e8ce851f68721b18..25d9a11eb61750ade3ba77abd7771068ebe668ee 100644 (file)
@@ -568,6 +568,55 @@ void __init iotable_init(struct map_desc *io_desc, int nr)
                create_mapping(io_desc + i);
 }
 
+static int __init check_membank_valid(struct membank *mb)
+{
+       /*
+        * Check whether this memory region has non-zero size.
+        */
+       if (mb->size == 0)
+               return 0;
+
+       /*
+        * Check whether this memory region would entirely overlap
+        * the vmalloc area.
+        */
+       if (phys_to_virt(mb->start) >= VMALLOC_MIN) {
+               printk(KERN_NOTICE "Ignoring RAM at %.8lx-%.8lx "
+                       "(vmalloc region overlap).\n",
+                       mb->start, mb->start + mb->size - 1);
+               return 0;
+       }
+
+       /*
+        * Check whether this memory region would partially overlap
+        * the vmalloc area.
+        */
+       if (phys_to_virt(mb->start + mb->size) < phys_to_virt(mb->start) ||
+           phys_to_virt(mb->start + mb->size) > VMALLOC_MIN) {
+               unsigned long newsize = VMALLOC_MIN - phys_to_virt(mb->start);
+
+               printk(KERN_NOTICE "Truncating RAM at %.8lx-%.8lx "
+                       "to -%.8lx (vmalloc region overlap).\n",
+                       mb->start, mb->start + mb->size - 1,
+                       mb->start + newsize - 1);
+               mb->size = newsize;
+       }
+
+       return 1;
+}
+
+static void __init sanity_check_meminfo(struct meminfo *mi)
+{
+       int i;
+       int j;
+
+       for (i = 0, j = 0; i < mi->nr_banks; i++) {
+               if (check_membank_valid(&mi->bank[i]))
+                       mi->bank[j++] = mi->bank[i];
+       }
+       mi->nr_banks = j;
+}
+
 static inline void prepare_page_table(struct meminfo *mi)
 {
        unsigned long addr;
@@ -753,6 +802,7 @@ void __init paging_init(struct meminfo *mi, struct machine_desc *mdesc)
        void *zero_page;
 
        build_mem_type_table();
+       sanity_check_meminfo(mi);
        prepare_page_table(mi);
        bootmem_init(mi);
        devicemaps_init(mdesc);