Skip to content

Commit 2a1a6ad

Browse files
ZideChen0lijinxia
authored andcommitted
hv: Other preparation for trampoline code relocation
- For UEFI boot, allocate memory for trampoline code in ACRN EFI, and pass the pointer to HV through efi_ctx - Correct LOW_RAM_SIZE and LOW_RAM_START in Kconfig and bsp_cfg.h - use trampline_start16_paddr instead of the hardcoded CONFIG_LOW_RAM_START for initial guest GDT and page tables Signed-off-by: Zheng, Gen <gen.zheng@intel.com> Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com> Acked-by: Xu, Anthony <anthony.xu@intel.com>
1 parent 40c8c4d commit 2a1a6ad

File tree

10 files changed

+24
-21
lines changed

10 files changed

+24
-21
lines changed

hypervisor/arch/x86/Kconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,9 @@ config MEM_LOGLEVEL_DEFAULT
7474
int "Default loglevel in memory"
7575
default 4
7676

77-
config LOW_RAM_START
78-
hex "Address of the beginning of low RAM region"
79-
default 0x00001000 if PLATFORM_SBL
80-
default 0x00008000 if PLATFORM_UEFI
81-
8277
config LOW_RAM_SIZE
8378
hex "Size of the low RAM region"
84-
default 0x000cf000 if PLATFORM_SBL
85-
default 0x00010000 if PLATFORM_UEFI
79+
default 0x00010000
8680

8781
config RAM_START
8882
hex "Address of the RAM region assigned to the hypervisor"

hypervisor/arch/x86/cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ volatile uint32_t up_count = 0;
2626
/* physical cpu active bitmap, support up to 64 cpus */
2727
uint64_t pcpu_active_bitmap = 0;
2828

29+
uint64_t trampline_start16_paddr;
30+
2931
/* TODO: add more capability per requirement */
3032
/*APICv features*/
3133
#define VAPIC_FEATURE_VIRT_ACCESS (1 << 0)

hypervisor/arch/x86/guest/guest.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,8 @@ uint64_t e820_alloc_low_memory(uint32_t size)
674674
* This API assume that the trusty memory is remapped to guest physical address
675675
* of 511G to 511G + 16MB
676676
*
677-
* FIXME: here using hard code GUEST_INIT_PAGE_TABLE_START as guest init page
678-
* table gpa start, and it will occupy at most GUEST_INIT_PT_PAGE_NUM pages.
679-
* Some check here:
677+
* FIXME: here the guest init page table will occupy at most
678+
* GUEST_INIT_PT_PAGE_NUM pages. Some check here:
680679
* - guest page table space should not override trampline code area
681680
* (it's a little tricky here, as under current identical mapping, HV & SOS
682681
* share same memory under 1M; under uefi boot mode, the defered AP startup
@@ -688,7 +687,7 @@ uint64_t e820_alloc_low_memory(uint32_t size)
688687
* after guest realmode/32bit no paging mode got supported.
689688
******************************************************************/
690689
#define GUEST_INIT_PAGE_TABLE_SKIP_SIZE 0x8000UL
691-
#define GUEST_INIT_PAGE_TABLE_START (CONFIG_LOW_RAM_START + \
690+
#define GUEST_INIT_PAGE_TABLE_START (trampline_start16_paddr + \
692691
GUEST_INIT_PAGE_TABLE_SKIP_SIZE)
693692
#define GUEST_INIT_PT_PAGE_NUM 7
694693
#define RSDP_F_ADDR 0xE0000
@@ -794,7 +793,7 @@ uint64_t create_guest_initial_paging(struct vm *vm)
794793
******************************************************************/
795794

796795
#define GUEST_INIT_GDT_SKIP_SIZE 0x8000UL
797-
#define GUEST_INIT_GDT_START (CONFIG_LOW_RAM_START + \
796+
#define GUEST_INIT_GDT_START (trampline_start16_paddr + \
798797
GUEST_INIT_GDT_SKIP_SIZE)
799798

800799
/* The GDT defined below compatible with linux kernel */

hypervisor/bsp/sbl/include/bsp/bsp_cfg.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#define HEAP_SIZE 0x100000
1818
#define CONSOLE_LOGLEVEL_DEFAULT 3
1919
#define MEM_LOGLEVEL_DEFAULT 5
20-
#define CONFIG_LOW_RAM_START 0x00001000
21-
#define CONFIG_LOW_RAM_SIZE 0x000CF000
20+
#define CONFIG_LOW_RAM_SIZE 0x00010000
2221
#define CONFIG_RAM_START 0x6E000000
2322
#define CONFIG_RAM_SIZE 0x02000000 /* 32M */
2423
#define CONFIG_MTRR_ENABLED 1

hypervisor/bsp/uefi/efi/boot.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ construct_mbi(struct multiboot_info **mbi_ret, struct efi_ctx *efi_ctx)
190190
mmap[j].mm_type = E820_RAM;
191191
j++;
192192

193-
/* reserve secondary memory region(0x1000 ~ 0x10000) for hv */
194-
err = __emalloc(CONFIG_LOW_RAM_SIZE, CONFIG_LOW_RAM_START,
195-
&addr, EfiReservedMemoryType);
196-
if (err != EFI_SUCCESS)
197-
goto out;
198-
199193
mbi->mi_flags |= MULTIBOOT_INFO_HAS_MMAP | MULTIBOOT_INFO_HAS_CMDLINE;
200194
mbi->mi_mmap_length = j*sizeof(struct multiboot_mmap);
201195

@@ -227,6 +221,13 @@ switch_to_guest_mode(EFI_HANDLE image)
227221

228222
efi_ctx = (struct efi_ctx *)(UINTN)addr;
229223

224+
/* reserve secondary memory region for hv */
225+
err = emalloc_for_low_mem(&addr, CONFIG_LOW_RAM_SIZE);
226+
if (err != EFI_SUCCESS)
227+
goto out;
228+
229+
efi_ctx->ap_trampline_buf = (void *)addr;
230+
230231
config_table = sys_table->ConfigurationTable;
231232

232233
for (i = 0; i < sys_table->NumberOfTableEntries; i++) {

hypervisor/bsp/uefi/efi/boot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct e820_entry {
9595
struct efi_ctx {
9696
uint64_t rip;
9797
VOID *rsdp;
98+
VOID *ap_trampline_buf;
9899
dt_addr_t gdt;
99100
dt_addr_t idt;
100101
uint16_t tr_sel;

hypervisor/bsp/uefi/include/bsp/bsp_cfg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#define HEAP_SIZE 0x100000
1818
#define CONSOLE_LOGLEVEL_DEFAULT 3
1919
#define MEM_LOGLEVEL_DEFAULT 5
20-
#define CONFIG_LOW_RAM_START 0x00008000
2120
#define CONFIG_LOW_RAM_SIZE 0x00010000
2221
#define CONFIG_RAM_START 0x20000000
2322
#define CONFIG_RAM_SIZE 0x02000000 /* 32M */

hypervisor/bsp/uefi/uefi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ void *get_rsdp_from_uefi(void)
9797
return HPA2HVA(efi_ctx->rsdp);
9898
}
9999

100+
void *get_ap_trampline_buf(void)
101+
{
102+
return efi_ctx->ap_trampline_buf;
103+
}
104+
100105
static void efi_init(void)
101106
{
102107
struct multiboot_info *mbi = NULL;

hypervisor/include/arch/x86/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ extern uint8_t trampline_pdpt_addr[];
169169
extern uint8_t trampline_gdt_ptr[];
170170
extern uint8_t trampline_start64_fixup[];
171171

172+
extern uint64_t trampline_start16_paddr;
172173
extern int ibrs_type;
173174

174175
/*

hypervisor/include/common/acrn_efi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct {
1515
struct efi_ctx {
1616
uint64_t rip;
1717
void *rsdp;
18+
void *ap_trampline_buf;
1819
dt_addr_t gdt;
1920
dt_addr_t idt;
2021
uint16_t tr_sel;
@@ -50,5 +51,6 @@ struct efi_ctx {
5051
}__attribute__((packed));
5152

5253
void *get_rsdp_from_uefi(void);
54+
void *get_ap_trampline_buf(void);
5355

5456
#endif /* UEFI_H*/

0 commit comments

Comments
 (0)