From 119eccfea12ecc5687402d15f0ed230686fa2b5e Mon Sep 17 00:00:00 2001 From: Shiqing Gao Date: Fri, 16 Nov 2018 16:54:15 +0800 Subject: [PATCH] hv: hypercall: clean up HV_DEBUG usage remove the usage of HV_DEBUG in hypercall.c and vmcall.c TO-DO: Enhance Makefile to compile debug/release into 2 libraries Tracked-On: #861 Signed-off-by: Shiqing Gao Acked-by: Eddie Dong --- hypervisor/Makefile | 4 + hypervisor/arch/x86/guest/vmcall.c | 17 +--- hypervisor/common/hypercall.c | 66 --------------- hypervisor/debug/hypercall.c | 115 +++++++++++++++++++++++++- hypervisor/include/common/hypercall.h | 36 ++------ hypervisor/include/debug/profiling.h | 6 -- hypervisor/release/hypercall.c | 13 +++ 7 files changed, 135 insertions(+), 122 deletions(-) create mode 100644 hypervisor/release/hypercall.c diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 4a8b73335..b479fc94a 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -111,6 +111,8 @@ LD ?= ld OBJCOPY ?= objcopy D_SRCS += $(wildcard debug/*.c) +R_SRCS += $(wildcard release/*.c) + C_SRCS += boot/acpi.c C_SRCS += boot/dmar_parse.c C_SRCS += boot/reloc.c @@ -225,6 +227,8 @@ C_OBJS := $(patsubst %.c,$(HV_OBJDIR)/%.o,$(C_SRCS)) ifneq ($(CONFIG_RELEASE),y) C_OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(D_SRCS)) CFLAGS += -DHV_DEBUG -DPROFILING_ON +else +C_OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(R_SRCS)) endif S_OBJS := $(patsubst %.S,$(HV_OBJDIR)/%.o,$(S_SRCS)) diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index dc3c890ae..300c4f5d7 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -169,20 +169,6 @@ int vmcall_vmexit_handler(struct acrn_vcpu *vcpu) ret = hcall_reset_ptdev_intr_info(vm, (uint16_t)param1, param2); break; -#ifdef HV_DEBUG - 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; -#endif - case HC_WORLD_SWITCH: ret = hcall_world_switch(vcpu); break; @@ -204,8 +190,7 @@ int vmcall_vmexit_handler(struct acrn_vcpu *vcpu) break; default: - pr_err("op %d: Invalid hypercall\n", hypcall_id); - ret = -EPERM; + ret = hcall_debug(vm, param1, param2, hypcall_id); break; } diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index be9f4ac27..8c1118b58 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -924,72 +924,6 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param) return ret; } -#ifdef HV_DEBUG -/** - * @brief Setup a share buffer for a VM. - * - * @param vm Pointer to VM data structure - * @param param guest physical address. This gpa points to - * struct sbuf_setup_param - * - * @pre Pointer vm shall point to VM0 - * @return 0 on success, non-zero on error. - */ -int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param) -{ - struct sbuf_setup_param ssp; - uint64_t *hva; - - (void)memset((void *)&ssp, 0U, sizeof(ssp)); - - if (copy_from_gpa(vm, &ssp, param, sizeof(ssp)) != 0) { - pr_err("%s: Unable copy param to vm\n", __func__); - return -1; - } - - if (ssp.gpa != 0U) { - hva = (uint64_t *)gpa2hva(vm, ssp.gpa); - } else { - hva = (uint64_t *)NULL; - } - - return sbuf_share_setup(ssp.pcpu_id, ssp.sbuf_id, hva); -} -#endif - -#ifdef HV_DEBUG -/** - * @brief Setup the hypervisor NPK log. - * - * @param vm Pointer to VM data structure - * @param param guest physical address. This gpa points to - * struct hv_npk_log_param - * - * @pre Pointer vm shall point to VM0 - * @return 0 on success, non-zero on error. - */ -int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param) -{ - struct hv_npk_log_param npk_param; - - (void)memset((void *)&npk_param, 0U, sizeof(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; -} -#endif - /** * @brief Get VCPU Power state. * diff --git a/hypervisor/debug/hypercall.c b/hypervisor/debug/hypercall.c index 4217581c2..c88dc7ae2 100644 --- a/hypervisor/debug/hypercall.c +++ b/hypervisor/debug/hypercall.c @@ -12,9 +12,18 @@ #ifdef PROFILING_ON /** - *@pre Pointer vm shall point to VM0 + * @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 + * data structure required by each command + * + * @pre Pointer vm shall point to VM0 + * @return 0 on success, non-zero on error. */ -int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t param) +static int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t param) { int32_t ret; switch (cmd) { @@ -49,4 +58,104 @@ int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t param) } return ret; } -#endif +#endif /* PROFILING_ON */ + +/** + * @brief Setup a share buffer for a VM. + * + * @param vm Pointer to VM data structure + * @param param guest physical address. This gpa points to + * struct sbuf_setup_param + * + * @pre Pointer vm shall point to VM0 + * @return 0 on success, non-zero on error. + */ +static int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param) +{ + struct sbuf_setup_param ssp; + uint64_t *hva; + + (void)memset((void *)&ssp, 0U, sizeof(ssp)); + + if (copy_from_gpa(vm, &ssp, param, sizeof(ssp)) != 0) { + pr_err("%s: Unable copy param to vm\n", __func__); + return -1; + } + + if (ssp.gpa != 0U) { + hva = (uint64_t *)gpa2hva(vm, ssp.gpa); + } else { + hva = (uint64_t *)NULL; + } + + return sbuf_share_setup(ssp.pcpu_id, ssp.sbuf_id, hva); +} + +/** + * @brief Setup the hypervisor NPK log. + * + * @param vm Pointer to VM data structure + * @param param guest physical address. This gpa points to + * struct hv_npk_log_param + * + * @pre Pointer vm shall point to VM0 + * @return 0 on success, non-zero on error. + */ +static int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param) +{ + struct hv_npk_log_param npk_param; + + (void)memset((void *)&npk_param, 0U, sizeof(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; +} + +/** + * @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 VM0 + * @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; + + default: + pr_err("op %d: Invalid hypercall\n", hypcall_id); + ret = -EPERM; + break; + } + + return ret; +} diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index 5f76e7328..27df83d9d 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -307,44 +307,18 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa int32_t hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param); -#ifdef HV_DEBUG /** - * @brief Setup a share buffer for a VM. - * - * @param vm Pointer to VM data structure - * @param param guest physical address. This gpa points to - * struct sbuf_setup_param - * - * @pre Pointer vm shall point to VM0 - * @return 0 on success, non-zero on error. - */ -int32_t hcall_setup_sbuf(struct acrn_vm *vm, uint64_t param); - -/** - * @brief Setup the hypervisor NPK log. + * @brief Setup hypervisor debug infrastructure, such as share buffer, NPK log and profiling. * * @param vm Pointer to VM data structure - * @param param guest physical address. This gpa points to - * struct hv_npk_log_param + * @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 VM0 * @return 0 on success, non-zero on error. */ -int32_t hcall_setup_hv_npk_log(struct acrn_vm *vm, uint64_t param); -#endif - -/** - * @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 - * data structure required by each command - * - * @return 0 on success, non-zero on error. - */ -int32_t hcall_profiling_ops(struct acrn_vm *vm, uint64_t cmd, uint64_t param); +int32_t hcall_debug(struct acrn_vm *vm, uint64_t param1, uint64_t param2, uint64_t hypcall_id); /** * @brief Get VCPU Power state. diff --git a/hypervisor/include/debug/profiling.h b/hypervisor/include/debug/profiling.h index a8d5e18e9..c1af9b0bb 100644 --- a/hypervisor/include/debug/profiling.h +++ b/hypervisor/include/debug/profiling.h @@ -22,12 +22,6 @@ static inline void profiling_vmexit_handler(__unused struct acrn_vcpu *vcpu, __unused uint64_t exit_reason) {} static inline void profiling_setup(void) {} -static inline int32_t hcall_profiling_ops(__unused struct acrn_vm *vm, - __unused uint64_t cmd, __unused uint64_t param) -{ - return -ENODEV; -} - #endif #endif /* PROFILING_H */ diff --git a/hypervisor/release/hypercall.c b/hypervisor/release/hypercall.c new file mode 100644 index 000000000..49564726e --- /dev/null +++ b/hypervisor/release/hypercall.c @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +int32_t hcall_debug(__unused struct acrn_vm *vm, __unused uint64_t param1, __unused uint64_t param2, + __unused uint64_t hypcall_id) +{ + return -EPERM; +}