mirror of
https://github.com/torvalds/linux.git
synced 2026-11-27 08:52:27 +00:00
Consolidate x86 instruction decoder users on the path of copying original code for kprobes. Kprobes decodes the same instruction a maximum of 3 times when preparing the instruction buffer: - The first time for getting the length of the instruction, - the 2nd for adjusting displacement, - and the 3rd for checking whether the instruction is boostable or not. For each time, the actual decoding target address is slightly different (1st is original address or recovered instruction buffer, 2nd and 3rd are pointing to the copied buffer), but all have the same instruction. Thus, this patch also changes the target address to the copied buffer at first and reuses the decoded "insn" for displacement adjusting and checking boostability. Signed-off-by: Masami Hiramatsu <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Anil S Keshavamurthy <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: David S . Miller <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ye Xiaolong <[email protected]> Link: http://lkml.kernel.org/r/149076389643.22469.13151892839998777373.stgit@devbox Signed-off-by: Ingo Molnar <[email protected]>
109 lines
2.8 KiB
C
109 lines
2.8 KiB
C
#ifndef __X86_KERNEL_KPROBES_COMMON_H
|
|
#define __X86_KERNEL_KPROBES_COMMON_H
|
|
|
|
/* Kprobes and Optprobes common header */
|
|
|
|
#ifdef CONFIG_X86_64
|
|
#define SAVE_REGS_STRING \
|
|
/* Skip cs, ip, orig_ax. */ \
|
|
" subq $24, %rsp\n" \
|
|
" pushq %rdi\n" \
|
|
" pushq %rsi\n" \
|
|
" pushq %rdx\n" \
|
|
" pushq %rcx\n" \
|
|
" pushq %rax\n" \
|
|
" pushq %r8\n" \
|
|
" pushq %r9\n" \
|
|
" pushq %r10\n" \
|
|
" pushq %r11\n" \
|
|
" pushq %rbx\n" \
|
|
" pushq %rbp\n" \
|
|
" pushq %r12\n" \
|
|
" pushq %r13\n" \
|
|
" pushq %r14\n" \
|
|
" pushq %r15\n"
|
|
#define RESTORE_REGS_STRING \
|
|
" popq %r15\n" \
|
|
" popq %r14\n" \
|
|
" popq %r13\n" \
|
|
" popq %r12\n" \
|
|
" popq %rbp\n" \
|
|
" popq %rbx\n" \
|
|
" popq %r11\n" \
|
|
" popq %r10\n" \
|
|
" popq %r9\n" \
|
|
" popq %r8\n" \
|
|
" popq %rax\n" \
|
|
" popq %rcx\n" \
|
|
" popq %rdx\n" \
|
|
" popq %rsi\n" \
|
|
" popq %rdi\n" \
|
|
/* Skip orig_ax, ip, cs */ \
|
|
" addq $24, %rsp\n"
|
|
#else
|
|
#define SAVE_REGS_STRING \
|
|
/* Skip cs, ip, orig_ax and gs. */ \
|
|
" subl $16, %esp\n" \
|
|
" pushl %fs\n" \
|
|
" pushl %es\n" \
|
|
" pushl %ds\n" \
|
|
" pushl %eax\n" \
|
|
" pushl %ebp\n" \
|
|
" pushl %edi\n" \
|
|
" pushl %esi\n" \
|
|
" pushl %edx\n" \
|
|
" pushl %ecx\n" \
|
|
" pushl %ebx\n"
|
|
#define RESTORE_REGS_STRING \
|
|
" popl %ebx\n" \
|
|
" popl %ecx\n" \
|
|
" popl %edx\n" \
|
|
" popl %esi\n" \
|
|
" popl %edi\n" \
|
|
" popl %ebp\n" \
|
|
" popl %eax\n" \
|
|
/* Skip ds, es, fs, gs, orig_ax, and ip. Note: don't pop cs here*/\
|
|
" addl $24, %esp\n"
|
|
#endif
|
|
|
|
/* Ensure if the instruction can be boostable */
|
|
extern int can_boost(struct insn *insn, void *orig_addr);
|
|
/* Recover instruction if given address is probed */
|
|
extern unsigned long recover_probed_instruction(kprobe_opcode_t *buf,
|
|
unsigned long addr);
|
|
/*
|
|
* Copy an instruction and adjust the displacement if the instruction
|
|
* uses the %rip-relative addressing mode.
|
|
*/
|
|
extern int __copy_instruction(u8 *dest, u8 *src, struct insn *insn);
|
|
|
|
/* Generate a relative-jump/call instruction */
|
|
extern void synthesize_reljump(void *from, void *to);
|
|
extern void synthesize_relcall(void *from, void *to);
|
|
|
|
#ifdef CONFIG_OPTPROBES
|
|
extern int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter);
|
|
extern unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr);
|
|
#else /* !CONFIG_OPTPROBES */
|
|
static inline int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr)
|
|
{
|
|
return addr;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_KPROBES_ON_FTRACE
|
|
extern int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
|
struct kprobe_ctlblk *kcb);
|
|
#else
|
|
static inline int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
|
struct kprobe_ctlblk *kcb)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif
|
|
#endif
|