Skip to content

Commit ff96453

Browse files
Sainath Grandhilijinxia
authored andcommitted
hv: Boot multiple OS for Partitioning mode ACRN
ACRN in partitioning mode boots multiple OS. Adding code to parse VM description structure and a reference description structure for booting 2 OSes. Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
1 parent 5e32c02 commit ff96453

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,10 @@ static void cpu_secondary_post(void)
639639

640640
exec_vmxon_instr(get_cpu_id());
641641

642+
#ifdef CONFIG_PARTITION_MODE
643+
prepare_vm(get_cpu_id());
644+
#endif
645+
642646
default_idle();
643647

644648
/* Control will only come here for secondary

hypervisor/arch/x86/guest/vm.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,40 @@ void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec)
404404
schedule_vcpu(bsp);
405405
}
406406

407+
#ifdef CONFIG_PARTITION_MODE
408+
/* Create vm/vcpu for vm */
409+
int prepare_vm(uint16_t pcpu_id)
410+
{
411+
int ret = 0;
412+
uint16_t i;
413+
struct vm *vm = NULL;
414+
const struct vm_description *vm_desc = NULL;
415+
bool is_vm_bsp;
416+
417+
vm_desc = pcpu_vm_desc_map[pcpu_id].vm_desc_ptr;
418+
is_vm_bsp = pcpu_vm_desc_map[pcpu_id].is_bsp;
419+
420+
if (is_vm_bsp) {
421+
ret = create_vm(vm_desc, &vm);
422+
ASSERT(ret == 0, "VM creation failed!");
423+
424+
prepare_vcpu(vm, vm_desc->vm_pcpu_ids[0]);
425+
426+
/* Prepare the AP for vm */
427+
for (i = 1U; i < vm_desc->vm_hw_num_cores; i++)
428+
prepare_vcpu(vm, vm_desc->vm_pcpu_ids[i]);
429+
430+
/* start vm BSP automatically */
431+
start_vm(vm);
432+
433+
pr_acrnlog("Start VM%x", vm_desc->vm_id);
434+
}
435+
436+
return ret;
437+
}
438+
439+
#else
440+
407441
/* Create vm/vcpu for vm0 */
408442
int prepare_vm0(void)
409443
{
@@ -448,6 +482,7 @@ int prepare_vm(uint16_t pcpu_id)
448482

449483
return err;
450484
}
485+
#endif
451486

452487
#ifdef CONFIG_VM0_DESC
453488
static inline bool vcpu_in_vm_desc(struct vcpu *vcpu,

hypervisor/bsp/sbl/vm_description.c

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <hypervisor.h>
88

9-
#ifdef CONFIG_VM0_DESC
9+
#if defined(CONFIG_VM0_DESC) && !defined(CONFIG_PARTITION_MODE)
1010

1111
/* Number of CPUs in VM0 */
1212
#define VM0_NUM_CPUS 1
@@ -24,3 +24,79 @@ struct vm_description vm0_desc = {
2424
struct vm_description vm0_desc;
2525

2626
#endif // CONFIG_VM0_DESC
27+
28+
#ifdef CONFIG_PARTITION_MODE
29+
30+
#define NUM_USER_VMS 2U
31+
32+
/**********************/
33+
/* VIRTUAL MACHINE 0 */
34+
/*********************/
35+
36+
/* Number of CPUs in this VM*/
37+
#define VM1_NUM_CPUS 2U
38+
39+
/* Logical CPU IDs assigned to this VM */
40+
int VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U};
41+
42+
/*********************/
43+
/* VIRTUAL MACHINE 1 */
44+
/*********************/
45+
46+
/* Number of CPUs in this VM*/
47+
#define VM2_NUM_CPUS 2U
48+
49+
/* Logical CPU IDs assigned with this VM */
50+
int VM2_CPUS[VM2_NUM_CPUS] = {3U, 1U};
51+
52+
53+
/*******************************/
54+
/* User Defined VM definitions */
55+
/*******************************/
56+
const struct vm_description_array vm_desc_mrb = {
57+
/* Number of user virtual machines */
58+
.num_vm_desc = NUM_USER_VMS,
59+
60+
/* Virtual Machine descriptions */
61+
.vm_desc_array = {
62+
{
63+
/* Internal variable, MUSTBE init to -1 */
64+
.vm_hw_num_cores = VM1_NUM_CPUS,
65+
.vm_pcpu_ids = &VM1_CPUS[0],
66+
.vm_id = 1U,
67+
.bootargs = "root=/dev/sda rw rootwait noxsave maxcpus=2 nohpet console=hvc0 \
68+
console=ttyS0 no_timer_check ignore_loglevel log_buf_len=16M \
69+
consoleblank=0 tsc=reliable"
70+
},
71+
72+
{
73+
/* Internal variable, MUSTBE init to -1 */
74+
.vm_hw_num_cores = VM2_NUM_CPUS,
75+
.vm_pcpu_ids = &VM2_CPUS[0],
76+
.vm_id = 2U,
77+
.bootargs = "root=/dev/sda rw rootwait noxsave maxcpus=2 nohpet console=hvc0 \
78+
console=ttyS0 no_timer_check ignore_loglevel log_buf_len=16M \
79+
consoleblank=0 tsc=reliable"
80+
},
81+
}
82+
};
83+
84+
const struct pcpu_vm_desc_mapping pcpu_vm_desc_map[] = {
85+
{
86+
.vm_desc_ptr = &vm_desc_mrb.vm_desc_array[0],
87+
.is_bsp = true,
88+
},
89+
{
90+
.vm_desc_ptr = &vm_desc_mrb.vm_desc_array[1],
91+
.is_bsp = false,
92+
},
93+
{
94+
.vm_desc_ptr = &vm_desc_mrb.vm_desc_array[0],
95+
.is_bsp = false,
96+
},
97+
{
98+
.vm_desc_ptr = &vm_desc_mrb.vm_desc_array[1],
99+
.is_bsp = true,
100+
},
101+
};
102+
#endif

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ struct vm_description {
170170
/* Whether secure world is enabled for current VM. */
171171
bool sworld_enabled;
172172
#ifdef CONFIG_PARTITION_MODE
173+
uint8_t vm_id;
173174
struct mptable_info *mptable;
175+
const char *bootargs;
174176
#endif
175177
};
176178

@@ -191,4 +193,16 @@ struct vm *get_vm_from_vmid(uint16_t vm_id);
191193
extern struct list_head vm_list;
192194
extern spinlock_t vm_list_lock;
193195

196+
#ifdef CONFIG_PARTITION_MODE
197+
struct vm_description_array {
198+
int num_vm_desc;
199+
const struct vm_description vm_desc_array[];
200+
};
201+
202+
struct pcpu_vm_desc_mapping {
203+
const struct vm_descriptin *vm_desc_ptr;
204+
bool is_bsp;
205+
};
206+
extern const struct pcpu_vm_desc_mapping pcpu_vm_desc_map[];
207+
#endif
194208
#endif /* VM_H_ */

0 commit comments

Comments
 (0)