Skip to content

Commit 2dca23c

Browse files
JasonChenCJlijinxia
authored andcommitted
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 <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 589c723 commit 2dca23c

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)
3838

3939
/* Dispatch the hypercall handler */
4040
switch (hypcall_id) {
41+
case HC_SOS_OFFLINE_CPU:
42+
ret = hcall_sos_offline_cpu(vm, param1);
43+
break;
4144
case HC_GET_API_VERSION:
4245
#ifdef CONFIG_VM0_DESC
4346
/* vm0 will call HC_GET_API_VERSION as first hypercall, fixup

hypervisor/common/hypercall.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ bool is_hypercall_from_ring0(void)
2525
return false;
2626
}
2727

28+
int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid)
29+
{
30+
struct vcpu *vcpu;
31+
int i;
32+
33+
if (!is_vm0(vm))
34+
return -1;
35+
36+
pr_info("sos offline cpu with lapicid %lld", lapicid);
37+
38+
foreach_vcpu(i, vm, vcpu) {
39+
if (vlapic_get_apicid(vcpu->arch_vcpu.vlapic) == lapicid) {
40+
/* should not offline BSP */
41+
if (vcpu->vcpu_id == 0)
42+
return -1;
43+
pause_vcpu(vcpu, VCPU_ZOMBIE);
44+
reset_vcpu(vcpu);
45+
destroy_vcpu(vcpu);
46+
}
47+
}
48+
49+
return 0;
50+
}
51+
2852
int32_t hcall_get_api_version(struct vm *vm, uint64_t param)
2953
{
3054
struct hc_api_version version;

hypervisor/include/common/hypercall.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ bool is_hypercall_from_ring0(void);
2424
* @{
2525
*/
2626

27+
/**
28+
* @brief offline vcpu from SOS
29+
*
30+
* The function offline specific vcpu from SOS.
31+
*
32+
* @param vm Pointer to VM data structure
33+
* @param lapicid lapic id of the vcpu which wants to offline
34+
*
35+
* @return 0 on success, non-zero on error.
36+
*/
37+
int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid);
38+
2739
/**
2840
* @brief Get hypervisor api version
2941
*

hypervisor/include/public/acrn_hv_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/* general */
2727
#define HC_ID_GEN_BASE 0x0UL
2828
#define HC_GET_API_VERSION _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00UL)
29+
#define HC_SOS_OFFLINE_CPU _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01UL)
2930

3031
/* VM management */
3132
#define HC_ID_VM_BASE 0x10UL

0 commit comments

Comments
 (0)