powerpc: Reject probes on instructions that can't be single stepped
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Wed, 30 Mar 2022 14:07:18 +0000 (19:37 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 5 May 2022 14:00:20 +0000 (00:00 +1000)
commit54cdacd7d3b3c1a8dc10965f56c8b5eb8eda1a33
treef2827fb522282693d36de004170c5a42df965b0b
parentf31c618373f2051a32e30002d8eacad7bbbd3885
powerpc: Reject probes on instructions that can't be single stepped

Per the ISA, a Trace interrupt is not generated for:
- [h|u]rfi[d]
- rfscv
- sc, scv, and Trap instructions that trap
- Power-Saving Mode instructions
- other instructions that cause interrupts (other than Trace interrupts)
- the first instructions of any interrupt handler (applies to Branch and Single Step tracing;
CIABR matches may still occur)
- instructions that are emulated by software

Add a helper to check for instructions belonging to the first four
categories above and to reject kprobes, uprobes and xmon breakpoints on
such instructions. We reject probing on instructions belonging to these
categories across all ISA versions and across both BookS and BookE.

For trap instructions, we can't know in advance if they can cause a
trap, and there is no good reason to allow probing on those. Also,
uprobes already refuses to probe trap instructions and kprobes does not
allow probes on trap instructions used for kernel warnings and bugs. As
such, stop allowing any type of probes/breakpoints on trap instruction
across uprobes, kprobes and xmon.

For some of the fp/altivec instructions that can generate an interrupt
and which we emulate in the kernel (altivec assist, for example), we
check and turn off single stepping in emulate_single_step().

Instructions generating a DSI are restarted and single stepping normally
completes once the instruction is completed.

In uprobes, if a single stepped instruction results in a non-fatal
signal to be delivered to the task, such signals are "delayed" until
after the instruction completes. For fatal signals, single stepping is
cancelled and the instruction restarted in-place so that core dump
captures proper addresses.

In kprobes, we do not allow probes on instructions having an extable
entry and we also do not allow probing interrupt vectors.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/f56ee979d50b8711fae350fc97870f3ca34acd75.1648648712.git.naveen.n.rao@linux.vnet.ibm.com
arch/powerpc/include/asm/ppc-opcode.h
arch/powerpc/include/asm/probes.h
arch/powerpc/kernel/kprobes.c
arch/powerpc/kernel/uprobes.c
arch/powerpc/xmon/xmon.c