cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

kprobes.h (3463B)


      1/* SPDX-License-Identifier: GPL-2.0-or-later */
      2#ifndef _ASM_X86_KPROBES_H
      3#define _ASM_X86_KPROBES_H
      4/*
      5 *  Kernel Probes (KProbes)
      6 *
      7 * Copyright (C) IBM Corporation, 2002, 2004
      8 *
      9 * See arch/x86/kernel/kprobes.c for x86 kprobes history.
     10 */
     11
     12#include <asm-generic/kprobes.h>
     13
     14#ifdef CONFIG_KPROBES
     15#include <linux/types.h>
     16#include <linux/ptrace.h>
     17#include <linux/percpu.h>
     18#include <asm/text-patching.h>
     19#include <asm/insn.h>
     20
     21#define  __ARCH_WANT_KPROBES_INSN_SLOT
     22
     23struct pt_regs;
     24struct kprobe;
     25
     26typedef u8 kprobe_opcode_t;
     27
     28#define MAX_STACK_SIZE 64
     29#define CUR_STACK_SIZE(ADDR) \
     30	(current_top_of_stack() - (unsigned long)(ADDR))
     31#define MIN_STACK_SIZE(ADDR)				\
     32	(MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ?	\
     33	 MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
     34
     35#define flush_insn_slot(p)	do { } while (0)
     36
     37/* optinsn template addresses */
     38extern __visible kprobe_opcode_t optprobe_template_entry[];
     39extern __visible kprobe_opcode_t optprobe_template_clac[];
     40extern __visible kprobe_opcode_t optprobe_template_val[];
     41extern __visible kprobe_opcode_t optprobe_template_call[];
     42extern __visible kprobe_opcode_t optprobe_template_end[];
     43#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE)
     44#define MAX_OPTINSN_SIZE 				\
     45	(((unsigned long)optprobe_template_end -	\
     46	  (unsigned long)optprobe_template_entry) +	\
     47	 MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE)
     48
     49extern const int kretprobe_blacklist_size;
     50
     51void arch_remove_kprobe(struct kprobe *p);
     52
     53extern void arch_kprobe_override_function(struct pt_regs *regs);
     54
     55/* Architecture specific copy of original instruction*/
     56struct arch_specific_insn {
     57	/* copy of the original instruction */
     58	kprobe_opcode_t *insn;
     59	/*
     60	 * boostable = 0: This instruction type is not boostable.
     61	 * boostable = 1: This instruction has been boosted: we have
     62	 * added a relative jump after the instruction copy in insn,
     63	 * so no single-step and fixup are needed (unless there's
     64	 * a post_handler).
     65	 */
     66	unsigned boostable:1;
     67	unsigned char size;	/* The size of insn */
     68	union {
     69		unsigned char opcode;
     70		struct {
     71			unsigned char type;
     72		} jcc;
     73		struct {
     74			unsigned char type;
     75			unsigned char asize;
     76		} loop;
     77		struct {
     78			unsigned char reg;
     79		} indirect;
     80	};
     81	s32 rel32;	/* relative offset must be s32, s16, or s8 */
     82	void (*emulate_op)(struct kprobe *p, struct pt_regs *regs);
     83	/* Number of bytes of text poked */
     84	int tp_len;
     85};
     86
     87struct arch_optimized_insn {
     88	/* copy of the original instructions */
     89	kprobe_opcode_t copied_insn[DISP32_SIZE];
     90	/* detour code buffer */
     91	kprobe_opcode_t *insn;
     92	/* the size of instructions copied to detour code buffer */
     93	size_t size;
     94};
     95
     96/* Return true (!0) if optinsn is prepared for optimization. */
     97static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
     98{
     99	return optinsn->size;
    100}
    101
    102struct prev_kprobe {
    103	struct kprobe *kp;
    104	unsigned long status;
    105	unsigned long old_flags;
    106	unsigned long saved_flags;
    107};
    108
    109/* per-cpu kprobe control block */
    110struct kprobe_ctlblk {
    111	unsigned long kprobe_status;
    112	unsigned long kprobe_old_flags;
    113	unsigned long kprobe_saved_flags;
    114	struct prev_kprobe prev_kprobe;
    115};
    116
    117extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
    118extern int kprobe_exceptions_notify(struct notifier_block *self,
    119				    unsigned long val, void *data);
    120extern int kprobe_int3_handler(struct pt_regs *regs);
    121
    122#else
    123
    124static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
    125
    126#endif /* CONFIG_KPROBES */
    127#endif /* _ASM_X86_KPROBES_H */