
Eddie Dong
This patch series are lack of a cover letter. I cannot understand how can fast-io work.
toggle quoted messageShow quoted text
-----Original Message----- From: acrn-dev@... <acrn-dev@...> On Behalf Of Conghui Chen Sent: Saturday, July 16, 2022 6:54 AM To: acrn-dev@... Cc: Chen, Conghui <conghui.chen@...> Subject: [acrn-dev] [PATCH 1/2] hv: add hypercall for fastio
Add hypercall to setup the fastio base address.
Signed-off-by: Conghui <conghui.chen@...> --- hypervisor/arch/x86/guest/vmcall.c | 4 +++ hypervisor/common/hypercall.c | 17 ++++++++++ hypervisor/dm/io_req.c | 36 ++++++++++++++++++++++ hypervisor/include/arch/x86/asm/guest/vm.h | 4 +++ hypervisor/include/common/hypercall.h | 29 +++++++++++++++++ hypervisor/include/dm/io_req.h | 11 +++++++ hypervisor/include/public/acrn_hv_defs.h | 2 ++ 7 files changed, 103 insertions(+)
diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index 78a963241..57a9658a8 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -60,6 +60,10 @@ static const struct hc_dispatch hc_dispatch_table[] = { .handler = hcall_set_ioreq_buffer}, [HC_IDX(HC_NOTIFY_REQUEST_FINISH)] = { .handler = hcall_notify_ioreq_finish}, + [HC_IDX(HC_ASSIGN_FASTIO)] = { + .handler = hcall_assign_fastio}, + [HC_IDX(HC_DEASSIGN_FASTIO)] = { + .handler = hcall_deassign_fastio}, [HC_IDX(HC_VM_SET_MEMORY_REGIONS)] = { .handler = hcall_set_vm_memory_regions}, [HC_IDX(HC_VM_WRITE_PROTECT_PAGE)] = { diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index d1e811c4f..588d06bc1 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -857,6 +857,23 @@ int32_t hcall_deassign_pcidev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, return ret; }
+int32_t hcall_assign_fastio(__unused struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, + __unused uint64_t param1, uint64_t param2) { + uint64_t fastio_base = param2; + + update_fastio_base(target_vm, fastio_base, true); + return 0; +} + +int32_t hcall_deassign_fastio(__unused struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, + __unused uint64_t param1, uint64_t param2) { + uint64_t fastio_base = param2; + + update_fastio_base(target_vm, fastio_base, false); + return 0; +} /** * @brief Assign one MMIO dev to a VM. * diff --git a/hypervisor/dm/io_req.c b/hypervisor/dm/io_req.c index b68a66cab..9d8e7427f 100644 --- a/hypervisor/dm/io_req.c +++ b/hypervisor/dm/io_req.c @@ -69,6 +69,42 @@ static inline bool has_complete_ioreq(const struct acrn_vcpu *vcpu) return (get_io_req_state(vcpu->vm, vcpu->vcpu_id) == ACRN_IOREQ_STATE_COMPLETE); }
+/** + * @brief update the fastio base table + * + * @param vm The VM whose fastio base table need to be updated + * @param base The fastio base. + * @param add Ture means add, False means remove. + * + * @return None + */ +void update_fastio_base(struct acrn_vm *vm, uint64_t base, bool add) { + int i=-1; + + if (base != 0) { + for (i = 0; i<MAX_IOEVENTFD_NUM; i++) { + if (add) { + if (vm->fastio_base[i] == 0) { + vm->fastio_base[i] = base; + break; + } + } else { + if (vm->fastio_base[i] == base) { + vm->fastio_base[i] = 0; + break; + } + } + } + if (i == MAX_IOEVENTFD_NUM) { + pr_fatal("too much ioeventfd, would not support!!"); + } + } else { + pr_err("%s: base = 0 is not supported!", __func__); + } + pr_info("%s: base=%lx add? %d idx=%d", __func__, base, add, i); } + /** * @brief Deliver \p io_req to Service VM and suspend \p vcpu till its completion * diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index d06300600..789cd48b7 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -32,6 +32,9 @@ #include <asm/guest/hyperv.h> #endif
+#ifndef MAX_IOEVENTFD_NUM +#define MAX_IOEVENTFD_NUM 64 +#endif enum reset_mode { POWER_ON_RESET, /* reset by hardware Power-on */ COLD_RESET, /* hardware cold reset */ @@ -174,6 +177,7 @@ struct acrn_vm { struct acrn_vrtc vrtc;
uint64_t intr_inject_delay_delta; /* delay of intr injection */ + uint64_t fastio_base[MAX_IOEVENTFD_NUM]; } __aligned(PAGE_SIZE);
/* diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index 22dcfae63..57432f586 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -290,6 +290,35 @@ int32_t hcall_assign_pcidev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, u */ int32_t hcall_deassign_pcidev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, uint64_t param1, uint64_t param2);
+/** + * @brief set fastio base + * + * Set the fastio base to hypervisor's fastio table, so that hypervisor +can do different process + * for it. + * + * @param vcpu not used + * @param target_vm Pointer to target VM data structure + * @param param1 not used + * @param param2 fastio base address + * + * @return 0 on success, non-zero on error. + */ +int32_t hcall_assign_fastio(struct acrn_vcpu *vcpu, struct acrn_vm +*target_vm, uint64_t param1, uint64_t param2); + +/** + * @brief remove fastio base + * + * Remove the fastio base from hypervisor's fastio table, no more special process. + * + * @param vcpu not used + * @param target_vm Pointer to target VM data structure + * @param param1 not used + * @param param2 fastio base address + * + * @return 0 on success, non-zero on error. + */ +int32_t hcall_deassign_fastio(struct acrn_vcpu *vcpu, struct acrn_vm +*target_vm, uint64_t param1, uint64_t param2); + /** * @brief Assign one MMIO dev to VM. * diff --git a/hypervisor/include/dm/io_req.h b/hypervisor/include/dm/io_req.h index b9b25d23b..026d169d4 100644 --- a/hypervisor/include/dm/io_req.h +++ b/hypervisor/include/dm/io_req.h @@ -190,6 +190,17 @@ int32_t acrn_insert_request(struct acrn_vcpu *vcpu, const struct io_request *io_ */ void reset_vm_ioreqs(struct acrn_vm *vm);
+/** + * @brief update the fastio base table + * + * @param vm The VM whose fastio base table need to be updated + * @param base The fastio base. + * @param add Ture means add, False means remove. + * + * @return None + */ +void update_fastio_base(struct acrn_vm *vm, uint64_t base, bool add); + /** * @brief Get the state of an IO request * diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h index de85a6c9f..7f3cf73d1 100644 --- a/hypervisor/include/public/acrn_hv_defs.h +++ b/hypervisor/include/public/acrn_hv_defs.h @@ -50,6 +50,8 @@ #define HC_ID_IOREQ_BASE 0x30UL #define HC_SET_IOREQ_BUFFER BASE_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x00UL) #define HC_NOTIFY_REQUEST_FINISH BASE_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x01UL) +#define HC_ASSIGN_FASTIO BASE_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x02UL) +#define HC_DEASSIGN_FASTIO BASE_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x03UL)
/* Guest memory management */ #define HC_ID_MEM_BASE 0x40UL -- 2.25.1
|