HV: hypercall: make hypercall functions return int32_t

The error code in the hypervisor is 32-bit signed integers. To reduce implicit
conversions, this patch make hcall_xxx returns int32_t, and finally converts it
to uint64_t when assigned to rax whose semantics is properly defined in C99.

Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Junjie Mao 2018-07-19 23:17:38 +08:00 committed by lijinxia
parent ad73bb511c
commit 1a1ee93656
4 changed files with 69 additions and 66 deletions

View File

@ -14,7 +14,7 @@
*/
int vmcall_vmexit_handler(struct vcpu *vcpu)
{
int64_t ret = -EACCES;
int32_t ret = -EACCES;
struct vm *vm = vcpu->vm;
struct run_context *cur_context =
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];

View File

@ -25,7 +25,7 @@ bool is_hypercall_from_ring0(void)
return false;
}
int64_t hcall_get_api_version(struct vm *vm, uint64_t param)
int32_t hcall_get_api_version(struct vm *vm, uint64_t param)
{
struct hc_api_version version;
@ -44,7 +44,8 @@ int64_t hcall_get_api_version(struct vm *vm, uint64_t param)
return 0;
}
static int handle_vpic_irqline(struct vm *vm, uint32_t irq, enum irq_mode mode)
static int32_t
handle_vpic_irqline(struct vm *vm, uint32_t irq, enum irq_mode mode)
{
int32_t ret = -1;
@ -68,7 +69,7 @@ static int handle_vpic_irqline(struct vm *vm, uint32_t irq, enum irq_mode mode)
return ret;
}
static int
static int32_t
handle_vioapic_irqline(struct vm *vm, uint32_t irq, enum irq_mode mode)
{
int32_t ret = -1;
@ -93,7 +94,8 @@ handle_vioapic_irqline(struct vm *vm, uint32_t irq, enum irq_mode mode)
return ret;
}
static int handle_virt_irqline(struct vm *vm, uint16_t target_vmid,
static int32_t
handle_virt_irqline(struct vm *vm, uint16_t target_vmid,
struct acrn_irqline *param, enum irq_mode mode)
{
int32_t ret = 0;
@ -131,9 +133,9 @@ static int handle_virt_irqline(struct vm *vm, uint16_t target_vmid,
return ret;
}
int64_t hcall_create_vm(struct vm *vm, uint64_t param)
int32_t hcall_create_vm(struct vm *vm, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct vm *target_vm = NULL;
/* VM are created from hv_main() directly
* Here we just return the vmid for DM
@ -170,9 +172,9 @@ int64_t hcall_create_vm(struct vm *vm, uint64_t param)
return ret;
}
int64_t hcall_destroy_vm(uint64_t vmid)
int32_t hcall_destroy_vm(uint64_t vmid)
{
int64_t ret = 0;
int32_t ret = 0;
struct vm *target_vm = get_vm_from_vmid(vmid);
if (target_vm == NULL) {
@ -183,9 +185,9 @@ int64_t hcall_destroy_vm(uint64_t vmid)
return ret;
}
int64_t hcall_resume_vm(uint64_t vmid)
int32_t hcall_resume_vm(uint64_t vmid)
{
int64_t ret = 0;
int32_t ret = 0;
struct vm *target_vm = get_vm_from_vmid(vmid);
if (target_vm == NULL) {
@ -200,7 +202,7 @@ int64_t hcall_resume_vm(uint64_t vmid)
return ret;
}
int64_t hcall_pause_vm(uint64_t vmid)
int32_t hcall_pause_vm(uint64_t vmid)
{
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -213,7 +215,7 @@ int64_t hcall_pause_vm(uint64_t vmid)
return 0;
}
int64_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
{
int32_t ret;
uint16_t pcpu_id;
@ -240,9 +242,9 @@ int64_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct acrn_irqline irqline;
if (copy_from_gpa(vm, &irqline, param, sizeof(irqline)) != 0) {
@ -254,9 +256,9 @@ int64_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct acrn_irqline irqline;
if (copy_from_gpa(vm, &irqline, param, sizeof(irqline)) != 0) {
@ -268,9 +270,9 @@ int64_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct acrn_irqline irqline;
if (copy_from_gpa(vm, &irqline, param, sizeof(irqline)) != 0) {
@ -282,7 +284,7 @@ int64_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param)
{
int32_t ret = 0;
struct acrn_msi_entry msi;
@ -302,9 +304,9 @@ int64_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
uint64_t hpa = 0UL;
struct acrn_set_ioreq_buffer iobuf;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -368,7 +370,7 @@ static void complete_request(struct vcpu *vcpu)
resume_vcpu(vcpu);
}
int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
int32_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
{
union vhm_request_buffer *req_buf;
struct vhm_request *req;
@ -403,7 +405,8 @@ int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
return 0;
}
static int64_t _set_vm_memmap(struct vm *vm, struct vm *target_vm,
static int32_t
_set_vm_memmap(struct vm *vm, struct vm *target_vm,
struct vm_set_memmap *memmap)
{
uint64_t hpa, base_paddr;
@ -459,7 +462,7 @@ static int64_t _set_vm_memmap(struct vm *vm, struct vm *target_vm,
memmap->remote_gpa, memmap->length, memmap->type, attr);
}
int64_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param)
{
struct vm_set_memmap memmap;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -488,7 +491,7 @@ int64_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param)
return _set_vm_memmap(vm, target_vm, &memmap);
}
int64_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param)
int32_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param)
{
struct set_memmaps set_memmaps;
struct memory_map *regions;
@ -531,9 +534,9 @@ int64_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param)
return 0;
}
int64_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct acrn_vm_pci_msix_remap remap;
struct ptdev_msi_info info;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -572,9 +575,9 @@ int64_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct vm_gpa2hpa v_gpa2hpa;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -597,9 +600,9 @@ int64_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret;
int32_t ret;
uint16_t bdf;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -635,9 +638,9 @@ int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
uint16_t bdf;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -655,9 +658,9 @@ int64_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
int32_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct hc_ptdev_irq irq;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -689,10 +692,10 @@ int64_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t
int32_t
hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
{
int64_t ret = 0;
int32_t ret = 0;
struct hc_ptdev_irq irq;
struct vm *target_vm = get_vm_from_vmid(vmid);
@ -723,7 +726,7 @@ hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
return ret;
}
int64_t hcall_setup_sbuf(struct vm *vm, uint64_t param)
int32_t hcall_setup_sbuf(struct vm *vm, uint64_t param)
{
struct sbuf_setup_param ssp;
uint64_t *hva;
@ -744,7 +747,7 @@ int64_t hcall_setup_sbuf(struct vm *vm, uint64_t param)
return sbuf_share_setup(ssp.pcpu_id, ssp.sbuf_id, hva);
}
int64_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param)
int32_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param)
{
uint16_t target_vm_id;
struct vm *target_vm;

View File

@ -10,7 +10,7 @@
/* this hcall is only come from trusty enabled vcpu itself, and cannot be
* called from other vcpus
*/
int64_t hcall_world_switch(struct vcpu *vcpu)
int32_t hcall_world_switch(struct vcpu *vcpu)
{
int32_t next_world_id = !(vcpu->arch_vcpu.cur_context);
@ -37,7 +37,7 @@ int64_t hcall_world_switch(struct vcpu *vcpu)
/* this hcall is only come from trusty enabled vcpu itself, and cannot be
* called from other vcpus
*/
int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
int32_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
{
if (!vcpu->vm->sworld_control.sworld_enabled) {
pr_err("%s, Secure World is not enabled!\n", __func__);

View File

@ -35,7 +35,7 @@ bool is_hypercall_from_ring0(void);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_get_api_version(struct vm *vm, uint64_t param);
int32_t hcall_get_api_version(struct vm *vm, uint64_t param);
/**
* @brief create virtual machine
@ -50,7 +50,7 @@ int64_t hcall_get_api_version(struct vm *vm, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_create_vm(struct vm *vm, uint64_t param);
int32_t hcall_create_vm(struct vm *vm, uint64_t param);
/**
* @brief destroy virtual machine
@ -62,7 +62,7 @@ int64_t hcall_create_vm(struct vm *vm, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_destroy_vm(uint64_t vmid);
int32_t hcall_destroy_vm(uint64_t vmid);
/**
* @brief resume virtual machine
@ -75,7 +75,7 @@ int64_t hcall_destroy_vm(uint64_t vmid);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_resume_vm(uint64_t vmid);
int32_t hcall_resume_vm(uint64_t vmid);
/**
* @brief pause virtual machine
@ -88,7 +88,7 @@ int64_t hcall_resume_vm(uint64_t vmid);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_pause_vm(uint64_t vmid);
int32_t hcall_pause_vm(uint64_t vmid);
/**
* @brief create vcpu
@ -104,7 +104,7 @@ int64_t hcall_pause_vm(uint64_t vmid);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief assert IRQ line
@ -119,7 +119,7 @@ int64_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief deassert IRQ line
@ -134,7 +134,7 @@ int64_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief trigger a pulse on IRQ line
@ -149,7 +149,7 @@ int64_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief inject MSI interrupt
@ -163,7 +163,7 @@ int64_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief set ioreq shared buffer
@ -178,7 +178,7 @@ int64_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief notify request done
@ -191,7 +191,7 @@ int64_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t param);
int32_t hcall_notify_req_finish(uint64_t vmid, uint64_t param);
/**
* @brief setup ept memory mapping
@ -206,7 +206,7 @@ int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief setup ept memory mapping for multi regions
@ -217,7 +217,7 @@ int64_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param);
int32_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param);
/**
* @brief remap PCI MSI interrupt
@ -232,7 +232,7 @@ int64_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief translate guest physical address to host physical address
@ -246,7 +246,7 @@ int64_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief Assign one passthrough dev to VM.
@ -258,7 +258,7 @@ int64_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief Deassign one passthrough dev from VM.
@ -270,7 +270,7 @@ int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief Set interrupt mapping info of ptdev.
@ -282,7 +282,7 @@ int64_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param);
int32_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param);
/**
* @brief Clear interrupt mapping info of ptdev.
@ -294,7 +294,7 @@ int64_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid,
int32_t hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid,
uint64_t param);
/**
@ -306,7 +306,7 @@ int64_t hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid,
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_setup_sbuf(struct vm *vm, uint64_t param);
int32_t hcall_setup_sbuf(struct vm *vm, uint64_t param);
/**
* @brief Get VCPU Power state.
@ -318,7 +318,7 @@ int64_t hcall_setup_sbuf(struct vm *vm, uint64_t param);
* @return 0 on success, non-zero on error.
*/
int64_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param);
int32_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param);
/**
* @defgroup trusty_hypercall Trusty Hypercalls
@ -344,7 +344,7 @@ int64_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param);
* @return 0 on success, non-zero on error.
*/
int64_t hcall_world_switch(struct vcpu *vcpu);
int32_t hcall_world_switch(struct vcpu *vcpu);
/**
* @brief Initialize environment for Trusty-OS on a vCPU.
@ -360,7 +360,7 @@ int64_t hcall_world_switch(struct vcpu *vcpu);
*
* @return 0 on success, non-zero on error.
*/
int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param);
int32_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param);
/**
* @}