Skip to contentSkip to conversation

uprobes: Pass probed vaddr to arch_uprobe_analyze_insn()

PATCH Superseded Ananth N Mavinakayanahalli 7 participants 22 messages Jun 6, 2012 – Jun 12, 2012

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 uprobes: Pass probed vaddr to arch_uprobe_analyze_insn()

From: Ananth N Mavinakayanahalli <[email protected]>

On RISC architectures like powerpc, instructions are fixed size. Instruction analysis on such platforms is just a matter of (insn % 4). Pass the vaddr at which the uprobe is to be inserted so that arch_uprobe_analyze_insn() can flag misaligned registration requests.

---
 arch/x86/include/asm/uprobes.h |    2 +-
 arch/x86/kernel/uprobes.c      |    3 ++-
 kernel/events/uprobes.c        |    2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/include/asm/uprobes.h +1 -1
Index: uprobes-24may/arch/x86/include/asm/uprobes.h
===================================================================
@@ -48,7 +48,7 @@ struct arch_uprobe_task {
 #endif
 };
 
-extern int  arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm);
+extern int  arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, loff_t vaddr);
 extern int  arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
 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);
arch/x86/kernel/uprobes.c +2 -1
Index: uprobes-24may/arch/x86/kernel/uprobes.c
===================================================================
@@ -409,9 +409,10 @@ static int validate_insn_bits(struct arc
  * arch_uprobe_analyze_insn - instruction analysis including validity and fixups.
  * @mm: the probed address space.
  * @arch_uprobe: the probepoint information.
+ * @vaddr: virtual address at which to install the probepoint
  * Return 0 on success or a -ve number on error.
  */
-int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm)
+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)
 {
 	int ret;
 	struct insn insn;
kernel/events/uprobes.c +1 -1
Index: uprobes-24may/kernel/events/uprobes.c
===================================================================
@@ -697,7 +697,7 @@ install_breakpoint(struct uprobe *uprobe
 		if (is_swbp_insn((uprobe_opcode_t *)uprobe->arch.insn))
 			return -EEXIST;
 
-		ret = arch_uprobe_analyze_insn(&uprobe->arch, mm);
+		ret = arch_uprobe_analyze_insn(&uprobe->arch, mm, vaddr);
 		if (ret)
 			return ret;
 
#1 lore raw

PATCH 2/2 uprobes: powerpc port

From: Ananth N Mavinakayanahalli <[email protected]>

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

One TODO in this port compared to x86 is the uprobe abort_xol() logic. x86 depends on the thread_struct.trap_nr (absent in powerpc) to determine if a signal was caused when the uprobed instruction was single-stepped/ emulated, in which case, we reset the instruction pointer to the probed address and retry the probe again.

[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
# ========

# captured on: Mon Jun  4 05:26:31 2012
# hostname : xxxx.ibm.com
# os release : 3.4.0-uprobe
# perf version : 3.4.0
# arch : ppc64
# nrcpus online : 4
# nrcpus avail : 4
# cpudesc : POWER6 (raw), altivec supported
# cpuid : 62,769
# total memory : 7310528 kB
# cmdline : /root/bin/perf record -e probe_libc:malloc -aR sleep 20
# event : name = probe_libc:malloc, type = 2, config = 0x124, config1 = 0x0, con
# HEADER_CPU_TOPOLOGY info available, use -I to display
# HEADER_NUMA_TOPOLOGY info available, use -I to display
# ========
#
# 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
arch/powerpc/include/asm/thread_info.h +3 -1
Index: linux-3.5-rc1/arch/powerpc/include/asm/thread_info.h
===================================================================
@@ -96,6 +96,7 @@
 #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 */
@@ -112,12 +113,13 @@
 #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 +49 -0

49 lines not on this page · raw message

arch/powerpc/kernel/Makefile +1 -0
Index: linux-3.5-rc1/arch/powerpc/kernel/Makefile
===================================================================
@@ -96,6 +96,7 @@
 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-3.5-rc1/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 @@
 
 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 +163 -0

163 lines not on this page · raw message

arch/powerpc/Kconfig +3 -0
Index: linux-3.5-rc1/arch/powerpc/Kconfig
===================================================================
@@ -237,6 +237,9 @@
 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
maintainer
#2 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

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

One TODO in this port compared to x86 is the uprobe abort_xol() logic. x86 depends on the thread_struct.trap_nr (absent in powerpc) to determine if a signal was caused when the uprobed instruction was single-stepped/ emulated, in which case, we reset the instruction pointer to the probed address and retry the probe again.=20

Another curious difference is that x86 uses an instruction decoder and contains massive tables to validate we can probe a particular instruction.

Can we probe all possible PPC instructions?

#3 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Ananth N Mavinakayanahalli

One TODO in this port compared to x86 is the uprobe abort_xol() logic. x86 depends on the thread_struct.trap_nr (absent in powerpc) to determine if a signal was caused when the uprobed instruction was single-stepped/ emulated, in which case, we reset the instruction pointer to the probed address and retry the probe again.

Quoted 5 lines

Another curious difference is that x86 uses an instruction decoder and contains massive tables to validate we can probe a particular instruction.

Can we probe all possible PPC instructions?

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

I am not aware of specific caveats for vector/altivec instructions; maybe Paul or Ben are more suitable to comment on that.

Ananth

#15 lore raw
In reply to Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Ananth N Mavinakayanahalli

+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)

Don't we traditionally use unsigned long to pass vaddrs?

Right. But the vaddr we pass here is vma_info->vaddr which is loff_t. I guess I should've made that clear in the patch description.

Ananth

#16 lore raw
Quoted 8 lines · Ananth N Mavinakayanahalli
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Ananth N Mavinakayanahalli

+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)

Don't we traditionally use unsigned long to pass vaddrs?

Right. But the vaddr we pass here is vma_info->vaddr which is loff_t. I guess I should've made that clear in the patch description.

Why not fix struct vma_info's vaddr type?

Thanks,

Ingo

#17 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:49 +0530, Ananth N Mavinakayanahalli wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)

Don't we traditionally use unsigned long to pass vaddrs?

Right. But the vaddr we pass here is vma_info->vaddr which is loff_t. I guess I should've made that clear in the patch description.

Why not fix struct vma_info's vaddr type?

Agreed. Will fix and send v2.

Ananth

#18 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:49 +0530, Ananth N Mavinakayanahalli wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)

Don't we traditionally use unsigned long to pass vaddrs?

Right. But the vaddr we pass here is vma_info->vaddr which is loff_t. I guess I should've made that clear in the patch description.

Why not fix struct vma_info's vaddr type?

Calculating and comparing vaddr results either uses variables of type loff_t. To avoid typecasting and avoid overflow at each of these places, we used loff_t.

Ananth, install_breakpoint() already has a variable of type addr of type unsigned long. Why dont you use addr instead of vaddr.

Signature · 2 lines
Thanks and regards
Srikar
maintainer
#20 lore raw
In reply to Ananth N Mavinakayanahalli
Quoted 7 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

On RISC architectures like powerpc, instructions are fixed size. Instruction analysis on such platforms is just a matter of (insn % 4). Pass the vaddr at which the uprobe is to be inserted so that arch_uprobe_analyze_insn() can flag misaligned registration requests.

And the next patch checks "vaddr & 0x03".

But why do you need this new arg? arch_uprobe_analyze_insn() could check "container_of(auprobe, struct uprobe, arch)->offset & 0x3" with the same effect, no? vm_start/vm_pgoff are obviously page-aligned.

Oleg.

#21 lore raw
Quoted 9 lines · Oleg Nesterov
Quoted 7 lines · Ananth N Mavinakayanahalli

From: Ananth N Mavinakayanahalli <[email protected]>

On RISC architectures like powerpc, instructions are fixed size. Instruction analysis on such platforms is just a matter of (insn % 4). Pass the vaddr at which the uprobe is to be inserted so that arch_uprobe_analyze_insn() can flag misaligned registration requests.

Quoted 6 lines

And the next patch checks "vaddr & 0x03".

But why do you need this new arg? arch_uprobe_analyze_insn() could check "container_of(auprobe, struct uprobe, arch)->offset & 0x3" with the same effect, no? vm_start/vm_pgoff are obviously page-aligned.

We cant use container_of because we moved the definition for struct uprobe to kernel/events/uprobe.c. This was possible before when struct uprobe definition was in include/uprobes.h

Signature · 2 lines
Thanks and Regards
Srikar
#4 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

In reply to Ananth N Mavinakayanahalli
Quoted 11 lines · Ananth N Mavinakayanahalli
Quoted 10 lines · Peter Zijlstra
Quoted 5 lines · Ananth N Mavinakayanahalli

One TODO in this port compared to x86 is the uprobe abort_xol() logic. x86 depends on the thread_struct.trap_nr (absent in powerpc) to determine if a signal was caused when the uprobed instruction was single-stepped/ emulated, in which case, we reset the instruction pointer to the probed address and retry the probe again.

Another curious difference is that x86 uses an instruction decoder and contains massive tables to validate we can probe a particular instruction.

Part of that difference is because the x86 instruction set is a lot more complex. Another part is due to the lack, back when the x86 code was created, of robust handling by uprobes of traps by probed instructions. So we refused to probe instructions that we knew (or strongly suspected) would generate traps in user mode -- e.g., privileged instructions, illegal instructions. A couple of times we had to "legalize" instructions or prefixes that we didn't originally expect to encounter.

Quoted 9 lines
Quoted 2 lines

Can we probe all possible PPC instructions?

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

Quoted 6 lines

I am not aware of specific caveats for vector/altivec instructions; maybe Paul or Ben are more suitable to comment on that.

Ananth

Jim

#19 lore raw
In reply to Srikar Dronamraju
Quoted 17 lines · Srikar Dronamraju
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:49 +0530, Ananth N Mavinakayanahalli wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, loff_t vaddr)

Don't we traditionally use unsigned long to pass vaddrs?

Right. But the vaddr we pass here is vma_info->vaddr which is loff_t. I guess I should've made that clear in the patch description.

Why not fix struct vma_info's vaddr type?

Quoted 6 lines

Calculating and comparing vaddr results either uses variables of type loff_t. To avoid typecasting and avoid overflow at each of these places, we used loff_t.

Ananth, install_breakpoint() already has a variable of type addr of type unsigned long. Why dont you use addr instead of vaddr.

Ok, makes sense. I'll change it in v2.

Ananth

#5 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

In reply to Jim Keniston
Quoted 3 lines · Jim Keniston
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:51 +0530, Ananth N Mavinakayanahalli wrote:

...

Quoted 10 lines
Quoted 6 lines

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

That'd be flagged elsewhere, by the architecture itself -- you'd get a privileged instruciton exception if you try execute any instruction not part of the UISA. I therefore don't think its a necessary check in the uprobes code.

Ananth

#6 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 14 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Jim Keniston
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:51 +0530, Ananth N Mavinakayanahalli wrote:

...

Quoted 7 lines
Quoted 6 lines

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Quoted 8 lines
Quoted 3 lines

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

That'd be flagged elsewhere, by the architecture itself -- you'd get a privileged instruciton exception if you try execute any instruction not part of the UISA. I therefore don't think its a necessary check in the uprobes code.

But you're not executing the instruction, you're passing it to emulate_step(). Or am I missing something?

cheers

#7 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 19 lines · Michael Ellerman
Quoted 18 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Jim Keniston
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:51 +0530, Ananth N Mavinakayanahalli wrote:

...

Quoted 10 lines
Quoted 6 lines

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

Quoted 7 lines
Quoted 4 lines

That'd be flagged elsewhere, by the architecture itself -- you'd get a privileged instruciton exception if you try execute any instruction not part of the UISA. I therefore don't think its a necessary check in the uprobes code.

But you're not executing the instruction, you're passing it to emulate_step(). Or am I missing something?

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Ananth

#8 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 25 lines · Ananth N Mavinakayanahalli
Quoted 24 lines · Michael Ellerman
Quoted 22 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Jim Keniston
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:51 +0530, Ananth N Mavinakayanahalli wrote:

...

Quoted 10 lines
Quoted 6 lines

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

That'd be flagged elsewhere, by the architecture itself -- you'd get a privileged instruciton exception if you try execute any instruction not part of the UISA. I therefore don't think its a necessary check in the uprobes code.

Quoted 5 lines
Quoted 2 lines

But you're not executing the instruction, you're passing it to emulate_step(). Or am I missing something?

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

cheers

#9 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 32 lines · Michael Ellerman
Quoted 25 lines · Ananth N Mavinakayanahalli
Quoted 24 lines · Michael Ellerman
Quoted 22 lines · Ananth N Mavinakayanahalli
Quoted 3 lines · Jim Keniston
Quoted 2 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Peter Zijlstra

On Wed, 2012-06-06 at 14:51 +0530, Ananth N Mavinakayanahalli wrote:

...

Quoted 10 lines
Quoted 6 lines

For the kernel, the only ones that are off limits are rfi (return from interrupt), mtmsr (move to msr). All other instructions can be probed.

Both those instructions are supervisor level, so we won't see them in userspace at all; so we should be able to probe all user level instructions.

Presumably rfi or mtmsr could show up in the instruction stream via an erroneous or mischievous asm statement. It'd be good to verify that you handle that gracefully.

That'd be flagged elsewhere, by the architecture itself -- you'd get a privileged instruciton exception if you try execute any instruction not part of the UISA. I therefore don't think its a necessary check in the uprobes code.

Quoted 5 lines
Quoted 2 lines

But you're not executing the instruction, you're passing it to emulate_step(). Or am I missing something?

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Quoted 6 lines

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

Sure. Will add that check and send v2.

Ananth

#10 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 8 lines · Ananth N Mavinakayanahalli
Quoted 7 lines · Michael Ellerman
Quoted 5 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Michael Ellerman

On Fri, 2012-06-08 at 10:06 +0530, Ananth N Mavinakayanahalli wrote:

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Quoted 8 lines
Quoted 6 lines

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

Sure. Will add that check and send v2.

Sorry I didn't mean add a test in the code, I meant construct a test case to confirm that it works as expected.

cheers

#11 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 13 lines · Michael Ellerman
Quoted 12 lines · Ananth N Mavinakayanahalli
Quoted 11 lines · Michael Ellerman
Quoted 5 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Michael Ellerman

On Fri, 2012-06-08 at 10:06 +0530, Ananth N Mavinakayanahalli wrote:

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

Sure. Will add that check and send v2.

Sorry I didn't mean add a test in the code, I meant construct a test case to confirm that it works as expected.

Michael,

I just hand-coded the instr to emulate_step() and here are the results:

MSR_PR is set
insn = 7c600124, ret = 0 /* mtmsr */
insn = 7c600164, ret = 0 /* mtmsrd */
insn = 4c000024, ret = -1 /* rfid */
insn = 4c000064, ret = 0 /* rfi */

Also verified that standalone programs with those instructions in inline asm will die with a SIGILL.

So, for mtmsr, mtmsrd and rfi, we have to single-step them which will result in a SIGILL in turn.

Ananth

#12 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 32 lines · Ananth N Mavinakayanahalli
Quoted 13 lines · Michael Ellerman
Quoted 12 lines · Ananth N Mavinakayanahalli
Quoted 11 lines · Michael Ellerman
Quoted 5 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Michael Ellerman

On Fri, 2012-06-08 at 10:06 +0530, Ananth N Mavinakayanahalli wrote:

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

Sure. Will add that check and send v2.

Sorry I didn't mean add a test in the code, I meant construct a test case to confirm that it works as expected.

Michael,

I just hand-coded the instr to emulate_step() and here are the results:

MSR_PR is set
insn = 7c600124, ret = 0 /* mtmsr */
insn = 7c600164, ret = 0 /* mtmsrd */
insn = 4c000024, ret = -1 /* rfid */
insn = 4c000064, ret = 0 /* rfi */

Quoted 5 lines

Also verified that standalone programs with those instructions in inline asm will die with a SIGILL.

So, for mtmsr, mtmsrd and rfi, we have to single-step them which will result in a SIGILL in turn.

What happens in the rfid case? You don't handle -1 from emulate_step() any differently AFAICS, so don't we try to single step that too?

cheers

#13 lore raw

Re: [PATCH 2/2] [POWERPC] uprobes: powerpc port

Quoted 33 lines · Michael Ellerman
Quoted 32 lines · Ananth N Mavinakayanahalli
Quoted 13 lines · Michael Ellerman
Quoted 12 lines · Ananth N Mavinakayanahalli
Quoted 11 lines · Michael Ellerman
Quoted 5 lines · Ananth N Mavinakayanahalli
Quoted 1 line · Michael Ellerman

On Fri, 2012-06-08 at 10:06 +0530, Ananth N Mavinakayanahalli wrote:

But MSR_PR=1 and hence emulate_step() will return -1 and hence we will end up single-stepping using user_enable_single_step(). Same with rfid.

Right. But that was exactly Jim's point, you may be asked to emulate those instructions even though you wouldn't expect to see them in userspace code, so you need to handle it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Luckily it looks like emulate_step() will do the right thing for you. It'd be good to test it to make 100% sure.

Sure. Will add that check and send v2.

Sorry I didn't mean add a test in the code, I meant construct a test case to confirm that it works as expected.

Michael,

I just hand-coded the instr to emulate_step() and here are the results:

MSR_PR is set
insn = 7c600124, ret = 0 /* mtmsr */
insn = 7c600164, ret = 0 /* mtmsrd */
insn = 4c000024, ret = -1 /* rfid */
insn = 4c000064, ret = 0 /* rfi */

Quoted 8 lines
Quoted 5 lines

Also verified that standalone programs with those instructions in inline asm will die with a SIGILL.

So, for mtmsr, mtmsrd and rfi, we have to single-step them which will result in a SIGILL in turn.

What happens in the rfid case? You don't handle -1 from emulate_step() any differently AFAICS, so don't we try to single step that too?

-1 is just emulate_step() flagging cases where instructions must not be single-stepped (rfi[d], mtmsr that clears MSR_RI). But as with the other OEA instructions in user space, we fail with a SIGILL.

As the application is hozed in any case if we encounter an OEA instruction, I'd think there is no point in handling a -1 from emulate_step() any differently.

Ananth