From e028749e5a8756559275e851ef8509b6b8ff0ffc Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Tue, 1 Oct 2024 14:17:09 +0100 Subject: [PATCH] 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 --- arch/arm64/kvm/hyp/hyp-entry.S | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index 03f97d71984c..f55f57f7fd84 100644 --- a/arch/arm64/kvm/hyp/hyp-entry.S +++ b/arch/arm64/kvm/hyp/hyp-entry.S @@ -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