1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Kernel Probes (KProbes) 4 * 5 * Copyright (C) 2020 Loongson Technology Corporation Limited 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; version 2 of the License. 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 */ 20 21 #ifndef _ASM_KPROBES_H 22 #define _ASM_KPROBES_H 23 24 #include <asm-generic/kprobes.h> 25 26 #ifdef CONFIG_KPROBES 27 #include <linux/ptrace.h> 28 #include <linux/types.h> 29 30 #include <asm/cacheflush.h> 31 #include <asm/kdebug.h> 32 #include <asm/inst.h> 33 34 #define __ARCH_WANT_KPROBES_INSN_SLOT 35 36 struct kprobe; 37 struct pt_regs; 38 39 typedef union loongarch_instruction kprobe_opcode_t; 40 41 #define MAX_INSN_SIZE 2 42 43 #define flush_insn_slot(p) \ 44 do { \ 45 if (p->addr) \ 46 flush_icache_range((unsigned long)p->addr, \ 47 (unsigned long)p->addr + \ 48 (MAX_INSN_SIZE * sizeof(kprobe_opcode_t))); \ 49 } while (0) 50 51 52 #define kretprobe_blacklist_size 0 53 54 void arch_remove_kprobe(struct kprobe *p); 55 int kprobe_fault_handler(struct pt_regs *regs, int trapnr); 56 57 /* Architecture specific copy of original instruction*/ 58 struct arch_specific_insn { 59 /* copy of the original instruction */ 60 kprobe_opcode_t *insn; 61 }; 62 63 struct prev_kprobe { 64 struct kprobe *kp; 65 unsigned long status; 66 unsigned long old_SR; 67 unsigned long saved_SR; 68 unsigned long saved_era; 69 }; 70 71 /* per-cpu kprobe control block */ 72 struct kprobe_ctlblk { 73 unsigned long kprobe_status; 74 unsigned long kprobe_old_SR; 75 unsigned long kprobe_saved_SR; 76 unsigned long kprobe_saved_era; 77 /* Per-thread fields, used while emulating branches */ 78 unsigned long flags; 79 unsigned long target_era; 80 struct prev_kprobe prev_kprobe; 81 }; 82 83 extern int kprobe_exceptions_notify(struct notifier_block *self, 84 unsigned long val, void *data); 85 86 #endif /* CONFIG_KPROBES */ 87 #endif /* _ASM_KPROBES_H */ 88