|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | +/* |
| 3 | + * FILE: dtrace_isa_arm64.c |
| 4 | + * DESCRIPTION: DTrace - arm64 architecture specific support functions |
| 5 | + * |
| 6 | + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation; either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <asm/stacktrace.h> |
| 20 | +#include <linux/ptrace.h> |
| 21 | + |
| 22 | +#include "dtrace.h" |
| 23 | + |
| 24 | +uintptr_t _userlimit = 0x0000ffffffffffffLL; |
| 25 | + |
| 26 | +void dtrace_copyin_arch(uintptr_t uaddr, uintptr_t kaddr, size_t size, |
| 27 | + volatile uint16_t *flags) |
| 28 | +{ |
| 29 | +} |
| 30 | + |
| 31 | +void dtrace_copyinstr_arch(uintptr_t uaddr, uintptr_t kaddr, size_t size, |
| 32 | + volatile uint16_t *flags) |
| 33 | +{ |
| 34 | +} |
| 35 | + |
| 36 | +void dtrace_copyout(uintptr_t uaddr, uintptr_t kaddr, size_t size, |
| 37 | + volatile uint16_t *flags) |
| 38 | +{ |
| 39 | +} |
| 40 | + |
| 41 | +void dtrace_copyoutstr(uintptr_t uaddr, uintptr_t kaddr, size_t size, |
| 42 | + volatile uint16_t *flags) |
| 43 | +{ |
| 44 | +} |
| 45 | + |
| 46 | +#define DTRACE_FUWORD(bits) \ |
| 47 | + uint##bits##_t dtrace_fuword##bits(void *uaddr) \ |
| 48 | + { \ |
| 49 | + extern uint##bits##_t dtrace_fuword##bits##_nocheck(void *);\ |
| 50 | + \ |
| 51 | + if ((uintptr_t)uaddr > _userlimit) { \ |
| 52 | + DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); \ |
| 53 | + this_cpu_core->cpuc_dtrace_illval = (uintptr_t)uaddr; \ |
| 54 | + } \ |
| 55 | + \ |
| 56 | + return dtrace_fuword##bits##_nocheck(uaddr); \ |
| 57 | + } |
| 58 | + |
| 59 | +DTRACE_FUWORD(8) |
| 60 | +DTRACE_FUWORD(16) |
| 61 | +DTRACE_FUWORD(32) |
| 62 | +DTRACE_FUWORD(64) |
| 63 | + |
| 64 | +static int dtrace_unwind_frame(struct task_struct *task, |
| 65 | + struct stackframe *frame) |
| 66 | +{ |
| 67 | + unsigned long fp = frame->fp; |
| 68 | + |
| 69 | + if (fp & 0xf) |
| 70 | + return -EINVAL; |
| 71 | + |
| 72 | + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); |
| 73 | + frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); |
| 74 | + frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); |
| 75 | + DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); |
| 76 | + |
| 77 | + if (!frame->fp && !frame->pc) |
| 78 | + return -EINVAL; |
| 79 | + |
| 80 | + return 0; |
| 81 | +} |
| 82 | + |
| 83 | +uint64_t dtrace_getarg(int argno, int aframes) |
| 84 | +{ |
| 85 | + uint64_t *st; |
| 86 | + uint64_t val; |
| 87 | + int i; |
| 88 | + struct stackframe frame; |
| 89 | + struct task_struct *task = current; |
| 90 | + |
| 91 | + if (argno < 7) |
| 92 | + return 0; |
| 93 | + |
| 94 | + if (this_cpu_core->cpu_dtrace_regs) |
| 95 | + st = (uint64_t *)this_cpu_core->cpu_dtrace_regs->regs[29]; |
| 96 | + else { |
| 97 | + frame.fp = (unsigned long)__builtin_frame_address(0); |
| 98 | + frame.pc = (unsigned long)dtrace_getarg; |
| 99 | + |
| 100 | + aframes += 1; /* Count this function. */ |
| 101 | + for (i = 0; i < aframes; i++) { |
| 102 | + if (dtrace_unwind_frame(task, &frame) < 0) |
| 103 | + break; |
| 104 | + } |
| 105 | + |
| 106 | + /* |
| 107 | + * If we cannot traverse the expected number of stack frames, |
| 108 | + * there is something wrong with the stack. |
| 109 | + */ |
| 110 | + if (i < aframes) { |
| 111 | + DTRACE_CPUFLAG_SET(CPU_DTRACE_BADSTACK); |
| 112 | + |
| 113 | + return 0; |
| 114 | + } |
| 115 | + |
| 116 | + st = (uint64_t *)frame.fp; |
| 117 | + } |
| 118 | + |
| 119 | + /* |
| 120 | + * The first 7 arguments (arg0 through arg6) are passed in registers |
| 121 | + * to dtrace_probe(). The remaining arguments (arg7 through arg9) are |
| 122 | + * passed on the stack. |
| 123 | + * |
| 124 | + * Stack layout: |
| 125 | + * bp[0] = pushed fp from caller |
| 126 | + * bp[1] = return address |
| 127 | + * bp[2] = 8th argument (arg7 -> argno = 7) |
| 128 | + * bp[3] = 9th argument (arg8 -> argno = 8) |
| 129 | + * ... |
| 130 | + */ |
| 131 | + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); |
| 132 | + val = READ_ONCE_NOCHECK(st[2 + (argno - 7)]); |
| 133 | + DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); |
| 134 | + |
| 135 | + return val; |
| 136 | +} |
| 137 | + |
| 138 | +ulong_t dtrace_getreg(struct task_struct *task, uint_t reg) |
| 139 | +{ |
| 140 | + struct pt_regs *rp = task_pt_regs(task); |
| 141 | + |
| 142 | + return regs_get_register(rp, reg * sizeof(uint64_t)); |
| 143 | +} |
| 144 | + |
| 145 | +void pdata_init(dtrace_module_t *pdata, struct module *mp) |
| 146 | +{ |
| 147 | + /* |
| 148 | + * Throw away existing data as we don't support reusal at |
| 149 | + * the moment. |
| 150 | + */ |
| 151 | + if (mp->pdata != NULL) |
| 152 | + pdata_cleanup(pdata, mp); |
| 153 | + |
| 154 | + pdata->sdt_tab = NULL; |
| 155 | + pdata->fbt_tab = NULL; |
| 156 | +} |
| 157 | + |
| 158 | +void pdata_cleanup(dtrace_module_t *pdata, struct module *mp) |
| 159 | +{ |
| 160 | + if (pdata->sdt_tab != NULL) |
| 161 | + dtrace_free_text(pdata->sdt_tab); |
| 162 | + if (pdata->fbt_tab != NULL) |
| 163 | + dtrace_free_text(pdata->fbt_tab); |
| 164 | +} |
0 commit comments