Lines Matching +full:fw +full:- +full:cfg +full:- +full:mmio
1 // SPDX-License-Identifier: GPL-2.0-only
53 return !!(v->arch.pending_exceptions) || kvm_request_pending(v); in kvm_arch_vcpu_runnable()
97 vcpu->run->exit_reason = KVM_EXIT_INTR; in kvmppc_prepare_to_enter()
98 r = -EINTR; in kvmppc_prepare_to_enter()
102 vcpu->mode = IN_GUEST_MODE; in kvmppc_prepare_to_enter()
105 * Reading vcpu->requests must happen after setting vcpu->mode, in kvmppc_prepare_to_enter()
145 struct kvm_vcpu_arch_shared *shared = vcpu->arch.shared; in kvmppc_swab_shared()
148 shared->sprg0 = swab64(shared->sprg0); in kvmppc_swab_shared()
149 shared->sprg1 = swab64(shared->sprg1); in kvmppc_swab_shared()
150 shared->sprg2 = swab64(shared->sprg2); in kvmppc_swab_shared()
151 shared->sprg3 = swab64(shared->sprg3); in kvmppc_swab_shared()
152 shared->srr0 = swab64(shared->srr0); in kvmppc_swab_shared()
153 shared->srr1 = swab64(shared->srr1); in kvmppc_swab_shared()
154 shared->dar = swab64(shared->dar); in kvmppc_swab_shared()
155 shared->msr = swab64(shared->msr); in kvmppc_swab_shared()
156 shared->dsisr = swab32(shared->dsisr); in kvmppc_swab_shared()
157 shared->int_pending = swab32(shared->int_pending); in kvmppc_swab_shared()
158 for (i = 0; i < ARRAY_SIZE(shared->sr); i++) in kvmppc_swab_shared()
159 shared->sr[i] = swab32(shared->sr[i]); in kvmppc_swab_shared()
187 if (vcpu->arch.intr_msr & MSR_LE) in kvmppc_kvm_pv()
189 if (shared_big_endian != vcpu->arch.shared_big_endian) in kvmppc_kvm_pv()
191 vcpu->arch.shared_big_endian = shared_big_endian; in kvmppc_kvm_pv()
200 vcpu->arch.disable_kernel_nx = true; in kvmppc_kvm_pv()
204 vcpu->arch.magic_page_pa = param1 & ~0xfffULL; in kvmppc_kvm_pv()
205 vcpu->arch.magic_page_ea = param2 & ~0xfffULL; in kvmppc_kvm_pv()
212 if ((vcpu->arch.magic_page_pa & 0xf000) != in kvmppc_kvm_pv()
213 ((ulong)vcpu->arch.shared & 0xf000)) { in kvmppc_kvm_pv()
214 void *old_shared = vcpu->arch.shared; in kvmppc_kvm_pv()
215 ulong shared = (ulong)vcpu->arch.shared; in kvmppc_kvm_pv()
219 shared |= vcpu->arch.magic_page_pa & 0xf000; in kvmppc_kvm_pv()
222 vcpu->arch.shared = new_shared; in kvmppc_kvm_pv()
259 if (!vcpu->arch.pvr) in kvmppc_sanity_check()
263 if ((vcpu->arch.cpu_type != KVM_CPU_3S_64) && vcpu->arch.papr_enabled) in kvmppc_sanity_check()
267 if (!vcpu->arch.papr_enabled && is_kvmppc_hv_enabled(vcpu->kvm)) in kvmppc_sanity_check()
278 vcpu->arch.sane = r; in kvmppc_sanity_check()
279 return r ? 0 : -EINVAL; in kvmppc_sanity_check()
291 /* Future optimization: only reload non-volatiles if they were in kvmppc_emulate_mmio()
299 vcpu->run->exit_reason = KVM_EXIT_MMIO; in kvmppc_emulate_mmio()
302 /* Future optimization: only reload non-volatiles if they were in kvmppc_emulate_mmio()
322 if (vcpu->mmio_is_write) in kvmppc_emulate_mmio()
325 kvmppc_core_queue_data_storage(vcpu, vcpu->arch.vaddr_accessed, dsisr); in kvmppc_emulate_mmio()
350 ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; in kvmppc_st()
352 int r = -EINVAL; in kvmppc_st()
354 vcpu->stat.st++; in kvmppc_st()
356 if (vcpu->kvm->arch.kvm_ops && vcpu->kvm->arch.kvm_ops->store_to_eaddr) in kvmppc_st()
357 r = vcpu->kvm->arch.kvm_ops->store_to_eaddr(vcpu, eaddr, ptr, in kvmppc_st()
360 if ((!r) || (r == -EAGAIN)) in kvmppc_st()
371 return -EPERM; in kvmppc_st()
377 void *magic = vcpu->arch.shared; in kvmppc_st()
383 if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size)) in kvmppc_st()
393 ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; in kvmppc_ld()
395 int rc = -EINVAL; in kvmppc_ld()
397 vcpu->stat.ld++; in kvmppc_ld()
399 if (vcpu->kvm->arch.kvm_ops && vcpu->kvm->arch.kvm_ops->load_from_eaddr) in kvmppc_ld()
400 rc = vcpu->kvm->arch.kvm_ops->load_from_eaddr(vcpu, eaddr, ptr, in kvmppc_ld()
403 if ((!rc) || (rc == -EAGAIN)) in kvmppc_ld()
414 return -EPERM; in kvmppc_ld()
417 return -ENOEXEC; in kvmppc_ld()
423 void *magic = vcpu->arch.shared; in kvmppc_ld()
430 rc = kvm_read_guest(vcpu->kvm, pte.raddr, ptr, size); in kvmppc_ld()
480 if (!try_module_get(kvm_ops->owner)) in kvm_arch_init_vm()
481 return -ENOENT; in kvm_arch_init_vm()
483 kvm->arch.kvm_ops = kvm_ops; in kvm_arch_init_vm()
486 module_put(kvm_ops->owner); in kvm_arch_init_vm()
489 return -EINVAL; in kvm_arch_init_vm()
506 mutex_lock(&kvm->lock); in kvm_arch_destroy_vm()
510 mutex_unlock(&kvm->lock); in kvm_arch_destroy_vm()
513 module_put(kvm->arch.kvm_ops->owner); in kvm_arch_destroy_vm()
524 * Hooray - we know which VM type we're running on. Depend on in kvm_vm_ioctl_check_extension()
603 if (kvm->arch.emul_smt_mode > 1) in kvm_vm_ioctl_check_extension()
604 r = kvm->arch.emul_smt_mode; in kvm_vm_ioctl_check_extension()
606 r = kvm->arch.smt_mode; in kvm_vm_ioctl_check_extension()
618 r = ((threads_per_subcore << 1) - 1); in kvm_vm_ioctl_check_extension()
634 r = !!(hv_enabled && kvmppc_hv_ops->hash_v3_possible && in kvm_vm_ioctl_check_extension()
635 kvmppc_hv_ops->hash_v3_possible()); in kvm_vm_ioctl_check_extension()
638 r = !!(hv_enabled && kvmppc_hv_ops->enable_nested && in kvm_vm_ioctl_check_extension()
639 !kvmppc_hv_ops->enable_nested(NULL)); in kvm_vm_ioctl_check_extension()
659 * return the number of present CPUs for -HV (since a host in kvm_vm_ioctl_check_extension()
692 r = !!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_HTM) || in kvm_vm_ioctl_check_extension()
698 r = hv_enabled && kvmppc_hv_ops->enable_svm && in kvm_vm_ioctl_check_extension()
699 !kvmppc_hv_ops->enable_svm(NULL); in kvm_vm_ioctl_check_extension()
702 r = !!(hv_enabled && kvmppc_hv_ops->enable_dawr1 && in kvm_vm_ioctl_check_extension()
703 !kvmppc_hv_ops->enable_dawr1(NULL)); in kvm_vm_ioctl_check_extension()
737 return -EINVAL; in kvm_arch_dev_ioctl()
786 hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); in kvm_arch_vcpu_create()
787 vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup; in kvm_arch_vcpu_create()
790 mutex_init(&vcpu->arch.exit_timing_lock); in kvm_arch_vcpu_create()
800 rcuwait_init(&vcpu->arch.wait); in kvm_arch_vcpu_create()
801 vcpu->arch.waitp = &vcpu->arch.wait; in kvm_arch_vcpu_create()
816 hrtimer_cancel(&vcpu->arch.dec_timer); in kvm_arch_vcpu_destroy()
818 switch (vcpu->arch.irq_type) { in kvm_arch_vcpu_destroy()
820 kvmppc_mpic_disconnect_vcpu(vcpu->arch.mpic, vcpu); in kvm_arch_vcpu_destroy()
850 * On non-booke this is associated with Altivec and in kvm_arch_vcpu_load()
853 mtspr(SPRN_VRSAVE, vcpu->arch.vrsave); in kvm_arch_vcpu_load()
862 vcpu->arch.vrsave = mfspr(SPRN_VRSAVE); in kvm_arch_vcpu_put()
874 return ((kvmppc_hv_ops && kvmppc_hv_ops->irq_bypass_add_producer) || in kvm_arch_has_irq_bypass()
875 (kvmppc_pr_ops && kvmppc_pr_ops->irq_bypass_add_producer)); in kvm_arch_has_irq_bypass()
883 struct kvm *kvm = irqfd->kvm; in kvm_arch_irq_bypass_add_producer()
885 if (kvm->arch.kvm_ops->irq_bypass_add_producer) in kvm_arch_irq_bypass_add_producer()
886 return kvm->arch.kvm_ops->irq_bypass_add_producer(cons, prod); in kvm_arch_irq_bypass_add_producer()
896 struct kvm *kvm = irqfd->kvm; in kvm_arch_irq_bypass_del_producer()
898 if (kvm->arch.kvm_ops->irq_bypass_del_producer) in kvm_arch_irq_bypass_del_producer()
899 kvm->arch.kvm_ops->irq_bypass_del_producer(cons, prod); in kvm_arch_irq_bypass_del_producer()
908 return -1; in kvmppc_get_vsr_dword_offset()
913 offset = 1 - index; in kvmppc_get_vsr_dword_offset()
924 return -1; in kvmppc_get_vsr_word_offset()
929 offset = 3 - index; in kvmppc_get_vsr_word_offset()
938 int offset = kvmppc_get_vsr_dword_offset(vcpu->arch.mmio_vsx_offset); in kvmppc_set_vsr_dword()
939 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vsr_dword()
941 if (offset == -1) in kvmppc_set_vsr_dword()
945 val.vval = VCPU_VSX_VR(vcpu, index - 32); in kvmppc_set_vsr_dword()
947 VCPU_VSX_VR(vcpu, index - 32) = val.vval; in kvmppc_set_vsr_dword()
957 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vsr_dword_dump()
960 val.vval = VCPU_VSX_VR(vcpu, index - 32); in kvmppc_set_vsr_dword_dump()
963 VCPU_VSX_VR(vcpu, index - 32) = val.vval; in kvmppc_set_vsr_dword_dump()
974 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vsr_word_dump()
981 VCPU_VSX_VR(vcpu, index - 32) = val.vval; in kvmppc_set_vsr_word_dump()
994 int offset = kvmppc_get_vsr_word_offset(vcpu->arch.mmio_vsx_offset); in kvmppc_set_vsr_word()
995 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vsr_word()
998 if (offset == -1) in kvmppc_set_vsr_word()
1002 val.vval = VCPU_VSX_VR(vcpu, index - 32); in kvmppc_set_vsr_word()
1004 VCPU_VSX_VR(vcpu, index - 32) = val.vval; in kvmppc_set_vsr_word()
1023 return -1; in kvmppc_get_vmx_offset_generic()
1026 offset = elts - index - 1; in kvmppc_get_vmx_offset_generic()
1063 vcpu->arch.mmio_vmx_offset); in kvmppc_set_vmx_dword()
1064 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vmx_dword()
1066 if (offset == -1) in kvmppc_set_vmx_dword()
1079 vcpu->arch.mmio_vmx_offset); in kvmppc_set_vmx_word()
1080 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vmx_word()
1082 if (offset == -1) in kvmppc_set_vmx_word()
1095 vcpu->arch.mmio_vmx_offset); in kvmppc_set_vmx_hword()
1096 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vmx_hword()
1098 if (offset == -1) in kvmppc_set_vmx_hword()
1111 vcpu->arch.mmio_vmx_offset); in kvmppc_set_vmx_byte()
1112 int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK; in kvmppc_set_vmx_byte()
1114 if (offset == -1) in kvmppc_set_vmx_byte()
1155 struct kvm_run *run = vcpu->run; in kvmppc_complete_mmio_load()
1158 if (run->mmio.len > sizeof(gpr)) in kvmppc_complete_mmio_load()
1161 if (!vcpu->arch.mmio_host_swabbed) { in kvmppc_complete_mmio_load()
1162 switch (run->mmio.len) { in kvmppc_complete_mmio_load()
1163 case 8: gpr = *(u64 *)run->mmio.data; break; in kvmppc_complete_mmio_load()
1164 case 4: gpr = *(u32 *)run->mmio.data; break; in kvmppc_complete_mmio_load()
1165 case 2: gpr = *(u16 *)run->mmio.data; break; in kvmppc_complete_mmio_load()
1166 case 1: gpr = *(u8 *)run->mmio.data; break; in kvmppc_complete_mmio_load()
1169 switch (run->mmio.len) { in kvmppc_complete_mmio_load()
1170 case 8: gpr = swab64(*(u64 *)run->mmio.data); break; in kvmppc_complete_mmio_load()
1171 case 4: gpr = swab32(*(u32 *)run->mmio.data); break; in kvmppc_complete_mmio_load()
1172 case 2: gpr = swab16(*(u16 *)run->mmio.data); break; in kvmppc_complete_mmio_load()
1173 case 1: gpr = *(u8 *)run->mmio.data; break; in kvmppc_complete_mmio_load()
1178 if ((vcpu->arch.mmio_sp64_extend) && (run->mmio.len == 4)) in kvmppc_complete_mmio_load()
1181 if (vcpu->arch.mmio_sign_extend) { in kvmppc_complete_mmio_load()
1182 switch (run->mmio.len) { in kvmppc_complete_mmio_load()
1197 switch (vcpu->arch.io_gpr & KVM_MMIO_REG_EXT_MASK) { in kvmppc_complete_mmio_load()
1199 kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr); in kvmppc_complete_mmio_load()
1202 if (vcpu->kvm->arch.kvm_ops->giveup_ext) in kvmppc_complete_mmio_load()
1203 vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_FP); in kvmppc_complete_mmio_load()
1205 VCPU_FPR(vcpu, vcpu->arch.io_gpr & KVM_MMIO_REG_MASK) = gpr; in kvmppc_complete_mmio_load()
1209 vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_MMIO_REG_MASK] = gpr; in kvmppc_complete_mmio_load()
1212 VCPU_FPR(vcpu, vcpu->arch.io_gpr & KVM_MMIO_REG_MASK) = gpr; in kvmppc_complete_mmio_load()
1213 vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_MMIO_REG_MASK] = gpr; in kvmppc_complete_mmio_load()
1218 if (vcpu->kvm->arch.kvm_ops->giveup_ext) in kvmppc_complete_mmio_load()
1219 vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_VSX); in kvmppc_complete_mmio_load()
1221 if (vcpu->arch.mmio_copy_type == KVMPPC_VSX_COPY_DWORD) in kvmppc_complete_mmio_load()
1223 else if (vcpu->arch.mmio_copy_type == KVMPPC_VSX_COPY_WORD) in kvmppc_complete_mmio_load()
1225 else if (vcpu->arch.mmio_copy_type == in kvmppc_complete_mmio_load()
1228 else if (vcpu->arch.mmio_copy_type == in kvmppc_complete_mmio_load()
1235 if (vcpu->kvm->arch.kvm_ops->giveup_ext) in kvmppc_complete_mmio_load()
1236 vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_VEC); in kvmppc_complete_mmio_load()
1238 if (vcpu->arch.mmio_copy_type == KVMPPC_VMX_COPY_DWORD) in kvmppc_complete_mmio_load()
1240 else if (vcpu->arch.mmio_copy_type == KVMPPC_VMX_COPY_WORD) in kvmppc_complete_mmio_load()
1242 else if (vcpu->arch.mmio_copy_type == in kvmppc_complete_mmio_load()
1245 else if (vcpu->arch.mmio_copy_type == in kvmppc_complete_mmio_load()
1254 kvm_vcpu_write_guest(vcpu, vcpu->arch.nested_io_gpr, &gpr, in kvmppc_complete_mmio_load()
1267 struct kvm_run *run = vcpu->run; in __kvmppc_handle_load()
1278 if (bytes > sizeof(run->mmio.data)) in __kvmppc_handle_load()
1281 run->mmio.phys_addr = vcpu->arch.paddr_accessed; in __kvmppc_handle_load()
1282 run->mmio.len = bytes; in __kvmppc_handle_load()
1283 run->mmio.is_write = 0; in __kvmppc_handle_load()
1285 vcpu->arch.io_gpr = rt; in __kvmppc_handle_load()
1286 vcpu->arch.mmio_host_swabbed = host_swabbed; in __kvmppc_handle_load()
1287 vcpu->mmio_needed = 1; in __kvmppc_handle_load()
1288 vcpu->mmio_is_write = 0; in __kvmppc_handle_load()
1289 vcpu->arch.mmio_sign_extend = sign_extend; in __kvmppc_handle_load()
1291 idx = srcu_read_lock(&vcpu->kvm->srcu); in __kvmppc_handle_load()
1293 ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, run->mmio.phys_addr, in __kvmppc_handle_load()
1294 bytes, &run->mmio.data); in __kvmppc_handle_load()
1296 srcu_read_unlock(&vcpu->kvm->srcu, idx); in __kvmppc_handle_load()
1300 vcpu->mmio_needed = 0; in __kvmppc_handle_load()
1331 if (vcpu->arch.mmio_vsx_copy_nums > 4) in kvmppc_handle_vsx_load()
1334 while (vcpu->arch.mmio_vsx_copy_nums) { in kvmppc_handle_vsx_load()
1341 vcpu->arch.paddr_accessed += vcpu->run->mmio.len; in kvmppc_handle_vsx_load()
1343 vcpu->arch.mmio_vsx_copy_nums--; in kvmppc_handle_vsx_load()
1344 vcpu->arch.mmio_vsx_offset++; in kvmppc_handle_vsx_load()
1353 struct kvm_run *run = vcpu->run; in kvmppc_handle_store()
1354 void *data = run->mmio.data; in kvmppc_handle_store()
1365 if (bytes > sizeof(run->mmio.data)) in kvmppc_handle_store()
1368 run->mmio.phys_addr = vcpu->arch.paddr_accessed; in kvmppc_handle_store()
1369 run->mmio.len = bytes; in kvmppc_handle_store()
1370 run->mmio.is_write = 1; in kvmppc_handle_store()
1371 vcpu->mmio_needed = 1; in kvmppc_handle_store()
1372 vcpu->mmio_is_write = 1; in kvmppc_handle_store()
1374 if ((vcpu->arch.mmio_sp64_extend) && (bytes == 4)) in kvmppc_handle_store()
1394 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvmppc_handle_store()
1396 ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, run->mmio.phys_addr, in kvmppc_handle_store()
1397 bytes, &run->mmio.data); in kvmppc_handle_store()
1399 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvmppc_handle_store()
1402 vcpu->mmio_needed = 0; in kvmppc_handle_store()
1416 int copy_type = vcpu->arch.mmio_copy_type; in kvmppc_get_vsr_data()
1422 kvmppc_get_vsr_dword_offset(vcpu->arch.mmio_vsx_offset); in kvmppc_get_vsr_data()
1424 if (vsx_offset == -1) { in kvmppc_get_vsr_data()
1425 result = -1; in kvmppc_get_vsr_data()
1432 reg.vval = VCPU_VSX_VR(vcpu, rs - 32); in kvmppc_get_vsr_data()
1439 kvmppc_get_vsr_word_offset(vcpu->arch.mmio_vsx_offset); in kvmppc_get_vsr_data()
1441 if (vsx_offset == -1) { in kvmppc_get_vsr_data()
1442 result = -1; in kvmppc_get_vsr_data()
1452 reg.vval = VCPU_VSX_VR(vcpu, rs - 32); in kvmppc_get_vsr_data()
1458 result = -1; in kvmppc_get_vsr_data()
1471 vcpu->arch.io_gpr = rs; in kvmppc_handle_vsx_store()
1474 if (vcpu->arch.mmio_vsx_copy_nums > 4) in kvmppc_handle_vsx_store()
1477 while (vcpu->arch.mmio_vsx_copy_nums) { in kvmppc_handle_vsx_store()
1478 if (kvmppc_get_vsr_data(vcpu, rs, &val) == -1) in kvmppc_handle_vsx_store()
1487 vcpu->arch.paddr_accessed += vcpu->run->mmio.len; in kvmppc_handle_vsx_store()
1489 vcpu->arch.mmio_vsx_copy_nums--; in kvmppc_handle_vsx_store()
1490 vcpu->arch.mmio_vsx_offset++; in kvmppc_handle_vsx_store()
1498 struct kvm_run *run = vcpu->run; in kvmppc_emulate_mmio_vsx_loadstore()
1502 vcpu->arch.paddr_accessed += run->mmio.len; in kvmppc_emulate_mmio_vsx_loadstore()
1504 if (!vcpu->mmio_is_write) { in kvmppc_emulate_mmio_vsx_loadstore()
1505 emulated = kvmppc_handle_vsx_load(vcpu, vcpu->arch.io_gpr, in kvmppc_emulate_mmio_vsx_loadstore()
1506 run->mmio.len, 1, vcpu->arch.mmio_sign_extend); in kvmppc_emulate_mmio_vsx_loadstore()
1509 vcpu->arch.io_gpr, run->mmio.len, 1); in kvmppc_emulate_mmio_vsx_loadstore()
1514 run->exit_reason = KVM_EXIT_MMIO; in kvmppc_emulate_mmio_vsx_loadstore()
1518 pr_info("KVM: MMIO emulation failed (VSX repeat)\n"); in kvmppc_emulate_mmio_vsx_loadstore()
1519 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; in kvmppc_emulate_mmio_vsx_loadstore()
1520 run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; in kvmppc_emulate_mmio_vsx_loadstore()
1537 if (vcpu->arch.mmio_vmx_copy_nums > 2) in kvmppc_handle_vmx_load()
1540 while (vcpu->arch.mmio_vmx_copy_nums) { in kvmppc_handle_vmx_load()
1547 vcpu->arch.paddr_accessed += vcpu->run->mmio.len; in kvmppc_handle_vmx_load()
1548 vcpu->arch.mmio_vmx_copy_nums--; in kvmppc_handle_vmx_load()
1549 vcpu->arch.mmio_vmx_offset++; in kvmppc_handle_vmx_load()
1562 kvmppc_get_vmx_dword_offset(vcpu, vcpu->arch.mmio_vmx_offset); in kvmppc_get_vmx_dword()
1564 if (vmx_offset == -1) in kvmppc_get_vmx_dword()
1565 return -1; in kvmppc_get_vmx_dword()
1580 kvmppc_get_vmx_word_offset(vcpu, vcpu->arch.mmio_vmx_offset); in kvmppc_get_vmx_word()
1582 if (vmx_offset == -1) in kvmppc_get_vmx_word()
1583 return -1; in kvmppc_get_vmx_word()
1598 kvmppc_get_vmx_hword_offset(vcpu, vcpu->arch.mmio_vmx_offset); in kvmppc_get_vmx_hword()
1600 if (vmx_offset == -1) in kvmppc_get_vmx_hword()
1601 return -1; in kvmppc_get_vmx_hword()
1616 kvmppc_get_vmx_byte_offset(vcpu, vcpu->arch.mmio_vmx_offset); in kvmppc_get_vmx_byte()
1618 if (vmx_offset == -1) in kvmppc_get_vmx_byte()
1619 return -1; in kvmppc_get_vmx_byte()
1634 if (vcpu->arch.mmio_vmx_copy_nums > 2) in kvmppc_handle_vmx_store()
1637 vcpu->arch.io_gpr = rs; in kvmppc_handle_vmx_store()
1639 while (vcpu->arch.mmio_vmx_copy_nums) { in kvmppc_handle_vmx_store()
1640 switch (vcpu->arch.mmio_copy_type) { in kvmppc_handle_vmx_store()
1642 if (kvmppc_get_vmx_dword(vcpu, index, &val) == -1) in kvmppc_handle_vmx_store()
1647 if (kvmppc_get_vmx_word(vcpu, index, &val) == -1) in kvmppc_handle_vmx_store()
1651 if (kvmppc_get_vmx_hword(vcpu, index, &val) == -1) in kvmppc_handle_vmx_store()
1655 if (kvmppc_get_vmx_byte(vcpu, index, &val) == -1) in kvmppc_handle_vmx_store()
1667 vcpu->arch.paddr_accessed += vcpu->run->mmio.len; in kvmppc_handle_vmx_store()
1668 vcpu->arch.mmio_vmx_copy_nums--; in kvmppc_handle_vmx_store()
1669 vcpu->arch.mmio_vmx_offset++; in kvmppc_handle_vmx_store()
1677 struct kvm_run *run = vcpu->run; in kvmppc_emulate_mmio_vmx_loadstore()
1681 vcpu->arch.paddr_accessed += run->mmio.len; in kvmppc_emulate_mmio_vmx_loadstore()
1683 if (!vcpu->mmio_is_write) { in kvmppc_emulate_mmio_vmx_loadstore()
1685 vcpu->arch.io_gpr, run->mmio.len, 1); in kvmppc_emulate_mmio_vmx_loadstore()
1688 vcpu->arch.io_gpr, run->mmio.len, 1); in kvmppc_emulate_mmio_vmx_loadstore()
1693 run->exit_reason = KVM_EXIT_MMIO; in kvmppc_emulate_mmio_vmx_loadstore()
1697 pr_info("KVM: MMIO emulation failed (VMX repeat)\n"); in kvmppc_emulate_mmio_vmx_loadstore()
1698 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; in kvmppc_emulate_mmio_vmx_loadstore()
1699 run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; in kvmppc_emulate_mmio_vmx_loadstore()
1716 size = one_reg_size(reg->id); in kvm_vcpu_ioctl_get_one_reg()
1718 return -EINVAL; in kvm_vcpu_ioctl_get_one_reg()
1720 r = kvmppc_get_one_reg(vcpu, reg->id, &val); in kvm_vcpu_ioctl_get_one_reg()
1721 if (r == -EINVAL) { in kvm_vcpu_ioctl_get_one_reg()
1723 switch (reg->id) { in kvm_vcpu_ioctl_get_one_reg()
1727 r = -ENXIO; in kvm_vcpu_ioctl_get_one_reg()
1730 val.vval = vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0]; in kvm_vcpu_ioctl_get_one_reg()
1734 r = -ENXIO; in kvm_vcpu_ioctl_get_one_reg()
1737 val = get_reg_val(reg->id, vcpu->arch.vr.vscr.u[3]); in kvm_vcpu_ioctl_get_one_reg()
1740 val = get_reg_val(reg->id, vcpu->arch.vrsave); in kvm_vcpu_ioctl_get_one_reg()
1744 r = -EINVAL; in kvm_vcpu_ioctl_get_one_reg()
1752 if (copy_to_user((char __user *)(unsigned long)reg->addr, &val, size)) in kvm_vcpu_ioctl_get_one_reg()
1753 r = -EFAULT; in kvm_vcpu_ioctl_get_one_reg()
1764 size = one_reg_size(reg->id); in kvm_vcpu_ioctl_set_one_reg()
1766 return -EINVAL; in kvm_vcpu_ioctl_set_one_reg()
1768 if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size)) in kvm_vcpu_ioctl_set_one_reg()
1769 return -EFAULT; in kvm_vcpu_ioctl_set_one_reg()
1771 r = kvmppc_set_one_reg(vcpu, reg->id, &val); in kvm_vcpu_ioctl_set_one_reg()
1772 if (r == -EINVAL) { in kvm_vcpu_ioctl_set_one_reg()
1774 switch (reg->id) { in kvm_vcpu_ioctl_set_one_reg()
1778 r = -ENXIO; in kvm_vcpu_ioctl_set_one_reg()
1781 vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0] = val.vval; in kvm_vcpu_ioctl_set_one_reg()
1785 r = -ENXIO; in kvm_vcpu_ioctl_set_one_reg()
1788 vcpu->arch.vr.vscr.u[3] = set_reg_val(reg->id, val); in kvm_vcpu_ioctl_set_one_reg()
1792 r = -ENXIO; in kvm_vcpu_ioctl_set_one_reg()
1795 vcpu->arch.vrsave = set_reg_val(reg->id, val); in kvm_vcpu_ioctl_set_one_reg()
1799 r = -EINVAL; in kvm_vcpu_ioctl_set_one_reg()
1809 struct kvm_run *run = vcpu->run; in kvm_arch_vcpu_ioctl_run()
1814 if (vcpu->mmio_needed) { in kvm_arch_vcpu_ioctl_run()
1815 vcpu->mmio_needed = 0; in kvm_arch_vcpu_ioctl_run()
1816 if (!vcpu->mmio_is_write) in kvm_arch_vcpu_ioctl_run()
1819 if (vcpu->arch.mmio_vsx_copy_nums > 0) { in kvm_arch_vcpu_ioctl_run()
1820 vcpu->arch.mmio_vsx_copy_nums--; in kvm_arch_vcpu_ioctl_run()
1821 vcpu->arch.mmio_vsx_offset++; in kvm_arch_vcpu_ioctl_run()
1824 if (vcpu->arch.mmio_vsx_copy_nums > 0) { in kvm_arch_vcpu_ioctl_run()
1827 vcpu->mmio_needed = 1; in kvm_arch_vcpu_ioctl_run()
1833 if (vcpu->arch.mmio_vmx_copy_nums > 0) { in kvm_arch_vcpu_ioctl_run()
1834 vcpu->arch.mmio_vmx_copy_nums--; in kvm_arch_vcpu_ioctl_run()
1835 vcpu->arch.mmio_vmx_offset++; in kvm_arch_vcpu_ioctl_run()
1838 if (vcpu->arch.mmio_vmx_copy_nums > 0) { in kvm_arch_vcpu_ioctl_run()
1841 vcpu->mmio_needed = 1; in kvm_arch_vcpu_ioctl_run()
1846 } else if (vcpu->arch.osi_needed) { in kvm_arch_vcpu_ioctl_run()
1847 u64 *gprs = run->osi.gprs; in kvm_arch_vcpu_ioctl_run()
1852 vcpu->arch.osi_needed = 0; in kvm_arch_vcpu_ioctl_run()
1853 } else if (vcpu->arch.hcall_needed) { in kvm_arch_vcpu_ioctl_run()
1856 kvmppc_set_gpr(vcpu, 3, run->papr_hcall.ret); in kvm_arch_vcpu_ioctl_run()
1858 kvmppc_set_gpr(vcpu, 4 + i, run->papr_hcall.args[i]); in kvm_arch_vcpu_ioctl_run()
1859 vcpu->arch.hcall_needed = 0; in kvm_arch_vcpu_ioctl_run()
1861 } else if (vcpu->arch.epr_needed) { in kvm_arch_vcpu_ioctl_run()
1862 kvmppc_set_epr(vcpu, run->epr.epr); in kvm_arch_vcpu_ioctl_run()
1863 vcpu->arch.epr_needed = 0; in kvm_arch_vcpu_ioctl_run()
1869 if (run->immediate_exit) in kvm_arch_vcpu_ioctl_run()
1870 r = -EINTR; in kvm_arch_vcpu_ioctl_run()
1893 if (irq->irq == KVM_INTERRUPT_UNSET) { in kvm_vcpu_ioctl_interrupt()
1910 if (cap->flags) in kvm_vcpu_ioctl_enable_cap()
1911 return -EINVAL; in kvm_vcpu_ioctl_enable_cap()
1913 switch (cap->cap) { in kvm_vcpu_ioctl_enable_cap()
1916 vcpu->arch.osi_enabled = true; in kvm_vcpu_ioctl_enable_cap()
1920 vcpu->arch.papr_enabled = true; in kvm_vcpu_ioctl_enable_cap()
1924 if (cap->args[0]) in kvm_vcpu_ioctl_enable_cap()
1925 vcpu->arch.epr_flags |= KVMPPC_EPR_USER; in kvm_vcpu_ioctl_enable_cap()
1927 vcpu->arch.epr_flags &= ~KVMPPC_EPR_USER; in kvm_vcpu_ioctl_enable_cap()
1932 vcpu->arch.watchdog_enabled = true; in kvm_vcpu_ioctl_enable_cap()
1937 struct kvm_config_tlb cfg; in kvm_vcpu_ioctl_enable_cap() local
1938 void __user *user_ptr = (void __user *)(uintptr_t)cap->args[0]; in kvm_vcpu_ioctl_enable_cap()
1940 r = -EFAULT; in kvm_vcpu_ioctl_enable_cap()
1941 if (copy_from_user(&cfg, user_ptr, sizeof(cfg))) in kvm_vcpu_ioctl_enable_cap()
1944 r = kvm_vcpu_ioctl_config_tlb(vcpu, &cfg); in kvm_vcpu_ioctl_enable_cap()
1953 r = -EBADF; in kvm_vcpu_ioctl_enable_cap()
1954 f = fdget(cap->args[0]); in kvm_vcpu_ioctl_enable_cap()
1958 r = -EPERM; in kvm_vcpu_ioctl_enable_cap()
1961 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]); in kvm_vcpu_ioctl_enable_cap()
1972 r = -EBADF; in kvm_vcpu_ioctl_enable_cap()
1973 f = fdget(cap->args[0]); in kvm_vcpu_ioctl_enable_cap()
1977 r = -EPERM; in kvm_vcpu_ioctl_enable_cap()
1981 r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]); in kvm_vcpu_ioctl_enable_cap()
1983 r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]); in kvm_vcpu_ioctl_enable_cap()
1995 r = -EBADF; in kvm_vcpu_ioctl_enable_cap()
1996 f = fdget(cap->args[0]); in kvm_vcpu_ioctl_enable_cap()
2000 r = -ENXIO; in kvm_vcpu_ioctl_enable_cap()
2004 r = -EPERM; in kvm_vcpu_ioctl_enable_cap()
2008 cap->args[1]); in kvm_vcpu_ioctl_enable_cap()
2016 r = -EINVAL; in kvm_vcpu_ioctl_enable_cap()
2017 if (!is_kvmppc_hv_enabled(vcpu->kvm)) in kvm_vcpu_ioctl_enable_cap()
2020 vcpu->kvm->arch.fwnmi_enabled = true; in kvm_vcpu_ioctl_enable_cap()
2024 r = -EINVAL; in kvm_vcpu_ioctl_enable_cap()
2037 if (kvm->arch.mpic) in kvm_arch_intc_initialized()
2041 if (kvm->arch.xics || kvm->arch.xive) in kvm_arch_intc_initialized()
2050 return -EINVAL; in kvm_arch_vcpu_ioctl_get_mpstate()
2056 return -EINVAL; in kvm_arch_vcpu_ioctl_set_mpstate()
2062 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_async_ioctl()
2068 return -EFAULT; in kvm_arch_vcpu_async_ioctl()
2071 return -ENOIOCTLCMD; in kvm_arch_vcpu_async_ioctl()
2077 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_ioctl()
2085 r = -EFAULT; in kvm_arch_vcpu_ioctl()
2098 r = -EFAULT; in kvm_arch_vcpu_ioctl()
2111 r = -EFAULT; in kvm_arch_vcpu_ioctl()
2121 r = -EINVAL; in kvm_arch_vcpu_ioctl()
2138 pvinfo->hcall[0] = cpu_to_be32(inst_sc1); in kvm_vm_ioctl_get_pvinfo()
2139 pvinfo->hcall[1] = cpu_to_be32(inst_nop); in kvm_vm_ioctl_get_pvinfo()
2140 pvinfo->hcall[2] = cpu_to_be32(inst_nop); in kvm_vm_ioctl_get_pvinfo()
2141 pvinfo->hcall[3] = cpu_to_be32(inst_nop); in kvm_vm_ioctl_get_pvinfo()
2157 pvinfo->hcall[0] = cpu_to_be32(inst_lis | ((KVM_SC_MAGIC_R0 >> 16) & inst_imm_mask)); in kvm_vm_ioctl_get_pvinfo()
2158 pvinfo->hcall[1] = cpu_to_be32(inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask)); in kvm_vm_ioctl_get_pvinfo()
2159 pvinfo->hcall[2] = cpu_to_be32(inst_sc); in kvm_vm_ioctl_get_pvinfo()
2160 pvinfo->hcall[3] = cpu_to_be32(inst_nop); in kvm_vm_ioctl_get_pvinfo()
2163 pvinfo->flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE; in kvm_vm_ioctl_get_pvinfo()
2172 return -ENXIO; in kvm_vm_ioctl_irq_line()
2174 irq_event->status = kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, in kvm_vm_ioctl_irq_line()
2175 irq_event->irq, irq_event->level, in kvm_vm_ioctl_irq_line()
2186 if (cap->flags) in kvm_vm_ioctl_enable_cap()
2187 return -EINVAL; in kvm_vm_ioctl_enable_cap()
2189 switch (cap->cap) { in kvm_vm_ioctl_enable_cap()
2192 unsigned long hcall = cap->args[0]; in kvm_vm_ioctl_enable_cap()
2194 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2196 cap->args[1] > 1) in kvm_vm_ioctl_enable_cap()
2200 if (cap->args[1]) in kvm_vm_ioctl_enable_cap()
2201 set_bit(hcall / 4, kvm->arch.enabled_hcalls); in kvm_vm_ioctl_enable_cap()
2203 clear_bit(hcall / 4, kvm->arch.enabled_hcalls); in kvm_vm_ioctl_enable_cap()
2208 unsigned long mode = cap->args[0]; in kvm_vm_ioctl_enable_cap()
2209 unsigned long flags = cap->args[1]; in kvm_vm_ioctl_enable_cap()
2211 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2212 if (kvm->arch.kvm_ops->set_smt_mode) in kvm_vm_ioctl_enable_cap()
2213 r = kvm->arch.kvm_ops->set_smt_mode(kvm, mode, flags); in kvm_vm_ioctl_enable_cap()
2218 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2220 !kvm->arch.kvm_ops->enable_nested) in kvm_vm_ioctl_enable_cap()
2222 r = kvm->arch.kvm_ops->enable_nested(kvm); in kvm_vm_ioctl_enable_cap()
2227 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2228 if (!is_kvmppc_hv_enabled(kvm) || !kvm->arch.kvm_ops->enable_svm) in kvm_vm_ioctl_enable_cap()
2230 r = kvm->arch.kvm_ops->enable_svm(kvm); in kvm_vm_ioctl_enable_cap()
2233 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2234 if (!is_kvmppc_hv_enabled(kvm) || !kvm->arch.kvm_ops->enable_dawr1) in kvm_vm_ioctl_enable_cap()
2236 r = kvm->arch.kvm_ops->enable_dawr1(kvm); in kvm_vm_ioctl_enable_cap()
2240 r = -EINVAL; in kvm_vm_ioctl_enable_cap()
2263 return -ENOTTY; in pseries_get_cpu_char()
2267 cp->character = c.character; in pseries_get_cpu_char()
2268 cp->behaviour = c.behaviour; in pseries_get_cpu_char()
2269 cp->character_mask = KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31 | in pseries_get_cpu_char()
2278 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY | in pseries_get_cpu_char()
2288 return -ENOTTY; in pseries_get_cpu_char()
2313 if (r != -ENOTTY) in kvmppc_get_cpu_char()
2318 fw_features = of_get_child_by_name(np, "fw-features"); in kvmppc_get_cpu_char()
2323 "inst-spec-barrier-ori31,31,0")) in kvmppc_get_cpu_char()
2324 cp->character |= KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31; in kvmppc_get_cpu_char()
2326 "fw-bcctrl-serialized")) in kvmppc_get_cpu_char()
2327 cp->character |= KVM_PPC_CPU_CHAR_BCCTRL_SERIALISED; in kvmppc_get_cpu_char()
2329 "inst-l1d-flush-ori30,30,0")) in kvmppc_get_cpu_char()
2330 cp->character |= KVM_PPC_CPU_CHAR_L1D_FLUSH_ORI30; in kvmppc_get_cpu_char()
2332 "inst-l1d-flush-trig2")) in kvmppc_get_cpu_char()
2333 cp->character |= KVM_PPC_CPU_CHAR_L1D_FLUSH_TRIG2; in kvmppc_get_cpu_char()
2335 "fw-l1d-thread-split")) in kvmppc_get_cpu_char()
2336 cp->character |= KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV; in kvmppc_get_cpu_char()
2338 "fw-count-cache-disabled")) in kvmppc_get_cpu_char()
2339 cp->character |= KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS; in kvmppc_get_cpu_char()
2341 "fw-count-cache-flush-bcctr2,0,0")) in kvmppc_get_cpu_char()
2342 cp->character |= KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST; in kvmppc_get_cpu_char()
2343 cp->character_mask = KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31 | in kvmppc_get_cpu_char()
2352 "speculation-policy-favor-security")) in kvmppc_get_cpu_char()
2353 cp->behaviour |= KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY; in kvmppc_get_cpu_char()
2355 "needs-l1d-flush-msr-pr-0-to-1")) in kvmppc_get_cpu_char()
2356 cp->behaviour |= KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR; in kvmppc_get_cpu_char()
2358 "needs-spec-barrier-for-bound-checks")) in kvmppc_get_cpu_char()
2359 cp->behaviour |= KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR; in kvmppc_get_cpu_char()
2361 "needs-count-cache-flush-on-context-switch")) in kvmppc_get_cpu_char()
2362 cp->behaviour |= KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE; in kvmppc_get_cpu_char()
2363 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY | in kvmppc_get_cpu_char()
2378 struct kvm *kvm __maybe_unused = filp->private_data; in kvm_arch_vm_ioctl()
2388 r = -EFAULT; in kvm_arch_vm_ioctl()
2398 r = -EFAULT; in kvm_arch_vm_ioctl()
2402 r = -EINVAL; in kvm_arch_vm_ioctl()
2412 r = -EFAULT; in kvm_arch_vm_ioctl()
2429 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2432 r = kvm->arch.kvm_ops->get_smmu_info(kvm, &info); in kvm_arch_vm_ioctl()
2434 r = -EFAULT; in kvm_arch_vm_ioctl()
2438 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2444 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2445 struct kvm_ppc_mmuv3_cfg cfg; in kvm_arch_vm_ioctl() local
2447 r = -EINVAL; in kvm_arch_vm_ioctl()
2448 if (!kvm->arch.kvm_ops->configure_mmu) in kvm_arch_vm_ioctl()
2450 r = -EFAULT; in kvm_arch_vm_ioctl()
2451 if (copy_from_user(&cfg, argp, sizeof(cfg))) in kvm_arch_vm_ioctl()
2453 r = kvm->arch.kvm_ops->configure_mmu(kvm, &cfg); in kvm_arch_vm_ioctl()
2457 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2460 r = -EINVAL; in kvm_arch_vm_ioctl()
2461 if (!kvm->arch.kvm_ops->get_rmmu_info) in kvm_arch_vm_ioctl()
2463 r = kvm->arch.kvm_ops->get_rmmu_info(kvm, &info); in kvm_arch_vm_ioctl()
2465 r = -EFAULT; in kvm_arch_vm_ioctl()
2473 r = -EFAULT; in kvm_arch_vm_ioctl()
2477 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2480 if (!kvm->arch.kvm_ops->svm_off) in kvm_arch_vm_ioctl()
2483 r = kvm->arch.kvm_ops->svm_off(kvm); in kvm_arch_vm_ioctl()
2487 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl()
2488 r = kvm->arch.kvm_ops->arch_vm_ioctl(filp, ioctl, arg); in kvm_arch_vm_ioctl()
2492 r = -ENOTTY; in kvm_arch_vm_ioctl()
2507 lpid = ida_alloc_range(&lpid_inuse, 1, nr_lpids - 1, GFP_KERNEL); in kvmppc_alloc_lpid()
2509 if (lpid == -ENOMEM) in kvmppc_alloc_lpid()
2513 return -ENOMEM; in kvmppc_alloc_lpid()
2542 if (vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs) in kvm_arch_create_vcpu_debugfs()
2543 vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs(vcpu, debugfs_dentry); in kvm_arch_create_vcpu_debugfs()
2548 if (kvm->arch.kvm_ops->create_vm_debugfs) in kvm_arch_create_vm_debugfs()
2549 kvm->arch.kvm_ops->create_vm_debugfs(kvm); in kvm_arch_create_vm_debugfs()