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

Pull kvm fixes from Paolo Bonzini:

- ARM/ARM64 locking fixes

- x86 fixes: PCID, UMIP, locking

- improved support for recent Windows version that have a 2048 Hz APIC
timer

- rename KVM_HINTS_DEDICATED CPUID bit to KVM_HINTS_REALTIME

- better behaved selftests

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
kvm: rename KVM_HINTS_DEDICATED to KVM_HINTS_REALTIME
KVM: arm/arm64: VGIC/ITS save/restore: protect kvm_read_guest() calls
KVM: arm/arm64: VGIC/ITS: protect kvm_read_guest() calls with SRCU lock
KVM: arm/arm64: VGIC/ITS: Promote irq_lock() in update_affinity
KVM: arm/arm64: Properly protect VGIC locks from IRQs
KVM: X86: Lower the default timer frequency limit to 200us
KVM: vmx: update sec exec controls for UMIP iff emulating UMIP
kvm: x86: Suppress CR3_PCID_INVD bit only when PCIDs are enabled
KVM: selftests: exit with 0 status code when tests cannot be run
KVM: hyperv: idr_find needs RCU protection
x86: Delay skip of emulated hypercall instruction
KVM: Extend MAX_IRQ_ROUTES to 4096 for all archs

+157 -87
+3 -3
Documentation/virtual/kvm/cpuid.txt
··· 72 72 73 73 flag || value || meaning 74 74 ================================================================================== 75 - KVM_HINTS_DEDICATED || 0 || guest checks this feature bit to 76 - || || determine if there is vCPU pinning 77 - || || and there is no vCPU over-commitment, 75 + KVM_HINTS_REALTIME || 0 || guest checks this feature bit to 76 + || || determine that vCPUs are never 77 + || || preempted for an unlimited time, 78 78 || || allowing optimizations 79 79 ----------------------------------------------------------------------------------
+16
arch/arm/include/asm/kvm_mmu.h
··· 309 309 return 8; 310 310 } 311 311 312 + /* 313 + * We are not in the kvm->srcu critical section most of the time, so we take 314 + * the SRCU read lock here. Since we copy the data from the user page, we 315 + * can immediately drop the lock again. 316 + */ 317 + static inline int kvm_read_guest_lock(struct kvm *kvm, 318 + gpa_t gpa, void *data, unsigned long len) 319 + { 320 + int srcu_idx = srcu_read_lock(&kvm->srcu); 321 + int ret = kvm_read_guest(kvm, gpa, data, len); 322 + 323 + srcu_read_unlock(&kvm->srcu, srcu_idx); 324 + 325 + return ret; 326 + } 327 + 312 328 static inline void *kvm_get_hyp_vector(void) 313 329 { 314 330 return kvm_ksym_ref(__kvm_hyp_vector);
+16
arch/arm64/include/asm/kvm_mmu.h
··· 360 360 return (cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR1_VMIDBITS_SHIFT) == 2) ? 16 : 8; 361 361 } 362 362 363 + /* 364 + * We are not in the kvm->srcu critical section most of the time, so we take 365 + * the SRCU read lock here. Since we copy the data from the user page, we 366 + * can immediately drop the lock again. 367 + */ 368 + static inline int kvm_read_guest_lock(struct kvm *kvm, 369 + gpa_t gpa, void *data, unsigned long len) 370 + { 371 + int srcu_idx = srcu_read_lock(&kvm->srcu); 372 + int ret = kvm_read_guest(kvm, gpa, data, len); 373 + 374 + srcu_read_unlock(&kvm->srcu, srcu_idx); 375 + 376 + return ret; 377 + } 378 + 363 379 #ifdef CONFIG_KVM_INDIRECT_VECTORS 364 380 /* 365 381 * EL2 vectors can be mapped and rerouted in a number of ways,
+1 -1
arch/x86/include/uapi/asm/kvm_para.h
··· 29 29 #define KVM_FEATURE_PV_TLB_FLUSH 9 30 30 #define KVM_FEATURE_ASYNC_PF_VMEXIT 10 31 31 32 - #define KVM_HINTS_DEDICATED 0 32 + #define KVM_HINTS_REALTIME 0 33 33 34 34 /* The last 8 bits are used to indicate how to interpret the flags field 35 35 * in pvclock structure. If no bits are set, all flags are ignored.
+4 -4
arch/x86/kernel/kvm.c
··· 457 457 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus) 458 458 { 459 459 native_smp_prepare_cpus(max_cpus); 460 - if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) 460 + if (kvm_para_has_hint(KVM_HINTS_REALTIME)) 461 461 static_branch_disable(&virt_spin_lock_key); 462 462 } 463 463 ··· 553 553 } 554 554 555 555 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && 556 - !kvm_para_has_hint(KVM_HINTS_DEDICATED) && 556 + !kvm_para_has_hint(KVM_HINTS_REALTIME) && 557 557 kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) 558 558 pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others; 559 559 ··· 649 649 int cpu; 650 650 651 651 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && 652 - !kvm_para_has_hint(KVM_HINTS_DEDICATED) && 652 + !kvm_para_has_hint(KVM_HINTS_REALTIME) && 653 653 kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { 654 654 for_each_possible_cpu(cpu) { 655 655 zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu), ··· 745 745 if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) 746 746 return; 747 747 748 - if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) 748 + if (kvm_para_has_hint(KVM_HINTS_REALTIME)) 749 749 return; 750 750 751 751 __pv_init_lock_hash();
+4 -2
arch/x86/kvm/hyperv.c
··· 1265 1265 struct kvm_run *run = vcpu->run; 1266 1266 1267 1267 kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result); 1268 - return 1; 1268 + return kvm_skip_emulated_instruction(vcpu); 1269 1269 } 1270 1270 1271 1271 static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param) ··· 1296 1296 if (param & ~KVM_HYPERV_CONN_ID_MASK) 1297 1297 return HV_STATUS_INVALID_HYPERCALL_INPUT; 1298 1298 1299 - /* conn_to_evt is protected by vcpu->kvm->srcu */ 1299 + /* the eventfd is protected by vcpu->kvm->srcu, but conn_to_evt isn't */ 1300 + rcu_read_lock(); 1300 1301 eventfd = idr_find(&vcpu->kvm->arch.hyperv.conn_to_evt, param); 1302 + rcu_read_unlock(); 1301 1303 if (!eventfd) 1302 1304 return HV_STATUS_INVALID_PORT_ID; 1303 1305
+15 -13
arch/x86/kvm/vmx.c
··· 1494 1494 SECONDARY_EXEC_ENABLE_VMFUNC; 1495 1495 } 1496 1496 1497 + static bool vmx_umip_emulated(void) 1498 + { 1499 + return vmcs_config.cpu_based_2nd_exec_ctrl & 1500 + SECONDARY_EXEC_DESC; 1501 + } 1502 + 1497 1503 static inline bool report_flexpriority(void) 1498 1504 { 1499 1505 return flexpriority_enabled; ··· 4767 4761 else 4768 4762 hw_cr4 |= KVM_PMODE_VM_CR4_ALWAYS_ON; 4769 4763 4770 - if ((cr4 & X86_CR4_UMIP) && !boot_cpu_has(X86_FEATURE_UMIP)) { 4771 - vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL, 4772 - SECONDARY_EXEC_DESC); 4773 - hw_cr4 &= ~X86_CR4_UMIP; 4774 - } else if (!is_guest_mode(vcpu) || 4775 - !nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC)) 4776 - vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, 4764 + if (!boot_cpu_has(X86_FEATURE_UMIP) && vmx_umip_emulated()) { 4765 + if (cr4 & X86_CR4_UMIP) { 4766 + vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL, 4777 4767 SECONDARY_EXEC_DESC); 4768 + hw_cr4 &= ~X86_CR4_UMIP; 4769 + } else if (!is_guest_mode(vcpu) || 4770 + !nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC)) 4771 + vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, 4772 + SECONDARY_EXEC_DESC); 4773 + } 4778 4774 4779 4775 if (cr4 & X86_CR4_VMXE) { 4780 4776 /* ··· 9503 9495 { 9504 9496 return vmcs_config.cpu_based_2nd_exec_ctrl & 9505 9497 SECONDARY_EXEC_XSAVES; 9506 - } 9507 - 9508 - static bool vmx_umip_emulated(void) 9509 - { 9510 - return vmcs_config.cpu_based_2nd_exec_ctrl & 9511 - SECONDARY_EXEC_DESC; 9512 9498 } 9513 9499 9514 9500 static void vmx_recover_nmi_blocking(struct vcpu_vmx *vmx)
+16 -10
arch/x86/kvm/x86.c
··· 114 114 static bool __read_mostly report_ignored_msrs = true; 115 115 module_param(report_ignored_msrs, bool, S_IRUGO | S_IWUSR); 116 116 117 - unsigned int min_timer_period_us = 500; 117 + unsigned int min_timer_period_us = 200; 118 118 module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR); 119 119 120 120 static bool __read_mostly kvmclock_periodic_sync = true; ··· 843 843 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 844 844 { 845 845 #ifdef CONFIG_X86_64 846 - cr3 &= ~CR3_PCID_INVD; 846 + bool pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE); 847 + 848 + if (pcid_enabled) 849 + cr3 &= ~CR3_PCID_INVD; 847 850 #endif 848 851 849 852 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) { ··· 6674 6671 int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) 6675 6672 { 6676 6673 unsigned long nr, a0, a1, a2, a3, ret; 6677 - int op_64_bit, r; 6674 + int op_64_bit; 6678 6675 6679 - r = kvm_skip_emulated_instruction(vcpu); 6680 - 6681 - if (kvm_hv_hypercall_enabled(vcpu->kvm)) 6682 - return kvm_hv_hypercall(vcpu); 6676 + if (kvm_hv_hypercall_enabled(vcpu->kvm)) { 6677 + if (!kvm_hv_hypercall(vcpu)) 6678 + return 0; 6679 + goto out; 6680 + } 6683 6681 6684 6682 nr = kvm_register_read(vcpu, VCPU_REGS_RAX); 6685 6683 a0 = kvm_register_read(vcpu, VCPU_REGS_RBX); ··· 6701 6697 6702 6698 if (kvm_x86_ops->get_cpl(vcpu) != 0) { 6703 6699 ret = -KVM_EPERM; 6704 - goto out; 6700 + goto out_error; 6705 6701 } 6706 6702 6707 6703 switch (nr) { ··· 6721 6717 ret = -KVM_ENOSYS; 6722 6718 break; 6723 6719 } 6724 - out: 6720 + out_error: 6725 6721 if (!op_64_bit) 6726 6722 ret = (u32)ret; 6727 6723 kvm_register_write(vcpu, VCPU_REGS_RAX, ret); 6724 + 6725 + out: 6728 6726 ++vcpu->stat.hypercalls; 6729 - return r; 6727 + return kvm_skip_emulated_instruction(vcpu); 6730 6728 } 6731 6729 EXPORT_SYMBOL_GPL(kvm_emulate_hypercall); 6732 6730
+1 -7
include/linux/kvm_host.h
··· 1045 1045 1046 1046 #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 1047 1047 1048 - #ifdef CONFIG_S390 1049 - #define KVM_MAX_IRQ_ROUTES 4096 //FIXME: we can have more than that... 1050 - #elif defined(CONFIG_ARM64) 1051 - #define KVM_MAX_IRQ_ROUTES 4096 1052 - #else 1053 - #define KVM_MAX_IRQ_ROUTES 1024 1054 - #endif 1048 + #define KVM_MAX_IRQ_ROUTES 4096 /* might need extension/rework in the future */ 1055 1049 1056 1050 bool kvm_arch_can_set_irq_routing(struct kvm *kvm); 1057 1051 int kvm_set_irq_routing(struct kvm *kvm,
+1 -1
tools/testing/selftests/kvm/Makefile
··· 15 15 16 16 INSTALL_HDR_PATH = $(top_srcdir)/usr 17 17 LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ 18 - CFLAGS += -O2 -g -std=gnu99 -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) 18 + CFLAGS += -O2 -g -std=gnu99 -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -I.. 19 19 20 20 # After inclusion, $(OUTPUT) is defined and 21 21 # $(TEST_GEN_PROGS) starts with $(OUTPUT)/
+1
tools/testing/selftests/kvm/include/test_util.h
··· 19 19 #include <errno.h> 20 20 #include <unistd.h> 21 21 #include <fcntl.h> 22 + #include "kselftest.h" 22 23 23 24 ssize_t test_write(int fd, const void *buf, size_t count); 24 25 ssize_t test_read(int fd, void *buf, size_t count);
+8 -8
tools/testing/selftests/kvm/lib/kvm_util.c
··· 50 50 int kvm_fd; 51 51 52 52 kvm_fd = open(KVM_DEV_PATH, O_RDONLY); 53 - TEST_ASSERT(kvm_fd >= 0, "open %s failed, rc: %i errno: %i", 54 - KVM_DEV_PATH, kvm_fd, errno); 53 + if (kvm_fd < 0) 54 + exit(KSFT_SKIP); 55 55 56 56 ret = ioctl(kvm_fd, KVM_CHECK_EXTENSION, cap); 57 57 TEST_ASSERT(ret != -1, "KVM_CHECK_EXTENSION IOCTL failed,\n" ··· 91 91 92 92 vm->mode = mode; 93 93 kvm_fd = open(KVM_DEV_PATH, perm); 94 - TEST_ASSERT(kvm_fd >= 0, "open %s failed, rc: %i errno: %i", 95 - KVM_DEV_PATH, kvm_fd, errno); 94 + if (kvm_fd < 0) 95 + exit(KSFT_SKIP); 96 96 97 97 /* Create VM. */ 98 98 vm->fd = ioctl(kvm_fd, KVM_CREATE_VM, NULL); ··· 418 418 419 419 cpuid = allocate_kvm_cpuid2(); 420 420 kvm_fd = open(KVM_DEV_PATH, O_RDONLY); 421 - TEST_ASSERT(kvm_fd >= 0, "open %s failed, rc: %i errno: %i", 422 - KVM_DEV_PATH, kvm_fd, errno); 421 + if (kvm_fd < 0) 422 + exit(KSFT_SKIP); 423 423 424 424 ret = ioctl(kvm_fd, KVM_GET_SUPPORTED_CPUID, cpuid); 425 425 TEST_ASSERT(ret == 0, "KVM_GET_SUPPORTED_CPUID failed %d %d\n", ··· 675 675 int dev_fd, ret; 676 676 677 677 dev_fd = open(KVM_DEV_PATH, O_RDONLY); 678 - TEST_ASSERT(dev_fd >= 0, "%s open %s failed, rc: %i errno: %i", 679 - __func__, KVM_DEV_PATH, dev_fd, errno); 678 + if (dev_fd < 0) 679 + exit(KSFT_SKIP); 680 680 681 681 ret = ioctl(dev_fd, KVM_GET_VCPU_MMAP_SIZE, NULL); 682 682 TEST_ASSERT(ret >= sizeof(struct kvm_run),
+31 -9
tools/testing/selftests/kvm/sync_regs_test.c
··· 85 85 { 86 86 } 87 87 88 + #define TEST_SYNC_FIELDS (KVM_SYNC_X86_REGS|KVM_SYNC_X86_SREGS|KVM_SYNC_X86_EVENTS) 89 + #define INVALID_SYNC_FIELD 0x80000000 90 + 88 91 int main(int argc, char *argv[]) 89 92 { 90 93 struct kvm_vm *vm; ··· 101 98 setbuf(stdout, NULL); 102 99 103 100 cap = kvm_check_cap(KVM_CAP_SYNC_REGS); 104 - TEST_ASSERT((unsigned long)cap == KVM_SYNC_X86_VALID_FIELDS, 105 - "KVM_CAP_SYNC_REGS (0x%x) != KVM_SYNC_X86_VALID_FIELDS (0x%lx)\n", 106 - cap, KVM_SYNC_X86_VALID_FIELDS); 101 + if ((cap & TEST_SYNC_FIELDS) != TEST_SYNC_FIELDS) { 102 + fprintf(stderr, "KVM_CAP_SYNC_REGS not supported, skipping test\n"); 103 + exit(KSFT_SKIP); 104 + } 105 + if ((cap & INVALID_SYNC_FIELD) != 0) { 106 + fprintf(stderr, "The \"invalid\" field is not invalid, skipping test\n"); 107 + exit(KSFT_SKIP); 108 + } 107 109 108 110 /* Create VM */ 109 111 vm = vm_create_default(VCPU_ID, guest_code); ··· 116 108 run = vcpu_state(vm, VCPU_ID); 117 109 118 110 /* Request reading invalid register set from VCPU. */ 119 - run->kvm_valid_regs = KVM_SYNC_X86_VALID_FIELDS << 1; 111 + run->kvm_valid_regs = INVALID_SYNC_FIELD; 112 + rv = _vcpu_run(vm, VCPU_ID); 113 + TEST_ASSERT(rv < 0 && errno == EINVAL, 114 + "Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n", 115 + rv); 116 + vcpu_state(vm, VCPU_ID)->kvm_valid_regs = 0; 117 + 118 + run->kvm_valid_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS; 120 119 rv = _vcpu_run(vm, VCPU_ID); 121 120 TEST_ASSERT(rv < 0 && errno == EINVAL, 122 121 "Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n", ··· 131 116 vcpu_state(vm, VCPU_ID)->kvm_valid_regs = 0; 132 117 133 118 /* Request setting invalid register set into VCPU. */ 134 - run->kvm_dirty_regs = KVM_SYNC_X86_VALID_FIELDS << 1; 119 + run->kvm_dirty_regs = INVALID_SYNC_FIELD; 120 + rv = _vcpu_run(vm, VCPU_ID); 121 + TEST_ASSERT(rv < 0 && errno == EINVAL, 122 + "Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n", 123 + rv); 124 + vcpu_state(vm, VCPU_ID)->kvm_dirty_regs = 0; 125 + 126 + run->kvm_dirty_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS; 135 127 rv = _vcpu_run(vm, VCPU_ID); 136 128 TEST_ASSERT(rv < 0 && errno == EINVAL, 137 129 "Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n", ··· 147 125 148 126 /* Request and verify all valid register sets. */ 149 127 /* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */ 150 - run->kvm_valid_regs = KVM_SYNC_X86_VALID_FIELDS; 128 + run->kvm_valid_regs = TEST_SYNC_FIELDS; 151 129 rv = _vcpu_run(vm, VCPU_ID); 152 130 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 153 131 "Unexpected exit reason: %u (%s),\n", ··· 168 146 run->s.regs.sregs.apic_base = 1 << 11; 169 147 /* TODO run->s.regs.events.XYZ = ABC; */ 170 148 171 - run->kvm_valid_regs = KVM_SYNC_X86_VALID_FIELDS; 149 + run->kvm_valid_regs = TEST_SYNC_FIELDS; 172 150 run->kvm_dirty_regs = KVM_SYNC_X86_REGS | KVM_SYNC_X86_SREGS; 173 151 rv = _vcpu_run(vm, VCPU_ID); 174 152 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, ··· 194 172 /* Clear kvm_dirty_regs bits, verify new s.regs values are 195 173 * overwritten with existing guest values. 196 174 */ 197 - run->kvm_valid_regs = KVM_SYNC_X86_VALID_FIELDS; 175 + run->kvm_valid_regs = TEST_SYNC_FIELDS; 198 176 run->kvm_dirty_regs = 0; 199 177 run->s.regs.regs.r11 = 0xDEADBEEF; 200 178 rv = _vcpu_run(vm, VCPU_ID); ··· 233 211 * with kvm_sync_regs values. 234 212 */ 235 213 run->kvm_valid_regs = 0; 236 - run->kvm_dirty_regs = KVM_SYNC_X86_VALID_FIELDS; 214 + run->kvm_dirty_regs = TEST_SYNC_FIELDS; 237 215 run->s.regs.regs.r11 = 0xBBBB; 238 216 rv = _vcpu_run(vm, VCPU_ID); 239 217 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+2 -2
tools/testing/selftests/kvm/vmx_tsc_adjust_test.c
··· 189 189 struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); 190 190 191 191 if (!(entry->ecx & CPUID_VMX)) { 192 - printf("nested VMX not enabled, skipping test"); 193 - return 0; 192 + fprintf(stderr, "nested VMX not enabled, skipping test\n"); 193 + exit(KSFT_SKIP); 194 194 } 195 195 196 196 vm = vm_create_default_vmx(VCPU_ID, (void *) l1_guest_code);
+3 -2
virt/kvm/arm/vgic/vgic-debug.c
··· 211 211 struct vgic_state_iter *iter = (struct vgic_state_iter *)v; 212 212 struct vgic_irq *irq; 213 213 struct kvm_vcpu *vcpu = NULL; 214 + unsigned long flags; 214 215 215 216 if (iter->dist_id == 0) { 216 217 print_dist_state(s, &kvm->arch.vgic); ··· 228 227 irq = &kvm->arch.vgic.spis[iter->intid - VGIC_NR_PRIVATE_IRQS]; 229 228 } 230 229 231 - spin_lock(&irq->irq_lock); 230 + spin_lock_irqsave(&irq->irq_lock, flags); 232 231 print_irq_state(s, irq, vcpu); 233 - spin_unlock(&irq->irq_lock); 232 + spin_unlock_irqrestore(&irq->irq_lock, flags); 234 233 235 234 return 0; 236 235 }
+19 -15
virt/kvm/arm/vgic/vgic-its.c
··· 52 52 { 53 53 struct vgic_dist *dist = &kvm->arch.vgic; 54 54 struct vgic_irq *irq = vgic_get_irq(kvm, NULL, intid), *oldirq; 55 + unsigned long flags; 55 56 int ret; 56 57 57 58 /* In this case there is no put, since we keep the reference. */ ··· 72 71 irq->intid = intid; 73 72 irq->target_vcpu = vcpu; 74 73 75 - spin_lock(&dist->lpi_list_lock); 74 + spin_lock_irqsave(&dist->lpi_list_lock, flags); 76 75 77 76 /* 78 77 * There could be a race with another vgic_add_lpi(), so we need to ··· 100 99 dist->lpi_list_count++; 101 100 102 101 out_unlock: 103 - spin_unlock(&dist->lpi_list_lock); 102 + spin_unlock_irqrestore(&dist->lpi_list_lock, flags); 104 103 105 104 /* 106 105 * We "cache" the configuration table entries in our struct vgic_irq's. ··· 281 280 int ret; 282 281 unsigned long flags; 283 282 284 - ret = kvm_read_guest(kvm, propbase + irq->intid - GIC_LPI_OFFSET, 285 - &prop, 1); 283 + ret = kvm_read_guest_lock(kvm, propbase + irq->intid - GIC_LPI_OFFSET, 284 + &prop, 1); 286 285 287 286 if (ret) 288 287 return ret; ··· 316 315 { 317 316 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; 318 317 struct vgic_irq *irq; 318 + unsigned long flags; 319 319 u32 *intids; 320 320 int irq_count, i = 0; 321 321 ··· 332 330 if (!intids) 333 331 return -ENOMEM; 334 332 335 - spin_lock(&dist->lpi_list_lock); 333 + spin_lock_irqsave(&dist->lpi_list_lock, flags); 336 334 list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { 337 335 if (i == irq_count) 338 336 break; ··· 341 339 continue; 342 340 intids[i++] = irq->intid; 343 341 } 344 - spin_unlock(&dist->lpi_list_lock); 342 + spin_unlock_irqrestore(&dist->lpi_list_lock, flags); 345 343 346 344 *intid_ptr = intids; 347 345 return i; ··· 350 348 static int update_affinity(struct vgic_irq *irq, struct kvm_vcpu *vcpu) 351 349 { 352 350 int ret = 0; 351 + unsigned long flags; 353 352 354 - spin_lock(&irq->irq_lock); 353 + spin_lock_irqsave(&irq->irq_lock, flags); 355 354 irq->target_vcpu = vcpu; 356 - spin_unlock(&irq->irq_lock); 355 + spin_unlock_irqrestore(&irq->irq_lock, flags); 357 356 358 357 if (irq->hw) { 359 358 struct its_vlpi_map map; ··· 444 441 * this very same byte in the last iteration. Reuse that. 445 442 */ 446 443 if (byte_offset != last_byte_offset) { 447 - ret = kvm_read_guest(vcpu->kvm, pendbase + byte_offset, 448 - &pendmask, 1); 444 + ret = kvm_read_guest_lock(vcpu->kvm, 445 + pendbase + byte_offset, 446 + &pendmask, 1); 449 447 if (ret) { 450 448 kfree(intids); 451 449 return ret; ··· 790 786 return false; 791 787 792 788 /* Each 1st level entry is represented by a 64-bit value. */ 793 - if (kvm_read_guest(its->dev->kvm, 789 + if (kvm_read_guest_lock(its->dev->kvm, 794 790 BASER_ADDRESS(baser) + index * sizeof(indirect_ptr), 795 791 &indirect_ptr, sizeof(indirect_ptr))) 796 792 return false; ··· 1371 1367 cbaser = CBASER_ADDRESS(its->cbaser); 1372 1368 1373 1369 while (its->cwriter != its->creadr) { 1374 - int ret = kvm_read_guest(kvm, cbaser + its->creadr, 1375 - cmd_buf, ITS_CMD_SIZE); 1370 + int ret = kvm_read_guest_lock(kvm, cbaser + its->creadr, 1371 + cmd_buf, ITS_CMD_SIZE); 1376 1372 /* 1377 1373 * If kvm_read_guest() fails, this could be due to the guest 1378 1374 * programming a bogus value in CBASER or something else going ··· 1897 1893 int next_offset; 1898 1894 size_t byte_offset; 1899 1895 1900 - ret = kvm_read_guest(kvm, gpa, entry, esz); 1896 + ret = kvm_read_guest_lock(kvm, gpa, entry, esz); 1901 1897 if (ret) 1902 1898 return ret; 1903 1899 ··· 2267 2263 int ret; 2268 2264 2269 2265 BUG_ON(esz > sizeof(val)); 2270 - ret = kvm_read_guest(kvm, gpa, &val, esz); 2266 + ret = kvm_read_guest_lock(kvm, gpa, &val, esz); 2271 2267 if (ret) 2272 2268 return ret; 2273 2269 val = le64_to_cpu(val);
+2 -2
virt/kvm/arm/vgic/vgic-v3.c
··· 344 344 bit_nr = irq->intid % BITS_PER_BYTE; 345 345 ptr = pendbase + byte_offset; 346 346 347 - ret = kvm_read_guest(kvm, ptr, &val, 1); 347 + ret = kvm_read_guest_lock(kvm, ptr, &val, 1); 348 348 if (ret) 349 349 return ret; 350 350 ··· 397 397 ptr = pendbase + byte_offset; 398 398 399 399 if (byte_offset != last_byte_offset) { 400 - ret = kvm_read_guest(kvm, ptr, &val, 1); 400 + ret = kvm_read_guest_lock(kvm, ptr, &val, 1); 401 401 if (ret) 402 402 return ret; 403 403 last_byte_offset = byte_offset;
+14 -8
virt/kvm/arm/vgic/vgic.c
··· 43 43 * kvm->lock (mutex) 44 44 * its->cmd_lock (mutex) 45 45 * its->its_lock (mutex) 46 - * vgic_cpu->ap_list_lock 47 - * kvm->lpi_list_lock 48 - * vgic_irq->irq_lock 46 + * vgic_cpu->ap_list_lock must be taken with IRQs disabled 47 + * kvm->lpi_list_lock must be taken with IRQs disabled 48 + * vgic_irq->irq_lock must be taken with IRQs disabled 49 + * 50 + * As the ap_list_lock might be taken from the timer interrupt handler, 51 + * we have to disable IRQs before taking this lock and everything lower 52 + * than it. 49 53 * 50 54 * If you need to take multiple locks, always take the upper lock first, 51 55 * then the lower ones, e.g. first take the its_lock, then the irq_lock. ··· 76 72 { 77 73 struct vgic_dist *dist = &kvm->arch.vgic; 78 74 struct vgic_irq *irq = NULL; 75 + unsigned long flags; 79 76 80 - spin_lock(&dist->lpi_list_lock); 77 + spin_lock_irqsave(&dist->lpi_list_lock, flags); 81 78 82 79 list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { 83 80 if (irq->intid != intid) ··· 94 89 irq = NULL; 95 90 96 91 out_unlock: 97 - spin_unlock(&dist->lpi_list_lock); 92 + spin_unlock_irqrestore(&dist->lpi_list_lock, flags); 98 93 99 94 return irq; 100 95 } ··· 139 134 void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) 140 135 { 141 136 struct vgic_dist *dist = &kvm->arch.vgic; 137 + unsigned long flags; 142 138 143 139 if (irq->intid < VGIC_MIN_LPI) 144 140 return; 145 141 146 - spin_lock(&dist->lpi_list_lock); 142 + spin_lock_irqsave(&dist->lpi_list_lock, flags); 147 143 if (!kref_put(&irq->refcount, vgic_irq_release)) { 148 - spin_unlock(&dist->lpi_list_lock); 144 + spin_unlock_irqrestore(&dist->lpi_list_lock, flags); 149 145 return; 150 146 }; 151 147 152 148 list_del(&irq->lpi_list); 153 149 dist->lpi_list_count--; 154 - spin_unlock(&dist->lpi_list_lock); 150 + spin_unlock_irqrestore(&dist->lpi_list_lock, flags); 155 151 156 152 kfree(irq); 157 153 }