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 #define UCALL_PIO_PORT ((u16)0x1000) 10 11 void ucall_arch_do_ucall(gva_t uc) 12 { 13 asm volatile("in %[port], %%al" 14 : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); 15 } 16 17 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) 18 { 19 struct kvm_run *run = vcpu->run; 20 21 if (run->exit_reason == KVM_EXIT_IO && run->io.port == UCALL_PIO_PORT) { 22 struct kvm_regs regs; 23 24 vcpu_regs_get(vcpu, ®s); 25 return (void *)regs.rdi; 26 } 27 return NULL; 28 } 29