Skip to contentSkip to conversation

uprobes: Add uprobes support for ARM

PATCH Superseded David Long 5 participants 29 messages Feb 10, 2014 – Mar 6, 2014

Subsystems (5)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

David Long

author
#0 lore raw

v6 cover uprobes: Add uprobes support for ARM

From: "David A. Long" <[email protected]>

This patch series adds basic uprobes support to ARM. It is based on patches developed earlier by Rabin Vincent. That approach of adding hooks into the kprobes instruction parsing code was not well received. This approach separates the ARM instruction parsing code in kprobes out into a separate set of functions which can be used by both kprobes and uprobes. Both kprobes and uprobes then provide their own semantic action tables to process the results of the parsing.

The following are noteworthy changes made for v6:

1) Put back the "const" type modifier in decode table usage.
2) Made t16_decode_pop() static again.
3) Merged the last patch back into the previous patch, to avoid needlessly introducing a uprobes dependency on kprobes in Kconfig.
4) Added a signed-off From rabin, and ack's from Tixy.

David A. Long (13):
uprobes: allow ignoring of probe hits
ARM: move shared uprobe/kprobe definitions into new include file
ARM: Move generic arm instruction parsing code to new files for
sharing between features
ARM: move generic thumb instruction parsing code to new files for use
by other feature
ARM: use a function table for determining instruction interpreter
action
ARM: Remove use of struct kprobe from generic probes code
ARM: Make the kprobes condition_check symbol names more generic
ARM: Change more ARM kprobes symbol names to something more
ARM: Rename the shared kprobes/uprobe return value enum
ARM: Change the remaining shared kprobes/uprobes symbols to something
generic
ARM: Add an emulate flag to the kprobes/uprobes instruction decode
functions
ARM: Make arch_specific_insn a define for new arch_probes_insn
structure
ARM: add uprobes support

Jon Medhurst (Tixy) (1):
ARM: Disable jprobes test when built into thumb-mode kernel

 arch/arm/Kconfig                                   |    3 +
 arch/arm/include/asm/kprobes.h                     |   15 +-
 arch/arm/include/asm/probes.h                      |   43 +
 arch/arm/include/asm/ptrace.h                      |    6 +
 arch/arm/include/asm/thread_info.h                 |    5 +-
 arch/arm/include/asm/uprobes.h                     |   45 +
 arch/arm/kernel/Makefile                           |    7 +-
 arch/arm/kernel/kprobes-arm.c                      |  804 ++------------
 arch/arm/kernel/kprobes-common.c                   |  468 +-------
 arch/arm/kernel/kprobes-test.c                     |   18 +-
 arch/arm/kernel/kprobes-thumb.c                    | 1142 +++-----------------
 arch/arm/kernel/kprobes.c                          |   23 +-
 arch/arm/kernel/kprobes.h                          |  400 +------
 arch/arm/kernel/{kprobes-arm.c => probes-arm.c}    |  441 ++------
 arch/arm/kernel/probes-arm.h                       |   73 ++
 .../arm/kernel/{kprobes-thumb.c => probes-thumb.c} |  770 ++-----------
 arch/arm/kernel/probes-thumb.h                     |   97 ++
 arch/arm/kernel/{kprobes-common.c => probes.c}     |  205 +---
 arch/arm/kernel/{kprobes.h => probes.h}            |  125 +--
 arch/arm/kernel/signal.c                           |    4 +
 arch/arm/kernel/uprobes-arm.c                      |  232 ++++
 arch/arm/kernel/uprobes.c                          |  208 ++++
 arch/arm/kernel/uprobes.h                          |   35 +
 include/linux/uprobes.h                            |    1 +
 kernel/events/uprobes.c                            |    9 +
 25 files changed, 1341 insertions(+), 3838 deletions(-)
 create mode 100644 arch/arm/include/asm/probes.h
 create mode 100644 arch/arm/include/asm/uprobes.h
 copy arch/arm/kernel/{kprobes-arm.c => probes-arm.c} (64%)
 create mode 100644 arch/arm/kernel/probes-arm.h
 copy arch/arm/kernel/{kprobes-thumb.c => probes-thumb.c} (56%)
 create mode 100644 arch/arm/kernel/probes-thumb.h
 copy arch/arm/kernel/{kprobes-common.c => probes.c} (67%)
 copy arch/arm/kernel/{kprobes.h => probes.h} (80%)
 create mode 100644 arch/arm/kernel/uprobes-arm.c
 create mode 100644 arch/arm/kernel/uprobes.c
 create mode 100644 arch/arm/kernel/uprobes.h
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH v6 1/14 uprobes: allow ignoring of probe hits

From: "David A. Long" <[email protected]>

Allow arches to decided to ignore a probe hit. ARM will use this to only call handlers if the conditions to execute a conditionally executed instruction are satisfied.

---
 include/linux/uprobes.h | 1 +
 kernel/events/uprobes.c | 9 +++++++++
 2 files changed, 10 insertions(+)
include/linux/uprobes.h +1 -0
index e32251e..edff2b9 100644
@@ -126,6 +126,7 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
 extern int  arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
+extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
 #else /* !CONFIG_UPROBES */
 struct uprobes_state {
 };
kernel/events/uprobes.c +9 -0
index 307d87c..04709b6 100644
@@ -1804,6 +1804,11 @@ static bool handle_trampoline(struct pt_regs *regs)
 	return true;
 }
 
+bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs)
+{
+	return false;
+}
+
 /*
  * Run handler and ask thread to singlestep.
  * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
@@ -1858,7 +1863,11 @@ static void handle_swbp(struct pt_regs *regs)
 	if (!get_utask())
 		goto out;
 
+	if (arch_uprobe_ignore(&uprobe->arch, regs))
+		goto out;
+
 	handler_chain(uprobe, regs);
+
 	if (can_skip_sstep(uprobe, regs))
 		goto out;
 
Signature · 1 line
1.8.1.2
author
#2 lore raw

PATCH v6 2/14 ARM: move shared uprobe/kprobe definitions into new include file

In reply to David Long

From: "David A. Long" <[email protected]>

Separate the kprobe-only definitions from the definitions needed by both kprobes and uprobes.

---
 arch/arm/include/asm/kprobes.h               | 15 +---------
 arch/arm/include/asm/{kprobes.h => probes.h} | 44 +++++-----------------------
 2 files changed, 8 insertions(+), 51 deletions(-)
 copy arch/arm/include/asm/{kprobes.h => probes.h} (52%)
arch/arm/include/asm/kprobes.h +1 -14
index f82ec22..30fc11b 100644
@@ -28,21 +28,8 @@
 #define kretprobe_blacklist_size	0
 
 typedef u32 kprobe_opcode_t;
-
 struct kprobe;
-typedef void (kprobe_insn_handler_t)(struct kprobe *, struct pt_regs *);
-typedef unsigned long (kprobe_check_cc)(unsigned long);
-typedef void (kprobe_insn_singlestep_t)(struct kprobe *, struct pt_regs *);
-typedef void (kprobe_insn_fn_t)(void);
-
-/* Architecture specific copy of original instruction. */
-struct arch_specific_insn {
-	kprobe_opcode_t			*insn;
-	kprobe_insn_handler_t		*insn_handler;
-	kprobe_check_cc			*insn_check_cc;
-	kprobe_insn_singlestep_t	*insn_singlestep;
-	kprobe_insn_fn_t		*insn_fn;
-};
+#include <asm/probes.h>
 
 struct prev_kprobe {
 	struct kprobe *kp;
arch/arm/include/asm/probes.h renamed from arch/arm/include/asm/kprobes.h +7 -37

58 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#3 lore raw

PATCH v6 3/14 ARM: Move generic arm instruction parsing code to new files for sharing between features

In reply to David Long

From: "David A. Long" <[email protected]>

Move the arm version of the kprobes instruction parsing code into more generic files from where it can be used by uprobes and possibly other subsystems. The symbol names will be made more generic in a subsequent part of this patchset.

---
 arch/arm/include/asm/probes.h                   |   2 +
 arch/arm/kernel/Makefile                        |   4 +-
 arch/arm/kernel/kprobes-arm.c                   | 722 +-----------------------
 arch/arm/kernel/kprobes-common.c                | 421 --------------
 arch/arm/kernel/kprobes.h                       | 373 +-----------
 arch/arm/kernel/{kprobes-arm.c => probes-arm.c} | 298 +---------
 arch/arm/kernel/probes-arm.h                    |  38 ++
 arch/arm/kernel/{kprobes-common.c => probes.c}  | 150 +----
 arch/arm/kernel/{kprobes.h => probes.h}         |  53 +-
 9 files changed, 79 insertions(+), 1982 deletions(-)
 copy arch/arm/kernel/{kprobes-arm.c => probes-arm.c} (76%)
 create mode 100644 arch/arm/kernel/probes-arm.h
 copy arch/arm/kernel/{kprobes-common.c => probes.c} (74%)
 copy arch/arm/kernel/{kprobes.h => probes.h} (91%)
arch/arm/include/asm/probes.h +2 -0
index 90c5f54..737a9b3 100644
@@ -19,6 +19,8 @@
 #ifndef _ASM_PROBES_H
 #define _ASM_PROBES_H
 
+struct kprobe;
+
 typedef void (kprobe_insn_handler_t)(struct kprobe *, struct pt_regs *);
 typedef unsigned long (kprobe_check_cc)(unsigned long);
 typedef void (kprobe_insn_singlestep_t)(struct kprobe *, struct pt_regs *);
arch/arm/kernel/Makefile +2 -2
index a30fc9b..4c8b13e 100644
@@ -50,11 +50,11 @@ obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o insn.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o insn.o
 obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o insn.o patch.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
-obj-$(CONFIG_KPROBES)		+= kprobes.o kprobes-common.o patch.o
+obj-$(CONFIG_KPROBES)		+= probes.o kprobes.o kprobes-common.o patch.o
 ifdef CONFIG_THUMB2_KERNEL
 obj-$(CONFIG_KPROBES)		+= kprobes-thumb.o
 else
-obj-$(CONFIG_KPROBES)		+= kprobes-arm.o
+obj-$(CONFIG_KPROBES)		+= kprobes-arm.o probes-arm.o
 endif
 obj-$(CONFIG_ARM_KPROBES_TEST)	+= test-kprobes.o
 test-kprobes-objs		:= kprobes-test.o
arch/arm/kernel/kprobes-arm.c +9 -713

780 lines not on this page · raw message

arch/arm/kernel/kprobes-common.c +0 -421

430 lines not on this page · raw message

arch/arm/kernel/kprobes.h +1 -372

378 lines not on this page · raw message

arch/arm/kernel/probes-arm.c renamed from arch/arm/kernel/kprobes-arm.c +11 -287

350 lines not on this page · raw message

arch/arm/kernel/probes-arm.h new file +38 -0
new file mode 100644
index 0000000..8608472
@@ -0,0 +1,38 @@
+/*
+ * arch/arm/kernel/probes-arm.h
+ *
+ * Copyright 2013 Linaro Ltd.
+ * Written by: David A. Long
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef _ARM_KERNEL_PROBES_ARM_H
+#define  _ARM_KERNEL_PROBES_ARM_H
+
+void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs);
+void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs);
+void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs);
+void __kprobes simulate_mrs(struct kprobe *p, struct pt_regs *regs);
+void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs);
+
+void __kprobes emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs);
+void __kprobes emulate_ldr(struct kprobe *p, struct pt_regs *regs);
+void __kprobes emulate_str(struct kprobe *p, struct pt_regs *regs);
+void __kprobes emulate_rd12rn16rm0rs8_rwflags(struct kprobe *p,
+	struct pt_regs *regs);
+void __kprobes emulate_rd12rn16rm0_rwflags_nopc(struct kprobe *p,
+	struct pt_regs *regs);
+void __kprobes emulate_rd16rn12rm0rs8_rwflags_nopc(struct kprobe *p,
+	struct pt_regs *regs);
+void __kprobes emulate_rd12rm0_noflags_nopc(struct kprobe *p,
+	struct pt_regs *regs);
+void __kprobes emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(struct kprobe *p,
+	struct pt_regs *regs);
+
+#endif
arch/arm/kernel/probes.c renamed from arch/arm/kernel/kprobes-common.c +6 -144

188 lines not on this page · raw message

arch/arm/kernel/probes.h renamed from arch/arm/kernel/kprobes.h +10 -43

79 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#4 lore raw

PATCH v6 4/14 ARM: move generic thumb instruction parsing code to new files for use by other feature

In reply to David Long

From: "David A. Long" <[email protected]>

Move the thumb version of the kprobes instruction parsing code into more generic files from where it can be used by uprobes and possibly other subsystems. The symbol names will be made more generic in a subsequent part of this patchset.

---
 arch/arm/kernel/Makefile                           |   2 +-
 arch/arm/kernel/kprobes-thumb.c                    | 946 +--------------------
 .../arm/kernel/{kprobes-thumb.c => probes-thumb.c} | 594 +------------
 arch/arm/kernel/probes-thumb.h                     |  81 ++
 4 files changed, 121 insertions(+), 1502 deletions(-)
 copy arch/arm/kernel/{kprobes-thumb.c => probes-thumb.c} (67%)
 create mode 100644 arch/arm/kernel/probes-thumb.h
arch/arm/kernel/Makefile +1 -1
index 4c8b13e..bb739f2 100644
@@ -52,7 +52,7 @@ obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o insn.o patch.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_KPROBES)		+= probes.o kprobes.o kprobes-common.o patch.o
 ifdef CONFIG_THUMB2_KERNEL
-obj-$(CONFIG_KPROBES)		+= kprobes-thumb.o
+obj-$(CONFIG_KPROBES)		+= kprobes-thumb.o probes-thumb.o
 else
 obj-$(CONFIG_KPROBES)		+= kprobes-arm.o probes-arm.o
 endif
arch/arm/kernel/kprobes-thumb.c +38 -908

1,159 lines not on this page · raw message

arch/arm/kernel/probes-thumb.c renamed from arch/arm/kernel/kprobes-thumb.c +1 -593

606 lines not on this page · raw message

arch/arm/kernel/probes-thumb.h new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#5 lore raw

PATCH v6 5/14 ARM: use a function table for determining instruction interpreter action

In reply to David Long

From: "David A. Long" <[email protected]>

Make the instruction interpreter call back to semantic action functions through a function pointer array provided by the invoker. The interpreter decodes the instructions into groups and uses the group number to index into the supplied array. kprobes and uprobes code will each supply their own array of functions.

---
 arch/arm/kernel/kprobes-arm.c    |  57 ++++++++++++---
 arch/arm/kernel/kprobes-common.c |   3 +-
 arch/arm/kernel/kprobes-thumb.c  | 149 ++++++++++++++++++++++++++++-----------
 arch/arm/kernel/kprobes.c        |   9 ++-
 arch/arm/kernel/kprobes.h        |  15 ++--
 arch/arm/kernel/probes-arm.c     | 114 +++++++++++++++---------------
 arch/arm/kernel/probes-arm.h     |  52 ++++++++++----
 arch/arm/kernel/probes-thumb.c   | 145 ++++++++++++++++++-------------------
 arch/arm/kernel/probes-thumb.h   | 104 ++++++++++++++-------------
 arch/arm/kernel/probes.c         |   9 +--
 arch/arm/kernel/probes.h         |  55 ++++++++++-----
 11 files changed, 441 insertions(+), 271 deletions(-)
arch/arm/kernel/kprobes-arm.c +49 -8
index a359475..72ee2a9 100644
@@ -73,7 +73,7 @@
 #endif
 
 
-void __kprobes
+static void __kprobes
 emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -102,7 +102,7 @@ emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
 		regs->uregs[rn] = rnv;
 }
 
-void __kprobes
+static void __kprobes
 emulate_ldr(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -132,7 +132,7 @@ emulate_ldr(struct kprobe *p, struct pt_regs *regs)
 		regs->uregs[rn] = rnv;
 }
 
-void __kprobes
+static void __kprobes
 emulate_str(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -159,7 +159,7 @@ emulate_str(struct kprobe *p, struct pt_regs *regs)
 		regs->uregs[rn] = rnv;
 }
 
-void __kprobes
+static void __kprobes
 emulate_rd12rn16rm0rs8_rwflags(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -194,7 +194,7 @@ emulate_rd12rn16rm0rs8_rwflags(struct kprobe *p, struct pt_regs *regs)
 	regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
 }
 
-void __kprobes
+static void __kprobes
 emulate_rd12rn16rm0_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -221,7 +221,7 @@ emulate_rd12rn16rm0_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 	regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
 }
 
-void __kprobes
+static void __kprobes
 emulate_rd16rn12rm0rs8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -250,7 +250,7 @@ emulate_rd16rn12rm0rs8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 	regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
 }
 
-void __kprobes
+static void __kprobes
 emulate_rd12rm0_noflags_nopc(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -270,7 +270,7 @@ emulate_rd12rm0_noflags_nopc(struct kprobe *p, struct pt_regs *regs)
 	regs->uregs[rd] = rdv;
 }
 
-void __kprobes
+static void __kprobes
 emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 {
 	kprobe_opcode_t insn = p->opcode;
@@ -299,3 +299,44 @@ emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
 	regs->uregs[rdhi] = rdhiv;
 	regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
 }
+
+const union decode_action kprobes_arm_actions[NUM_PROBES_ARM_ACTIONS] = {
+	[PROBES_EMULATE_NONE] = {.handler = kprobe_emulate_none},
+	[PROBES_SIMULATE_NOP] = {.handler = kprobe_simulate_nop},
+	[PROBES_PRELOAD_IMM] = {.handler = kprobe_simulate_nop},
+	[PROBES_PRELOAD_REG] = {.handler = kprobe_simulate_nop},
+	[PROBES_BRANCH_IMM] = {.handler = simulate_blx1},
+	[PROBES_MRS] = {.handler = simulate_mrs},
+	[PROBES_BRANCH_REG] = {.handler = simulate_blx2bx},
+	[PROBES_CLZ] = {.handler = emulate_rd12rm0_noflags_nopc},
+	[PROBES_SATURATING_ARITHMETIC] = {
+		.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_MUL1] = {.handler = emulate_rdlo12rdhi16rn0rm8_rwflags_nopc},
+	[PROBES_MUL2] = {.handler = emulate_rd16rn12rm0rs8_rwflags_nopc},
+	[PROBES_SWP] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_LDRSTRD] = {.handler = emulate_ldrdstrd},
+	[PROBES_LOAD_EXTRA] = {.handler = emulate_ldr},
+	[PROBES_LOAD] = {.handler = emulate_ldr},
+	[PROBES_STORE_EXTRA] = {.handler = emulate_str},
+	[PROBES_STORE] = {.handler = emulate_str},
+	[PROBES_MOV_IP_SP] = {.handler = simulate_mov_ipsp},
+	[PROBES_DATA_PROCESSING_REG] = {
+		.handler = emulate_rd12rn16rm0rs8_rwflags},
+	[PROBES_DATA_PROCESSING_IMM] = {
+		.handler = emulate_rd12rn16rm0rs8_rwflags},
+	[PROBES_MOV_HALFWORD] = {.handler = emulate_rd12rm0_noflags_nopc},
+	[PROBES_SEV] = {.handler = kprobe_emulate_none},
+	[PROBES_WFE] = {.handler = kprobe_simulate_nop},
+	[PROBES_SATURATE] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_REV] = {.handler = emulate_rd12rm0_noflags_nopc},
+	[PROBES_MMI] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_PACK] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_EXTEND] = {.handler = emulate_rd12rm0_noflags_nopc},
+	[PROBES_EXTEND_ADD] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
+	[PROBES_MUL_ADD_LONG] = {
+		.handler = emulate_rdlo12rdhi16rn0rm8_rwflags_nopc},
+	[PROBES_MUL_ADD] = {.handler = emulate_rd16rn12rm0rs8_rwflags_nopc},
+	[PROBES_BITFIELD] = {.handler = emulate_rd12rm0_noflags_nopc},
+	[PROBES_BRANCH] = {.handler = simulate_bbl},
+	[PROBES_LDMSTM] = {.decoder = kprobe_decode_ldmstm}
+};
arch/arm/kernel/kprobes-common.c +2 -1
index ed47b54..fe12b90 100644
@@ -113,7 +113,8 @@ emulate_ldm_r3_15(struct kprobe *p, struct pt_regs *regs)
 }
 
 enum kprobe_insn __kprobes
-kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi)
+kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+		const struct decode_header *h)
 {
 	kprobe_insn_handler_t *handler = 0;
 	unsigned reglist = insn & 0xffff;
arch/arm/kernel/kprobes-thumb.c +107 -42

361 lines not on this page · raw message

arch/arm/kernel/kprobes.c +7 -2
index a7b621e..128db0e 100644
@@ -54,6 +54,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 	unsigned long addr = (unsigned long)p->addr;
 	bool thumb;
 	kprobe_decode_insn_t *decode_insn;
+	const union decode_action *actions;
 	int is;
 
 	if (in_exception_text(addr))
@@ -67,20 +68,24 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 		insn <<= 16;
 		insn |= ((u16 *)addr)[1];
 		decode_insn = thumb32_kprobe_decode_insn;
-	} else
+		actions = kprobes_t32_actions;
+	} else {
 		decode_insn = thumb16_kprobe_decode_insn;
+		actions = kprobes_t16_actions;
+	}
 #else /* !CONFIG_THUMB2_KERNEL */
 	thumb = false;
 	if (addr & 0x3)
 		return -EINVAL;
 	insn = *p->addr;
 	decode_insn = arm_kprobe_decode_insn;
+	actions = kprobes_arm_actions;
 #endif
 
 	p->opcode = insn;
 	p->ainsn.insn = tmp_insn;
 
-	switch ((*decode_insn)(insn, &p->ainsn)) {
+	switch ((*decode_insn)(insn, &p->ainsn, actions)) {
 	case INSN_REJECTED:	/* not supported */
 		return -EINVAL;
 
arch/arm/kernel/kprobes.h +11 -4
index aa68c0e..7798035 100644
@@ -27,6 +27,8 @@
 #define KPROBE_THUMB16_BREAKPOINT_INSTRUCTION	0xde18
 #define KPROBE_THUMB32_BREAKPOINT_INSTRUCTION	0xf7f0a018
 
+struct decode_header;
+union decode_action;
 
 enum kprobe_insn {
 	INSN_REJECTED,
@@ -35,19 +37,24 @@ enum kprobe_insn {
 };
 
 typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t,
-						struct arch_specific_insn *);
+						struct arch_specific_insn *,
+						const union decode_action *);
 
 #ifdef CONFIG_THUMB2_KERNEL
 
 enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t,
-						struct arch_specific_insn *);
+					    struct arch_specific_insn *,
+					    const union decode_action *);
 enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t,
-						struct arch_specific_insn *);
+					    struct arch_specific_insn *,
+					    const union decode_action *);
 
 #else /* !CONFIG_THUMB2_KERNEL */
 
 enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t,
-					struct arch_specific_insn *);
+					struct arch_specific_insn *,
+					const union decode_action *);
+
 #endif
 
 void __init arm_kprobe_decode_init(void);
arch/arm/kernel/probes-arm.c +58 -56

388 lines not on this page · raw message

arch/arm/kernel/probes-arm.h +38 -14

62 lines not on this page · raw message

arch/arm/kernel/probes-thumb.c +73 -72

491 lines not on this page · raw message

arch/arm/kernel/probes-thumb.h +55 -49

110 lines not on this page · raw message

arch/arm/kernel/probes.c +5 -4
index 9ab077d..7cd1763 100644
@@ -378,7 +378,8 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
  */
 int __kprobes
 kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
-		   const union decode_item *table, bool thumb)
+		   const union decode_item *table, bool thumb,
+		   const union decode_action *actions)
 {
 	const struct decode_header *h = (struct decode_header *)table;
 	const struct decode_header *next;
@@ -412,18 +413,18 @@ kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
 
 		case DECODE_TYPE_CUSTOM: {
 			struct decode_custom *d = (struct decode_custom *)h;
-			return (*d->decoder.decoder)(insn, asi);
+			return actions[d->decoder.action].decoder(insn, asi, h);
 		}
 
 		case DECODE_TYPE_SIMULATE: {
 			struct decode_simulate *d = (struct decode_simulate *)h;
-			asi->insn_handler = d->handler.handler;
+			asi->insn_handler = actions[d->handler.action].handler;
 			return INSN_GOOD_NO_SLOT;
 		}
 
 		case DECODE_TYPE_EMULATE: {
 			struct decode_emulate *d = (struct decode_emulate *)h;
-			asi->insn_handler = d->handler.handler;
+			asi->insn_handler = actions[d->handler.action].handler;
 			set_emulated_insn(insn, asi, thumb);
 			return INSN_GOOD;
 		}
arch/arm/kernel/probes.h +36 -19

128 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#6 lore raw

PATCH v6 6/14 ARM: Disable jprobes test when built into thumb-mode kernel

In reply to David Long

From: "Jon Medhurst (Tixy)" <[email protected]>

For now the jprobes tests fail on ARM for when built into a kernel compiled in thumb mode. They work fine for ARM kernels, and when built as a loadable module.

---
 arch/arm/kernel/kprobes-test.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm/kernel/kprobes-test.c +10 -0
index 0cd63d0..65230b2 100644
@@ -221,6 +221,7 @@ static int pre_handler_called;
 static int post_handler_called;
 static int jprobe_func_called;
 static int kretprobe_handler_called;
+static int tests_failed;
 
 #define FUNC_ARG1 0x12345678
 #define FUNC_ARG2 0xabcdef
@@ -457,6 +458,13 @@ static int run_api_tests(long (*func)(long, long))
 
 	pr_info("    jprobe\n");
 	ret = test_jprobe(func);
+#if defined(CONFIG_THUMB2_KERNEL) && !defined(MODULE)
+	if (ret == -EINVAL) {
+		pr_err("FAIL: Known longtime bug with jprobe on Thumb kernels");
+		tests_failed = ret;
+		ret = 0;
+	}
+#endif
 	if (ret < 0)
 		return ret;
 
@@ -1667,6 +1675,8 @@ static int __init run_all_tests(void)
 
 out:
 	if (ret == 0)
+		ret = tests_failed;
+	if (ret == 0)
 		pr_info("Finished kprobe tests OK\n");
 	else
 		pr_err("kprobe tests failed\n");
Signature · 1 line
1.8.1.2
author
#7 lore raw

PATCH v6 7/14 ARM: Remove use of struct kprobe from generic probes code

In reply to David Long

From: "David A. Long" <[email protected]>

Change the generic ARM probes code to pass in the opcode and architecture-specific structure separately instead of using struct kprobe, so we do not pollute code being used only for uprobes or other non-kprobes instruction interpretation.

---
 arch/arm/include/asm/probes.h    |   9 +-
 arch/arm/kernel/kprobes-arm.c    |  61 +++++++-------
 arch/arm/kernel/kprobes-common.c |  40 +++++----
 arch/arm/kernel/kprobes-thumb.c  | 175 +++++++++++++++++++--------------------
 arch/arm/kernel/kprobes.c        |   2 +-
 arch/arm/kernel/probes-arm.c     |  33 ++++----
 arch/arm/kernel/probes-arm.h     |  15 ++--
 arch/arm/kernel/probes-thumb.c   |  15 ++--
 arch/arm/kernel/probes.c         |  14 ++--
 arch/arm/kernel/probes.h         |   8 +-
 10 files changed, 201 insertions(+), 171 deletions(-)
arch/arm/include/asm/probes.h +7 -2
index 737a9b3..4d014c4 100644
@@ -21,9 +21,14 @@
 
 struct kprobe;
 
-typedef void (kprobe_insn_handler_t)(struct kprobe *, struct pt_regs *);
+struct arch_specific_insn;
+typedef void (kprobe_insn_handler_t)(kprobe_opcode_t,
+				     struct arch_specific_insn *,
+				     struct pt_regs *);
 typedef unsigned long (kprobe_check_cc)(unsigned long);
-typedef void (kprobe_insn_singlestep_t)(struct kprobe *, struct pt_regs *);
+typedef void (kprobe_insn_singlestep_t)(kprobe_opcode_t,
+					struct arch_specific_insn *,
+					struct pt_regs *);
 typedef void (kprobe_insn_fn_t)(void);
 
 /* Architecture specific copy of original instruction. */
arch/arm/kernel/kprobes-arm.c +31 -30

166 lines not on this page · raw message

arch/arm/kernel/kprobes-common.c +26 -14
index fe12b90..da65499 100644
@@ -18,9 +18,10 @@
 #include "kprobes.h"
 
 
-static void __kprobes simulate_ldm1stm1(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes simulate_ldm1stm1(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi,
+		struct pt_regs *regs)
 {
-	kprobe_opcode_t insn = p->opcode;
 	int rn = (insn >> 16) & 0xf;
 	int lbit = insn & (1 << 20);
 	int wbit = insn & (1 << 21);
@@ -59,24 +60,31 @@ static void __kprobes simulate_ldm1stm1(struct kprobe *p, struct pt_regs *regs)
 	}
 }
 
-static void __kprobes simulate_stm1_pc(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes simulate_stm1_pc(kprobe_opcode_t insn,
+	struct arch_specific_insn *asi,
+	struct pt_regs *regs)
 {
-	regs->ARM_pc = (long)p->addr + str_pc_offset;
-	simulate_ldm1stm1(p, regs);
-	regs->ARM_pc = (long)p->addr + 4;
+	unsigned long addr = regs->ARM_pc - 4;
+
+	regs->ARM_pc = (long)addr + str_pc_offset;
+	simulate_ldm1stm1(insn, asi, regs);
+	regs->ARM_pc = (long)addr + 4;
 }
 
-static void __kprobes simulate_ldm1_pc(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes simulate_ldm1_pc(kprobe_opcode_t insn,
+	struct arch_specific_insn *asi,
+	struct pt_regs *regs)
 {
-	simulate_ldm1stm1(p, regs);
+	simulate_ldm1stm1(insn, asi, regs);
 	load_write_pc(regs->ARM_pc, regs);
 }
 
 static void __kprobes
-emulate_generic_r0_12_noflags(struct kprobe *p, struct pt_regs *regs)
+emulate_generic_r0_12_noflags(kprobe_opcode_t insn,
+	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	register void *rregs asm("r1") = regs;
-	register void *rfn asm("lr") = p->ainsn.insn_fn;
+	register void *rfn asm("lr") = asi->insn_fn;
 
 	__asm__ __volatile__ (
 		"stmdb	sp!, {%[regs], r11}	\n\t"
@@ -100,15 +108,19 @@ emulate_generic_r0_12_noflags(struct kprobe *p, struct pt_regs *regs)
 }
 
 static void __kprobes
-emulate_generic_r2_14_noflags(struct kprobe *p, struct pt_regs *regs)
+emulate_generic_r2_14_noflags(kprobe_opcode_t insn,
+	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	emulate_generic_r0_12_noflags(p, (struct pt_regs *)(regs->uregs+2));
+	emulate_generic_r0_12_noflags(insn, asi,
+		(struct pt_regs *)(regs->uregs+2));
 }
 
 static void __kprobes
-emulate_ldm_r3_15(struct kprobe *p, struct pt_regs *regs)
+emulate_ldm_r3_15(kprobe_opcode_t insn,
+	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	emulate_generic_r0_12_noflags(p, (struct pt_regs *)(regs->uregs+3));
+	emulate_generic_r0_12_noflags(insn, asi,
+		(struct pt_regs *)(regs->uregs+3));
 	load_write_pc(regs->ARM_pc, regs);
 }
 
arch/arm/kernel/kprobes-thumb.c +86 -89

452 lines not on this page · raw message

arch/arm/kernel/kprobes.c +1 -1
index 128db0e..0206ee9 100644
@@ -202,7 +202,7 @@ singlestep_skip(struct kprobe *p, struct pt_regs *regs)
 static inline void __kprobes
 singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
 {
-	p->ainsn.insn_singlestep(p, regs);
+	p->ainsn.insn_singlestep(p->opcode, &p->ainsn, regs);
 }
 
 /*
arch/arm/kernel/probes-arm.c +17 -16
index c53aedd..7cbe973 100644
@@ -18,8 +18,7 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 
-#include <linux/kprobes.h>
-#include "kprobes.h"
+#include "probes.h"
 #include "probes-arm.h"
 
 #define sign_extend(x, signbit) ((x) | (0 - ((x) & (1 << (signbit)))))
@@ -56,10 +55,10 @@
  * read and write of flags.
  */
 
-void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs)
+void __kprobes simulate_bbl(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	kprobe_opcode_t insn = p->opcode;
-	long iaddr = (long)p->addr;
+	long iaddr = (long) regs->ARM_pc - 4;
 	int disp  = branch_displacement(insn);
 
 	if (insn & (1 << 24))
@@ -68,10 +67,10 @@ void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs)
 	regs->ARM_pc = iaddr + 8 + disp;
 }
 
-void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs)
+void __kprobes simulate_blx1(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	kprobe_opcode_t insn = p->opcode;
-	long iaddr = (long)p->addr;
+	long iaddr = (long) regs->ARM_pc - 4;
 	int disp = branch_displacement(insn);
 
 	regs->ARM_lr = iaddr + 4;
@@ -79,14 +78,14 @@ void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs)
 	regs->ARM_cpsr |= PSR_T_BIT;
 }
 
-void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs)
+void __kprobes simulate_blx2bx(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	kprobe_opcode_t insn = p->opcode;
 	int rm = insn & 0xf;
 	long rmv = regs->uregs[rm];
 
 	if (insn & (1 << 5))
-		regs->ARM_lr = (long)p->addr + 4;
+		regs->ARM_lr = (long) regs->ARM_pc;
 
 	regs->ARM_pc = rmv & ~0x1;
 	regs->ARM_cpsr &= ~PSR_T_BIT;
@@ -94,15 +93,16 @@ void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs)
 		regs->ARM_cpsr |= PSR_T_BIT;
 }
 
-void __kprobes simulate_mrs(struct kprobe *p, struct pt_regs *regs)
+void __kprobes simulate_mrs(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
-	kprobe_opcode_t insn = p->opcode;
 	int rd = (insn >> 12) & 0xf;
 	unsigned long mask = 0xf8ff03df; /* Mask out execution state */
 	regs->uregs[rd] = regs->ARM_cpsr & mask;
 }
 
-void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs)
+void __kprobes simulate_mov_ipsp(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	regs->uregs[12] = regs->uregs[13];
 }
@@ -702,10 +702,11 @@ const union decode_item kprobe_decode_arm_table[] = {
 EXPORT_SYMBOL_GPL(kprobe_decode_arm_table);
 #endif
 
-static void __kprobes arm_singlestep(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes arm_singlestep(kprobe_opcode_t insn,
+		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	regs->ARM_pc += 4;
-	p->ainsn.insn_handler(p, regs);
+	asi->insn_handler(insn, asi, regs);
 }
 
 /* Return:
arch/arm/kernel/probes-arm.h +10 -5
index ef30894..d0ac8a4 100644
@@ -53,10 +53,15 @@ enum probes_arm_action {
 	NUM_PROBES_ARM_ACTIONS
 };
 
-void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs);
-void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs);
-void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs);
-void __kprobes simulate_mrs(struct kprobe *p, struct pt_regs *regs);
-void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs);
+void __kprobes simulate_bbl(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi, struct pt_regs *regs);
+void __kprobes simulate_blx1(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi, struct pt_regs *regs);
+void __kprobes simulate_blx2bx(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi, struct pt_regs *regs);
+void __kprobes simulate_mrs(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi, struct pt_regs *regs);
+void __kprobes simulate_mov_ipsp(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi, struct pt_regs *regs);
 
 #endif
arch/arm/kernel/probes-thumb.c +9 -6
index 278dda3..85dc5af 100644
@@ -9,10 +9,9 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/kprobes.h>
 #include <linux/module.h>
 
-#include "kprobes.h"
+#include "probes.h"
 #include "probes-thumb.h"
 
 
@@ -843,17 +842,21 @@ static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
 	return true;
 }
 
-static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes thumb16_singlestep(kprobe_opcode_t opcode,
+		struct arch_specific_insn *asi,
+		struct pt_regs *regs)
 {
 	regs->ARM_pc += 2;
-	p->ainsn.insn_handler(p, regs);
+	asi->insn_handler(opcode, asi, regs);
 	regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
 }
 
-static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
+static void __kprobes thumb32_singlestep(kprobe_opcode_t opcode,
+		struct arch_specific_insn *asi,
+		struct pt_regs *regs)
 {
 	regs->ARM_pc += 4;
-	p->ainsn.insn_handler(p, regs);
+	asi->insn_handler(opcode, asi, regs);
 	regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
 }
 
arch/arm/kernel/probes.c +8 -6
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/kprobes.h>
 #include <asm/system_info.h>
 
-#include "kprobes.h"
-
+#include "probes.h"
 
 #ifndef find_str_pc_offset
 
@@ -173,13 +171,17 @@ kprobe_check_cc * const kprobe_condition_checks[16] = {
 };
 
 
-void __kprobes kprobe_simulate_nop(struct kprobe *p, struct pt_regs *regs)
+void __kprobes kprobe_simulate_nop(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi,
+	struct pt_regs *regs)
 {
 }
 
-void __kprobes kprobe_emulate_none(struct kprobe *p, struct pt_regs *regs)
+void __kprobes kprobe_emulate_none(kprobe_opcode_t opcode,
+	struct arch_specific_insn *asi,
+	struct pt_regs *regs)
 {
-	p->ainsn.insn_fn();
+	asi->insn_fn();
 }
 
 /*
arch/arm/kernel/probes.h +6 -2
index e446b92..4516616 100644
@@ -20,6 +20,7 @@
 #define  _ARM_KERNEL_PROBES_H
 
 #include <linux/kprobes.h>
+#include "kprobes.h"
 
 #if __LINUX_ARM_ARCH__ >= 7
 
@@ -35,6 +36,7 @@ void __init find_str_pc_offset(void);
 
 #endif
 
+struct decode_header;
 
 /*
  * Update ITSTATE after normal execution of an IT block instruction.
@@ -127,8 +129,10 @@ static inline void __kprobes alu_write_pc(long pcv, struct pt_regs *regs)
 }
 
 
-void __kprobes kprobe_simulate_nop(struct kprobe *p, struct pt_regs *regs);
-void __kprobes kprobe_emulate_none(struct kprobe *p, struct pt_regs *regs);
+void __kprobes kprobe_simulate_nop(kprobe_opcode_t, struct arch_specific_insn *,
+		struct pt_regs *regs);
+void __kprobes kprobe_emulate_none(kprobe_opcode_t, struct arch_specific_insn *,
+		struct pt_regs *regs);
 
 enum kprobe_insn __kprobes
 kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
Signature · 1 line
1.8.1.2
#8 lore raw

Re: [PATCH v6 07/14] ARM: Remove use of struct kprobe from generic probes code

arch/arm/kernel/probes.c line 15

Quoted 10 lines · David Long
arch/arm/kernel/probes.c +0 -1
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/kprobes.h>
 #include <asm/system_info.h>

How well has this code been tested? This file doesn't even build because (I suspect) the above change:

arch/arm/kernel/probes.c: In function 'test_alu_write_pc_interworking':
arch/arm/kernel/probes.c:68:2: error: implicit declaration of function 'BUG_ON' [-Werror=implicit-function-declaration] make[2]: *** [arch/arm/kernel/probes.o] Error 1

This is because linux/kprobes.h includes linux/bug.h, which would provide the requirements for BUG_ON().

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
#9 lore raw

Re: [PATCH v6 07/14] ARM: Remove use of struct kprobe from generic probes code

Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · David Long
arch/arm/kernel/probes.c +0 -0
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
  */
 
Quoted 7 lines

arch/arm/kernel/probes.c line 15

Quoted 3 lines
arch/arm/kernel/probes.c +0 -1
 #include <linux/kernel.h>
-#include <linux/kprobes.h>
 #include <asm/system_info.h>

How well has this code been tested?

From the error below I assume only when __LINUX_ARM_ARCH__ >= 7

I have v5 and v6 hardware and will give it a go on those. I would do v4 but I've no idea how to get a kernel onto the Assabet I rescued from a skip...

Quoted 9 lines

This file doesn't even build because
(I suspect) the above change:

arch/arm/kernel/probes.c: In function 'test_alu_write_pc_interworking':
arch/arm/kernel/probes.c:68:2: error: implicit declaration of function 'BUG_ON' [-Werror=implicit-function-declaration] make[2]: *** [arch/arm/kernel/probes.o] Error 1

This is because linux/kprobes.h includes linux/bug.h, which would provide the requirements for BUG_ON().

Signature · 1 line
Tixy
#10 lore raw

PATCH v6 7/14 ARM: Remove use of struct kprobe from generic probes code

Quoted 15 lines · Jon Medhurst (Tixy)
Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · David Long
arch/arm/kernel/probes.c +0 -0
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
  */
 
Quoted 5 lines

arch/arm/kernel/probes.c line 15

Quoted 3 lines
arch/arm/kernel/probes.c +0 -1
 #include <linux/kernel.h>
-#include <linux/kprobes.h>
 #include <asm/system_info.h>

How well has this code been tested?

Quoted 3 lines

From the error below I assume only when __LINUX_ARM_ARCH__ >= 7

I have v5 and v6 hardware

Actually, I don't have any v6 hardware, for some strange reason I thought a cortex A8 was v6.

Signature · 1 line
Tixy
author
#11 lore raw

Re: [PATCH v6 07/14] ARM: Remove use of struct kprobe from generic probes code

In reply to Russell King - ARM Linux
Quoted 15 lines · Russell King - ARM Linux

arch/arm/kernel/probes.c line 15

Quoted 10 lines · David Long
arch/arm/kernel/probes.c +0 -1
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
   */
 
  #include <linux/kernel.h>
-#include <linux/kprobes.h>
  #include <asm/system_info.h>

How well has this code been tested? This file doesn't even build because (I suspect) the above change:

Quoted 7 lines

arch/arm/kernel/probes.c: In function 'test_alu_write_pc_interworking':
arch/arm/kernel/probes.c:68:2: error: implicit declaration of function 'BUG_ON' [-Werror=implicit-function-declaration] make[2]: *** [arch/arm/kernel/probes.o] Error 1

This is because linux/kprobes.h includes linux/bug.h, which would provide the requirements for BUG_ON().

It was tested by building and running on Panda with all four permutations of uprobes and kprobes enabled/disabled. x86 was also test built and run to verify no regressions, and other testing was done inside Linaro for arm64 endianess correctness. Very recently daily build testing has been added and this config problem has shown up, and our test configs adjusted accordingly. I think the problem was masked on panda by CONFIG_PROFILING being set for that (and many other) platform(s). On x86 it looks like the problem is avoided by CONFIG_PERF_EVENTS always being set in arch/x86/Kconfig.

I was not aware of the use/requirement (or existence even) of randconfig for validation testing, nor did I know a config dependency issue like this one would be considered a showstopper problem.

-dl

#12 lore raw

Re: [PATCH v6 07/14] ARM: Remove use of struct kprobe from generic probes code

Quoted 34 lines · David Long
Quoted 15 lines · Russell King - ARM Linux

arch/arm/kernel/probes.c line 15

Quoted 10 lines · David Long
arch/arm/kernel/probes.c +0 -1
index 7cd1763..179deac 100644
@@ -12,11 +12,9 @@
   */
 
  #include <linux/kernel.h>
-#include <linux/kprobes.h>
  #include <asm/system_info.h>

How well has this code been tested? This file doesn't even build because (I suspect) the above change:

Quoted 7 lines

arch/arm/kernel/probes.c: In function 'test_alu_write_pc_interworking':
arch/arm/kernel/probes.c:68:2: error: implicit declaration of function 'BUG_ON' [-Werror=implicit-function-declaration] make[2]: *** [arch/arm/kernel/probes.o] Error 1

This is because linux/kprobes.h includes linux/bug.h, which would provide the requirements for BUG_ON().

It was tested by building and running on Panda with all four permutations of uprobes and kprobes enabled/disabled. x86 was also test built and run to verify no regressions, and other testing was done inside Linaro for arm64 endianess correctness. Very recently daily build testing has been added and this config problem has shown up, and our test configs adjusted accordingly. I think the problem was masked on panda by CONFIG_PROFILING being set for that (and many other) platform(s). On x86 it looks like the problem is avoided by CONFIG_PERF_EVENTS always being set in arch/x86/Kconfig.

Quoted 3 lines

I was not aware of the use/requirement (or existence even) of randconfig for validation testing, nor did I know a config dependency issue like this one would be considered a showstopper problem.

The point of randconfig is to find those combinations which you haven't tested. For example, you say above that you tested on a Panda board. However, there's dependencies in this code for ARMv5, ARMv6 and ARMv7 as well, which you haven't tested for by only targetting Panda.

For example, the failure above is caused if you try and build this code with support for ARMv6 enabled. This causes test_alu_write_pc_interworking() to be built, which finds the problem with BUG_ON().

What the overall requirement here is that we avoid new regressions - in this case, it's a missing include file indirectly included via linux/kprobes.h.

One of my biggest gripes is that people like reducing the include files in their sources to the barest minimum, relying on indirect includes to give them what their .c file requires. This is - as is demonstrated above - very fragile, and leads to these kinds of unexpected build failures. If people thought about it properly, they'd realise that this is no way to behave. Instead, a .c file should always include the headers that it has a direct requirement for. In this case, that's linux/bug.h. This problem is compounded by ARM having a multitude of configuration options which directly affect compiled code.

Again, this is not your fault, but the author of kprobes.c who made a rather poor decision in only including (originally) six headers:

+#include <linux/kernel.h>
+#include <linux/kprobes.h>
+#include <linux/module.h>
+#include <linux/stringify.h>
+#include <asm/traps.h>
+#include <asm/cacheflush.h>

despite requiring more.

However, this is not the reason I dropped your patch series - I dropped them because of the other problem I mailed about, caused by the Kconfig dependencies. That needs fixing first to avoid the problem your changes have uncovered - it's no good fixing it afterwards because it can end up breaking git bisect. The precise time where you don't want git bisect to break is during a merge window, and that's when this code will be going in.

Now that I look closer at this, the UPROBES Kconfig stuff is totally insane - this commit:

commit f3f096cfedf8113380c56fc855275cc75cd8cf55

Author: Srikar Dronamraju <[email protected]>
Date:   Wed Apr 11 16:00:43 2012 +0530

tracing: Provide trace events interface for uprobes

introduced this madness:

config UPROBES
bool "Transparent user-space probes (EXPERIMENTAL)" depends on UPROBE_EVENT && PERF_EVENTS default n
select PERCPU_RWSEM

config UPROBE_EVENT
bool "Enable uprobes-based dynamic events" depends on ARCH_SUPPORTS_UPROBES depends on MMU
select UPROBES
select PROBE_EVENTS
select TRACING

What this expresses is that UPROBES can't be enabled unless UPROBE_EVENT is enabled. If UPROBE_EVENT is enabled, then UPROBES is force-enabled irrespective of its dependencies. Hence, this forces UPROBES to *always* have the same value as UPROBE_EVENT, it can never be anything different.

I'm at a loss to understand why we have these two configuration options. The above commit just looks totally wrong from the Kconfig perspective.

Maybe Srikar Dronamraju can comment about what the original intention was here - but it looks like one or other should just be killed off.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
author
#13 lore raw

PATCH v6 8/14 ARM: Make the kprobes condition_check symbol names more generic

In reply to David Long

From: "David A. Long" <[email protected]>

In preparation for sharing the ARM kprobes instruction interpreting code with uprobes, make the symbols names less kprobes-specific.

---
 arch/arm/include/asm/probes.h    | 11 +++---
 arch/arm/kernel/kprobes-arm.c    | 16 ++++-----
 arch/arm/kernel/kprobes-common.c | 14 ++++----
 arch/arm/kernel/kprobes-thumb.c  | 76 ++++++++++++++++++++--------------------
 arch/arm/kernel/kprobes.h        |  8 ++---
 arch/arm/kernel/probes-arm.c     | 16 ++++-----
 arch/arm/kernel/probes-arm.h     | 10 +++---
 arch/arm/kernel/probes-thumb.c   | 10 +++---
 arch/arm/kernel/probes.c         | 22 ++++++------
 arch/arm/kernel/probes.h         | 12 +++----
 10 files changed, 98 insertions(+), 97 deletions(-)
arch/arm/include/asm/probes.h +6 -5
index 4d014c4..c4acf6c 100644
@@ -20,22 +20,23 @@
 #define _ASM_PROBES_H
 
 struct kprobe;
+typedef u32 probes_opcode_t;
 
 struct arch_specific_insn;
-typedef void (kprobe_insn_handler_t)(kprobe_opcode_t,
+typedef void (kprobe_insn_handler_t)(probes_opcode_t,
 				     struct arch_specific_insn *,
 				     struct pt_regs *);
-typedef unsigned long (kprobe_check_cc)(unsigned long);
-typedef void (kprobe_insn_singlestep_t)(kprobe_opcode_t,
+typedef unsigned long (probes_check_cc)(unsigned long);
+typedef void (kprobe_insn_singlestep_t)(probes_opcode_t,
 					struct arch_specific_insn *,
 					struct pt_regs *);
 typedef void (kprobe_insn_fn_t)(void);
 
 /* Architecture specific copy of original instruction. */
 struct arch_specific_insn {
-	kprobe_opcode_t			*insn;
+	probes_opcode_t			*insn;
 	kprobe_insn_handler_t		*insn_handler;
-	kprobe_check_cc			*insn_check_cc;
+	probes_check_cc			*insn_check_cc;
 	kprobe_insn_singlestep_t	*insn_singlestep;
 	kprobe_insn_fn_t		*insn_fn;
 };
arch/arm/kernel/kprobes-arm.c +8 -8
index d62bbdf..bbbdda5 100644
@@ -73,7 +73,7 @@
 #endif
 
 static void __kprobes
-emulate_ldrdstrd(kprobe_opcode_t insn,
+emulate_ldrdstrd(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
@@ -102,7 +102,7 @@ emulate_ldrdstrd(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_ldr(kprobe_opcode_t insn,
+emulate_ldr(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
@@ -132,7 +132,7 @@ emulate_ldr(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_str(kprobe_opcode_t insn,
+emulate_str(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	unsigned long rtpc = regs->ARM_pc - 4 + str_pc_offset;
@@ -159,7 +159,7 @@ emulate_str(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_rd12rn16rm0rs8_rwflags(kprobe_opcode_t insn,
+emulate_rd12rn16rm0rs8_rwflags(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
@@ -194,7 +194,7 @@ emulate_rd12rn16rm0rs8_rwflags(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_rd12rn16rm0_rwflags_nopc(kprobe_opcode_t insn,
+emulate_rd12rn16rm0_rwflags_nopc(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
@@ -221,7 +221,7 @@ emulate_rd12rn16rm0_rwflags_nopc(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_rd16rn12rm0rs8_rwflags_nopc(kprobe_opcode_t insn,
+emulate_rd16rn12rm0rs8_rwflags_nopc(probes_opcode_t insn,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
@@ -251,7 +251,7 @@ emulate_rd16rn12rm0rs8_rwflags_nopc(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_rd12rm0_noflags_nopc(kprobe_opcode_t insn,
+emulate_rd12rm0_noflags_nopc(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
@@ -271,7 +271,7 @@ emulate_rd12rm0_noflags_nopc(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(kprobe_opcode_t insn,
+emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(probes_opcode_t insn,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
arch/arm/kernel/kprobes-common.c +7 -7
index da65499..93b03c8 100644
@@ -18,7 +18,7 @@
 #include "kprobes.h"
 
 
-static void __kprobes simulate_ldm1stm1(kprobe_opcode_t insn,
+static void __kprobes simulate_ldm1stm1(probes_opcode_t insn,
 		struct arch_specific_insn *asi,
 		struct pt_regs *regs)
 {
@@ -60,7 +60,7 @@ static void __kprobes simulate_ldm1stm1(kprobe_opcode_t insn,
 	}
 }
 
-static void __kprobes simulate_stm1_pc(kprobe_opcode_t insn,
+static void __kprobes simulate_stm1_pc(probes_opcode_t insn,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
@@ -71,7 +71,7 @@ static void __kprobes simulate_stm1_pc(kprobe_opcode_t insn,
 	regs->ARM_pc = (long)addr + 4;
 }
 
-static void __kprobes simulate_ldm1_pc(kprobe_opcode_t insn,
+static void __kprobes simulate_ldm1_pc(probes_opcode_t insn,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
@@ -80,7 +80,7 @@ static void __kprobes simulate_ldm1_pc(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_generic_r0_12_noflags(kprobe_opcode_t insn,
+emulate_generic_r0_12_noflags(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	register void *rregs asm("r1") = regs;
@@ -108,7 +108,7 @@ emulate_generic_r0_12_noflags(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_generic_r2_14_noflags(kprobe_opcode_t insn,
+emulate_generic_r2_14_noflags(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	emulate_generic_r0_12_noflags(insn, asi,
@@ -116,7 +116,7 @@ emulate_generic_r2_14_noflags(kprobe_opcode_t insn,
 }
 
 static void __kprobes
-emulate_ldm_r3_15(kprobe_opcode_t insn,
+emulate_ldm_r3_15(probes_opcode_t insn,
 	struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	emulate_generic_r0_12_noflags(insn, asi,
@@ -125,7 +125,7 @@ emulate_ldm_r3_15(kprobe_opcode_t insn,
 }
 
 enum kprobe_insn __kprobes
-kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *h)
 {
 	kprobe_insn_handler_t *handler = 0;
arch/arm/kernel/kprobes-thumb.c +38 -38

293 lines not on this page · raw message

arch/arm/kernel/kprobes.h +4 -4
index 7798035..d0530b1 100644
@@ -36,22 +36,22 @@ enum kprobe_insn {
 	INSN_GOOD_NO_SLOT
 };
 
-typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t,
+typedef enum kprobe_insn (kprobe_decode_insn_t)(probes_opcode_t,
 						struct arch_specific_insn *,
 						const union decode_action *);
 
 #ifdef CONFIG_THUMB2_KERNEL
 
-enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t,
+enum kprobe_insn thumb16_kprobe_decode_insn(probes_opcode_t,
 					    struct arch_specific_insn *,
 					    const union decode_action *);
-enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t,
+enum kprobe_insn thumb32_kprobe_decode_insn(probes_opcode_t,
 					    struct arch_specific_insn *,
 					    const union decode_action *);
 
 #else /* !CONFIG_THUMB2_KERNEL */
 
-enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t,
+enum kprobe_insn arm_kprobe_decode_insn(probes_opcode_t,
 					struct arch_specific_insn *,
 					const union decode_action *);
 
arch/arm/kernel/probes-arm.c +8 -8
index 7cbe973..f0c3720 100644
@@ -55,7 +55,7 @@
  * read and write of flags.
  */
 
-void __kprobes simulate_bbl(kprobe_opcode_t insn,
+void __kprobes simulate_bbl(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	long iaddr = (long) regs->ARM_pc - 4;
@@ -67,7 +67,7 @@ void __kprobes simulate_bbl(kprobe_opcode_t insn,
 	regs->ARM_pc = iaddr + 8 + disp;
 }
 
-void __kprobes simulate_blx1(kprobe_opcode_t insn,
+void __kprobes simulate_blx1(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	long iaddr = (long) regs->ARM_pc - 4;
@@ -78,7 +78,7 @@ void __kprobes simulate_blx1(kprobe_opcode_t insn,
 	regs->ARM_cpsr |= PSR_T_BIT;
 }
 
-void __kprobes simulate_blx2bx(kprobe_opcode_t insn,
+void __kprobes simulate_blx2bx(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	int rm = insn & 0xf;
@@ -93,7 +93,7 @@ void __kprobes simulate_blx2bx(kprobe_opcode_t insn,
 		regs->ARM_cpsr |= PSR_T_BIT;
 }
 
-void __kprobes simulate_mrs(kprobe_opcode_t insn,
+void __kprobes simulate_mrs(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
@@ -101,7 +101,7 @@ void __kprobes simulate_mrs(kprobe_opcode_t insn,
 	regs->uregs[rd] = regs->ARM_cpsr & mask;
 }
 
-void __kprobes simulate_mov_ipsp(kprobe_opcode_t insn,
+void __kprobes simulate_mov_ipsp(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	regs->uregs[12] = regs->uregs[13];
@@ -702,7 +702,7 @@ const union decode_item kprobe_decode_arm_table[] = {
 EXPORT_SYMBOL_GPL(kprobe_decode_arm_table);
 #endif
 
-static void __kprobes arm_singlestep(kprobe_opcode_t insn,
+static void __kprobes arm_singlestep(probes_opcode_t insn,
 		struct arch_specific_insn *asi, struct pt_regs *regs)
 {
 	regs->ARM_pc += 4;
@@ -722,11 +722,11 @@ static void __kprobes arm_singlestep(kprobe_opcode_t insn,
  *   should also be very rare.
  */
 enum kprobe_insn __kprobes
-arm_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+arm_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		       const union decode_action *actions)
 {
 	asi->insn_singlestep = arm_singlestep;
-	asi->insn_check_cc = kprobe_condition_checks[insn>>28];
+	asi->insn_check_cc = probes_condition_checks[insn>>28];
 	return kprobe_decode_insn(insn, asi, kprobe_decode_arm_table, false,
 				  actions);
 }
arch/arm/kernel/probes-arm.h +5 -5
index d0ac8a4..9a9d379d 100644
@@ -53,15 +53,15 @@ enum probes_arm_action {
 	NUM_PROBES_ARM_ACTIONS
 };
 
-void __kprobes simulate_bbl(kprobe_opcode_t opcode,
+void __kprobes simulate_bbl(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
-void __kprobes simulate_blx1(kprobe_opcode_t opcode,
+void __kprobes simulate_blx1(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
-void __kprobes simulate_blx2bx(kprobe_opcode_t opcode,
+void __kprobes simulate_blx2bx(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
-void __kprobes simulate_mrs(kprobe_opcode_t opcode,
+void __kprobes simulate_mrs(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
-void __kprobes simulate_mov_ipsp(kprobe_opcode_t opcode,
+void __kprobes simulate_mov_ipsp(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
 
 #endif
arch/arm/kernel/probes-thumb.c +5 -5
index 85dc5af..f954e14 100644
@@ -838,11 +838,11 @@ EXPORT_SYMBOL_GPL(kprobe_decode_thumb16_table);
 static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
 {
 	if (unlikely(in_it_block(cpsr)))
-		return kprobe_condition_checks[current_cond(cpsr)](cpsr);
+		return probes_condition_checks[current_cond(cpsr)](cpsr);
 	return true;
 }
 
-static void __kprobes thumb16_singlestep(kprobe_opcode_t opcode,
+static void __kprobes thumb16_singlestep(probes_opcode_t opcode,
 		struct arch_specific_insn *asi,
 		struct pt_regs *regs)
 {
@@ -851,7 +851,7 @@ static void __kprobes thumb16_singlestep(kprobe_opcode_t opcode,
 	regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
 }
 
-static void __kprobes thumb32_singlestep(kprobe_opcode_t opcode,
+static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
 		struct arch_specific_insn *asi,
 		struct pt_regs *regs)
 {
@@ -861,7 +861,7 @@ static void __kprobes thumb32_singlestep(kprobe_opcode_t opcode,
 }
 
 enum kprobe_insn __kprobes
-thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+thumb16_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb16_singlestep;
@@ -871,7 +871,7 @@ thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
 }
 
 enum kprobe_insn __kprobes
-thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+thumb32_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb32_singlestep;
arch/arm/kernel/probes.c +11 -11
index 179deac..9836dc6 100644
@@ -163,7 +163,7 @@ static unsigned long __kprobes __check_al(unsigned long cpsr)
 	return true;
 }
 
-kprobe_check_cc * const kprobe_condition_checks[16] = {
+probes_check_cc * const probes_condition_checks[16] = {
 	&__check_eq, &__check_ne, &__check_cs, &__check_cc,
 	&__check_mi, &__check_pl, &__check_vs, &__check_vc,
 	&__check_hi, &__check_ls, &__check_ge, &__check_lt,
@@ -171,13 +171,13 @@ kprobe_check_cc * const kprobe_condition_checks[16] = {
 };
 
 
-void __kprobes kprobe_simulate_nop(kprobe_opcode_t opcode,
+void __kprobes kprobe_simulate_nop(probes_opcode_t opcode,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
 }
 
-void __kprobes kprobe_emulate_none(kprobe_opcode_t opcode,
+void __kprobes kprobe_emulate_none(probes_opcode_t opcode,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
@@ -191,8 +191,8 @@ void __kprobes kprobe_emulate_none(kprobe_opcode_t opcode,
  * unconditional as the condition code will already be checked before any
  * emulation handler is called.
  */
-static kprobe_opcode_t __kprobes
-prepare_emulated_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+static probes_opcode_t __kprobes
+prepare_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		      bool thumb)
 {
 #ifdef CONFIG_THUMB2_KERNEL
@@ -217,7 +217,7 @@ prepare_emulated_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
  * prepare_emulated_insn
  */
 static void  __kprobes
-set_emulated_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+set_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		  bool thumb)
 {
 #ifdef CONFIG_THUMB2_KERNEL
@@ -253,14 +253,14 @@ set_emulated_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
  * non-zero value, the corresponding nibble in pinsn is validated and modified
  * according to the type.
  */
-static bool __kprobes decode_regs(kprobe_opcode_t *pinsn, u32 regs)
+static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs)
 {
-	kprobe_opcode_t insn = *pinsn;
-	kprobe_opcode_t mask = 0xf; /* Start at least significant nibble */
+	probes_opcode_t insn = *pinsn;
+	probes_opcode_t mask = 0xf; /* Start at least significant nibble */
 
 	for (; regs != 0; regs >>= 4, mask <<= 4) {
 
-		kprobe_opcode_t new_bits = INSN_NEW_BITS;
+		probes_opcode_t new_bits = INSN_NEW_BITS;
 
 		switch (regs & 0xf) {
 
@@ -379,7 +379,7 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
  *
  */
 int __kprobes
-kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		   const union decode_item *table, bool thumb,
 		   const union decode_action *actions)
 {
arch/arm/kernel/probes.h +6 -6
index 4516616..afc6acd 100644
@@ -129,13 +129,13 @@ static inline void __kprobes alu_write_pc(long pcv, struct pt_regs *regs)
 }
 
 
-void __kprobes kprobe_simulate_nop(kprobe_opcode_t, struct arch_specific_insn *,
+void __kprobes kprobe_simulate_nop(probes_opcode_t, struct arch_specific_insn *,
 		struct pt_regs *regs);
-void __kprobes kprobe_emulate_none(kprobe_opcode_t, struct arch_specific_insn *,
+void __kprobes kprobe_emulate_none(probes_opcode_t, struct arch_specific_insn *,
 		struct pt_regs *regs);
 
 enum kprobe_insn __kprobes
-kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *h);
 
 /*
@@ -309,7 +309,7 @@ union decode_item {
 	int			action;
 };
 
-typedef enum kprobe_insn (probes_custom_decode_t)(kprobe_opcode_t,
+typedef enum kprobe_insn (probes_custom_decode_t)(probes_opcode_t,
 						  struct arch_specific_insn *,
 						  const struct decode_header *);
 
@@ -406,10 +406,10 @@ extern const union decode_item kprobe_decode_arm_table[];
 extern const union decode_action kprobes_arm_actions[];
 #endif
 
-extern kprobe_check_cc * const kprobe_condition_checks[16];
+extern probes_check_cc * const probes_condition_checks[16];
 
 
-int kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+int kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		       const union decode_item *table, bool thumb16,
 		       const union decode_action *actions);
 
Signature · 1 line
1.8.1.2
author
#14 lore raw

PATCH v6 9/14 ARM: Change more ARM kprobes symbol names to something more

In reply to David Long

From: "David A. Long" <[email protected]>

Change kprobe_emulate_none, kprobe_simulate_nop, and arm_kprobe_decode_init function names to something more appropriate for code being shared outside of the kprobes subsystem. Also, move the new arm_probes_decode_init declaration out of the kprobes.h include file and into the probes.h include file.

---
 arch/arm/kernel/kprobes-arm.c   | 12 ++++++------
 arch/arm/kernel/kprobes-thumb.c | 10 +++++-----
 arch/arm/kernel/kprobes.c       |  2 +-
 arch/arm/kernel/kprobes.h       |  2 --
 arch/arm/kernel/probes.c        |  6 +++---
 arch/arm/kernel/probes.h        |  6 ++++--
 6 files changed, 19 insertions(+), 19 deletions(-)
arch/arm/kernel/kprobes-arm.c +6 -6
index bbbdda5..52591e3 100644
@@ -302,10 +302,10 @@ emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(probes_opcode_t insn,
 }
 
 const union decode_action kprobes_arm_actions[NUM_PROBES_ARM_ACTIONS] = {
-	[PROBES_EMULATE_NONE] = {.handler = kprobe_emulate_none},
-	[PROBES_SIMULATE_NOP] = {.handler = kprobe_simulate_nop},
-	[PROBES_PRELOAD_IMM] = {.handler = kprobe_simulate_nop},
-	[PROBES_PRELOAD_REG] = {.handler = kprobe_simulate_nop},
+	[PROBES_EMULATE_NONE] = {.handler = probes_emulate_none},
+	[PROBES_SIMULATE_NOP] = {.handler = probes_simulate_nop},
+	[PROBES_PRELOAD_IMM] = {.handler = probes_simulate_nop},
+	[PROBES_PRELOAD_REG] = {.handler = probes_simulate_nop},
 	[PROBES_BRANCH_IMM] = {.handler = simulate_blx1},
 	[PROBES_MRS] = {.handler = simulate_mrs},
 	[PROBES_BRANCH_REG] = {.handler = simulate_blx2bx},
@@ -326,8 +326,8 @@ const union decode_action kprobes_arm_actions[NUM_PROBES_ARM_ACTIONS] = {
 	[PROBES_DATA_PROCESSING_IMM] = {
 		.handler = emulate_rd12rn16rm0rs8_rwflags},
 	[PROBES_MOV_HALFWORD] = {.handler = emulate_rd12rm0_noflags_nopc},
-	[PROBES_SEV] = {.handler = kprobe_emulate_none},
-	[PROBES_WFE] = {.handler = kprobe_simulate_nop},
+	[PROBES_SEV] = {.handler = probes_emulate_none},
+	[PROBES_WFE] = {.handler = probes_simulate_nop},
 	[PROBES_SATURATE] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
 	[PROBES_REV] = {.handler = emulate_rd12rm0_noflags_nopc},
 	[PROBES_MMI] = {.handler = emulate_rd12rn16rm0_rwflags_nopc},
arch/arm/kernel/kprobes-thumb.c +5 -5
index 3e26fde..3cbaf14 100644
@@ -612,8 +612,8 @@ const union decode_action kprobes_t16_actions[NUM_PROBES_T16_ACTIONS] = {
 	[PROBES_T16_SIGN_EXTEND] = {.handler = t16_emulate_loregs_rwflags},
 	[PROBES_T16_PUSH] = {.decoder = t16_decode_push},
 	[PROBES_T16_POP] = {.decoder = t16_decode_pop},
-	[PROBES_T16_SEV] = {.handler = kprobe_emulate_none},
-	[PROBES_T16_WFE] = {.handler = kprobe_simulate_nop},
+	[PROBES_T16_SEV] = {.handler = probes_emulate_none},
+	[PROBES_T16_WFE] = {.handler = probes_simulate_nop},
 	[PROBES_T16_IT] = {.decoder = t16_decode_it},
 	[PROBES_T16_CMP] = {.handler = t16_emulate_loregs_rwflags},
 	[PROBES_T16_ADDSUB] = {.handler = t16_emulate_loregs_noitrwflags},
@@ -643,12 +643,12 @@ const union decode_action kprobes_t32_actions[NUM_PROBES_T32_ACTIONS] = {
 	[PROBES_T32_MOVW] = {.handler = t32_emulate_rd8rn16_noflags},
 	[PROBES_T32_SAT] = {.handler = t32_emulate_rd8rn16rm0_rwflags},
 	[PROBES_T32_BITFIELD] = {.handler = t32_emulate_rd8rn16_noflags},
-	[PROBES_T32_SEV] = {.handler = kprobe_emulate_none},
-	[PROBES_T32_WFE] = {.handler = kprobe_simulate_nop},
+	[PROBES_T32_SEV] = {.handler = probes_emulate_none},
+	[PROBES_T32_WFE] = {.handler = probes_simulate_nop},
 	[PROBES_T32_MRS] = {.handler = t32_simulate_mrs},
 	[PROBES_T32_BRANCH_COND] = {.decoder = t32_decode_cond_branch},
 	[PROBES_T32_BRANCH] = {.handler = t32_simulate_branch},
-	[PROBES_T32_PLDI] = {.handler = kprobe_simulate_nop},
+	[PROBES_T32_PLDI] = {.handler = probes_simulate_nop},
 	[PROBES_T32_LDR_LIT] = {.handler = t32_simulate_ldr_literal},
 	[PROBES_T32_LDRSTR] = {.handler = t32_emulate_ldrstr},
 	[PROBES_T32_SIGN_EXTEND] = {.handler = t32_emulate_rd8rn16rm0_rwflags},
arch/arm/kernel/kprobes.c +1 -1
index 0206ee9..3e3a3e0 100644
@@ -612,7 +612,7 @@ static struct undef_hook kprobes_arm_break_hook = {
 
 int __init arch_init_kprobes()
 {
-	arm_kprobe_decode_init();
+	arm_probes_decode_init();
 #ifdef CONFIG_THUMB2_KERNEL
 	register_undef_hook(&kprobes_thumb16_break_hook);
 	register_undef_hook(&kprobes_thumb32_break_hook);
arch/arm/kernel/kprobes.h +0 -2
index d0530b1..e2ae4ed 100644
@@ -57,8 +57,6 @@ enum kprobe_insn arm_kprobe_decode_insn(probes_opcode_t,
 
 #endif
 
-void __init arm_kprobe_decode_init(void);
-
 #include "probes.h"
 
 #endif /* _ARM_KERNEL_KPROBES_H */
arch/arm/kernel/probes.c +3 -3
index 9836dc6..3a8da34 100644
@@ -72,7 +72,7 @@ void __init test_alu_write_pc_interworking(void)
 #endif /* !test_alu_write_pc_interworking */
 
 
-void __init arm_kprobe_decode_init(void)
+void __init arm_probes_decode_init(void)
 {
 	find_str_pc_offset();
 	test_load_write_pc_interworking();
@@ -171,13 +171,13 @@ probes_check_cc * const probes_condition_checks[16] = {
 };
 
 
-void __kprobes kprobe_simulate_nop(probes_opcode_t opcode,
+void __kprobes probes_simulate_nop(probes_opcode_t opcode,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
 }
 
-void __kprobes kprobe_emulate_none(probes_opcode_t opcode,
+void __kprobes probes_emulate_none(probes_opcode_t opcode,
 	struct arch_specific_insn *asi,
 	struct pt_regs *regs)
 {
arch/arm/kernel/probes.h +4 -2
index afc6acd..df05a58 100644
@@ -22,6 +22,8 @@
 #include <linux/kprobes.h>
 #include "kprobes.h"
 
+void __init arm_probes_decode_init(void);
+
 #if __LINUX_ARM_ARCH__ >= 7
 
 /* str_pc_offset is architecturally defined from ARMv7 onwards */
@@ -129,9 +131,9 @@ static inline void __kprobes alu_write_pc(long pcv, struct pt_regs *regs)
 }
 
 
-void __kprobes kprobe_simulate_nop(probes_opcode_t, struct arch_specific_insn *,
+void __kprobes probes_simulate_nop(probes_opcode_t, struct arch_specific_insn *,
 		struct pt_regs *regs);
-void __kprobes kprobe_emulate_none(probes_opcode_t, struct arch_specific_insn *,
+void __kprobes probes_emulate_none(probes_opcode_t, struct arch_specific_insn *,
 		struct pt_regs *regs);
 
 enum kprobe_insn __kprobes
Signature · 1 line
1.8.1.2
author
#15 lore raw

PATCH v6 10/14 ARM: Rename the shared kprobes/uprobe return value enum

In reply to David Long

From: "David A. Long" <[email protected]>

Change the name of kprobes_insn to probes_insn so it can be shared between kprobes and uprobes without confusion.

---
 arch/arm/kernel/kprobes-common.c |  2 +-
 arch/arm/kernel/kprobes-thumb.c  | 16 ++++++++--------
 arch/arm/kernel/kprobes.h        | 14 ++++----------
 arch/arm/kernel/probes-arm.c     |  2 +-
 arch/arm/kernel/probes-thumb.c   |  4 ++--
 arch/arm/kernel/probes.h         |  9 +++++++--
 6 files changed, 23 insertions(+), 24 deletions(-)
arch/arm/kernel/kprobes-common.c +1 -1
index 93b03c8..b921b60 100644
@@ -124,7 +124,7 @@ emulate_ldm_r3_15(probes_opcode_t insn,
 	load_write_pc(regs->ARM_pc, regs);
 }
 
-enum kprobe_insn __kprobes
+enum probes_insn __kprobes
 kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *h)
 {
arch/arm/kernel/kprobes-thumb.c +8 -8
index 3cbaf14..2a67903 100644
@@ -65,7 +65,7 @@ t32_simulate_cond_branch(probes_opcode_t insn,
 	regs->ARM_pc = pc + (offset * 2);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t32_decode_cond_branch(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
@@ -141,11 +141,11 @@ t32_simulate_ldr_literal(probes_opcode_t insn,
 	regs->uregs[rt] = rtv;
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t32_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
-	enum kprobe_insn ret = kprobe_decode_ldmstm(insn, asi, d);
+	enum probes_insn ret = kprobe_decode_ldmstm(insn, asi, d);
 
 	/* Fixup modified instruction to have halfwords in correct order...*/
 	insn = asi->insn[0];
@@ -401,7 +401,7 @@ t16_singlestep_it(probes_opcode_t insn,
 	t16_simulate_it(insn, asi, regs);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t16_decode_it(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
@@ -419,7 +419,7 @@ t16_simulate_cond_branch(probes_opcode_t insn,
 	regs->ARM_pc = pc + (offset * 2);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t16_decode_cond_branch(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
@@ -509,7 +509,7 @@ t16_emulate_hiregs(probes_opcode_t insn,
 	regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t16_decode_hiregs(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
@@ -537,7 +537,7 @@ t16_emulate_push(probes_opcode_t insn,
 		);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t16_decode_push(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
@@ -590,7 +590,7 @@ t16_emulate_pop_pc(probes_opcode_t insn,
 	bx_write_pc(pc, regs);
 }
 
-static enum kprobe_insn __kprobes
+static enum probes_insn __kprobes
 t16_decode_pop(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *d)
 {
arch/arm/kernel/kprobes.h +4 -10
index e2ae4ed..3684fc9 100644
@@ -30,28 +30,22 @@
 struct decode_header;
 union decode_action;
 
-enum kprobe_insn {
-	INSN_REJECTED,
-	INSN_GOOD,
-	INSN_GOOD_NO_SLOT
-};
-
-typedef enum kprobe_insn (kprobe_decode_insn_t)(probes_opcode_t,
+typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
 						struct arch_specific_insn *,
 						const union decode_action *);
 
 #ifdef CONFIG_THUMB2_KERNEL
 
-enum kprobe_insn thumb16_kprobe_decode_insn(probes_opcode_t,
+enum probes_insn thumb16_kprobe_decode_insn(probes_opcode_t,
 					    struct arch_specific_insn *,
 					    const union decode_action *);
-enum kprobe_insn thumb32_kprobe_decode_insn(probes_opcode_t,
+enum probes_insn thumb32_kprobe_decode_insn(probes_opcode_t,
 					    struct arch_specific_insn *,
 					    const union decode_action *);
 
 #else /* !CONFIG_THUMB2_KERNEL */
 
-enum kprobe_insn arm_kprobe_decode_insn(probes_opcode_t,
+enum probes_insn arm_kprobe_decode_insn(probes_opcode_t,
 					struct arch_specific_insn *,
 					const union decode_action *);
 
arch/arm/kernel/probes-arm.c +1 -1
index f0c3720..d377cc4 100644
@@ -721,7 +721,7 @@ static void __kprobes arm_singlestep(probes_opcode_t insn,
  *   if the work was put into it, but low return considering they
  *   should also be very rare.
  */
-enum kprobe_insn __kprobes
+enum probes_insn __kprobes
 arm_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		       const union decode_action *actions)
 {
arch/arm/kernel/probes-thumb.c +2 -2
index f954e14..9b04aeb 100644
@@ -860,7 +860,7 @@ static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
 	regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
 }
 
-enum kprobe_insn __kprobes
+enum probes_insn __kprobes
 thumb16_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
@@ -870,7 +870,7 @@ thumb16_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 				  actions);
 }
 
-enum kprobe_insn __kprobes
+enum probes_insn __kprobes
 thumb32_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
arch/arm/kernel/probes.h +7 -2
index df05a58..1d08fc3 100644
@@ -136,7 +136,7 @@ void __kprobes probes_simulate_nop(probes_opcode_t, struct arch_specific_insn *,
 void __kprobes probes_emulate_none(probes_opcode_t, struct arch_specific_insn *,
 		struct pt_regs *regs);
 
-enum kprobe_insn __kprobes
+enum probes_insn __kprobes
 kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *h);
 
@@ -311,7 +311,7 @@ union decode_item {
 	int			action;
 };
 
-typedef enum kprobe_insn (probes_custom_decode_t)(probes_opcode_t,
+typedef enum probes_insn (probes_custom_decode_t)(probes_opcode_t,
 						  struct arch_specific_insn *,
 						  const struct decode_header *);
 
@@ -389,6 +389,11 @@ struct decode_or {
 #define DECODE_OR(_mask, _value)				\
 	DECODE_HEADER(DECODE_TYPE_OR, _mask, _value, 0)
 
+enum probes_insn {
+	INSN_REJECTED,
+	INSN_GOOD,
+	INSN_GOOD_NO_SLOT
+};
 
 struct decode_reject {
 	struct decode_header	header;
Signature · 1 line
1.8.1.2
author
#16 lore raw

PATCH v6 11/14 ARM: Change the remaining shared kprobes/uprobes symbols to something generic

In reply to David Long

From: "David A. Long" <[email protected]>

Any more ARM kprobes/uprobes symbols which have "kprobe" in the name must be changed to the more generic "probes" or other non-kprobes specific symbol.

---
 arch/arm/include/asm/probes.h    | 13 ++++++-------
 arch/arm/kernel/kprobes-common.c |  2 +-
 arch/arm/kernel/kprobes-test.c   |  8 +++++---
 arch/arm/kernel/kprobes.c        | 10 ++++++----
 arch/arm/kernel/kprobes.h        | 21 ++++++++------------
 arch/arm/kernel/probes-arm.c     |  8 ++++----
 arch/arm/kernel/probes-arm.h     |  6 ++++++
 arch/arm/kernel/probes-thumb.c   | 18 ++++++++---------
 arch/arm/kernel/probes-thumb.h   | 10 ++++++++++
 arch/arm/kernel/probes.c         |  4 ++--
 arch/arm/kernel/probes.h         | 42 ++++++++++++----------------------------
 11 files changed, 69 insertions(+), 73 deletions(-)
arch/arm/include/asm/probes.h +6 -7
index c4acf6c..c37252c 100644
@@ -19,26 +19,25 @@
 #ifndef _ASM_PROBES_H
 #define _ASM_PROBES_H
 
-struct kprobe;
 typedef u32 probes_opcode_t;
 
 struct arch_specific_insn;
-typedef void (kprobe_insn_handler_t)(probes_opcode_t,
+typedef void (probes_insn_handler_t)(probes_opcode_t,
 				     struct arch_specific_insn *,
 				     struct pt_regs *);
 typedef unsigned long (probes_check_cc)(unsigned long);
-typedef void (kprobe_insn_singlestep_t)(probes_opcode_t,
+typedef void (probes_insn_singlestep_t)(probes_opcode_t,
 					struct arch_specific_insn *,
 					struct pt_regs *);
-typedef void (kprobe_insn_fn_t)(void);
+typedef void (probes_insn_fn_t)(void);
 
 /* Architecture specific copy of original instruction. */
 struct arch_specific_insn {
 	probes_opcode_t			*insn;
-	kprobe_insn_handler_t		*insn_handler;
+	probes_insn_handler_t		*insn_handler;
 	probes_check_cc			*insn_check_cc;
-	kprobe_insn_singlestep_t	*insn_singlestep;
-	kprobe_insn_fn_t		*insn_fn;
+	probes_insn_singlestep_t	*insn_singlestep;
+	probes_insn_fn_t		*insn_fn;
 };
 
 #endif
arch/arm/kernel/kprobes-common.c +1 -1
index b921b60..adc6d70 100644
@@ -128,7 +128,7 @@ enum probes_insn __kprobes
 kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
 		const struct decode_header *h)
 {
-	kprobe_insn_handler_t *handler = 0;
+	probes_insn_handler_t *handler = 0;
 	unsigned reglist = insn & 0xffff;
 	int is_ldm = insn & 0x100000;
 	int rn = (insn >> 16) & 0xf;
arch/arm/kernel/kprobes-test.c +5 -3
index 65230b2..a1f155c 100644
@@ -205,6 +205,8 @@
 #include <asm/opcodes.h>
 
 #include "kprobes.h"
+#include "probes-arm.h"
+#include "probes-thumb.h"
 #include "kprobes-test.h"
 
 
@@ -1616,7 +1618,7 @@ static int __init run_all_tests(void)
 		goto out;
 
 	pr_info("ARM instruction simulation\n");
-	ret = run_test_cases(kprobe_arm_test_cases, kprobe_decode_arm_table);
+	ret = run_test_cases(kprobe_arm_test_cases, probes_decode_arm_table);
 	if (ret)
 		goto out;
 
@@ -1639,13 +1641,13 @@ static int __init run_all_tests(void)
 
 	pr_info("16-bit Thumb instruction simulation\n");
 	ret = run_test_cases(kprobe_thumb16_test_cases,
-				kprobe_decode_thumb16_table);
+				probes_decode_thumb16_table);
 	if (ret)
 		goto out;
 
 	pr_info("32-bit Thumb instruction simulation\n");
 	ret = run_test_cases(kprobe_thumb32_test_cases,
-				kprobe_decode_thumb32_table);
+				probes_decode_thumb32_table);
 	if (ret)
 		goto out;
 #endif
arch/arm/kernel/kprobes.c +6 -4
index 3e3a3e0..db040ad 100644
@@ -29,6 +29,8 @@
 #include <asm/cacheflush.h>
 
 #include "kprobes.h"
+#include "probes-arm.h"
+#include "probes-thumb.h"
 #include "patch.h"
 
 #define MIN_STACK_SIZE(addr) 				\
@@ -67,10 +69,10 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 	if (is_wide_instruction(insn)) {
 		insn <<= 16;
 		insn |= ((u16 *)addr)[1];
-		decode_insn = thumb32_kprobe_decode_insn;
+		decode_insn = thumb32_probes_decode_insn;
 		actions = kprobes_t32_actions;
 	} else {
-		decode_insn = thumb16_kprobe_decode_insn;
+		decode_insn = thumb16_probes_decode_insn;
 		actions = kprobes_t16_actions;
 	}
 #else /* !CONFIG_THUMB2_KERNEL */
@@ -78,7 +80,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 	if (addr & 0x3)
 		return -EINVAL;
 	insn = *p->addr;
-	decode_insn = arm_kprobe_decode_insn;
+	decode_insn = arm_probes_decode_insn;
 	actions = kprobes_arm_actions;
 #endif
 
@@ -97,7 +99,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 			p->ainsn.insn[is] = tmp_insn[is];
 		flush_insns(p->ainsn.insn,
 				sizeof(p->ainsn.insn[0]) * MAX_INSN_SIZE);
-		p->ainsn.insn_fn = (kprobe_insn_fn_t *)
+		p->ainsn.insn_fn = (probes_insn_fn_t *)
 					((uintptr_t)p->ainsn.insn | thumb);
 		break;
 
arch/arm/kernel/kprobes.h +8 -13
index 3684fc9..eee8089 100644
@@ -19,6 +19,8 @@
 #ifndef _ARM_KERNEL_KPROBES_H
 #define _ARM_KERNEL_KPROBES_H
 
+#include "probes.h"
+
 /*
  * These undefined instructions must be unique and
  * reserved solely for kprobes' use.
@@ -27,8 +29,9 @@
 #define KPROBE_THUMB16_BREAKPOINT_INSTRUCTION	0xde18
 #define KPROBE_THUMB32_BREAKPOINT_INSTRUCTION	0xf7f0a018
 
-struct decode_header;
-union decode_action;
+enum probes_insn __kprobes
+kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+		const struct decode_header *h);
 
 typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
 						struct arch_specific_insn *,
@@ -36,21 +39,13 @@ typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
 
 #ifdef CONFIG_THUMB2_KERNEL
 
-enum probes_insn thumb16_kprobe_decode_insn(probes_opcode_t,
-					    struct arch_specific_insn *,
-					    const union decode_action *);
-enum probes_insn thumb32_kprobe_decode_insn(probes_opcode_t,
-					    struct arch_specific_insn *,
-					    const union decode_action *);
+extern const union decode_action kprobes_t32_actions[];
+extern const union decode_action kprobes_t16_actions[];
 
 #else /* !CONFIG_THUMB2_KERNEL */
 
-enum probes_insn arm_kprobe_decode_insn(probes_opcode_t,
-					struct arch_specific_insn *,
-					const union decode_action *);
+extern const union decode_action kprobes_arm_actions[];
 
 #endif
 
-#include "probes.h"
-
 #endif /* _ARM_KERNEL_KPROBES_H */
arch/arm/kernel/probes-arm.c +4 -4
index d377cc4..0faa4b2 100644
@@ -608,7 +608,7 @@ static const union decode_item arm_cccc_100x_table[] = {
 	DECODE_END
 };
 
-const union decode_item kprobe_decode_arm_table[] = {
+const union decode_item probes_decode_arm_table[] = {
 	/*
 	 * Unconditional instructions
 	 *			1111 xxxx xxxx xxxx xxxx xxxx xxxx xxxx
@@ -699,7 +699,7 @@ const union decode_item kprobe_decode_arm_table[] = {
 	DECODE_END
 };
 #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
-EXPORT_SYMBOL_GPL(kprobe_decode_arm_table);
+EXPORT_SYMBOL_GPL(probes_decode_arm_table);
 #endif
 
 static void __kprobes arm_singlestep(probes_opcode_t insn,
@@ -722,11 +722,11 @@ static void __kprobes arm_singlestep(probes_opcode_t insn,
  *   should also be very rare.
  */
 enum probes_insn __kprobes
-arm_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+arm_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		       const union decode_action *actions)
 {
 	asi->insn_singlestep = arm_singlestep;
 	asi->insn_check_cc = probes_condition_checks[insn>>28];
-	return kprobe_decode_insn(insn, asi, kprobe_decode_arm_table, false,
+	return probes_decode_insn(insn, asi, probes_decode_arm_table, false,
 				  actions);
 }
arch/arm/kernel/probes-arm.h +6 -0
index 9a9d379d..7a5cce4 100644
@@ -64,4 +64,10 @@ void __kprobes simulate_mrs(probes_opcode_t opcode,
 void __kprobes simulate_mov_ipsp(probes_opcode_t opcode,
 	struct arch_specific_insn *asi, struct pt_regs *regs);
 
+extern const union decode_item probes_decode_arm_table[];
+
+enum probes_insn arm_probes_decode_insn(probes_opcode_t,
+		struct arch_specific_insn *,
+		const union decode_action *actions);
+
 #endif
arch/arm/kernel/probes-thumb.c +9 -9
index 9b04aeb..69d4de5 100644
@@ -1,5 +1,5 @@
 /*
- * arch/arm/kernel/kprobes-thumb.c
+ * arch/arm/kernel/probes-thumb.c
  *
  * Copyright (C) 2011 Jon Medhurst <[email protected]>.
  *
@@ -551,7 +551,7 @@ static const union decode_item t32_table_1111_1011_1[] = {
 	DECODE_END
 };
 
-const union decode_item kprobe_decode_thumb32_table[] = {
+const union decode_item probes_decode_thumb32_table[] = {
 
 	/*
 	 * Load/store multiple instructions
@@ -640,7 +640,7 @@ const union decode_item kprobe_decode_thumb32_table[] = {
 	DECODE_END
 };
 #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
-EXPORT_SYMBOL_GPL(kprobe_decode_thumb32_table);
+EXPORT_SYMBOL_GPL(probes_decode_thumb32_table);
 #endif
 
 static const union decode_item t16_table_1011[] = {
@@ -695,7 +695,7 @@ static const union decode_item t16_table_1011[] = {
 	DECODE_END
 };
 
-const union decode_item kprobe_decode_thumb16_table[] = {
+const union decode_item probes_decode_thumb16_table[] = {
 
 	/*
 	 * Shift (immediate), add, subtract, move, and compare
@@ -832,7 +832,7 @@ const union decode_item kprobe_decode_thumb16_table[] = {
 	DECODE_END
 };
 #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
-EXPORT_SYMBOL_GPL(kprobe_decode_thumb16_table);
+EXPORT_SYMBOL_GPL(probes_decode_thumb16_table);
 #endif
 
 static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
@@ -861,21 +861,21 @@ static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
 }
 
 enum probes_insn __kprobes
-thumb16_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb16_singlestep;
 	asi->insn_check_cc = thumb_check_cc;
-	return kprobe_decode_insn(insn, asi, kprobe_decode_thumb16_table, true,
+	return probes_decode_insn(insn, asi, probes_decode_thumb16_table, true,
 				  actions);
 }
 
 enum probes_insn __kprobes
-thumb32_kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 			   const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb32_singlestep;
 	asi->insn_check_cc = thumb_check_cc;
-	return kprobe_decode_insn(insn, asi, kprobe_decode_thumb32_table, true,
+	return probes_decode_insn(insn, asi, probes_decode_thumb32_table, true,
 				  actions);
 }
arch/arm/kernel/probes-thumb.h +10 -0
index 4589072..b26411e 100644
@@ -84,4 +84,14 @@ enum probes_t16_action {
 	NUM_PROBES_T16_ACTIONS
 };
 
+extern const union decode_item probes_decode_thumb32_table[];
+extern const union decode_item probes_decode_thumb16_table[];
+
+enum probes_insn __kprobes
+thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+		const union decode_action *actions);
+enum probes_insn __kprobes
+thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+		const union decode_action *actions);
+
 #endif
arch/arm/kernel/probes.c +2 -2
index 3a8da34..865d4b7 100644
@@ -336,7 +336,7 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
 };
 
 /*
- * kprobe_decode_insn operates on data tables in order to decode an ARM
+ * probes_decode_insn operates on data tables in order to decode an ARM
  * architecture instruction onto which a kprobe has been placed.
  *
  * These instruction decoding tables are a concatenation of entries each
@@ -379,7 +379,7 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
  *
  */
 int __kprobes
-kprobe_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		   const union decode_item *table, bool thumb,
 		   const union decode_action *actions)
 {
arch/arm/kernel/probes.h +12 -30

86 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#17 lore raw

PATCH v6 12/14 ARM: Add an emulate flag to the kprobes/uprobes instruction decode functions

In reply to David Long

From: "David A. Long" <[email protected]>

Add an emulate flag into the instruction interpreter, primarily for uprobes support.

---
 arch/arm/kernel/kprobes.c      |  2 +-
 arch/arm/kernel/kprobes.h      |  1 +
 arch/arm/kernel/probes-arm.c   |  4 ++--
 arch/arm/kernel/probes-arm.h   |  2 +-
 arch/arm/kernel/probes-thumb.c |  8 ++++----
 arch/arm/kernel/probes-thumb.h |  4 ++--
 arch/arm/kernel/probes.c       | 18 +++++++++++++-----
 arch/arm/kernel/probes.h       |  2 +-
 8 files changed, 25 insertions(+), 16 deletions(-)
arch/arm/kernel/kprobes.c +1 -1
index db040ad..9421c0d 100644
@@ -87,7 +87,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
 	p->opcode = insn;
 	p->ainsn.insn = tmp_insn;
 
-	switch ((*decode_insn)(insn, &p->ainsn, actions)) {
+	switch ((*decode_insn)(insn, &p->ainsn, true, actions)) {
 	case INSN_REJECTED:	/* not supported */
 		return -EINVAL;
 
arch/arm/kernel/kprobes.h +1 -0
index eee8089..d0a24b7 100644
@@ -35,6 +35,7 @@ kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
 
 typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
 						struct arch_specific_insn *,
+						bool,
 						const union decode_action *);
 
 #ifdef CONFIG_THUMB2_KERNEL
arch/arm/kernel/probes-arm.c +2 -2
index 0faa4b2..a4f6914 100644
@@ -723,10 +723,10 @@ static void __kprobes arm_singlestep(probes_opcode_t insn,
  */
 enum probes_insn __kprobes
 arm_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-		       const union decode_action *actions)
+		       bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = arm_singlestep;
 	asi->insn_check_cc = probes_condition_checks[insn>>28];
 	return probes_decode_insn(insn, asi, probes_decode_arm_table, false,
-				  actions);
+				  emulate, actions);
 }
arch/arm/kernel/probes-arm.h +1 -1
index 7a5cce4..ea614dc 100644
@@ -67,7 +67,7 @@ void __kprobes simulate_mov_ipsp(probes_opcode_t opcode,
 extern const union decode_item probes_decode_arm_table[];
 
 enum probes_insn arm_probes_decode_insn(probes_opcode_t,
-		struct arch_specific_insn *,
+		struct arch_specific_insn *, bool emulate,
 		const union decode_action *actions);
 
 #endif
arch/arm/kernel/probes-thumb.c +4 -4
index 69d4de5..1a3ddf8 100644
@@ -862,20 +862,20 @@ static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
 
 enum probes_insn __kprobes
 thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-			   const union decode_action *actions)
+			   bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb16_singlestep;
 	asi->insn_check_cc = thumb_check_cc;
 	return probes_decode_insn(insn, asi, probes_decode_thumb16_table, true,
-				  actions);
+				  emulate, actions);
 }
 
 enum probes_insn __kprobes
 thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-			   const union decode_action *actions)
+			   bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb32_singlestep;
 	asi->insn_check_cc = thumb_check_cc;
 	return probes_decode_insn(insn, asi, probes_decode_thumb32_table, true,
-				  actions);
+				  emulate, actions);
 }
arch/arm/kernel/probes-thumb.h +2 -2
index b26411e..dd95866 100644
@@ -89,9 +89,9 @@ extern const union decode_item probes_decode_thumb16_table[];
 
 enum probes_insn __kprobes
 thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-		const union decode_action *actions);
+		bool emulate, const union decode_action *actions);
 enum probes_insn __kprobes
 thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-		const union decode_action *actions);
+		bool emulate, const union decode_action *actions);
 
 #endif
arch/arm/kernel/probes.c +13 -5
index 865d4b7..8a4088f 100644
@@ -253,7 +253,7 @@ set_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
  * non-zero value, the corresponding nibble in pinsn is validated and modified
  * according to the type.
  */
-static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs)
+static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs, bool modify)
 {
 	probes_opcode_t insn = *pinsn;
 	probes_opcode_t mask = 0xf; /* Start at least significant nibble */
@@ -319,7 +319,9 @@ static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs)
 		insn |= new_bits & mask;
 	}
 
-	*pinsn = insn;
+	if (modify)
+		*pinsn = insn;
+
 	return true;
 
 reject:
@@ -381,13 +383,14 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
 int __kprobes
 probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		   const union decode_item *table, bool thumb,
-		   const union decode_action *actions)
+		   bool emulate, const union decode_action *actions)
 {
 	const struct decode_header *h = (struct decode_header *)table;
 	const struct decode_header *next;
 	bool matched = false;
 
-	insn = prepare_emulated_insn(insn, asi, thumb);
+	if (emulate)
+		insn = prepare_emulated_insn(insn, asi, thumb);
 
 	for (;; h = next) {
 		enum decode_type type = h->type_regs.bits & DECODE_TYPE_MASK;
@@ -402,7 +405,7 @@ probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 		if (!matched && (insn & h->mask.bits) != h->value.bits)
 			continue;
 
-		if (!decode_regs(&insn, regs))
+		if (!decode_regs(&insn, regs, emulate))
 			return INSN_REJECTED;
 
 		switch (type) {
@@ -426,6 +429,11 @@ probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 
 		case DECODE_TYPE_EMULATE: {
 			struct decode_emulate *d = (struct decode_emulate *)h;
+
+			if (!emulate)
+				return actions[d->handler.action].decoder(insn,
+					asi, h);
+
 			asi->insn_handler = actions[d->handler.action].handler;
 			set_emulated_insn(insn, asi, thumb);
 			return INSN_GOOD;
arch/arm/kernel/probes.h +1 -1
index e296ff1..321d15f 100644
@@ -399,7 +399,7 @@ probes_insn_handler_t probes_emulate_none;
 
 int __kprobes
 probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
-		const union decode_item *table, bool thumb,
+		const union decode_item *table, bool thumb, bool emulate,
 		const union decode_action *actions);
 
 #endif
Signature · 1 line
1.8.1.2
author
#18 lore raw

PATCH v6 13/14 ARM: Make arch_specific_insn a define for new arch_probes_insn structure

In reply to David Long

From: "David A. Long" <[email protected]>

Because the common underlying code for ARM kprobes and uprobes needs to share a common architecrure-specific context structure, and because the generic kprobes include file insists on defining this to a dummy structure when kprobes is not configured, a new common structure is required which can exist when uprobes is configured without kprobes. In this case kprobes will define a dummy structure, but without the define aliasing the two structure tags it will not affect uprobes and the shared probes code.

---
 arch/arm/include/asm/kprobes.h   |  2 ++
 arch/arm/include/asm/probes.h    |  8 ++---
 arch/arm/kernel/kprobes-arm.c    | 16 ++++-----
 arch/arm/kernel/kprobes-common.c | 14 ++++----
 arch/arm/kernel/kprobes-thumb.c  | 70 ++++++++++++++++++++--------------------
 arch/arm/kernel/kprobes.h        |  4 +--
 arch/arm/kernel/probes-arm.c     | 14 ++++----
 arch/arm/kernel/probes-arm.h     | 12 +++----
 arch/arm/kernel/probes-thumb.c   |  8 ++---
 arch/arm/kernel/probes-thumb.h   |  4 +--
 arch/arm/kernel/probes.c         | 10 +++---
 arch/arm/kernel/probes.h         |  4 +--
 12 files changed, 84 insertions(+), 82 deletions(-)
arch/arm/include/asm/kprobes.h +2 -0
index 30fc11b..87b8aa2 100644
@@ -31,6 +31,8 @@ typedef u32 kprobe_opcode_t;
 struct kprobe;
 #include <asm/probes.h>
 
+#define	arch_specific_insn	arch_probes_insn
+
 struct prev_kprobe {
 	struct kprobe *kp;
 	unsigned int status;
arch/arm/include/asm/probes.h +4 -4
index c37252c..806cfe6 100644
@@ -21,18 +21,18 @@
 
 typedef u32 probes_opcode_t;
 
-struct arch_specific_insn;
+struct arch_probes_insn;
 typedef void (probes_insn_handler_t)(probes_opcode_t,
-				     struct arch_specific_insn *,
+				     struct arch_probes_insn *,
 				     struct pt_regs *);
 typedef unsigned long (probes_check_cc)(unsigned long);
 typedef void (probes_insn_singlestep_t)(probes_opcode_t,
-					struct arch_specific_insn *,
+					struct arch_probes_insn *,
 					struct pt_regs *);
 typedef void (probes_insn_fn_t)(void);
 
 /* Architecture specific copy of original instruction. */
-struct arch_specific_insn {
+struct arch_probes_insn {
 	probes_opcode_t			*insn;
 	probes_insn_handler_t		*insn_handler;
 	probes_check_cc			*insn_check_cc;
arch/arm/kernel/kprobes-arm.c +8 -8
index 52591e3..4169ad8 100644
@@ -74,7 +74,7 @@
 
 static void __kprobes
 emulate_ldrdstrd(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
 	int rt = (insn >> 12) & 0xf;
@@ -103,7 +103,7 @@ emulate_ldrdstrd(probes_opcode_t insn,
 
 static void __kprobes
 emulate_ldr(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
 	int rt = (insn >> 12) & 0xf;
@@ -133,7 +133,7 @@ emulate_ldr(probes_opcode_t insn,
 
 static void __kprobes
 emulate_str(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	unsigned long rtpc = regs->ARM_pc - 4 + str_pc_offset;
 	unsigned long rnpc = regs->ARM_pc + 4;
@@ -160,7 +160,7 @@ emulate_str(probes_opcode_t insn,
 
 static void __kprobes
 emulate_rd12rn16rm0rs8_rwflags(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	unsigned long pc = regs->ARM_pc + 4;
 	int rd = (insn >> 12) & 0xf;
@@ -195,7 +195,7 @@ emulate_rd12rn16rm0rs8_rwflags(probes_opcode_t insn,
 
 static void __kprobes
 emulate_rd12rn16rm0_rwflags_nopc(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
 	int rn = (insn >> 16) & 0xf;
@@ -222,7 +222,7 @@ emulate_rd12rn16rm0_rwflags_nopc(probes_opcode_t insn,
 
 static void __kprobes
 emulate_rd16rn12rm0rs8_rwflags_nopc(probes_opcode_t insn,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 	int rd = (insn >> 16) & 0xf;
@@ -252,7 +252,7 @@ emulate_rd16rn12rm0rs8_rwflags_nopc(probes_opcode_t insn,
 
 static void __kprobes
 emulate_rd12rm0_noflags_nopc(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
 	int rm = insn & 0xf;
@@ -272,7 +272,7 @@ emulate_rd12rm0_noflags_nopc(probes_opcode_t insn,
 
 static void __kprobes
 emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(probes_opcode_t insn,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 	int rdlo = (insn >> 12) & 0xf;
arch/arm/kernel/kprobes-common.c +7 -7
index adc6d70..ca0b98c 100644
@@ -19,7 +19,7 @@
 
 
 static void __kprobes simulate_ldm1stm1(probes_opcode_t insn,
-		struct arch_specific_insn *asi,
+		struct arch_probes_insn *asi,
 		struct pt_regs *regs)
 {
 	int rn = (insn >> 16) & 0xf;
@@ -61,7 +61,7 @@ static void __kprobes simulate_ldm1stm1(probes_opcode_t insn,
 }
 
 static void __kprobes simulate_stm1_pc(probes_opcode_t insn,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 	unsigned long addr = regs->ARM_pc - 4;
@@ -72,7 +72,7 @@ static void __kprobes simulate_stm1_pc(probes_opcode_t insn,
 }
 
 static void __kprobes simulate_ldm1_pc(probes_opcode_t insn,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 	simulate_ldm1stm1(insn, asi, regs);
@@ -81,7 +81,7 @@ static void __kprobes simulate_ldm1_pc(probes_opcode_t insn,
 
 static void __kprobes
 emulate_generic_r0_12_noflags(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	register void *rregs asm("r1") = regs;
 	register void *rfn asm("lr") = asi->insn_fn;
@@ -109,7 +109,7 @@ emulate_generic_r0_12_noflags(probes_opcode_t insn,
 
 static void __kprobes
 emulate_generic_r2_14_noflags(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	emulate_generic_r0_12_noflags(insn, asi,
 		(struct pt_regs *)(regs->uregs+2));
@@ -117,7 +117,7 @@ emulate_generic_r2_14_noflags(probes_opcode_t insn,
 
 static void __kprobes
 emulate_ldm_r3_15(probes_opcode_t insn,
-	struct arch_specific_insn *asi, struct pt_regs *regs)
+	struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	emulate_generic_r0_12_noflags(insn, asi,
 		(struct pt_regs *)(regs->uregs+3));
@@ -125,7 +125,7 @@ emulate_ldm_r3_15(probes_opcode_t insn,
 }
 
 enum probes_insn __kprobes
-kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_specific_insn *asi,
+kprobe_decode_ldmstm(probes_opcode_t insn, struct arch_probes_insn *asi,
 		const struct decode_header *h)
 {
 	probes_insn_handler_t *handler = 0;
arch/arm/kernel/kprobes-thumb.c +35 -35

280 lines not on this page · raw message

arch/arm/kernel/kprobes.h +2 -2
index d0a24b7..9a2712e 100644
@@ -30,11 +30,11 @@
 #define KPROBE_THUMB32_BREAKPOINT_INSTRUCTION	0xf7f0a018
 
 enum probes_insn __kprobes
-kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
+kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_probes_insn *asi,
 		const struct decode_header *h);
 
 typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
-						struct arch_specific_insn *,
+						struct arch_probes_insn *,
 						bool,
 						const union decode_action *);
 
arch/arm/kernel/probes-arm.c +7 -7
index a4f6914..4e1d9e3 100644
@@ -56,7 +56,7 @@
  */
 
 void __kprobes simulate_bbl(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	long iaddr = (long) regs->ARM_pc - 4;
 	int disp  = branch_displacement(insn);
@@ -68,7 +68,7 @@ void __kprobes simulate_bbl(probes_opcode_t insn,
 }
 
 void __kprobes simulate_blx1(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	long iaddr = (long) regs->ARM_pc - 4;
 	int disp = branch_displacement(insn);
@@ -79,7 +79,7 @@ void __kprobes simulate_blx1(probes_opcode_t insn,
 }
 
 void __kprobes simulate_blx2bx(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	int rm = insn & 0xf;
 	long rmv = regs->uregs[rm];
@@ -94,7 +94,7 @@ void __kprobes simulate_blx2bx(probes_opcode_t insn,
 }
 
 void __kprobes simulate_mrs(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	int rd = (insn >> 12) & 0xf;
 	unsigned long mask = 0xf8ff03df; /* Mask out execution state */
@@ -102,7 +102,7 @@ void __kprobes simulate_mrs(probes_opcode_t insn,
 }
 
 void __kprobes simulate_mov_ipsp(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	regs->uregs[12] = regs->uregs[13];
 }
@@ -703,7 +703,7 @@ EXPORT_SYMBOL_GPL(probes_decode_arm_table);
 #endif
 
 static void __kprobes arm_singlestep(probes_opcode_t insn,
-		struct arch_specific_insn *asi, struct pt_regs *regs)
+		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
 	regs->ARM_pc += 4;
 	asi->insn_handler(insn, asi, regs);
@@ -722,7 +722,7 @@ static void __kprobes arm_singlestep(probes_opcode_t insn,
  *   should also be very rare.
  */
 enum probes_insn __kprobes
-arm_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+arm_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		       bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = arm_singlestep;
arch/arm/kernel/probes-arm.h +6 -6
index ea614dc..ace6572 100644
@@ -54,20 +54,20 @@ enum probes_arm_action {
 };
 
 void __kprobes simulate_bbl(probes_opcode_t opcode,
-	struct arch_specific_insn *asi, struct pt_regs *regs);
+	struct arch_probes_insn *asi, struct pt_regs *regs);
 void __kprobes simulate_blx1(probes_opcode_t opcode,
-	struct arch_specific_insn *asi, struct pt_regs *regs);
+	struct arch_probes_insn *asi, struct pt_regs *regs);
 void __kprobes simulate_blx2bx(probes_opcode_t opcode,
-	struct arch_specific_insn *asi, struct pt_regs *regs);
+	struct arch_probes_insn *asi, struct pt_regs *regs);
 void __kprobes simulate_mrs(probes_opcode_t opcode,
-	struct arch_specific_insn *asi, struct pt_regs *regs);
+	struct arch_probes_insn *asi, struct pt_regs *regs);
 void __kprobes simulate_mov_ipsp(probes_opcode_t opcode,
-	struct arch_specific_insn *asi, struct pt_regs *regs);
+	struct arch_probes_insn *asi, struct pt_regs *regs);
 
 extern const union decode_item probes_decode_arm_table[];
 
 enum probes_insn arm_probes_decode_insn(probes_opcode_t,
-		struct arch_specific_insn *, bool emulate,
+		struct arch_probes_insn *, bool emulate,
 		const union decode_action *actions);
 
 #endif
arch/arm/kernel/probes-thumb.c +4 -4
index 1a3ddf8..28a1fc3 100644
@@ -843,7 +843,7 @@ static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
 }
 
 static void __kprobes thumb16_singlestep(probes_opcode_t opcode,
-		struct arch_specific_insn *asi,
+		struct arch_probes_insn *asi,
 		struct pt_regs *regs)
 {
 	regs->ARM_pc += 2;
@@ -852,7 +852,7 @@ static void __kprobes thumb16_singlestep(probes_opcode_t opcode,
 }
 
 static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
-		struct arch_specific_insn *asi,
+		struct arch_probes_insn *asi,
 		struct pt_regs *regs)
 {
 	regs->ARM_pc += 4;
@@ -861,7 +861,7 @@ static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
 }
 
 enum probes_insn __kprobes
-thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 			   bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb16_singlestep;
@@ -871,7 +871,7 @@ thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
 }
 
 enum probes_insn __kprobes
-thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 			   bool emulate, const union decode_action *actions)
 {
 	asi->insn_singlestep = thumb32_singlestep;
arch/arm/kernel/probes-thumb.h +2 -2
index dd95866..cd1ae36 100644
@@ -88,10 +88,10 @@ extern const union decode_item probes_decode_thumb32_table[];
 extern const union decode_item probes_decode_thumb16_table[];
 
 enum probes_insn __kprobes
-thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		bool emulate, const union decode_action *actions);
 enum probes_insn __kprobes
-thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		bool emulate, const union decode_action *actions);
 
 #endif
arch/arm/kernel/probes.c +5 -5
index 8a4088f..0f6fd61 100644
@@ -172,13 +172,13 @@ probes_check_cc * const probes_condition_checks[16] = {
 
 
 void __kprobes probes_simulate_nop(probes_opcode_t opcode,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 }
 
 void __kprobes probes_emulate_none(probes_opcode_t opcode,
-	struct arch_specific_insn *asi,
+	struct arch_probes_insn *asi,
 	struct pt_regs *regs)
 {
 	asi->insn_fn();
@@ -192,7 +192,7 @@ void __kprobes probes_emulate_none(probes_opcode_t opcode,
  * emulation handler is called.
  */
 static probes_opcode_t __kprobes
-prepare_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+prepare_emulated_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		      bool thumb)
 {
 #ifdef CONFIG_THUMB2_KERNEL
@@ -217,7 +217,7 @@ prepare_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
  * prepare_emulated_insn
  */
 static void  __kprobes
-set_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+set_emulated_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		  bool thumb)
 {
 #ifdef CONFIG_THUMB2_KERNEL
@@ -381,7 +381,7 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
  *
  */
 int __kprobes
-probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		   const union decode_item *table, bool thumb,
 		   bool emulate, const union decode_action *actions)
 {
arch/arm/kernel/probes.h +2 -2
index 321d15f..4056c8a 100644
@@ -304,7 +304,7 @@ union decode_item {
 
 struct decode_header;
 typedef enum probes_insn (probes_custom_decode_t)(probes_opcode_t,
-						  struct arch_specific_insn *,
+						  struct arch_probes_insn *,
 						  const struct decode_header *);
 
 union decode_action {
@@ -398,7 +398,7 @@ probes_insn_handler_t probes_simulate_nop;
 probes_insn_handler_t probes_emulate_none;
 
 int __kprobes
-probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
+probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 		const union decode_item *table, bool thumb, bool emulate,
 		const union decode_action *actions);
 
Signature · 1 line
1.8.1.2
author
#19 lore raw

PATCH v6 14/14 ARM: add uprobes support

In reply to David Long

From: "David A. Long" <[email protected]>

Using Rabin Vincent's ARM uprobes patches as a base, enable uprobes support on ARM.

Caveats:

- Thumb is not supported

---
 arch/arm/Kconfig                   |   3 +
 arch/arm/include/asm/ptrace.h      |   6 +
 arch/arm/include/asm/thread_info.h |   5 +-
 arch/arm/include/asm/uprobes.h     |  45 +++++++
 arch/arm/kernel/Makefile           |   1 +
 arch/arm/kernel/signal.c           |   4 +
 arch/arm/kernel/uprobes-arm.c      | 232 +++++++++++++++++++++++++++++++++++++
 arch/arm/kernel/uprobes.c          | 208 +++++++++++++++++++++++++++++++++
 arch/arm/kernel/uprobes.h          |  35 ++++++
 9 files changed, 538 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/include/asm/uprobes.h
 create mode 100644 arch/arm/kernel/uprobes-arm.c
 create mode 100644 arch/arm/kernel/uprobes.c
 create mode 100644 arch/arm/kernel/uprobes.h
arch/arm/Kconfig +3 -0
index e254198..4d05bb9 100644
@@ -207,6 +207,9 @@ config ZONE_DMA
 config NEED_DMA_MAP_STATE
        def_bool y
 
+config ARCH_SUPPORTS_UPROBES
+	def_bool y
+
 config ARCH_HAS_DMA_SET_COHERENT_MASK
 	bool
 
arch/arm/include/asm/ptrace.h +6 -0
index 04c99f3..ee688b0a 100644
@@ -80,6 +80,12 @@ static inline long regs_return_value(struct pt_regs *regs)
 
 #define instruction_pointer(regs)	(regs)->ARM_pc
 
+static inline void instruction_pointer_set(struct pt_regs *regs,
+					   unsigned long val)
+{
+	instruction_pointer(regs) = val;
+}
+
 #ifdef CONFIG_SMP
 extern unsigned long profile_pc(struct pt_regs *regs);
 #else
arch/arm/include/asm/thread_info.h +4 -1
index 71a06b2..f989d7c 100644
@@ -153,6 +153,7 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
 #define TIF_SIGPENDING		0
 #define TIF_NEED_RESCHED	1
 #define TIF_NOTIFY_RESUME	2	/* callback before returning to user */
+#define TIF_UPROBE		7
 #define TIF_SYSCALL_TRACE	8
 #define TIF_SYSCALL_AUDIT	9
 #define TIF_SYSCALL_TRACEPOINT	10
@@ -165,6 +166,7 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
+#define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
@@ -178,7 +180,8 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
 /*
  * Change these and you break ASM code in entry-common.S
  */
-#define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | _TIF_NOTIFY_RESUME)
+#define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
+				 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
 
 #endif /* __KERNEL__ */
 #endif /* __ASM_ARM_THREAD_INFO_H */
arch/arm/include/asm/uprobes.h new file +45 -0

45 lines not on this page · raw message

arch/arm/kernel/Makefile +1 -0
index bb739f2..a766bcb 100644
@@ -50,6 +50,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o insn.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o insn.o
 obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o insn.o patch.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_UPROBES)		+= probes.o probes-arm.o uprobes.o uprobes-arm.o
 obj-$(CONFIG_KPROBES)		+= probes.o kprobes.o kprobes-common.o patch.o
 ifdef CONFIG_THUMB2_KERNEL
 obj-$(CONFIG_KPROBES)		+= kprobes-thumb.o probes-thumb.o
arch/arm/kernel/signal.c +4 -0
index 04d6388..bd19834 100644
@@ -13,6 +13,7 @@
 #include <linux/personality.h>
 #include <linux/uaccess.h>
 #include <linux/tracehook.h>
+#include <linux/uprobes.h>
 
 #include <asm/elf.h>
 #include <asm/cacheflush.h>
@@ -590,6 +591,9 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
 					return restart;
 				}
 				syscall = 0;
+			} else if (thread_flags & _TIF_UPROBE) {
+				clear_thread_flag(TIF_UPROBE);
+				uprobe_notify_resume(regs);
 			} else {
 				clear_thread_flag(TIF_NOTIFY_RESUME);
 				tracehook_notify_resume(regs);
arch/arm/kernel/uprobes-arm.c new file +232 -0

232 lines not on this page · raw message

arch/arm/kernel/uprobes.c new file +208 -0

208 lines not on this page · raw message

arch/arm/kernel/uprobes.h new file +35 -0
new file mode 100644
index 0000000..1d0c12d
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 Rabin Vincent <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ARM_KERNEL_UPROBES_H
+#define __ARM_KERNEL_UPROBES_H
+
+enum probes_insn uprobe_decode_ldmstm(probes_opcode_t insn,
+				      struct arch_probes_insn *asi,
+				      const struct decode_header *d);
+
+enum probes_insn decode_ldr(probes_opcode_t insn,
+			    struct arch_probes_insn *asi,
+			    const struct decode_header *d);
+
+enum probes_insn
+decode_rd12rn16rm0rs8_rwflags(probes_opcode_t insn,
+			      struct arch_probes_insn *asi,
+			      const struct decode_header *d);
+
+enum probes_insn
+decode_wb_pc(probes_opcode_t insn, struct arch_probes_insn *asi,
+	     const struct decode_header *d, bool alu);
+
+enum probes_insn
+decode_pc_ro(probes_opcode_t insn, struct arch_probes_insn *asi,
+	     const struct decode_header *d);
+
+extern const union decode_action uprobes_probes_actions[];
+
+#endif
Signature · 1 line
1.8.1.2
#20 lore raw
In reply to David Long
Quoted 7 lines · David Long

This patch series adds basic uprobes support to ARM. It is based on patches developed earlier by Rabin Vincent. That approach of adding hooks into the kprobes instruction parsing code was not well received. This approach separates the ARM instruction parsing code in kprobes out into a separate set of functions which can be used by both kprobes and uprobes. Both kprobes and uprobes then provide their own semantic action tables to process the results of the parsing.

Here's more build errors, from omap4430-sdp's randconfig build from last night - note that the linker can't always get the filenames right:

arch/arm/kernel/built-in.o: In function `do_work_pending':
psci_smp.c:(.text+0x2e44): undefined reference to uprobe_notify_resume' arch/arm/kernel/built-in.o: In function uprobe_trap_handler':
psci_smp.c:(.text+0x79d4): undefined reference to uprobe_pre_sstep_notifier' psci_smp.c:(.text+0x79e8): undefined reference to uprobe_post_sstep_notifier' arch/arm/kernel/built-in.o: In function `set_swbp':
psci_smp.c:(.text+0x7a54): undefined reference to uprobe_write_opcode' kernel/built-in.o: In function mmput.part.45':
context_tracking.c:(.text+0xaf0): undefined reference to uprobe_clear_state' kernel/built-in.o: In function mm_release':
context_tracking.c:(.text+0xd3c): undefined reference to uprobe_free_utask' kernel/built-in.o: In function copy_process.part.47':
context_tracking.c:(.text+0x1748): undefined reference to uprobe_copy_process' kernel/built-in.o: In function get_signal_to_deliver':
context_tracking.c:(.text+0x111bc): undefined reference to uprobe_deny_signal' kernel/built-in.o: In function probe_event_enable.constprop.5':
context_tracking.c:(.text+0x9f0b8): undefined reference to uprobe_register' kernel/built-in.o: In function trace_uprobe_register':
context_tracking.c:(.text+0x9f134): undefined reference to uprobe_unregister' kernel/built-in.o: In function dup_mmap':
context_tracking.c:(.text.unlikely+0x354): undefined reference to uprobe_start_dup_mmap' context_tracking.c:(.text.unlikely+0x380): undefined reference to uprobe_dup_mmap' context_tracking.c:(.text.unlikely+0x5e8): undefined reference to uprobe_end_dup_mmap' mm/built-in.o: In function unmap_single_vma':
page_isolation.c:(.text+0x22d10): undefined reference to uprobe_munmap' mm/built-in.o: In function vma_adjust':
page_isolation.c:(.text+0x2748c): undefined reference to uprobe_munmap' page_isolation.c:(.text+0x274a0): undefined reference to uprobe_munmap' page_isolation.c:(.text+0x27858): undefined reference to uprobe_mmap' page_isolation.c:(.text+0x2786c): undefined reference to uprobe_mmap' page_isolation.c:(.text+0x2788c): undefined reference to uprobe_munmap' page_isolation.c:(.text+0x2790c): undefined reference to uprobe_mmap' mm/built-in.o: In function `mmap_region':
page_isolation.c:(.text+0x2963c): undefined reference to `uprobe_mmap' make[1]: *** [vmlinux] Error 1
make[1]: Target `zImage' not remade because of errors.

So, let's take uprobe_notify_resume(). This is unconditionally referenced by arch/arm/kernel/signal.c:

                                syscall = 0;
                        } else if (thread_flags & _TIF_UPROBE) {
                                clear_thread_flag(TIF_UPROBE);
                                uprobe_notify_resume(regs);
                        } else {
                                clear_thread_flag(TIF_NOTIFY_RESUME);
                                tracehook_notify_resume(regs);
                        }

and is declared in include/linux/uprobes.h:

	#ifdef CONFIG_UPROBES
	#include <asm/uprobes.h>
	...
	extern void uprobe_notify_resume(struct pt_regs *regs);
	...
	#else /* !CONFIG_UPROBES */
	...
	static inline void uprobe_notify_resume(struct pt_regs *regs)
	{
	}
	...
	#endif /* !CONFIG_UPROBES */

It is defined in kernel/events/uprobes.c:

kernel/events/uprobes.c:void uprobe_notify_resume(struct pt_regs *regs)

which is built when CONFIG_UPROBES is set:

	obj-$(CONFIG_UPROBES) += uprobes.o

but, the events directory is only built when CONFIG_PERF_EVENTS is also set:

	obj-$(CONFIG_PERF_EVENTS) += events/

and the failing configuration has:

# CONFIG_PERF_EVENTS is not set
CONFIG_UPROBES=y

Clearly, it doesn't make sense for UPROBES to be enabled with PERF_EVENTS disabled - and indeed the Kconfig ensures that this dependency is properly expressed:

	config UPROBES
	        bool "Transparent user-space probes (EXPERIMENTAL)"
	        depends on UPROBE_EVENT && PERF_EVENTS
	        default n
	        select PERCPU_RWSEM

but where this all falls down is here:

config UPROBE_EVENT
bool "Enable uprobes-based dynamic events" depends on ARCH_SUPPORTS_UPROBES depends on MMU
select UPROBES
select PROBE_EVENTS
select TRACING
default n

Which is yet another brilliant example of why this "select" crap is soo evil. Yes, the failing configuration has:

CONFIG_UPROBE_EVENT=y

Ineed, there was a Kconfig warning:

	warning: (UPROBE_EVENT) selects UPROBES which has unmet direct dependencies (UPROBE_EVENT && PERF_EVENTS)

This is not your fault. It's the fault of everyone who passed through commit f3f096cfedf8113380c56fc855275cc75cd8cf55 without properly reviewing it and paying attention to that select crap. Given how evil "select" is, it's something which should always be thoroughly reviewed - with analysis of the dependencies. I believe commits which introduce new select statements should document an analysis of why those new select statements are appropriate and how they ensure that any dependencies of the selected symbol are not violated.

Therefore, I will not take the ARM uprobes code while this kind of select abortion is present - it needs to be fixed first to avoid these build errors. Sorry.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
author
#21 lore raw

Oleg,

I've been looking at arch/Kconfig and kernel/trace/Kconfig where they deal with uprobes. The relevant items are CONFIG_UPROBES and CONFIG_UPROBE_EVENT. It just doesn't look right to me. It looks like "select" is used in part maybe just to avoid the recursive dependency error that would be generated if "depends on" were used in both places. However I don't think UPROBES should be dependent on UPROBE_EVENT, only the other way around. As RK noted in previous email (copied in part below) the select does not pull in the lower level dependencies. This all works on x86 only because arch/x86/Kconfig defines CONFIG_PERF_EVENT (which feels like a big hammer). We don't need to do this on ARM, and we don't do it. The result is that, unless PERF_EVENT is set separately, uprobes tends not to build. I was lucking-out in my testing due to other default config items turning on PERF_EVENT.

What do you think about the following patch?:

Quoted 19 lines
arch/Kconfig +2 -1
index 80bbb8c..8793066 100644
@@ -87,7 +87,8 @@ config KPROBES_ON_FTRACE
 
 config UPROBES
 	bool "Transparent user-space probes (EXPERIMENTAL)"
-	depends on UPROBE_EVENT && PERF_EVENTS
+	depends on ARCH_SUPPORTS_UPROBES
+	depends on PERF_EVENTS
 	default n
 	select PERCPU_RWSEM
 	help
kernel/trace/Kconfig +0 -0
index 015f85a..7d2647e 100644

kernel/trace/Kconfig config KPROBE_EVENT · line 429

Quoted 10 lines
kernel/trace/Kconfig +1 -2
@@ -422,9 +422,8 @@ config KPROBE_EVENT
 
 config UPROBE_EVENT
 	bool "Enable uprobes-based dynamic events"
-	depends on ARCH_SUPPORTS_UPROBES
 	depends on MMU
-	select UPROBES
+	depends on UPROBES
 	select PROBE_EVENTS
 	select TRACING
 	default n

This removes the pseudo-recursive dependency. The downside is that now you have to set PERF_EVENTS to use UPROBES, and UPROBES to use UPROBE_EVENT, whereas before on x86 you only had to set UPROBE_EVENT (as long as PERF_EVENTS stays hardcoded on). I think this could be avoided by making each "depends on" a "selects", since they apply transitively.
I'm sensing this would be an unpopular idea though.

-dl

On 03/01/14 07:30, Russell King - ARM Linux wrote:

[ ... ]

Quoted 43 lines

Clearly, it doesn't make sense for UPROBES to be enabled with PERF_EVENTS disabled - and indeed the Kconfig ensures that this dependency is properly expressed:

	config UPROBES
	        bool "Transparent user-space probes (EXPERIMENTAL)"
	        depends on UPROBE_EVENT && PERF_EVENTS
	        default n
	        select PERCPU_RWSEM

but where this all falls down is here:

config UPROBE_EVENT
bool "Enable uprobes-based dynamic events" depends on ARCH_SUPPORTS_UPROBES depends on MMU
select UPROBES
select PROBE_EVENTS
select TRACING
default n

Which is yet another brilliant example of why this "select" crap is soo evil. Yes, the failing configuration has:

CONFIG_UPROBE_EVENT=y

Ineed, there was a Kconfig warning:

	warning: (UPROBE_EVENT) selects UPROBES which has unmet direct dependencies (UPROBE_EVENT && PERF_EVENTS)

This is not your fault. It's the fault of everyone who passed through commit f3f096cfedf8113380c56fc855275cc75cd8cf55 without properly reviewing it and paying attention to that select crap. Given how evil "select" is, it's something which should always be thoroughly reviewed - with analysis of the dependencies. I believe commits which introduce new select statements should document an analysis of why those new select statements are appropriate and how they ensure that any dependencies of the selected symbol are not violated.

Therefore, I will not take the ARM uprobes code while this kind of select abortion is present - it needs to be fixed first to avoid these build errors. Sorry.

#22 lore raw
Quoted 6 lines

Oleg,

I've been looking at arch/Kconfig and kernel/trace/Kconfig where they deal with uprobes. The relevant items are CONFIG_UPROBES and CONFIG_UPROBE_EVENT. It just doesn't look right to me. It looks

It should be me who should take the blame for this and not Oleg. This was discussed more than couple of times. I can recollect couple of discussions here.
http://article.gmane.org/gmane.linux.kernel/1017186
http://article.gmane.org/gmane.linux.kernel/1001605

I know there were more discussions on this, but I cant dig them out at this time. Finally it was decided that
1. Users shouldnt have to select more than one config to select Uprobes.
2. There was no point in selecting Uprobes and not having Uprobe_event and vice versa.

Quoted 1 line

From the above, If a user chose UPROBE_EVENT, (which is the interface

for uprobes), we would automatically assume that he wants to use Uprobes framework.

Quoted 3 lines

like "select" is used in part maybe just to avoid the recursive dependency error that would be generated if "depends on" were used in both places.

We did "Select Uprobes" not because of avoiding recursive dependency but as told above, to select the framework, given that user has chosen the framework. We dont want to give a choice to user to choose uprobe_event but not choose Uprobes or vice versa.

Quoted 2 lines

However I don't think UPROBES should be dependent on UPROBE_EVENT, only the other way around. As RK noted in previous

Whats the point of having the framework(Uprobes) without an interface?

Quoted 8 lines

email (copied in part below) the select does not pull in the lower level dependencies. This all works on x86 only because arch/x86/Kconfig defines CONFIG_PERF_EVENT (which feels like a big hammer). We don't need to do this on ARM, and we don't do it. The result is that, unless PERF_EVENT is set separately, uprobes tends not to build. I was lucking-out in my testing due to other default config items turning on PERF_EVENT.

--
Thanks and Regards
Srikar Dronamraju

author
#23 lore raw
Quoted 5 lines · Srikar Dronamraju

It should be me who should take the blame for this and not Oleg. This was discussed more than couple of times. I can recollect couple of discussions here.
http://article.gmane.org/gmane.linux.kernel/1017186
http://article.gmane.org/gmane.linux.kernel/1001605

I wasn't trying to assign blame to anyone, I was just soliciting an opinion from the last uprobes maintainer I had a conversation with. Thanks for the links.

Quoted 10 lines

I know there were more discussions on this, but I cant dig them out at this time. Finally it was decided that
1. Users shouldnt have to select more than one config to select Uprobes.
2. There was no point in selecting Uprobes and not having Uprobe_event and vice versa.

From the above, If a user chose UPROBE_EVENT, (which is the interface
for uprobes), we would automatically assume that he wants to use Uprobes framework.

Quoted 8 lines
Quoted 3 lines

like "select" is used in part maybe just to avoid the recursive dependency error that would be generated if "depends on" were used in both places.

We did "Select Uprobes" not because of avoiding recursive dependency but as told above, to select the framework, given that user has chosen the framework. We dont want to give a choice to user to choose uprobe_event but not choose Uprobes or vice versa.

I suppose that's more to the point.

Quoted 5 lines
Quoted 2 lines

However I don't think UPROBES should be dependent on UPROBE_EVENT, only the other way around. As RK noted in previous

Whats the point of having the framework(Uprobes) without an interface?

My comment was based only in the fact it built successfully that way on both x86 and ARM. If there's no way to access the functionality without both selected then I suppose it does make sense to not allow that configuration. Maybe it's time to remove one of these config symbols. I didn't see anything in the email history on this that says that would be a bad idea. I'll try and come up with a patch.

-dl

#24 lore raw
In reply to Srikar Dronamraju
Quoted 9 lines · Srikar Dronamraju

I know there were more discussions on this, but I cant dig them out at this time. Finally it was decided that
1. Users shouldnt have to select more than one config to select Uprobes.
2. There was no point in selecting Uprobes and not having Uprobe_event and vice versa.

Quoted 1 line

From the above, If a user chose UPROBE_EVENT, (which is the interface

for uprobes), we would automatically assume that he wants to use Uprobes framework.

That much is fine - however, UPROBES itself is effectively not a user selectable symbol, even today. As I've already pointed it, it's impossible for the user to select because it depends on UPROBE_EVENT, but when UPROBE_EVENT is enabled, it's forced to be set to "y" meaning that the user can't turn UPROBES off.

So, the UPROBES symbol has two states:
1. hidden, because its dependencies aren't satisfied.
2. force-y, because UPROBE_EVENT is enabled.

Hence, UPROBES itself serves no purpose.

Now, the solution you mentioned in:

	http://article.gmane.org/gmane.linux.kernel/1017186

looks entirely reasonable to me if there is the desire to keep the two separate - but from what Frederic said in that post, it seems that there isn't.

So I'd suggest just getting rid of this UPROBES symbol, moving the dependency of PERF_EVENTS to UPROBE_EVENTS. If another interface to uprobes comes along, it can always be reintroduced in the manner you suggested in the above.

Either solution should resolve the issue we're seeing on ARM with David's patches.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
maintainer
#25 lore raw
In reply to David Long
Quoted 6 lines · David Long

Oleg,

I've been looking at arch/Kconfig and kernel/trace/Kconfig where they deal with uprobes. The relevant items are CONFIG_UPROBES and CONFIG_UPROBE_EVENT. It just doesn't look right to me.

Yes, this looks strange. I never understood these dependencies. In fact I even never tried. And I do not really understand kbuild, unfortunately...

Quoted 9 lines

arch/Kconfig config KPROBES_ON_FTRACE · line 91

Quoted 9 lines
arch/Kconfig +2 -1
@@ -87,7 +87,8 @@ config KPROBES_ON_FTRACE
 
 config UPROBES
 	bool "Transparent user-space probes (EXPERIMENTAL)"
-	depends on UPROBE_EVENT && PERF_EVENTS
+	depends on ARCH_SUPPORTS_UPROBES
+	depends on PERF_EVENTS

And why CONFIG_UPROBES should depend on PERF_EVENTS? uprobes can be used by (say) systemtap without UPROBE_EVENT/PERF_EVENTS.

But as Russell pointed out the events directory is only built if CONFIG_PERF_EVENTS=y, so it should depend on it or select...

I dunno. Personally I vote for the patch from Srikar in

	http://article.gmane.org/gmane.linux.kernel/1017186

This is what we currently have, currently CONFIG_UPROBES is not user-selectable anyway.

Oleg.

#26 lore raw
Quoted 28 lines · Oleg Nesterov
Quoted 6 lines · David Long

Oleg,

I've been looking at arch/Kconfig and kernel/trace/Kconfig where they deal with uprobes. The relevant items are CONFIG_UPROBES and CONFIG_UPROBE_EVENT. It just doesn't look right to me.

Yes, this looks strange. I never understood these dependencies. In fact I even never tried. And I do not really understand kbuild, unfortunately...

Quoted 9 lines

arch/Kconfig config KPROBES_ON_FTRACE · line 91

Quoted 9 lines
arch/Kconfig +2 -1
@@ -87,7 +87,8 @@ config KPROBES_ON_FTRACE
 
 config UPROBES
 	bool "Transparent user-space probes (EXPERIMENTAL)"
-	depends on UPROBE_EVENT && PERF_EVENTS
+	depends on ARCH_SUPPORTS_UPROBES
+	depends on PERF_EVENTS

And why CONFIG_UPROBES should depend on PERF_EVENTS? uprobes can be used by (say) systemtap without UPROBE_EVENT/PERF_EVENTS.

But as Russell pointed out the events directory is only built if CONFIG_PERF_EVENTS=y, so it should depend on it or select...

Quoted 6 lines

I dunno. Personally I vote for the patch from Srikar in

	http://article.gmane.org/gmane.linux.kernel/1017186

This is what we currently have, currently CONFIG_UPROBES is not user-selectable anyway.

Yes, me too, but with the proviso that UPROBE_EVENT also sorts itself out with PERF_EVENTS in some way too (either by selecting it, which IMHO isn't nice, or by depending on it, or the build dependency itself gets sorted.)

Maybe a simpler answer would be to change the build stuff (hand-crafted):

kernel/Makefile
-obj-$(CONFIG_PERF_EVENTS) += events/
+obj-y += events/

and kernel/events/Makefile:

-obj-y := core.o ring_buffer.o callchain.o
+perf-y := core.o ring_buffer.o callchain.o

-obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +perf-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +
+obj-${CONFIG_PERF_EVENTS) += $(perf-y)

?

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
maintainer
#27 lore raw
Quoted 14 lines · Russell King - ARM Linux
Quoted 12 lines · Oleg Nesterov

And why CONFIG_UPROBES should depend on PERF_EVENTS? uprobes can be used by (say) systemtap without UPROBE_EVENT/PERF_EVENTS.

But as Russell pointed out the events directory is only built if CONFIG_PERF_EVENTS=y, so it should depend on it or select...

I dunno. Personally I vote for the patch from Srikar in

	http://article.gmane.org/gmane.linux.kernel/1017186
Quoted 7 lines
Quoted 2 lines

This is what we currently have, currently CONFIG_UPROBES is not user-selectable anyway.

Yes, me too, but with the proviso that UPROBE_EVENT also sorts itself out with PERF_EVENTS in some way too (either by selecting it, which IMHO isn't nice, or by depending on it, or the build dependency itself gets sorted.)

OK... what do you think about the patch below for now?

Quoted 8 lines

Maybe a simpler answer would be to change the build stuff (hand-crafted):

kernel/Makefile

(quoted diff) +1 -1
-obj-$(CONFIG_PERF_EVENTS) += events/
+obj-y += events/

and kernel/events/Makefile:

Review

Quoted 7 lines
(quoted diff) +4 -2
-obj-y := core.o ring_buffer.o callchain.o
+perf-y := core.o ring_buffer.o callchain.o
 
-obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
+perf-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
+
+obj-${CONFIG_PERF_EVENTS) += $(perf-y)

I fully agree. Except I can't review this change ;) But hopefully I can understand what it should do.

But personally I'd prefer to start with the simple/safe change which allows us to merge this series. If nothing else, even if I think that kernel/events/uprobes.c doesn't need CONFIG_PERF_EVENTS, this should be verified and discussed with perf maintainers.

If you agree with the patch below, how should we route it? I won't argue if you push it along with other patches from David.

BTW... why UPROBE_EVENT depends on MMU? I think that ARCH_SUPPORTS_UPROBES should not be true if !CONFIG_MMU.

Oleg.
---

arch/Kconfig +1 -5
index 80bbb8c..97ff872 100644
@@ -86,9 +86,7 @@ config KPROBES_ON_FTRACE
 	 optimize on top of function tracing.
 
 config UPROBES
-	bool "Transparent user-space probes (EXPERIMENTAL)"
-	depends on UPROBE_EVENT && PERF_EVENTS
-	default n
+	def_bool n
 	select PERCPU_RWSEM
 	help
 	  Uprobes is the user-space counterpart to kprobes: they
@@ -101,8 +99,6 @@ config UPROBES
 	    managed by the kernel and kept transparent to the probed
 	    application. )
 
-	  If in doubt, say "N".
-
 config HAVE_64BIT_ALIGNED_ACCESS
 	def_bool 64BIT && !HAVE_EFFICIENT_UNALIGNED_ACCESS
 	help
kernel/trace/Kconfig +1 -0
index 015f85a..8639819 100644
@@ -424,6 +424,7 @@ config UPROBE_EVENT
 	bool "Enable uprobes-based dynamic events"
 	depends on ARCH_SUPPORTS_UPROBES
 	depends on MMU
+	depends on PERF_EVENTS
 	select UPROBES
 	select PROBE_EVENTS
 	select TRACING
author
#28 lore raw
Quoted 44 lines · Oleg Nesterov
Quoted 14 lines · Russell King - ARM Linux
Quoted 12 lines · Oleg Nesterov

And why CONFIG_UPROBES should depend on PERF_EVENTS? uprobes can be used by (say) systemtap without UPROBE_EVENT/PERF_EVENTS.

But as Russell pointed out the events directory is only built if CONFIG_PERF_EVENTS=y, so it should depend on it or select...

I dunno. Personally I vote for the patch from Srikar in

	http://article.gmane.org/gmane.linux.kernel/1017186
Quoted 7 lines
Quoted 2 lines

This is what we currently have, currently CONFIG_UPROBES is not user-selectable anyway.

Yes, me too, but with the proviso that UPROBE_EVENT also sorts itself out with PERF_EVENTS in some way too (either by selecting it, which IMHO isn't nice, or by depending on it, or the build dependency itself gets sorted.)

OK... what do you think about the patch below for now?

Quoted 8 lines

Maybe a simpler answer would be to change the build stuff (hand-crafted):

kernel/Makefile

(quoted diff) +1 -1
-obj-$(CONFIG_PERF_EVENTS) += events/
+obj-y += events/

and kernel/events/Makefile:

Review

Quoted 7 lines
(quoted diff) +4 -2
-obj-y := core.o ring_buffer.o callchain.o
+perf-y := core.o ring_buffer.o callchain.o
 
-obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
+perf-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
+
+obj-${CONFIG_PERF_EVENTS) += $(perf-y)

I fully agree. Except I can't review this change ;) But hopefully I can understand what it should do.

Quoted 8 lines

But personally I'd prefer to start with the simple/safe change which allows us to merge this series. If nothing else, even if I think that kernel/events/uprobes.c doesn't need CONFIG_PERF_EVENTS, this should be verified and discussed with perf maintainers.

If you agree with the patch below, how should we route it? I won't argue if you push it along with other patches from David.

Oleg, I'll put you down as the author and add a signed-off line for you if that is OK? Not sure who should ack it.

Quoted 36 lines

BTW... why UPROBE_EVENT depends on MMU? I think that ARCH_SUPPORTS_UPROBES should not be true if !CONFIG_MMU.

Oleg.
---

arch/Kconfig +1 -5
index 80bbb8c..97ff872 100644
@@ -86,9 +86,7 @@ config KPROBES_ON_FTRACE
  	 optimize on top of function tracing.
 
  config UPROBES
-	bool "Transparent user-space probes (EXPERIMENTAL)"
-	depends on UPROBE_EVENT && PERF_EVENTS
-	default n
+	def_bool n
  	select PERCPU_RWSEM
  	help
  	  Uprobes is the user-space counterpart to kprobes: they
@@ -101,8 +99,6 @@ config UPROBES
  	    managed by the kernel and kept transparent to the probed
  	    application. )
 
-	  If in doubt, say "N".
-
  config HAVE_64BIT_ALIGNED_ACCESS
  	def_bool 64BIT && !HAVE_EFFICIENT_UNALIGNED_ACCESS
  	help
kernel/trace/Kconfig +0 -0
index 015f85a..8639819 100644

kernel/trace/Kconfig config UPROBE_EVENT · line 430

Quoted 7 lines
kernel/trace/Kconfig +1 -0
@@ -424,6 +424,7 @@ config UPROBE_EVENT
  	bool "Enable uprobes-based dynamic events"
  	depends on ARCH_SUPPORTS_UPROBES
  	depends on MMU
+	depends on PERF_EVENTS
  	select UPROBES
  	select PROBE_EVENTS
  	select TRACING

Can we agree Oleg's patch above is the best way to go in the short term?
I've tested it and it addresses the problem, although of course one
has to know to enable PERF_EVENTS to even see the UPROBE_EVENT option (not a problem on x86 as they always set PERF_EVENTS).

I'm continuing to test the above with my new include file changes, using Arnd's randconfig patches. Looks good so far.

-dl