Skip to contentSkip to conversation

powerpc: Add trap_nr to thread_struct

PATCH New Ananth N Mavinakayanahalli 4 participants 12 messages Jul 26, 2012 – Aug 22, 2012

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

PATCH 1/2 powerpc: Add trap_nr to thread_struct

From: Ananth N Mavinakayanahalli <[email protected]>

Add thread_struct.trap_nr and use it to store the last exception the thread experienced. In this patch, we populate the field at various places where we force_sig_info() to the process.

This is also used in uprobes to determine if the probed instruction caused an exception.

Patch applies on the current master branch of Linus' tree (bdc0077af)

---
 arch/powerpc/include/asm/processor.h |    1 +
 arch/powerpc/kernel/process.c        |    2 ++
 arch/powerpc/kernel/traps.c          |    1 +
 arch/powerpc/mm/fault.c              |    1 +
 4 files changed, 5 insertions(+)
arch/powerpc/include/asm/processor.h +1 -0
Index: linux-26jul/arch/powerpc/include/asm/processor.h
===================================================================
@@ -219,6 +219,7 @@ struct thread_struct {
 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
 #endif
 	unsigned long	dabr;		/* Data address breakpoint register */
+	unsigned long	trap_nr;	/* last trap # on this thread */
 #ifdef CONFIG_ALTIVEC
 	/* Complete AltiVec register set */
 	vector128	vr[32] __attribute__((aligned(16)));
arch/powerpc/kernel/process.c +2 -0
Index: linux-26jul/arch/powerpc/kernel/process.c
===================================================================
@@ -258,6 +258,7 @@ void do_send_trap(struct pt_regs *regs, 
 {
 	siginfo_t info;
 
+	current->thread.trap_nr = signal_code;
 	if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code,
 			11, SIGSEGV) == NOTIFY_STOP)
 		return;
@@ -275,6 +276,7 @@ void do_dabr(struct pt_regs *regs, unsig
 {
 	siginfo_t info;
 
+	current->thread.trap_nr = TRAP_HWBKPT;
 	if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code,
 			11, SIGSEGV) == NOTIFY_STOP)
 		return;
arch/powerpc/kernel/traps.c +1 -0
Index: linux-26jul/arch/powerpc/kernel/traps.c
===================================================================
@@ -251,6 +251,7 @@ void _exception(int signr, struct pt_reg
 	if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs))
 		local_irq_enable();
 
+	current->thread.trap_nr = code;
 	memset(&info, 0, sizeof(info));
 	info.si_signo = signr;
 	info.si_code = code;
arch/powerpc/mm/fault.c +1 -0
Index: linux-26jul/arch/powerpc/mm/fault.c
===================================================================
@@ -133,6 +133,7 @@ static int do_sigbus(struct pt_regs *reg
 	up_read(&current->mm->mmap_sem);
 
 	if (user_mode(regs)) {
+		current->thread.trap_nr = BUS_ADRERR;
 		info.si_signo = SIGBUS;
 		info.si_errno = 0;
 		info.si_code = BUS_ADRERR;
#1 lore raw

PATCH v3 2/2 powerpc: Uprobes port to powerpc

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

[root@xxxx ~]# ./bin/perf probe -x /lib64/libc.so.6 malloc Added new event:
probe_libc:malloc (on 0xb4860)

You can now use it in all perf tools, such as:

perf record -e probe_libc:malloc -aR sleep 1

[root@xxxx ~]# ./bin/perf record -e probe_libc:malloc -aR sleep 20 [ perf record: Woken up 22 times to write data ]
[ perf record: Captured and wrote 5.843 MB perf.data (~255302 samples) ] [root@xxxx ~]# ./bin/perf report --stdio
...

# Samples: 83K of event 'probe_libc:malloc'
# Event count (approx.): 83484
#
# Overhead Command Shared Object Symbol

# ........  ............  .............  ..........
#
    69.05%           tar  libc-2.12.so   [.] malloc
    28.57%            rm  libc-2.12.so   [.] malloc
     1.32%  avahi-daemon  libc-2.12.so   [.] malloc
     0.58%          bash  libc-2.12.so   [.] malloc
     0.28%          sshd  libc-2.12.so   [.] malloc
     0.08%    irqbalance  libc-2.12.so   [.] malloc
     0.05%         bzip2  libc-2.12.so   [.] malloc
     0.04%         sleep  libc-2.12.so   [.] malloc
     0.03%    multipathd  libc-2.12.so   [.] malloc
     0.01%      sendmail  libc-2.12.so   [.] malloc
     0.01%     automount  libc-2.12.so   [.] malloc

Patch applies on the current master branch of Linus' tree (bdc0077af). The trap_nr addition patch is a prereq.

---

Tested on POWER6; I don't see anything here that should stop it from working on a ppc32; since I don't have access to a ppc32 machine, it would be good if somoene could verify that part.

V3:
Added abort_xol() logic for powerpc, using thread_struct.trap_nr to determine if the stepped instruction caused an exception.

V2:
a. arch_uprobe_analyze_insn() now gets unsigned long addr. b. Verified that mtmsr[d] and rfi[d] are handled correctly by
emulate_step() (no changes to this patch).

 arch/powerpc/Kconfig                   |    3 
 arch/powerpc/include/asm/thread_info.h |    4 
 arch/powerpc/include/asm/uprobes.h     |   50 +++++++++
 arch/powerpc/kernel/Makefile           |    1 
 arch/powerpc/kernel/signal.c           |    6 +
 arch/powerpc/kernel/uprobes.c          |  174 +++++++++++++++++++++++++++++++++
 6 files changed, 237 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/thread_info.h +3 -1
Index: linux-26jul/arch/powerpc/include/asm/thread_info.h
===================================================================
@@ -102,6 +102,7 @@ static inline struct thread_info *curren
 #define TIF_RESTOREALL		11	/* Restore all regs (implies NOERROR) */
 #define TIF_NOERROR		12	/* Force successful syscall return */
 #define TIF_NOTIFY_RESUME	13	/* callback before returning to user */
+#define TIF_UPROBE		14	/* breakpointed or single-stepping */
 #define TIF_SYSCALL_TRACEPOINT	15	/* syscall tracepoint instrumentation */
 
 /* as above, but as bit values */
@@ -118,12 +119,13 @@ static inline struct thread_info *curren
 #define _TIF_RESTOREALL		(1<<TIF_RESTOREALL)
 #define _TIF_NOERROR		(1<<TIF_NOERROR)
 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
+#define _TIF_UPROBE		(1<<TIF_UPROBE)
 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SYSCALL_T_OR_A	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
 				 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
 
 #define _TIF_USER_WORK_MASK	(_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
-				 _TIF_NOTIFY_RESUME)
+				 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
 #define _TIF_PERSYSCALL_MASK	(_TIF_RESTOREALL|_TIF_NOERROR)
 
 /* Bits in local_flags */
arch/powerpc/include/asm/uprobes.h new file +50 -0

50 lines not on this page · raw message

arch/powerpc/kernel/Makefile +1 -0
Index: linux-26jul/arch/powerpc/kernel/Makefile
===================================================================
@@ -96,6 +96,7 @@ obj-$(CONFIG_MODULES)		+= ppc_ksyms.o
 obj-$(CONFIG_BOOTX_TEXT)	+= btext.o
 obj-$(CONFIG_SMP)		+= smp.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
+obj-$(CONFIG_UPROBES)		+= uprobes.o
 obj-$(CONFIG_PPC_UDBG_16550)	+= legacy_serial.o udbg_16550.o
 obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-$(CONFIG_SWIOTLB)		+= dma-swiotlb.o
arch/powerpc/kernel/signal.c +6 -0
Index: linux-26jul/arch/powerpc/kernel/signal.c
===================================================================
@@ -11,6 +11,7 @@
 
 #include <linux/tracehook.h>
 #include <linux/signal.h>
+#include <linux/uprobes.h>
 #include <linux/key.h>
 #include <asm/hw_breakpoint.h>
 #include <asm/uaccess.h>
@@ -157,6 +158,11 @@ static int do_signal(struct pt_regs *reg
 
 void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
 {
+	if (thread_info_flags & _TIF_UPROBE) {
+		clear_thread_flag(TIF_UPROBE);
+		uprobe_notify_resume(regs);
+	}
+
 	if (thread_info_flags & _TIF_SIGPENDING)
 		do_signal(regs);
 
arch/powerpc/kernel/uprobes.c new file +174 -0

174 lines not on this page · raw message

arch/powerpc/Kconfig +3 -0
Index: linux-26jul/arch/powerpc/Kconfig
===================================================================
@@ -237,6 +237,9 @@ config PPC_OF_PLATFORM_PCI
 config ARCH_SUPPORTS_DEBUG_PAGEALLOC
 	def_bool y
 
+config ARCH_SUPPORTS_UPROBES
+	def_bool y
+
 config PPC_ADV_DEBUG_REGS
 	bool
 	depends on 40x || BOOKE
Acked-by on v3 2/2
#2 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 36 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

[root@xxxx ~]# ./bin/perf probe -x /lib64/libc.so.6 malloc Added new event:
probe_libc:malloc (on 0xb4860)

You can now use it in all perf tools, such as:

perf record -e probe_libc:malloc -aR sleep 1

[root@xxxx ~]# ./bin/perf record -e probe_libc:malloc -aR sleep 20 [ perf record: Woken up 22 times to write data ]
[ perf record: Captured and wrote 5.843 MB perf.data (~255302 samples) ] [root@xxxx ~]# ./bin/perf report --stdio
...

# Samples: 83K of event 'probe_libc:malloc'
# Event count (approx.): 83484
#
# Overhead Command Shared Object Symbol

# ........  ............  .............  ..........
#
    69.05%           tar  libc-2.12.so   [.] malloc
    28.57%            rm  libc-2.12.so   [.] malloc
     1.32%  avahi-daemon  libc-2.12.so   [.] malloc
     0.58%          bash  libc-2.12.so   [.] malloc
     0.28%          sshd  libc-2.12.so   [.] malloc
     0.08%    irqbalance  libc-2.12.so   [.] malloc
     0.05%         bzip2  libc-2.12.so   [.] malloc
     0.04%         sleep  libc-2.12.so   [.] malloc
     0.03%    multipathd  libc-2.12.so   [.] malloc
     0.01%      sendmail  libc-2.12.so   [.] malloc
     0.01%     automount  libc-2.12.so   [.] malloc
Quoted 4 lines

Patch applies on the current master branch of Linus' tree (bdc0077af). The trap_nr addition patch is a prereq.

maintainer
#3 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

In reply to Ananth N Mavinakayanahalli
Quoted 4 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

I am just curious why this series was ignored by powerpc maintainers...

Of course I can not review this code, I know nothing about powerpc, but the patches look simple/straightforward.

Paul, Benjamin?

Just one question... Shouldn't arch_uprobe_pre_xol() forbid to probe UPROBE_SWBP_INSN (at least) ?

(I assume that emulate_step() can't handle this case but of course I
do not understand arch/powerpc/lib/sstep.c)

Note that uprobe_pre_sstep_notifier() sets utask->state = UTASK_BP_HIT without any checks. This doesn't look right if it was UTASK_SSTEP...

But again, I do not know what powepc will actually do if we try to single-step over UPROBE_SWBP_INSN.

Oleg.

#4 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 7 lines · Oleg Nesterov
Quoted 4 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

I am just curious why this series was ignored by powerpc maintainers...

Because it arrived too late for the previous merge window considering my limited bandwidth for reviewing things and that nobody else seems to have reviewed it :-)

It's still on track for the next one, and I'm hoping to dedicate most of next week going through patches & doing a powerpc -next.

Quoted 8 lines

Of course I can not review this code, I know nothing about powerpc, but the patches look simple/straightforward.

Paul, Benjamin?

Just one question... Shouldn't arch_uprobe_pre_xol() forbid to probe UPROBE_SWBP_INSN (at least) ?

Quoted 8 lines

(I assume that emulate_step() can't handle this case but of course I
do not understand arch/powerpc/lib/sstep.c)

Note that uprobe_pre_sstep_notifier() sets utask->state = UTASK_BP_HIT without any checks. This doesn't look right if it was UTASK_SSTEP...

But again, I do not know what powepc will actually do if we try to single-step over UPROBE_SWBP_INSN.

Ananth ?

Cheers,
Ben.

#5 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 7 lines · Benjamin Herrenschmidt
Quoted 6 lines · Oleg Nesterov
Quoted 4 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

Quoted 8 lines
Quoted 1 line

I am just curious why this series was ignored by powerpc maintainers...

Because it arrived too late for the previous merge window considering my limited bandwidth for reviewing things and that nobody else seems to have reviewed it :-)

It's still on track for the next one, and I'm hoping to dedicate most of next week going through patches & doing a powerpc -next.

Thanks Ben!

Quoted 11 lines
Quoted 11 lines

Of course I can not review this code, I know nothing about powerpc, but the patches look simple/straightforward.

Paul, Benjamin?

Just one question... Shouldn't arch_uprobe_pre_xol() forbid to probe UPROBE_SWBP_INSN (at least) ?

(I assume that emulate_step() can't handle this case but of course I
do not understand arch/powerpc/lib/sstep.c)

Quoted 7 lines
Quoted 5 lines

Note that uprobe_pre_sstep_notifier() sets utask->state = UTASK_BP_HIT without any checks. This doesn't look right if it was UTASK_SSTEP...

But again, I do not know what powepc will actually do if we try to single-step over UPROBE_SWBP_INSN.

Ananth ?

set_swbp() will return -EEXIST to install_breakpoint if we are trying to put a breakpoint on UPROBE_SWBP_INSN. So, the arch agnostic code itself takes care of this case... or am I missing something?

However, I see that we need a powerpc specific is_swbp_insn() implementation since we will have to take care of all the trap variants.

I will need to update the patches based on changes being made by Oleg and Sebastien for the single-step issues. Will incorporate the powerpc specific is_swbp_insn() change along with the changes required for the single-step part and send out the next version.

Ananth

maintainer
#6 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 11 lines · Ananth N Mavinakayanahalli
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines · Oleg Nesterov
Quoted 4 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

This is the port of uprobes to powerpc. Usage is similar to x86.

I am just curious why this series was ignored by powerpc maintainers...

Quoted 8 lines
Quoted 6 lines

Because it arrived too late for the previous merge window considering my limited bandwidth for reviewing things and that nobody else seems to have reviewed it :-)

It's still on track for the next one, and I'm hoping to dedicate most of next week going through patches & doing a powerpc -next.

Thanks Ben!

Great!

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Just one question... Shouldn't arch_uprobe_pre_xol() forbid to probe UPROBE_SWBP_INSN (at least) ?

(I assume that emulate_step() can't handle this case but of course I
do not understand arch/powerpc/lib/sstep.c)

Note that uprobe_pre_sstep_notifier() sets utask->state = UTASK_BP_HIT without any checks. This doesn't look right if it was UTASK_SSTEP...

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

But again, I do not know what powepc will actually do if we try to single-step over UPROBE_SWBP_INSN.

Ananth ?

set_swbp() will return -EEXIST to install_breakpoint if we are trying to put a breakpoint on UPROBE_SWBP_INSN.

not really, this -EEXIST (already removed by recent changes) means that bp was already installed.

But this doesn't matter,

Quoted 2 lines

So, the arch agnostic code itself
takes care of this case...

Yes. I forgot about install_breakpoint()->is_swbp_insn() check which returns -ENOTSUPP, somehow I thought arch_uprobe_analyze_insn() does this.

Quoted 1 line

or am I missing something?

No, it is me.

Quoted 2 lines

However, I see that we need a powerpc specific is_swbp_insn() implementation since we will have to take care of all the trap variants.

Hmm, I am not sure. is_swbp_insn(insn), as it is used in the arch agnostic code, should only return true if insn == UPROBE_SWBP_INSN (just in case, this logic needs more fixes but this is offtopic).

If powerpc has another insn(s) which can trigger powerpc's do_int3() counterpart, they should be rejected by arch_uprobe_analyze_insn(). I think.

Quoted 2 lines

I will need to update the patches based on changes being made by Oleg and Sebastien for the single-step issues.

Perhaps you can do this in a separate change?

We need some (simple) changes in the arch agnostic code first, they should not break poweppc. These changes are still under discussion. Once we have "__weak arch_uprobe_step*" you can reimplement these hooks and fix the problems with single-stepping.

Oleg.

#7 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

On Thu, Aug 16, 2012 at 05:21:12PM +0200, Oleg Nesterov wrote:

...

Quoted 9 lines
Quoted 2 lines

So, the arch agnostic code itself
takes care of this case...

Yes. I forgot about install_breakpoint()->is_swbp_insn() check which returns -ENOTSUPP, somehow I thought arch_uprobe_analyze_insn() does this.

Quoted 1 line

or am I missing something?

Quoted 8 lines

No, it is me.

Quoted 2 lines

However, I see that we need a powerpc specific is_swbp_insn() implementation since we will have to take care of all the trap variants.

Hmm, I am not sure. is_swbp_insn(insn), as it is used in the arch agnostic code, should only return true if insn == UPROBE_SWBP_INSN (just in case, this logic needs more fixes but this is offtopic).

I think it does...

Quoted 3 lines

If powerpc has another insn(s) which can trigger powerpc's do_int3() counterpart, they should be rejected by arch_uprobe_analyze_insn(). I think.

The insn that gets passed to arch_uprobe_analyze_insn() is copy_insn()'s version, which is the file copy of the instruction. We should also take care of the in-memory copy, in case gdb had inserted a breakpoint at the same location, right? Updating is_swbp_insn() per-arch where needed will take care of both the cases, 'cos it gets called before arch_analyze_uprobe_insn() too.

Quoted 9 lines
Quoted 2 lines

I will need to update the patches based on changes being made by Oleg and Sebastien for the single-step issues.

Perhaps you can do this in a separate change?

We need some (simple) changes in the arch agnostic code first, they should not break poweppc. These changes are still under discussion. Once we have "__weak arch_uprobe_step*" you can reimplement these hooks and fix the problems with single-stepping.

OK. Agreed.

Ananth

maintainer
#8 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 7 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Oleg Nesterov

Hmm, I am not sure. is_swbp_insn(insn), as it is used in the arch agnostic code, should only return true if insn == UPROBE_SWBP_INSN (just in case, this logic needs more fixes but this is offtopic).

Quoted 8 lines

I think it does...

Quoted 3 lines

If powerpc has another insn(s) which can trigger powerpc's do_int3() counterpart, they should be rejected by arch_uprobe_analyze_insn(). I think.

The insn that gets passed to arch_uprobe_analyze_insn() is copy_insn()'s version, which is the file copy of the instruction.

Yes, exactly. And we are going to single-step this saved uprobe->arch.insn, even if gdb/whatever replaces the original insn later or already replaced.

So arch_uprobe_analyze_insn() should reject the "unsafe" instructions which we can't step over safely.

Quoted 3 lines

We should also take
care of the in-memory copy, in case gdb had inserted a breakpoint at the same location, right?

gdb (or even the application itself) and uprobes can obviously confuse each other, in many ways, and we can do nothing at least currently. Just we should ensure that the kernel can't crash/hang/etc.

Quoted 3 lines

Updating is_swbp_insn() per-arch where needed will take care of both the cases, 'cos it gets called before arch_analyze_uprobe_insn() too.

For example. set_swbp()->is_swbp_insn() == T means that (for example) uprobe_register() and uprobe_mmap() raced with each other and there is no need for set_swbp().

However, find_active_uprobe()->is_swbp_at_addr()->is_swbp_insn() is different, "true" confirms that this insn has triggered do_int3() and thus we need send_sig(SIGTRAP) (just in case, this is not strictly correct too but offtopic again).

We definitely need more changes/fixes/improvements in this area. And perhaps powerpc requires more changes in the arch-neutral code, I dunno. In particular, I think is_swbp_insn() should have a single caller, is_swbp_at_addr(), and this caller should always play with current->mm. And many, many other changes in the long term.

So far I think that, if powerpc really needs to change is_swbp_insn(), it would be better to make another patch and discuss this change. But of course I can't judge.

Oleg.

#9 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 14 lines · Oleg Nesterov
Quoted 13 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Oleg Nesterov

Hmm, I am not sure. is_swbp_insn(insn), as it is used in the arch agnostic code, should only return true if insn == UPROBE_SWBP_INSN (just in case, this logic needs more fixes but this is offtopic).

I think it does...

Quoted 3 lines

If powerpc has another insn(s) which can trigger powerpc's do_int3() counterpart, they should be rejected by arch_uprobe_analyze_insn(). I think.

Quoted 8 lines
Quoted 2 lines

The insn that gets passed to arch_uprobe_analyze_insn() is copy_insn()'s version, which is the file copy of the instruction.

Yes, exactly. And we are going to single-step this saved uprobe->arch.insn, even if gdb/whatever replaces the original insn later or already replaced.

So arch_uprobe_analyze_insn() should reject the "unsafe" instructions which we can't step over safely.

Agreed.

Quoted 7 lines
Quoted 3 lines

We should also take
care of the in-memory copy, in case gdb had inserted a breakpoint at the same location, right?

gdb (or even the application itself) and uprobes can obviously confuse each other, in many ways, and we can do nothing at least currently. Just we should ensure that the kernel can't crash/hang/etc.

Absolutely. The proper fix for this at least from a breakpoint insertion perspective is to educate gdb (possibly ptrace itself) to fail on a breakpoint insertion request on an already existing one.

Quoted 7 lines
Quoted 3 lines

Updating is_swbp_insn() per-arch where needed will take care of both the cases, 'cos it gets called before arch_analyze_uprobe_insn() too.

For example. set_swbp()->is_swbp_insn() == T means that (for example) uprobe_register() and uprobe_mmap() raced with each other and there is no need for set_swbp().

This is true for Intel like architectures that have *one* swbp instruction. On Powerpc, gdb for instance, can insert a trap variant at the address. Therefore, is_swbp_insn() by definition should return true for all trap variants.

Quoted 7 lines

However, find_active_uprobe()->is_swbp_at_addr()->is_swbp_insn() is different, "true" confirms that this insn has triggered do_int3() and thus we need send_sig(SIGTRAP) (just in case, this is not strictly correct too but offtopic again).

We definitely need more changes/fixes/improvements in this area. And perhaps powerpc requires more changes in the arch-neutral code, I dunno.

For powerpc, just having is_swbp_insn() (already a weak function) handle the trap variants, should suffice.

Quoted 7 lines

In particular, I think is_swbp_insn() should have a single caller, is_swbp_at_addr(), and this caller should always play with current->mm. And many, many other changes in the long term.

So far I think that, if powerpc really needs to change is_swbp_insn(), it would be better to make another patch and discuss this change. But of course I can't judge.

OK. I will separate out the is_swbp_insn() change into a separate patch.

Ananth

maintainer
#10 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

Quoted 7 lines · Ananth N Mavinakayanahalli
Quoted 4 lines · Oleg Nesterov
Quoted 3 lines

We should also take
care of the in-memory copy, in case gdb had inserted a breakpoint at the same location, right?

Quoted 7 lines
Quoted 3 lines

gdb (or even the application itself) and uprobes can obviously confuse each other, in many ways, and we can do nothing at least currently. Just we should ensure that the kernel can't crash/hang/etc.

Absolutely. The proper fix for this at least from a breakpoint insertion perspective is to educate gdb (possibly ptrace itself) to fail on a breakpoint insertion request on an already existing one.

Oh, I don't think this is possible. And there are other problems like this. Uprobe can confuse gdb too, in many ways. For example, uprobe_register() can wrongly _remove_ int3 installed by gdb.

The proper fix, I think, is to rework the whole idea about uprobe bps, but this is really "in the long term". install_breakpoint() should only unmap the page and mark its pte as "owned by kernel, FOLL_WRITE should not work". Something like migration or PROT_NONE. The task itself should install bp during the page fault. And we need the "backing store" for the pages with uprobes. Yes, this all is very vague and I can be wrong.

Anyway, this is relatively minor, we have more serious problems.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Updating is_swbp_insn() per-arch where needed will take care of both the cases, 'cos it gets called before arch_analyze_uprobe_insn() too.

Quoted 8 lines
Quoted 3 lines

For example. set_swbp()->is_swbp_insn() == T means that (for example) uprobe_register() and uprobe_mmap() raced with each other and there is no need for set_swbp().

This is true for Intel like architectures that have *one* swbp instruction. On Powerpc, gdb for instance, can insert a trap variant at the address. Therefore, is_swbp_insn() by definition should return true for all trap variants.

Not in this case, I think.

OK, I was going to do this later, but this discussion makes me think I should try to send the patch sooner.

set_swbp()->is_swbp_at_addr() is simply unneeded and in fact should be considered as unnecessary pessimization.

set_orig_insn()->is_swbp_at_addr() makes more sense, but it can't fix all races with userpace. Still it should die.

Quoted 1 line

OK. I will separate out the is_swbp_insn() change into a separate patch.

Great thanks. And if we remove is_swbp_insn() from set_swbp() and set_orig_insn() then the semantics of is_swbp_insn() will much more clear, and in this case I powerpc probably really needs to change it.

Oleg.

#11 lore raw

Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

On Tue, Aug 21, 2012 at 03:09:30PM +0200, Oleg Nesterov wrote:

...

Quoted 13 lines
Quoted 4 lines

This is true for Intel like architectures that have *one* swbp instruction. On Powerpc, gdb for instance, can insert a trap variant at the address. Therefore, is_swbp_insn() by definition should return true for all trap variants.

Not in this case, I think.

OK, I was going to do this later, but this discussion makes me think I should try to send the patch sooner.

set_swbp()->is_swbp_at_addr() is simply unneeded and in fact should be considered as unnecessary pessimization.

Quoted 8 lines

set_orig_insn()->is_swbp_at_addr() makes more sense, but it can't fix all races with userpace. Still it should die.

Quoted 1 line

OK. I will separate out the is_swbp_insn() change into a separate patch.

Great thanks. And if we remove is_swbp_insn() from set_swbp() and set_orig_insn() then the semantics of is_swbp_insn() will much more clear, and in this case I powerpc probably really needs to change it.

Oleg,

I have posted a new version for review [1] without the is_swbp_insn() change. I will await your changes around is_swbp_at_addr() and make changes to the powerpc code if necessary.

Regards,
Ananth

[1] https://lists.ozlabs.org/pipermail/linuxppc-dev/2012-August/100524.html