History

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm fixes from Paolo Bonzini: - Fixes for s390 interrupt delivery - Fixes for Xen emulator bugs showing up as debug kernel WARNs - Fix another issue with SEV/ES string I/O VMGEXITs * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86: Take srcu lock in post_kvm_run_save() KVM: SEV-ES: fix another issue with string I/O VMGEXITs KVM: x86/xen: Fix kvm_xen_has_interrupt() sleeping in kvm_vcpu_block() KVM: x86: switch pvclock_gtod_sync_lock to a raw spinlock KVM: s390: preserve deliverable_mask in __airqs_kick_single_vcpu KVM: s390: clear kicked_mask before sleeping again

Linus Torvalds committed 5 years ago

Commit ca5e83e2 parents 180eca5 f3d14366 files · +61 −25Browse files

Unified · Split

6 files
  1. arch/s390/kvm/interrupt.c +3 −2
  2. arch/s390/kvm/kvm-s390.c +1 −0
  3. arch/x86/include/asm/kvm_host.h +1 −1
  4. arch/x86/kvm/svm/sev.c +12 −3
  5. arch/x86/kvm/x86.c +22 −14
  6. arch/x86/kvm/xen.c +22 −5
arch/s390/kvm/interrupt.c+3−2
@@ -3053,13 +3053,14 @@ static void __airqs_kick_single_vcpu(struct kvm *kvm, u8 deliverable_mask) · 3052 unmodified lines
3053 int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus);3053 int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus);
3054 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;3054 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
3055 struct kvm_vcpu *vcpu;3055 struct kvm_vcpu *vcpu;
3056 u8 vcpu_isc_mask;
3056 3057
3057 for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) {3058 for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) {
3058 vcpu = kvm_get_vcpu(kvm, vcpu_idx);3059 vcpu = kvm_get_vcpu(kvm, vcpu_idx);
3059 if (psw_ioint_disabled(vcpu))3060 if (psw_ioint_disabled(vcpu))
3060 continue;3061 continue;
3061 deliverable_mask &= (u8)(vcpu->arch.sie_block->gcr[6] >> 24);3062 vcpu_isc_mask = (u8)(vcpu->arch.sie_block->gcr[6] >> 24);
3062 if (deliverable_mask) {3063 if (deliverable_mask & vcpu_isc_mask) {
3063 /* lately kicked but not yet running */3064 /* lately kicked but not yet running */
3064 if (test_and_set_bit(vcpu_idx, gi->kicked_mask))3065 if (test_and_set_bit(vcpu_idx, gi->kicked_mask))
3065 return;3066 return;
arch/s390/kvm/kvm-s390.c+1−0
@@ -3363,6 +3363,7 @@ out_free_sie_block: · 3362 unmodified lines
3363 3363
3364int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)3364int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
3365{3365{
3366 clear_bit(vcpu->vcpu_idx, vcpu->kvm->arch.gisa_int.kicked_mask);
3366 return kvm_s390_vcpu_has_irq(vcpu, 0);3367 return kvm_s390_vcpu_has_irq(vcpu, 0);
3367}3368}
3368 3369
arch/x86/include/asm/kvm_host.h+1−1
@@ -1098,7 +1098,7 @@ struct kvm_arch { · 1097 unmodified lines
1098 u64 cur_tsc_generation;1098 u64 cur_tsc_generation;
1099 int nr_vcpus_matched_tsc;1099 int nr_vcpus_matched_tsc;
1100 1100
1101 spinlock_t pvclock_gtod_sync_lock;1101 raw_spinlock_t pvclock_gtod_sync_lock;
1102 bool use_master_clock;1102 bool use_master_clock;
1103 u64 master_kernel_ns;1103 u64 master_kernel_ns;
1104 u64 master_cycle_now;1104 u64 master_cycle_now;
arch/x86/kvm/svm/sev.c+12−3
@@ -2591,11 +2591,20 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) · 2590 unmodified lines
2591 2591
2592int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)2592int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)
2593{2593{
2594 if (!setup_vmgexit_scratch(svm, in, svm->vmcb->control.exit_info_2))2594 int count;
2595 int bytes;
2596
2597 if (svm->vmcb->control.exit_info_2 > INT_MAX)
2598 return -EINVAL;
2599
2600 count = svm->vmcb->control.exit_info_2;
2601 if (unlikely(check_mul_overflow(count, size, &bytes)))
2602 return -EINVAL;
2603
2604 if (!setup_vmgexit_scratch(svm, in, bytes))
2595 return -EINVAL;2605 return -EINVAL;
2596 2606
2597 return kvm_sev_es_string_io(&svm->vcpu, size, port,2607 return kvm_sev_es_string_io(&svm->vcpu, size, port, svm->ghcb_sa, count, in);
2598 svm->ghcb_sa, svm->ghcb_sa_len / size, in);
2599}2608}
2600 2609
2601void sev_es_init_vmcb(struct vcpu_svm *svm)2610void sev_es_init_vmcb(struct vcpu_svm *svm)
arch/x86/kvm/x86.c+22−14
@@ -2542,7 +2542,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) · 2541 unmodified lines
2542 kvm_vcpu_write_tsc_offset(vcpu, offset);2542 kvm_vcpu_write_tsc_offset(vcpu, offset);
2543 raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);2543 raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);
2544 2544
2545 spin_lock_irqsave(&kvm->arch.pvclock_gtod_sync_lock, flags);2545 raw_spin_lock_irqsave(&kvm->arch.pvclock_gtod_sync_lock, flags);
2546 if (!matched) {2546 if (!matched) {
2547 kvm->arch.nr_vcpus_matched_tsc = 0;2547 kvm->arch.nr_vcpus_matched_tsc = 0;
2548 } else if (!already_matched) {2548 } else if (!already_matched) {
@@ -2550,7 +2550,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) · 1 unmodified line
2550 }2550 }
2551 2551
2552 kvm_track_tsc_matching(vcpu);2552 kvm_track_tsc_matching(vcpu);
2553 spin_unlock_irqrestore(&kvm->arch.pvclock_gtod_sync_lock, flags);2553 raw_spin_unlock_irqrestore(&kvm->arch.pvclock_gtod_sync_lock, flags);
2554}2554}
2555 2555
2556static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu,2556static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu,
@@ -2780,9 +2780,9 @@ static void kvm_gen_update_masterclock(struct kvm *kvm) · 223 unmodified lines
2780 kvm_make_mclock_inprogress_request(kvm);2780 kvm_make_mclock_inprogress_request(kvm);
2781 2781
2782 /* no guest entries from this point */2782 /* no guest entries from this point */
2783 spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);2783 raw_spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);
2784 pvclock_update_vm_gtod_copy(kvm);2784 pvclock_update_vm_gtod_copy(kvm);
2785 spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);2785 raw_spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);
2786 2786
2787 kvm_for_each_vcpu(i, vcpu, kvm)2787 kvm_for_each_vcpu(i, vcpu, kvm)
2788 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);2788 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
@@ -2800,15 +2800,15 @@ u64 get_kvmclock_ns(struct kvm *kvm) · 11 unmodified lines
2800 unsigned long flags;2800 unsigned long flags;
2801 u64 ret;2801 u64 ret;
2802 2802
2803 spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);2803 raw_spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);
2804 if (!ka->use_master_clock) {2804 if (!ka->use_master_clock) {
2805 spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);2805 raw_spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);
2806 return get_kvmclock_base_ns() + ka->kvmclock_offset;2806 return get_kvmclock_base_ns() + ka->kvmclock_offset;
2807 }2807 }
2808 2808
2809 hv_clock.tsc_timestamp = ka->master_cycle_now;2809 hv_clock.tsc_timestamp = ka->master_cycle_now;
2810 hv_clock.system_time = ka->master_kernel_ns + ka->kvmclock_offset;2810 hv_clock.system_time = ka->master_kernel_ns + ka->kvmclock_offset;
2811 spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);2811 raw_spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);
2812 2812
2813 /* both __this_cpu_read() and rdtsc() should be on the same cpu */2813 /* both __this_cpu_read() and rdtsc() should be on the same cpu */
2814 get_cpu();2814 get_cpu();
@@ -2902,13 +2902,13 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) · 87 unmodified lines
2902 * If the host uses TSC clock, then passthrough TSC as stable2902 * If the host uses TSC clock, then passthrough TSC as stable
2903 * to the guest.2903 * to the guest.
2904 */2904 */
2905 spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);2905 raw_spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);
2906 use_master_clock = ka->use_master_clock;2906 use_master_clock = ka->use_master_clock;
2907 if (use_master_clock) {2907 if (use_master_clock) {
2908 host_tsc = ka->master_cycle_now;2908 host_tsc = ka->master_cycle_now;
2909 kernel_ns = ka->master_kernel_ns;2909 kernel_ns = ka->master_kernel_ns;
2910 }2910 }
2911 spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);2911 raw_spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);
2912 2912
2913 /* Keep irq disabled to prevent changes to the clock */2913 /* Keep irq disabled to prevent changes to the clock */
2914 local_irq_save(flags);2914 local_irq_save(flags);
@@ -6100,13 +6100,13 @@ set_pit2_out: · 3185 unmodified lines
6100 * is slightly ahead) here we risk going negative on unsigned6100 * is slightly ahead) here we risk going negative on unsigned
6101 * 'system_time' when 'user_ns.clock' is very small.6101 * 'system_time' when 'user_ns.clock' is very small.
6102 */6102 */
6103 spin_lock_irq(&ka->pvclock_gtod_sync_lock);6103 raw_spin_lock_irq(&ka->pvclock_gtod_sync_lock);
6104 if (kvm->arch.use_master_clock)6104 if (kvm->arch.use_master_clock)
6105 now_ns = ka->master_kernel_ns;6105 now_ns = ka->master_kernel_ns;
6106 else6106 else
6107 now_ns = get_kvmclock_base_ns();6107 now_ns = get_kvmclock_base_ns();
6108 ka->kvmclock_offset = user_ns.clock - now_ns;6108 ka->kvmclock_offset = user_ns.clock - now_ns;
6109 spin_unlock_irq(&ka->pvclock_gtod_sync_lock);6109 raw_spin_unlock_irq(&ka->pvclock_gtod_sync_lock);
6110 6110
6111 kvm_make_all_cpus_request(kvm, KVM_REQ_CLOCK_UPDATE);6111 kvm_make_all_cpus_request(kvm, KVM_REQ_CLOCK_UPDATE);
6112 break;6112 break;
@@ -8156,9 +8156,9 @@ static void kvm_hyperv_tsc_notifier(void) · 2043 unmodified lines
8156 list_for_each_entry(kvm, &vm_list, vm_list) {8156 list_for_each_entry(kvm, &vm_list, vm_list) {
8157 struct kvm_arch *ka = &kvm->arch;8157 struct kvm_arch *ka = &kvm->arch;
8158 8158
8159 spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);8159 raw_spin_lock_irqsave(&ka->pvclock_gtod_sync_lock, flags);
8160 pvclock_update_vm_gtod_copy(kvm);8160 pvclock_update_vm_gtod_copy(kvm);
8161 spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);8161 raw_spin_unlock_irqrestore(&ka->pvclock_gtod_sync_lock, flags);
8162 8162
8163 kvm_for_each_vcpu(cpu, vcpu, kvm)8163 kvm_for_each_vcpu(cpu, vcpu, kvm)
8164 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);8164 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
@@ -8800,9 +8800,17 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu) · 635 unmodified lines
8800 8800
8801 kvm_run->cr8 = kvm_get_cr8(vcpu);8801 kvm_run->cr8 = kvm_get_cr8(vcpu);
8802 kvm_run->apic_base = kvm_get_apic_base(vcpu);8802 kvm_run->apic_base = kvm_get_apic_base(vcpu);
8803
8804 /*
8805 * The call to kvm_ready_for_interrupt_injection() may end up in
8806 * kvm_xen_has_interrupt() which may require the srcu lock to be
8807 * held, to protect against changes in the vcpu_info address.
8808 */
8809 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
8803 kvm_run->ready_for_interrupt_injection =8810 kvm_run->ready_for_interrupt_injection =
8804 pic_in_kernel(vcpu->kvm) ||8811 pic_in_kernel(vcpu->kvm) ||
8805 kvm_vcpu_ready_for_interrupt_injection(vcpu);8812 kvm_vcpu_ready_for_interrupt_injection(vcpu);
8813 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
8806 8814
8807 if (is_smm(vcpu))8815 if (is_smm(vcpu))
8808 kvm_run->flags |= KVM_RUN_X86_SMM;8816 kvm_run->flags |= KVM_RUN_X86_SMM;
@@ -11199,7 +11207,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · 2390 unmodified lines
11199 11207
11200 raw_spin_lock_init(&kvm->arch.tsc_write_lock);11208 raw_spin_lock_init(&kvm->arch.tsc_write_lock);
11201 mutex_init(&kvm->arch.apic_map_lock);11209 mutex_init(&kvm->arch.apic_map_lock);
11202 spin_lock_init(&kvm->arch.pvclock_gtod_sync_lock);11210 raw_spin_lock_init(&kvm->arch.pvclock_gtod_sync_lock);
11203 11211
11204 kvm->arch.kvmclock_offset = -get_kvmclock_base_ns();11212 kvm->arch.kvmclock_offset = -get_kvmclock_base_ns();
11205 pvclock_update_vm_gtod_copy(kvm);11213 pvclock_update_vm_gtod_copy(kvm);
arch/x86/kvm/xen.c+22−5
@@ -190,6 +190,7 @@ void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, int state) · 189 unmodified lines
190 190
191int __kvm_xen_has_interrupt(struct kvm_vcpu *v)191int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
192{192{
193 int err;
193 u8 rc = 0;194 u8 rc = 0;
194 195
195 /*196 /*
@@ -216,13 +217,29 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v) · 20 unmodified lines
216 if (likely(slots->generation == ghc->generation &&217 if (likely(slots->generation == ghc->generation &&
217 !kvm_is_error_hva(ghc->hva) && ghc->memslot)) {218 !kvm_is_error_hva(ghc->hva) && ghc->memslot)) {
218 /* Fast path */219 /* Fast path */
219 __get_user(rc, (u8 __user *)ghc->hva + offset);220 pagefault_disable();
220 } else {221 err = __get_user(rc, (u8 __user *)ghc->hva + offset);
221 /* Slow path */222 pagefault_enable();
222 kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,223 if (!err)
223 sizeof(rc));224 return rc;
224 }225 }
225 226
227 /* Slow path */
228
229 /*
230 * This function gets called from kvm_vcpu_block() after setting the
231 * task to TASK_INTERRUPTIBLE, to see if it needs to wake immediately
232 * from a HLT. So we really mustn't sleep. If the page ended up absent
233 * at that point, just return 1 in order to trigger an immediate wake,
234 * and we'll end up getting called again from a context where we *can*
235 * fault in the page and wait for it.
236 */
237 if (in_atomic() || !task_is_running(current))
238 return 1;
239
240 kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,
241 sizeof(rc));
242
226 return rc;243 return rc;
227}244}
228 245