| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | #ifndef _ASM_X86_KPROBES_H |
|---|
| 2 | 3 | #define _ASM_X86_KPROBES_H |
|---|
| 3 | 4 | /* |
|---|
| 4 | 5 | * Kernel Probes (KProbes) |
|---|
| 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 as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | 6 | * |
|---|
| 20 | 7 | * Copyright (C) IBM Corporation, 2002, 2004 |
|---|
| 21 | 8 | * |
|---|
| .. | .. |
|---|
| 24 | 11 | |
|---|
| 25 | 12 | #include <asm-generic/kprobes.h> |
|---|
| 26 | 13 | |
|---|
| 27 | | -#define BREAKPOINT_INSTRUCTION 0xcc |
|---|
| 28 | | - |
|---|
| 29 | 14 | #ifdef CONFIG_KPROBES |
|---|
| 30 | 15 | #include <linux/types.h> |
|---|
| 31 | 16 | #include <linux/ptrace.h> |
|---|
| 32 | 17 | #include <linux/percpu.h> |
|---|
| 18 | +#include <asm/text-patching.h> |
|---|
| 33 | 19 | #include <asm/insn.h> |
|---|
| 34 | 20 | |
|---|
| 35 | 21 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
|---|
| .. | .. |
|---|
| 38 | 24 | struct kprobe; |
|---|
| 39 | 25 | |
|---|
| 40 | 26 | typedef u8 kprobe_opcode_t; |
|---|
| 41 | | -#define RELATIVEJUMP_OPCODE 0xe9 |
|---|
| 42 | | -#define RELATIVEJUMP_SIZE 5 |
|---|
| 43 | | -#define RELATIVECALL_OPCODE 0xe8 |
|---|
| 44 | | -#define RELATIVE_ADDR_SIZE 4 |
|---|
| 27 | + |
|---|
| 45 | 28 | #define MAX_STACK_SIZE 64 |
|---|
| 46 | 29 | #define CUR_STACK_SIZE(ADDR) \ |
|---|
| 47 | 30 | (current_top_of_stack() - (unsigned long)(ADDR)) |
|---|
| .. | .. |
|---|
| 53 | 36 | |
|---|
| 54 | 37 | /* optinsn template addresses */ |
|---|
| 55 | 38 | extern __visible kprobe_opcode_t optprobe_template_entry[]; |
|---|
| 39 | +extern __visible kprobe_opcode_t optprobe_template_clac[]; |
|---|
| 56 | 40 | extern __visible kprobe_opcode_t optprobe_template_val[]; |
|---|
| 57 | 41 | extern __visible kprobe_opcode_t optprobe_template_call[]; |
|---|
| 58 | 42 | extern __visible kprobe_opcode_t optprobe_template_end[]; |
|---|
| 59 | | -#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE) |
|---|
| 43 | +#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE) |
|---|
| 60 | 44 | #define MAX_OPTINSN_SIZE \ |
|---|
| 61 | 45 | (((unsigned long)optprobe_template_end - \ |
|---|
| 62 | 46 | (unsigned long)optprobe_template_entry) + \ |
|---|
| 63 | | - MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE) |
|---|
| 47 | + MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE) |
|---|
| 64 | 48 | |
|---|
| 65 | 49 | extern const int kretprobe_blacklist_size; |
|---|
| 66 | 50 | |
|---|
| .. | .. |
|---|
| 74 | 58 | /* copy of the original instruction */ |
|---|
| 75 | 59 | kprobe_opcode_t *insn; |
|---|
| 76 | 60 | /* |
|---|
| 77 | | - * boostable = false: This instruction type is not boostable. |
|---|
| 78 | | - * boostable = true: This instruction has been boosted: we have |
|---|
| 61 | + * boostable = 0: This instruction type is not boostable. |
|---|
| 62 | + * boostable = 1: This instruction has been boosted: we have |
|---|
| 79 | 63 | * added a relative jump after the instruction copy in insn, |
|---|
| 80 | 64 | * so no single-step and fixup are needed (unless there's |
|---|
| 81 | 65 | * a post_handler). |
|---|
| 82 | 66 | */ |
|---|
| 83 | | - bool boostable; |
|---|
| 84 | | - bool if_modifier; |
|---|
| 67 | + unsigned boostable:1; |
|---|
| 68 | + unsigned char size; /* The size of insn */ |
|---|
| 69 | + union { |
|---|
| 70 | + unsigned char opcode; |
|---|
| 71 | + struct { |
|---|
| 72 | + unsigned char type; |
|---|
| 73 | + } jcc; |
|---|
| 74 | + struct { |
|---|
| 75 | + unsigned char type; |
|---|
| 76 | + unsigned char asize; |
|---|
| 77 | + } loop; |
|---|
| 78 | + struct { |
|---|
| 79 | + unsigned char reg; |
|---|
| 80 | + } indirect; |
|---|
| 81 | + }; |
|---|
| 82 | + s32 rel32; /* relative offset must be s32, s16, or s8 */ |
|---|
| 83 | + void (*emulate_op)(struct kprobe *p, struct pt_regs *regs); |
|---|
| 84 | + /* Number of bytes of text poked */ |
|---|
| 85 | + int tp_len; |
|---|
| 85 | 86 | }; |
|---|
| 86 | 87 | |
|---|
| 87 | 88 | struct arch_optimized_insn { |
|---|
| 88 | 89 | /* copy of the original instructions */ |
|---|
| 89 | | - kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE]; |
|---|
| 90 | + kprobe_opcode_t copied_insn[DISP32_SIZE]; |
|---|
| 90 | 91 | /* detour code buffer */ |
|---|
| 91 | 92 | kprobe_opcode_t *insn; |
|---|
| 92 | 93 | /* the size of instructions copied to detour code buffer */ |
|---|
| .. | .. |
|---|
| 118 | 119 | extern int kprobe_exceptions_notify(struct notifier_block *self, |
|---|
| 119 | 120 | unsigned long val, void *data); |
|---|
| 120 | 121 | extern int kprobe_int3_handler(struct pt_regs *regs); |
|---|
| 121 | | -extern int kprobe_debug_handler(struct pt_regs *regs); |
|---|
| 122 | + |
|---|
| 123 | +#else |
|---|
| 124 | + |
|---|
| 125 | +static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; } |
|---|
| 122 | 126 | |
|---|
| 123 | 127 | #endif /* CONFIG_KPROBES */ |
|---|
| 124 | 128 | #endif /* _ASM_X86_KPROBES_H */ |
|---|