1 // SPDX-License-Identifier: GPL-2.0
3 * ucall support. A ucall is a "hypercall to userspace".
5 * Copyright (C) 2018, Red Hat, Inc.
9 #define UCALL_PIO_PORT ((uint16_t)0x1000)
11 void ucall_init(struct kvm_vm *vm, void *arg)
15 void ucall_uninit(struct kvm_vm *vm)
19 void ucall(uint64_t cmd, int nargs, ...)
27 nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS;
30 for (i = 0; i < nargs; ++i)
31 uc.args[i] = va_arg(va, uint64_t);
34 asm volatile("in %[port], %%al"
35 : : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax");
38 uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
40 struct kvm_run *run = vcpu_state(vm, vcpu_id);
41 struct ucall ucall = {};
43 if (run->exit_reason == KVM_EXIT_IO && run->io.port == UCALL_PIO_PORT) {
46 vcpu_regs_get(vm, vcpu_id, ®s);
47 memcpy(&ucall, addr_gva2hva(vm, (vm_vaddr_t)regs.rdi),
50 vcpu_run_complete_io(vm, vcpu_id);
52 memcpy(uc, &ucall, sizeof(ucall));