// SPDX-License-Identifier: GPL-2.0-or-later /* * User-space Probes (UProbes) for powerpc * * Copyright IBM Corporation, 2007-2012 * * Adapted from the x86 port by Ananth N Mavinakayanahalli <ananth@in.ibm.com>
*/ #include <linux/kernel.h> #include <linux/sched.h> #include <linux/ptrace.h> #include <linux/uprobes.h> #include <linux/uaccess.h> #include <linux/kdebug.h>
#include <asm/sstep.h> #include <asm/inst.h>
#define UPROBE_TRAP_NR UINT_MAX
/** * is_trap_insn - check if the instruction is a trap variant * @insn: instruction to be checked. * Returns true if @insn is a trap variant.
*/ bool is_trap_insn(uprobe_opcode_t *insn)
{ return (is_trap(*insn));
}
/** * arch_uprobe_analyze_insn * @mm: the probed address space. * @arch_uprobe: the probepoint information. * @addr: vaddr to probe. * Return 0 on success or a -ve number on error.
*/ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsignedlong addr)
{ if (addr & 0x03) return -EINVAL;
if (cpu_has_feature(CPU_FTR_ARCH_31) &&
ppc_inst_prefixed(ppc_inst_read(auprobe->insn)) &&
(addr & 0x3f) == 60) {
pr_info_ratelimited("Cannot register a uprobe on 64 byte unaligned prefixed instruction\n"); return -EINVAL;
}
if (!can_single_step(ppc_inst_val(ppc_inst_read(auprobe->insn)))) {
pr_info_ratelimited("Cannot register a uprobe on instructions that can't be single stepped\n"); return -ENOTSUPP;
}
return 0;
}
/* * arch_uprobe_pre_xol - prepare to execute out of line. * @auprobe: the probepoint information. * @regs: reflects the saved user state of current task.
*/ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct arch_uprobe_task *autask = ¤t->utask->autask;
/** * uprobe_get_swbp_addr - compute address of swbp given post-swbp regs * @regs: Reflects the saved state of the task after it has hit a breakpoint * instruction. * Return the address of the breakpoint instruction.
*/ unsignedlong uprobe_get_swbp_addr(struct pt_regs *regs)
{ return instruction_pointer(regs);
}
/* * If xol insn itself traps and generates a signal (SIGILL/SIGSEGV/etc), * then detect the case where a singlestepped instruction jumps back to its * own address. It is assumed that anything like do_page_fault/do_trap/etc * sets thread.trap_nr != UINT_MAX. * * arch_uprobe_pre_xol/arch_uprobe_post_xol save/restore thread.trap_nr, * arch_uprobe_xol_was_trapped() simply checks that ->trap_nr is not equal to * UPROBE_TRAP_NR == UINT_MAX set by arch_uprobe_pre_xol().
*/ bool arch_uprobe_xol_was_trapped(struct task_struct *t)
{ if (t->thread.trap_nr != UPROBE_TRAP_NR) returntrue;
returnfalse;
}
/* * Called after single-stepping. To avoid the SMP problems that can * occur when we temporarily put back the original opcode to * single-step, we single-stepped a copy of the instruction. * * This function prepares to resume execution after the single-step.
*/ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct uprobe_task *utask = current->utask;
/* * On powerpc, except for loads and stores, most instructions * including ones that alter code flow (branches, calls, returns) * are emulated in the kernel. We get here only if the emulation * support doesn't exist and have to fix-up the next instruction * to be executed.
*/
regs_set_return_ip(regs, (unsignedlong)ppc_inst_next((void *)utask->vaddr, auprobe->insn));
/* regs == NULL is a kernel bug */ if (WARN_ON(!regs)) return NOTIFY_DONE;
/* We are only interested in userspace traps */ if (!user_mode(regs)) return NOTIFY_DONE;
switch (val) { case DIE_BPT: if (uprobe_pre_sstep_notifier(regs)) return NOTIFY_STOP; break; case DIE_SSTEP: if (uprobe_post_sstep_notifier(regs)) return NOTIFY_STOP; break; default: break;
} return NOTIFY_DONE;
}
/* * This function gets called when XOL instruction either gets trapped or * the thread has a fatal signal, so reset the instruction pointer to its * probed address.
*/ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct uprobe_task *utask = current->utask;
/* * See if the instruction can be emulated. * Returns true if instruction was emulated, false otherwise.
*/ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ int ret;
/* * emulate_step() returns 1 if the insn was successfully emulated. * For all other cases, we need to single-step in hardware.
*/
ret = emulate_step(regs, ppc_inst_read(auprobe->insn)); if (ret > 0) returntrue;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.