]> Git Repo - linux.git/commitdiff
arm64: probes: Move kprobes-specific fields
authorMark Rutland <[email protected]>
Tue, 8 Oct 2024 15:58:49 +0000 (16:58 +0100)
committerCatalin Marinas <[email protected]>
Tue, 15 Oct 2024 17:16:19 +0000 (18:16 +0100)
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]>
arch/arm64/include/asm/probes.h
arch/arm64/kernel/probes/kprobes.c

index 006946745352ef348d1d9f1525edf230abeee911..4aa54322794dae375d19d2dfd9eb7dcb006b1089 100644 (file)
 typedef u32 probe_opcode_t;
 typedef void (probes_handler_t) (u32 opcode, long addr, struct pt_regs *);
 
-/* architecture specific copy of original instruction */
 struct arch_probe_insn {
-       probe_opcode_t *insn;
-       pstate_check_t *pstate_cc;
        probes_handler_t *handler;
-       /* restore address after step xol */
-       unsigned long restore;
 };
 #ifdef CONFIG_KPROBES
 typedef u32 kprobe_opcode_t;
 struct arch_specific_insn {
        struct arch_probe_insn api;
+       probe_opcode_t *xol_insn;
+       /* restore address after step xol */
+       unsigned long xol_restore;
 };
 #endif
 
index 4268678d0e86cc6cb3c25f13c2ab087a41876f76..222419a41a400d28ad158837005c4a51d93b6b97 100644 (file)
@@ -43,7 +43,7 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
 
 static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
 {
-       kprobe_opcode_t *addr = p->ainsn.api.insn;
+       kprobe_opcode_t *addr = p->ainsn.xol_insn;
 
        /*
         * 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)
        /*
         * Needs restoring of return address after stepping xol.
         */
-       p->ainsn.api.restore = (unsigned long) p->addr +
+       p->ainsn.xol_restore = (unsigned long) p->addr +
          sizeof(kprobe_opcode_t);
 }
 
 static void __kprobes arch_prepare_simulate(struct kprobe *p)
 {
        /* This instructions is not executed xol. No need to adjust the PC */
-       p->ainsn.api.restore = 0;
+       p->ainsn.xol_restore = 0;
 }
 
 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)
                return -EINVAL;
 
        case INSN_GOOD_NO_SLOT: /* insn need simulation */
-               p->ainsn.api.insn = NULL;
+               p->ainsn.xol_insn = NULL;
                break;
 
        case INSN_GOOD: /* instruction uses slot */
-               p->ainsn.api.insn = get_insn_slot();
-               if (!p->ainsn.api.insn)
+               p->ainsn.xol_insn = get_insn_slot();
+               if (!p->ainsn.xol_insn)
                        return -ENOMEM;
                break;
        }
 
        /* prepare the instruction */
-       if (p->ainsn.api.insn)
+       if (p->ainsn.xol_insn)
                arch_prepare_ss_slot(p);
        else
                arch_prepare_simulate(p);
@@ -148,9 +148,9 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p)
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
-       if (p->ainsn.api.insn) {
-               free_insn_slot(p->ainsn.api.insn, 0);
-               p->ainsn.api.insn = NULL;
+       if (p->ainsn.xol_insn) {
+               free_insn_slot(p->ainsn.xol_insn, 0);
+               p->ainsn.xol_insn = NULL;
        }
 }
 
@@ -205,9 +205,9 @@ static void __kprobes setup_singlestep(struct kprobe *p,
        }
 
 
-       if (p->ainsn.api.insn) {
+       if (p->ainsn.xol_insn) {
                /* prepare for single stepping */
-               slot = (unsigned long)p->ainsn.api.insn;
+               slot = (unsigned long)p->ainsn.xol_insn;
 
                kprobes_save_local_irqflag(kcb, regs);
                instruction_pointer_set(regs, slot);
@@ -245,8 +245,8 @@ static void __kprobes
 post_kprobe_handler(struct kprobe *cur, struct kprobe_ctlblk *kcb, struct pt_regs *regs)
 {
        /* return addr restore if non-branching insn */
-       if (cur->ainsn.api.restore != 0)
-               instruction_pointer_set(regs, cur->ainsn.api.restore);
+       if (cur->ainsn.xol_restore != 0)
+               instruction_pointer_set(regs, cur->ainsn.xol_restore);
 
        /* restore back original saved kprobe variables and continue */
        if (kcb->kprobe_status == KPROBE_REENTER) {
@@ -348,7 +348,7 @@ kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned long esr)
        struct kprobe *cur = kprobe_running();
 
        if (cur && (kcb->kprobe_status & (KPROBE_HIT_SS | KPROBE_REENTER)) &&
-           ((unsigned long)&cur->ainsn.api.insn[1] == addr)) {
+           ((unsigned long)&cur->ainsn.xol_insn[1] == addr)) {
                kprobes_restore_local_irqflag(kcb, regs);
                post_kprobe_handler(cur, kcb, regs);
 
This page took 0.082685 seconds and 4 git commands to generate.