diff --git a/arch/x86/guest/guest.c b/arch/x86/guest/guest.c index 7f2e57f68..3ad100043 100644 --- a/arch/x86/guest/guest.c +++ b/arch/x86/guest/guest.c @@ -196,6 +196,7 @@ void obtain_e820_mem_info(void) e820_mem.mem_bottom = UINT64_MAX; e820_mem.mem_top = 0x00; + e820_mem.total_mem_size = 0; e820_mem.max_ram_blk_base = 0; e820_mem.max_ram_blk_size = 0; @@ -210,11 +211,13 @@ void obtain_e820_mem_info(void) + entry->length; } - if (entry->baseaddr == UOS_DEFAULT_START_ADDR - && entry->type == E820_TYPE_RAM) { - e820_mem.max_ram_blk_base = - entry->baseaddr; - e820_mem.max_ram_blk_size = entry->length; + if (entry->type == E820_TYPE_RAM) { + e820_mem.total_mem_size += entry->length; + if (entry->baseaddr == UOS_DEFAULT_START_ADDR) { + e820_mem.max_ram_blk_base = + entry->baseaddr; + e820_mem.max_ram_blk_size = entry->length; + } } } } @@ -282,7 +285,9 @@ static void rebuild_vm0_e820(void) entry->type = new_entry.type; } + e820_mem.total_mem_size -= CONFIG_RAM_SIZE; } + int prepare_vm0_memmap_and_e820(struct vm *vm) { unsigned int i; diff --git a/bsp/sbl/include/bsp/bsp_cfg.h b/bsp/sbl/include/bsp/bsp_cfg.h index a10709e88..47f8cd2d7 100644 --- a/bsp/sbl/include/bsp/bsp_cfg.h +++ b/bsp/sbl/include/bsp/bsp_cfg.h @@ -45,4 +45,5 @@ #define CONFIG_LOW_RAM_SIZE 0x000CF000 #define CONFIG_RAM_START 0x6E000000 #define CONFIG_RAM_SIZE 0x02000000 /* 32M */ +#define CONFIG_CMA #endif /* BSP_CFG_H */ diff --git a/common/vm_load.c b/common/vm_load.c index 493ac3ff0..af4512c8c 100644 --- a/common/vm_load.c +++ b/common/vm_load.c @@ -187,6 +187,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) strcpy_s((char *)hva, MEM_2K, vm->sw.linux_info.bootargs_src_addr); +#ifdef CONFIG_CMA /* add "cma=XXXXM@0xXXXXXXXX" to cmdline*/ if (is_vm0(vm) && (e820_mem.max_ram_blk_size > 0)) { snprintf(dyn_bootargs, 100, " cma=%dM@0x%llx\n", @@ -197,6 +198,32 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) +vm->sw.linux_info.bootargs_size - 1, 100, dyn_bootargs); } +#else + /* add "hugepagesz=1G hugepages=x" to cmdline for 1G hugepage + * reserving. Current strategy is "total_mem_size in Giga - + * remained 1G pages" for reserving. + */ + if (is_vm0(vm) && check_mmu_1gb_support(PTT_HOST)) { + int reserving_1g_pages; + +#ifdef CONFIG_REMAIN_1G_PAGES + reserving_1g_pages = (e820_mem.total_mem_size >> 30) - + CONFIG_REMAIN_1G_PAGES; +#else + reserving_1g_pages = (e820_mem.total_mem_size >> 30) - + 3; +#endif + if (reserving_1g_pages > 0) { + snprintf(dyn_bootargs, 100, + " hugepagesz=1G hugepages=%d\n", + reserving_1g_pages); + /* Delete '\n' at the end of cmdline */ + strcpy_s((char *)hva + +vm->sw.linux_info.bootargs_size - 1, + 100, dyn_bootargs); + } + } +#endif /* Check if a RAM disk is present with Linux guest */ if (vm->sw.linux_info.ramdisk_src_addr) { diff --git a/include/arch/x86/guest/guest.h b/include/arch/x86/guest/guest.h index 5d406ebf5..f7199a991 100644 --- a/include/arch/x86/guest/guest.h +++ b/include/arch/x86/guest/guest.h @@ -62,6 +62,7 @@ struct vhm_request; struct e820_mem_params { uint64_t mem_bottom; uint64_t mem_top; + uint64_t total_mem_size; uint64_t max_ram_blk_base; /* used for the start address of UOS */ uint64_t max_ram_blk_size; };