| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * arm64 callchain support |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2015 ARM Limited |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | 6 | */ |
|---|
| 18 | 7 | #include <linux/perf_event.h> |
|---|
| 19 | 8 | #include <linux/uaccess.h> |
|---|
| 20 | 9 | |
|---|
| 10 | +#include <asm/pointer_auth.h> |
|---|
| 21 | 11 | #include <asm/stacktrace.h> |
|---|
| 22 | 12 | |
|---|
| 23 | 13 | struct frame_tail { |
|---|
| .. | .. |
|---|
| 35 | 25 | { |
|---|
| 36 | 26 | struct frame_tail buftail; |
|---|
| 37 | 27 | unsigned long err; |
|---|
| 28 | + unsigned long lr; |
|---|
| 38 | 29 | |
|---|
| 39 | 30 | /* Also check accessibility of one struct frame_tail beyond */ |
|---|
| 40 | | - if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) |
|---|
| 31 | + if (!access_ok(tail, sizeof(buftail))) |
|---|
| 41 | 32 | return NULL; |
|---|
| 42 | 33 | |
|---|
| 43 | 34 | pagefault_disable(); |
|---|
| .. | .. |
|---|
| 47 | 38 | if (err) |
|---|
| 48 | 39 | return NULL; |
|---|
| 49 | 40 | |
|---|
| 50 | | - perf_callchain_store(entry, buftail.lr); |
|---|
| 41 | + lr = ptrauth_strip_insn_pac(buftail.lr); |
|---|
| 42 | + |
|---|
| 43 | + perf_callchain_store(entry, lr); |
|---|
| 51 | 44 | |
|---|
| 52 | 45 | /* |
|---|
| 53 | 46 | * Frame pointers should strictly progress back up the stack |
|---|
| .. | .. |
|---|
| 82 | 75 | unsigned long err; |
|---|
| 83 | 76 | |
|---|
| 84 | 77 | /* Also check accessibility of one struct frame_tail beyond */ |
|---|
| 85 | | - if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) |
|---|
| 78 | + if (!access_ok(tail, sizeof(buftail))) |
|---|
| 86 | 79 | return NULL; |
|---|
| 87 | 80 | |
|---|
| 88 | 81 | pagefault_disable(); |
|---|
| .. | .. |
|---|
| 109 | 102 | void perf_callchain_user(struct perf_callchain_entry_ctx *entry, |
|---|
| 110 | 103 | struct pt_regs *regs) |
|---|
| 111 | 104 | { |
|---|
| 112 | | - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { |
|---|
| 105 | + struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs(); |
|---|
| 106 | + |
|---|
| 107 | + if (guest_cbs && guest_cbs->is_in_guest()) { |
|---|
| 113 | 108 | /* We don't support guest os callchain now */ |
|---|
| 114 | 109 | return; |
|---|
| 115 | 110 | } |
|---|
| .. | .. |
|---|
| 144 | 139 | * whist unwinding the stackframe and is like a subroutine return so we use |
|---|
| 145 | 140 | * the PC. |
|---|
| 146 | 141 | */ |
|---|
| 147 | | -static int callchain_trace(struct stackframe *frame, void *data) |
|---|
| 142 | +static bool callchain_trace(void *data, unsigned long pc) |
|---|
| 148 | 143 | { |
|---|
| 149 | 144 | struct perf_callchain_entry_ctx *entry = data; |
|---|
| 150 | | - perf_callchain_store(entry, frame->pc); |
|---|
| 151 | | - return 0; |
|---|
| 145 | + perf_callchain_store(entry, pc); |
|---|
| 146 | + return true; |
|---|
| 152 | 147 | } |
|---|
| 153 | 148 | |
|---|
| 154 | 149 | void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, |
|---|
| 155 | 150 | struct pt_regs *regs) |
|---|
| 156 | 151 | { |
|---|
| 152 | + struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs(); |
|---|
| 157 | 153 | struct stackframe frame; |
|---|
| 158 | 154 | |
|---|
| 159 | | - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { |
|---|
| 155 | + if (guest_cbs && guest_cbs->is_in_guest()) { |
|---|
| 160 | 156 | /* We don't support guest os callchain now */ |
|---|
| 161 | 157 | return; |
|---|
| 162 | 158 | } |
|---|
| 163 | 159 | |
|---|
| 164 | | - frame.fp = regs->regs[29]; |
|---|
| 165 | | - frame.pc = regs->pc; |
|---|
| 166 | | -#ifdef CONFIG_FUNCTION_GRAPH_TRACER |
|---|
| 167 | | - frame.graph = current->curr_ret_stack; |
|---|
| 168 | | -#endif |
|---|
| 169 | | - |
|---|
| 160 | + start_backtrace(&frame, regs->regs[29], regs->pc); |
|---|
| 170 | 161 | walk_stackframe(current, &frame, callchain_trace, entry); |
|---|
| 171 | 162 | } |
|---|
| 172 | 163 | |
|---|
| 173 | 164 | unsigned long perf_instruction_pointer(struct pt_regs *regs) |
|---|
| 174 | 165 | { |
|---|
| 175 | | - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) |
|---|
| 176 | | - return perf_guest_cbs->get_guest_ip(); |
|---|
| 166 | + struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs(); |
|---|
| 167 | + |
|---|
| 168 | + if (guest_cbs && guest_cbs->is_in_guest()) |
|---|
| 169 | + return guest_cbs->get_guest_ip(); |
|---|
| 177 | 170 | |
|---|
| 178 | 171 | return instruction_pointer(regs); |
|---|
| 179 | 172 | } |
|---|
| 180 | 173 | |
|---|
| 181 | 174 | unsigned long perf_misc_flags(struct pt_regs *regs) |
|---|
| 182 | 175 | { |
|---|
| 176 | + struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs(); |
|---|
| 183 | 177 | int misc = 0; |
|---|
| 184 | 178 | |
|---|
| 185 | | - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { |
|---|
| 186 | | - if (perf_guest_cbs->is_user_mode()) |
|---|
| 179 | + if (guest_cbs && guest_cbs->is_in_guest()) { |
|---|
| 180 | + if (guest_cbs->is_user_mode()) |
|---|
| 187 | 181 | misc |= PERF_RECORD_MISC_GUEST_USER; |
|---|
| 188 | 182 | else |
|---|
| 189 | 183 | misc |= PERF_RECORD_MISC_GUEST_KERNEL; |
|---|