Skip to content

Commit 2b22e88

Browse files
binbinwu1lijinxia
authored andcommitted
hv: init: rm the code of creating guest init page table
If SOS start from 64bit mode, it will use the page table created by bootloader or BIOS. HV doesn't need to create page table for it. Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 33e1149 commit 2b22e88

File tree

2 files changed

+0
-141
lines changed

2 files changed

+0
-141
lines changed

hypervisor/arch/x86/guest/guest.c

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -707,136 +707,6 @@ uint64_t e820_alloc_low_memory(uint32_t size_arg)
707707
return ACRN_INVALID_HPA;
708708
}
709709

710-
#ifdef CONFIG_START_VM0_BSP_64BIT
711-
/*******************************************************************
712-
* GUEST initial page table
713-
*
714-
* guest starts with long mode, HV needs to prepare Guest identity
715-
* mapped page table.
716-
* For SOS:
717-
* Guest page tables cover 0~4G space with 2M page size, will use
718-
* 6 pages memory for page tables.
719-
* For UOS(Trusty not enabled):
720-
* Guest page tables cover 0~4G space with 2M page size, will use
721-
* 6 pages memory for page tables.
722-
* For UOS(Trusty enabled):
723-
* Guest page tables cover 0~4G and trusy memory space with 2M page size,
724-
* will use 7 pages memory for page tables.
725-
* This API assume that the trusty memory is remapped to guest physical address
726-
* of 511G to 511G + 16MB
727-
*
728-
* FIXME: here the guest init page table will occupy at most
729-
* GUEST_INIT_PT_PAGE_NUM pages. Some check here:
730-
* - guest page table space should not override trampoline code area
731-
* (it's a little tricky here, as under current identical mapping, HV & SOS
732-
* share same memory under 1M; under uefi boot mode, the defered AP startup
733-
* need trampoline code area which reserved by uefi stub keep there
734-
* no change even after SOS startup)
735-
* - guest page table space should not override possible RSDP fix segment
736-
*
737-
* Anyway, it's a tmp solution, the init page tables should be totally removed
738-
* after guest realmode/32bit no paging mode got supported.
739-
******************************************************************/
740-
#define GUEST_INIT_PAGE_TABLE_SKIP_SIZE 0x8000UL
741-
#define GUEST_INIT_PAGE_TABLE_START (trampoline_start16_paddr + \
742-
GUEST_INIT_PAGE_TABLE_SKIP_SIZE)
743-
#define GUEST_INIT_PT_PAGE_NUM 7
744-
#define RSDP_F_ADDR 0xE0000
745-
uint64_t create_guest_initial_paging(struct vm *vm)
746-
{
747-
uint64_t i = 0;
748-
uint64_t entry = 0;
749-
uint64_t entry_num = 0;
750-
uint64_t pdpt_base_paddr = 0;
751-
uint64_t pd_base_paddr = 0;
752-
uint64_t table_present = 0;
753-
uint64_t table_offset = 0;
754-
void *addr = NULL;
755-
void *pml4_addr = GPA2HVA(vm, GUEST_INIT_PAGE_TABLE_START);
756-
757-
ASSERT((GUEST_INIT_PAGE_TABLE_START + 7 * PAGE_SIZE_4K) <
758-
RSDP_F_ADDR, "RSDP fix segment could be override");
759-
760-
if (GUEST_INIT_PAGE_TABLE_SKIP_SIZE <
761-
(unsigned long)&_ld_trampoline_size) {
762-
panic("guest init PTs override trampoline code");
763-
}
764-
765-
/* Using continuous memory for guest page tables, the total 4K page
766-
* number for it(without trusty) is GUEST_INIT_PT_PAGE_NUM-1.
767-
* here make sure they are init as 0 (page entry no present)
768-
*/
769-
(void)memset(pml4_addr, 0U, PAGE_SIZE_4K * GUEST_INIT_PT_PAGE_NUM-1);
770-
771-
/* Write PML4E */
772-
table_present = (IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT);
773-
/* PML4 used 1 page, skip it to fetch PDPT */
774-
pdpt_base_paddr = GUEST_INIT_PAGE_TABLE_START + PAGE_SIZE_4K;
775-
entry = pdpt_base_paddr | table_present;
776-
mem_write64(pml4_addr, entry);
777-
778-
/* Write PDPTE, PDPT used 1 page, skip it to fetch PD */
779-
pd_base_paddr = pdpt_base_paddr + PAGE_SIZE_4K;
780-
addr = pml4_addr + PAGE_SIZE_4K;
781-
/* Guest page tables cover 0~4G space with 2M page size */
782-
for (i = 0; i < 4; i++) {
783-
entry = ((pd_base_paddr + (i * PAGE_SIZE_4K))
784-
| table_present);
785-
mem_write64(addr, entry);
786-
addr += IA32E_COMM_ENTRY_SIZE;
787-
}
788-
789-
/* Write PDE, PT used 4 pages */
790-
table_present = (IA32E_PDPTE_PS_BIT
791-
| IA32E_COMM_P_BIT
792-
| IA32E_COMM_RW_BIT);
793-
/* Totally 2048(512*4) entries with 2M page size for 0~4G*/
794-
entry_num = IA32E_NUM_ENTRIES * 4;
795-
addr = pml4_addr + 2 * PAGE_SIZE_4K;
796-
for (i = 0; i < entry_num; i++) {
797-
entry = (i * (1 << MMU_PDE_PAGE_SHIFT)) | table_present;
798-
mem_write64(addr, entry);
799-
addr += IA32E_COMM_ENTRY_SIZE;
800-
}
801-
802-
/* For UOS, if trusty is enabled,
803-
* need to setup tempory page table for trusty
804-
* FIXME: this is a tempory solution for trusty enabling,
805-
* the final solution is that vSBL will setup guest page tables
806-
*/
807-
if (vm->sworld_control.flag.supported && !is_vm0(vm)) {
808-
/* clear page entry for trusty */
809-
(void)memset(pml4_addr + 6U * PAGE_SIZE_4K, 0U, PAGE_SIZE_4K);
810-
811-
/* Write PDPTE for trusy memory, PD will use 7th page */
812-
pd_base_paddr = GUEST_INIT_PAGE_TABLE_START +
813-
(6 * PAGE_SIZE_4K);
814-
table_offset =
815-
IA32E_PDPTE_INDEX_CALC(TRUSTY_EPT_REBASE_GPA);
816-
addr = (pml4_addr + PAGE_SIZE_4K + table_offset);
817-
table_present = (IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT);
818-
entry = (pd_base_paddr | table_present);
819-
mem_write64(addr, entry);
820-
821-
/* Write PDE for trusty with 2M page size */
822-
entry_num = TRUSTY_MEMORY_SIZE / (1 << MMU_PDE_PAGE_SHIFT);
823-
addr = pml4_addr + 6 * PAGE_SIZE_4K;
824-
table_present = (IA32E_PDPTE_PS_BIT
825-
| IA32E_COMM_P_BIT
826-
| IA32E_COMM_RW_BIT);
827-
for (i = 0; i < entry_num; i++) {
828-
entry = (TRUSTY_EPT_REBASE_GPA +
829-
(i * (1 << MMU_PDE_PAGE_SHIFT)))
830-
| table_present;
831-
mem_write64(addr, entry);
832-
addr += IA32E_COMM_ENTRY_SIZE;
833-
}
834-
}
835-
836-
return GUEST_INIT_PAGE_TABLE_START;
837-
}
838-
#endif
839-
840710
/*******************************************************************
841711
* GUEST initial GDT table
842712
*

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,6 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
222222
vcpu->pcpu_id, vcpu->vm->vm_id, vcpu->vcpu_id,
223223
is_vcpu_bsp(vcpu) ? "PRIMARY" : "SECONDARY");
224224

225-
#ifdef CONFIG_START_VM0_BSP_64BIT
226-
/* Is this VCPU a VM0 BSP, create page hierarchy for this VM */
227-
if (is_vcpu_bsp(vcpu) && is_vm0(vcpu->vm)) {
228-
/* Set up temporary guest page tables */
229-
vm->arch_vm.guest_init_pml4 = create_guest_initial_paging(vm);
230-
pr_info("VM %d VCPU %hu CR3: 0x%016llx ",
231-
vm->vm_id, vcpu->vcpu_id,
232-
vm->arch_vm.guest_init_pml4);
233-
}
234-
#endif
235-
236225
vcpu->arch_vcpu.vpid = allocate_vpid();
237226

238227
/* Allocate VMCS region for this VCPU */

0 commit comments

Comments
 (0)