* [Qemu-devel] [PATCH] MTRR support on x86, part 1 @ 2008-12-04 22:43 Carl-Daniel Hailfinger 2008-12-11 20:59 ` Anthony Liguori 0 siblings, 1 reply; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2008-12-04 22:43 UTC (permalink / raw) To: qemu-devel The current codebase ignores MTRR (Memory Type Range Register) configuration writes and reads because Qemu does not implement caching. All BIOS/firmware in know of for x86 do implement a mode called Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU cache like RAM before RAM is enabled. Qemu assumes RAM is accessible from the start, but it would be nice to be able to run real BIOS/firmware in Qemu. For that, we need CAR support and for CAR support we have to support MTRRs. This patch is a first step in that direction. MTRRs are MSRs supported by all recent x86 CPUs, even old i586. Besides influencing cache, the MTRRs can be written and read back, so discarding MTRR writes violates the expectations of existing code out there. Handle common x86 MTRR reads and writes, but don't act on them. One open question remains: Is CPUX86State initialized with zeros or do I have to zero the MTRR settings stored there explicitly? Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Index: target-i386/cpu.h =================================================================== --- target-i386/cpu.h (revision 5879) +++ target-i386/cpu.h (working copy) @@ -261,8 +261,25 @@ #define MSR_IA32_PERF_STATUS 0x198 +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) + +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix16K_A0000 0x259 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_MTRRfix4K_C8000 0x269 +#define MSR_MTRRfix4K_D0000 0x26a +#define MSR_MTRRfix4K_D8000 0x26b +#define MSR_MTRRfix4K_E0000 0x26c +#define MSR_MTRRfix4K_E8000 0x26d +#define MSR_MTRRfix4K_F0000 0x26e +#define MSR_MTRRfix4K_F8000 0x26f + #define MSR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff + #define MSR_EFER 0xc0000080 #define MSR_EFER_SCE (1 << 0) @@ -629,6 +646,14 @@ uint32_t cpuid_ext3_features; uint32_t cpuid_apic_id; + /* MTRRs */ + uint64_t mtrr_fixed[11]; + uint64_t mtrr_deftype; + struct { + uint64_t base; + uint64_t mask; + } mtrr_var[8]; + #ifdef USE_KQEMU int kqemu_enabled; int last_io_time; Index: target-i386/op_helper.c =================================================================== --- target-i386/op_helper.c (revision 5879) +++ target-i386/op_helper.c (working copy) @@ -3073,6 +3073,46 @@ env->kernelgsbase = val; break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base = val; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask = val; + break; + case MSR_MTRRfix64K_00000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix64K_00000] = val; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1] = val; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3] = val; + break; + case MSR_MTRRdefType: + env->mtrr_deftype = val; + break; default: /* XXX: exception ? */ break; @@ -3145,6 +3185,46 @@ } break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask; + break; + case MSR_MTRRfix64K_00000: + val = env->mtrr_fixed[0]; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1]; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3]; + break; + case MSR_MTRRdefType: + val = env->mtrr_deftype; + break; default: /* XXX: exception ? */ val = 0; -- http://www.hailfinger.org/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86, part 1 2008-12-04 22:43 [Qemu-devel] [PATCH] MTRR support on x86, part 1 Carl-Daniel Hailfinger @ 2008-12-11 20:59 ` Anthony Liguori 2008-12-11 21:14 ` Carl-Daniel Hailfinger 2008-12-11 22:10 ` Carl-Daniel Hailfinger 0 siblings, 2 replies; 8+ messages in thread From: Anthony Liguori @ 2008-12-11 20:59 UTC (permalink / raw) To: qemu-devel Carl-Daniel Hailfinger wrote: > The current codebase ignores MTRR (Memory Type Range Register) > configuration writes and reads because Qemu does not implement caching. > All BIOS/firmware in know of for x86 do implement a mode called > Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU > cache like RAM before RAM is enabled. Qemu assumes RAM is accessible > from the start, but it would be nice to be able to run real > BIOS/firmware in Qemu. For that, we need CAR support and for CAR support > we have to support MTRRs. > > This patch is a first step in that direction. MTRRs are MSRs supported > by all recent x86 CPUs, even old i586. Besides influencing cache, the > MTRRs can be written and read back, so discarding MTRR writes violates > the expectations of existing code out there. > Handle common x86 MTRR reads and writes, but don't act on them. > > One open question remains: Is CPUX86State initialized with zeros or do I > have to zero the MTRR settings stored there explicitly? > > Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> > > Index: target-i386/cpu.h > =================================================================== > --- target-i386/cpu.h (revision 5879) > +++ target-i386/cpu.h (working copy) > @@ -261,8 +261,25 @@ > > #define MSR_IA32_PERF_STATUS 0x198 > > +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) > +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) > + > +#define MSR_MTRRfix64K_00000 0x250 > +#define MSR_MTRRfix16K_80000 0x258 > +#define MSR_MTRRfix16K_A0000 0x259 > +#define MSR_MTRRfix4K_C0000 0x268 > +#define MSR_MTRRfix4K_C8000 0x269 > +#define MSR_MTRRfix4K_D0000 0x26a > +#define MSR_MTRRfix4K_D8000 0x26b > +#define MSR_MTRRfix4K_E0000 0x26c > +#define MSR_MTRRfix4K_E8000 0x26d > +#define MSR_MTRRfix4K_F0000 0x26e > +#define MSR_MTRRfix4K_F8000 0x26f > I'm not a huge fan of the naming convention here. > #define MSR_PAT 0x277 > > +#define MSR_MTRRdefType 0x2ff > + > #define MSR_EFER 0xc0000080 > > #define MSR_EFER_SCE (1 << 0) > @@ -629,6 +646,14 @@ > uint32_t cpuid_ext3_features; > uint32_t cpuid_apic_id; > > + /* MTRRs */ > + uint64_t mtrr_fixed[11]; > + uint64_t mtrr_deftype; > + struct { > + uint64_t base; > + uint64_t mask; > + } mtrr_var[8]; > These have to be saved/restored or else you'll potentially break live migration/savevm/loadvm. Regards, Anthony Liguori ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86, part 1 2008-12-11 20:59 ` Anthony Liguori @ 2008-12-11 21:14 ` Carl-Daniel Hailfinger 2008-12-11 22:10 ` Carl-Daniel Hailfinger 1 sibling, 0 replies; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2008-12-11 21:14 UTC (permalink / raw) To: qemu-devel On 11.12.2008 21:59, Anthony Liguori wrote: > Carl-Daniel Hailfinger wrote: >> The current codebase ignores MTRR (Memory Type Range Register) >> configuration writes and reads because Qemu does not implement caching. >> All BIOS/firmware in know of for x86 do implement a mode called >> Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU >> cache like RAM before RAM is enabled. Qemu assumes RAM is accessible >> from the start, but it would be nice to be able to run real >> BIOS/firmware in Qemu. For that, we need CAR support and for CAR support >> we have to support MTRRs. >> >> This patch is a first step in that direction. MTRRs are MSRs supported >> by all recent x86 CPUs, even old i586. Besides influencing cache, the >> MTRRs can be written and read back, so discarding MTRR writes violates >> the expectations of existing code out there. >> Handle common x86 MTRR reads and writes, but don't act on them. >> >> One open question remains: Is CPUX86State initialized with zeros or do I >> have to zero the MTRR settings stored there explicitly? >> >> Signed-off-by: Carl-Daniel Hailfinger >> <c-d.hailfinger.devel.2006@gmx.net> >> >> Index: target-i386/cpu.h >> =================================================================== >> --- target-i386/cpu.h (revision 5879) >> +++ target-i386/cpu.h (working copy) >> @@ -261,8 +261,25 @@ >> >> #define MSR_IA32_PERF_STATUS 0x198 >> >> +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) >> +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) >> + >> +#define MSR_MTRRfix64K_00000 0x250 >> +#define MSR_MTRRfix16K_80000 0x258 >> +#define MSR_MTRRfix16K_A0000 0x259 >> +#define MSR_MTRRfix4K_C0000 0x268 >> +#define MSR_MTRRfix4K_C8000 0x269 >> +#define MSR_MTRRfix4K_D0000 0x26a >> +#define MSR_MTRRfix4K_D8000 0x26b >> +#define MSR_MTRRfix4K_E0000 0x26c >> +#define MSR_MTRRfix4K_E8000 0x26d >> +#define MSR_MTRRfix4K_F0000 0x26e >> +#define MSR_MTRRfix4K_F8000 0x26f >> > > I'm not a huge fan of the naming convention here. Except the MSR_ prefix, this is the name the MTRRs have in the AMD data sheets. I'm open to alternatives, though. If you have a suggestion, I'll implement it. >> #define MSR_PAT 0x277 >> >> +#define MSR_MTRRdefType 0x2ff >> + >> #define MSR_EFER 0xc0000080 >> >> #define MSR_EFER_SCE (1 << 0) >> @@ -629,6 +646,14 @@ >> uint32_t cpuid_ext3_features; >> uint32_t cpuid_apic_id; >> >> + /* MTRRs */ >> + uint64_t mtrr_fixed[11]; >> + uint64_t mtrr_deftype; >> + struct { >> + uint64_t base; >> + uint64_t mask; >> + } mtrr_var[8]; >> > > These have to be saved/restored or else you'll potentially break live > migration/savevm/loadvm. Thanks, I was unaware of that. I'll read up on savevm/loadvm and post a new patch. Thanks for the review! Regards, Carl-Daniel -- http://www.hailfinger.org/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86, part 1 2008-12-11 20:59 ` Anthony Liguori 2008-12-11 21:14 ` Carl-Daniel Hailfinger @ 2008-12-11 22:10 ` Carl-Daniel Hailfinger 2008-12-11 22:37 ` Carl-Daniel Hailfinger 1 sibling, 1 reply; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2008-12-11 22:10 UTC (permalink / raw) To: qemu-devel On 11.12.2008 21:59, Anthony Liguori wrote: > Carl-Daniel Hailfinger wrote: >> The current codebase ignores MTRR (Memory Type Range Register) >> configuration writes and reads because Qemu does not implement caching. >> All BIOS/firmware in know of for x86 do implement a mode called >> Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU >> cache like RAM before RAM is enabled. Qemu assumes RAM is accessible >> from the start, but it would be nice to be able to run real >> BIOS/firmware in Qemu. For that, we need CAR support and for CAR support >> we have to support MTRRs. >> >> This patch is a first step in that direction. MTRRs are MSRs supported >> by all recent x86 CPUs, even old i586. Besides influencing cache, the >> MTRRs can be written and read back, so discarding MTRR writes violates >> the expectations of existing code out there. >> Handle common x86 MTRR reads and writes, but don't act on them. >> >> Signed-off-by: Carl-Daniel Hailfinger >> <c-d.hailfinger.devel.2006@gmx.net> >> >> Index: target-i386/cpu.h >> =================================================================== >> --- target-i386/cpu.h (revision 5879) >> +++ target-i386/cpu.h (working copy) >> @@ -261,8 +261,25 @@ >> >> #define MSR_IA32_PERF_STATUS 0x198 >> >> +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) >> +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) >> + >> +#define MSR_MTRRfix64K_00000 0x250 >> +#define MSR_MTRRfix16K_80000 0x258 >> +#define MSR_MTRRfix16K_A0000 0x259 >> +#define MSR_MTRRfix4K_C0000 0x268 >> +#define MSR_MTRRfix4K_C8000 0x269 >> +#define MSR_MTRRfix4K_D0000 0x26a >> +#define MSR_MTRRfix4K_D8000 0x26b >> +#define MSR_MTRRfix4K_E0000 0x26c >> +#define MSR_MTRRfix4K_E8000 0x26d >> +#define MSR_MTRRfix4K_F0000 0x26e >> +#define MSR_MTRRfix4K_F8000 0x26f >> > > I'm not a huge fan of the naming convention here. The offer to use another naming scheme still stands. If you have any suggestion, I'll act upon it. >> #define MSR_PAT 0x277 >> >> +#define MSR_MTRRdefType 0x2ff >> + >> #define MSR_EFER 0xc0000080 >> >> #define MSR_EFER_SCE (1 << 0) >> @@ -629,6 +646,14 @@ >> uint32_t cpuid_ext3_features; >> uint32_t cpuid_apic_id; >> >> + /* MTRRs */ >> + uint64_t mtrr_fixed[11]; >> + uint64_t mtrr_deftype; >> + struct { >> + uint64_t base; >> + uint64_t mask; >> + } mtrr_var[8]; >> > > These have to be saved/restored or else you'll potentially break live > migration/savevm/loadvm. I added save/restore support. Thanks a lot for giving me the hints I needed to implement this. Regards, Carl-Daniel The current codebase ignores MTRR (Memory Type Range Register) configuration writes and reads because Qemu does not implement caching. All BIOS/firmware in know of for x86 do implement a mode called Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU cache like RAM before RAM is enabled. Qemu assumes RAM is accessible from the start, but it would be nice to be able to run real BIOS/firmware in Qemu. For that, we need CAR support and for CAR support we have to support MTRRs. This patch is a first step in that direction. MTRRs are MSRs supported by all recent x86 CPUs, even old i586. Besides influencing cache, the MTRRs can be written and read back, so discarding MTRR writes violates the expectations of existing code out there. Handle common x86 MTRR reads and writes, but don't act on them. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Index: target-i386/machine.c =================================================================== --- target-i386/machine.c (revision 5987) +++ target-i386/machine.c (working copy) @@ -134,6 +134,15 @@ qemu_put_be16s(f, &env->intercept_dr_write); qemu_put_be32s(f, &env->intercept_exceptions); qemu_put_8s(f, &env->v_tpr); + + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_put_be64s(f, &env->mtrr_fixed[i]); + qemu_put_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_put_be64s(f, &env->mtrr_var[i].base); + qemu_put_be64s(f, &env->mtrr_var[i].mask); + } } #ifdef USE_X86LDOUBLE @@ -169,7 +178,7 @@ int32_t a20_mask; if (version_id != 3 && version_id != 4 && version_id != 5 - && version_id != 6 && version_id != 7) + && version_id != 6 && version_id != 7 && version_id != 8) return -EINVAL; for(i = 0; i < CPU_NB_REGS; i++) qemu_get_betls(f, &env->regs[i]); @@ -302,6 +311,18 @@ qemu_get_be32s(f, &env->intercept_exceptions); qemu_get_8s(f, &env->v_tpr); } + + if (version_id >= 8) { + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_put_be64s(f, &env->mtrr_fixed[i]); + qemu_put_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_put_be64s(f, &env->mtrr_var[i].base); + qemu_put_be64s(f, &env->mtrr_var[i].mask); + } + } + /* XXX: ensure compatiblity for halted bit ? */ /* XXX: compute redundant hflags bits */ env->hflags = hflags; Index: target-i386/cpu.h =================================================================== --- target-i386/cpu.h (revision 5987) +++ target-i386/cpu.h (working copy) @@ -261,8 +261,25 @@ #define MSR_IA32_PERF_STATUS 0x198 +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) + +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix16K_A0000 0x259 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_MTRRfix4K_C8000 0x269 +#define MSR_MTRRfix4K_D0000 0x26a +#define MSR_MTRRfix4K_D8000 0x26b +#define MSR_MTRRfix4K_E0000 0x26c +#define MSR_MTRRfix4K_E8000 0x26d +#define MSR_MTRRfix4K_F0000 0x26e +#define MSR_MTRRfix4K_F8000 0x26f + #define MSR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff + #define MSR_EFER 0xc0000080 #define MSR_EFER_SCE (1 << 0) @@ -629,6 +646,14 @@ uint32_t cpuid_ext3_features; uint32_t cpuid_apic_id; + /* MTRRs */ + uint64_t mtrr_fixed[11]; + uint64_t mtrr_deftype; + struct { + uint64_t base; + uint64_t mask; + } mtrr_var[8]; + #ifdef USE_KQEMU int kqemu_enabled; int last_io_time; @@ -776,7 +801,7 @@ #define cpu_signal_handler cpu_x86_signal_handler #define cpu_list x86_cpu_list -#define CPU_SAVE_VERSION 7 +#define CPU_SAVE_VERSION 8 /* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel Index: target-i386/op_helper.c =================================================================== --- target-i386/op_helper.c (revision 5987) +++ target-i386/op_helper.c (working copy) @@ -3069,6 +3069,46 @@ env->kernelgsbase = val; break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base = val; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask = val; + break; + case MSR_MTRRfix64K_00000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix64K_00000] = val; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1] = val; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3] = val; + break; + case MSR_MTRRdefType: + env->mtrr_deftype = val; + break; default: /* XXX: exception ? */ break; @@ -3141,6 +3181,46 @@ } break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask; + break; + case MSR_MTRRfix64K_00000: + val = env->mtrr_fixed[0]; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1]; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3]; + break; + case MSR_MTRRdefType: + val = env->mtrr_deftype; + break; default: /* XXX: exception ? */ val = 0; ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86, part 1 2008-12-11 22:10 ` Carl-Daniel Hailfinger @ 2008-12-11 22:37 ` Carl-Daniel Hailfinger 2009-01-21 17:00 ` [Qemu-devel] [PATCH] MTRR support on x86 [resend] Carl-Daniel Hailfinger 0 siblings, 1 reply; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2008-12-11 22:37 UTC (permalink / raw) To: qemu-devel On 11.12.2008 23:10, Carl-Daniel Hailfinger wrote: > On 11.12.2008 21:59, Anthony Liguori wrote: > >> Carl-Daniel Hailfinger wrote: >> >>> The current codebase ignores MTRR (Memory Type Range Register) >>> configuration writes and reads because Qemu does not implement caching. >>> All BIOS/firmware in know of for x86 do implement a mode called >>> Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU >>> cache like RAM before RAM is enabled. Qemu assumes RAM is accessible >>> from the start, but it would be nice to be able to run real >>> BIOS/firmware in Qemu. For that, we need CAR support and for CAR support >>> we have to support MTRRs. >>> >>> This patch is a first step in that direction. MTRRs are MSRs supported >>> by all recent x86 CPUs, even old i586. Besides influencing cache, the >>> MTRRs can be written and read back, so discarding MTRR writes violates >>> the expectations of existing code out there. >>> Handle common x86 MTRR reads and writes, but don't act on them. >>> >>> Signed-off-by: Carl-Daniel Hailfinger >>> <c-d.hailfinger.devel.2006@gmx.net> >>> >>> Index: target-i386/cpu.h >>> =================================================================== >>> --- target-i386/cpu.h (revision 5879) >>> +++ target-i386/cpu.h (working copy) >>> @@ -261,8 +261,25 @@ >>> >>> #define MSR_IA32_PERF_STATUS 0x198 >>> >>> +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) >>> +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) >>> + >>> +#define MSR_MTRRfix64K_00000 0x250 >>> +#define MSR_MTRRfix16K_80000 0x258 >>> +#define MSR_MTRRfix16K_A0000 0x259 >>> +#define MSR_MTRRfix4K_C0000 0x268 >>> +#define MSR_MTRRfix4K_C8000 0x269 >>> +#define MSR_MTRRfix4K_D0000 0x26a >>> +#define MSR_MTRRfix4K_D8000 0x26b >>> +#define MSR_MTRRfix4K_E0000 0x26c >>> +#define MSR_MTRRfix4K_E8000 0x26d >>> +#define MSR_MTRRfix4K_F0000 0x26e >>> +#define MSR_MTRRfix4K_F8000 0x26f >>> >>> >> I'm not a huge fan of the naming convention here. >> > > The offer to use another naming scheme still stands. If you have any > suggestion, I'll act upon it. > > > >>> #define MSR_PAT 0x277 >>> >>> +#define MSR_MTRRdefType 0x2ff >>> + >>> #define MSR_EFER 0xc0000080 >>> >>> #define MSR_EFER_SCE (1 << 0) >>> @@ -629,6 +646,14 @@ >>> uint32_t cpuid_ext3_features; >>> uint32_t cpuid_apic_id; >>> >>> + /* MTRRs */ >>> + uint64_t mtrr_fixed[11]; >>> + uint64_t mtrr_deftype; >>> + struct { >>> + uint64_t base; >>> + uint64_t mask; >>> + } mtrr_var[8]; >>> >>> >> These have to be saved/restored or else you'll potentially break live >> migration/savevm/loadvm. >> > > I added save/restore support. > Thanks a lot for giving me the hints I needed to implement this. > Sorry, I submitted a previous buggy version. New version follows. The current codebase ignores MTRR (Memory Type Range Register) configuration writes and reads because Qemu does not implement caching. All BIOS/firmware in know of for x86 do implement a mode called Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU cache like RAM before RAM is enabled. Qemu assumes RAM is accessible from the start, but it would be nice to be able to run real BIOS/firmware in Qemu. For that, we need CAR support and for CAR support we have to support MTRRs. This patch is a first step in that direction. MTRRs are MSRs supported by all recent x86 CPUs, even old i586. Besides influencing cache, the MTRRs can be written and read back, so discarding MTRR writes violates the expectations of existing code out there. Handle common x86 MTRR reads and writes, but don't act on them. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Index: target-i386/machine.c =================================================================== --- target-i386/machine.c (revision 5987) +++ target-i386/machine.c (working copy) @@ -134,6 +134,15 @@ qemu_put_be16s(f, &env->intercept_dr_write); qemu_put_be32s(f, &env->intercept_exceptions); qemu_put_8s(f, &env->v_tpr); + + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_put_be64s(f, &env->mtrr_fixed[i]); + qemu_put_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_put_be64s(f, &env->mtrr_var[i].base); + qemu_put_be64s(f, &env->mtrr_var[i].mask); + } } #ifdef USE_X86LDOUBLE @@ -169,7 +178,7 @@ int32_t a20_mask; if (version_id != 3 && version_id != 4 && version_id != 5 - && version_id != 6 && version_id != 7) + && version_id != 6 && version_id != 7 && version_id != 8) return -EINVAL; for(i = 0; i < CPU_NB_REGS; i++) qemu_get_betls(f, &env->regs[i]); @@ -302,6 +311,18 @@ qemu_get_be32s(f, &env->intercept_exceptions); qemu_get_8s(f, &env->v_tpr); } + + if (version_id >= 8) { + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_get_be64s(f, &env->mtrr_fixed[i]); + qemu_get_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_get_be64s(f, &env->mtrr_var[i].base); + qemu_get_be64s(f, &env->mtrr_var[i].mask); + } + } + /* XXX: ensure compatiblity for halted bit ? */ /* XXX: compute redundant hflags bits */ env->hflags = hflags; Index: target-i386/cpu.h =================================================================== --- target-i386/cpu.h (revision 5987) +++ target-i386/cpu.h (working copy) @@ -261,8 +261,25 @@ #define MSR_IA32_PERF_STATUS 0x198 +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) + +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix16K_A0000 0x259 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_MTRRfix4K_C8000 0x269 +#define MSR_MTRRfix4K_D0000 0x26a +#define MSR_MTRRfix4K_D8000 0x26b +#define MSR_MTRRfix4K_E0000 0x26c +#define MSR_MTRRfix4K_E8000 0x26d +#define MSR_MTRRfix4K_F0000 0x26e +#define MSR_MTRRfix4K_F8000 0x26f + #define MSR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff + #define MSR_EFER 0xc0000080 #define MSR_EFER_SCE (1 << 0) @@ -629,6 +646,14 @@ uint32_t cpuid_ext3_features; uint32_t cpuid_apic_id; + /* MTRRs */ + uint64_t mtrr_fixed[11]; + uint64_t mtrr_deftype; + struct { + uint64_t base; + uint64_t mask; + } mtrr_var[8]; + #ifdef USE_KQEMU int kqemu_enabled; int last_io_time; @@ -776,7 +801,7 @@ #define cpu_signal_handler cpu_x86_signal_handler #define cpu_list x86_cpu_list -#define CPU_SAVE_VERSION 7 +#define CPU_SAVE_VERSION 8 /* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel Index: target-i386/op_helper.c =================================================================== --- target-i386/op_helper.c (revision 5987) +++ target-i386/op_helper.c (working copy) @@ -3069,6 +3069,46 @@ env->kernelgsbase = val; break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base = val; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask = val; + break; + case MSR_MTRRfix64K_00000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix64K_00000] = val; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1] = val; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3] = val; + break; + case MSR_MTRRdefType: + env->mtrr_deftype = val; + break; default: /* XXX: exception ? */ break; @@ -3141,6 +3181,46 @@ } break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask; + break; + case MSR_MTRRfix64K_00000: + val = env->mtrr_fixed[0]; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1]; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3]; + break; + case MSR_MTRRdefType: + val = env->mtrr_deftype; + break; default: /* XXX: exception ? */ val = 0; ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH] MTRR support on x86 [resend] 2008-12-11 22:37 ` Carl-Daniel Hailfinger @ 2009-01-21 17:00 ` Carl-Daniel Hailfinger 2009-01-22 3:03 ` Carl-Daniel Hailfinger 2009-01-26 17:53 ` Anthony Liguori 0 siblings, 2 replies; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2009-01-21 17:00 UTC (permalink / raw) To: qemu-devel; +Cc: Marcelo Tosatti The current codebase ignores MTRR (Memory Type Range Register) configuration writes and reads because Qemu does not implement caching. All BIOS/firmware in know of for x86 do implement a mode called Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU cache like RAM before RAM is enabled. Qemu assumes RAM is accessible from the start, but it would be nice to be able to run real BIOS/firmware in Qemu. For that, we need CAR support and for CAR support we have to support MTRRs. This patch is a first step in that direction. MTRRs are MSRs supported by all recent x86 CPUs, even old i586. Besides influencing cache, the MTRRs can be written and read back, so discarding MTRR writes violates the expectations of existing code out there. An added benefit of this patch is that it fixes the following Linux kernel error message present in recent kernels (provided the BIOS has the recent MTRR patches applied): ------------[ cut here ]------------ WARNING: at arch/x86/kernel/cpu/mtrr/main.c:1500 mtrr_trim_uncached_memory+0x382/0x384() WARNING: strange, CPU MTRRs all blank? Modules linked in: Supported: Yes Pid: 0, comm: swapper Not tainted 2.6.27.7-9-default #1 [<c0106570>] dump_trace+0x6b/0x249 [<c01070a5>] show_trace+0x20/0x39 [<c0343c02>] dump_stack+0x71/0x76 [<c012acb2>] warn_slowpath+0x6f/0x90 [<c0542f8f>] mtrr_trim_uncached_memory+0x382/0x384 [<c053f24d>] setup_arch+0x40d/0x639 [<c053a6ac>] start_kernel+0x6b/0x31f ======================= ---[ end trace 4eaa2a86a8e2da22 ]--- Handle common x86 MTRR reads and writes, but don't act on them. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Index: target-i386/machine.c =================================================================== --- target-i386/machine.c (revision 6374) +++ target-i386/machine.c (working copy) @@ -134,6 +134,15 @@ qemu_put_be16s(f, &env->intercept_dr_write); qemu_put_be32s(f, &env->intercept_exceptions); qemu_put_8s(f, &env->v_tpr); + + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_put_be64s(f, &env->mtrr_fixed[i]); + qemu_put_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_put_be64s(f, &env->mtrr_var[i].base); + qemu_put_be64s(f, &env->mtrr_var[i].mask); + } } #ifdef USE_X86LDOUBLE @@ -169,7 +178,7 @@ int32_t a20_mask; if (version_id != 3 && version_id != 4 && version_id != 5 - && version_id != 6 && version_id != 7) + && version_id != 6 && version_id != 7 && version_id != 8) return -EINVAL; for(i = 0; i < CPU_NB_REGS; i++) qemu_get_betls(f, &env->regs[i]); @@ -302,6 +311,18 @@ qemu_get_be32s(f, &env->intercept_exceptions); qemu_get_8s(f, &env->v_tpr); } + + if (version_id >= 8) { + /* MTRRs */ + for(i = 0; i < 11; i++) + qemu_get_be64s(f, &env->mtrr_fixed[i]); + qemu_get_be64s(f, &env->mtrr_deftype); + for(i = 0; i < 8; i++) { + qemu_get_be64s(f, &env->mtrr_var[i].base); + qemu_get_be64s(f, &env->mtrr_var[i].mask); + } + } + /* XXX: ensure compatiblity for halted bit ? */ /* XXX: compute redundant hflags bits */ env->hflags = hflags; Index: target-i386/cpu.h =================================================================== --- target-i386/cpu.h (revision 6374) +++ target-i386/cpu.h (working copy) @@ -261,8 +261,25 @@ #define MSR_IA32_PERF_STATUS 0x198 +#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) +#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) + +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix16K_A0000 0x259 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_MTRRfix4K_C8000 0x269 +#define MSR_MTRRfix4K_D0000 0x26a +#define MSR_MTRRfix4K_D8000 0x26b +#define MSR_MTRRfix4K_E0000 0x26c +#define MSR_MTRRfix4K_E8000 0x26d +#define MSR_MTRRfix4K_F0000 0x26e +#define MSR_MTRRfix4K_F8000 0x26f + #define MSR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff + #define MSR_EFER 0xc0000080 #define MSR_EFER_SCE (1 << 0) @@ -629,6 +646,14 @@ uint32_t cpuid_ext3_features; uint32_t cpuid_apic_id; + /* MTRRs */ + uint64_t mtrr_fixed[11]; + uint64_t mtrr_deftype; + struct { + uint64_t base; + uint64_t mask; + } mtrr_var[8]; + #ifdef USE_KQEMU int kqemu_enabled; int last_io_time; @@ -805,7 +830,7 @@ #define cpu_signal_handler cpu_x86_signal_handler #define cpu_list x86_cpu_list -#define CPU_SAVE_VERSION 7 +#define CPU_SAVE_VERSION 8 /* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel Index: target-i386/op_helper.c =================================================================== --- target-i386/op_helper.c (revision 6374) +++ target-i386/op_helper.c (working copy) @@ -3050,6 +3050,46 @@ env->kernelgsbase = val; break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base = val; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask = val; + break; + case MSR_MTRRfix64K_00000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix64K_00000] = val; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1] = val; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3] = val; + break; + case MSR_MTRRdefType: + env->mtrr_deftype = val; + break; default: /* XXX: exception ? */ break; @@ -3122,6 +3162,46 @@ } break; #endif + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask; + break; + case MSR_MTRRfix64K_00000: + val = env->mtrr_fixed[0]; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1]; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3]; + break; + case MSR_MTRRdefType: + val = env->mtrr_deftype; + break; default: /* XXX: exception ? */ val = 0; -- http://www.hailfinger.org/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86 [resend] 2009-01-21 17:00 ` [Qemu-devel] [PATCH] MTRR support on x86 [resend] Carl-Daniel Hailfinger @ 2009-01-22 3:03 ` Carl-Daniel Hailfinger 2009-01-26 17:53 ` Anthony Liguori 1 sibling, 0 replies; 8+ messages in thread From: Carl-Daniel Hailfinger @ 2009-01-22 3:03 UTC (permalink / raw) To: qemu-devel; +Cc: Marcelo Tosatti On 21.01.2009 18:00, Carl-Daniel Hailfinger wrote: > The current codebase ignores MTRR (Memory Type Range Register) > configuration writes and reads because Qemu does not implement caching. > All BIOS/firmware in know of for x86 do implement a mode called > Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU > cache like RAM before RAM is enabled. Qemu assumes RAM is accessible > from the start, but it would be nice to be able to run real > BIOS/firmware in Qemu. For that, we need CAR support and for CAR support > we have to support MTRRs. > > This patch is a first step in that direction. MTRRs are MSRs supported > by all recent x86 CPUs, even old i586. Besides influencing cache, the > MTRRs can be written and read back, so discarding MTRR writes violates > the expectations of existing code out there. > > An added benefit of this patch is that it fixes the following Linux > kernel error message present in recent kernels (provided the BIOS has > the recent MTRR patches applied): > ------------[ cut here ]------------ > WARNING: at arch/x86/kernel/cpu/mtrr/main.c:1500 mtrr_trim_uncached_memory+0x382/0x384() > WARNING: strange, CPU MTRRs all blank? > Modules linked in: > Supported: Yes > Pid: 0, comm: swapper Not tainted 2.6.27.7-9-default #1 > [<c0106570>] dump_trace+0x6b/0x249 > [<c01070a5>] show_trace+0x20/0x39 > [<c0343c02>] dump_stack+0x71/0x76 > [<c012acb2>] warn_slowpath+0x6f/0x90 > [<c0542f8f>] mtrr_trim_uncached_memory+0x382/0x384 > [<c053f24d>] setup_arch+0x40d/0x639 > [<c053a6ac>] start_kernel+0x6b/0x31f > ======================= > ---[ end trace 4eaa2a86a8e2da22 ]--- > > Handle common x86 MTRR reads and writes, but don't act on them. > > Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> > Just a short heads-up: Since one of the BIOS MTRR support patches is a bit incomplete, this patch is not enough to silence that Linux warning. I'll post a new patch with improved compatibility tomorrow. Regards, Carl-Daniel -- http://www.hailfinger.org/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] MTRR support on x86 [resend] 2009-01-21 17:00 ` [Qemu-devel] [PATCH] MTRR support on x86 [resend] Carl-Daniel Hailfinger 2009-01-22 3:03 ` Carl-Daniel Hailfinger @ 2009-01-26 17:53 ` Anthony Liguori 1 sibling, 0 replies; 8+ messages in thread From: Anthony Liguori @ 2009-01-26 17:53 UTC (permalink / raw) To: qemu-devel; +Cc: Marcelo Tosatti Carl-Daniel Hailfinger wrote: > The current codebase ignores MTRR (Memory Type Range Register) > configuration writes and reads because Qemu does not implement caching. > All BIOS/firmware in know of for x86 do implement a mode called > Cache-as-RAM (CAR) which locks down the CPU cache lines and uses the CPU > cache like RAM before RAM is enabled. Qemu assumes RAM is accessible > from the start, but it would be nice to be able to run real > BIOS/firmware in Qemu. For that, we need CAR support and for CAR support > we have to support MTRRs. > > This patch is a first step in that direction. MTRRs are MSRs supported > by all recent x86 CPUs, even old i586. Besides influencing cache, the > MTRRs can be written and read back, so discarding MTRR writes violates > the expectations of existing code out there. > > An added benefit of this patch is that it fixes the following Linux > kernel error message present in recent kernels (provided the BIOS has > the recent MTRR patches applied): > ------------[ cut here ]------------ > WARNING: at arch/x86/kernel/cpu/mtrr/main.c:1500 mtrr_trim_uncached_memory+0x382/0x384() > WARNING: strange, CPU MTRRs all blank? > Modules linked in: > Supported: Yes > Pid: 0, comm: swapper Not tainted 2.6.27.7-9-default #1 > [<c0106570>] dump_trace+0x6b/0x249 > [<c01070a5>] show_trace+0x20/0x39 > [<c0343c02>] dump_stack+0x71/0x76 > [<c012acb2>] warn_slowpath+0x6f/0x90 > [<c0542f8f>] mtrr_trim_uncached_memory+0x382/0x384 > [<c053f24d>] setup_arch+0x40d/0x639 > [<c053a6ac>] start_kernel+0x6b/0x31f > ======================= > ---[ end trace 4eaa2a86a8e2da22 ]--- > > Handle common x86 MTRR reads and writes, but don't act on them. > > Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> > Applied. Thanks. Regards, Anthony Liguori > > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-01-26 17:53 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-12-04 22:43 [Qemu-devel] [PATCH] MTRR support on x86, part 1 Carl-Daniel Hailfinger 2008-12-11 20:59 ` Anthony Liguori 2008-12-11 21:14 ` Carl-Daniel Hailfinger 2008-12-11 22:10 ` Carl-Daniel Hailfinger 2008-12-11 22:37 ` Carl-Daniel Hailfinger 2009-01-21 17:00 ` [Qemu-devel] [PATCH] MTRR support on x86 [resend] Carl-Daniel Hailfinger 2009-01-22 3:03 ` Carl-Daniel Hailfinger 2009-01-26 17:53 ` Anthony Liguori
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).