Skip to content

Commit 8a37402

Browse files
Yinghai LuKAGA-KOKO
authored andcommitted
x86: fix trimming e820 with MTRR holes. - fix
v2: process hole then end_pfn fix update_memory_range with whole cover comparing Signed-off-by: Yinghai Lu <yinghai.lu@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 42651f1 commit 8a37402

3 files changed

Lines changed: 19 additions & 31 deletions

File tree

‎arch/x86/kernel/cpu/mtrr/main.c‎

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,11 +1098,12 @@ int __init amd_special_default_mtrr(void)
10981098
static u64 __init real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
10991099
{
11001100
u64 trim_start, trim_size;
1101-
trim_start = start_pfn;
1101+
trim_start = start_pfn;
11021102
trim_start <<= PAGE_SHIFT;
11031103
trim_size = limit_pfn;
11041104
trim_size <<= PAGE_SHIFT;
11051105
trim_size -= trim_start;
1106+
11061107
return update_memory_range(trim_start, trim_size, E820_RAM,
11071108
E820_RESERVED);
11081109
}
@@ -1124,7 +1125,6 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
11241125
struct res_range range[RANGE_NUM];
11251126
int nr_range;
11261127
u64 total_real_trim_size;
1127-
int changed;
11281128

11291129
/* extra one for all 0 */
11301130
int num[MTRR_NUM_TYPES + 1];
@@ -1189,49 +1189,35 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
11891189
}
11901190
nr_range = x86_get_mtrr_mem_range(range, nr_range, 0, 0);
11911191

1192-
changed = 0;
1193-
total_real_trim_size = 0;
1194-
1195-
/* check the top at first */
1196-
i = nr_range - 1;
1197-
if (range[i].end + 1 < end_pfn) {
1198-
total_real_trim_size += real_trim_memory(range[i].end + 1, end_pfn);
1199-
}
1200-
1201-
if (total_real_trim_size) {
1202-
printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover"
1203-
" all of memory, losing %lluMB of RAM.\n",
1204-
total_real_trim_size >> 20);
1205-
1206-
WARN_ON(1);
1207-
1208-
printk(KERN_INFO "update e820 for mtrr -- end_pfn\n");
1209-
update_e820();
1210-
changed = 1;
1211-
}
1212-
12131192
total_real_trim_size = 0;
1193+
/* check the head */
12141194
if (range[0].start)
12151195
total_real_trim_size += real_trim_memory(0, range[0].start);
1216-
1217-
for (i = 0; i < nr_range - 1; i--) {
1196+
/* check the holes */
1197+
for (i = 0; i < nr_range - 1; i++) {
12181198
if (range[i].end + 1 < range[i+1].start)
12191199
total_real_trim_size += real_trim_memory(range[i].end + 1, range[i+1].start);
12201200
}
1201+
/* check the top */
1202+
i = nr_range - 1;
1203+
if (range[i].end + 1 < end_pfn)
1204+
total_real_trim_size += real_trim_memory(range[i].end + 1, end_pfn);
12211205

12221206
if (total_real_trim_size) {
12231207
printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover"
12241208
" all of memory, losing %lluMB of RAM.\n",
12251209
total_real_trim_size >> 20);
12261210

1227-
WARN_ON(1);
1211+
if (enable_mtrr_cleanup < 1)
1212+
WARN_ON(1);
12281213

1229-
printk(KERN_INFO "update e820 for mtrr -- holes\n");
1214+
printk(KERN_INFO "update e820 for mtrr\n");
12301215
update_e820();
1231-
changed = 1;
1216+
1217+
return 1;
12321218
}
12331219

1234-
return changed;
1220+
return 0;
12351221
}
12361222

12371223
/**

‎arch/x86/kernel/e820_32.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@ u64 __init update_memory_range(u64 start, u64 size, unsigned old_type,
797797
if (ei->type != old_type)
798798
continue;
799799
/* totally covered? */
800-
if (ei->addr >= start && ei->size <= size) {
800+
if (ei->addr >= start &&
801+
(ei->addr + ei->size) <= (start + size)) {
801802
ei->type = new_type;
802803
real_updated_size += ei->size;
803804
continue;

‎arch/x86/kernel/e820_64.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,8 @@ u64 __init update_memory_range(u64 start, u64 size, unsigned old_type,
843843
if (ei->type != old_type)
844844
continue;
845845
/* totally covered? */
846-
if (ei->addr >= start && ei->size <= size) {
846+
if (ei->addr >= start &&
847+
(ei->addr + ei->size) <= (start + size)) {
847848
ei->type = new_type;
848849
real_updated_size += ei->size;
849850
continue;

0 commit comments

Comments
 (0)