Skip to content

Commit

Permalink
KVM: arm64: Extract __do_hyp_init into a helper function
Browse files Browse the repository at this point in the history
In preparation for adding a CPU entry point in nVHE hyp code, extract
most of __do_hyp_init hypervisor initialization code into a common
helper function. This will be invoked by the entry point to install KVM
on the newly booted CPU.

Signed-off-by: David Brazdil <dbrazdil@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20201202184122.26046-20-dbrazdil@google.com
  • Loading branch information
David Brazdil authored and Marc Zyngier committed Dec 4, 2020
1 parent 1fd12b7 commit f74e1e2
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions arch/arm64/kvm/hyp/nvhe/hyp-init.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,36 @@ __do_hyp_init:
mov x0, #SMCCC_RET_NOT_SUPPORTED
eret

1: ldr x0, [x1, #NVHE_INIT_TPIDR_EL2]
msr tpidr_el2, x0
1: mov x0, x1
mov x4, lr
bl ___kvm_hyp_init
mov lr, x4

ldr x0, [x1, #NVHE_INIT_MAIR_EL2]
msr mair_el2, x0
/* Hello, World! */
mov x0, #SMCCC_RET_SUCCESS
eret
SYM_CODE_END(__kvm_hyp_init)

/*
* Initialize the hypervisor in EL2.
*
* Only uses x0..x3 so as to not clobber callee-saved SMCCC registers
* and leave x4 for the caller.
*
* x0: struct kvm_nvhe_init_params PA
*/
SYM_CODE_START_LOCAL(___kvm_hyp_init)
ldr x1, [x0, #NVHE_INIT_TPIDR_EL2]
msr tpidr_el2, x1

ldr x1, [x0, #NVHE_INIT_STACK_HYP_VA]
mov sp, x1

ldr x0, [x1, #NVHE_INIT_STACK_HYP_VA]
mov sp, x0
ldr x1, [x0, #NVHE_INIT_MAIR_EL2]
msr mair_el2, x1

ldr x0, [x1, #NVHE_INIT_PGD_PA]
phys_to_ttbr x2, x0
ldr x1, [x0, #NVHE_INIT_PGD_PA]
phys_to_ttbr x2, x1
alternative_if ARM64_HAS_CNP
orr x2, x2, #TTBR_CNP_BIT
alternative_else_nop_endif
Expand All @@ -87,9 +106,9 @@ alternative_else_nop_endif
/*
* Set the PS bits in TCR_EL2.
*/
ldr x0, [x1, #NVHE_INIT_TCR_EL2]
tcr_compute_pa_size x0, #TCR_EL2_PS_SHIFT, x1, x2
msr tcr_el2, x0
ldr x1, [x0, #NVHE_INIT_TCR_EL2]
tcr_compute_pa_size x1, #TCR_EL2_PS_SHIFT, x2, x3
msr tcr_el2, x1

isb

Expand Down Expand Up @@ -117,10 +136,8 @@ alternative_else_nop_endif
kimg_hyp_va x0, x1
msr vbar_el2, x0

/* Hello, World! */
mov x0, #SMCCC_RET_SUCCESS
eret
SYM_CODE_END(__kvm_hyp_init)
ret
SYM_CODE_END(___kvm_hyp_init)

SYM_CODE_START(__kvm_handle_stub_hvc)
cmp x0, #HVC_SOFT_RESTART
Expand Down

0 comments on commit f74e1e2

Please sign in to comment.