aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2009-12-07 05:16:48 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2010-03-01 10:35:39 -0500
commitfc78f51938e1ea866daa2045851b2e5681371668 (patch)
treebf46fdc9daca6cab3b42d102ec12c133a62cb2ff /arch/x86/kvm/x86.c
parentcdc0e24456bf5678f63497569c3676c9019f82c1 (diff)
KVM: Add accessor for reading cr4 (or some bits of cr4)
Some bits of cr4 can be owned by the guest on vmx, so when we read them, we copy them to the vcpu structure. In preparation for making the set of guest-owned bits dynamic, use helpers to access these bits so we don't need to know where the bit resides. No changes to svm since all bits are host-owned there. Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 27931867791..84dd33e717f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -482,7 +482,7 @@ EXPORT_SYMBOL_GPL(kvm_lmsw);
482 482
483void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 483void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
484{ 484{
485 unsigned long old_cr4 = vcpu->arch.cr4; 485 unsigned long old_cr4 = kvm_read_cr4(vcpu);
486 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE; 486 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE;
487 487
488 if (cr4 & CR4_RESERVED_BITS) { 488 if (cr4 & CR4_RESERVED_BITS) {
@@ -1899,7 +1899,7 @@ static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu,
1899 return 0; 1899 return 0;
1900 if (mce->status & MCI_STATUS_UC) { 1900 if (mce->status & MCI_STATUS_UC) {
1901 if ((vcpu->arch.mcg_status & MCG_STATUS_MCIP) || 1901 if ((vcpu->arch.mcg_status & MCG_STATUS_MCIP) ||
1902 !(vcpu->arch.cr4 & X86_CR4_MCE)) { 1902 !kvm_read_cr4_bits(vcpu, X86_CR4_MCE)) {
1903 printk(KERN_DEBUG "kvm: set_mce: " 1903 printk(KERN_DEBUG "kvm: set_mce: "
1904 "injects mce exception while " 1904 "injects mce exception while "
1905 "previous one is in progress!\n"); 1905 "previous one is in progress!\n");
@@ -3616,7 +3616,6 @@ unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr)
3616{ 3616{
3617 unsigned long value; 3617 unsigned long value;
3618 3618
3619 kvm_x86_ops->decache_cr4_guest_bits(vcpu);
3620 switch (cr) { 3619 switch (cr) {
3621 case 0: 3620 case 0:
3622 value = vcpu->arch.cr0; 3621 value = vcpu->arch.cr0;
@@ -3628,7 +3627,7 @@ unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr)
3628 value = vcpu->arch.cr3; 3627 value = vcpu->arch.cr3;
3629 break; 3628 break;
3630 case 4: 3629 case 4:
3631 value = vcpu->arch.cr4; 3630 value = kvm_read_cr4(vcpu);
3632 break; 3631 break;
3633 case 8: 3632 case 8:
3634 value = kvm_get_cr8(vcpu); 3633 value = kvm_get_cr8(vcpu);
@@ -3656,7 +3655,7 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
3656 kvm_set_cr3(vcpu, val); 3655 kvm_set_cr3(vcpu, val);
3657 break; 3656 break;
3658 case 4: 3657 case 4:
3659 kvm_set_cr4(vcpu, mk_cr_64(vcpu->arch.cr4, val)); 3658 kvm_set_cr4(vcpu, mk_cr_64(kvm_read_cr4(vcpu), val));
3660 break; 3659 break;
3661 case 8: 3660 case 8:
3662 kvm_set_cr8(vcpu, val & 0xfUL); 3661 kvm_set_cr8(vcpu, val & 0xfUL);
@@ -4237,11 +4236,10 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
4237 sregs->gdt.limit = dt.limit; 4236 sregs->gdt.limit = dt.limit;
4238 sregs->gdt.base = dt.base; 4237 sregs->gdt.base = dt.base;
4239 4238
4240 kvm_x86_ops->decache_cr4_guest_bits(vcpu);
4241 sregs->cr0 = vcpu->arch.cr0; 4239 sregs->cr0 = vcpu->arch.cr0;
4242 sregs->cr2 = vcpu->arch.cr2; 4240 sregs->cr2 = vcpu->arch.cr2;
4243 sregs->cr3 = vcpu->arch.cr3; 4241 sregs->cr3 = vcpu->arch.cr3;
4244 sregs->cr4 = vcpu->arch.cr4; 4242 sregs->cr4 = kvm_read_cr4(vcpu);
4245 sregs->cr8 = kvm_get_cr8(vcpu); 4243 sregs->cr8 = kvm_get_cr8(vcpu);
4246 sregs->efer = vcpu->arch.shadow_efer; 4244 sregs->efer = vcpu->arch.shadow_efer;
4247 sregs->apic_base = kvm_get_apic_base(vcpu); 4245 sregs->apic_base = kvm_get_apic_base(vcpu);
@@ -4737,13 +4735,11 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
4737 kvm_x86_ops->set_efer(vcpu, sregs->efer); 4735 kvm_x86_ops->set_efer(vcpu, sregs->efer);
4738 kvm_set_apic_base(vcpu, sregs->apic_base); 4736 kvm_set_apic_base(vcpu, sregs->apic_base);
4739 4737
4740 kvm_x86_ops->decache_cr4_guest_bits(vcpu);
4741
4742 mmu_reset_needed |= vcpu->arch.cr0 != sregs->cr0; 4738 mmu_reset_needed |= vcpu->arch.cr0 != sregs->cr0;
4743 kvm_x86_ops->set_cr0(vcpu, sregs->cr0); 4739 kvm_x86_ops->set_cr0(vcpu, sregs->cr0);
4744 vcpu->arch.cr0 = sregs->cr0; 4740 vcpu->arch.cr0 = sregs->cr0;
4745 4741
4746 mmu_reset_needed |= vcpu->arch.cr4 != sregs->cr4; 4742 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;
4747 kvm_x86_ops->set_cr4(vcpu, sregs->cr4); 4743 kvm_x86_ops->set_cr4(vcpu, sregs->cr4);
4748 if (!is_long_mode(vcpu) && is_pae(vcpu)) { 4744 if (!is_long_mode(vcpu) && is_pae(vcpu)) {
4749 load_pdptrs(vcpu, vcpu->arch.cr3); 4745 load_pdptrs(vcpu, vcpu->arch.cr3);