Skip to content

Commit 238d8bb

Browse files
JasonChenCJacrnsi
authored andcommitted
reshuffle init_vm_boot_info
now only SOS need decide boot with de-privilege or direct boot mode, while for other pre-launched VMs, they should use direct boot mode. this patch merge boot/guest/direct_boot_info.c & boot/guest/deprivilege_boot_info.c into boot/guest/vboot_info.c, and change init_direct_vboot_info() function name to init_general_vm_boot_info(). in init_vm_boot_info(), depend on get_sos_boot_mode(), SOS may choose to init vm boot info by setting the vm_sw_loader to deprivilege specific one; for SOS using DIRECT_BOOT_MODE and all other VMS, they will use general_sw_loader as vm_sw_loader and go through init_general_vm_boot_info() for virtual boot vm info filling. this patch also move spurious handler initilization for de-privilege mode from boot/guest/deprivilege_boot.c to boot/guest/vboot_info.c, and just set it in deprivilege sw_loader before irq enabling. Changes to be committed: modified: Makefile modified: arch/x86/guest/vm.c modified: boot/guest/deprivilege_boot.c deleted: boot/guest/deprivilege_boot_info.c modified: boot/guest/direct_boot.c renamed: boot/guest/direct_boot_info.c -> boot/guest/vboot_info.c modified: boot/guest/vboot_wrapper.c modified: boot/include/guest/deprivilege_boot.h modified: boot/include/guest/direct_boot.h modified: boot/include/guest/vboot.h new file: boot/include/guest/vboot_info.h modified: common/vm_load.c modified: include/arch/x86/guest/vm.h Tracked-On: #1842 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent 0018da4 commit 238d8bb

File tree

13 files changed

+92
-97
lines changed

13 files changed

+92
-97
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ C_SRCS += boot/dmar_info.c
168168
C_SRCS += boot/cmdline.c
169169
C_SRCS += boot/guest/vboot_wrapper.c
170170
C_SRCS += boot/guest/deprivilege_boot.c
171-
C_SRCS += boot/guest/deprivilege_boot_info.c
172171
C_SRCS += boot/guest/direct_boot.c
173-
C_SRCS += boot/guest/direct_boot_info.c
172+
C_SRCS += boot/guest/vboot_info.c
174173

175174
S_SRCS += arch/x86/idt.S
176175
C_SRCS += arch/x86/ioapic.c

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <mmu.h>
2424
#include <logmsg.h>
2525
#include <vboot.h>
26+
#include <vboot_info.h>
2627
#include <board.h>
2728

2829
vm_sw_loader_t vm_sw_loader;
@@ -666,10 +667,6 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
666667
}
667668

668669
if (err == 0) {
669-
if (vm_sw_loader == NULL) {
670-
vm_sw_loader = general_sw_loader;
671-
}
672-
673670
(void )vm_sw_loader(vm);
674671

675672
/* start vm BSP automatically */

hypervisor/boot/guest/deprivilege_boot.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,16 @@ static void* get_depri_boot_rsdp(void)
6363
return hpa2hva((uint64_t)(depri_boot_ctx.rsdp));
6464
}
6565

66-
static void depri_boot_spurious_handler(uint32_t vector)
67-
{
68-
if (get_pcpu_id() == BOOT_CPU_ID) {
69-
struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID);
70-
71-
if (vcpu != NULL) {
72-
vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE);
73-
} else {
74-
pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__);
75-
}
76-
}
77-
}
78-
7966
static void init_depri_boot_irq(void)
8067
{
81-
spurious_handler = (spurious_handler_t)depri_boot_spurious_handler;
82-
/* we defer irq enabling till vlapic is ready */
68+
/* nothing to do for now */
8369
}
8470

8571
static struct vboot_operations depri_boot_ops = {
8672
.init = init_depri_boot,
8773
.get_ap_trampoline = get_depri_boot_ap_trampoline,
8874
.get_rsdp = get_depri_boot_rsdp,
8975
.init_irq = init_depri_boot_irq,
90-
.init_vboot_info = init_depri_vboot_info,
9176
};
9277

9378
struct vboot_operations* get_deprivilege_boot_ops(void)

hypervisor/boot/guest/deprivilege_boot_info.c

Lines changed: 0 additions & 50 deletions
This file was deleted.

hypervisor/boot/guest/direct_boot.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static struct vboot_operations direct_boot_ops = {
3737
.get_ap_trampoline = get_direct_boot_ap_trampoline,
3838
.get_rsdp = get_direct_boot_rsdp,
3939
.init_irq = init_direct_boot_irq,
40-
.init_vboot_info = init_direct_vboot_info,
4140
};
4241

4342
struct vboot_operations* get_direct_boot_ops(void)

hypervisor/boot/guest/direct_boot_info.c renamed to hypervisor/boot/guest/vboot_info.c

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/*
2-
* Copyright (C) 2018 Intel Corporation. All rights reserved.
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
6+
67
#include <types.h>
78
#include <rtl.h>
89
#include <errno.h>
10+
#include <per_cpu.h>
11+
#include <irq.h>
12+
#include <boot_context.h>
913
#include <sprintf.h>
1014
#include <multiboot.h>
1115
#include <pgtable.h>
@@ -14,6 +18,7 @@
1418
#include <mmu.h>
1519
#include <vm.h>
1620
#include <logmsg.h>
21+
#include <deprivilege_boot.h>
1722

1823
#define ACRN_DBG_BOOT 6U
1924

@@ -150,16 +155,7 @@ static void *get_kernel_load_addr(void *kernel_src_addr)
150155
return (void *)zeropage;
151156
}
152157

153-
/**
154-
* @param[inout] vm pointer to a vm descriptor
155-
*
156-
* @retval 0 on success
157-
* @retval -EINVAL on invalid parameters
158-
*
159-
* @pre vm != NULL
160-
* @pre is_sos_vm(vm) == true
161-
*/
162-
int32_t init_direct_vboot_info(struct acrn_vm *vm)
158+
static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
163159
{
164160
struct multiboot_module *mods = NULL;
165161
struct multiboot_info *mbi = NULL;
@@ -238,3 +234,70 @@ int32_t init_direct_vboot_info(struct acrn_vm *vm)
238234
}
239235
return ret;
240236
}
237+
238+
static void depri_boot_spurious_handler(uint32_t vector)
239+
{
240+
if (get_pcpu_id() == BOOT_CPU_ID) {
241+
struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID);
242+
243+
if (vcpu != NULL) {
244+
vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE);
245+
} else {
246+
pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__);
247+
}
248+
}
249+
}
250+
251+
static int32_t depri_boot_sw_loader(struct acrn_vm *vm)
252+
{
253+
int32_t ret = 0;
254+
/* get primary vcpu */
255+
struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID);
256+
struct acrn_vcpu_regs *vcpu_regs = &boot_context;
257+
const struct depri_boot_context *depri_boot_ctx = get_depri_boot_ctx();
258+
const struct lapic_regs *depri_boot_lapic_regs = get_depri_boot_lapic_regs();
259+
260+
pr_dbg("Loading guest to run-time location");
261+
262+
vlapic_restore(vcpu_vlapic(vcpu), depri_boot_lapic_regs);
263+
264+
/* For UEFI platform, the bsp init regs come from two places:
265+
* 1. saved in depri_boot: gpregs, rip
266+
* 2. saved when HV started: other registers
267+
* We copy the info saved in depri_boot to boot_context and
268+
* init bsp with boot_context.
269+
*/
270+
memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs),
271+
&(depri_boot_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs));
272+
273+
vcpu_regs->rip = depri_boot_ctx->vcpu_regs.rip;
274+
set_vcpu_regs(vcpu, vcpu_regs);
275+
276+
/* defer irq enabling till vlapic is ready */
277+
spurious_handler = depri_boot_spurious_handler;
278+
CPU_IRQ_ENABLE();
279+
280+
return ret;
281+
}
282+
283+
/**
284+
* @param[inout] vm pointer to a vm descriptor
285+
*
286+
* @retval 0 on success
287+
* @retval -EINVAL on invalid parameters
288+
*
289+
* @pre vm != NULL
290+
*/
291+
int32_t init_vm_boot_info(struct acrn_vm *vm)
292+
{
293+
int32_t ret = 0;
294+
295+
if (is_sos_vm(vm) && (get_sos_boot_mode() == DEPRI_BOOT_MODE)) {
296+
vm_sw_loader = depri_boot_sw_loader;
297+
} else {
298+
vm_sw_loader = direct_boot_sw_loader;
299+
ret = init_general_vm_boot_info(vm);
300+
}
301+
302+
return ret;
303+
}

hypervisor/boot/guest/vboot_wrapper.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,3 @@ void init_vboot_irq(void)
9595
{
9696
return vboot_ops->init_irq();
9797
}
98-
99-
/* @pre: vboot_ops->init_vboot_info != NULL */
100-
int32_t init_vm_boot_info(struct acrn_vm *vm)
101-
{
102-
return vboot_ops->init_vboot_info(vm);
103-
}

hypervisor/boot/include/guest/deprivilege_boot.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ const struct depri_boot_context *get_depri_boot_ctx(void);
1919
const struct lapic_regs *get_depri_boot_lapic_regs(void);
2020

2121
struct vboot_operations* get_deprivilege_boot_ops(void);
22-
int32_t init_depri_vboot_info(__unused struct acrn_vm *vm);
2322

2423
#endif /* end of include guard: DEPRIVILEGE_BOOT_H */

hypervisor/boot/include/guest/direct_boot.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
#include <vboot.h>
1212

1313
struct vboot_operations* get_direct_boot_ops(void);
14-
int32_t init_direct_vboot_info(struct acrn_vm *vm);
1514

1615
#endif /* end of include guard: DIRECT_BOOT_H */

hypervisor/boot/include/guest/vboot.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ enum vboot_mode {
1313
DEPRI_BOOT_MODE
1414
};
1515

16-
struct acrn_vm;
1716
struct vboot_operations {
1817
void (*init)(void);
1918
uint64_t (*get_ap_trampoline)(void);
2019
void *(*get_rsdp)(void);
2120
void (*init_irq)(void);
22-
int32_t (*init_vboot_info)(struct acrn_vm *vm);
2321
};
2422

2523
void init_vboot_operations(void);
2624
void init_vboot(void);
2725
void init_vboot_irq(void);
28-
int32_t init_vm_boot_info(struct acrn_vm *vm);
2926
uint64_t get_ap_trampoline_buf(void);
3027
void *get_rsdp_ptr(void);
3128

0 commit comments

Comments
 (0)