* [patch 0/4] Kprobes support for IA64
@ 2005-05-23 15:39 Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 1/4] " Anil S Keshavamurthy
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2005-05-23 15:39 UTC (permalink / raw)
To: akpm
Cc: tony.luck, rohit.seth, rusty.lynch, prasanna, ananth, systemtap,
linux-ia64, linux-kernel, anil.s.keshavamurthy
Hi Andrew,
As many of you know that kprobes exist in the main line kernel
for various architecture including i386, x86_64, ppc64 and sparc64.
Attached patches following this mail are a port of Kprobes and Jprobes for IA64.
I have tesed this patches for kprobes and Jprobes and this seems to work fine.
I have tested this patch by inserting kprobes on various slots and
various templates including various types of branch instructions.
I have also tested this patch using the tool
http://marc.theaimsgroup.com/?l=linux-kernel&m=111657358022586&w=2
and the kprobes for IA64 works great.
This path depends on
http://marc.theaimsgroup.com/?l=linux-kernel&m=111634286225988&w=2
which is in your mm tree.
Here is list of TODO things and pathes for the same will appear soon.
1) Support kprobes on "mov r1=ip" type of instruction
2) Support Kprobes and Jprobes to exist on the same address
3) Support Return probes
3) Architecture independent cleanup of kprobes
I am sending this mail through quilt and looks like the subject line appear to be
same on all patches, sorry about that.
Please apply.
Thanks,
-Anil Keshavamurthy
Sr. Software Engineer
Open Source Technology Center/SSG
Intel Corp.
(w) 503-712-4476
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* [patch 1/4] Kprobes support for IA64
2005-05-23 15:39 [patch 0/4] Kprobes support for IA64 Anil S Keshavamurthy
@ 2005-05-23 15:39 ` Anil S Keshavamurthy
2005-05-24 5:40 ` Keith Owens
2005-05-23 15:39 ` [patch 2/4] " Anil S Keshavamurthy
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Anil S Keshavamurthy @ 2005-05-23 15:39 UTC (permalink / raw)
To: akpm
Cc: tony.luck, rohit.seth, rusty.lynch, prasanna, ananth, systemtap,
linux-ia64, linux-kernel, anil.s.keshavamurthy
[-- Attachment #1: kprobes-ia64-kdebug.patch --]
[-- Type: text/plain, Size: 6090 bytes --]
This patch adds the kdebug die notification mechanism needed by Kprobes.
For break instruction on Branch type slot, imm21 is ignored and value
zero is placed in IIM register, hence we need to handle kprobes
for switch case zero.
=========================================================================
signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
signed-off-by: Rusty Lynch <Rusty.lynch@intel.com>
=========================================================================
arch/ia64/kernel/traps.c | 33 ++++++++++++++++++++++++
arch/ia64/mm/fault.c | 8 ++++++
include/asm-ia64/break.h | 2 +
include/asm-ia64/kdebug.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+), 1 deletion(-)
Index: linux-2.6.12-rc4/arch/ia64/kernel/traps.c
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/kernel/traps.c 2005-05-19 15:39:40.000000000 -0700
+++ linux-2.6.12-rc4/arch/ia64/kernel/traps.c 2005-05-22 23:27:53.000000000 -0700
@@ -21,12 +21,26 @@
#include <asm/intrinsics.h>
#include <asm/processor.h>
#include <asm/uaccess.h>
+#include <asm/kdebug.h>
extern spinlock_t timerlist_lock;
fpswa_interface_t *fpswa_interface;
EXPORT_SYMBOL(fpswa_interface);
+struct notifier_block *ia64die_chain;
+static DEFINE_SPINLOCK(die_notifier_lock);
+
+int register_die_notifier(struct notifier_block *nb)
+{
+ int err = 0;
+ unsigned long flags;
+ spin_lock_irqsave(&die_notifier_lock, flags);
+ err = notifier_chain_register(&ia64die_chain, nb);
+ spin_unlock_irqrestore(&die_notifier_lock, flags);
+ return err;
+}
+
void __init
trap_init (void)
{
@@ -119,6 +133,10 @@
switch (break_num) {
case 0: /* unknown error (used by GCC for __builtin_abort()) */
+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num, TRAP_BRKPT, SIGTRAP)
+ == NOTIFY_STOP) {
+ return;
+ }
die_if_kernel("bugcheck!", regs, break_num);
sig = SIGILL; code = ILL_ILLOPC;
break;
@@ -171,6 +189,15 @@
sig = SIGILL; code = __ILL_BNDMOD;
break;
+ case 0x80200:
+ case 0x80300:
+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num, TRAP_BRKPT, SIGTRAP)
+ == NOTIFY_STOP) {
+ return;
+ }
+ sig = SIGTRAP; code = TRAP_BRKPT;
+ break;
+
default:
if (break_num < 0x40000 || break_num > 0x100000)
die_if_kernel("Bad break", regs, break_num);
@@ -521,7 +548,11 @@
#endif
break;
case 35: siginfo.si_code = TRAP_BRANCH; ifa = 0; break;
- case 36: siginfo.si_code = TRAP_TRACE; ifa = 0; break;
+ case 36:
+ if (notify_die(DIE_SS, "ss", ®s, vector,
+ vector, SIGTRAP) == NOTIFY_STOP)
+ return;
+ siginfo.si_code = TRAP_TRACE; ifa = 0; break;
}
siginfo.si_signo = SIGTRAP;
siginfo.si_errno = 0;
Index: linux-2.6.12-rc4/arch/ia64/mm/fault.c
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/mm/fault.c 2005-05-19 15:39:40.000000000 -0700
+++ linux-2.6.12-rc4/arch/ia64/mm/fault.c 2005-05-22 23:05:02.000000000 -0700
@@ -14,6 +14,7 @@
#include <asm/processor.h>
#include <asm/system.h>
#include <asm/uaccess.h>
+#include <asm/kdebug.h>
extern void die (char *, struct pt_regs *, long);
@@ -102,6 +103,13 @@
goto bad_area_no_up;
#endif
+ /*
+ * This is to handle the kprobes on user space access instructions
+ */
+ if (notify_die(DIE_PAGE_FAULT, "page fault", regs, code, TRAP_BRKPT,
+ SIGSEGV) == NOTIFY_STOP)
+ return;
+
down_read(&mm->mmap_sem);
vma = find_vma_prev(mm, address, &prev_vma);
Index: linux-2.6.12-rc4/include/asm-ia64/break.h
===================================================================
--- linux-2.6.12-rc4.orig/include/asm-ia64/break.h 2005-05-19 15:39:40.000000000 -0700
+++ linux-2.6.12-rc4/include/asm-ia64/break.h 2005-05-19 15:39:44.000000000 -0700
@@ -12,6 +12,8 @@
* OS-specific debug break numbers:
*/
#define __IA64_BREAK_KDB 0x80100
+#define __IA64_BREAK_KPROBE 0x80200
+#define __IA64_BREAK_JPROBE 0x80300
/*
* OS-specific break numbers:
Index: linux-2.6.12-rc4/include/asm-ia64/kdebug.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.12-rc4/include/asm-ia64/kdebug.h 2005-05-19 15:39:44.000000000 -0700
@@ -0,0 +1,61 @@
+#ifndef _IA64_KDEBUG_H
+#define _IA64_KDEBUG_H 1
+/*
+ * include/asm-ia64/kdebug.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Intel Corporation, 2005
+ *
+ * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
+ * <anil.s.keshavamurthy@intel.com> adopted from
+ * include/asm-x86_64/kdebug.h
+ */
+#include <linux/notifier.h>
+
+struct pt_regs;
+
+struct die_args {
+ struct pt_regs *regs;
+ const char *str;
+ long err;
+ int trapnr;
+ int signr;
+};
+
+int register_die_notifier(struct notifier_block *nb);
+extern struct notifier_block *ia64die_chain;
+
+enum die_val {
+ DIE_BREAK = 1,
+ DIE_SS,
+ DIE_PAGE_FAULT,
+};
+
+static inline int notify_die(enum die_val val, char *str, struct pt_regs *regs,
+ long err, int trap, int sig)
+{
+ struct die_args args = {
+ .regs = regs,
+ .str = str,
+ .err = err,
+ .trapnr = trap,
+ .signr = sig
+ };
+
+ return notifier_call_chain(&ia64die_chain, val, &args);
+}
+
+#endif
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* [patch 2/4] Kprobes support for IA64
2005-05-23 15:39 [patch 0/4] Kprobes support for IA64 Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 1/4] " Anil S Keshavamurthy
@ 2005-05-23 15:39 ` Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 3/4] " Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 4/4] " Anil S Keshavamurthy
3 siblings, 0 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2005-05-23 15:39 UTC (permalink / raw)
To: akpm
Cc: tony.luck, rohit.seth, rusty.lynch, prasanna, ananth, systemtap,
linux-ia64, linux-kernel, anil.s.keshavamurthy
[-- Attachment #1: kprobes-base-ia64-support.patch --]
[-- Type: text/plain, Size: 13404 bytes --]
This is an IA64 arch specific handling of Kprobes
signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
signed-off-by: Rusty Lynch <Rusty.lynch@intel.com>
=========================================================================
arch/ia64/Kconfig.debug | 11 +
arch/ia64/kernel/Makefile | 1
arch/ia64/kernel/kprobes.c | 332 +++++++++++++++++++++++++++++++++++++++++++++
include/asm-ia64/kprobes.h | 70 +++++++++
4 files changed, 414 insertions(+)
Index: linux-2.6.12-rc4/arch/ia64/Kconfig.debug
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/Kconfig.debug 2005-05-22 23:27:22.000000000 -0700
+++ linux-2.6.12-rc4/arch/ia64/Kconfig.debug 2005-05-22 23:28:12.000000000 -0700
@@ -2,6 +2,17 @@
source "lib/Kconfig.debug"
+config KPROBES
+ bool "Kprobes"
+ depends on DEBUG_KERNEL
+ help
+ Kprobes allows you to trap at almost any kernel address and
+ execute a callback function. register_kprobe() establishes
+ a probepoint and specifies the callback. Kprobes is useful
+ for kernel debugging, non-intrusive instrumentation and testing.
+ If in doubt, say "N".
+
+
choice
prompt "Physical memory granularity"
default IA64_GRANULE_64MB
Index: linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c 2005-05-23 07:57:43.106362451 -0700
@@ -0,0 +1,332 @@
+/*
+ * Kernel Probes (KProbes)
+ * arch/ia64/kernel/kprobes.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2002, 2004
+ * Copyright (C) Intel Corporation, 2005
+ *
+ * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
+ * <anil.s.keshavamurthy@intel.com> adapted from i386
+ */
+
+#include <linux/config.h>
+#include <linux/kprobes.h>
+#include <linux/ptrace.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/preempt.h>
+#include <linux/moduleloader.h>
+
+#include <asm/pgtable.h>
+#include <asm/kdebug.h>
+
+/* kprobe_status settings */
+#define KPROBE_HIT_ACTIVE 0x00000001
+#define KPROBE_HIT_SS 0x00000002
+
+static struct kprobe *current_kprobe;
+static unsigned long kprobe_status;
+
+enum instruction_type {A, I, M, F, B, L, X, u};
+static enum instruction_type bundle_encoding[32][3] = {
+ { M, I, I }, /* 00 */
+ { M, I, I }, /* 01 */
+ { M, I, I }, /* 02 */
+ { M, I, I }, /* 03 */
+ { M, L, X }, /* 04 */
+ { M, L, X }, /* 05 */
+ { u, u, u }, /* 06 */
+ { u, u, u }, /* 07 */
+ { M, M, I }, /* 08 */
+ { M, M, I }, /* 09 */
+ { M, M, I }, /* 0A */
+ { M, M, I }, /* 0B */
+ { M, F, I }, /* 0C */
+ { M, F, I }, /* 0D */
+ { M, M, F }, /* 0E */
+ { M, M, F }, /* 0F */
+ { M, I, B }, /* 10 */
+ { M, I, B }, /* 11 */
+ { M, B, B }, /* 12 */
+ { M, B, B }, /* 13 */
+ { u, u, u }, /* 14 */
+ { u, u, u }, /* 15 */
+ { B, B, B }, /* 16 */
+ { B, B, B }, /* 17 */
+ { M, M, B }, /* 18 */
+ { M, M, B }, /* 19 */
+ { u, u, u }, /* 1A */
+ { u, u, u }, /* 1B */
+ { M, F, B }, /* 1C */
+ { M, F, B }, /* 1D */
+ { u, u, u }, /* 1E */
+ { u, u, u }, /* 1F */
+};
+
+int arch_prepare_kprobe(struct kprobe *p)
+{
+ unsigned long addr = (unsigned long) p->addr;
+ unsigned long bundle_addr = addr & ~0xFULL;
+ unsigned long slot = addr & 0xf;
+ bundle_t bundle;
+ unsigned long template;
+
+ /*
+ * TODO: Verify that a probe is not being inserted
+ * in sensitive regions of code
+ * TODO: Verify that the memory holding the probe is rwx
+ * TODO: verify this is a kernel address
+ */
+ memcpy(&bundle, (unsigned long *)bundle_addr, sizeof(bundle_t));
+ template = bundle.quad0.template;
+ if (((bundle_encoding[template][1] == L) && slot > 1) || (slot > 2)) {
+ printk(KERN_WARNING "Attempting to insert unaligned kprobe at 0x%lx\n", addr);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+void arch_copy_kprobe(struct kprobe *p)
+{
+ unsigned long addr = (unsigned long)p->addr;
+ unsigned long bundle_addr = addr & ~0xFULL;
+
+ memcpy(&p->ainsn.insn.bundle, (unsigned long *)bundle_addr,
+ sizeof(bundle_t));
+ memcpy(&p->opcode.bundle, &p->ainsn.insn.bundle, sizeof(bundle_t));
+}
+
+void arch_arm_kprobe(struct kprobe *p)
+{
+ unsigned long addr = (unsigned long)p->addr;
+ unsigned long arm_addr = addr & ~0xFULL;
+ unsigned long slot = addr & 0xf;
+ unsigned long template;
+ bundle_t bundle;
+
+ memcpy(&bundle, &p->ainsn.insn.bundle, sizeof(bundle_t));
+
+ template = bundle.quad0.template;
+ if (slot == 1 && bundle_encoding[template][1] == L)
+ slot = 2;
+ switch (slot) {
+ case 0:
+ bundle.quad0.slot0 = BREAK_INST;
+ break;
+ case 1:
+ bundle.quad0.slot1_p0 = BREAK_INST;
+ bundle.quad1.slot1_p1 = (BREAK_INST >> (64-46));
+ break;
+ case 2:
+ bundle.quad1.slot2 = BREAK_INST;
+ break;
+ }
+
+ /* Flush icache for the instruction at the emulated address */
+ flush_icache_range((unsigned long)&p->ainsn.insn.bundle,
+ (unsigned long)&p->ainsn.insn.bundle +
+ sizeof(bundle_t));
+ /*
+ * Patch the original instruction with the probe instruction
+ * and flush the instruction cache
+ */
+ memcpy((char *) arm_addr, (char *) &bundle, sizeof(bundle_t));
+ flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+}
+
+void arch_disarm_kprobe(struct kprobe *p)
+{
+ unsigned long addr = (unsigned long)p->addr;
+ unsigned long arm_addr = addr & ~0xFULL;
+
+ /* p->opcode contains the original unaltered bundle */
+ memcpy((char *) arm_addr, (char *) &p->opcode.bundle, sizeof(bundle_t));
+ flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
+}
+
+void arch_remove_kprobe(struct kprobe *p)
+{
+}
+
+/*
+ * We are resuming execution after a single step fault, so the pt_regs
+ * structure reflects the register state after we executed the instruction
+ * located in the kprobe (p->ainsn.insn.bundle). We still need to adjust
+ * the ip to point back to the original stack address, and if we see that
+ * the slot has incremented back to zero, then we need to point to the next
+ * slot location.
+ */
+static void resume_execution(struct kprobe *p, struct pt_regs *regs)
+{
+ unsigned long bundle = (unsigned long)p->addr & ~0xFULL;
+
+ /*
+ * TODO: Handle cases where kprobe was inserted on a branch instruction
+ */
+
+ if (!ia64_psr(regs)->ri)
+ regs->cr_iip = bundle + 0x10;
+ else
+ regs->cr_iip = bundle;
+
+ ia64_psr(regs)->ss = 0;
+}
+
+static void prepare_ss(struct kprobe *p, struct pt_regs *regs)
+{
+ unsigned long bundle_addr = (unsigned long) &p->ainsn.insn.bundle;
+ unsigned long slot = (unsigned long)p->addr & 0xf;
+
+ /* Update instruction pointer (IIP) and slot number (IPSR.ri) */
+ regs->cr_iip = bundle_addr & ~0xFULL;
+
+ if (slot > 2)
+ slot = 0;
+
+ ia64_psr(regs)->ri = slot;
+
+ /* turn on single stepping */
+ ia64_psr(regs)->ss = 1;
+}
+
+static int pre_kprobes_handler(struct pt_regs *regs)
+{
+ struct kprobe *p;
+ int ret = 0;
+ kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs);
+
+ preempt_disable();
+
+ /* Handle recursion cases */
+ if (kprobe_running()) {
+ p = get_kprobe(addr);
+ if (p) {
+ if (kprobe_status == KPROBE_HIT_SS) {
+ unlock_kprobes();
+ goto no_kprobe;
+ }
+ arch_disarm_kprobe(p);
+ ret = 1;
+ } else {
+ /*
+ * jprobe instrumented function just completed
+ */
+ p = current_kprobe;
+ if (p->break_handler && p->break_handler(p, regs)) {
+ goto ss_probe;
+ }
+ }
+ }
+
+ lock_kprobes();
+ p = get_kprobe(addr);
+ if (!p) {
+ unlock_kprobes();
+ goto no_kprobe;
+ }
+
+ kprobe_status = KPROBE_HIT_ACTIVE;
+ current_kprobe = p;
+
+ if (p->pre_handler && p->pre_handler(p, regs))
+ /*
+ * Our pre-handler is specifically requesting that we just
+ * do a return. This is handling the case where the
+ * pre-handler is really our special jprobe pre-handler.
+ */
+ return 1;
+
+ss_probe:
+ prepare_ss(p, regs);
+ kprobe_status = KPROBE_HIT_SS;
+ return 1;
+
+no_kprobe:
+ preempt_enable_no_resched();
+ return ret;
+}
+
+static int post_kprobes_handler(struct pt_regs *regs)
+{
+ if (!kprobe_running())
+ return 0;
+
+ if (current_kprobe->post_handler)
+ current_kprobe->post_handler(current_kprobe, regs, 0);
+
+ resume_execution(current_kprobe, regs);
+
+ unlock_kprobes();
+ preempt_enable_no_resched();
+ return 1;
+}
+
+static int kprobes_fault_handler(struct pt_regs *regs, int trapnr)
+{
+ if (!kprobe_running())
+ return 0;
+
+ if (current_kprobe->fault_handler &&
+ current_kprobe->fault_handler(current_kprobe, regs, trapnr))
+ return 1;
+
+ if (kprobe_status & KPROBE_HIT_SS) {
+ resume_execution(current_kprobe, regs);
+ unlock_kprobes();
+ preempt_enable_no_resched();
+ }
+
+ return 0;
+}
+
+int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
+ void *data)
+{
+ struct die_args *args = (struct die_args *)data;
+ switch(val) {
+ case DIE_BREAK:
+ if (pre_kprobes_handler(args->regs))
+ return NOTIFY_STOP;
+ break;
+ case DIE_SS:
+ if (post_kprobes_handler(args->regs))
+ return NOTIFY_STOP;
+ break;
+ case DIE_PAGE_FAULT:
+ if (kprobes_fault_handler(args->regs, args->trapnr))
+ return NOTIFY_STOP;
+ default:
+ break;
+ }
+ return NOTIFY_DONE;
+}
+
+int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ printk(KERN_WARNING "Jprobes is not supported\n");
+ return 0;
+}
+
+void jprobe_return(void)
+{
+}
+
+int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ return 0;
+}
Index: linux-2.6.12-rc4/arch/ia64/kernel/Makefile
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/kernel/Makefile 2005-05-22 23:27:22.000000000 -0700
+++ linux-2.6.12-rc4/arch/ia64/kernel/Makefile 2005-05-23 07:57:43.105385888 -0700
@@ -20,6 +20,7 @@
obj-$(CONFIG_PERFMON) += perfmon_default_smpl.o
obj-$(CONFIG_IA64_CYCLONE) += cyclone.o
obj-$(CONFIG_IA64_MCA_RECOVERY) += mca_recovery.o
+obj-$(CONFIG_KPROBES) += kprobes.o
mca_recovery-y += mca_drv.o mca_drv_asm.o
# The gate DSO image is built using a special linker script.
Index: linux-2.6.12-rc4/include/asm-ia64/kprobes.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.12-rc4/include/asm-ia64/kprobes.h 2005-05-23 07:57:43.107339013 -0700
@@ -0,0 +1,70 @@
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+/*
+ * Kernel Probes (KProbes)
+ * include/asm-ia64/kprobes.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2002, 2004
+ * Copyright (C) Intel Corporation, 2005
+ *
+ * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
+ * <anil.s.keshavamurthy@intel.com> adapted from i386
+ */
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <asm/break.h>
+
+#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)
+
+typedef struct _bundle {
+ struct {
+ unsigned long long template : 5;
+ unsigned long long slot0 : 41;
+ unsigned long long slot1_p0 : 64-46;
+ } quad0;
+ struct {
+ unsigned long long slot1_p1 : 41 - (64-46);
+ unsigned long long slot2 : 41;
+ } quad1;
+} __attribute__((__aligned__(16))) bundle_t;
+
+typedef struct kprobe_opcode {
+ bundle_t bundle;
+} kprobe_opcode_t;
+
+struct fnptr {
+ unsigned long ip;
+ unsigned long gp;
+};
+
+/* Architecture specific copy of original instruction*/
+struct arch_specific_insn {
+ /* copy of the original instruction */
+ kprobe_opcode_t insn;
+};
+
+#ifdef CONFIG_KPROBES
+extern int kprobe_exceptions_notify(struct notifier_block *self,
+ unsigned long val, void *data);
+#else /* !CONFIG_KPROBES */
+static inline int kprobe_exceptions_notify(struct notifier_block *self,
+ unsigned long val, void *data)
+{
+ return 0;
+}
+#endif
+#endif /* _ASM_KPROBES_H */
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* [patch 3/4] Kprobes support for IA64
2005-05-23 15:39 [patch 0/4] Kprobes support for IA64 Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 1/4] " Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 2/4] " Anil S Keshavamurthy
@ 2005-05-23 15:39 ` Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 4/4] " Anil S Keshavamurthy
3 siblings, 0 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2005-05-23 15:39 UTC (permalink / raw)
To: akpm
Cc: tony.luck, rohit.seth, rusty.lynch, prasanna, ananth, systemtap,
linux-ia64, linux-kernel, anil.s.keshavamurthy
[-- Attachment #1: kprobes-jprobes-support.patch --]
[-- Type: text/plain, Size: 6169 bytes --]
This patch adds IA64 architecture specific JProbes support on top of Kprobes
signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
signed-off-by: Rusty Lynch <Rusty.lynch@intel.com>
=======================================================================
arch/ia64/kernel/Makefile | 2 -
arch/ia64/kernel/jprobes.S | 61 +++++++++++++++++++++++++++++++++++++++++++++
arch/ia64/kernel/kprobes.c | 28 ++++++++++++++++----
include/asm-ia64/kprobes.h | 5 +++
4 files changed, 89 insertions(+), 7 deletions(-)
Index: linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/kernel/kprobes.c 2005-05-23 07:57:06.490151962 -0700
+++ linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c 2005-05-23 07:57:38.340737509 -0700
@@ -35,12 +35,15 @@
#include <asm/pgtable.h>
#include <asm/kdebug.h>
+extern void jprobe_inst_return(void);
+
/* kprobe_status settings */
#define KPROBE_HIT_ACTIVE 0x00000001
#define KPROBE_HIT_SS 0x00000002
static struct kprobe *current_kprobe;
static unsigned long kprobe_status;
+static struct pt_regs jprobe_saved_regs;
enum instruction_type {A, I, M, F, B, L, X, u};
static enum instruction_type bundle_encoding[32][3] = {
@@ -318,15 +321,28 @@
int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
{
- printk(KERN_WARNING "Jprobes is not supported\n");
- return 0;
-}
+ struct jprobe *jp = container_of(p, struct jprobe, kp);
+ unsigned long addr = ((struct fnptr *)(jp->entry))->ip;
-void jprobe_return(void)
-{
+ /* save architectural state */
+ jprobe_saved_regs = *regs;
+
+ /* after rfi, execute the jprobe instrumented function */
+ regs->cr_iip = addr & ~0xFULL;
+ ia64_psr(regs)->ri = addr & 0xf;
+ regs->r1 = ((struct fnptr *)(jp->entry))->gp;
+
+ /*
+ * fix the return address to our jprobe_inst_return() function
+ * in the jprobes.S file
+ */
+ regs->b0 = ((struct fnptr *)(jprobe_inst_return))->ip;
+
+ return 1;
}
int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
{
- return 0;
+ *regs = jprobe_saved_regs;
+ return 1;
}
Index: linux-2.6.12-rc4/arch/ia64/kernel/Makefile
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/kernel/Makefile 2005-05-23 07:55:50.895426325 -0700
+++ linux-2.6.12-rc4/arch/ia64/kernel/Makefile 2005-05-23 07:57:22.849526761 -0700
@@ -20,7 +20,7 @@
obj-$(CONFIG_PERFMON) += perfmon_default_smpl.o
obj-$(CONFIG_IA64_CYCLONE) += cyclone.o
obj-$(CONFIG_IA64_MCA_RECOVERY) += mca_recovery.o
-obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KPROBES) += kprobes.o jprobes.o
mca_recovery-y += mca_drv.o mca_drv_asm.o
# The gate DSO image is built using a special linker script.
Index: linux-2.6.12-rc4/arch/ia64/kernel/jprobes.S
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.12-rc4/arch/ia64/kernel/jprobes.S 2005-05-23 07:57:22.850503324 -0700
@@ -0,0 +1,61 @@
+/*
+ * Jprobe specific operations
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Intel Corporation, 2005
+ *
+ * 2005-May Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
+ * <anil.s.keshavamurthy@intel.com> initial implementation
+ *
+ * Jprobes (a.k.a. "jump probes" which is built on-top of kprobes) allow a
+ * probe to be inserted into the beginning of a function call. The fundamental
+ * difference between a jprobe and a kprobe is the jprobe handler is executed
+ * in the same context as the target function, while the kprobe handlers
+ * are executed in interrupt context.
+ *
+ * For jprobes we initially gain control by placing a break point in the
+ * first instruction of the targeted function. When we catch that specific
+ * break, we:
+ * * set the return address to our jprobe_inst_return() function
+ * * jump to the jprobe handler function
+ *
+ * Since we fixed up the return address, the jprobe handler will return to our
+ * jprobe_inst_return() function, giving us control again. At this point we
+ * are back in the parents frame marker, so we do yet another call to our
+ * jprobe_break() function to fix up the frame marker as it would normally
+ * exist in the target function.
+ *
+ * Our jprobe_return function then transfers control back to kprobes.c by
+ * executing a break instruction using one of our reserved numbers. When we
+ * catch that break in kprobes.c, we continue like we do for a normal kprobe
+ * by single stepping the emulated instruction, and then returning execution
+ * to the correct location.
+ */
+#include <asm/asmmacro.h>
+
+ /*
+ * void jprobe_break(void)
+ */
+ENTRY(jprobe_break)
+ break.m 0x80300
+END(jprobe_break)
+
+ /*
+ * void jprobe_inst_return(void)
+ */
+GLOBAL_ENTRY(jprobe_inst_return)
+ br.call.sptk.many b0=jprobe_break
+END(jprobe_inst_return)
Index: linux-2.6.12-rc4/include/asm-ia64/kprobes.h
===================================================================
--- linux-2.6.12-rc4.orig/include/asm-ia64/kprobes.h 2005-05-23 07:55:50.897379450 -0700
+++ linux-2.6.12-rc4/include/asm-ia64/kprobes.h 2005-05-23 07:57:38.341714071 -0700
@@ -57,6 +57,11 @@
kprobe_opcode_t insn;
};
+/* ia64 does not need this */
+static inline void jprobe_return(void)
+{
+}
+
#ifdef CONFIG_KPROBES
extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* [patch 4/4] Kprobes support for IA64
2005-05-23 15:39 [patch 0/4] Kprobes support for IA64 Anil S Keshavamurthy
` (2 preceding siblings ...)
2005-05-23 15:39 ` [patch 3/4] " Anil S Keshavamurthy
@ 2005-05-23 15:39 ` Anil S Keshavamurthy
3 siblings, 0 replies; 12+ messages in thread
From: Anil S Keshavamurthy @ 2005-05-23 15:39 UTC (permalink / raw)
To: akpm
Cc: tony.luck, rohit.seth, rusty.lynch, prasanna, ananth, systemtap,
linux-ia64, linux-kernel, anil.s.keshavamurthy
[-- Attachment #1: kprobes-branch-support.patch --]
[-- Type: text/plain, Size: 7083 bytes --]
This patch is required to support kprobe on branch/call instructions.
Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
=====================================================================
arch/ia64/kernel/kprobes.c | 131 +++++++++++++++++++++++++++++++++++++++------
include/asm-ia64/kprobes.h | 17 +++++
2 files changed, 132 insertions(+), 16 deletions(-)
Index: linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c
===================================================================
--- linux-2.6.12-rc4.orig/arch/ia64/kernel/kprobes.c 2005-05-23 07:57:22.848550199 -0700
+++ linux-2.6.12-rc4/arch/ia64/kernel/kprobes.c 2005-05-23 07:57:24.205972057 -0700
@@ -120,25 +120,75 @@
unsigned long arm_addr = addr & ~0xFULL;
unsigned long slot = addr & 0xf;
unsigned long template;
+ unsigned long major_opcode = 0;
+ unsigned long lx_type_inst = 0;
+ unsigned long kprobe_inst = 0;
bundle_t bundle;
+
+ p->ainsn.inst_flag = 0;
+ p->ainsn.target_br_reg = 0;
memcpy(&bundle, &p->ainsn.insn.bundle, sizeof(bundle_t));
+ template = bundle.quad0.template;
+ if (slot == 1 && bundle_encoding[template][1] == L) {
+ lx_type_inst = 1;
+ slot = 2;
+ }
+
- template = bundle.quad0.template;
- if (slot == 1 && bundle_encoding[template][1] == L)
- slot = 2;
switch (slot) {
case 0:
+ major_opcode = (bundle.quad0.slot0 >> SLOT0_OPCODE_SHIFT);
+ kprobe_inst = bundle.quad0.slot0;
bundle.quad0.slot0 = BREAK_INST;
break;
case 1:
+ major_opcode = (bundle.quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
+ kprobe_inst = (bundle.quad0.slot1_p0 |
+ (bundle.quad1.slot1_p1 << (64-46)));
bundle.quad0.slot1_p0 = BREAK_INST;
bundle.quad1.slot1_p1 = (BREAK_INST >> (64-46));
break;
case 2:
+ major_opcode = (bundle.quad1.slot2 >> SLOT2_OPCODE_SHIFT);
+ kprobe_inst = bundle.quad1.slot2;
bundle.quad1.slot2 = BREAK_INST;
break;
}
+ /*
+ * Look for IP relative Branches, IP relative call or
+ * IP relative predicate instructions
+ */
+ if (bundle_encoding[template][slot] == B) {
+ switch (major_opcode) {
+ case INDIRECT_CALL_OPCODE:
+ p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
+ p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
+ break;
+ case IP_RELATIVE_PREDICT_OPCODE:
+ case IP_RELATIVE_BRANCH_OPCODE:
+ p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR;
+ break;
+ case IP_RELATIVE_CALL_OPCODE:
+ p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR;
+ p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
+ p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+ } else if (lx_type_inst) {
+ switch (major_opcode) {
+ case LONG_CALL_OPCODE:
+ p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
+ p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+ }
/* Flush icache for the instruction at the emulated address */
flush_icache_range((unsigned long)&p->ainsn.insn.bundle,
@@ -170,24 +220,75 @@
* We are resuming execution after a single step fault, so the pt_regs
* structure reflects the register state after we executed the instruction
* located in the kprobe (p->ainsn.insn.bundle). We still need to adjust
- * the ip to point back to the original stack address, and if we see that
- * the slot has incremented back to zero, then we need to point to the next
- * slot location.
+ * the ip to point back to the original stack address. To set the IP address
+ * to original stack address, handle the case where we need to fixup the
+ * relative IP address and/or fixup branch register.
*/
static void resume_execution(struct kprobe *p, struct pt_regs *regs)
{
- unsigned long bundle = (unsigned long)p->addr & ~0xFULL;
+ unsigned long bundle_addr = ((unsigned long) (&p->ainsn.insn.bundle)) & ~0xFULL;
+ unsigned long resume_addr = (unsigned long)p->addr & ~0xFULL;
+ unsigned long template;
+ int slot = ((unsigned long)p->addr & 0xf);
- /*
- * TODO: Handle cases where kprobe was inserted on a branch instruction
- */
+ template = p->opcode.bundle.quad0.template;
+
+ if (slot == 1 && bundle_encoding[template][1] == L)
+ slot = 2;
+
+ if (p->ainsn.inst_flag) {
+
+ if (p->ainsn.inst_flag & INST_FLAG_FIX_RELATIVE_IP_ADDR) {
+ /* Fix relative IP address */
+ regs->cr_iip = (regs->cr_iip - bundle_addr) + resume_addr;
+ }
- if (!ia64_psr(regs)->ri)
- regs->cr_iip = bundle + 0x10;
- else
- regs->cr_iip = bundle;
+ if (p->ainsn.inst_flag & INST_FLAG_FIX_BRANCH_REG) {
+ /*
+ * Fix target branch register, software convention is
+ * to use either b0 or b6 or b7, so just checking
+ * only those registers
+ */
+ switch (p->ainsn.target_br_reg) {
+ case 0:
+ if ((regs->b0 == bundle_addr) ||
+ (regs->b0 == bundle_addr + 0x10)) {
+ regs->b0 = (regs->b0 - bundle_addr) +
+ resume_addr;
+ }
+ break;
+ case 6:
+ if ((regs->b6 == bundle_addr) ||
+ (regs->b6 == bundle_addr + 0x10)) {
+ regs->b6 = (regs->b6 - bundle_addr) +
+ resume_addr;
+ }
+ break;
+ case 7:
+ if ((regs->b7 == bundle_addr) ||
+ (regs->b7 == bundle_addr + 0x10)) {
+ regs->b7 = (regs->b7 - bundle_addr) +
+ resume_addr;
+ }
+ break;
+ } /* end switch */
+ }
+ goto turn_ss_off;
+ }
- ia64_psr(regs)->ss = 0;
+ if (slot == 2) {
+ if (regs->cr_iip == bundle_addr + 0x10) {
+ regs->cr_iip = resume_addr + 0x10;
+ }
+ } else {
+ if (regs->cr_iip == bundle_addr) {
+ regs->cr_iip = resume_addr;
+ }
+ }
+
+turn_ss_off:
+ /* Turn off Single Step bit */
+ ia64_psr(regs)->ss = 0;
}
static void prepare_ss(struct kprobe *p, struct pt_regs *regs)
Index: linux-2.6.12-rc4/include/asm-ia64/kprobes.h
===================================================================
--- linux-2.6.12-rc4.orig/include/asm-ia64/kprobes.h 2005-05-23 07:57:22.851479886 -0700
+++ linux-2.6.12-rc4/include/asm-ia64/kprobes.h 2005-05-23 07:57:24.207925182 -0700
@@ -42,6 +42,17 @@
} quad1;
} __attribute__((__aligned__(16))) bundle_t;
+#define SLOT0_OPCODE_SHIFT (37)
+#define SLOT1_p1_OPCODE_SHIFT (37 - (64-46))
+#define SLOT2_OPCODE_SHIFT (37)
+
+#define INDIRECT_CALL_OPCODE (1)
+#define IP_RELATIVE_CALL_OPCODE (5)
+#define IP_RELATIVE_BRANCH_OPCODE (4)
+#define IP_RELATIVE_PREDICT_OPCODE (7)
+#define LONG_BRANCH_OPCODE (0xC)
+#define LONG_CALL_OPCODE (0xD)
+
typedef struct kprobe_opcode {
bundle_t bundle;
} kprobe_opcode_t;
@@ -53,8 +64,12 @@
/* Architecture specific copy of original instruction*/
struct arch_specific_insn {
- /* copy of the original instruction */
+ /* copy of the instruction to be emulated */
kprobe_opcode_t insn;
+ #define INST_FLAG_FIX_RELATIVE_IP_ADDR 1
+ #define INST_FLAG_FIX_BRANCH_REG 2
+ unsigned long inst_flag;
+ unsigned short target_br_reg;
};
/* ia64 does not need this */
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch 1/4] Kprobes support for IA64
2005-05-23 15:39 ` [patch 1/4] " Anil S Keshavamurthy
@ 2005-05-24 5:40 ` Keith Owens
0 siblings, 0 replies; 12+ messages in thread
From: Keith Owens @ 2005-05-24 5:40 UTC (permalink / raw)
To: Anil S Keshavamurthy
Cc: akpm, tony.luck, rohit.seth, rusty.lynch, prasanna, ananth,
systemtap, linux-ia64, linux-kernel
On Mon, 23 May 2005 08:39:07 -0700,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> wrote:
>
>This patch adds the kdebug die notification mechanism needed by Kprobes.
> case 0: /* unknown error (used by GCC for __builtin_abort()) */
>+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num, TRAP_BRKPT, SIGTRAP)
>+ == NOTIFY_STOP) {
>+ return;
>+ }
> die_if_kernel("bugcheck!", regs, break_num);
> sig = SIGILL; code = ILL_ILLOPC;
> break;
Nit pick. Any break instruction in a B slot will set break_num 0, so
you cannot tell if the break was inserted by kprobe or by another
debugger. Setting the string to "kprobe" is misleading here, change it
to "break 0".
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [patch 1/4] Kprobes support for IA64
@ 2005-05-24 16:20 Lynch, Rusty
2005-05-25 14:00 ` Alan D. Brunelle
0 siblings, 1 reply; 12+ messages in thread
From: Lynch, Rusty @ 2005-05-24 16:20 UTC (permalink / raw)
To: Keith Owens, Keshavamurthy, Anil S
Cc: akpm, Luck, Tony, Seth, Rohit, prasanna, ananth, systemtap,
linux-ia64, linux-kernel
>From: Keith Owens [mailto:kaos@sgi.com]
>Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> wrote:
>>
>>This patch adds the kdebug die notification mechanism needed by
Kprobes.
>> case 0: /* unknown error (used by GCC for
__builtin_abort()) */
>>+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num,
>TRAP_BRKPT, SIGTRAP)
>>+ == NOTIFY_STOP) {
>>+ return;
>>+ }
>> die_if_kernel("bugcheck!", regs, break_num);
>> sig = SIGILL; code = ILL_ILLOPC;
>> break;
>
>Nit pick. Any break instruction in a B slot will set break_num 0, so
>you cannot tell if the break was inserted by kprobe or by another
>debugger. Setting the string to "kprobe" is misleading here, change it
>to "break 0".
Good catch. We'll update the informational string.
--rusty
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch 1/4] Kprobes support for IA64
2005-05-24 16:20 [patch 1/4] " Lynch, Rusty
@ 2005-05-25 14:00 ` Alan D. Brunelle
2005-05-26 0:49 ` Keith Owens
0 siblings, 1 reply; 12+ messages in thread
From: Alan D. Brunelle @ 2005-05-25 14:00 UTC (permalink / raw)
To: Lynch, Rusty
Cc: Keith Owens, Keshavamurthy, Anil S, akpm, Luck, Tony, Seth, Rohit,
prasanna, ananth, systemtap, linux-ia64, linux-kernel
Isn't the real issue here that if kprobes attempts to put in a 'break
0x80200' into a B-slot that it instead becomes a 'break.b 0' -- as the
break.b does not accept an immediate value? Which probably means that
either kprobes (a) should not rely on the immediate value of the break
at all (always put in an immediate value of 0), or (b) kprobes should
not allow a probe on a B-slot of an instruction bundle.
Kprobes does have the two cases covered in traps.c (case 0 - when a
B-slot break is used, and case 0x80200 for a non-B-slot break). But this
doesn't seem very clean. (If it was decided that one should not overload
the break 0 case, and instead use a uniquely defined break number, then
it fails on a B-slot probe. If it is OK to overload the break 0 case,
why have another break number at all?)
I started doing a port of kprobes, ran into this, and decided to try a
different mechanism that replaced the whole instruction bundle - so that
I could format the instruction bundle to allow a break instruction with
an immediate value (and thus uniquely identify KPROBE breaks).
[Basically put the break in the 1st slot (all the time), and then go
execute the original instruction *bundle* elsewhere when the break is hit.]
PS. I don't see the 0x80300 defined __IA64_BREAK_JPROBE being used
anywhere...
Alan D. Brunelle
Hewlett-Packard
Lynch, Rusty wrote:
>>From: Keith Owens [mailto:kaos@sgi.com]
>>Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> wrote:
>>
>>
>>>This patch adds the kdebug die notification mechanism needed by
>>>
>>>
>Kprobes.
>
>
>>> case 0: /* unknown error (used by GCC for
>>>
>>>
>__builtin_abort()) */
>
>
>>>+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num,
>>>
>>>
>>TRAP_BRKPT, SIGTRAP)
>>
>>
>>>+ == NOTIFY_STOP) {
>>>+ return;
>>>+ }
>>> die_if_kernel("bugcheck!", regs, break_num);
>>> sig = SIGILL; code = ILL_ILLOPC;
>>> break;
>>>
>>>
>>Nit pick. Any break instruction in a B slot will set break_num 0, so
>>you cannot tell if the break was inserted by kprobe or by another
>>debugger. Setting the string to "kprobe" is misleading here, change it
>>to "break 0".
>>
>>
>
>Good catch. We'll update the informational string.
>
> --rusty
>-
>To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [patch 1/4] Kprobes support for IA64
@ 2005-05-25 16:46 Lynch, Rusty
0 siblings, 0 replies; 12+ messages in thread
From: Lynch, Rusty @ 2005-05-25 16:46 UTC (permalink / raw)
To: Alan D. Brunelle
Cc: Keith Owens, Keshavamurthy, Anil S, akpm, Luck, Tony, Seth, Rohit,
prasanna, ananth, systemtap, linux-ia64, linux-kernel
From: Alan D. Brunelle [mailto:Alan.Brunelle@hp.com]
>Isn't the real issue here that if kprobes attempts to put in a 'break
>0x80200' into a B-slot that it instead becomes a 'break.b 0' -- as the
>break.b does not accept an immediate value? Which probably means that
>either kprobes (a) should not rely on the immediate value of the break
>at all (always put in an immediate value of 0), or (b) kprobes should
>not allow a probe on a B-slot of an instruction bundle.
>
>Kprobes does have the two cases covered in traps.c (case 0 - when a
>B-slot break is used, and case 0x80200 for a non-B-slot break). But
this
>doesn't seem very clean. (If it was decided that one should not
overload
>the break 0 case, and instead use a uniquely defined break number, then
>it fails on a B-slot probe. If it is OK to overload the break 0 case,
>why have another break number at all?)
The realization that breaking on a b-slot caused the immediate value to
be ignored happened after we had the main portion of kprobes and jprobes
implemented. Now that I think about it, there really isn't any reason
to ever use anything but an immediate value of zero for all cases.
Well... except for maybe gaining control back from a jprobe. The
current patch doesn't take advantage of the fact that a jprobe uses a
different immediate value (as you point out below). Instead it is up to
pre_kprobe_handler() to recognize the case (see the jprobe comment in
the middle of the function.) I would rather have
kprobes_exceptions_notify() call a separate jprobe handler function.
The Jprobe break is not inserted in an existing bundle like the break
used to gain initial control for kprobes, to the break0 thing is not an
issue.
>
>I started doing a port of kprobes, ran into this, and decided to try a
>different mechanism that replaced the whole instruction bundle - so
that
>I could format the instruction bundle to allow a break instruction with
>an immediate value (and thus uniquely identify KPROBE breaks).
>[Basically put the break in the 1st slot (all the time), and then go
>execute the original instruction *bundle* elsewhere when the break is
hit.]
>
We explored this for a while, but you start getting lots of
complications when you consider that other probes could be inserted on
the remaining slots of the same bundle.
I think we can have a sensible implementation that always inserts a
break with a zero immediate value, and then have jprobes execute a break
with a reserved non-zero immediate value.
>PS. I don't see the 0x80300 defined __IA64_BREAK_JPROBE being used
>anywhere...
The number is being used in jprobes.S:jprobe_break, but not the #define
for some reason (but it should.)
Although, like I pointed out before, the current handler does not take
advantage of this.
>
>Alan D. Brunelle
>Hewlett-Packard
>
>
>Lynch, Rusty wrote:
>
>>>From: Keith Owens [mailto:kaos@sgi.com]
>>>Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> wrote:
>>>
>>>
>>>>This patch adds the kdebug die notification mechanism needed by
>>>>
>>>>
>>Kprobes.
>>
>>
>>>> case 0: /* unknown error (used by GCC for
>>>>
>>>>
>>__builtin_abort()) */
>>
>>
>>>>+ if (notify_die(DIE_BREAK, "kprobe", regs, break_num,
>>>>
>>>>
>>>TRAP_BRKPT, SIGTRAP)
>>>
>>>
>>>>+ == NOTIFY_STOP) {
>>>>+ return;
>>>>+ }
>>>> die_if_kernel("bugcheck!", regs, break_num);
>>>> sig = SIGILL; code = ILL_ILLOPC;
>>>> break;
>>>>
>>>>
>>>Nit pick. Any break instruction in a B slot will set break_num 0, so
>>>you cannot tell if the break was inserted by kprobe or by another
>>>debugger. Setting the string to "kprobe" is misleading here, change
it
>>>to "break 0".
>>>
>>>
>>
>>Good catch. We'll update the informational string.
>>
>> --rusty
>>-
>>To unsubscribe from this list: send the line "unsubscribe linux-ia64"
in
>>the body of a message to majordomo@vger.kernel.org
>>More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>>
>>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch 1/4] Kprobes support for IA64
2005-05-25 14:00 ` Alan D. Brunelle
@ 2005-05-26 0:49 ` Keith Owens
2005-05-26 1:06 ` Keshavamurthy Anil S
0 siblings, 1 reply; 12+ messages in thread
From: Keith Owens @ 2005-05-26 0:49 UTC (permalink / raw)
To: Alan D. Brunelle
Cc: Lynch, Rusty, Keshavamurthy, Anil S, akpm, Luck, Tony,
Seth, Rohit, prasanna, ananth, systemtap, linux-ia64,
linux-kernel
On Wed, 25 May 2005 10:00:18 -0400,
"Alan D. Brunelle" <Alan.Brunelle@hp.com> wrote:
>Isn't the real issue here that if kprobes attempts to put in a 'break
>0x80200' into a B-slot that it instead becomes a 'break.b 0' -- as the
>break.b does not accept an immediate value?
break.b is a B9 type instruction, which does take an imm21 value. It
is the hardware that does not store imm21 in CR.IIM when break.b is
issued.
>Kprobes does have the two cases covered in traps.c (case 0 - when a
>B-slot break is used, and case 0x80200 for a non-B-slot break). But this
>doesn't seem very clean. (If it was decided that one should not overload
>the break 0 case, and instead use a uniquely defined break number, then
>it fails on a B-slot probe. If it is OK to overload the break 0 case,
>why have another break number at all?)
Mainly for documentation when looking at the assembler code. break 0
is used for BUG(), coding a different value in the break instruction
for the debugger helps the person debugging the debugger :(. I have no
problem with coding two cases in ia64_bad_break() in order to work
around the hardware "feature".
Also consider the case where your debugger allows users to code a
deliberate entry to the debugger, like KDB_ENTER(). That case always
requires a separate break imm21 value, because the break point is not
known to the debugger until the code is executed.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch 1/4] Kprobes support for IA64
2005-05-26 0:49 ` Keith Owens
@ 2005-05-26 1:06 ` Keshavamurthy Anil S
2005-05-26 19:40 ` David Mosberger
0 siblings, 1 reply; 12+ messages in thread
From: Keshavamurthy Anil S @ 2005-05-26 1:06 UTC (permalink / raw)
To: Keith Owens
Cc: Alan D. Brunelle, Lynch, Rusty, Keshavamurthy, Anil S, akpm,
Luck, Tony, Seth, Rohit, prasanna, ananth, systemtap,
linux-ia64, linux-kernel
On Thu, May 26, 2005 at 10:49:02AM +1000, Keith Owens wrote:
> On Wed, 25 May 2005 10:00:18 -0400,
> "Alan D. Brunelle" <Alan.Brunelle@hp.com> wrote:
> >Isn't the real issue here that if kprobes attempts to put in a 'break
> >0x80200' into a B-slot that it instead becomes a 'break.b 0' -- as the
> >break.b does not accept an immediate value?
>
> break.b is a B9 type instruction, which does take an imm21 value. It
> is the hardware that does not store imm21 in CR.IIM when break.b is
> issued.
>
> >Kprobes does have the two cases covered in traps.c (case 0 - when a
> >B-slot break is used, and case 0x80200 for a non-B-slot break). But this
> >doesn't seem very clean. (If it was decided that one should not overload
> >the break 0 case, and instead use a uniquely defined break number, then
> >it fails on a B-slot probe. If it is OK to overload the break 0 case,
> >why have another break number at all?)
>
> Mainly for documentation when looking at the assembler code. break 0
> is used for BUG(), coding a different value in the break instruction
> for the debugger helps the person debugging the debugger :(. I have no
> problem with coding two cases in ia64_bad_break() in order to work
> around the hardware "feature".
I agree with Keith, when a person taking a instructin dump, a
different value will help uniquely identify that this
is a kprobe break instruction which is a replaced instrucion
of the original instruction. So we will leave with what we have
now, i.e handle the same with two cases.
>
> Also consider the case where your debugger allows users to code a
> deliberate entry to the debugger, like KDB_ENTER(). That case always
> requires a separate break imm21 value, because the break point is not
> known to the debugger until the code is executed.
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch 1/4] Kprobes support for IA64
2005-05-26 1:06 ` Keshavamurthy Anil S
@ 2005-05-26 19:40 ` David Mosberger
0 siblings, 0 replies; 12+ messages in thread
From: David Mosberger @ 2005-05-26 19:40 UTC (permalink / raw)
To: Keshavamurthy Anil S
Cc: Keith Owens, Alan D. Brunelle, Lynch, Rusty, akpm, Luck, Tony,
Seth, Rohit, prasanna, ananth, systemtap, linux-ia64,
linux-kernel
>>>>> On Wed, 25 May 2005 18:06:52 -0700, Keshavamurthy Anil S <anil.s.keshavamurthy@intel.com> said:
Keshavamurthy> I agree with Keith, when a person taking a instructin
Keshavamurthy> dump, a different value will help uniquely identify
Keshavamurthy> that this is a kprobe break instruction which is a
Keshavamurthy> replaced instrucion of the original instruction. So
Keshavamurthy> we will leave with what we have now, i.e handle the
Keshavamurthy> same with two cases.
We could read the imm21 value from the break.b instruction.
--david
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-05-26 19:43 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-23 15:39 [patch 0/4] Kprobes support for IA64 Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 1/4] " Anil S Keshavamurthy
2005-05-24 5:40 ` Keith Owens
2005-05-23 15:39 ` [patch 2/4] " Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 3/4] " Anil S Keshavamurthy
2005-05-23 15:39 ` [patch 4/4] " Anil S Keshavamurthy
-- strict thread matches above, loose matches on Subject: below --
2005-05-24 16:20 [patch 1/4] " Lynch, Rusty
2005-05-25 14:00 ` Alan D. Brunelle
2005-05-26 0:49 ` Keith Owens
2005-05-26 1:06 ` Keshavamurthy Anil S
2005-05-26 19:40 ` David Mosberger
2005-05-25 16:46 Lynch, Rusty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox