hv: move error message logging into gpa copy APIs

In this way, the code looks simpler and line of code is reduced.

Tracked-On: #3854
Signed-off-by: Zide Chen <zide.chen@intel.com>
This commit is contained in:
Zide Chen 2020-03-16 14:26:11 -07:00 committed by wenlingz
parent 37291fa890
commit eef3b51eda
4 changed files with 19 additions and 52 deletions

View File

@ -405,8 +405,16 @@ static inline int32_t copy_gva(struct acrn_vcpu *vcpu, void *h_ptr_arg, uint64_t
*/
int32_t copy_from_gpa(struct acrn_vm *vm, void *h_ptr, uint64_t gpa, uint32_t size)
{
return copy_gpa(vm, h_ptr, gpa, size, 1);
int32_t ret = 0;
ret = copy_gpa(vm, h_ptr, gpa, size, 1);
if (ret != 0) {
pr_err("Unable to copy GPA 0x%llx from VM%d to HPA 0x%llx\n", gpa, vm->vm_id, (uint64_t)h_ptr);
}
return ret;
}
/* @pre Caller(Guest) should make sure gpa is continuous.
* - gpa from hypercall input which from kernel stack is gpa continuous, not
* support kernel stack from vmap
@ -416,7 +424,14 @@ int32_t copy_from_gpa(struct acrn_vm *vm, void *h_ptr, uint64_t gpa, uint32_t si
*/
int32_t copy_to_gpa(struct acrn_vm *vm, void *h_ptr, uint64_t gpa, uint32_t size)
{
return copy_gpa(vm, h_ptr, gpa, size, 0);
int32_t ret = 0;
ret = copy_gpa(vm, h_ptr, gpa, size, 0);
if (ret != 0) {
pr_err("Unable to copy HPA 0x%llx to GPA 0x%llx in VM%d\n", (uint64_t)h_ptr, gpa, vm->vm_id);
}
return ret;
}
int32_t copy_from_gva(struct acrn_vcpu *vcpu, void *h_ptr, uint64_t gva,

View File

@ -93,7 +93,6 @@ int32_t hcall_get_api_version(struct acrn_vm *vm, uint64_t param)
int32_t ret;
if (copy_to_gpa(vm, &version, param, sizeof(version)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
} else {
ret = 0;
@ -123,7 +122,6 @@ int32_t hcall_get_platform_info(struct acrn_vm *vm, uint64_t param)
platform_info.max_vcpus_per_vm = MAX_VCPUS_PER_VM;
platform_info.max_kata_containers = CONFIG_MAX_KATA_VM_NUM;
if (copy_to_gpa(vm, &platform_info, param, sizeof(platform_info)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
}
@ -180,13 +178,11 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
}
if (copy_to_gpa(vm, &cv, param, sizeof(cv)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
}
}
}
} else {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
}
@ -316,7 +312,6 @@ int32_t hcall_set_vcpu_regs(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
if ((!is_poweroff_vm(target_vm)) && (param != 0U) && (is_postlaunched_vm(target_vm)) &&
(target_vm->state != VM_RUNNING)) {
if (copy_from_gpa(vm, &vcpu_regs, param, sizeof(vcpu_regs)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else if (vcpu_regs.vcpu_id >= MAX_VCPUS_PER_VM) {
pr_err("%s: invalid vcpu_id for set_vcpu_regs\n", __func__);
} else {
@ -445,7 +440,6 @@ int32_t hcall_inject_msi(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
struct acrn_msi_entry msi;
if (copy_from_gpa(vm, &msi, param, sizeof(msi)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
/* For target cpu with lapic pt, send ipi instead of injection via vlapic */
if (is_lapic_pt_configured(target_vm)) {
@ -503,7 +497,6 @@ int32_t hcall_set_ioreq_buffer(struct acrn_vm *vm, uint16_t vmid, uint64_t param
struct acrn_set_ioreq_buffer iobuf;
if (copy_from_gpa(vm, &iobuf, param, sizeof(iobuf)) != 0) {
pr_err("%p %s: Unable copy param to vm\n", target_vm, __func__);
} else {
dev_dbg(DBG_LEVEL_HYCALL, "[%d] SET BUFFER=0x%p",
vmid, iobuf.req_buf);
@ -766,7 +759,6 @@ int32_t hcall_write_protect_page(struct acrn_vm *vm, uint16_t vmid, uint64_t wp_
struct wp_data wp;
if (copy_from_gpa(vm, &wp, wp_gpa, sizeof(wp)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
ret = write_protect_page(target_vm, &wp);
}
@ -804,7 +796,6 @@ int32_t hcall_gpa_to_hpa(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
pr_err("%s,vm[%hu] gpa 0x%lx,GPA is unmapping.",
__func__, target_vm->vm_id, v_gpa2hpa.gpa);
} else if (copy_to_gpa(vm, &v_gpa2hpa, param, sizeof(v_gpa2hpa)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
ret = 0;
}
@ -834,7 +825,6 @@ int32_t hcall_assign_pcidev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
if (!is_poweroff_vm(target_vm) && is_postlaunched_vm(target_vm)) {
if (copy_from_gpa(vm, &pcidev, param, sizeof(pcidev)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
ret = vpci_assign_pcidev(target_vm, &pcidev);
}
@ -864,7 +854,6 @@ int32_t hcall_deassign_pcidev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
if (!is_poweroff_vm(target_vm) && is_postlaunched_vm(target_vm)) {
if (copy_from_gpa(vm, &pcidev, param, sizeof(pcidev)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
ret = vpci_deassign_pcidev(target_vm, &pcidev);
}
@ -895,7 +884,6 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa
struct hc_ptdev_irq irq;
if (copy_from_gpa(vm, &irq, param, sizeof(irq)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
if (irq.type == IRQ_INTX) {
struct pci_vdev *vdev;
@ -949,7 +937,6 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
struct hc_ptdev_irq irq;
if (copy_from_gpa(vm, &irq, param, sizeof(irq)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
} else {
if (irq.type == IRQ_INTX) {
struct pci_vdev *vdev;
@ -1011,7 +998,6 @@ int32_t hcall_get_cpu_pm_state(struct acrn_vm *vm, uint64_t cmd, uint64_t param)
ret = -1;
} else if (copy_to_gpa(vm, &(target_vm->pm.px_cnt), param,
sizeof(target_vm->pm.px_cnt)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
} else {
ret = 0;
@ -1040,7 +1026,6 @@ int32_t hcall_get_cpu_pm_state(struct acrn_vm *vm, uint64_t cmd, uint64_t param)
px_data = target_vm->pm.px_data + pn;
if (copy_to_gpa(vm, px_data, param,
sizeof(struct cpu_px_data)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
break;
}
@ -1054,7 +1039,6 @@ int32_t hcall_get_cpu_pm_state(struct acrn_vm *vm, uint64_t cmd, uint64_t param)
ret = -1;
} else if (copy_to_gpa(vm, &(target_vm->pm.cx_cnt), param,
sizeof(target_vm->pm.cx_cnt)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
} else {
ret = 0;
@ -1081,7 +1065,6 @@ int32_t hcall_get_cpu_pm_state(struct acrn_vm *vm, uint64_t cmd, uint64_t param)
if (copy_to_gpa(vm, cx_data, param,
sizeof(struct cpu_cx_data)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
break;
}

View File

@ -82,7 +82,6 @@ static int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param)
uint64_t *hva;
if (copy_from_gpa(vm, &ssp, param, sizeof(ssp)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
}
@ -110,18 +109,12 @@ static int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param)
struct hv_npk_log_param npk_param;
if (copy_from_gpa(vm, &npk_param, param, sizeof(npk_param)) != 0) {
pr_err("%s: Unable copy param from vm\n", __func__);
return -1;
}
npk_log_setup(&npk_param);
if (copy_to_gpa(vm, &npk_param, param, sizeof(npk_param)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
}
return 0;
return copy_to_gpa(vm, &npk_param, param, sizeof(npk_param));
}
/**
@ -138,18 +131,12 @@ static int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param)
*/
static int32_t hcall_get_hw_info(struct acrn_vm *vm, uint64_t param)
{
int32_t ret = 0;
struct acrn_hw_info hw_info;
(void)memset((void *)&hw_info, 0U, sizeof(hw_info));
hw_info.cpu_num = get_pcpu_nums();
ret = copy_to_gpa(vm, &hw_info, param, sizeof(hw_info));
if (ret != 0) {
pr_err("%s: Unable to copy param to vm", __func__);
}
return ret;
return copy_to_gpa(vm, &hw_info, param, sizeof(hw_info));
}
/**

View File

@ -818,7 +818,6 @@ int32_t profiling_msr_ops_all_cpus(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &msr_list, addr, (uint32_t)pcpu_nums * sizeof(struct profiling_msr_ops_list)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -830,7 +829,6 @@ int32_t profiling_msr_ops_all_cpus(struct acrn_vm *vm, uint64_t addr)
smp_call_function(get_active_pcpu_bitmap(), profiling_ipi_handler, NULL);
if (copy_to_gpa(vm, &msr_list, addr, sizeof(msr_list)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -853,7 +851,6 @@ int32_t profiling_vm_list_info(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &vm_info_list, addr, sizeof(vm_info_list)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -895,7 +892,6 @@ int32_t profiling_vm_list_info(struct acrn_vm *vm, uint64_t addr)
}
if (copy_to_gpa(vm, &vm_info_list, addr, sizeof(vm_info_list)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -913,7 +909,6 @@ int32_t profiling_get_version_info(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &ver_info, addr, sizeof(ver_info)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -926,7 +921,6 @@ int32_t profiling_get_version_info(struct acrn_vm *vm, uint64_t addr)
(1U << (uint64_t)VM_SWITCH_TRACING));
if (copy_to_gpa(vm, &ver_info, addr, sizeof(ver_info)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -945,7 +939,6 @@ int32_t profiling_get_control(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &prof_control, addr, sizeof(prof_control)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -962,7 +955,6 @@ int32_t profiling_get_control(struct acrn_vm *vm, uint64_t addr)
}
if (copy_to_gpa(vm, &prof_control, addr, sizeof(prof_control)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -985,7 +977,6 @@ int32_t profiling_set_control(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &prof_control, addr, sizeof(prof_control)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -1075,7 +1066,6 @@ int32_t profiling_set_control(struct acrn_vm *vm, uint64_t addr)
}
if (copy_to_gpa(vm, &prof_control, addr, sizeof(prof_control)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -1096,7 +1086,6 @@ int32_t profiling_configure_pmi(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &pmi_config, addr, sizeof(pmi_config)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -1152,7 +1141,6 @@ int32_t profiling_configure_pmi(struct acrn_vm *vm, uint64_t addr)
smp_call_function(get_active_pcpu_bitmap(), profiling_ipi_handler, NULL);
if (copy_to_gpa(vm, &pmi_config, addr, sizeof(pmi_config)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -1173,7 +1161,6 @@ int32_t profiling_configure_vmsw(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &vmsw_config, addr, sizeof(vmsw_config)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -1214,7 +1201,6 @@ int32_t profiling_configure_vmsw(struct acrn_vm *vm, uint64_t addr)
}
if (copy_to_gpa(vm, &vmsw_config, addr, sizeof(vmsw_config)) != 0) {
pr_err("%s: Unable to copy addr to vm\n", __func__);
return -EINVAL;
}
@ -1233,7 +1219,6 @@ int32_t profiling_get_pcpu_id(struct acrn_vm *vm, uint64_t addr)
dev_dbg(DBG_LEVEL_PROFILING, "%s: entering", __func__);
if (copy_from_gpa(vm, &pcpuid, addr, sizeof(pcpuid)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -1241,7 +1226,6 @@ int32_t profiling_get_pcpu_id(struct acrn_vm *vm, uint64_t addr)
&pcpuid.ebx, &pcpuid.ecx, &pcpuid.edx);
if (copy_to_gpa(vm, &pcpuid, addr, sizeof(pcpuid)) != 0) {
pr_err("%s: Unable to copy param to vm\n", __func__);
return -EINVAL;
}
@ -1263,7 +1247,6 @@ int32_t profiling_get_status_info(struct acrn_vm *vm, uint64_t gpa)
if (copy_from_gpa(vm, &pstats, gpa,
pcpu_nums*sizeof(struct profiling_status)) != 0) {
pr_err("%s: Unable to copy addr from vm\n", __func__);
return -EINVAL;
}
@ -1276,7 +1259,6 @@ int32_t profiling_get_status_info(struct acrn_vm *vm, uint64_t gpa)
if (copy_to_gpa(vm, &pstats, gpa,
pcpu_nums*sizeof(struct profiling_status)) != 0) {
pr_err("%s: Unable to copy param to vm\n", __func__);
return -EINVAL;
}