root / pc-bios / bios-pq / 0006_kvm-bios-extend-mtrrs-to-above-4g.patch @ 9a717b55
History | View | Annotate | Download (2 kB)
1 |
extend MTRRs to above 4G (Alex Williamson)
|
---|---|
2 |
|
3 |
When I try to boot guests using a recent Linux kernel (2.6.26+), memory
|
4 |
above 3.5G gets thrown away with an error like this:
|
5 |
|
6 |
WARNING: BIOS bug: CPU MTRRs don't cover all of memory, losing 4608MB of RAM
|
7 |
|
8 |
This extends MTRRs to cover all of memory.
|
9 |
|
10 |
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
|
11 |
Signed-off-by: Avi Kivity <avi@redhat.com>
|
12 |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
13 |
|
14 |
Index: bochs/bios/rombios32.c
|
15 |
===================================================================
|
16 |
--- bochs.orig/bios/rombios32.c
|
17 |
+++ bochs/bios/rombios32.c
|
18 |
@@ -427,6 +427,7 @@ uint32_t cpuid_signature;
|
19 |
uint32_t cpuid_features; |
20 |
uint32_t cpuid_ext_features; |
21 |
unsigned long ram_size; |
22 |
+uint64_t above4g_ram_size;
|
23 |
uint8_t bios_uuid[16];
|
24 |
#ifdef BX_USE_EBDA_TABLES
|
25 |
unsigned long ebda_cur_addr; |
26 |
@@ -561,6 +562,14 @@ void setup_mtrr(void) |
27 |
wrmsr_smp(MTRRphysMask_MSR(i), (~vmask & 0xfffffff000ull) | 0x800); |
28 |
vbase += vmask + 1;
|
29 |
} |
30 |
+ for (vbase = 1ull << 32; i < vcnt && vbase < above4g_ram_size; ++i) {
|
31 |
+ vmask = (1ull << 40) - 1;
|
32 |
+ while (vbase + vmask + 1 > above4g_ram_size)
|
33 |
+ vmask >>= 1;
|
34 |
+ wrmsr_smp(MTRRphysBase_MSR(i), vbase | 6);
|
35 |
+ wrmsr_smp(MTRRphysMask_MSR(i), (~vmask & 0xfffffff000ull) | 0x800);
|
36 |
+ vbase += vmask + 1;
|
37 |
+ }
|
38 |
wrmsr_smp(MSR_MTRRdefType, 0xc00);
|
39 |
} |
40 |
|
41 |
@@ -572,11 +581,19 @@ void ram_probe(void) |
42 |
else
|
43 |
ram_size = (cmos_readb(0x30) | (cmos_readb(0x31) << 8)) * 1024 + |
44 |
1 * 1024 * 1024; |
45 |
+ if (cmos_readb(0x5b) | cmos_readb(0x5c) | cmos_readb(0x5d))
|
46 |
+ above4g_ram_size = ((uint64_t)cmos_readb(0x5b) << 16) |
|
47 |
+ ((uint64_t)cmos_readb(0x5c) << 24) | ((uint64_t)cmos_readb(0x5d) << 32);
|
48 |
+
|
49 |
+ if (above4g_ram_size)
|
50 |
+ above4g_ram_size += 1ull << 32;
|
51 |
+
|
52 |
BX_INFO("ram_size=0x%08lx\n", ram_size);
|
53 |
#ifdef BX_USE_EBDA_TABLES
|
54 |
ebda_cur_addr = ((*(uint16_t *)(0x40e)) << 4) + 0x380; |
55 |
BX_INFO("ebda_cur_addr: 0x%08lx\n", ebda_cur_addr);
|
56 |
#endif
|
57 |
+ BX_INFO("top of ram %ldMB\n", above4g_ram_size >> 20);
|
58 |
setup_mtrr(); |
59 |
} |
60 |
|
61 |
|
62 |
|