rpms/kernel/devel linux-2.6-kprobes-add-regs_return_value-helper.patch, NONE, 1.1 linux-2.6-kprobes-documentation.patch, NONE, 1.1 linux-2.6-kprobes-portable.patch, NONE, 1.1 kernel-2.6.spec, 1.2651, 1.2652
fedora-cvs-commits at redhat.com
fedora-cvs-commits at redhat.com
Thu Sep 14 17:57:07 UTC 2006
- Previous message (by thread): rpms/dbus/devel .cvsignore, 1.21, 1.22 dbus-0.61-selinux-avc-audit.patch, 1.2, 1.3 dbus-0.92-audit-system.patch, 1.1, 1.2 dbus.spec, 1.96, 1.97 sources, 1.21, 1.22
- Next message (by thread): rpms/poppler/devel poppler.spec,1.30,1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: davej
Update of /cvs/dist/rpms/kernel/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv16482
Modified Files:
kernel-2.6.spec
Added Files:
linux-2.6-kprobes-add-regs_return_value-helper.patch
linux-2.6-kprobes-documentation.patch
linux-2.6-kprobes-portable.patch
Log Message:
kprobes changes to make systemtap's life easier
linux-2.6-kprobes-add-regs_return_value-helper.patch:
asm-i386/ptrace.h | 3 +++
asm-ia64/ptrace.h | 3 +++
asm-powerpc/ptrace.h | 2 ++
asm-s390/ptrace.h | 1 +
asm-x86_64/ptrace.h | 2 ++
5 files changed, 11 insertions(+)
--- NEW FILE linux-2.6-kprobes-add-regs_return_value-helper.patch ---
diff -rup a/include/asm-i386/ptrace.h b/include/asm-i386/ptrace.h
--- a/include/asm-i386/ptrace.h 2006-06-18 01:49:35.000000000 +0000
+++ b/include/asm-i386/ptrace.h 2006-08-25 16:36:01.426620000 +0000
@@ -79,7 +79,10 @@ static inline int user_mode_vm(struct pt
{
return ((regs->xcs & 3) | (regs->eflags & VM_MASK)) != 0;
}
+
#define instruction_pointer(regs) ((regs)->eip)
+#define regs_return_value(regs) ((regs)->eax)
+
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
extern unsigned long profile_pc(struct pt_regs *regs);
#else
diff -rup a/include/asm-ia64/ptrace.h b/include/asm-ia64/ptrace.h
--- a/include/asm-ia64/ptrace.h 2006-08-25 15:57:41.053661000 +0000
+++ b/include/asm-ia64/ptrace.h 2006-08-25 16:32:00.910820000 +0000
@@ -237,6 +237,9 @@ struct switch_stack {
* the canonical representation by adding to instruction pointer.
*/
# define instruction_pointer(regs) ((regs)->cr_iip + ia64_psr(regs)->ri)
+
+#define regs_return_value(regs) ((regs)->r8)
+
/* Conserve space in histogram by encoding slot bits in address
* bits 2 and 3 rather than bits 0 and 1.
*/
diff -rup a/include/asm-powerpc/ptrace.h b/include/asm-powerpc/ptrace.h
--- a/include/asm-powerpc/ptrace.h 2006-08-25 15:57:44.472720000 +0000
+++ b/include/asm-powerpc/ptrace.h 2006-08-25 16:32:00.916820000 +0000
@@ -73,6 +73,8 @@ struct pt_regs {
#ifndef __ASSEMBLY__
#define instruction_pointer(regs) ((regs)->nip)
+#define regs_return_value(regs) ((regs)->gpr[3])
+
#ifdef CONFIG_SMP
extern unsigned long profile_pc(struct pt_regs *regs);
#else
diff -rup a/include/asm-s390/ptrace.h b/include/asm-s390/ptrace.h
--- a/include/asm-s390/ptrace.h 2006-08-25 15:57:44.980740000 +0000
+++ b/include/asm-s390/ptrace.h 2006-08-25 16:32:00.933820000 +0000
@@ -472,6 +472,7 @@ struct user_regs_struct
#define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
#define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
+#define regs_return_value(regs)((regs)->gprs[2])
#define profile_pc(regs) instruction_pointer(regs)
extern void show_regs(struct pt_regs * regs);
#endif
diff -rup a/include/asm-x86_64/ptrace.h b/include/asm-x86_64/ptrace.h
--- a/include/asm-x86_64/ptrace.h 2006-06-18 01:49:35.000000000 +0000
+++ b/include/asm-x86_64/ptrace.h 2006-08-25 16:32:00.960820000 +0000
@@ -84,6 +84,8 @@ struct pt_regs {
#define user_mode(regs) (!!((regs)->cs & 3))
#define user_mode_vm(regs) user_mode(regs)
#define instruction_pointer(regs) ((regs)->rip)
+#define regs_return_value(regs) ((regs)->rax)
+
extern unsigned long profile_pc(struct pt_regs *regs);
void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
linux-2.6-kprobes-documentation.patch:
kprobes.txt | 89 +++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 56 insertions(+), 33 deletions(-)
--- NEW FILE linux-2.6-kprobes-documentation.patch ---
diff -rup a/Documentation/kprobes.txt b/Documentation/kprobes.txt
--- a/Documentation/kprobes.txt 2006-06-18 01:49:35.000000000 +0000
+++ b/Documentation/kprobes.txt 2006-08-25 16:39:03.338260000 +0000
@@ -151,9 +151,9 @@ So that you can load and unload Kprobes-
make sure "Loadable module support" (CONFIG_MODULES) and "Module
unloading" (CONFIG_MODULE_UNLOAD) are set to "y".
-You may also want to ensure that CONFIG_KALLSYMS and perhaps even
-CONFIG_KALLSYMS_ALL are set to "y", since kallsyms_lookup_name()
-is a handy, version-independent way to find a function's address.
+Also make sure that CONFIG_KALLSYMS and perhaps even CONFIG_KALLSYMS_ALL
+are set to "y", since kallsyms_lookup_name() is used by the in-kernel
+kprobe address resolution code.
If you need to insert a probe in the middle of a function, you may find
it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO),
@@ -179,6 +179,27 @@ occurs during execution of kp->pre_handl
or during single-stepping of the probed instruction, Kprobes calls
kp->fault_handler. Any or all handlers can be NULL.
+NOTE:
+1. With the introduction of the "symbol_name" field to struct kprobe,
+the probepoint address resolution will now be taken care of by the kernel.
+The following will now work:
+
+ kp.symbol_name = "symbol_name";
+
+(64-bit powerpc intricacies such as function descriptors are handled
+transparently)
+
+2. Use the "offset" field of struct kprobe if the offset into the symbol
+to install a probepoint is known. This field is used to calculate the
+probepoint.
+
+3. Specify either the kprobe "symbol_name" OR the "addr". If both are
+specified, kprobe registration will fail with -EINVAL.
+
+4. With CISC architectures (such as i386 and x86_64), the kprobes code
+does not validate if the kprobe.addr is at an instruction boundary.
+Use "offset" with caution.
+
register_kprobe() returns 0 on success, or a negative errno otherwise.
User's pre-handler (kp->pre_handler):
@@ -225,6 +246,12 @@ control to Kprobes.) If the probed func
fastcall, or anything else that affects how args are passed, the
handler's declaration must match.
+NOTE: A macro JPROBE_ENTRY is provided to handle architecture-specific
+aliasing of jp->entry. In the interest of portability, it is advised
+to use:
+
+ jp->entry = JPROBE_ENTRY(handler);
+
register_jprobe() returns 0 on success, or a negative errno otherwise.
4.3 register_kretprobe
@@ -251,6 +278,11 @@ of interest:
- ret_addr: the return address
- rp: points to the corresponding kretprobe object
- task: points to the corresponding task struct
+
+The regs_return_value(regs) macro provides a simple abstraction to
+extract the return value from the appropriate register as defined by
+the architecture's ABI.
+
The handler's return value is currently ignored.
4.4 unregister_*probe
@@ -369,7 +401,6 @@ stack trace and selected i386 registers
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kprobes.h>
-#include <linux/kallsyms.h>
#include <linux/sched.h>
/*For each probe you need to allocate a kprobe structure*/
@@ -403,18 +434,14 @@ int handler_fault(struct kprobe *p, stru
return 0;
}
-int init_module(void)
+static int __init kprobe_init(void)
{
int ret;
kp.pre_handler = handler_pre;
kp.post_handler = handler_post;
kp.fault_handler = handler_fault;
- kp.addr = (kprobe_opcode_t*) kallsyms_lookup_name("do_fork");
- /* register the kprobe now */
- if (!kp.addr) {
- printk("Couldn't find %s to plant kprobe\n", "do_fork");
- return -1;
- }
+ kp.symbol_name = "do_fork";
+
if ((ret = register_kprobe(&kp) < 0)) {
printk("register_kprobe failed, returned %d\n", ret);
return -1;
@@ -423,12 +450,14 @@ int init_module(void)
return 0;
}
-void cleanup_module(void)
+static void __exit kprobe_exit(void)
{
unregister_kprobe(&kp);
printk("kprobe unregistered\n");
}
+module_init(kprobe_init)
+module_exit(kprobe_exit)
MODULE_LICENSE("GPL");
----- cut here -----
@@ -463,7 +492,6 @@ the arguments of do_fork().
#include <linux/fs.h>
#include <linux/uio.h>
#include <linux/kprobes.h>
-#include <linux/kallsyms.h>
/*
* Jumper probe for do_fork.
@@ -485,17 +513,13 @@ long jdo_fork(unsigned long clone_flags,
}
static struct jprobe my_jprobe = {
- .entry = (kprobe_opcode_t *) jdo_fork
+ .entry = JPROBE_ENTRY(jdo_fork)
};
-int init_module(void)
+static int __init jprobe_init(void)
{
int ret;
- my_jprobe.kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("do_fork");
- if (!my_jprobe.kp.addr) {
- printk("Couldn't find %s to plant jprobe\n", "do_fork");
- return -1;
- }
+ my_jprobe.kp.symbol_name = "do_fork";
if ((ret = register_jprobe(&my_jprobe)) <0) {
printk("register_jprobe failed, returned %d\n", ret);
@@ -506,12 +530,14 @@ int init_module(void)
return 0;
}
-void cleanup_module(void)
+static void __exit jprobe_exit(void)
{
unregister_jprobe(&my_jprobe);
printk("jprobe unregistered\n");
}
+module_init(jprobe_init)
+module_exit(jprobe_exit)
MODULE_LICENSE("GPL");
----- cut here -----
@@ -530,16 +556,13 @@ report failed calls to sys_open().
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kprobes.h>
-#include <linux/kallsyms.h>
static const char *probed_func = "sys_open";
/* Return-probe handler: If the probed function fails, log the return value. */
static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
{
- // Substitute the appropriate register name for your architecture --
- // e.g., regs->rax for x86_64, regs->gpr[3] for ppc64.
- int retval = (int) regs->eax;
+ int retval = return_value(regs);
if (retval < 0) {
printk("%s returns %d\n", probed_func, retval);
}
@@ -552,15 +575,11 @@ static struct kretprobe my_kretprobe = {
.maxactive = 20
};
-int init_module(void)
+static int __init kretprobe_init(void)
{
int ret;
- my_kretprobe.kp.addr =
- (kprobe_opcode_t *) kallsyms_lookup_name(probed_func);
- if (!my_kretprobe.kp.addr) {
- printk("Couldn't find %s to plant return probe\n", probed_func);
- return -1;
- }
+ my_kretprobe.kp.symbol_name = (char *)probed_func;
+
if ((ret = register_kretprobe(&my_kretprobe)) < 0) {
printk("register_kretprobe failed, returned %d\n", ret);
return -1;
@@ -569,7 +588,7 @@ int init_module(void)
return 0;
}
-void cleanup_module(void)
+static void __exit kretprobe_exit(void)
{
unregister_kretprobe(&my_kretprobe);
printk("kretprobe unregistered\n");
@@ -578,6 +597,8 @@ void cleanup_module(void)
my_kretprobe.nmissed, probed_func);
}
+module_init(kretprobe_init)
+module_exit(kretprobe_exit)
MODULE_LICENSE("GPL");
----- cut here -----
@@ -590,3 +611,5 @@ messages.)
For additional information on Kprobes, refer to the following URLs:
http://www-106.ibm.com/developerworks/library/l-kprobes.html?ca=dgr-lnxw42Kprobe
http://www.redhat.com/magazine/005mar05/features/kprobes/
+http://www-users.cs.umn.edu/~boutcher/kprobes/
+http://www.linuxsymposium.org/2006/linuxsymposium_procv2.pdf (pages 101-115)
linux-2.6-kprobes-portable.patch:
arch/i386/Kconfig | 2 +-
arch/ia64/Kconfig | 2 +-
arch/powerpc/Kconfig | 2 +-
arch/sparc64/Kconfig | 2 +-
arch/x86_64/Kconfig | 2 +-
include/asm-powerpc/kprobes.h | 22 ++++++++++++++++++++++
include/linux/kprobes.h | 6 ++++++
kernel/kallsyms.c | 1 -
kernel/kprobes.c | 26 ++++++++++++++++++++++++++
net/ipv4/tcp_probe.c | 6 ++++--
10 files changed, 63 insertions(+), 8 deletions(-)
--- NEW FILE linux-2.6-kprobes-portable.patch ---
diff -rup a/arch/i386/Kconfig b/arch/i386/Kconfig
--- a/arch/i386/Kconfig 2006-09-06 13:19:06.626705000 +0000
+++ b/arch/i386/Kconfig 2006-09-06 13:32:48.266766000 +0000
@@ -1183,7 +1183,7 @@ source "arch/i386/oprofile/Kconfig"
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
- depends on EXPERIMENTAL && MODULES
+ depends on KALLSYMS && EXPERIMENTAL && MODULES
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
diff -rup a/arch/ia64/Kconfig b/arch/ia64/Kconfig
--- a/arch/ia64/Kconfig 2006-09-06 13:18:44.867220000 +0000
+++ b/arch/ia64/Kconfig 2006-09-06 13:32:48.276767000 +0000
@@ -562,7 +562,7 @@ source "arch/ia64/oprofile/Kconfig"
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
- depends on EXPERIMENTAL && MODULES
+ depends on KALLSYMS && EXPERIMENTAL && MODULES
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
diff -rup a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
--- a/arch/powerpc/Kconfig 2006-09-06 13:18:38.214089000 +0000
+++ b/arch/powerpc/Kconfig 2006-09-06 13:32:48.286767000 +0000
@@ -1075,7 +1075,7 @@ source "arch/powerpc/oprofile/Kconfig"
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
- depends on PPC64 && EXPERIMENTAL && MODULES
+ depends on PPC64 && KALLSYMS && EXPERIMENTAL && MODULES
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
diff -rup a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
--- a/arch/sparc64/Kconfig 2006-09-06 13:17:28.086544000 +0000
+++ b/arch/sparc64/Kconfig 2006-09-06 13:32:48.294766000 +0000
@@ -416,7 +416,7 @@ source "arch/sparc64/oprofile/Kconfig"
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
- depends on EXPERIMENTAL && MODULES
+ depends on KALLSYMS && EXPERIMENTAL && MODULES
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
diff -rup a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig 2006-09-06 13:18:45.263243000 +0000
+++ b/arch/x86_64/Kconfig 2006-09-06 13:32:48.302767000 +0000
@@ -686,7 +686,7 @@ source "arch/x86_64/oprofile/Kconfig"
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
- depends on EXPERIMENTAL && MODULES
+ depends on KALLSYMS && EXPERIMENTAL && MODULES
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
diff -rup a/include/asm-powerpc/kprobes.h b/include/asm-powerpc/kprobes.h
--- a/include/asm-powerpc/kprobes.h 2006-09-06 13:18:17.894626000 +0000
+++ b/include/asm-powerpc/kprobes.h 2006-09-06 13:36:19.027386000 +0000
@@ -44,6 +44,28 @@ typedef unsigned int kprobe_opcode_t;
#define IS_TDI(instr) (((instr) & 0xfc000000) == 0x08000000)
#define IS_TWI(instr) (((instr) & 0xfc000000) == 0x0c000000)
+/*
+ * 64bit powerpc uses function descriptors.
+ * Handle cases where:
+ * - User passes a <.symbol> or <module:.symbol>
+ * - User passes a <symbol> or <module:symbol>
+ * - User passes a non-existant symbol, kallsyms_lookup_name
+ * returns 0. Don't deref the NULL pointer in that case
+ */
+#define kprobe_lookup_name(name, addr) \
+{ \
+ addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
+ if (addr) { \
+ char *colon; \
+ if ((colon = strchr(name, ':')) != NULL) { \
+ colon++; \
+ if (*colon != '\0' && *colon != '.') \
+ addr = *(kprobe_opcode_t **)addr; \
+ } else if (name[0] != '.') \
+ addr = *(kprobe_opcode_t **)addr; \
+ } \
+}
+
#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry)
#define is_trap(instr) (IS_TW(instr) || IS_TD(instr) || \
diff -rup a/include/linux/kprobes.h b/include/linux/kprobes.h
--- a/include/linux/kprobes.h 2006-09-06 13:18:21.991714000 +0000
+++ b/include/linux/kprobes.h 2006-09-06 13:32:48.316766000 +0000
@@ -77,6 +77,12 @@ struct kprobe {
/* location of the probe point */
kprobe_opcode_t *addr;
+ /* Allow user to indicate symbol name of the probe point */
+ char *symbol_name;
+
+ /* Offset into the symbol */
+ unsigned int offset;
+
/* Called before addr is executed. */
kprobe_pre_handler_t pre_handler;
diff -rup a/kernel/kallsyms.c b/kernel/kallsyms.c
--- a/kernel/kallsyms.c 2006-09-06 13:18:25.018781000 +0000
+++ b/kernel/kallsyms.c 2006-09-06 13:32:48.324767000 +0000
@@ -154,7 +154,6 @@ unsigned long kallsyms_lookup_name(const
}
return module_kallsyms_lookup_name(name);
}
-EXPORT_SYMBOL_GPL(kallsyms_lookup_name);
/*
* Lookup an address
diff -rup a/kernel/kprobes.c b/kernel/kprobes.c
--- a/kernel/kprobes.c 2006-09-06 13:18:25.041780000 +0000
+++ b/kernel/kprobes.c 2006-09-06 13:32:48.333767000 +0000
@@ -37,6 +37,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/moduleloader.h>
+#include <linux/kallsyms.h>
#include <asm-generic/sections.h>
#include <asm/cacheflush.h>
#include <asm/errno.h>
@@ -45,6 +46,16 @@
#define KPROBE_HASH_BITS 6
#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
+
+/*
+ * Some oddball architectures like 64bit powerpc have function descriptors
+ * so this must be overridable.
+ */
+#ifndef kprobe_lookup_name
+#define kprobe_lookup_name(name, addr) \
+ addr = ((kprobe_opcode_t *)(kallsyms_lookup_name(name)))
+#endif
+
static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
static atomic_t kprobe_count;
@@ -447,6 +458,21 @@ static int __kprobes __register_kprobe(s
struct kprobe *old_p;
struct module *probed_mod;
+ /*
+ * If we have a symbol_name argument look it up,
+ * and add it to the address. That way the addr
+ * field can either be global or relative to a symbol.
+ */
+ if (p->symbol_name) {
+ if (p->addr)
+ return -EINVAL;
+ kprobe_lookup_name(p->symbol_name, p->addr);
+ }
+
+ if (!p->addr)
+ return -EINVAL;
+ p->addr = (kprobe_opcode_t *)(((char *)p->addr)+ p->offset);
+
if ((!kernel_text_address((unsigned long) p->addr)) ||
in_kprobes_functions((unsigned long) p->addr))
return -EINVAL;
diff -rup a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
--- a/net/ipv4/tcp_probe.c 2006-09-06 13:18:28.794868000 +0000
+++ b/net/ipv4/tcp_probe.c 2006-09-06 13:32:48.341766000 +0000
@@ -99,8 +99,10 @@ static int jtcp_sendmsg(struct kiocb *io
}
static struct jprobe tcp_send_probe = {
- .kp = { .addr = (kprobe_opcode_t *) &tcp_sendmsg, },
- .entry = (kprobe_opcode_t *) &jtcp_sendmsg,
+ .kp = {
+ .symbol_name = "tcp_sendmsg",
+ },
+ .entry = JPROBE_ENTRY(jtcp_sendmsg),
};
Index: kernel-2.6.spec
===================================================================
RCS file: /cvs/dist/rpms/kernel/devel/kernel-2.6.spec,v
retrieving revision 1.2651
retrieving revision 1.2652
diff -u -r1.2651 -r1.2652
--- kernel-2.6.spec 14 Sep 2006 15:21:49 -0000 1.2651
+++ kernel-2.6.spec 14 Sep 2006 17:57:05 -0000 1.2652
@@ -511,6 +511,11 @@
# Infiniband driver
Patch2600: linux-2.6-openib-sdp.patch
+# kprobes changes.
+Patch2700: linux-2.6-kprobes-portable.patch
+Patch2701: linux-2.6-kprobes-documentation.patch
+Patch2702: linux-2.6-kprobes-add-regs_return_value-helper.patch
+
#
# 10000 to 20000 is for stuff that has to come last due to the
# amount of drivers they touch. But only these should go here.
@@ -1105,6 +1110,11 @@
# Infiniband driver
%patch2600 -p1
+# kprobe changes
+%patch2700 -p1
+%patch2701 -p1
+%patch2702 -p1
+
#
# Patches 5000 to 6000 are reserved for new drivers that are about to
# be merged upstream
@@ -1882,6 +1892,9 @@
%endif
%changelog
+* Thu Sep 14 2006 Dave Jones <davej at redhat.com>
+- kprobe changes to make systemtap's life easier.
+
* Thu Sep 14 2006 Don Zickus <dzickus at redhat.com>
- sync up beta1 fixes and patches
- includes infiniband driver
- Previous message (by thread): rpms/dbus/devel .cvsignore, 1.21, 1.22 dbus-0.61-selinux-avc-audit.patch, 1.2, 1.3 dbus-0.92-audit-system.patch, 1.1, 1.2 dbus.spec, 1.96, 1.97 sources, 1.21, 1.22
- Next message (by thread): rpms/poppler/devel poppler.spec,1.30,1.31
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the fedora-cvs-commits
mailing list