^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_KPROBES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_KPROBES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Kernel Probes (KProbes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) IBM Corporation, 2002, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) Intel Corporation, 2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * <anil.s.keshavamurthy@intel.com> adapted from i386
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm-generic/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/break.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifdef CONFIG_KPROBES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define __ARCH_WANT_KPROBES_INSN_SLOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MAX_INSN_SIZE 2 /* last half is for kprobe-booster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define NOP_M_INST (long)(1<<27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define BRL_INST(i1, i2) ((long)((0xcL << 37) | /* brl */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) (0x1L << 12) | /* many */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) (((i1) & 1) << 36) | ((i2) << 13))) /* imm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) typedef union cmp_inst {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned long long qp : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned long long p1 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned long long c : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned long long r2 : 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long long r3 : 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long long p2 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned long long ta : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned long long x2 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned long long tb : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned long long opcode : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned long long reserved : 23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned long long l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) } cmp_inst_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct kprobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) typedef struct _bundle {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long long template : 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned long long slot0 : 41;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned long long slot1_p0 : 64-46;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) } quad0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long long slot1_p1 : 41 - (64-46);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned long long slot2 : 41;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) } quad1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) } __attribute__((__aligned__(16))) bundle_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct prev_kprobe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct kprobe *kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define MAX_PARAM_RSE_SIZE (0x60+0x60/0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* per-cpu kprobe control block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define ARCH_PREV_KPROBE_SZ 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct kprobe_ctlblk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long kprobe_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned long *bsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned long cfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) atomic_t prev_kprobe_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define kretprobe_blacklist_size 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define SLOT0_OPCODE_SHIFT (37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SLOT1_p1_OPCODE_SHIFT (37 - (64-46))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define SLOT2_OPCODE_SHIFT (37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define INDIRECT_CALL_OPCODE (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define IP_RELATIVE_CALL_OPCODE (5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define IP_RELATIVE_BRANCH_OPCODE (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define IP_RELATIVE_PREDICT_OPCODE (7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define LONG_BRANCH_OPCODE (0xC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define LONG_CALL_OPCODE (0xD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define flush_insn_slot(p) do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) typedef struct kprobe_opcode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) bundle_t bundle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } kprobe_opcode_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Architecture specific copy of original instruction*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct arch_specific_insn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* copy of the instruction to be emulated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) kprobe_opcode_t *insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define INST_FLAG_FIX_RELATIVE_IP_ADDR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define INST_FLAG_FIX_BRANCH_REG 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define INST_FLAG_BREAK_INST 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define INST_FLAG_BOOSTABLE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned long inst_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned short target_br_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned short slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) extern int kprobe_exceptions_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned long val, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) extern void invalidate_stacked_regs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) extern void flush_register_stack(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) extern void arch_remove_kprobe(struct kprobe *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif /* CONFIG_KPROBES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #endif /* _ASM_KPROBES_H */