hv: extend sbuf hypercall

Extend sbuf hypercall to support other kinds of share buffer.

Tracked-On: #8209
Signed-off-by: Conghui <conghui.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Conghui 2022-09-06 15:50:43 +08:00 committed by acrnsi-robot
parent efb01db779
commit 9cf9606e56
7 changed files with 49 additions and 41 deletions

View File

@ -181,7 +181,6 @@ struct acrn_vm *parse_target_vm(struct acrn_vm *service_vm, uint64_t hcall_id, u
case HC_GET_API_VERSION:
case HC_SERVICE_VM_OFFLINE_CPU:
case HC_SET_CALLBACK_VECTOR:
case HC_SETUP_SBUF:
case HC_SETUP_HV_NPK_LOG:
case HC_PROFILING_OPS:
case HC_GET_HW_INFO:

View File

@ -518,6 +518,33 @@ int32_t hcall_set_ioreq_buffer(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm
return ret;
}
/**
* @brief Setup a share buffer for a VM.
*
* @param vcpu Pointer to vCPU that initiates the hypercall
* @param param1 guest physical address. This gpa points to
* struct sbuf_setup_param
*
* @pre is_service_vm(vcpu->vm)
* @return 0 on success, non-zero on error.
*/
int32_t hcall_setup_sbuf(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm,
__unused uint64_t param1, uint64_t param2)
{
struct acrn_vm *vm = vcpu->vm;
struct acrn_sbuf_param asp;
uint64_t *hva;
int ret = -1;
if (copy_from_gpa(vm, &asp, param2, sizeof(asp)) == 0) {
if (asp.gpa != 0U) {
hva = (uint64_t *)gpa2hva(vm, asp.gpa);
ret = sbuf_setup_common(target_vm, asp.cpu_id, asp.sbuf_id, hva);
}
}
return ret;
}
/**
* @brief notify request done
*

View File

@ -77,4 +77,21 @@ uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data)
return ele_size;
}
int32_t sbuf_setup_common(__unused struct acrn_vm *vm, uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva)
{
int32_t ret = 0;
switch (sbuf_id) {
case ACRN_TRACE:
case ACRN_HVLOG:
case ACRN_SEP:
case ACRN_SOCWATCH:
ret = sbuf_share_setup(cpu_id, sbuf_id, hva);
break;
default:
pr_err("%s not support sbuf_id %d", __func__, sbuf_id);
ret = -1;
}
return ret;
}

View File

@ -69,36 +69,6 @@ int32_t hcall_profiling_ops(struct acrn_vcpu *vcpu, __unused struct acrn_vm *tar
}
#endif /* PROFILING_ON */
/**
* @brief Setup a share buffer for a VM.
*
* @param vcpu Pointer to vCPU that initiates the hypercall
* @param param1 guest physical address. This gpa points to
* struct sbuf_setup_param
*
* @pre is_service_vm(vcpu->vm)
* @return 0 on success, non-zero on error.
*/
int32_t hcall_setup_sbuf(struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
uint64_t param1, __unused uint64_t param2)
{
struct acrn_vm *vm = vcpu->vm;
struct sbuf_setup_param ssp;
uint64_t *hva;
if (copy_from_gpa(vm, &ssp, param1, sizeof(ssp)) != 0) {
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.
*

View File

@ -21,5 +21,6 @@ uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data);
int32_t sbuf_share_setup(uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva);
void sbuf_reset(void);
uint32_t sbuf_next_ptr(uint32_t pos, uint32_t span, uint32_t scope);
int32_t sbuf_setup_common(__unused struct acrn_vm *vm, uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva);
#endif /* SHARED_BUFFER_H */

View File

@ -56,6 +56,7 @@
#define HC_VM_GPA2HPA BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x01UL)
#define HC_VM_SET_MEMORY_REGIONS BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
#define HC_VM_WRITE_PROTECT_PAGE BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x03UL)
#define HC_SETUP_SBUF BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x04UL)
/* PCI assignment*/
#define HC_ID_PCI_BASE 0x50UL
@ -73,7 +74,6 @@
/* DEBUG */
#define HC_ID_DBG_BASE 0x60UL
#define HC_SETUP_SBUF BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x00UL)
#define HC_SETUP_HV_NPK_LOG BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x01UL)
#define HC_PROFILING_OPS BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x02UL)
#define HC_GET_HW_INFO BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x03UL)
@ -186,9 +186,9 @@ struct wp_data {
/**
* Setup parameter for share buffer, used for HC_SETUP_SBUF hypercall
*/
struct sbuf_setup_param {
/** sbuf physical cpu id */
uint16_t pcpu_id;
struct acrn_sbuf_param {
/** sbuf cpu id */
uint16_t cpu_id;
/** Reserved */
uint16_t reserved;

View File

@ -8,12 +8,6 @@
#include <errno.h>
#include <asm/guest/vm.h>
int32_t hcall_setup_sbuf(__unused struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
__unused uint64_t param1, __unused uint64_t param2)
{
return -EPERM;
}
int32_t hcall_setup_hv_npk_log(__unused struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
__unused uint64_t param1, __unused uint64_t param2)
{