Skip to content

Commit 602cd26

Browse files
author
David A. Long
committed
ARM: Add an emulate flag to the kprobes/uprobes instruction decode functions
Add an emulate flag into the instruction interpreter, primarily for uprobes support. Signed-off-by: David A. Long <dave.long@linaro.org> Acked-by: Jon Medhurst <tixy@linaro.org>
1 parent 47e190f commit 602cd26

8 files changed

Lines changed: 25 additions & 16 deletions

File tree

‎arch/arm/kernel/kprobes.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
8989
p->opcode = insn;
9090
p->ainsn.insn = tmp_insn;
9191

92-
switch ((*decode_insn)(insn, &p->ainsn, actions)) {
92+
switch ((*decode_insn)(insn, &p->ainsn, true, actions)) {
9393
case INSN_REJECTED: /* not supported */
9494
return -EINVAL;
9595

‎arch/arm/kernel/kprobes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi,
3535

3636
typedef enum probes_insn (kprobe_decode_insn_t)(probes_opcode_t,
3737
struct arch_specific_insn *,
38+
bool,
3839
const union decode_action *);
3940

4041
#ifdef CONFIG_THUMB2_KERNEL

‎arch/arm/kernel/probes-arm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,10 @@ static void __kprobes arm_singlestep(probes_opcode_t insn,
725725
*/
726726
enum probes_insn __kprobes
727727
arm_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
728-
const union decode_action *actions)
728+
bool emulate, const union decode_action *actions)
729729
{
730730
asi->insn_singlestep = arm_singlestep;
731731
asi->insn_check_cc = probes_condition_checks[insn>>28];
732732
return probes_decode_insn(insn, asi, probes_decode_arm_table, false,
733-
actions);
733+
emulate, actions);
734734
}

‎arch/arm/kernel/probes-arm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void __kprobes simulate_mov_ipsp(probes_opcode_t opcode,
6767
extern const union decode_item probes_decode_arm_table[];
6868

6969
enum probes_insn arm_probes_decode_insn(probes_opcode_t,
70-
struct arch_specific_insn *,
70+
struct arch_specific_insn *, bool emulate,
7171
const union decode_action *actions);
7272

7373
#endif

‎arch/arm/kernel/probes-thumb.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,20 +863,20 @@ static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
863863

864864
enum probes_insn __kprobes
865865
thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
866-
const union decode_action *actions)
866+
bool emulate, const union decode_action *actions)
867867
{
868868
asi->insn_singlestep = thumb16_singlestep;
869869
asi->insn_check_cc = thumb_check_cc;
870870
return probes_decode_insn(insn, asi, probes_decode_thumb16_table, true,
871-
actions);
871+
emulate, actions);
872872
}
873873

874874
enum probes_insn __kprobes
875875
thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
876-
const union decode_action *actions)
876+
bool emulate, const union decode_action *actions)
877877
{
878878
asi->insn_singlestep = thumb32_singlestep;
879879
asi->insn_check_cc = thumb_check_cc;
880880
return probes_decode_insn(insn, asi, probes_decode_thumb32_table, true,
881-
actions);
881+
emulate, actions);
882882
}

‎arch/arm/kernel/probes-thumb.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ extern const union decode_item probes_decode_thumb16_table[];
8989

9090
enum probes_insn __kprobes
9191
thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
92-
const union decode_action *actions);
92+
bool emulate, const union decode_action *actions);
9393
enum probes_insn __kprobes
9494
thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
95-
const union decode_action *actions);
95+
bool emulate, const union decode_action *actions);
9696

9797
#endif

‎arch/arm/kernel/probes.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ set_emulated_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
257257
* non-zero value, the corresponding nibble in pinsn is validated and modified
258258
* according to the type.
259259
*/
260-
static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs)
260+
static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs, bool modify)
261261
{
262262
probes_opcode_t insn = *pinsn;
263263
probes_opcode_t mask = 0xf; /* Start at least significant nibble */
@@ -323,7 +323,9 @@ static bool __kprobes decode_regs(probes_opcode_t *pinsn, u32 regs)
323323
insn |= new_bits & mask;
324324
}
325325

326-
*pinsn = insn;
326+
if (modify)
327+
*pinsn = insn;
328+
327329
return true;
328330

329331
reject:
@@ -385,13 +387,14 @@ static const int decode_struct_sizes[NUM_DECODE_TYPES] = {
385387
int __kprobes
386388
probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
387389
const union decode_item *table, bool thumb,
388-
const union decode_action *actions)
390+
bool emulate, const union decode_action *actions)
389391
{
390392
const struct decode_header *h = (struct decode_header *)table;
391393
const struct decode_header *next;
392394
bool matched = false;
393395

394-
insn = prepare_emulated_insn(insn, asi, thumb);
396+
if (emulate)
397+
insn = prepare_emulated_insn(insn, asi, thumb);
395398

396399
for (;; h = next) {
397400
enum decode_type type = h->type_regs.bits & DECODE_TYPE_MASK;
@@ -406,7 +409,7 @@ probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
406409
if (!matched && (insn & h->mask.bits) != h->value.bits)
407410
continue;
408411

409-
if (!decode_regs(&insn, regs))
412+
if (!decode_regs(&insn, regs, emulate))
410413
return INSN_REJECTED;
411414

412415
switch (type) {
@@ -430,6 +433,11 @@ probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
430433

431434
case DECODE_TYPE_EMULATE: {
432435
struct decode_emulate *d = (struct decode_emulate *)h;
436+
437+
if (!emulate)
438+
return actions[d->handler.action].decoder(insn,
439+
asi, h);
440+
433441
asi->insn_handler = actions[d->handler.action].handler;
434442
set_emulated_insn(insn, asi, thumb);
435443
return INSN_GOOD;

‎arch/arm/kernel/probes.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ probes_insn_handler_t probes_emulate_none;
401401

402402
int __kprobes
403403
probes_decode_insn(probes_opcode_t insn, struct arch_specific_insn *asi,
404-
const union decode_item *table, bool thumb,
404+
const union decode_item *table, bool thumb, bool emulate,
405405
const union decode_action *actions);
406406

407407
#endif

0 commit comments

Comments
 (0)