Skip to contentSkip to conversation

uprobes: return probe implementation

RFC PATCH In review Anton Arapov 4 participants 15 messages Mar 4, 2013 – Mar 5, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover uprobes: return probe implementation

Hello,

RFC v4 uretprobes implementation. I'd be grateful for review. /* Oleg, this one is more quirky than previous, don't beat me. */

These patches extending uprobes by enabling tools, such as perf(trace_event),
set a breakpoint on probed function's return address.

v4:
- get rid of area->rp_trampoline_vaddr as it always the same as ->vaddr
- preallocate slot, as the first one in xol_add_vma()
- cleanup ->return_uprobes list in uprobe_free_utask(), because the task can exit from inside the ret-probe'd function(s).
- in find_active_uprobe(): Once we inserted "int3" we must ensure that handle_swbp() will be called even if this uprobe goes away. We have the reference but it only protects uprobe itself, it can't protect agains delete_uprobe().
IOW, we must ensure that uprobe_pre_sstep_notifier() can't return 0.
- check, whether utask is not NULL in handle_uretprobe()
? do we want a printk() for this case?
- minor handle_uretprobe() fixups

v3 changes:
- removed uretprobe_bypass logic, it will be better to send it as independent patch
- unified xol_get_trampoline_slot() and xol_get_insn_slot()
- protected uprobe with refcounter in prepare_uretprobe()
- uprobe_register() routine fails now, if neither consumer is set
- enclosed implementation into 1/6, 6/6 patches -ENOSYS bits

v2 changes:
- introduced rp_handler(), get rid of return_consumers
- get rid of uretprobe_[un]register()
- introduced arch_uretprobe_get_sp()
- removed uprobe_task->doomed, kill task immediately
- fix arch_uretprobe_hijack_return_addr()'s returns
- address the v1 minor issues

integrated patchset:
http://github.com/arapov/linux-aa/commits/uretprobes_v3

previous implementations:
RFCv3: https://lkml.org/lkml/2013/2/28/148
RFCv2: https://lkml.org/lkml/2013/1/9/157
RFCv1: https://lkml.org/lkml/2012/12/21/133

thanks,
Anton

Anton Arapov (6):
uretprobes: preparation patch uretprobes/x86: hijack return address
uretprobes: generalize xol_get_insn_slot()
uretprobes: return probe entry, prepare uretprobe
uretprobes: invoke return probe handlers
uretprobes: implemented, thus remove -ENOSYS

 arch/x86/include/asm/uprobes.h |   6 ++
 arch/x86/kernel/uprobes.c      |  29 +++++++++
 include/linux/uprobes.h        |   5 ++
 kernel/events/uprobes.c        | 134 ++++++++++++++++++++++++++++++++++++++---
 4 files changed, 166 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.1.2
#1 lore raw

RFC PATCH v4 1/6 uretprobes: preparation patch

1/6 and 6/6 patches are here to enclose return probes implementation as well
as prohibit uprobe_register() routine with no consumer set.

v3 changes: (the patch is introduced in v3)
- check whether at least one of the consumer's handlers were set
- a 'TODO' cap that will be removed once return probes be implemented

---
 include/linux/uprobes.h | 1 +
 kernel/events/uprobes.c | 8 ++++++++
 2 files changed, 9 insertions(+)
include/linux/uprobes.h +1 -0
index 02b83db..a28bdee 100644
@@ -46,6 +46,7 @@ enum uprobe_filter_ctx {
 
 struct uprobe_consumer {
 	int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
+	int (*rp_handler)(struct uprobe_consumer *self, struct pt_regs *regs);
 	bool (*filter)(struct uprobe_consumer *self,
 				enum uprobe_filter_ctx ctx,
 				struct mm_struct *mm);
kernel/events/uprobes.c +8 -0
index a567c8c..d904164 100644
@@ -828,6 +828,14 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *
 	struct uprobe *uprobe;
 	int ret;
 
+	/* Uprobe must have at least one set consumer */
+	if (!uc->handler && !uc->rp_handler)
+		return -EINVAL;
+
+	/* TODO: Implement return probes */
+	if (uc->rp_handler)
+		return -ENOSYS;
+
 	/* Racy, just to catch the obvious mistakes */
 	if (offset > i_size_read(inode))
 		return -EINVAL;
Signature · 1 line
1.8.1.2
#2 lore raw

RFC PATCH v4 2/6 uretprobes/x86: hijack return address

In reply to Anton Arapov

hijack the return address and replace it with a "trampoline"

v2:
- remove ->doomed flag, kill task immediately

---
 arch/x86/include/asm/uprobes.h |  1 +
 arch/x86/kernel/uprobes.c      | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
arch/x86/include/asm/uprobes.h +1 -0
index 8ff8be7..c353555 100644
@@ -55,4 +55,5 @@ extern int  arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
 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 rp_trampoline_vaddr, struct pt_regs *regs);
 #endif	/* _ASM_UPROBES_H */
arch/x86/kernel/uprobes.c +29 -0
index 0ba4cfb..85e2153 100644
@@ -697,3 +697,32 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
 		send_sig(SIGTRAP, current, 0);
 	return ret;
 }
+
+extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long
+		rp_trampoline_vaddr, struct pt_regs *regs)
+{
+	int rasize, ncopied;
+	unsigned long orig_ret_vaddr = 0; /* clear high bits for 32-bit apps */
+
+	rasize = is_ia32_task() ? 4 : 8;
+	ncopied = copy_from_user(&orig_ret_vaddr, (void __user *)regs->sp, rasize);
+	if (unlikely(ncopied))
+		return 0;
+
+	/* check whether address has been already hijacked */
+	if (orig_ret_vaddr == rp_trampoline_vaddr)
+		return orig_ret_vaddr;
+
+	ncopied = copy_to_user((void __user *)regs->sp, &rp_trampoline_vaddr, rasize);
+	if (unlikely(ncopied)) {
+		if (ncopied != rasize) {
+			printk(KERN_ERR "uretprobe: return address clobbered: "
+					"pid=%d, %%sp=%#lx, %%ip=%#lx\n",
+					current->pid, regs->sp, regs->ip);
+			/* kill task immediately */
+			send_sig(SIGSEGV, current, 0);
+		}
+	}
+
+	return orig_ret_vaddr;
+}
Signature · 1 line
1.8.1.2
#3 lore raw

RFC PATCH v4 3/6 uretprobes: generalize xol_get_insn_slot()

In reply to Anton Arapov

Generalize xol_take_insn_slot() to enable more consumers of the
function, e.g. trampoline implementation for return probes.

The first time a uprobe with return consumer is hit for a process, a
trampoline slot is obtained in the xol_area and initialized with a breakpoint instruction. This slot is subsequently used by all uretprobes.

v3:
- unified xol_get_insn_slot(), thus get rid of xol_get_trampoline_slot()

---
 kernel/events/uprobes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/uprobes.c +3 -3
index d904164..69bf060 100644
@@ -1221,7 +1221,7 @@ static unsigned long xol_take_insn_slot(struct xol_area *area)
  * xol_get_insn_slot - allocate a slot for xol.
  * Returns the allocated slot address or 0.
  */
-static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
+static unsigned long xol_get_insn_slot(unsigned char *insn)
 {
 	struct xol_area *area;
 	unsigned long offset;
@@ -1239,7 +1239,7 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
 	/* Initialize the slot */
 	offset = xol_vaddr & ~PAGE_MASK;
 	vaddr = kmap_atomic(area->page);
-	memcpy(vaddr + offset, uprobe->arch.insn, MAX_UINSN_BYTES);
+	memcpy(vaddr + offset, insn, MAX_UINSN_BYTES);
 	kunmap_atomic(vaddr);
 	/*
 	 * We probably need flush_icache_user_range() but it needs vma.
@@ -1353,7 +1353,7 @@ pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, unsigned long bp_vaddr)
 	if (!utask)
 		return -ENOMEM;
 
-	xol_vaddr = xol_get_insn_slot(uprobe);
+	xol_vaddr = xol_get_insn_slot(uprobe->arch.insn);
 	if (!xol_vaddr)
 		return -ENOMEM;
 
Signature · 1 line
1.8.1.2
#4 lore raw

RFC PATCH v4 4/6 uretprobes: return probe entry, prepare uretprobe

In reply to Anton Arapov

When a uprobe with return consumer is hit, prepare_uretprobe function is
invoked. It creates return_instance, hijacks return address and replaces it with the trampoline.

N.B. it might be a good idea to introduce get_uprobe() to reflect
put_uprobe() later, but it is not a subject of this patchset.

v4:
- get rid of area->rp_trampoline_vaddr as it always the same as ->vaddr
- preallocate slot, as the first one in xol_add_vma()
- cleanup ->return_uprobes list in uprobe_free_utask(), because the task can exit from inside the ret-probe'd function(s).
- in find_active_uprobe(): Once we inserted "int3" we must ensure that handle_swbp() will be called even if this uprobe goes away. We have the reference but it only protects uprobe itself, it can't protect agains delete_uprobe().
IOW, we must ensure that uprobe_pre_sstep_notifier() can't return 0.
v3:
- protected uprobe with refcounter. See atomic_inc in prepare_uretprobe()
and put_uprobe() in a following patch in handle_uretprobe() v2:
- get rid of ->return_consumers member from struct uprobe, introduce
rp_handler() in consumer

---
 include/linux/uprobes.h |  4 +++
 kernel/events/uprobes.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 68 insertions(+), 3 deletions(-)
include/linux/uprobes.h +4 -0
index a28bdee..6b0a309 100644
@@ -69,6 +69,10 @@ struct uprobe_task {
 	enum uprobe_task_state		state;
 	struct arch_uprobe_task		autask;
 
+	/*
+	 * list for tracking uprobes with return consumers
+	 */
+	struct hlist_head		return_uprobes;
 	struct uprobe			*active_uprobe;
 
 	unsigned long			xol_vaddr;
kernel/events/uprobes.c +64 -3

137 lines not on this page · raw message

Signature · 1 line
1.8.1.2
maintainer
#5 lore raw

Re: [RFC PATCH v4 4/6] uretprobes: return probe entry, prepare uretprobe

Quoted 10 lines · Anton Arapov
kernel/events/uprobes.c +1 -0
@@ -1085,6 +1093,7 @@ static int xol_add_vma(struct xol_area *area)
 {
 	struct mm_struct *mm = current->mm;
 	int ret = -EALREADY;
+	uprobe_opcode_t insn = UPROBE_SWBP_INSN;
 
 	down_write(&mm->mmap_sem);
 	if (mm->uprobes_state.xol_area)

kernel/events/uprobes.c static int xol_add_vma(struct xol_area *area) · line 1123

Quoted 9 lines
kernel/events/uprobes.c +6 -0
@@ -1106,6 +1115,13 @@ static int xol_add_vma(struct xol_area *area)
 	smp_wmb();	/* pairs with get_xol_area() */
 	mm->uprobes_state.xol_area = area;
 	ret = 0;
+
+	/*
+	 * If we reached this place, we did allocate a new area. We want
+	 * pre-alloc a slot for the return probes here.
+	 */
+	xol_get_insn_slot(&insn);

Just change get_xol_area() to do set_bit(0, bitmap) and copy_to_page(page, int3) (extacted from xol_get_insn_slot().

kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1544

Quoted 9 lines
kernel/events/uprobes.c +3 -1
@@ -1485,8 +1538,11 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp)
 		*is_swbp = -EFAULT;
 	}
 
-	if (!uprobe && test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags))
+	utask = get_utask();
+	if (!uprobe && hlist_empty(&utask->return_uprobes) &&
+	    test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags)) {
 		mmf_recalc_uprobes(mm);

Wait, I was wrong. We should not clear MMF_* if another thread has ->return_uprobes. Perhaps we should change uprobe_pre_sstep_notifier() instead...

kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1563

Quoted 8 lines
kernel/events/uprobes.c +5 -1
 	down_read(&uprobe->register_rwsem);
 	for (uc = uprobe->consumers; uc; uc = uc->next) {
-		int rc = uc->handler(uc, regs);
+		if (uc->handler)
+			rc = uc->handler(uc, regs);
+
+		if (uc->rp_handler)
+			prepare_uretprobe(uprobe, regs); /* put bp at return */

Again, this is not right. We should do this only once after the main loop.

Oleg.

#6 lore raw

Re: [RFC PATCH v4 4/6] uretprobes: return probe entry, prepare uretprobe

Quoted 8 lines · Oleg Nesterov
Quoted 7 lines · Anton Arapov
kernel/events/uprobes.c +1 -0
@@ -1085,6 +1093,7 @@ static int xol_add_vma(struct xol_area *area)
 {
 	struct mm_struct *mm = current->mm;
 	int ret = -EALREADY;
+	uprobe_opcode_t insn = UPROBE_SWBP_INSN;
 
Quoted 14 lines

kernel/events/uprobes.c static int xol_add_vma(struct xol_area *area) · line 1123

Quoted 12 lines
kernel/events/uprobes.c +6 -0
 	down_write(&mm->mmap_sem);
 	if (mm->uprobes_state.xol_area)
@@ -1106,6 +1115,13 @@ static int xol_add_vma(struct xol_area *area)
 	smp_wmb();	/* pairs with get_xol_area() */
 	mm->uprobes_state.xol_area = area;
 	ret = 0;
+
+	/*
+	 * If we reached this place, we did allocate a new area. We want
+	 * pre-alloc a slot for the return probes here.
+	 */
+	xol_get_insn_slot(&insn);

Just change get_xol_area() to do set_bit(0, bitmap) and copy_to_page(page, int3) (extacted from xol_get_insn_slot().

ah yes, right. Thanks for this hint.

Quoted 5 lines
Quoted 5 lines
kernel/events/uprobes.c +0 -0
@@ -1485,8 +1538,11 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp)
 		*is_swbp = -EFAULT;
 	}
 
Quoted 8 lines

kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1544

Quoted 5 lines
kernel/events/uprobes.c +3 -1
-	if (!uprobe && test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags))
+	utask = get_utask();
+	if (!uprobe && hlist_empty(&utask->return_uprobes) &&
+	    test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags)) {
 		mmf_recalc_uprobes(mm);

Wait, I was wrong. We should not clear MMF_* if another thread has ->return_uprobes. Perhaps we should change uprobe_pre_sstep_notifier() instead...

Will look into it.

Quoted 10 lines

kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1563

Quoted 8 lines
kernel/events/uprobes.c +5 -1
 	down_read(&uprobe->register_rwsem);
 	for (uc = uprobe->consumers; uc; uc = uc->next) {
-		int rc = uc->handler(uc, regs);
+		if (uc->handler)
+			rc = uc->handler(uc, regs);
+
+		if (uc->rp_handler)
+			prepare_uretprobe(uprobe, regs); /* put bp at return */

Again, this is not right. We should do this only once after the main loop.

fixed for v5.

Thanks!
Anton.

#7 lore raw

RFC PATCH v4 5/6 uretprobes: invoke return probe handlers

In reply to Anton Arapov

Uretprobe handlers are invoked when the trampoline is hit, on completion the
trampoline is replaced with the saved return address and the uretprobe instance deleted.

v4:
- check, whether utask is not NULL in handle_uretprobe()
? do we want a printk() for this case?
- get rid of area->rp_trampoline_vaddr
- minor handle_uretprobe() fixups
v3:
- protected uprobe with refcounter. See put_uprobe() in handle_uretprobe()
that reflects increment in prepare_uretprobe()
v2:
- get rid of ->return_consumers member from struct uprobe, introduce
rp_handler() in consumer instead

---
 arch/x86/include/asm/uprobes.h |  5 ++++
 kernel/events/uprobes.c        | 57 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 60 insertions(+), 2 deletions(-)
arch/x86/include/asm/uprobes.h +5 -0
index c353555..fa9d9de 100644
@@ -56,4 +56,9 @@ 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 rp_trampoline_vaddr, struct pt_regs *regs);
+
+static inline unsigned long arch_uretprobe_get_sp(struct pt_regs *regs)
+{
+	return (unsigned long)regs->sp;
+}
 #endif	/* _ASM_UPROBES_H */
kernel/events/uprobes.c +55 -2

75 lines not on this page · raw message

Signature · 1 line
1.8.1.2
maintainer
#8 lore raw

Re: [RFC PATCH v4 5/6] uretprobes: invoke return probe handlers

Quoted 10 lines · Anton Arapov
kernel/events/uprobes.c +9 -0
+static void handle_uretprobe(struct xol_area *area, struct pt_regs *regs)
+{
+	struct hlist_head *head;
+	struct hlist_node *tmp;
+	struct return_uprobe_i *ri;
+	struct uprobe_task *utask;
+	unsigned long orig_ret_vaddr;
+
+	/* TODO: uretprobe bypass logic */

kernel/events/uprobes.c static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) · line 1607

Quoted 10 lines
kernel/events/uprobes.c +10 -0
+
+	utask = get_utask();
+	if (!utask) {
+		/* TODO:RFC task is not probed, do we want printk here? */
+		return;
+	}
+	head = &utask->return_uprobes;
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->uprobe->consumers) {
+			instruction_pointer_set(regs, ri->orig_ret_vaddr);

This doesn't look right if ri->orig_ret_vaddr == area->vaddr. We should splice the list and find orig_ret_vaddr in advance.

kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 1646

Quoted 11 lines
kernel/events/uprobes.c +5 -2
@@ -1589,8 +1639,11 @@ static void handle_swbp(struct pt_regs *regs)
 
 	if (!uprobe) {
 		if (is_swbp > 0) {
-			/* No matching uprobe; signal SIGTRAP. */
-			send_sig(SIGTRAP, current, 0);
+			area = get_xol_area();
+			if (area && bp_vaddr == area->vaddr)
+				handle_uretprobe(area, regs);
+			else
+				send_sig(SIGTRAP, current, 0);

Why? We can check bp_vaddr at the start, before find_active_uprobe().

And I'd suggest to not use area->vaddr directly, imho a trivial helper makes sense.

Oleg.

#9 lore raw

Re: [RFC PATCH v4 5/6] uretprobes: invoke return probe handlers

Quoted 15 lines · Oleg Nesterov
Quoted 14 lines · Anton Arapov
kernel/events/uprobes.c +13 -0
+static void handle_uretprobe(struct xol_area *area, struct pt_regs *regs)
+{
+	struct hlist_head *head;
+	struct hlist_node *tmp;
+	struct return_uprobe_i *ri;
+	struct uprobe_task *utask;
+	unsigned long orig_ret_vaddr;
+
+	/* TODO: uretprobe bypass logic */
+
+	utask = get_utask();
+	if (!utask) {
+		/* TODO:RFC task is not probed, do we want printk here? */
Quoted 8 lines

kernel/events/uprobes.c static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) · line 1607

Quoted 6 lines
kernel/events/uprobes.c +6 -0
+		return;
+	}
+	head = &utask->return_uprobes;
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->uprobe->consumers) {
+			instruction_pointer_set(regs, ri->orig_ret_vaddr);

This doesn't look right if ri->orig_ret_vaddr == area->vaddr. We should splice the list and find orig_ret_vaddr in advance.

True, this cycle is buggy. I will rework handle_uretprobe().

Quoted 13 lines

kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 1646

Quoted 11 lines
kernel/events/uprobes.c +5 -2
@@ -1589,8 +1639,11 @@ static void handle_swbp(struct pt_regs *regs)
 
 	if (!uprobe) {
 		if (is_swbp > 0) {
-			/* No matching uprobe; signal SIGTRAP. */
-			send_sig(SIGTRAP, current, 0);
+			area = get_xol_area();
+			if (area && bp_vaddr == area->vaddr)
+				handle_uretprobe(area, regs);
+			else
+				send_sig(SIGTRAP, current, 0);

Why? We can check bp_vaddr at the start, before find_active_uprobe().

For some reason, I was thinking it is better to hide this logic under if (!uprobe). Will correct this chunk.

Quoted 2 lines

And I'd suggest to not use area->vaddr directly, imho a trivial helper makes sense.

I see the idea behind, with this change it will be more clear and fragile in case someone change the underneath logic. Will do this.

thank you very much!
Anton.

#10 lore raw

Re: [RFC PATCH v4 5/6] uretprobes: invoke return probe handlers

In reply to Anton Arapov
Quoted 6 lines · Anton Arapov
arch/x86/include/asm/uprobes.h +0 -0
index c353555..fa9d9de 100644

arch/x86/include/asm/uprobes.h extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk); · line 63

Quoted 8 lines
arch/x86/include/asm/uprobes.h +5 -0
@@ -56,4 +56,9 @@ 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 rp_trampoline_vaddr, struct pt_regs *regs);
+
+static inline unsigned long arch_uretprobe_get_sp(struct pt_regs *regs)
+{
+	return (unsigned long)regs->sp;
+}

You could use GET_USP() here.

#11 lore raw

Re: [RFC PATCH v4 5/6] uretprobes: invoke return probe handlers

Quoted 17 lines · Ananth N Mavinakayanahalli
Quoted 6 lines · Anton Arapov
arch/x86/include/asm/uprobes.h +0 -0
index c353555..fa9d9de 100644

arch/x86/include/asm/uprobes.h extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk); · line 63

Quoted 8 lines
arch/x86/include/asm/uprobes.h +5 -0
@@ -56,4 +56,9 @@ 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 rp_trampoline_vaddr, struct pt_regs *regs);
+
+static inline unsigned long arch_uretprobe_get_sp(struct pt_regs *regs)
+{
+	return (unsigned long)regs->sp;
+}

You could use GET_USP() here.

perhaps, which in turn is a helper for user_stack_pointer() :) comment is valid though.

thanks,
Anton.

#12 lore raw

RFC PATCH v4 6/6 uretprobes: implemented, thus remove -ENOSYS

In reply to Anton Arapov

1/6 and 6/6 patches are here to enclose return probes implementation
as well as prohibit uprobe_register() routine with no consumer set.

v3 changes: (the patch is introduced in v3)
- remove 'TODO' as return probes implemented now

---
 kernel/events/uprobes.c | 4 ----
 1 file changed, 4 deletions(-)
kernel/events/uprobes.c +0 -4
index e86b6ea..b9c51dc 100644
@@ -840,10 +840,6 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *
 	if (!uc->handler && !uc->rp_handler)
 		return -EINVAL;
 
-	/* TODO: Implement return probes */
-	if (uc->rp_handler)
-		return -ENOSYS;
-
 	/* Racy, just to catch the obvious mistakes */
 	if (offset > i_size_read(inode))
 		return -EINVAL;
Signature · 1 line
1.8.1.2
#13 lore raw
In reply to Anton Arapov
Quoted 4 lines · Anton Arapov

Hello,

RFC v4 uretprobes implementation. I'd be grateful for review. /* Oleg, this one is more quirky than previous, don't beat me. */

Please include a good high level description of the new feature in one of the patches - preferably also stick it somewhere into Documentation/.

Thanks,

Ingo

#14 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Anton Arapov

Hello,

RFC v4 uretprobes implementation. I'd be grateful for review. /* Oleg, this one is more quirky than previous, don't beat me. */

Please include a good high level description of the new feature in one of the patches - preferably also stick it somewhere into Documentation/.

Yes, I apologize, I did wait for someone's complaint to push myself to
write meaningful description.

thanks,
Anton

Quoted 3 lines

Thanks,

Ingo