ANDROID: KVM: arm64: Add Ftrace trampolines for pKVM hyp

In preparation for supporting Ftrace in the pKVM hypervisor, add two
trampolines. The first one intends to trace function entries. It saves
the caller states before jumping into __hyp_ftrace_trace(). It is
expected from the latter to return the link register.

That LR can then either be the orignal caller parent, or our second
trampoline __hyp_ftrace_ret_tramp. This trampoline is calling
__hyp_ftrace_ret_trace() which can trace function returns and must
restore the original LR value.

Bug: 357781595
Change-Id: I9327d15d8c69ff94c9dbff2806a145de29af308b
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2024-10-01 14:17:09 +01:00
parent e77aff6717
commit e028749e5a
+45
View File
@@ -262,3 +262,48 @@ SYM_CODE_START(__bp_harden_hyp_vecs)
1: .org __bp_harden_hyp_vecs + __BP_HARDEN_HYP_VECS_SZ
.org 1b
SYM_CODE_END(__bp_harden_hyp_vecs)
#if defined(__KVM_NVHE_HYPERVISOR__) && defined(CONFIG_PROTECTED_NVHE_FTRACE)
SYM_FUNC_START(__hyp_ftrace_tramp)
stp x0, x1, [sp, #-16]!
stp x2, x3, [sp, #-16]!
stp x4, x5, [sp, #-16]!
stp x6, x7, [sp, #-16]!
stp x8, x29, [sp, #-16]! // x8, FP
stp x30, xzr, [sp, #-16]! // LR, ALIGN(16)
sub x0, x30, #AARCH64_INSN_SIZE // unsigned long ip
mov x1, x9 // unsigned long parent_ip
mov x2, x10 // unsigned long offset_idx
bl __hyp_ftrace_trace
mov x30, x0 // LR = __hyp_ftrace_trace();
ldp x9, xzr, [sp], #16
ldp x8, x29, [sp], #16
ldp x6, x7, [sp], #16
ldp x4, x5, [sp], #16
ldp x2, x3, [sp], #16
ldp x0, x1, [sp], #16
ret x9
SYM_FUNC_END(__hyp_ftrace_tramp)
SYM_FUNC_START(__hyp_ftrace_ret_tramp)
stp x0, x1, [sp, #-16]!
stp x2, x3, [sp, #-16]!
stp x4, x5, [sp, #-16]!
stp x6, x7, [sp, #-16]!
stp x8, x29, [sp, #-16]! // x8, FP
bl __hyp_ftrace_ret_trace
mov x30, x0
ldp x8, x29, [sp], #16 // x8, FP
ldp x6, x7, [sp], #16
ldp x4, x5, [sp], #16
ldp x2, x3, [sp], #16
ldp x0, x1, [sp], #16
ret
SYM_FUNC_END(__hyp_ftrace_ret_tramp)
#endif