1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * ucall support. A ucall is a "hypercall to userspace". 4 * 5 * Copyright (C) 2018, Red Hat, Inc. 6 */ 7 #include "kvm_util.h" 8 9 vm_vaddr_t *ucall_exit_mmio_addr; 10 11 void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) 12 { 13 vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR); 14 15 virt_map(vm, mmio_gva, mmio_gpa, 1); 16 17 vm->ucall_mmio_addr = mmio_gpa; 18 19 write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva); 20 } 21 22 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) 23 { 24 struct kvm_run *run = vcpu->run; 25 26 if (run->exit_reason == KVM_EXIT_MMIO && 27 run->mmio.phys_addr == vcpu->vm->ucall_mmio_addr) { 28 TEST_ASSERT(run->mmio.is_write && run->mmio.len == sizeof(uint64_t), 29 "Unexpected ucall exit mmio address access"); 30 return (void *)(*((uint64_t *)run->mmio.data)); 31 } 32 33 return NULL; 34 } 35