HV: Introduce a new API is_rt_vm

This patch checks if the GUEST_FLAG_RT is set when GUEST_FLAG_LAPIC_PASSTHROUGH is set.
If GUEST_FLAG_RT is not set while GUEST_FLAG_LAPIC_PASSTHROUGH is set, we will refuse
to boot the VM.

Meanwhile, this patch introduces a new API is_rt_vm.

Tracked-On: #2865
Signed-off-by: Kaige Fu <kaige.fu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Kaige Fu 2019-03-27 14:47:49 +00:00 committed by ACRN System Integration
parent 2e4d7eb527
commit ed286e3239
5 changed files with 36 additions and 12 deletions

View File

@ -12,7 +12,8 @@
#define VM0_CONFIG_NAME "PRE-LAUNCHED VM1 for DNV-CB2"
#define VM0_CONFIG_TYPE PRE_LAUNCHED_VM
#define VM0_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(2) | PLUG_CPU(4) | PLUG_CPU(6))
#define VM0_CONFIG_FLAGS GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING
#define VM0_CONFIG_FLAGS (GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING | \
GUEST_FLAG_RT)
#define VM0_CONFIG_MEM_START_HPA 0x100000000UL
#define VM0_CONFIG_MEM_SIZE 0x80000000UL
@ -26,7 +27,8 @@
#define VM1_CONFIG_NAME "PRE-LAUNCHED VM2 for DNV-CB2"
#define VM1_CONFIG_TYPE PRE_LAUNCHED_VM
#define VM1_CONFIG_PCPU_BITMAP (PLUG_CPU(1) | PLUG_CPU(3) | PLUG_CPU(5) | PLUG_CPU(7))
#define VM1_CONFIG_FLAGS GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING
#define VM1_CONFIG_FLAGS (GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING | \
GUEST_FLAG_RT)
#define VM1_CONFIG_MEM_START_HPA 0x180000000UL
#define VM1_CONFIG_MEM_SIZE 0x80000000UL

View File

@ -101,6 +101,10 @@ int32_t sanitize_vm_config(void)
case PRE_LAUNCHED_VM:
if (vm_config->pcpu_bitmap == 0U) {
ret = -EINVAL;
/* GUEST_FLAG_RT must be set if we have GUEST_FLAG_LAPIC_PASSTHROUGH set in guest_flags */
} else if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
ret = -EINVAL;
} else {
pre_launch_pcpu_bitmap |= vm_config->pcpu_bitmap;
}

View File

@ -72,6 +72,16 @@ bool is_lapic_pt(const struct acrn_vm *vm)
return ((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U);
}
/**
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
*/
bool is_rt_vm(const struct acrn_vm *vm)
{
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
return ((vm_config->guest_flags & GUEST_FLAG_RT) != 0U);
}
/**
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
*/

View File

@ -136,19 +136,26 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
vm_config->guest_flags |= cv.vm_flag;
(void)memcpy_s(&vm_config->GUID[0], 16U, &cv.GUID[0], 16U);
ret = create_vm(vm_id, vm_config, &target_vm);
if (ret != 0) {
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
cv.vmid = ACRN_INVALID_VMID;
/* GUEST_FLAG_RT must be set if we have GUEST_FLAG_LAPIC_PASSTHROUGH set in guest_flags */
if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
pr_err("Wrong guest flags 0x%llx\n", vm_config->guest_flags);
ret = -1;
} else {
cv.vmid = target_vm->vm_id;
ret = 0;
}
ret = create_vm(vm_id, vm_config, &target_vm);
if (ret != 0) {
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
cv.vmid = ACRN_INVALID_VMID;
ret = -1;
} else {
cv.vmid = target_vm->vm_id;
ret = 0;
}
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
ret = -1;
}
}
}
} else {

View File

@ -221,6 +221,7 @@ uint16_t get_vm_pcpu_nums(const struct acrn_vm_config *vm_config);
void vrtc_init(struct acrn_vm *vm);
bool is_lapic_pt(const struct acrn_vm *vm);
bool is_rt_vm(const struct acrn_vm *vm);
bool vm_hide_mtrr(const struct acrn_vm *vm);
#endif /* !ASSEMBLER */