x86.c (13ea3300100ec3461560b1e061033cd167333a86) | x86.c (9ed96e87c5748de4c2807ef17e81287c7304186c) |
---|---|
1/* 2 * Kernel-based Virtual Machine driver for Linux 3 * 4 * derived from drivers/kvm/kvm_main.c 5 * 6 * Copyright (C) 2006 Qumranet, Inc. 7 * Copyright (C) 2008 Qumranet, Inc. 8 * Copyright IBM Corporation, 2008 --- 80 unchanged lines hidden (view full) --- 89static void process_nmi(struct kvm_vcpu *vcpu); 90 91struct kvm_x86_ops *kvm_x86_ops; 92EXPORT_SYMBOL_GPL(kvm_x86_ops); 93 94static bool ignore_msrs = 0; 95module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR); 96 | 1/* 2 * Kernel-based Virtual Machine driver for Linux 3 * 4 * derived from drivers/kvm/kvm_main.c 5 * 6 * Copyright (C) 2006 Qumranet, Inc. 7 * Copyright (C) 2008 Qumranet, Inc. 8 * Copyright IBM Corporation, 2008 --- 80 unchanged lines hidden (view full) --- 89static void process_nmi(struct kvm_vcpu *vcpu); 90 91struct kvm_x86_ops *kvm_x86_ops; 92EXPORT_SYMBOL_GPL(kvm_x86_ops); 93 94static bool ignore_msrs = 0; 95module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR); 96 |
97unsigned int min_timer_period_us = 500; 98module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR); 99 |
|
97bool kvm_has_tsc_control; 98EXPORT_SYMBOL_GPL(kvm_has_tsc_control); 99u32 kvm_max_guest_tsc_khz; 100EXPORT_SYMBOL_GPL(kvm_max_guest_tsc_khz); 101 102/* tsc tolerance in parts per million - default to 1/2 of the NTP threshold */ 103static u32 tsc_tolerance_ppm = 250; 104module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR); --- 3104 unchanged lines hidden (view full) --- 3209 struct kvm_vapic_addr va; 3210 3211 r = -EINVAL; 3212 if (!irqchip_in_kernel(vcpu->kvm)) 3213 goto out; 3214 r = -EFAULT; 3215 if (copy_from_user(&va, argp, sizeof va)) 3216 goto out; | 100bool kvm_has_tsc_control; 101EXPORT_SYMBOL_GPL(kvm_has_tsc_control); 102u32 kvm_max_guest_tsc_khz; 103EXPORT_SYMBOL_GPL(kvm_max_guest_tsc_khz); 104 105/* tsc tolerance in parts per million - default to 1/2 of the NTP threshold */ 106static u32 tsc_tolerance_ppm = 250; 107module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR); --- 3104 unchanged lines hidden (view full) --- 3212 struct kvm_vapic_addr va; 3213 3214 r = -EINVAL; 3215 if (!irqchip_in_kernel(vcpu->kvm)) 3216 goto out; 3217 r = -EFAULT; 3218 if (copy_from_user(&va, argp, sizeof va)) 3219 goto out; |
3217 r = kvm_lapic_set_vapic_addr(vcpu, va.vapic_addr); | 3220 r = 0; 3221 kvm_lapic_set_vapic_addr(vcpu, va.vapic_addr); |
3218 break; 3219 } 3220 case KVM_X86_SETUP_MCE: { 3221 u64 mcg_cap; 3222 3223 r = -EFAULT; 3224 if (copy_from_user(&mcg_cap, argp, sizeof mcg_cap)) 3225 goto out; --- 2507 unchanged lines hidden (view full) --- 5733 kvm_run->ready_for_interrupt_injection = 1; 5734 else 5735 kvm_run->ready_for_interrupt_injection = 5736 kvm_arch_interrupt_allowed(vcpu) && 5737 !kvm_cpu_has_interrupt(vcpu) && 5738 !kvm_event_needs_reinjection(vcpu); 5739} 5740 | 3222 break; 3223 } 3224 case KVM_X86_SETUP_MCE: { 3225 u64 mcg_cap; 3226 3227 r = -EFAULT; 3228 if (copy_from_user(&mcg_cap, argp, sizeof mcg_cap)) 3229 goto out; --- 2507 unchanged lines hidden (view full) --- 5737 kvm_run->ready_for_interrupt_injection = 1; 5738 else 5739 kvm_run->ready_for_interrupt_injection = 5740 kvm_arch_interrupt_allowed(vcpu) && 5741 !kvm_cpu_has_interrupt(vcpu) && 5742 !kvm_event_needs_reinjection(vcpu); 5743} 5744 |
5745static int vapic_enter(struct kvm_vcpu *vcpu) 5746{ 5747 struct kvm_lapic *apic = vcpu->arch.apic; 5748 struct page *page; 5749 5750 if (!apic || !apic->vapic_addr) 5751 return 0; 5752 5753 page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT); 5754 if (is_error_page(page)) 5755 return -EFAULT; 5756 5757 vcpu->arch.apic->vapic_page = page; 5758 return 0; 5759} 5760 5761static void vapic_exit(struct kvm_vcpu *vcpu) 5762{ 5763 struct kvm_lapic *apic = vcpu->arch.apic; 5764 int idx; 5765 5766 if (!apic || !apic->vapic_addr) 5767 return; 5768 5769 idx = srcu_read_lock(&vcpu->kvm->srcu); 5770 kvm_release_page_dirty(apic->vapic_page); 5771 mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT); 5772 srcu_read_unlock(&vcpu->kvm->srcu, idx); 5773} 5774 |
|
5741static void update_cr8_intercept(struct kvm_vcpu *vcpu) 5742{ 5743 int max_irr, tpr; 5744 5745 if (!kvm_x86_ops->update_cr8_intercept) 5746 return; 5747 5748 if (!vcpu->arch.apic) --- 80 unchanged lines hidden (view full) --- 5829 memset(eoi_exit_bitmap, 0, 32); 5830 memset(tmr, 0, 32); 5831 5832 kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr); 5833 kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); 5834 kvm_apic_update_tmr(vcpu, tmr); 5835} 5836 | 5775static void update_cr8_intercept(struct kvm_vcpu *vcpu) 5776{ 5777 int max_irr, tpr; 5778 5779 if (!kvm_x86_ops->update_cr8_intercept) 5780 return; 5781 5782 if (!vcpu->arch.apic) --- 80 unchanged lines hidden (view full) --- 5863 memset(eoi_exit_bitmap, 0, 32); 5864 memset(tmr, 0, 32); 5865 5866 kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr); 5867 kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); 5868 kvm_apic_update_tmr(vcpu, tmr); 5869} 5870 |
5871/* 5872 * Returns 1 to let __vcpu_run() continue the guest execution loop without 5873 * exiting to the userspace. Otherwise, the value will be returned to the 5874 * userspace. 5875 */ |
|
5837static int vcpu_enter_guest(struct kvm_vcpu *vcpu) 5838{ 5839 int r; 5840 bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && 5841 vcpu->run->request_interrupt_window; 5842 bool req_immediate_exit = false; 5843 5844 if (vcpu->requests) { --- 188 unchanged lines hidden (view full) --- 6033 6034 6035static int __vcpu_run(struct kvm_vcpu *vcpu) 6036{ 6037 int r; 6038 struct kvm *kvm = vcpu->kvm; 6039 6040 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); | 5876static int vcpu_enter_guest(struct kvm_vcpu *vcpu) 5877{ 5878 int r; 5879 bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && 5880 vcpu->run->request_interrupt_window; 5881 bool req_immediate_exit = false; 5882 5883 if (vcpu->requests) { --- 188 unchanged lines hidden (view full) --- 6072 6073 6074static int __vcpu_run(struct kvm_vcpu *vcpu) 6075{ 6076 int r; 6077 struct kvm *kvm = vcpu->kvm; 6078 6079 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); |
6080 r = vapic_enter(vcpu); 6081 if (r) { 6082 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); 6083 return r; 6084 } |
|
6041 6042 r = 1; 6043 while (r > 0) { 6044 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && 6045 !vcpu->arch.apf.halted) 6046 r = vcpu_enter_guest(vcpu); 6047 else { 6048 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); --- 35 unchanged lines hidden (view full) --- 6084 6085 if (signal_pending(current)) { 6086 r = -EINTR; 6087 vcpu->run->exit_reason = KVM_EXIT_INTR; 6088 ++vcpu->stat.signal_exits; 6089 } 6090 if (need_resched()) { 6091 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); | 6085 6086 r = 1; 6087 while (r > 0) { 6088 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && 6089 !vcpu->arch.apf.halted) 6090 r = vcpu_enter_guest(vcpu); 6091 else { 6092 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); --- 35 unchanged lines hidden (view full) --- 6128 6129 if (signal_pending(current)) { 6130 r = -EINTR; 6131 vcpu->run->exit_reason = KVM_EXIT_INTR; 6132 ++vcpu->stat.signal_exits; 6133 } 6134 if (need_resched()) { 6135 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); |
6092 kvm_resched(vcpu); | 6136 cond_resched(); |
6093 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); 6094 } 6095 } 6096 6097 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); 6098 | 6137 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); 6138 } 6139 } 6140 6141 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); 6142 |
6143 vapic_exit(vcpu); 6144 |
|
6099 return r; 6100} 6101 6102static inline int complete_emulated_io(struct kvm_vcpu *vcpu) 6103{ 6104 int r; 6105 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 6106 r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE); --- 1337 unchanged lines hidden --- | 6145 return r; 6146} 6147 6148static inline int complete_emulated_io(struct kvm_vcpu *vcpu) 6149{ 6150 int r; 6151 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 6152 r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE); --- 1337 unchanged lines hidden --- |