From 2dca23c7c9431523c17d4e2d3ca7b78db99c30e4 Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Wed, 30 May 2018 22:22:37 +0800 Subject: [PATCH] add hypercall hc_sos_offline_cpu support SOS boot with all physicall cpus, before running UOS, it should free CPU resource by offline not used cpus - first do standard cpu offline flow - then call hcall_sos_offline_cpu hypercall to release cpu resource really Signed-off-by: Jason Chen CJ Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vmcall.c | 3 +++ hypervisor/common/hypercall.c | 24 ++++++++++++++++++++++++ hypervisor/include/common/hypercall.h | 12 ++++++++++++ hypervisor/include/public/acrn_hv_defs.h | 1 + 4 files changed, 40 insertions(+) diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index 210b6fb2b..a7db2611e 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -38,6 +38,9 @@ int vmcall_vmexit_handler(struct vcpu *vcpu) /* Dispatch the hypercall handler */ switch (hypcall_id) { + case HC_SOS_OFFLINE_CPU: + ret = hcall_sos_offline_cpu(vm, param1); + break; case HC_GET_API_VERSION: #ifdef CONFIG_VM0_DESC /* vm0 will call HC_GET_API_VERSION as first hypercall, fixup diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 84f66ebac..e4dcc0dda 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -25,6 +25,30 @@ bool is_hypercall_from_ring0(void) return false; } +int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid) +{ + struct vcpu *vcpu; + int i; + + if (!is_vm0(vm)) + return -1; + + pr_info("sos offline cpu with lapicid %lld", lapicid); + + foreach_vcpu(i, vm, vcpu) { + if (vlapic_get_apicid(vcpu->arch_vcpu.vlapic) == lapicid) { + /* should not offline BSP */ + if (vcpu->vcpu_id == 0) + return -1; + pause_vcpu(vcpu, VCPU_ZOMBIE); + reset_vcpu(vcpu); + destroy_vcpu(vcpu); + } + } + + return 0; +} + int32_t hcall_get_api_version(struct vm *vm, uint64_t param) { struct hc_api_version version; diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index be8edc5a3..42bac48a2 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -24,6 +24,18 @@ bool is_hypercall_from_ring0(void); * @{ */ +/** + * @brief offline vcpu from SOS + * + * The function offline specific vcpu from SOS. + * + * @param vm Pointer to VM data structure + * @param lapicid lapic id of the vcpu which wants to offline + * + * @return 0 on success, non-zero on error. + */ +int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid); + /** * @brief Get hypervisor api version * diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h index ae526efe0..30eca2a26 100644 --- a/hypervisor/include/public/acrn_hv_defs.h +++ b/hypervisor/include/public/acrn_hv_defs.h @@ -26,6 +26,7 @@ /* general */ #define HC_ID_GEN_BASE 0x0UL #define HC_GET_API_VERSION _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00UL) +#define HC_SOS_OFFLINE_CPU _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01UL) /* VM management */ #define HC_ID_VM_BASE 0x10UL