Loading...
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef _ASM_POWERPC_KPROBES_H
3#define _ASM_POWERPC_KPROBES_H
4
5#include <asm-generic/kprobes.h>
6
7#ifdef __KERNEL__
8/*
9 * Kernel Probes (KProbes)
10 *
11 * Copyright (C) IBM Corporation, 2002, 2004
12 *
13 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
14 * Probes initial implementation ( includes suggestions from
15 * Rusty Russell).
16 * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli
17 * <ananth@in.ibm.com>
18 */
19#include <linux/types.h>
20#include <linux/ptrace.h>
21#include <linux/percpu.h>
22#include <linux/module.h>
23#include <asm/probes.h>
24#include <asm/code-patching.h>
25
26#ifdef CONFIG_KPROBES
27#define __ARCH_WANT_KPROBES_INSN_SLOT
28
29struct pt_regs;
30struct kprobe;
31
32typedef u32 kprobe_opcode_t;
33
34extern kprobe_opcode_t optinsn_slot;
35
36/* Optinsn template address */
37extern kprobe_opcode_t optprobe_template_entry[];
38extern kprobe_opcode_t optprobe_template_op_address[];
39extern kprobe_opcode_t optprobe_template_call_handler[];
40extern kprobe_opcode_t optprobe_template_insn[];
41extern kprobe_opcode_t optprobe_template_call_emulate[];
42extern kprobe_opcode_t optprobe_template_ret[];
43extern kprobe_opcode_t optprobe_template_end[];
44
45/* Fixed instruction size for powerpc */
46#define MAX_INSN_SIZE 2
47#define MAX_OPTIMIZED_LENGTH sizeof(kprobe_opcode_t) /* 4 bytes */
48#define MAX_OPTINSN_SIZE (optprobe_template_end - optprobe_template_entry)
49#define RELATIVEJUMP_SIZE sizeof(kprobe_opcode_t) /* 4 bytes */
50
51#define flush_insn_slot(p) do { } while (0)
52#define kretprobe_blacklist_size 0
53
54void __kretprobe_trampoline(void);
55extern void arch_remove_kprobe(struct kprobe *p);
56
57/* Architecture specific copy of original instruction */
58struct arch_specific_insn {
59 /* copy of original instruction */
60 kprobe_opcode_t *insn;
61 /*
62 * Set in kprobes code, initially to 0. If the instruction can be
63 * eumulated, this is set to 1, if not, to -1.
64 */
65 int boostable;
66};
67
68struct prev_kprobe {
69 struct kprobe *kp;
70 unsigned long status;
71 unsigned long saved_msr;
72};
73
74/* per-cpu kprobe control block */
75struct kprobe_ctlblk {
76 unsigned long kprobe_status;
77 unsigned long kprobe_saved_msr;
78 struct prev_kprobe prev_kprobe;
79};
80
81struct arch_optimized_insn {
82 kprobe_opcode_t copied_insn[1];
83 /* detour buffer */
84 kprobe_opcode_t *insn;
85};
86
87extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
88extern int kprobe_handler(struct pt_regs *regs);
89extern int kprobe_post_handler(struct pt_regs *regs);
90#else
91static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
92static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
93#endif /* CONFIG_KPROBES */
94#endif /* __KERNEL__ */
95#endif /* _ASM_POWERPC_KPROBES_H */
1#ifndef _ASM_POWERPC_KPROBES_H
2#define _ASM_POWERPC_KPROBES_H
3#ifdef __KERNEL__
4/*
5 * Kernel Probes (KProbes)
6 *
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>
31#include <linux/percpu.h>
32
33#define __ARCH_WANT_KPROBES_INSN_SLOT
34
35struct pt_regs;
36struct kprobe;
37
38typedef unsigned int kprobe_opcode_t;
39#define BREAKPOINT_INSTRUCTION 0x7fe00008 /* trap */
40#define MAX_INSN_SIZE 1
41
42#define IS_TW(instr) (((instr) & 0xfc0007fe) == 0x7c000008)
43#define IS_TD(instr) (((instr) & 0xfc0007fe) == 0x7c000088)
44#define IS_TDI(instr) (((instr) & 0xfc000000) == 0x08000000)
45#define IS_TWI(instr) (((instr) & 0xfc000000) == 0x0c000000)
46
47#ifdef CONFIG_PPC64
48/*
49 * 64bit powerpc uses function descriptors.
50 * Handle cases where:
51 * - User passes a <.symbol> or <module:.symbol>
52 * - User passes a <symbol> or <module:symbol>
53 * - User passes a non-existent symbol, kallsyms_lookup_name
54 * returns 0. Don't deref the NULL pointer in that case
55 */
56#define kprobe_lookup_name(name, addr) \
57{ \
58 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
59 if (addr) { \
60 char *colon; \
61 if ((colon = strchr(name, ':')) != NULL) { \
62 colon++; \
63 if (*colon != '\0' && *colon != '.') \
64 addr = *(kprobe_opcode_t **)addr; \
65 } else if (name[0] != '.') \
66 addr = *(kprobe_opcode_t **)addr; \
67 } else { \
68 char dot_name[KSYM_NAME_LEN]; \
69 dot_name[0] = '.'; \
70 dot_name[1] = '\0'; \
71 strncat(dot_name, name, KSYM_NAME_LEN - 2); \
72 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \
73 } \
74}
75
76#define is_trap(instr) (IS_TW(instr) || IS_TD(instr) || \
77 IS_TWI(instr) || IS_TDI(instr))
78#else
79/* Use stock kprobe_lookup_name since ppc32 doesn't use function descriptors */
80#define is_trap(instr) (IS_TW(instr) || IS_TWI(instr))
81#endif
82
83#define flush_insn_slot(p) do { } while (0)
84#define kretprobe_blacklist_size 0
85
86void kretprobe_trampoline(void);
87extern void arch_remove_kprobe(struct kprobe *p);
88
89/* Architecture specific copy of original instruction */
90struct arch_specific_insn {
91 /* copy of original instruction */
92 kprobe_opcode_t *insn;
93 /*
94 * Set in kprobes code, initially to 0. If the instruction can be
95 * eumulated, this is set to 1, if not, to -1.
96 */
97 int boostable;
98};
99
100struct prev_kprobe {
101 struct kprobe *kp;
102 unsigned long status;
103 unsigned long saved_msr;
104};
105
106/* per-cpu kprobe control block */
107struct kprobe_ctlblk {
108 unsigned long kprobe_status;
109 unsigned long kprobe_saved_msr;
110 struct pt_regs jprobe_saved_regs;
111 struct prev_kprobe prev_kprobe;
112};
113
114extern int kprobe_exceptions_notify(struct notifier_block *self,
115 unsigned long val, void *data);
116extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
117#endif /* __KERNEL__ */
118#endif /* _ASM_POWERPC_KPROBES_H */