aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorSheng Yang <sheng@linux.intel.com>2008-10-09 04:01:54 -0400
committerAvi Kivity <avi@redhat.com>2008-12-31 09:51:44 -0500
commit0bed3b568b68e5835ef5da888a372b9beabf7544 (patch)
treeec8d816662d845831055a411496c97523bdd5de1 /arch/x86/kvm/x86.c
parent932d27a7913fc6b3c64c6e6082628b0a1561dec9 (diff)
KVM: Improve MTRR structure
As well as reset mmu context when set MTRR. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a2c4b5594555..f5b2334c6bda 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -39,6 +39,7 @@
39#include <asm/uaccess.h> 39#include <asm/uaccess.h>
40#include <asm/msr.h> 40#include <asm/msr.h>
41#include <asm/desc.h> 41#include <asm/desc.h>
42#include <asm/mtrr.h>
42 43
43#define MAX_IO_MSRS 256 44#define MAX_IO_MSRS 256
44#define CR0_RESERVED_BITS \ 45#define CR0_RESERVED_BITS \
@@ -650,10 +651,38 @@ static bool msr_mtrr_valid(unsigned msr)
650 651
651static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data) 652static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
652{ 653{
654 u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
655
653 if (!msr_mtrr_valid(msr)) 656 if (!msr_mtrr_valid(msr))
654 return 1; 657 return 1;
655 658
656 vcpu->arch.mtrr[msr - 0x200] = data; 659 if (msr == MSR_MTRRdefType) {
660 vcpu->arch.mtrr_state.def_type = data;
661 vcpu->arch.mtrr_state.enabled = (data & 0xc00) >> 10;
662 } else if (msr == MSR_MTRRfix64K_00000)
663 p[0] = data;
664 else if (msr == MSR_MTRRfix16K_80000 || msr == MSR_MTRRfix16K_A0000)
665 p[1 + msr - MSR_MTRRfix16K_80000] = data;
666 else if (msr >= MSR_MTRRfix4K_C0000 && msr <= MSR_MTRRfix4K_F8000)
667 p[3 + msr - MSR_MTRRfix4K_C0000] = data;
668 else if (msr == MSR_IA32_CR_PAT)
669 vcpu->arch.pat = data;
670 else { /* Variable MTRRs */
671 int idx, is_mtrr_mask;
672 u64 *pt;
673
674 idx = (msr - 0x200) / 2;
675 is_mtrr_mask = msr - 0x200 - 2 * idx;
676 if (!is_mtrr_mask)
677 pt =
678 (u64 *)&vcpu->arch.mtrr_state.var_ranges[idx].base_lo;
679 else
680 pt =
681 (u64 *)&vcpu->arch.mtrr_state.var_ranges[idx].mask_lo;
682 *pt = data;
683 }
684
685 kvm_mmu_reset_context(vcpu);
657 return 0; 686 return 0;
658} 687}
659 688
@@ -749,10 +778,37 @@ int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
749 778
750static int get_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) 779static int get_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
751{ 780{
781 u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
782
752 if (!msr_mtrr_valid(msr)) 783 if (!msr_mtrr_valid(msr))
753 return 1; 784 return 1;
754 785
755 *pdata = vcpu->arch.mtrr[msr - 0x200]; 786 if (msr == MSR_MTRRdefType)
787 *pdata = vcpu->arch.mtrr_state.def_type +
788 (vcpu->arch.mtrr_state.enabled << 10);
789 else if (msr == MSR_MTRRfix64K_00000)
790 *pdata = p[0];
791 else if (msr == MSR_MTRRfix16K_80000 || msr == MSR_MTRRfix16K_A0000)
792 *pdata = p[1 + msr - MSR_MTRRfix16K_80000];
793 else if (msr >= MSR_MTRRfix4K_C0000 && msr <= MSR_MTRRfix4K_F8000)
794 *pdata = p[3 + msr - MSR_MTRRfix4K_C0000];
795 else if (msr == MSR_IA32_CR_PAT)
796 *pdata = vcpu->arch.pat;
797 else { /* Variable MTRRs */
798 int idx, is_mtrr_mask;
799 u64 *pt;
800
801 idx = (msr - 0x200) / 2;
802 is_mtrr_mask = msr - 0x200 - 2 * idx;
803 if (!is_mtrr_mask)
804 pt =
805 (u64 *)&vcpu->arch.mtrr_state.var_ranges[idx].base_lo;
806 else
807 pt =
808 (u64 *)&vcpu->arch.mtrr_state.var_ranges[idx].mask_lo;
809 *pdata = *pt;
810 }
811
756 return 0; 812 return 0;
757} 813}
758 814
@@ -3942,6 +3998,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
3942 /* We do fxsave: this must be aligned. */ 3998 /* We do fxsave: this must be aligned. */
3943 BUG_ON((unsigned long)&vcpu->arch.host_fx_image & 0xF); 3999 BUG_ON((unsigned long)&vcpu->arch.host_fx_image & 0xF);
3944 4000
4001 vcpu->arch.mtrr_state.have_fixed = 1;
3945 vcpu_load(vcpu); 4002 vcpu_load(vcpu);
3946 r = kvm_arch_vcpu_reset(vcpu); 4003 r = kvm_arch_vcpu_reset(vcpu);
3947 if (r == 0) 4004 if (r == 0)