acrn-hypervisor/hypervisor/include/arch/x86/asm/zeropage.h
Victor Sun 1b3a75c984 HV: place kernel and ramdisk by find_space_from_ve820()
We should not hardcode the VM ramdisk load address right after kernel
load address because of two reasons:
	1. Per Linux kernel boot protocol, the Kernel need a size of
	   contiguous memory(i.e. init_size field in zeropage) from
	   its load address to boot, then the address would overlap
	   with ramdisk;
	2. The hardcoded address could not be ensured as a valid address
	   in guest e820 table, especially with a huge ramdisk;

Also we should not hardcode the VM kernel load address to its pref_address
which work for non-relocatable kernel only. For a relocatable kernel,
it could run from any valid address where bootloader load to.

The patch will set the VM kernel and ramdisk load address by scanning
guest e820 table with find_space_from_ve820() api:
	1. For SOS VM, the ramdisk has been loaded by multiboot bootloader
	   already so set the load address as module source address,
	   the relocatable kernel would be relocated to a appropriate address
	   out space of hypervisor and boot modules to avoid guest memory
	   copy corruption;
	2. For pre-launched VM, the kernel would be loaded to pref_address
	   first, then ramdisk will be put to a appropriate address out space
	   of kernel according to guest memory layout and maximum ramdisk
	   address limit under 4GB;

Tracked-On: #5879

Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
2021-06-11 10:06:02 +08:00

49 lines
1.2 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef ZEROPAGE_H
#define ZEROPAGE_H
#include <asm/e820.h>
#include <efi.h>
struct zero_page {
uint8_t pad0[0x1c0]; /* 0x000 */
struct efi_info boot_efi_info;
uint8_t pad1[0x8]; /* 0x1e0 */
uint8_t e820_nentries; /* 0x1e8 */
uint8_t pad2[0x8]; /* 0x1e9 */
struct {
uint8_t setup_sects; /* 0x1f1 */
uint8_t hdr_pad1[0x1e]; /* 0x1f2 */
uint8_t loader_type; /* 0x210 */
uint8_t load_flags; /* 0x211 */
uint8_t hdr_pad2[0x6]; /* 0x212 */
uint32_t ramdisk_addr; /* 0x218 */
uint32_t ramdisk_size; /* 0x21c */
uint8_t hdr_pad3[0x8]; /* 0x220 */
uint32_t bootargs_addr; /* 0x228 */
uint32_t initrd_addr_max; /* 0x22c */
uint32_t kernel_alignment; /* 0x230 */
uint8_t relocatable_kernel; /* 0x234 */
uint8_t hdr_pad5[0x13]; /* 0x235 */
uint32_t payload_offset;/* 0x248 */
uint32_t payload_length;/* 0x24c */
uint8_t hdr_pad6[0x8]; /* 0x250 */
uint64_t pref_addr; /* 0x258 */
uint32_t init_size; /* 0x260 */
uint8_t hdr_pad7[4]; /* 0x264 */
} __packed hdr;
uint8_t pad3[0x68]; /* 0x268 */
struct e820_entry entries[0x80]; /* 0x2d0 */
uint8_t pad4[0x330]; /* 0xcd0 */
} __packed;
#endif