HV: vm_load: correct needed size of bzImage kernel

The previous code did not load bzImage start from protected mode part, result
in the protected mode part un-align with kernel_alignment field and then cause
kernel decompression start from a later aligned address. In this case we had
to enlarge the needed size of bzImage kernel to kernel_init_size plus double
size of kernel_alignment.

With loading issue of bzImage protected mode part fixed, the kernel needed size
is corrected in this patch.

Tracked-On: #6323

Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Victor Sun 2021-06-23 16:29:11 +08:00 committed by wenlingz
parent 2b5bd2e87a
commit d1d59437ea

View File

@ -47,7 +47,7 @@ static void *get_initrd_load_addr(struct acrn_vm *vm, uint64_t kernel_start)
uint64_t ramdisk_load_gpa = INVALID_GPA;
uint64_t ramdisk_gpa_max = DEFAULT_RAMDISK_GPA_MAX;
struct zero_page *zeropage = (struct zero_page *)vm->sw.kernel_info.kernel_src_addr;
uint32_t kernel_init_size, initrd_addr_max;
uint32_t kernel_init_size, kernel_align, initrd_addr_max;
uint64_t kernel_end;
/* Per Linux boot protocol, the Kernel need a size of contiguous
@ -58,9 +58,10 @@ static void *get_initrd_load_addr(struct acrn_vm *vm, uint64_t kernel_start)
*/
stac();
kernel_init_size = zeropage->hdr.init_size;
kernel_align = zeropage->hdr.kernel_alignment;
initrd_addr_max = zeropage->hdr.initrd_addr_max;
stac();
kernel_end = kernel_start + MEM_2M + kernel_init_size;
kernel_end = roundup(kernel_start, kernel_align) + kernel_init_size;
if (initrd_addr_max != 0U) {
ramdisk_gpa_max = initrd_addr_max;
@ -143,9 +144,9 @@ static void *get_bzimage_kernel_load_addr(struct acrn_vm *vm)
uint32_t kernel_init_size = zeropage->hdr.init_size;
/* Because the kernel load address need to be up aligned to kernel_align size
* whereas find_space_from_ve820() can only return page aligned address,
* we enlarge the needed size to (kernel_init_size + 2 * kernel_align).
* we enlarge the needed size to (kernel_init_size + kernel_align).
*/
uint32_t kernel_size = kernel_init_size + 2 * kernel_align;
uint32_t kernel_size = kernel_init_size + kernel_align;
get_boot_mods_range(&mods_start, &mods_end);
mods_start = sos_vm_hpa2gpa(mods_start);