[PATCH 5/9] uprobes: add arch write opcode hook

From: David Long
Date: Thu Aug 01 2013 - 19:47:18 EST


From: "David A. Long" <dave.long@xxxxxxxxxx>

Allow arches to write the opcode with a custom function. ARM needs to
customize the swbp instruction depending on the condition code of the
instruction it replaces.

Signed-off-by: Rabin Vincent <rabin@xxxxxx>
Signed-off-by: David A. Long <dave.long@xxxxxxxxxx>
---
include/linux/uprobes.h | 3 +++
kernel/events/uprobes.c | 20 +++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
index 6feae5d..9cd3b25 100644
--- a/include/linux/uprobes.h
+++ b/include/linux/uprobes.h
@@ -136,6 +136,9 @@ extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs)
extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
extern void __weak arch_uprobe_xol_copy(struct arch_uprobe *auprobe, void *vaddr);
extern int __weak arch_uprobes_init(void);
+extern void __weak arch_uprobe_write_opcode(struct arch_uprobe *auprobe,
+ void *vaddr,
+ uprobe_opcode_t opcode);
#else /* !CONFIG_UPROBES */
struct uprobes_state {
};
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 5004f6f..6a60eec 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -248,6 +248,12 @@ static int verify_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t
* have fixed length instructions.
*/

+void __weak arch_uprobe_write_opcode(struct arch_uprobe *auprobe, void *vaddr,
+ uprobe_opcode_t opcode)
+{
+ memcpy(vaddr, &opcode, UPROBE_SWBP_INSN_SIZE);
+}
+
/*
* write_opcode - write the opcode at a given virtual address.
* @mm: the probed process address space.
@@ -260,8 +266,8 @@ static int verify_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t
* For mm @mm, write the opcode at @vaddr.
* Return 0 (success) or a negative errno.
*/
-static int write_opcode(struct mm_struct *mm, unsigned long vaddr,
- uprobe_opcode_t opcode)
+static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
+ unsigned long vaddr, uprobe_opcode_t opcode)
{
struct page *old_page, *new_page;
struct vm_area_struct *vma;
@@ -285,7 +291,10 @@ retry:
__SetPageUptodate(new_page);

copy_highpage(new_page, old_page);
- copy_to_page(new_page, vaddr, &opcode, UPROBE_SWBP_INSN_SIZE);
+ vaddr_new = kmap_atomic(new_page);
+ arch_uprobe_write_opcode(auprobe, vaddr_new + (vaddr & ~PAGE_MASK),
+ opcode);
+ kunmap_atomic(vaddr_new);

ret = anon_vma_prepare(vma);
if (ret)
@@ -314,7 +323,7 @@ put_old:
*/
int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
{
- return write_opcode(mm, vaddr, UPROBE_SWBP_INSN);
+ return write_opcode(auprobe, mm, vaddr, UPROBE_SWBP_INSN);
}

/**
@@ -329,7 +338,8 @@ int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned
int __weak
set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
{
- return write_opcode(mm, vaddr, *(uprobe_opcode_t *)auprobe->insn);
+ return write_opcode(auprobe, mm, vaddr,
+ *(uprobe_opcode_t *)auprobe->insn);
}

static int match_uprobe(struct uprobe *l, struct uprobe *r)
--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/