hv: add a new field cpu_affinity in struct acrn_vm

For post-launched VMs, the configured CPU affinity could be different
from the actual running CPU affinity. This new field acrn_vm->cpu_affinity
recognizes this difference so that it's possible that CREATE_VM
hypercall won't overwrite the configured CPU afifnity.

Change name cpu_affinity_bitmap in acrn_vm_config to cpu_affinity.
This is read-only in run time, never overwritten by acrn-dm.

Remove vm_config->vcpu_num, which means the number of vCPUs of the
configured CPU affinity. This is not to be confused with the actual
running vCPU number: vm->hw.created_vcpus.

Changed get_vm_bsp_pcpu_id() to get_configured_bsp_pcpu_id() for less
confusion.

Tracked-On: #4616
Signed-off-by: Zide Chen <zide.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Zide Chen
2020-04-29 11:50:07 -07:00
committed by wenlingz
parent 0629c5c8c2
commit 0a956c34c7
5 changed files with 51 additions and 47 deletions

View File

@@ -166,14 +166,14 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
/* Filter out the bits should not set by DM and then assign it to guest_flags */
vm_config->guest_flags |= (cv.vm_flag & DM_OWNED_GUEST_FLAG_MASK);
/* post-launched VM is allowed to choose pCPUs from vm_config->cpu_affinity_bitmap only */
if ((cv.cpu_affinity & ~(vm_config->cpu_affinity_bitmap)) != 0UL) {
pr_err("%s: Post-launch VM can't share PCPU with Pre-launch VM!", __func__);
} else {
/* DM could overwrite the statically configured PCPU bitmap */
if (bitmap_weight(cv.cpu_affinity) != 0U) {
vm_config->vcpu_num = bitmap_weight(cv.cpu_affinity);
vm_config->cpu_affinity_bitmap = cv.cpu_affinity;
/* post-launched VM is allowed to choose pCPUs from vm_config->cpu_affinity only */
if ((cv.cpu_affinity & ~(vm_config->cpu_affinity)) == 0UL) {
/* By default launch VM with all the configured pCPUs */
uint64_t pcpu_bitmap = vm_config->cpu_affinity;
if (cv.cpu_affinity != 0UL) {
/* overwrite the statically configured CPU affinity */
pcpu_bitmap = cv.cpu_affinity;
}
/*
@@ -184,17 +184,19 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0UL)) {
pr_err("Wrong guest flags 0x%lx\n", vm_config->guest_flags);
} else {
if (create_vm(vm_id, vm_config, &target_vm) != 0) {
dev_dbg(DBG_LEVEL_HYCALL, "HCALL: Create VM failed");
cv.vmid = ACRN_INVALID_VMID;
} else {
if (create_vm(vm_id, pcpu_bitmap, vm_config, &target_vm) == 0) {
/* return a relative vm_id from SOS view */
cv.vmid = vmid_2_rel_vmid(vm->vm_id, vm_id);
cv.vcpu_num = vm_config->vcpu_num;
cv.vcpu_num = target_vm->hw.created_vcpus;
} else {
dev_dbg(DBG_LEVEL_HYCALL, "HCALL: Create VM failed");
cv.vmid = ACRN_INVALID_VMID;
}
ret = copy_to_gpa(vm, &cv, param, sizeof(cv));
}
} else {
pr_err("Post-launched VM%u chooses invalid pCPUs(0x%llx).", vm_id, cv.cpu_affinity);
}
}
}