aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-10-22 10:50:39 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 11:01:20 -0500
commitb209749f528488c4c0d20a42c0fbcbf49e6933b3 (patch)
tree0e0a24225a5c6bca1c1986cc0daaf8753424cfe6 /arch/x86/kvm
parent565f1fbd9d2f766dcfed5db90b89ef80afe8b49a (diff)
KVM: local APIC TPR access reporting facility
Add a facility to report on accesses to the local apic tpr even if the local apic is emulated in the kernel. This is basically a hack that allows userspace to patch Windows which tends to bang on the tpr a lot. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/lapic.c21
-rw-r--r--arch/x86/kvm/x86.c25
2 files changed, 46 insertions, 0 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 4076331b01ee..50c3f3a8dd3d 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -551,6 +551,23 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
551 return tmcct; 551 return tmcct;
552} 552}
553 553
554static void __report_tpr_access(struct kvm_lapic *apic, bool write)
555{
556 struct kvm_vcpu *vcpu = apic->vcpu;
557 struct kvm_run *run = vcpu->run;
558
559 set_bit(KVM_REQ_REPORT_TPR_ACCESS, &vcpu->requests);
560 kvm_x86_ops->cache_regs(vcpu);
561 run->tpr_access.rip = vcpu->arch.rip;
562 run->tpr_access.is_write = write;
563}
564
565static inline void report_tpr_access(struct kvm_lapic *apic, bool write)
566{
567 if (apic->vcpu->arch.tpr_access_reporting)
568 __report_tpr_access(apic, write);
569}
570
554static u32 __apic_read(struct kvm_lapic *apic, unsigned int offset) 571static u32 __apic_read(struct kvm_lapic *apic, unsigned int offset)
555{ 572{
556 u32 val = 0; 573 u32 val = 0;
@@ -568,6 +585,9 @@ static u32 __apic_read(struct kvm_lapic *apic, unsigned int offset)
568 val = apic_get_tmcct(apic); 585 val = apic_get_tmcct(apic);
569 break; 586 break;
570 587
588 case APIC_TASKPRI:
589 report_tpr_access(apic, false);
590 /* fall thru */
571 default: 591 default:
572 apic_update_ppr(apic); 592 apic_update_ppr(apic);
573 val = apic_get_reg(apic, offset); 593 val = apic_get_reg(apic, offset);
@@ -677,6 +697,7 @@ static void apic_mmio_write(struct kvm_io_device *this,
677 break; 697 break;
678 698
679 case APIC_TASKPRI: 699 case APIC_TASKPRI:
700 report_tpr_access(apic, true);
680 apic_set_tpr(apic, val & 0xff); 701 apic_set_tpr(apic, val & 0xff);
681 break; 702 break;
682 703
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 513258c797ca..c2b80884447e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -684,6 +684,7 @@ int kvm_dev_ioctl_check_extension(long ext)
684 case KVM_CAP_USER_MEMORY: 684 case KVM_CAP_USER_MEMORY:
685 case KVM_CAP_SET_TSS_ADDR: 685 case KVM_CAP_SET_TSS_ADDR:
686 case KVM_CAP_EXT_CPUID: 686 case KVM_CAP_EXT_CPUID:
687 case KVM_CAP_VAPIC:
687 r = 1; 688 r = 1;
688 break; 689 break;
689 default: 690 default:
@@ -1055,6 +1056,15 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
1055 return 0; 1056 return 0;
1056} 1057}
1057 1058
1059static int vcpu_ioctl_tpr_access_reporting(struct kvm_vcpu *vcpu,
1060 struct kvm_tpr_access_ctl *tac)
1061{
1062 if (tac->flags)
1063 return -EINVAL;
1064 vcpu->arch.tpr_access_reporting = !!tac->enabled;
1065 return 0;
1066}
1067
1058long kvm_arch_vcpu_ioctl(struct file *filp, 1068long kvm_arch_vcpu_ioctl(struct file *filp,
1059 unsigned int ioctl, unsigned long arg) 1069 unsigned int ioctl, unsigned long arg)
1060{ 1070{
@@ -1148,6 +1158,21 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1148 case KVM_SET_MSRS: 1158 case KVM_SET_MSRS:
1149 r = msr_io(vcpu, argp, do_set_msr, 0); 1159 r = msr_io(vcpu, argp, do_set_msr, 0);
1150 break; 1160 break;
1161 case KVM_TPR_ACCESS_REPORTING: {
1162 struct kvm_tpr_access_ctl tac;
1163
1164 r = -EFAULT;
1165 if (copy_from_user(&tac, argp, sizeof tac))
1166 goto out;
1167 r = vcpu_ioctl_tpr_access_reporting(vcpu, &tac);
1168 if (r)
1169 goto out;
1170 r = -EFAULT;
1171 if (copy_to_user(argp, &tac, sizeof tac))
1172 goto out;
1173 r = 0;
1174 break;
1175 };
1151 default: 1176 default:
1152 r = -EINVAL; 1177 r = -EINVAL;
1153 } 1178 }