From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LP6QL-0008LF-FF for qemu-devel@nongnu.org; Mon, 19 Jan 2009 21:33:05 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LP6QK-0008Kj-Vw for qemu-devel@nongnu.org; Mon, 19 Jan 2009 21:33:05 -0500 Received: from [199.232.76.173] (port=36793 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LP6QK-0008Ke-MN for qemu-devel@nongnu.org; Mon, 19 Jan 2009 21:33:04 -0500 Received: from mx2.redhat.com ([66.187.237.31]:39312) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LP6QK-0001PT-1K for qemu-devel@nongnu.org; Mon, 19 Jan 2009 21:33:04 -0500 Message-Id: <20090120023057.803304190@amt.cnet> Date: Tue, 20 Jan 2009 00:30:45 -0200 From: Marcelo Tosatti References: <20090120023040.623163208@amt.cnet> Content-Disposition: inline; filename=0006_mtrr_above_4g.patch Subject: [Qemu-devel] [patch 5/9] kvm: bios: extend MTRRs to above 4G Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, bochs-developers@lists.sourceforge.net Cc: Anthony Liguori , Avi Kivity , Alex Williamson When I try to boot guests using a recent Linux kernel (2.6.26+), memory above 3.5G gets thrown away with an error like this: WARNING: BIOS bug: CPU MTRRs don't cover all of memory, losing 4608MB of RAM This extends MTRRs to cover all of memory. Signed-off-by: Alex Williamson Signed-off-by: Avi Kivity From: Alex Williamson Index: bochs/bios/rombios32.c =================================================================== --- bochs.orig/bios/rombios32.c +++ bochs/bios/rombios32.c @@ -427,6 +427,7 @@ uint32_t cpuid_signature; uint32_t cpuid_features; uint32_t cpuid_ext_features; unsigned long ram_size; +uint64_t above4g_ram_size; uint8_t bios_uuid[16]; #ifdef BX_USE_EBDA_TABLES unsigned long ebda_cur_addr; @@ -561,6 +562,14 @@ void setup_mtrr(void) wrmsr_smp(MTRRphysMask_MSR(i), (~vmask & 0xfffffff000ull) | 0x800); vbase += vmask + 1; } + for (vbase = 1ull << 32; i < vcnt && vbase < above4g_ram_size; ++i) { + vmask = (1ull << 40) - 1; + while (vbase + vmask + 1 > above4g_ram_size) + vmask >>= 1; + wrmsr_smp(MTRRphysBase_MSR(i), vbase | 6); + wrmsr_smp(MTRRphysMask_MSR(i), (~vmask & 0xfffffff000ull) | 0x800); + vbase += vmask + 1; + } wrmsr_smp(MSR_MTRRdefType, 0xc00); } @@ -572,11 +581,19 @@ void ram_probe(void) else ram_size = (cmos_readb(0x30) | (cmos_readb(0x31) << 8)) * 1024 + 1 * 1024 * 1024; + if (cmos_readb(0x5b) | cmos_readb(0x5c) | cmos_readb(0x5d)) + above4g_ram_size = ((uint64_t)cmos_readb(0x5b) << 16) | + ((uint64_t)cmos_readb(0x5c) << 24) | ((uint64_t)cmos_readb(0x5d) << 32); + + if (above4g_ram_size) + above4g_ram_size += 1ull << 32; + BX_INFO("ram_size=0x%08lx\n", ram_size); #ifdef BX_USE_EBDA_TABLES ebda_cur_addr = ((*(uint16_t *)(0x40e)) << 4) + 0x380; BX_INFO("ebda_cur_addr: 0x%08lx\n", ebda_cur_addr); #endif + BX_INFO("top of ram %ldMB\n", above4g_ram_size >> 20); setup_mtrr(); }