Skip to content

Commit 2b35c07

Browse files
ZideChen0wenlingz
authored andcommitted
hv: do EPT mapping only for physical memory backed GPA on pre-launched VMs
Currently for pre-launched VMs, HV intends to do EPT mapping for all GPA space, which implies that it wastes HPA to back PCI hole and other vE820 entries that are not backed by physical memory. This patch solves this issue and fixes ve820 entries whose length is not aligned to 4K, and changes the lowmem entry's start GPA from 1MB to 2MB. Tracked-On: #2587 Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent da14c96 commit 2b35c07

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

hypervisor/arch/x86/configs/apl-mrb/ve820.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
#include <e820.h>
88

99
const struct e820_entry ve820_entry[E820_MAX_ENTRIES] = {
10-
{ /* 0 to mptable */
10+
{ /* usable RAM under 1MB */
1111
.baseaddr = 0x0UL,
12-
.length = 0xEFFFFUL,
12+
.length = 0xF0000UL, /* 960KB */
1313
.type = E820_TYPE_RAM
1414
},
1515

16-
{ /* mptable 65536U */
17-
.baseaddr = 0xF0000UL,
18-
.length = 0x10000UL,
16+
{ /* mptable */
17+
.baseaddr = 0xF0000UL, /* 960KB */
18+
.length = 0x10000UL, /* 16KB */
1919
.type = E820_TYPE_RESERVED
2020
},
2121

22-
{ /* mptable to lowmem */
23-
.baseaddr = 0x100000UL,
24-
.length = 0x1FF00000UL,
22+
{ /* lowmem */
23+
.baseaddr = 0x200000UL, /* 2MB */
24+
.length = 0x1FE00000UL, /* 510MB */
2525
.type = E820_TYPE_RAM
2626
},
2727

28-
{ /* lowmem to PCI hole */
29-
.baseaddr = 0x20000000UL,
30-
.length = 0xa0000000UL,
28+
{ /* between lowmem and PCI hole */
29+
.baseaddr = 0x20000000UL, /* 512MB */
30+
.length = 0xA0000000UL, /* 2560MB */
3131
.type = E820_TYPE_RESERVED
3232
},
3333

34-
{ /* PCI hole to 4G */
35-
.baseaddr = 0xe0000000UL,
36-
.length = 0x20000000UL,
34+
{ /* between PCI hole and 4GB */
35+
.baseaddr = 0xe0000000UL, /* 3.5GB */
36+
.length = 0x20000000UL, /* 512MB */
3737
.type = E820_TYPE_RESERVED
3838
},
3939
};

hypervisor/arch/x86/configs/dnv-cb2/ve820.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
#include <e820.h>
88

99
const struct e820_entry ve820_entry[E820_MAX_ENTRIES] = {
10-
{ /* 0 to mptable */
10+
{ /* usable RAM under 1MB */
1111
.baseaddr = 0x0UL,
12-
.length = 0xEFFFFUL,
12+
.length = 0xF0000UL, /* 960KB */
1313
.type = E820_TYPE_RAM
1414
},
1515

16-
{ /* mptable 65536U */
17-
.baseaddr = 0xF0000UL,
18-
.length = 0x10000UL,
16+
{ /* mptable */
17+
.baseaddr = 0xF0000UL, /* 960KB */
18+
.length = 0x10000UL, /* 16KB */
1919
.type = E820_TYPE_RESERVED
2020
},
2121

22-
{ /* mptable to lowmem */
23-
.baseaddr = 0x100000UL,
24-
.length = 0x7FF00000UL,
22+
{ /* lowmem */
23+
.baseaddr = 0x200000UL, /* 2MB */
24+
.length = 0x7FE00000UL, /* 2046MB */
2525
.type = E820_TYPE_RAM
2626
},
2727

28-
{ /* lowmem to PCI hole */
29-
.baseaddr = 0x80000000UL,
30-
.length = 0x40000000UL,
28+
{ /* between lowmem and PCI hole */
29+
.baseaddr = 0x80000000UL, /* 2GB */
30+
.length = 0x40000000UL, /* 1GB */
3131
.type = E820_TYPE_RESERVED
3232
},
3333

34-
{ /* PCI hole to 4G */
35-
.baseaddr = 0xe0000000UL,
36-
.length = 0x20000000UL,
34+
{ /* between PCI hole and 4GB */
35+
.baseaddr = 0xe0000000UL, /* 3.5GB */
36+
.length = 0x20000000UL, /* 512MB */
3737
.type = E820_TYPE_RESERVED
3838
},
3939
};

hypervisor/arch/x86/guest/vm.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,39 @@ static void create_prelaunched_vm_e820(struct acrn_vm *vm)
141141
vm->e820_entry_num = E820_MAX_ENTRIES;
142142
vm->e820_entries = (struct e820_entry *)ve820_entry;
143143
}
144+
145+
/**
146+
* @pre vm != NULL && vm_config != NULL
147+
*/
148+
static void prepare_prelaunched_vm_memmap(struct acrn_vm *vm, const struct acrn_vm_config *vm_config)
149+
{
150+
uint64_t base_hpa = vm_config->memory.start_hpa;
151+
uint32_t i;
152+
153+
for (i = 0U; i < vm->e820_entry_num; i++) {
154+
struct e820_entry *entry = &(vm->e820_entries[i]);
155+
156+
if (entry->length == 0UL) {
157+
break;
158+
}
159+
160+
/* Do EPT mapping for GPAs that are backed by physical memory */
161+
if (entry->type == E820_TYPE_RAM) {
162+
ept_mr_add(vm, (uint64_t *)vm->arch_vm.nworld_eptp, base_hpa, entry->baseaddr,
163+
entry->length, EPT_RWX | EPT_WB);
164+
165+
base_hpa += entry->length;
166+
}
167+
168+
/* GPAs under 1MB are always backed by physical memory */
169+
if ((entry->type != E820_TYPE_RAM) && (entry->baseaddr < (uint64_t)MEM_1M)) {
170+
ept_mr_add(vm, (uint64_t *)vm->arch_vm.nworld_eptp, base_hpa, entry->baseaddr,
171+
entry->length, EPT_RWX | EPT_UNCACHED);
172+
173+
base_hpa += entry->length;
174+
}
175+
}
176+
}
144177
#endif
145178

146179
/**
@@ -324,9 +357,7 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
324357
&vm_config->GUID[0], sizeof(vm_config->GUID));
325358
#ifdef CONFIG_PARTITION_MODE
326359
create_prelaunched_vm_e820(vm);
327-
ept_mr_add(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
328-
vm_config->memory.start_hpa, 0UL, vm_config->memory.size,
329-
EPT_RWX|EPT_WB);
360+
prepare_prelaunched_vm_memmap(vm, vm_config);
330361
(void)init_vm_boot_info(vm);
331362
#endif
332363
}

0 commit comments

Comments
 (0)