Skip to content

Commit 6105c5d

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: probes: Move kprobes-specific fields
We share struct arch_probe_insn between krpboes and uprobes, but most of its fields aren't necessary for uprobes: * The 'insn' field is only used by kprobes as a pointer to the XOL slot. * The 'restore' field is only used by probes as the PC to restore after stepping an instruction in the XOL slot. * The 'pstate_cc' field isn't used by kprobes or uprobes, and seems to only exist as a result of copy-pasting the 32-bit arm implementation of kprobes. As these fields live in struct arch_probe_insn they cannot use definitions that only exist when CONFIG_KPROBES=y, such as the kprobe_opcode_t typedef, which we'd like to use in subsequent patches. Clean this up by removing the 'pstate_cc' field, and moving the kprobes-specific fields into the kprobes-specific struct arch_specific_insn. To make it clear that the fields are related to stepping instructions in the XOL slot, 'insn' is renamed to 'xol_insn' and 'restore' is renamed to 'xol_restore' At the same time, remove the misleading and useless comment above struct arch_probe_insn. The should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 13f8f1e commit 6105c5d

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

arch/arm64/include/asm/probes.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
typedef u32 probe_opcode_t;
1313
typedef void (probes_handler_t) (u32 opcode, long addr, struct pt_regs *);
1414

15-
/* architecture specific copy of original instruction */
1615
struct arch_probe_insn {
17-
probe_opcode_t *insn;
18-
pstate_check_t *pstate_cc;
1916
probes_handler_t *handler;
20-
/* restore address after step xol */
21-
unsigned long restore;
2217
};
2318
#ifdef CONFIG_KPROBES
2419
typedef u32 kprobe_opcode_t;
2520
struct arch_specific_insn {
2621
struct arch_probe_insn api;
22+
probe_opcode_t *xol_insn;
23+
/* restore address after step xol */
24+
unsigned long xol_restore;
2725
};
2826
#endif
2927

arch/arm64/kernel/probes/kprobes.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
4343

4444
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
4545
{
46-
kprobe_opcode_t *addr = p->ainsn.api.insn;
46+
kprobe_opcode_t *addr = p->ainsn.xol_insn;
4747

4848
/*
4949
* Prepare insn slot, Mark Rutland points out it depends on a coupe of
@@ -70,14 +70,14 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
7070
/*
7171
* Needs restoring of return address after stepping xol.
7272
*/
73-
p->ainsn.api.restore = (unsigned long) p->addr +
73+
p->ainsn.xol_restore = (unsigned long) p->addr +
7474
sizeof(kprobe_opcode_t);
7575
}
7676

7777
static void __kprobes arch_prepare_simulate(struct kprobe *p)
7878
{
7979
/* This instructions is not executed xol. No need to adjust the PC */
80-
p->ainsn.api.restore = 0;
80+
p->ainsn.xol_restore = 0;
8181
}
8282

8383
static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
@@ -110,18 +110,18 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
110110
return -EINVAL;
111111

112112
case INSN_GOOD_NO_SLOT: /* insn need simulation */
113-
p->ainsn.api.insn = NULL;
113+
p->ainsn.xol_insn = NULL;
114114
break;
115115

116116
case INSN_GOOD: /* instruction uses slot */
117-
p->ainsn.api.insn = get_insn_slot();
118-
if (!p->ainsn.api.insn)
117+
p->ainsn.xol_insn = get_insn_slot();
118+
if (!p->ainsn.xol_insn)
119119
return -ENOMEM;
120120
break;
121121
}
122122

123123
/* prepare the instruction */
124-
if (p->ainsn.api.insn)
124+
if (p->ainsn.xol_insn)
125125
arch_prepare_ss_slot(p);
126126
else
127127
arch_prepare_simulate(p);
@@ -148,9 +148,9 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p)
148148

149149
void __kprobes arch_remove_kprobe(struct kprobe *p)
150150
{
151-
if (p->ainsn.api.insn) {
152-
free_insn_slot(p->ainsn.api.insn, 0);
153-
p->ainsn.api.insn = NULL;
151+
if (p->ainsn.xol_insn) {
152+
free_insn_slot(p->ainsn.xol_insn, 0);
153+
p->ainsn.xol_insn = NULL;
154154
}
155155
}
156156

@@ -205,9 +205,9 @@ static void __kprobes setup_singlestep(struct kprobe *p,
205205
}
206206

207207

208-
if (p->ainsn.api.insn) {
208+
if (p->ainsn.xol_insn) {
209209
/* prepare for single stepping */
210-
slot = (unsigned long)p->ainsn.api.insn;
210+
slot = (unsigned long)p->ainsn.xol_insn;
211211

212212
kprobes_save_local_irqflag(kcb, regs);
213213
instruction_pointer_set(regs, slot);
@@ -245,8 +245,8 @@ static void __kprobes
245245
post_kprobe_handler(struct kprobe *cur, struct kprobe_ctlblk *kcb, struct pt_regs *regs)
246246
{
247247
/* return addr restore if non-branching insn */
248-
if (cur->ainsn.api.restore != 0)
249-
instruction_pointer_set(regs, cur->ainsn.api.restore);
248+
if (cur->ainsn.xol_restore != 0)
249+
instruction_pointer_set(regs, cur->ainsn.xol_restore);
250250

251251
/* restore back original saved kprobe variables and continue */
252252
if (kcb->kprobe_status == KPROBE_REENTER) {
@@ -348,7 +348,7 @@ kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned long esr)
348348
struct kprobe *cur = kprobe_running();
349349

350350
if (cur && (kcb->kprobe_status & (KPROBE_HIT_SS | KPROBE_REENTER)) &&
351-
((unsigned long)&cur->ainsn.api.insn[1] == addr)) {
351+
((unsigned long)&cur->ainsn.xol_insn[1] == addr)) {
352352
kprobes_restore_local_irqflag(kcb, regs);
353353
post_kprobe_handler(cur, kcb, regs);
354354

0 commit comments

Comments
 (0)