refine hypercall

-- use an array to fast locate the hypercall handler
   to replace switch case.
-- uniform hypercall handler as below:
   int32_t (*handler)(sos_vm, target_vm, param1, param2)

Tracked-On: #4958
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi
2020-08-13 17:34:06 +08:00
committed by wenlingz
parent 7935354864
commit 53b11d1048
8 changed files with 510 additions and 516 deletions

View File

@@ -18,44 +18,45 @@
* @brief Execute profiling operation
*
* @param vm Pointer to VM data structure
* @param cmd profiling command to be executed
* @param cmd profiling command to be executed
* @param param guest physical address. This gpa points to
* @param param1 profiling command to be executed
* @param param2 guest physical address. This gpa points to
* data structure required by each command
*
* @pre Pointer vm shall point to SOS_VM
* @return 0 on success, non-zero on error.
*/
static int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t param)
int32_t hcall_profiling_ops(struct acrn_vm *vm, __unused struct acrn_vm *target_vm, uint64_t param1, uint64_t param2)
{
int32_t ret;
uint64_t cmd = param1;
switch (cmd) {
case PROFILING_MSR_OPS:
ret = profiling_msr_ops_all_cpus(vm, param);
ret = profiling_msr_ops_all_cpus(vm, param2);
break;
case PROFILING_GET_VMINFO:
ret = profiling_vm_list_info(vm, param);
ret = profiling_vm_list_info(vm, param2);
break;
case PROFILING_GET_VERSION:
ret = profiling_get_version_info(vm, param);
ret = profiling_get_version_info(vm, param2);
break;
case PROFILING_GET_CONTROL_SWITCH:
ret = profiling_get_control(vm, param);
ret = profiling_get_control(vm, param2);
break;
case PROFILING_SET_CONTROL_SWITCH:
ret = profiling_set_control(vm, param);
ret = profiling_set_control(vm, param2);
break;
case PROFILING_CONFIG_PMI:
ret = profiling_configure_pmi(vm, param);
ret = profiling_configure_pmi(vm, param2);
break;
case PROFILING_CONFIG_VMSWITCH:
ret = profiling_configure_vmsw(vm, param);
ret = profiling_configure_vmsw(vm, param2);
break;
case PROFILING_GET_PCPUID:
ret = profiling_get_pcpu_id(vm, param);
ret = profiling_get_pcpu_id(vm, param2);
break;
case PROFILING_GET_STATUS:
ret = profiling_get_status_info(vm, param);
ret = profiling_get_status_info(vm, param2);
break;
default:
pr_err("%s: invalid profiling command %lu\n", __func__, cmd);
@@ -70,18 +71,19 @@ static int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t pa
* @brief Setup a share buffer for a VM.
*
* @param vm Pointer to VM data structure
* @param param guest physical address. This gpa points to
* @param param1 guest physical address. This gpa points to
* struct sbuf_setup_param
*
* @pre Pointer vm shall point to SOS_VM
* @return 0 on success, non-zero on error.
*/
static int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param)
int32_t hcall_setup_sbuf(struct acrn_vm *vm, __unused struct acrn_vm *target_vm,
uint64_t param1, __unused uint64_t param2)
{
struct sbuf_setup_param ssp;
uint64_t *hva;
if (copy_from_gpa(vm, &ssp, param, sizeof(ssp)) != 0) {
if (copy_from_gpa(vm, &ssp, param1, sizeof(ssp)) != 0) {
return -1;
}
@@ -98,23 +100,24 @@ static int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param)
* @brief Setup the hypervisor NPK log.
*
* @param vm Pointer to VM data structure
* @param param guest physical address. This gpa points to
* @param param1 guest physical address. This gpa points to
* struct hv_npk_log_param
*
* @pre Pointer vm shall point to SOS_VM
* @return 0 on success, non-zero on error.
*/
static int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param)
int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, __unused struct acrn_vm *target_vm,
uint64_t param1, __unused uint64_t param2)
{
struct hv_npk_log_param npk_param;
if (copy_from_gpa(vm, &npk_param, param, sizeof(npk_param)) != 0) {
if (copy_from_gpa(vm, &npk_param, param1, sizeof(npk_param)) != 0) {
return -1;
}
npk_log_setup(&npk_param);
return copy_to_gpa(vm, &npk_param, param, sizeof(npk_param));
return copy_to_gpa(vm, &npk_param, param1, sizeof(npk_param));
}
/**
@@ -124,59 +127,18 @@ static int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param)
* @param param Guest physical address pointing to struct acrn_hw_info
*
* @pre vm shall point to SOS_VM
* @pre param shall be a valid physical address
* @pre param1 shall be a valid physical address
*
* @retval 0 on success
* @retval -1 in case of error
*/
static int32_t hcall_get_hw_info(struct acrn_vm *vm, uint64_t param)
int32_t hcall_get_hw_info(struct acrn_vm *vm, __unused struct acrn_vm *target_vm,
uint64_t param1, __unused uint64_t param2)
{
struct acrn_hw_info hw_info;
(void)memset((void *)&hw_info, 0U, sizeof(hw_info));
hw_info.cpu_num = get_pcpu_nums();
return copy_to_gpa(vm, &hw_info, param, sizeof(hw_info));
}
/**
* @brief Setup hypervisor debug infrastructure, such as share buffer, NPK log and profiling.
*
* @param vm Pointer to VM data structure
* @param param1 hypercall param1 from guest
* @param param2 hypercall param2 from guest
* @param hypcall_id hypercall ID from guest
*
* @pre Pointer vm shall point to SOS_VM
* @return 0 on success, non-zero on error.
*/
int32_t hcall_debug(struct acrn_vm *vm, uint64_t param1, uint64_t param2, uint64_t hypcall_id)
{
int32_t ret;
/* Dispatch the debug hypercall handler */
switch (hypcall_id) {
case HC_SETUP_SBUF:
ret = hcall_setup_sbuf(vm, param1);
break;
case HC_SETUP_HV_NPK_LOG:
ret = hcall_setup_hv_npk_log(vm, param1);
break;
case HC_PROFILING_OPS:
ret = hcall_profiling_ops(vm, param1, param2);
break;
case HC_GET_HW_INFO:
ret = hcall_get_hw_info(vm, param1);
break;
default:
pr_err("op %d: Invalid hypercall\n", hypcall_id);
ret = -EPERM;
break;
}
return ret;
return copy_to_gpa(vm, &hw_info, param1, sizeof(hw_info));
}