Skip to content

Commit ae8893c

Browse files
jsun26intelwenlingz
authored andcommitted
HV: use api to get kernel load addr
For a Linux guest, the kernel load address should be gotten from zeropage even for a pre-launched VM; Tracked-On: #3214 Signed-off-by: Victor Sun <victor.sun@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent 1c00611 commit ae8893c

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

hypervisor/boot/guest/vboot_info.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,36 @@ static void merge_cmdline(const struct acrn_vm *vm, const char *cmdline, const c
135135
}
136136
}
137137

138-
static void *get_kernel_load_addr(void *kernel_src_addr)
138+
static void *get_kernel_load_addr(struct acrn_vm *vm)
139139
{
140+
void *load_addr = NULL;
141+
struct vm_sw_info *sw_info = &vm->sw;
140142
struct zero_page *zeropage;
141143

142-
/* According to the explaination for pref_address
143-
* in Documentation/x86/boot.txt, a relocating
144-
* bootloader should attempt to load kernel at pref_address
145-
* if possible. A non-relocatable kernel will unconditionally
146-
* move itself and to run at this address, so no need to copy
147-
* kernel to perf_address by bootloader, if kernel is
148-
* non-relocatable.
149-
*/
150-
zeropage = (struct zero_page *)kernel_src_addr;
151-
if (zeropage->hdr.relocatable_kernel != 0U) {
152-
zeropage = (struct zero_page *)zeropage->hdr.pref_addr;
144+
switch (sw_info->kernel_type) {
145+
case VM_LINUX_GUEST:
146+
/* According to the explaination for pref_address
147+
* in Documentation/x86/boot.txt, a relocating
148+
* bootloader should attempt to load kernel at pref_address
149+
* if possible. A non-relocatable kernel will unconditionally
150+
* move itself and to run at this address, so no need to copy
151+
* kernel to perf_address by bootloader, if kernel is
152+
* non-relocatable.
153+
*/
154+
zeropage = (struct zero_page *)sw_info->kernel_info.kernel_src_addr;
155+
if (zeropage->hdr.relocatable_kernel != 0U) {
156+
zeropage = (struct zero_page *)zeropage->hdr.pref_addr;
157+
}
158+
load_addr = (void *)zeropage;
159+
break;
160+
default:
161+
pr_err("Unsupported Kernel type.");
162+
break;
153163
}
154-
155-
return (void *)zeropage;
164+
if (load_addr == NULL) {
165+
pr_err("Could not get kernel load addr of VM %d .", vm->vm_id);
166+
}
167+
return load_addr;
156168
}
157169

158170
static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
@@ -187,18 +199,15 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
187199
vm->sw.kernel_type = VM_LINUX_GUEST;
188200
vm->sw.kernel_info.kernel_src_addr = hpa2hva((uint64_t)mods[0].mm_mod_start);
189201
vm->sw.kernel_info.kernel_size = mods[0].mm_mod_end - mods[0].mm_mod_start;
202+
vm->sw.kernel_info.kernel_load_addr = get_kernel_load_addr(vm);
190203

191204
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
192205

193206
if (vm_config->load_order == PRE_LAUNCHED_VM) {
194-
vm->sw.kernel_info.kernel_load_addr = (void *)(MEM_1M * 16U);
195207
vm->sw.bootargs_info.src_addr = (void *)vm_config->os_config.bootargs;
196208
vm->sw.bootargs_info.size =
197209
strnlen_s(vm_config->os_config.bootargs, MAX_BOOTARGS_SIZE);
198210
} else {
199-
vm->sw.kernel_info.kernel_load_addr =
200-
get_kernel_load_addr(vm->sw.kernel_info.kernel_src_addr);
201-
202211
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
203212
/*
204213
* If there is cmdline from mbi->mi_cmdline, merge it with
@@ -228,7 +237,9 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
228237
parse_other_modules(vm, mods + 1, mbi->mi_mods_count - 1);
229238
}
230239
clac();
231-
ret = 0;
240+
if (vm->sw.kernel_info.kernel_load_addr != NULL) {
241+
ret = 0;
242+
}
232243
}
233244
}
234245
}

0 commit comments

Comments
 (0)