Skip to content

Commit 706dbc0

Browse files
vijaydhanrajwenlingz
authored andcommitted
acrn-config: support non-contiguous HPA for pre-launched VM
This patch modifies the python scripts in scenario, board and vm-configuration to support, 1. Generation of seperate ve820 for each VM. 2. Ability to configure each VM's HPA from acrn-config UI tool. 3. Non-contiguous HPAs for pre-launched VMs. Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com> Tracked-On: #4195 Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 6e8b413 commit 706dbc0

File tree

5 files changed

+154
-66
lines changed

5 files changed

+154
-66
lines changed

misc/acrn-config/board_config/ve820_c.py

Lines changed: 127 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
import sys
77
import board_cfg_lib
88

9-
109
FOUR_GBYTE = 4 * 1024 * 1024 * 1024
1110
LOW_MEM_TO_PCI_HOLE = 0x20000000
1211

1312

14-
def ve820_per_launch(config, hpa_size):
13+
def ve820_per_launch(config, hpa_size, hpa2_size):
1514
"""
1615
Start to generate board.c
1716
:param config: it is a file pointer of board information for writing to
@@ -22,88 +21,137 @@ def ve820_per_launch(config, hpa_size):
2221

2322
board_name = board_cfg_lib.undline_name(board_name)
2423

25-
high_mem_hpa_len = 0x0
2624
low_mem_to_pci_hole_len = '0xA0000000'
2725
low_mem_to_pci_hole = '0x20000000'
2826
pci_hole_addr = '0xe0000000'
2927
pci_hole_len = '0x20000000'
3028
start_low_hpa = 0x100000
31-
if (int(hpa_size, 16) <= 512 * 1024 * 1024):
32-
low_mem_hpa_len = int(hpa_size, 16) - 1 * 1024 * 1024
33-
else:
34-
low_mem_hpa_len = 511 * 1024 * 1024
35-
high_mem_hpa_len = int(hpa_size, 16) - 512 * 1024 * 1024
29+
low_mem_hpa_len = []
30+
high_mem_hpa_len = []
31+
high_mem_hpa2_len = []
32+
high_mem_hpa2_addr = []
3633

3734
# pre_launch memroy: mem_size is the ve820 length
3835
print("#include <e820.h>", file=config)
3936
print("#include <vm.h>", file=config)
4037
print("", file=config)
41-
if (high_mem_hpa_len == 0):
42-
print("#define VE820_ENTRIES_{}\t{}U".format(board_name, 5), file=config)
43-
else:
44-
print("#define VE820_ENTRIES_{}\t{}U".format(board_name, 6), file=config)
45-
46-
print("static const struct e820_entry ve820_entry[{}] = {{".format(
47-
"VE820_ENTRIES_{}".format(board_name)), file=config)
48-
print("\t{\t/* usable RAM under 1MB */", file=config)
49-
print("\t\t.baseaddr = 0x0UL,", file=config)
50-
print("\t\t.length = 0xF0000UL,\t\t/* 960KB */", file=config)
51-
print("\t\t.type = E820_TYPE_RAM", file=config)
52-
print("\t},", file=config)
53-
print("", file=config)
54-
print("\t{\t/* mptable */", file=config)
55-
print("\t\t.baseaddr = 0xF0000UL,\t\t/* 960KB */", file=config)
56-
print("\t\t.length = 0x10000UL,\t\t/* 16KB */", file=config)
57-
print("\t\t.type = E820_TYPE_RESERVED", file=config)
58-
print("\t},", file=config)
59-
print("", file=config)
60-
61-
print("\t{\t/* lowmem */", file=config)
6238

63-
print("\t\t.baseaddr = {}UL,\t\t/* 1MB */".format(
64-
hex(start_low_hpa)), file=config)
65-
print("\t\t.length = {}UL,\t/* {}MB */".format(
66-
hex(low_mem_hpa_len), low_mem_hpa_len / 1024 / 1024), file=config)
39+
for i in range(board_cfg_lib.VM_COUNT):
40+
if (int(hpa_size[i], 16) <= 512 * 1024 * 1024):
41+
low_mem_hpa_len.append(int(hpa_size[i], 16) - 1 * 1024 * 1024)
42+
high_mem_hpa_len.append(0)
43+
else:
44+
low_mem_hpa_len.append(511 * 1024 * 1024)
45+
high_mem_hpa_len.append(int(hpa_size[i], 16) - 512 * 1024 * 1024)
46+
47+
#HPA2 is always allocated in >4G space.
48+
high_mem_hpa2_len.append(int(hpa2_size[i], 16))
49+
if (high_mem_hpa_len[i] != 0) and (high_mem_hpa2_len[i] != 0):
50+
high_mem_hpa2_addr.append(hex(FOUR_GBYTE) + high_mem_hpa_len[i])
51+
else:
52+
high_mem_hpa2_addr.append(hex(FOUR_GBYTE))
53+
54+
if (high_mem_hpa_len[i] != 0) and (high_mem_hpa2_len[i] != 0):
55+
print("#define VM{}_VE820_ENTRIES_{}\t{}U".format(i, board_name, 7), file=config)
56+
elif (high_mem_hpa_len[i] != 0) or (high_mem_hpa2_len[i] != 0):
57+
print("#define VM{}_VE820_ENTRIES_{}\t{}U".format(i, board_name, 6), file=config)
58+
else:
59+
print("#define VM{}_VE820_ENTRIES_{}\t{}U".format(i, board_name, 5), file=config)
60+
61+
for i in range(board_cfg_lib.VM_COUNT):
62+
print("static const struct e820_entry vm{}_ve820_entry[{}] = {{".format(
63+
i, "VM{}_VE820_ENTRIES_{}".format(i, board_name)), file=config)
64+
print("\t{\t/* usable RAM under 1MB */", file=config)
65+
print("\t\t.baseaddr = 0x0UL,", file=config)
66+
print("\t\t.length = 0xF0000UL,\t\t/* 960KB */", file=config)
67+
print("\t\t.type = E820_TYPE_RAM", file=config)
68+
print("\t},", file=config)
69+
print("", file=config)
70+
print("\t{\t/* mptable */", file=config)
71+
print("\t\t.baseaddr = 0xF0000UL,\t\t/* 960KB */", file=config)
72+
print("\t\t.length = 0x10000UL,\t\t/* 64KB */", file=config)
73+
print("\t\t.type = E820_TYPE_RESERVED", file=config)
74+
print("\t},", file=config)
75+
print("", file=config)
6776

68-
print("\t\t.type = E820_TYPE_RAM", file=config)
69-
print("\t},", file=config)
70-
print("", file=config)
77+
print("\t{\t/* lowmem */", file=config)
7178

72-
print("\t{\t/* between lowmem and PCI hole */", file=config)
73-
print("\t\t.baseaddr = {}UL,\t/* {}MB */".format(
74-
low_mem_to_pci_hole, int(low_mem_to_pci_hole, 16) / 1024 / 1024), file=config)
75-
print("\t\t.length = {}UL,\t/* {}MB */".format(
76-
low_mem_to_pci_hole_len, int(low_mem_to_pci_hole_len, 16) / 1024 / 1024), file=config)
77-
print("\t\t.type = E820_TYPE_RESERVED", file=config)
78-
print("\t},", file=config)
79-
print("", file=config)
80-
print("\t{\t/* between PCI hole and 4 GB */", file=config)
81-
print("\t\t.baseaddr = {}UL,\t/* {}GB */".format(
82-
hex(int(pci_hole_addr, 16)), int(pci_hole_addr, 16) / 1024 / 1024 / 1024), file=config)
83-
print("\t\t.length = {}UL,\t/* {}MB */".format(
84-
hex(int(pci_hole_len, 16)), int(pci_hole_len, 16) / 1024 / 1024), file=config)
85-
print("\t\t.type = E820_TYPE_RESERVED", file=config)
86-
print("\t},", file=config)
87-
print("", file=config)
88-
if (high_mem_hpa_len != 0):
89-
print("\t{\t/* high mem after 4GB*/", file=config)
90-
print("\t\t.baseaddr = {}UL,\t/* 4 GB */".format(
91-
hex(FOUR_GBYTE)), file=config)
79+
print("\t\t.baseaddr = {}UL,\t\t/* 1MB */".format(
80+
hex(start_low_hpa)), file=config)
9281
print("\t\t.length = {}UL,\t/* {}MB */".format(
93-
hex(high_mem_hpa_len), high_mem_hpa_len / 1024 / 1024), file=config)
82+
hex(low_mem_hpa_len[i]), low_mem_hpa_len[i] / 1024 / 1024), file=config)
83+
9484
print("\t\t.type = E820_TYPE_RAM", file=config)
9585
print("\t},", file=config)
9686
print("", file=config)
9787

98-
print("};", file=config)
99-
print("", file=config)
88+
print("\t{\t/* between lowmem and PCI hole */", file=config)
89+
print("\t\t.baseaddr = {}UL,\t/* {}MB */".format(
90+
low_mem_to_pci_hole, int(low_mem_to_pci_hole, 16) / 1024 / 1024), file=config)
91+
print("\t\t.length = {}UL,\t/* {}MB */".format(
92+
low_mem_to_pci_hole_len, int(low_mem_to_pci_hole_len, 16) / 1024 / 1024), file=config)
93+
print("\t\t.type = E820_TYPE_RESERVED", file=config)
94+
print("\t},", file=config)
95+
print("", file=config)
96+
print("\t{\t/* between PCI hole and 4 GB */", file=config)
97+
print("\t\t.baseaddr = {}UL,\t/* {}GB */".format(
98+
hex(int(pci_hole_addr, 16)), int(pci_hole_addr, 16) / 1024 / 1024 / 1024), file=config)
99+
print("\t\t.length = {}UL,\t/* {}MB */".format(
100+
hex(int(pci_hole_len, 16)), int(pci_hole_len, 16) / 1024 / 1024), file=config)
101+
print("\t\t.type = E820_TYPE_RESERVED", file=config)
102+
print("\t},", file=config)
103+
print("", file=config)
104+
if (high_mem_hpa_len[i] != 0) and (high_mem_hpa2_len[i] != 0):
105+
print("\t{\t/* high mem after 4GB*/", file=config)
106+
print("\t\t.baseaddr = {}UL,\t/* 4 GB */".format(
107+
hex(FOUR_GBYTE)), file=config)
108+
print("\t\t.length = {}UL,\t/* {}MB */".format(
109+
hex(high_mem_hpa_len[i]), high_mem_hpa_len[i] / 1024 / 1024), file=config)
110+
print("\t\t.type = E820_TYPE_RAM", file=config)
111+
print("\t},", file=config)
112+
print("", file=config)
113+
print("\t{\t/* HPA2 after high mem*/", file=config)
114+
print("\t\t.baseaddr = {}UL,\t/* {}GB */".format(
115+
hex(high_mem_hpa2_addr[i]), int(high_mem_hpa2_addr[i], 16) / 1024 / 1024 / 1024), file=config)
116+
print("\t\t.length = {}UL,\t/* {}MB */".format(
117+
hex(high_mem_hpa_len[i]), high_mem_hpa_len[i] / 1024 / 1024), file=config)
118+
print("\t\t.type = E820_TYPE_RAM", file=config)
119+
print("\t},", file=config)
120+
print("", file=config)
121+
elif (high_mem_hpa_len[i] != 0):
122+
print("\t{\t/* high mem after 4GB*/", file=config)
123+
print("\t\t.baseaddr = {}UL,\t/* 4 GB */".format(
124+
hex(FOUR_GBYTE)), file=config)
125+
print("\t\t.length = {}UL,\t/* {}MB */".format(
126+
hex(high_mem_hpa_len[i]), high_mem_hpa_len[i] / 1024 / 1024), file=config)
127+
print("\t\t.type = E820_TYPE_RAM", file=config)
128+
print("\t},", file=config)
129+
print("", file=config)
130+
elif(high_mem_hpa2_len[i] != 0):
131+
print("\t{\t/* HPA2 after 4GB*/", file=config)
132+
print("\t\t.baseaddr = {}UL,\t/* 4 GB */".format(
133+
hex(FOUR_GBYTE)), file=config)
134+
print("\t\t.length = {}UL,\t/* {}MB */".format(
135+
hex(high_mem_hpa2_len[i]), high_mem_hpa2_len[i] / 1024 / 1024), file=config)
136+
print("\t\t.type = E820_TYPE_RAM", file=config)
137+
print("\t},", file=config)
138+
print("", file=config)
139+
print("};", file=config)
140+
print("", file=config)
141+
100142
print("/**", file=config)
101143
print(" * @pre vm != NULL", file=config)
102144
print("*/", file=config)
103145
print("void create_prelaunched_vm_e820(struct acrn_vm *vm)", file=config)
104146
print("{", file=config)
105-
print("\tvm->e820_entry_num = VE820_ENTRIES_{};".format(board_name), file=config)
106-
print("\tvm->e820_entries = ve820_entry;", file=config)
147+
for i in range(board_cfg_lib.VM_COUNT):
148+
print("\tif (vm->vm_id == {}U)".format(hex(i)), file=config)
149+
print("\t{", file=config)
150+
print("\t\tvm->e820_entry_num = VM{}_VE820_ENTRIES_{};".format(i, board_name), file=config)
151+
print("\t\tvm->e820_entries = vm{}_ve820_entry;".format(i), file=config)
152+
print("\t}", file=config)
153+
print("", file=config)
154+
107155
print("}", file=config)
108156

109157
return err_dic
@@ -144,9 +192,24 @@ def generate_file(config):
144192
err_dic['board config: generate ve820.c failed'] = "Unknow type of host physical address size"
145193
return err_dic
146194

147-
hpa_size = hpa_size_list[0]
148-
if pre_vm_cnt != 0 and ('0x' in hpa_size or '0X' in hpa_size):
149-
err_dic = ve820_per_launch(config, hpa_size)
195+
# read HPA2 mem size from scenario.xml
196+
hpa2_size_list = board_cfg_lib.get_sub_leaf_tag(
197+
board_cfg_lib.SCENARIO_INFO_FILE, "memory", "size_hpa2")
198+
ret = board_cfg_lib.is_hpa_size(hpa2_size_list)
199+
if not ret:
200+
board_cfg_lib.print_red("Unknow type of second host physical address size", err=True)
201+
err_dic['board config: generate ve820.c failed'] = "Unknow type of second host physical address size"
202+
return err_dic
203+
204+
# HPA size for both VMs should have valid length.
205+
for i in range(board_cfg_lib.VM_COUNT):
206+
if hpa_size_list[i] == '0x0' or hpa_size_list[i] == '0X0':
207+
board_cfg_lib.print_red("HPA size should not be zero", err=True)
208+
err_dic['board config: generate ve820.c failed'] = "HPA size should not be zero"
209+
return err_dic
210+
211+
if pre_vm_cnt != 0:
212+
err_dic = ve820_per_launch(config, hpa_size_list, hpa2_size_list)
150213
else:
151214
non_ve820_pre_launch(config)
152215

misc/acrn-config/scenario_config/scenario_item.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class MemInfo:
179179
""" This is Abstract of class of memory setting information """
180180
mem_start_hpa = {}
181181
mem_size = {}
182+
mem_start_hpa2 = {}
183+
mem_size_hpa2 = {}
182184

183185
def __init__(self, scenario_file):
184186
self.scenario_info = scenario_file
@@ -192,6 +194,10 @@ def get_info(self):
192194
self.scenario_info, "memory", "start_hpa")
193195
self.mem_size = scenario_cfg_lib.get_leaf_tag_map(
194196
self.scenario_info, "memory", "size")
197+
self.mem_start_hpa2 = scenario_cfg_lib.get_leaf_tag_map(
198+
self.scenario_info, "memory", "start_hpa2")
199+
self.mem_size_hpa2 = scenario_cfg_lib.get_leaf_tag_map(
200+
self.scenario_info, "memory", "size_hpa2")
195201

196202
def check_item(self):
197203
"""
@@ -200,6 +206,8 @@ def check_item(self):
200206
"""
201207
scenario_cfg_lib.mem_start_hpa_check(self.mem_start_hpa, "memory", "start_hpa")
202208
scenario_cfg_lib.mem_size_check(self.mem_size, "memory", "size")
209+
scenario_cfg_lib.mem_start_hpa_check(self.mem_start_hpa2, "memory", "start_hpa2")
210+
scenario_cfg_lib.mem_size_check(self.mem_size_hpa2, "memory", "size_hpa2")
203211

204212

205213
class CfgPci:

misc/acrn-config/scenario_config/vm_configurations_c.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ def gen_logical_partition_source(vm_info, config):
463463
print("\t\t.memory = {", file=config)
464464
print("\t\t\t.start_hpa = VM{0}_CONFIG_MEM_START_HPA,".format(i), file=config)
465465
print("\t\t\t.size = VM{0}_CONFIG_MEM_SIZE,".format(i), file=config)
466+
print("\t\t\t.start_hpa2 = VM{0}_CONFIG_MEM_START_HPA2,".format(i), file=config)
467+
print("\t\t\t.size_hpa2 = VM{0}_CONFIG_MEM_SIZE_HPA2,".format(i), file=config)
466468
print("\t\t},", file=config)
467469
is_need_epc(vm_info.epc_section, i, config)
468470
print("\t\t.os_config = {", file=config)
@@ -600,6 +602,8 @@ def gen_hybrid_source(vm_info, config):
600602
if i == 0:
601603
print("\t\t\t.start_hpa = VM0_CONFIG_MEM_START_HPA,", file=config)
602604
print("\t\t\t.size = VM0_CONFIG_MEM_SIZE,", file=config)
605+
print("\t\t\t.start_hpa2 = VM0_CONFIG_MEM_START_HPA2,", file=config)
606+
print("\t\t\t.size_hpa2 = VM0_CONFIG_MEM_SIZE_HPA2,", file=config)
603607
elif i == 1:
604608
print("\t\t\t.start_hpa = 0UL,", file=config)
605609
print("\t\t\t.size = CONFIG_SOS_RAM_SIZE,", file=config)

misc/acrn-config/scenario_config/vm_configurations_h.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def logic_max_vm_num(config):
138138
print(" *\tVMX_CONFIG_VCPU_AFFINITY", file=config)
139139
print(" *\tVMX_CONFIG_MEM_START_HPA", file=config)
140140
print(" *\tVMX_CONFIG_MEM_SIZE", file=config)
141+
print(" *\tVMX_CONFIG_MEM_START_HPA2", file=config)
142+
print(" *\tVMX_CONFIG_MEM_SIZE_HPA2", file=config)
141143
print(" *\tVMX_CONFIG_OS_BOOTARG_ROOT", file=config)
142144
print(" *\tVMX_CONFIG_OS_BOOTARG_MAX_CPUS", file=config)
143145
print(" *\tVMX_CONFIG_OS_BOOTARG_CONSOLE", file=config)
@@ -171,7 +173,11 @@ def gen_logical_partition_header(vm_info, config):
171173
print("#define VM{0}_CONFIG_MEM_START_HPA\t\t{1}UL".format(
172174
i, vm_info.mem_info.mem_start_hpa[i]), file=config)
173175
print("#define VM{0}_CONFIG_MEM_SIZE\t\t\t{1}UL".format(
174-
i, vm_info.mem_info.mem_size[0]), file=config)
176+
i, vm_info.mem_info.mem_size[i]), file=config)
177+
print("#define VM{0}_CONFIG_MEM_START_HPA2\t\t{1}UL".format(
178+
i, vm_info.mem_info.mem_start_hpa2[i]), file=config)
179+
print("#define VM{0}_CONFIG_MEM_SIZE_HPA2\t\t\t{1}UL".format(
180+
i, vm_info.mem_info.mem_size_hpa2[i]), file=config)
175181
print('#define VM{0}_CONFIG_OS_BOOTARG_ROOT\t\t"root={1} "'.format(
176182
i, vm_info.os_cfg.kern_root_dev[i]), file=config)
177183
print('#define VM{0}_CONFIG_OS_BOOTARG_MAXCPUS\t\t"maxcpus={1} "'.format(
@@ -271,6 +277,9 @@ def gen_hybrid_header(vm_info, config):
271277
print("#define VM0_CONFIG_MEM_START_HPA\t{0}UL".format(
272278
vm_info.mem_info.mem_start_hpa[0]), file=config)
273279
print("#define VM0_CONFIG_MEM_SIZE\t\t{0}UL".format(vm_info.mem_info.mem_size[0]), file=config)
280+
print("#define VM0_CONFIG_MEM_START_HPA2\t{0}UL".format(
281+
vm_info.mem_info.mem_start_hpa2[0]), file=config)
282+
print("#define VM0_CONFIG_MEM_SIZE_HPA2\t\t{0}UL".format(vm_info.mem_info.mem_size_hpa2[0]), file=config)
274283
print("", file=config)
275284
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
276285
print('\t\t\t\t\t"rw rootwait "\t\\', file=config)

misc/acrn-config/xmls/config-xmls/generic/logical_partition.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<memory>
2020
<start_hpa desc="The start physical address in host for the VM">0x100000000</start_hpa>
2121
<size desc="The memory size in Bytes for the VM">0x20000000</size>
22+
<start_hpa2 desc="The start physical address in host for the VM">0x0</start_hpa2>
23+
<size_hpa2 desc="The memory size in Bytes for the VM">0x0</size_hpa2>
2224
</memory>
2325
<os_config>
2426
<name desc="Specify the OS name of VM, currently it is not referenced by hypervisor code.">ClearLinux</name>
@@ -65,7 +67,9 @@
6567
</epc_section>
6668
<memory>
6769
<start_hpa desc="The start physical address in host for the VM">0x120000000</start_hpa>
68-
<size desc="The memory size in Bytes for the VM" readonly="true">0x20000000</size>
70+
<size desc="The memory size in Bytes for the VM">0x20000000</size>
71+
<start_hpa2 desc="The start physical address in host for the VM">0x0</start_hpa2>
72+
<size_hpa2 desc="The memory size in Bytes for the VM">0x0</size_hpa2>
6973
</memory>
7074
<os_config>
7175
<name desc="Specify the OS name of VM, currently it is not referenced by hypervisor code.">ClearLinux</name>

0 commit comments

Comments
 (0)