blob: 0503c98b21172ff09044e2dcfbf847acdf6e9fb3 [file] [log] [blame]
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +10001#ifndef _ASM_POWERPC_KPROBES_H
2#define _ASM_POWERPC_KPROBES_H
Luis R. Rodriguez7d134b22017-02-27 14:26:56 -08003
4#include <asm-generic/kprobes.h>
5
Arnd Bergmann88ced032005-12-16 22:43:46 +01006#ifdef __KERNEL__
Paul Mackerras14cf11a2005-09-26 16:04:21 +10007/*
8 * Kernel Probes (KProbes)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 * Copyright (C) IBM Corporation, 2002, 2004
25 *
26 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
27 * Probes initial implementation ( includes suggestions from
28 * Rusty Russell).
29 * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli
30 * <ananth@in.ibm.com>
31 */
32#include <linux/types.h>
33#include <linux/ptrace.h>
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -080034#include <linux/percpu.h>
Naveen N. Rao30176462017-02-08 14:27:31 +053035#include <linux/module.h>
Ananth N Mavinakayanahalli7118e7e2012-08-23 21:26:02 +000036#include <asm/probes.h>
Anton Blanchard47f86b42014-04-03 16:08:38 +110037#include <asm/code-patching.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100038
Naveen N. Rao6cc89ba2016-11-21 22:36:41 +053039#ifdef CONFIG_KPROBES
Anil S Keshavamurthy2d14e392006-01-09 20:52:41 -080040#define __ARCH_WANT_KPROBES_INSN_SLOT
41
Paul Mackerras14cf11a2005-09-26 16:04:21 +100042struct pt_regs;
Ananth N Mavinakayanahalli0498b632006-01-09 20:52:46 -080043struct kprobe;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100044
Ananth N Mavinakayanahalli28e1e582012-09-05 22:17:04 +000045typedef ppc_opcode_t kprobe_opcode_t;
Anju T51c9c082017-02-08 15:20:51 +053046
47extern kprobe_opcode_t optinsn_slot;
48
49/* Optinsn template address */
50extern kprobe_opcode_t optprobe_template_entry[];
51extern kprobe_opcode_t optprobe_template_op_address[];
52extern kprobe_opcode_t optprobe_template_call_handler[];
53extern kprobe_opcode_t optprobe_template_insn[];
54extern kprobe_opcode_t optprobe_template_call_emulate[];
55extern kprobe_opcode_t optprobe_template_ret[];
56extern kprobe_opcode_t optprobe_template_end[];
57
58/* Fixed instruction size for powerpc */
59#define MAX_INSN_SIZE 1
60#define MAX_OPTIMIZED_LENGTH sizeof(kprobe_opcode_t) /* 4 bytes */
61#define MAX_OPTINSN_SIZE (optprobe_template_end - optprobe_template_entry)
62#define RELATIVEJUMP_SIZE sizeof(kprobe_opcode_t) /* 4 bytes */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100063
Michael Ellermanf55d9662016-06-06 22:26:10 +053064#ifdef PPC64_ELF_ABI_v2
Naveen N. Raobf794bf2014-12-15 20:20:31 +053065/* PPC64 ABIv2 needs local entry point */
Ananth N Mavinakayanahalli3a872d82006-10-02 02:17:30 -070066#define kprobe_lookup_name(name, addr) \
67{ \
68 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
Naveen N. Raobf794bf2014-12-15 20:20:31 +053069 if (addr) \
70 addr = (kprobe_opcode_t *)ppc_function_entry(addr); \
71}
Michael Ellermanf55d9662016-06-06 22:26:10 +053072#elif defined(PPC64_ELF_ABI_v1)
Naveen N. Raobf794bf2014-12-15 20:20:31 +053073/*
74 * 64bit powerpc ABIv1 uses function descriptors:
75 * - Check for the dot variant of the symbol first.
76 * - If that fails, try looking up the symbol provided.
77 *
78 * This ensures we always get to the actual symbol and not the descriptor.
79 * Also handle <module:symbol> format.
80 */
81#define kprobe_lookup_name(name, addr) \
82{ \
83 char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; \
Naveen N. Rao30176462017-02-08 14:27:31 +053084 const char *modsym; \
Naveen N. Raobf794bf2014-12-15 20:20:31 +053085 bool dot_appended = false; \
86 if ((modsym = strchr(name, ':')) != NULL) { \
87 modsym++; \
88 if (*modsym != '\0' && *modsym != '.') { \
89 /* Convert to <module:.symbol> */ \
90 strncpy(dot_name, name, modsym - name); \
91 dot_name[modsym - name] = '.'; \
92 dot_name[modsym - name + 1] = '\0'; \
93 strncat(dot_name, modsym, \
94 sizeof(dot_name) - (modsym - name) - 2);\
95 dot_appended = true; \
96 } else { \
97 dot_name[0] = '\0'; \
98 strncat(dot_name, name, sizeof(dot_name) - 1); \
99 } \
100 } else if (name[0] != '.') { \
Srinivasa Dseb609e52007-04-23 11:28:49 +0530101 dot_name[0] = '.'; \
102 dot_name[1] = '\0'; \
Tejun Heo9281ace2007-07-17 04:03:51 -0700103 strncat(dot_name, name, KSYM_NAME_LEN - 2); \
Naveen N. Raobf794bf2014-12-15 20:20:31 +0530104 dot_appended = true; \
105 } else { \
106 dot_name[0] = '\0'; \
107 strncat(dot_name, name, KSYM_NAME_LEN - 1); \
108 } \
109 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \
110 if (!addr && dot_appended) { \
111 /* Let's try the original non-dot symbol lookup */ \
112 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
Ananth N Mavinakayanahalli412998c2006-10-02 02:17:31 -0700113 } \
Ananth N Mavinakayanahalli3a872d82006-10-02 02:17:30 -0700114}
Michael Ellermanf55d9662016-06-06 22:26:10 +0530115#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000116
bibo, maoa9ad9652006-07-30 03:03:26 -0700117#define flush_insn_slot(p) do { } while (0)
Masami Hiramatsuf438d912007-10-16 01:27:49 -0700118#define kretprobe_blacklist_size 0
Anil S Keshavamurthye6f47f92006-06-26 00:25:29 -0700119
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000120void kretprobe_trampoline(void);
Ananth N Mavinakayanahalli0498b632006-01-09 20:52:46 -0800121extern void arch_remove_kprobe(struct kprobe *p);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000122
123/* Architecture specific copy of original instruction */
124struct arch_specific_insn {
125 /* copy of original instruction */
126 kprobe_opcode_t *insn;
Ananth N Mavinakayanahallie6349a952007-04-18 15:57:51 +1000127 /*
128 * Set in kprobes code, initially to 0. If the instruction can be
129 * eumulated, this is set to 1, if not, to -1.
130 */
131 int boostable;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000132};
133
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800134struct prev_kprobe {
135 struct kprobe *kp;
136 unsigned long status;
137 unsigned long saved_msr;
138};
139
140/* per-cpu kprobe control block */
141struct kprobe_ctlblk {
142 unsigned long kprobe_status;
143 unsigned long kprobe_saved_msr;
144 struct pt_regs jprobe_saved_regs;
145 struct prev_kprobe prev_kprobe;
146};
147
Anju T51c9c082017-02-08 15:20:51 +0530148struct arch_optimized_insn {
149 kprobe_opcode_t copied_insn[1];
150 /* detour buffer */
151 kprobe_opcode_t *insn;
152};
153
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000154extern int kprobe_exceptions_notify(struct notifier_block *self,
Anil S Keshavamurthy41dead42006-01-09 20:52:42 -0800155 unsigned long val, void *data);
Christoph Hellwig9f90b992007-04-30 11:56:46 +0100156extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
Naveen N. Rao6cc89ba2016-11-21 22:36:41 +0530157extern int kprobe_handler(struct pt_regs *regs);
158extern int kprobe_post_handler(struct pt_regs *regs);
159#else
160static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
161static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
162#endif /* CONFIG_KPROBES */
Arnd Bergmann88ced032005-12-16 22:43:46 +0100163#endif /* __KERNEL__ */
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +1000164#endif /* _ASM_POWERPC_KPROBES_H */