Skip to content

Commit ed286e3

Browse files
KaigeFuacrnsi
authored andcommitted
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>
1 parent 2e4d7eb commit ed286e3

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

hypervisor/arch/x86/configs/dnv-cb2/partition_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#define VM0_CONFIG_NAME "PRE-LAUNCHED VM1 for DNV-CB2"
1313
#define VM0_CONFIG_TYPE PRE_LAUNCHED_VM
1414
#define VM0_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(2) | PLUG_CPU(4) | PLUG_CPU(6))
15-
#define VM0_CONFIG_FLAGS GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING
15+
#define VM0_CONFIG_FLAGS (GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING | \
16+
GUEST_FLAG_RT)
1617
#define VM0_CONFIG_MEM_START_HPA 0x100000000UL
1718
#define VM0_CONFIG_MEM_SIZE 0x80000000UL
1819

@@ -26,7 +27,8 @@
2627
#define VM1_CONFIG_NAME "PRE-LAUNCHED VM2 for DNV-CB2"
2728
#define VM1_CONFIG_TYPE PRE_LAUNCHED_VM
2829
#define VM1_CONFIG_PCPU_BITMAP (PLUG_CPU(1) | PLUG_CPU(3) | PLUG_CPU(5) | PLUG_CPU(7))
29-
#define VM1_CONFIG_FLAGS GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING
30+
#define VM1_CONFIG_FLAGS (GUEST_FLAG_LAPIC_PASSTHROUGH | GUEST_FLAG_IO_COMPLETION_POLLING | \
31+
GUEST_FLAG_RT)
3032
#define VM1_CONFIG_MEM_START_HPA 0x180000000UL
3133
#define VM1_CONFIG_MEM_SIZE 0x80000000UL
3234

hypervisor/arch/x86/configs/vm_config.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ int32_t sanitize_vm_config(void)
101101
case PRE_LAUNCHED_VM:
102102
if (vm_config->pcpu_bitmap == 0U) {
103103
ret = -EINVAL;
104+
/* GUEST_FLAG_RT must be set if we have GUEST_FLAG_LAPIC_PASSTHROUGH set in guest_flags */
105+
} else if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
106+
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
107+
ret = -EINVAL;
104108
} else {
105109
pre_launch_pcpu_bitmap |= vm_config->pcpu_bitmap;
106110
}

hypervisor/arch/x86/guest/vm.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ bool is_lapic_pt(const struct acrn_vm *vm)
7272
return ((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U);
7373
}
7474

75+
/**
76+
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
77+
*/
78+
bool is_rt_vm(const struct acrn_vm *vm)
79+
{
80+
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
81+
82+
return ((vm_config->guest_flags & GUEST_FLAG_RT) != 0U);
83+
}
84+
7585
/**
7686
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
7787
*/

hypervisor/common/hypercall.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,26 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
136136
vm_config->guest_flags |= cv.vm_flag;
137137
(void)memcpy_s(&vm_config->GUID[0], 16U, &cv.GUID[0], 16U);
138138

139-
ret = create_vm(vm_id, vm_config, &target_vm);
140-
if (ret != 0) {
141-
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
142-
cv.vmid = ACRN_INVALID_VMID;
139+
/* GUEST_FLAG_RT must be set if we have GUEST_FLAG_LAPIC_PASSTHROUGH set in guest_flags */
140+
if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
141+
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
142+
pr_err("Wrong guest flags 0x%llx\n", vm_config->guest_flags);
143143
ret = -1;
144144
} else {
145-
cv.vmid = target_vm->vm_id;
146-
ret = 0;
147-
}
145+
ret = create_vm(vm_id, vm_config, &target_vm);
146+
if (ret != 0) {
147+
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
148+
cv.vmid = ACRN_INVALID_VMID;
149+
ret = -1;
150+
} else {
151+
cv.vmid = target_vm->vm_id;
152+
ret = 0;
153+
}
148154

149-
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
150-
pr_err("%s: Unable copy param to vm\n", __func__);
151-
ret = -1;
155+
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
156+
pr_err("%s: Unable copy param to vm\n", __func__);
157+
ret = -1;
158+
}
152159
}
153160
}
154161
} else {

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ uint16_t get_vm_pcpu_nums(const struct acrn_vm_config *vm_config);
221221
void vrtc_init(struct acrn_vm *vm);
222222

223223
bool is_lapic_pt(const struct acrn_vm *vm);
224+
bool is_rt_vm(const struct acrn_vm *vm);
224225
bool vm_hide_mtrr(const struct acrn_vm *vm);
225226

226227
#endif /* !ASSEMBLER */

0 commit comments

Comments
 (0)