1 #include <linux/module.h>
2 #include <linux/sched.h>
8 * Some BIOSes seem to corrupt the low 64k of memory during events
9 * like suspend/resume and unplugging an HDMI cable. Reserve all
10 * remaining free memory in that area and fill it with a distinct
13 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
14 #define MAX_SCAN_AREAS 8
16 static int __read_mostly memory_corruption_check = -1;
18 static unsigned __read_mostly corruption_check_size = 64*1024;
19 static unsigned __read_mostly corruption_check_period = 60; /* seconds */
21 static struct e820entry scan_areas[MAX_SCAN_AREAS];
22 static int num_scan_areas;
25 static int set_corruption_check(char *arg)
29 memory_corruption_check = simple_strtol(arg, &end, 10);
31 return (*end == 0) ? 0 : -EINVAL;
33 early_param("memory_corruption_check", set_corruption_check);
35 static int set_corruption_check_period(char *arg)
39 corruption_check_period = simple_strtoul(arg, &end, 10);
41 return (*end == 0) ? 0 : -EINVAL;
43 early_param("memory_corruption_check_period", set_corruption_check_period);
45 static int set_corruption_check_size(char *arg)
50 size = memparse(arg, &end);
53 corruption_check_size = size;
55 return (size == corruption_check_size) ? 0 : -EINVAL;
57 early_param("memory_corruption_check_size", set_corruption_check_size);
60 void __init setup_bios_corruption_check(void)
62 u64 addr = PAGE_SIZE; /* assume first page is reserved anyway */
64 if (memory_corruption_check == -1) {
65 memory_corruption_check =
66 #ifdef CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK
74 if (corruption_check_size == 0)
75 memory_corruption_check = 0;
77 if (!memory_corruption_check)
80 corruption_check_size = round_up(corruption_check_size, PAGE_SIZE);
82 while (addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) {
84 addr = find_e820_area_size(addr, &size, PAGE_SIZE);
89 if ((addr + size) > corruption_check_size)
90 size = corruption_check_size - addr;
95 e820_update_range(addr, size, E820_RAM, E820_RESERVED);
96 scan_areas[num_scan_areas].addr = addr;
97 scan_areas[num_scan_areas].size = size;
100 /* Assume we've already mapped this early memory */
101 memset(__va(addr), 0, size);
106 printk(KERN_INFO "Scanning %d areas for low memory corruption\n",
111 static struct timer_list periodic_check_timer;
113 void check_for_bios_corruption(void)
118 if (!memory_corruption_check)
121 for (i = 0; i < num_scan_areas; i++) {
122 unsigned long *addr = __va(scan_areas[i].addr);
123 unsigned long size = scan_areas[i].size;
125 for (; size; addr++, size -= sizeof(unsigned long)) {
128 printk(KERN_ERR "Corrupted low memory at %p (%lx phys) = %08lx\n",
129 addr, __pa(addr), *addr);
135 WARN(corruption, KERN_ERR "Memory corruption detected in low memory\n");
138 static void periodic_check_for_corruption(unsigned long data)
140 check_for_bios_corruption();
141 mod_timer(&periodic_check_timer,
142 round_jiffies(jiffies + corruption_check_period*HZ));
145 void start_periodic_check_for_corruption(void)
147 if (!memory_corruption_check || corruption_check_period == 0)
150 printk(KERN_INFO "Scanning for low memory corruption every %d seconds\n",
151 corruption_check_period);
153 init_timer(&periodic_check_timer);
154 periodic_check_timer.function = &periodic_check_for_corruption;
155 periodic_check_for_corruption(0);