Lines Matching +full:gpa +full:- +full:0

8  * See the COPYING file in the top-level directory.
14 #include "qemu/main-loop.h"
15 #include "qemu/error-report.h"
20 #include "exec/address-spaces.h"
21 #include "xen-emu.h"
26 #include "hw/i386/apic-msidef.h"
43 #include "xen-compat.h"
55 static bool kvm_gva_to_gpa(CPUState *cs, uint64_t gva, uint64_t *gpa, in kvm_gva_to_gpa() argument
63 *len = TARGET_PAGE_SIZE - (gva & ~TARGET_PAGE_MASK); in kvm_gva_to_gpa()
70 *gpa = tr.physical_address; in kvm_gva_to_gpa()
78 uint64_t gpa; in kvm_gva_rw() local
82 if (!kvm_gva_to_gpa(cs, gva, &gpa, &len, is_write)) { in kvm_gva_rw()
83 return -EFAULT; in kvm_gva_rw()
89 cpu_physical_memory_rw(gpa, buf, len, is_write); in kvm_gva_rw()
92 sz -= len; in kvm_gva_rw()
96 return 0; in kvm_gva_rw()
124 return -ENOSYS; in kvm_xen_init()
130 .u.xen_version = s->xen_version, in kvm_xen_init()
138 if (ret < 0) { in kvm_xen_init()
140 strerror(-ret)); in kvm_xen_init()
145 if (s->xen_caps) { in kvm_xen_init()
146 return 0; in kvm_xen_init()
151 * of vCPU0 to deassert the IRQ when ->evtchn_upcall_pending is cleared. in kvm_xen_init()
155 * it nicely in the kernel: check vcpu_info[0]->evtchn_upcall_pending at in kvm_xen_init()
158 * But the in-kernel irqchip is deprecated, so we're unlikely to add in kvm_xen_init()
172 error_report("kvm: Xen support requires kernel-irqchip=split"); in kvm_xen_init()
173 return -EINVAL; in kvm_xen_init()
176 s->xen_caps = xen_caps; in kvm_xen_init()
185 return 0; in kvm_xen_init()
191 CPUX86State *env = &cpu->env; in kvm_xen_init_vcpu()
205 .u.vcpu_id = cs->cpu_index, in kvm_xen_init_vcpu()
210 strerror(-err)); in kvm_xen_init_vcpu()
215 env->xen_vcpu_info_gpa = INVALID_GPA; in kvm_xen_init_vcpu()
216 env->xen_vcpu_info_default_gpa = INVALID_GPA; in kvm_xen_init_vcpu()
217 env->xen_vcpu_time_info_gpa = INVALID_GPA; in kvm_xen_init_vcpu()
218 env->xen_vcpu_runstate_gpa = INVALID_GPA; in kvm_xen_init_vcpu()
220 qemu_mutex_init(&env->xen_timers_lock); in kvm_xen_init_vcpu()
221 env->xen_singleshot_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, in kvm_xen_init_vcpu()
224 if (!env->xen_singleshot_timer) { in kvm_xen_init_vcpu()
225 return -ENOMEM; in kvm_xen_init_vcpu()
227 env->xen_singleshot_timer->opaque = cs; in kvm_xen_init_vcpu()
229 env->xen_periodic_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, in kvm_xen_init_vcpu()
232 if (!env->xen_periodic_timer) { in kvm_xen_init_vcpu()
233 return -ENOMEM; in kvm_xen_init_vcpu()
235 env->xen_periodic_timer->opaque = cs; in kvm_xen_init_vcpu()
237 return 0; in kvm_xen_init_vcpu()
242 return kvm_state->xen_caps; in kvm_xen_get_caps()
248 int err = 0; in kvm_xen_hcall_xen_version()
262 fi.submap = 0; in kvm_xen_hcall_xen_version()
263 if (fi.submap_idx == 0) { in kvm_xen_hcall_xen_version()
280 exit->u.hcall.result = err; in kvm_xen_hcall_xen_version()
284 static int kvm_xen_set_vcpu_attr(CPUState *cs, uint16_t type, uint64_t gpa) in kvm_xen_set_vcpu_attr() argument
289 xhsi.u.gpa = gpa; in kvm_xen_set_vcpu_attr()
291 trace_kvm_xen_set_vcpu_attr(cs->cpu_index, type, gpa); in kvm_xen_set_vcpu_attr()
298 uint8_t vector = X86_CPU(cs)->env.xen_vcpu_callback_vector; in kvm_xen_set_vcpu_callback_vector()
304 trace_kvm_xen_set_vcpu_callback(cs->cpu_index, vector); in kvm_xen_set_vcpu_callback_vector()
312 CPUX86State *env = &cpu->env; in do_set_vcpu_callback_vector()
314 env->xen_vcpu_callback_vector = data.host_int; in do_set_vcpu_callback_vector()
321 static int set_vcpu_info(CPUState *cs, uint64_t gpa) in set_vcpu_info() argument
324 CPUX86State *env = &cpu->env; in set_vcpu_info()
329 ret = kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO, gpa); in set_vcpu_info()
330 if (ret || gpa == INVALID_GPA) { in set_vcpu_info()
334 mrs = memory_region_find(get_system_memory(), gpa, in set_vcpu_info()
336 if (mrs.mr && mrs.mr->ram_block && in set_vcpu_info()
338 vcpu_info_hva = qemu_map_ram_ptr(mrs.mr->ram_block, in set_vcpu_info()
346 ret = -EINVAL; in set_vcpu_info()
350 if (env->xen_vcpu_info_mr) { in set_vcpu_info()
351 memory_region_unref(env->xen_vcpu_info_mr); in set_vcpu_info()
353 env->xen_vcpu_info_hva = vcpu_info_hva; in set_vcpu_info()
354 env->xen_vcpu_info_mr = mrs.mr; in set_vcpu_info()
361 CPUX86State *env = &cpu->env; in do_set_vcpu_info_default_gpa()
363 env->xen_vcpu_info_default_gpa = data.host_ulong; in do_set_vcpu_info_default_gpa()
366 if (env->xen_vcpu_info_gpa == INVALID_GPA) { in do_set_vcpu_info_default_gpa()
367 set_vcpu_info(cs, env->xen_vcpu_info_default_gpa); in do_set_vcpu_info_default_gpa()
374 CPUX86State *env = &cpu->env; in do_set_vcpu_info_gpa()
376 env->xen_vcpu_info_gpa = data.host_ulong; in do_set_vcpu_info_gpa()
378 set_vcpu_info(cs, env->xen_vcpu_info_gpa); in do_set_vcpu_info_gpa()
388 return X86_CPU(cs)->env.xen_vcpu_info_hva; in kvm_xen_get_vcpu_info_hva()
393 CPUX86State *env = &X86_CPU(cs)->env; in kvm_xen_maybe_deassert_callback()
394 struct vcpu_info *vi = env->xen_vcpu_info_hva; in kvm_xen_maybe_deassert_callback()
400 if (!vi->evtchn_upcall_pending) { in kvm_xen_maybe_deassert_callback()
407 if (!vi->evtchn_upcall_pending) { in kvm_xen_maybe_deassert_callback()
408 X86_CPU(cs)->env.xen_callback_asserted = false; in kvm_xen_maybe_deassert_callback()
409 xen_evtchn_set_callback_level(0); in kvm_xen_maybe_deassert_callback()
417 CPUState *cs = qemu_get_cpu(0); in kvm_xen_set_callback_asserted()
420 X86_CPU(cs)->env.xen_callback_asserted = true; in kvm_xen_set_callback_asserted()
426 CPUState *cs = qemu_get_cpu(0); in kvm_xen_has_vcpu_callback_vector()
428 return cs && !!X86_CPU(cs)->env.xen_vcpu_callback_vector; in kvm_xen_has_vcpu_callback_vector()
440 vector = X86_CPU(cs)->env.xen_vcpu_callback_vector; in kvm_xen_inject_vcpu_callback_vector()
443 * The per-vCPU callback vector injected via lapic. Just in kvm_xen_inject_vcpu_callback_vector()
448 (X86_CPU(cs)->apic_id << MSI_ADDR_DEST_ID_SHIFT), in kvm_xen_inject_vcpu_callback_vector()
467 if (vcpu_id == 0) { in kvm_xen_inject_vcpu_callback_vector()
478 CPUX86State *env = &cpu->env; in kvm_xen_set_vcpu_timer()
482 .u.timer.port = env->xen_virq[VIRQ_TIMER], in kvm_xen_set_vcpu_timer()
484 .u.timer.expires_ns = env->xen_singleshot_timer_ns, in kvm_xen_set_vcpu_timer()
492 QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); in do_set_vcpu_timer_virq()
501 return -ENOENT; in kvm_xen_set_vcpu_virq()
508 return -EINVAL; in kvm_xen_set_vcpu_virq()
511 if (port && X86_CPU(cs)->env.xen_virq[virq]) { in kvm_xen_set_vcpu_virq()
512 return -EEXIST; in kvm_xen_set_vcpu_virq()
515 X86_CPU(cs)->env.xen_virq[virq] = port; in kvm_xen_set_vcpu_virq()
520 return 0; in kvm_xen_set_vcpu_virq()
526 CPUX86State *env = &cpu->env; in do_set_vcpu_time_info_gpa()
528 env->xen_vcpu_time_info_gpa = data.host_ulong; in do_set_vcpu_time_info_gpa()
531 env->xen_vcpu_time_info_gpa); in do_set_vcpu_time_info_gpa()
537 CPUX86State *env = &cpu->env; in do_set_vcpu_runstate_gpa()
539 env->xen_vcpu_runstate_gpa = data.host_ulong; in do_set_vcpu_runstate_gpa()
542 env->xen_vcpu_runstate_gpa); in do_set_vcpu_runstate_gpa()
548 CPUX86State *env = &cpu->env; in do_vcpu_soft_reset()
550 env->xen_vcpu_info_gpa = INVALID_GPA; in do_vcpu_soft_reset()
551 env->xen_vcpu_info_default_gpa = INVALID_GPA; in do_vcpu_soft_reset()
552 env->xen_vcpu_time_info_gpa = INVALID_GPA; in do_vcpu_soft_reset()
553 env->xen_vcpu_runstate_gpa = INVALID_GPA; in do_vcpu_soft_reset()
554 env->xen_vcpu_callback_vector = 0; in do_vcpu_soft_reset()
555 memset(env->xen_virq, 0, sizeof(env->xen_virq)); in do_vcpu_soft_reset()
565 QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); in do_vcpu_soft_reset()
566 env->xen_singleshot_timer_ns = 0; in do_vcpu_soft_reset()
576 uint64_t gpa = gfn << TARGET_PAGE_BITS; in xen_set_shared_info() local
585 * KVM-specific. in xen_set_shared_info()
587 err = xen_overlay_map_shinfo_page(gpa); in xen_set_shared_info()
594 for (i = 0; i < XEN_LEGACY_MAX_VCPUS; i++) { in xen_set_shared_info()
598 RUN_ON_CPU_HOST_ULONG(gpa)); in xen_set_shared_info()
600 gpa += sizeof(vcpu_info_t); in xen_set_shared_info()
610 if (idx > 0) { in add_to_physmap_one()
611 return -EINVAL; in add_to_physmap_one()
620 return -ENOTSUP; in add_to_physmap_one()
624 return -EPERM; in add_to_physmap_one()
627 return -EINVAL; in add_to_physmap_one()
637 if (hypercall_compat32(exit->u.hcall.longmode)) { in do_add_to_physmap()
642 return -EFAULT; in do_add_to_physmap()
651 return -EFAULT; in do_add_to_physmap()
656 return -ESRCH; in do_add_to_physmap()
670 if (hypercall_compat32(exit->u.hcall.longmode)) { in do_add_to_physmap_batch()
675 return -EFAULT; in do_add_to_physmap_batch()
687 return -EFAULT; in do_add_to_physmap_batch()
696 return -ESRCH; in do_add_to_physmap_batch()
701 return -EINVAL; in do_add_to_physmap_batch()
704 while (xatpb.size--) { in do_add_to_physmap_batch()
705 unsigned long idx = 0; in do_add_to_physmap_batch()
706 unsigned long gpfn = 0; in do_add_to_physmap_batch()
709 /* For 32-bit compat this only copies the low 32 bits of each */ in do_add_to_physmap_batch()
712 return -EFAULT; in do_add_to_physmap_batch()
720 return -EFAULT; in do_add_to_physmap_batch()
724 return 0; in do_add_to_physmap_batch()
745 exit->u.hcall.result = err; in kvm_xen_hcall_memory_op()
754 int err = 0; in handle_set_param()
760 err = -EFAULT; in handle_set_param()
765 err = -ESRCH; in handle_set_param()
774 xen_set_long_mode(exit->u.hcall.longmode); in handle_set_param()
781 exit->u.hcall.result = err; in handle_set_param()
790 int err = 0; in handle_get_param()
796 err = -EFAULT; in handle_get_param()
801 err = -ESRCH; in handle_get_param()
815 err = -EINVAL; in handle_get_param()
821 err = -EINVAL; in handle_get_param()
829 err = -EFAULT; in handle_get_param()
832 exit->u.hcall.result = err; in handle_get_param()
846 return -EFAULT; in kvm_xen_hcall_evtchn_upcall_vector()
849 if (up.vector < 0x10) { in kvm_xen_hcall_evtchn_upcall_vector()
850 return -EINVAL; in kvm_xen_hcall_evtchn_upcall_vector()
855 return -EINVAL; in kvm_xen_hcall_evtchn_upcall_vector()
860 return 0; in kvm_xen_hcall_evtchn_upcall_vector()
866 int ret = -ENOSYS; in kvm_xen_hcall_hvm_op()
873 ret = -ENOSYS; in kvm_xen_hcall_hvm_op()
886 exit->u.hcall.result = ret; in kvm_xen_hcall_hvm_op()
894 uint64_t gpa; in vcpuop_register_vcpu_info() local
901 return -ENOENT; in vcpuop_register_vcpu_info()
905 return -EFAULT; in vcpuop_register_vcpu_info()
908 if (rvi.offset > TARGET_PAGE_SIZE - sizeof(struct vcpu_info)) { in vcpuop_register_vcpu_info()
909 return -EINVAL; in vcpuop_register_vcpu_info()
912 gpa = ((rvi.mfn << TARGET_PAGE_BITS) + rvi.offset); in vcpuop_register_vcpu_info()
913 async_run_on_cpu(target, do_set_vcpu_info_gpa, RUN_ON_CPU_HOST_ULONG(gpa)); in vcpuop_register_vcpu_info()
914 return 0; in vcpuop_register_vcpu_info()
921 uint64_t gpa; in vcpuop_register_vcpu_time_info() local
929 return -ENOENT; in vcpuop_register_vcpu_time_info()
933 return -EFAULT; in vcpuop_register_vcpu_time_info()
938 * page tables each time. But Linux/KVM uses the GPA, on the assumption in vcpuop_register_vcpu_time_info()
940 * for it. If Linux is changed to redo the GVA→GPA translation each time, in vcpuop_register_vcpu_time_info()
943 if (!kvm_gva_to_gpa(cs, tma.addr.p, &gpa, &len, false) || in vcpuop_register_vcpu_time_info()
945 return -EFAULT; in vcpuop_register_vcpu_time_info()
949 RUN_ON_CPU_HOST_ULONG(gpa)); in vcpuop_register_vcpu_time_info()
950 return 0; in vcpuop_register_vcpu_time_info()
957 uint64_t gpa; in vcpuop_register_runstate_info() local
965 return -ENOENT; in vcpuop_register_runstate_info()
969 return -EFAULT; in vcpuop_register_runstate_info()
973 if (!kvm_gva_to_gpa(cs, rma.addr.p, &gpa, &len, false)) { in vcpuop_register_runstate_info()
974 return -EFAULT; in vcpuop_register_runstate_info()
978 RUN_ON_CPU_HOST_ULONG(gpa)); in vcpuop_register_runstate_info()
979 return 0; in vcpuop_register_runstate_info()
988 if (ret < 0) { in kvm_get_current_ns()
999 CPUX86State *env = &X86_CPU(cpu)->env; in xen_vcpu_singleshot_timer_event()
1000 uint16_t port = env->xen_virq[VIRQ_TIMER]; in xen_vcpu_singleshot_timer_event()
1006 qemu_mutex_lock(&env->xen_timers_lock); in xen_vcpu_singleshot_timer_event()
1007 env->xen_singleshot_timer_ns = 0; in xen_vcpu_singleshot_timer_event()
1008 qemu_mutex_unlock(&env->xen_timers_lock); in xen_vcpu_singleshot_timer_event()
1014 CPUX86State *env = &X86_CPU(cpu)->env; in xen_vcpu_periodic_timer_event()
1015 uint16_t port = env->xen_virq[VIRQ_TIMER]; in xen_vcpu_periodic_timer_event()
1022 qemu_mutex_lock(&env->xen_timers_lock); in xen_vcpu_periodic_timer_event()
1025 timer_mod_ns(env->xen_periodic_timer, in xen_vcpu_periodic_timer_event()
1026 qemu_now + env->xen_periodic_timer_period); in xen_vcpu_periodic_timer_event()
1028 qemu_mutex_unlock(&env->xen_timers_lock); in xen_vcpu_periodic_timer_event()
1033 CPUX86State *tenv = &X86_CPU(target)->env; in do_set_periodic_timer()
1036 timer_del(tenv->xen_periodic_timer); in do_set_periodic_timer()
1038 qemu_mutex_lock(&tenv->xen_timers_lock); in do_set_periodic_timer()
1041 timer_mod_ns(tenv->xen_periodic_timer, qemu_now + period_ns); in do_set_periodic_timer()
1042 tenv->xen_periodic_timer_period = period_ns; in do_set_periodic_timer()
1044 qemu_mutex_unlock(&tenv->xen_timers_lock); in do_set_periodic_timer()
1045 return 0; in do_set_periodic_timer()
1050 #define STIME_MAX ((time_t)((int64_t)~0ull >> 1))
1052 #define STIME_DELTA_MAX ((int64_t)((uint64_t)~0ull >> 2))
1061 return -EFAULT; in vcpuop_set_periodic_timer()
1065 return -EINVAL; in vcpuop_set_periodic_timer()
1073 CPUX86State *tenv = &X86_CPU(target)->env; in vcpuop_stop_periodic_timer()
1075 qemu_mutex_lock(&tenv->xen_timers_lock); in vcpuop_stop_periodic_timer()
1077 timer_del(tenv->xen_periodic_timer); in vcpuop_stop_periodic_timer()
1078 tenv->xen_periodic_timer_period = 0; in vcpuop_stop_periodic_timer()
1080 qemu_mutex_unlock(&tenv->xen_timers_lock); in vcpuop_stop_periodic_timer()
1081 return 0; in vcpuop_stop_periodic_timer()
1091 CPUX86State *env = &X86_CPU(cs)->env; in do_set_singleshot_timer()
1094 int64_t delta = timeout_abs - now; in do_set_singleshot_timer()
1096 if (linux_wa && unlikely((int64_t)timeout_abs < 0 || in do_set_singleshot_timer()
1097 (delta > 0 && (uint32_t)(delta >> 50) != 0))) { in do_set_singleshot_timer()
1111 timer_mod_ns(env->xen_singleshot_timer, qemu_now + delta); in do_set_singleshot_timer()
1112 env->xen_singleshot_timer_ns = now + delta; in do_set_singleshot_timer()
1113 return 0; in do_set_singleshot_timer()
1118 struct vcpu_set_singleshot_timer sst = { 0 }; in vcpuop_set_singleshot_timer()
1121 * The struct is a uint64_t followed by a uint32_t. On 32-bit that in vcpuop_set_singleshot_timer()
1122 * makes it 12 bytes. On 64-bit it gets padded to 16. The parts in vcpuop_set_singleshot_timer()
1125 * to copy the full 16 bytes from 64-bit guests, and return -EFAULT in vcpuop_set_singleshot_timer()
1133 return -EFAULT; in vcpuop_set_singleshot_timer()
1136 QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); in vcpuop_set_singleshot_timer()
1148 CPUX86State *env = &X86_CPU(cs)->env; in vcpuop_stop_singleshot_timer()
1150 qemu_mutex_lock(&env->xen_timers_lock); in vcpuop_stop_singleshot_timer()
1152 timer_del(env->xen_singleshot_timer); in vcpuop_stop_singleshot_timer()
1153 env->xen_singleshot_timer_ns = 0; in vcpuop_stop_singleshot_timer()
1155 qemu_mutex_unlock(&env->xen_timers_lock); in vcpuop_stop_singleshot_timer()
1156 return 0; in vcpuop_stop_singleshot_timer()
1164 if (unlikely(timeout == 0)) { in kvm_xen_hcall_set_timer_op()
1167 QEMU_LOCK_GUARD(&X86_CPU(cpu)->env.xen_timers_lock); in kvm_xen_hcall_set_timer_op()
1170 exit->u.hcall.result = err; in kvm_xen_hcall_set_timer_op()
1178 CPUState *dest = cs->cpu_index == vcpu_id ? cs : qemu_get_cpu(vcpu_id); in kvm_xen_hcall_vcpu_op()
1182 err = -ENOENT; in kvm_xen_hcall_vcpu_op()
1197 if (cs->cpu_index == vcpu_id) { in kvm_xen_hcall_vcpu_op()
1200 err = -EINVAL; in kvm_xen_hcall_vcpu_op()
1205 if (cs->cpu_index == vcpu_id) { in kvm_xen_hcall_vcpu_op()
1208 err = -EINVAL; in kvm_xen_hcall_vcpu_op()
1224 exit->u.hcall.result = err; in kvm_xen_hcall_vcpu_op()
1232 int err = -ENOSYS; in kvm_xen_hcall_evtchn_op()
1239 err = -ENOSYS; in kvm_xen_hcall_evtchn_op()
1247 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1253 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1262 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1274 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1286 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1292 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1301 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1307 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1316 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1322 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1331 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1343 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1349 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1358 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1365 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1374 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1386 err = -EFAULT; in kvm_xen_hcall_evtchn_op()
1397 exit->u.hcall.result = err; in kvm_xen_hcall_evtchn_op()
1417 * it maps to HVM_PARAM_CALLBACK_TYPE_GSI with GSI#0, but Xen refuses to in kvm_xen_soft_reset()
1420 err = xen_evtchn_set_callback_param(0); in kvm_xen_soft_reset()
1449 return 0; in kvm_xen_soft_reset()
1455 int ret = 0; in schedop_shutdown()
1461 return -EFAULT; in schedop_shutdown()
1485 ret = -EINVAL; in schedop_shutdown()
1496 int err = -ENOSYS; in kvm_xen_hcall_sched_op()
1513 err = 0; in kvm_xen_hcall_sched_op()
1520 exit->u.hcall.result = err; in kvm_xen_hcall_sched_op()
1536 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1542 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1551 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1557 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1566 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1572 err = -EFAULT; in kvm_xen_hcall_gnttab_op()
1584 /* Xen explicitly returns -ENOSYS to HVM guests for all others */ in kvm_xen_hcall_gnttab_op()
1585 err = -ENOSYS; in kvm_xen_hcall_gnttab_op()
1589 exit->u.hcall.result = err; in kvm_xen_hcall_gnttab_op()
1603 if (hypercall_compat32(exit->u.hcall.longmode)) { in kvm_xen_hcall_physdev_op()
1607 return -EFAULT; in kvm_xen_hcall_physdev_op()
1613 * it 64-bit aligned in the 64-bit version. in kvm_xen_hcall_physdev_op()
1618 memmove(&map.table_base, &map32->table_base, sizeof(map.table_base)); in kvm_xen_hcall_physdev_op()
1621 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1632 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1641 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1647 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1656 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1662 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1671 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1677 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1686 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1692 err = -EFAULT; in kvm_xen_hcall_physdev_op()
1697 err = -ENOSYS; in kvm_xen_hcall_physdev_op()
1704 exit->u.hcall.result = err; in kvm_xen_hcall_physdev_op()
1710 uint16_t code = exit->u.hcall.input; in do_kvm_xen_handle_exit()
1712 if (exit->u.hcall.cpl > 0) { in do_kvm_xen_handle_exit()
1713 exit->u.hcall.result = -EPERM; in do_kvm_xen_handle_exit()
1719 if (exit->u.hcall.longmode) { in do_kvm_xen_handle_exit()
1721 exit->u.hcall.params[0]); in do_kvm_xen_handle_exit()
1723 /* In 32-bit mode, the 64-bit timer value is in two args. */ in do_kvm_xen_handle_exit()
1724 uint64_t val = ((uint64_t)exit->u.hcall.params[1]) << 32 | in do_kvm_xen_handle_exit()
1725 (uint32_t)exit->u.hcall.params[0]; in do_kvm_xen_handle_exit()
1729 return kvm_xen_hcall_gnttab_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1730 exit->u.hcall.params[1], in do_kvm_xen_handle_exit()
1731 exit->u.hcall.params[2]); in do_kvm_xen_handle_exit()
1733 return kvm_xen_hcall_sched_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1734 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1736 return kvm_xen_hcall_evtchn_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1737 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1740 exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1741 exit->u.hcall.params[1], in do_kvm_xen_handle_exit()
1742 exit->u.hcall.params[2]); in do_kvm_xen_handle_exit()
1744 return kvm_xen_hcall_hvm_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1745 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1747 return kvm_xen_hcall_memory_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1748 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1750 return kvm_xen_hcall_physdev_op(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1751 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1753 return kvm_xen_hcall_xen_version(exit, cpu, exit->u.hcall.params[0], in do_kvm_xen_handle_exit()
1754 exit->u.hcall.params[1]); in do_kvm_xen_handle_exit()
1762 if (exit->type != KVM_EXIT_XEN_HCALL) { in kvm_xen_handle_exit()
1763 return -1; in kvm_xen_handle_exit()
1772 if (exit->u.hcall.longmode != xen_is_long_mode()) { in kvm_xen_handle_exit()
1779 * -ENOSYS. This case is for hypercalls which are unexpected. in kvm_xen_handle_exit()
1781 exit->u.hcall.result = -ENOSYS; in kvm_xen_handle_exit()
1783 PRId64 " (0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 ")\n", in kvm_xen_handle_exit()
1784 (uint64_t)exit->u.hcall.input, in kvm_xen_handle_exit()
1785 (uint64_t)exit->u.hcall.params[0], in kvm_xen_handle_exit()
1786 (uint64_t)exit->u.hcall.params[1], in kvm_xen_handle_exit()
1787 (uint64_t)exit->u.hcall.params[2]); in kvm_xen_handle_exit()
1790 trace_kvm_xen_hypercall(CPU(cpu)->cpu_index, exit->u.hcall.cpl, in kvm_xen_handle_exit()
1791 exit->u.hcall.input, exit->u.hcall.params[0], in kvm_xen_handle_exit()
1792 exit->u.hcall.params[1], exit->u.hcall.params[2], in kvm_xen_handle_exit()
1793 exit->u.hcall.result); in kvm_xen_handle_exit()
1794 return 0; in kvm_xen_handle_exit()
1800 return s->xen_gnttab_max_frames; in kvm_xen_get_gnttab_max_frames()
1806 return s->xen_evtchn_max_pirq; in kvm_xen_get_evtchn_max_pirq()
1812 CPUX86State *env = &cpu->env; in kvm_put_xen_state()
1813 uint64_t gpa; in kvm_put_xen_state() local
1816 gpa = env->xen_vcpu_info_gpa; in kvm_put_xen_state()
1817 if (gpa == INVALID_GPA) { in kvm_put_xen_state()
1818 gpa = env->xen_vcpu_info_default_gpa; in kvm_put_xen_state()
1821 if (gpa != INVALID_GPA) { in kvm_put_xen_state()
1822 ret = set_vcpu_info(cs, gpa); in kvm_put_xen_state()
1823 if (ret < 0) { in kvm_put_xen_state()
1828 gpa = env->xen_vcpu_time_info_gpa; in kvm_put_xen_state()
1829 if (gpa != INVALID_GPA) { in kvm_put_xen_state()
1831 gpa); in kvm_put_xen_state()
1832 if (ret < 0) { in kvm_put_xen_state()
1837 gpa = env->xen_vcpu_runstate_gpa; in kvm_put_xen_state()
1838 if (gpa != INVALID_GPA) { in kvm_put_xen_state()
1840 gpa); in kvm_put_xen_state()
1841 if (ret < 0) { in kvm_put_xen_state()
1846 if (env->xen_periodic_timer_period) { in kvm_put_xen_state()
1847 ret = do_set_periodic_timer(cs, env->xen_periodic_timer_period); in kvm_put_xen_state()
1848 if (ret < 0) { in kvm_put_xen_state()
1858 QEMU_LOCK_GUARD(&env->xen_timers_lock); in kvm_put_xen_state()
1859 if (env->xen_singleshot_timer_ns) { in kvm_put_xen_state()
1860 ret = do_set_singleshot_timer(cs, env->xen_singleshot_timer_ns, in kvm_put_xen_state()
1862 if (ret < 0) { in kvm_put_xen_state()
1866 return 0; in kvm_put_xen_state()
1869 if (env->xen_vcpu_callback_vector) { in kvm_put_xen_state()
1871 if (ret < 0) { in kvm_put_xen_state()
1876 if (env->xen_virq[VIRQ_TIMER]) { in kvm_put_xen_state()
1878 RUN_ON_CPU_HOST_INT(env->xen_virq[VIRQ_TIMER])); in kvm_put_xen_state()
1880 return 0; in kvm_put_xen_state()
1886 CPUX86State *env = &cpu->env; in kvm_get_xen_state()
1887 uint64_t gpa; in kvm_get_xen_state() local
1896 gpa = env->xen_vcpu_info_gpa; in kvm_get_xen_state()
1897 if (gpa == INVALID_GPA) { in kvm_get_xen_state()
1898 gpa = env->xen_vcpu_info_default_gpa; in kvm_get_xen_state()
1900 if (gpa != INVALID_GPA) { in kvm_get_xen_state()
1902 gpa, in kvm_get_xen_state()
1912 return 0; in kvm_get_xen_state()
1919 if (env->xen_virq[VIRQ_TIMER]) { in kvm_get_xen_state()
1924 if (ret < 0) { in kvm_get_xen_state()
1935 QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); in kvm_get_xen_state()
1936 env->xen_singleshot_timer_ns = va.u.timer.expires_ns; in kvm_get_xen_state()
1939 return 0; in kvm_get_xen_state()