Skip to contentSkip to conversation

Linux Kernel Markers 0.6 for 2.6.17

PATCH In review Mathieu Desnoyers 2 participants 2 messages Sep 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Linux Kernel Markers 0.6 for 2.6.17

Hi,

Thanks to everyone's advices, here is yet yet again a new LKM version. The principal improvement is the use of an asmlinkage declaration for the probe function to make sure that the variable arguments will be correctly received by the probe, even if it is not expecting a variable argument list.

Mathieu

---BEGIN---

arch/i386/Kconfig +2 -0
@@ -1082,6 +1082,8 @@ config KPROBES
 	  for kernel debugging, non-intrusive instrumentation and testing.
 	  If in doubt, say "N".
 
+source "kernel/Kconfig.marker"
+
 source "ltt/Kconfig"
 
 endmenu
include/linux/marker.h new file +119 -0

119 lines not on this page · raw message

kernel/Kconfig.marker new file +31 -0
@@ -0,0 +1,31 @@
+# Code markers configuration
+
+menu "Marker configuration"
+
+
+config MARK_SYMBOL
+	bool "Replace markers with symbols"
+	default n
+	help
+	  Put symbols in place of markers, useful for kprobe.
+
+config MARK_JUMP_CALL
+	bool "Replace markers with a jump over an inactive function call"
+	default n
+	help
+	  Put a jump over a call in place of markers.
+
+config MARK_JUMP_INLINE
+	bool "Replace markers with a jump over an inline function"
+	default n
+	help
+	  Put a jump over an inline function.
+
+config MARK_JUMP
+	bool "Jump marker probes set/disable infrastructure"
+	select KALLSYMS
+	default n
+	help
+	  Install or remove probes from markers.
+
+endmenu
kernel/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_MARK_JUMP) += marker.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/marker.c new file +178 -0

178 lines not on this page · raw message

---END---

---BEGIN---

/* probe.c
*
* Loads a function at a marker call site.
*
* (C) Copyright 2006 Mathieu Desnoyers <[email protected]> *
* This file is released under the GPLv2.
* See the file COPYING for more details.
*/

#include <linux/marker.h>
#include <linux/module.h>
#include <linux/kallsyms.h>

/* function to install */
asmlinkage void do_mark1(const char *format, int value)

{
	printk("value is %d\n", value);
}

int init_module(void)

{
	return marker_set_probe("subsys_mark1", (marker_probe_func*)do_mark1,
			MARKER_CALL);
}

void cleanup_module(void)

{
	marker_disable_probe("subsys_mark1", (marker_probe_func*)do_mark1,
		MARKER_CALL);
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mathieu Desnoyers");
MODULE_DESCRIPTION("Probe");
---END---

---BEGIN---

/* test-mark.c
*
*/

#include <linux/marker.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>

int x=7;

struct proc_dir_entry *pentry = NULL;

static int my_open(struct inode *inode, struct file *file)

{
	MARK(subsys_mark1, "%d", 1);
	MARK(subsys_mark2, "%d %s", 2, "blah2");
	MARK(subsys_mark3, "%d %s", x, "blah3");

	return -EPERM;
}

static struct file_operations my_operations = {
.open = my_open,
};

int init_module(void)

{
       pentry = create_proc_entry("testmark", 0444, NULL);
        if(pentry)
                pentry->proc_fops = &my_operations;
	return 0;
}

void cleanup_module(void)

{
	remove_proc_entry("testmark", NULL);
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mathieu Desnoyers");
MODULE_DESCRIPTION("Marker Test");

---END---

OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68 
#1 lore raw
Quoted 1 line · On Thu, 21 Sep 2006 17:56:44 -0400 Mathieu Desnoyers wrote:

Hi Mathieu,

In your next version, please use a space between "if" and "(".

Quoted 52 lines
kernel/marker.c new file +48 -0
@@ -0,0 +1,178 @@
+/* Pointers can be used around preemption disabled */
+static int marker_get_pointers(const char *name,
+	struct marker_pointers *ptrs)
+{
+	if(!(ptrs->call && ptrs->jmpselect && ptrs->jmpcall
+			&& ptrs->jmpinline && ptrs->jmpover)) {
+		return ENOENT;
+	}
+}
+
+int marker_set_probe(const char *name, marker_probe_func *probe,
+		enum marker_type type)
+{
+	if(result) {
+		printk(KERN_NOTICE
+			"Unable to find kallsyms for markers in %s\n",
+			name);
+		goto unlock;
+	}
+
+		case MARKER_CALL:
+			if(*ptrs.call != __mark_empty_function) {
+				result = EBUSY;
+				printk(KERN_NOTICE
+					"Probe already installed on "
+					"marker in %s\n",
+					name);
+				goto unlock;
+			}
+		case MARKER_INLINE:
+			if(*ptrs.jmpover == *ptrs.jmpinline) {
+				result = ENODEV;
+				printk(KERN_NOTICE
+					"No inline probe exists "
+					"for marker in %s\n",
+					name);
+				goto unlock;
+			}
+}
+
+void marker_disable_probe(const char *name, marker_probe_func *probe,
+		enum marker_type type)
+{
+	if(result)
+		goto unlock;
+
+		case MARKER_CALL:
+			if(*ptrs.call == probe) {

kernel/marker.c line 58

Quoted 10 lines
kernel/marker.c new file +10 -0
+				*ptrs.jmpselect = *ptrs.jmpover;
+				*ptrs.call = __mark_empty_function;
+			}
+		case MARKER_INLINE:
+			if(*ptrs.jmpselect == *ptrs.jmpinline)
+				*ptrs.jmpselect = *ptrs.jmpover;
+			break;
+	if(!result && type == MARKER_CALL)
+		synchronize_sched();
+}

Thanks.
---
~Randy