blob: d821835ade8620982e1f888411feacc9b367c6d1 [file] [log] [blame]
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +10001#ifndef _ASM_POWERPC_KPROBES_H
2#define _ASM_POWERPC_KPROBES_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Paul Mackerras14cf11a2005-09-26 16:04:21 +10004/*
5 * Kernel Probes (KProbes)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * Copyright (C) IBM Corporation, 2002, 2004
22 *
23 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
24 * Probes initial implementation ( includes suggestions from
25 * Rusty Russell).
26 * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli
27 * <ananth@in.ibm.com>
28 */
29#include <linux/types.h>
30#include <linux/ptrace.h>
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -080031#include <linux/percpu.h>
Naveen N. Rao30176462017-02-08 14:27:31 +053032#include <linux/module.h>
Ananth N Mavinakayanahalli7118e7e2012-08-23 21:26:02 +000033#include <asm/probes.h>
Anton Blanchard47f86b42014-04-03 16:08:38 +110034#include <asm/code-patching.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100035
Naveen N. Rao6cc89ba2016-11-21 22:36:41 +053036#ifdef CONFIG_KPROBES
Anil S Keshavamurthy2d14e392006-01-09 20:52:41 -080037#define __ARCH_WANT_KPROBES_INSN_SLOT
38
Paul Mackerras14cf11a2005-09-26 16:04:21 +100039struct pt_regs;
Ananth N Mavinakayanahalli0498b632006-01-09 20:52:46 -080040struct kprobe;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100041
Ananth N Mavinakayanahalli28e1e582012-09-05 22:17:04 +000042typedef ppc_opcode_t kprobe_opcode_t;
Anju T51c9c082017-02-08 15:20:51 +053043
44extern kprobe_opcode_t optinsn_slot;
45
46/* Optinsn template address */
47extern kprobe_opcode_t optprobe_template_entry[];
48extern kprobe_opcode_t optprobe_template_op_address[];
49extern kprobe_opcode_t optprobe_template_call_handler[];
50extern kprobe_opcode_t optprobe_template_insn[];
51extern kprobe_opcode_t optprobe_template_call_emulate[];
52extern kprobe_opcode_t optprobe_template_ret[];
53extern kprobe_opcode_t optprobe_template_end[];
54
55/* Fixed instruction size for powerpc */
56#define MAX_INSN_SIZE 1
57#define MAX_OPTIMIZED_LENGTH sizeof(kprobe_opcode_t) /* 4 bytes */
58#define MAX_OPTINSN_SIZE (optprobe_template_end - optprobe_template_entry)
59#define RELATIVEJUMP_SIZE sizeof(kprobe_opcode_t) /* 4 bytes */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100060
Michael Ellermanf55d9662016-06-06 22:26:10 +053061#ifdef PPC64_ELF_ABI_v2
Naveen N. Raobf794bf2014-12-15 20:20:31 +053062/* PPC64 ABIv2 needs local entry point */
Ananth N Mavinakayanahalli3a872d82006-10-02 02:17:30 -070063#define kprobe_lookup_name(name, addr) \
64{ \
65 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
Naveen N. Raobf794bf2014-12-15 20:20:31 +053066 if (addr) \
67 addr = (kprobe_opcode_t *)ppc_function_entry(addr); \
68}
Michael Ellermanf55d9662016-06-06 22:26:10 +053069#elif defined(PPC64_ELF_ABI_v1)
Naveen N. Raobf794bf2014-12-15 20:20:31 +053070/*
71 * 64bit powerpc ABIv1 uses function descriptors:
72 * - Check for the dot variant of the symbol first.
73 * - If that fails, try looking up the symbol provided.
74 *
75 * This ensures we always get to the actual symbol and not the descriptor.
76 * Also handle <module:symbol> format.
77 */
78#define kprobe_lookup_name(name, addr) \
79{ \
80 char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; \
Naveen N. Rao30176462017-02-08 14:27:31 +053081 const char *modsym; \
Naveen N. Raobf794bf2014-12-15 20:20:31 +053082 bool dot_appended = false; \
83 if ((modsym = strchr(name, ':')) != NULL) { \
84 modsym++; \
85 if (*modsym != '\0' && *modsym != '.') { \
86 /* Convert to <module:.symbol> */ \
87 strncpy(dot_name, name, modsym - name); \
88 dot_name[modsym - name] = '.'; \
89 dot_name[modsym - name + 1] = '\0'; \
90 strncat(dot_name, modsym, \
91 sizeof(dot_name) - (modsym - name) - 2);\
92 dot_appended = true; \
93 } else { \
94 dot_name[0] = '\0'; \
95 strncat(dot_name, name, sizeof(dot_name) - 1); \
96 } \
97 } else if (name[0] != '.') { \
Srinivasa Dseb609e52007-04-23 11:28:49 +053098 dot_name[0] = '.'; \
99 dot_name[1] = '\0'; \
Tejun Heo9281ace2007-07-17 04:03:51 -0700100 strncat(dot_name, name, KSYM_NAME_LEN - 2); \
Naveen N. Raobf794bf2014-12-15 20:20:31 +0530101 dot_appended = true; \
102 } else { \
103 dot_name[0] = '\0'; \
104 strncat(dot_name, name, KSYM_NAME_LEN - 1); \
105 } \
106 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \
107 if (!addr && dot_appended) { \
108 /* Let's try the original non-dot symbol lookup */ \
109 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
Ananth N Mavinakayanahalli412998c2006-10-02 02:17:31 -0700110 } \
Ananth N Mavinakayanahalli3a872d82006-10-02 02:17:30 -0700111}
Michael Ellermanf55d9662016-06-06 22:26:10 +0530112#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000113
bibo, maoa9ad9652006-07-30 03:03:26 -0700114#define flush_insn_slot(p) do { } while (0)
Masami Hiramatsuf438d912007-10-16 01:27:49 -0700115#define kretprobe_blacklist_size 0
Anil S Keshavamurthye6f47f92006-06-26 00:25:29 -0700116
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000117void kretprobe_trampoline(void);
Ananth N Mavinakayanahalli0498b632006-01-09 20:52:46 -0800118extern void arch_remove_kprobe(struct kprobe *p);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000119
120/* Architecture specific copy of original instruction */
121struct arch_specific_insn {
122 /* copy of original instruction */
123 kprobe_opcode_t *insn;
Ananth N Mavinakayanahallie6349a952007-04-18 15:57:51 +1000124 /*
125 * Set in kprobes code, initially to 0. If the instruction can be
126 * eumulated, this is set to 1, if not, to -1.
127 */
128 int boostable;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000129};
130
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800131struct prev_kprobe {
132 struct kprobe *kp;
133 unsigned long status;
134 unsigned long saved_msr;
135};
136
137/* per-cpu kprobe control block */
138struct kprobe_ctlblk {
139 unsigned long kprobe_status;
140 unsigned long kprobe_saved_msr;
141 struct pt_regs jprobe_saved_regs;
142 struct prev_kprobe prev_kprobe;
143};
144
Anju T51c9c082017-02-08 15:20:51 +0530145struct arch_optimized_insn {
146 kprobe_opcode_t copied_insn[1];
147 /* detour buffer */
148 kprobe_opcode_t *insn;
149};
150
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000151extern int kprobe_exceptions_notify(struct notifier_block *self,
Anil S Keshavamurthy41dead42006-01-09 20:52:42 -0800152 unsigned long val, void *data);
Christoph Hellwig9f90b992007-04-30 11:56:46 +0100153extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
Naveen N. Rao6cc89ba2016-11-21 22:36:41 +0530154extern int kprobe_handler(struct pt_regs *regs);
155extern int kprobe_post_handler(struct pt_regs *regs);
156#else
157static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
158static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
159#endif /* CONFIG_KPROBES */
Arnd Bergmann88ced032005-12-16 22:43:46 +0100160#endif /* __KERNEL__ */
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +1000161#endif /* _ASM_POWERPC_KPROBES_H */