From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Ingo Molnar <mingo@elte.hu>
Cc: Masami Hiramatsu <mhiramat@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nick Piggin <npiggin@suse.de>,
Steven Rostedt <rostedt@goodmis.org>,
Andi Kleen <andi@firstfloor.org>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Arjan van de Ven <arjan@infradead.org>,
Rusty Russell <rusty@rustcorp.com.au>,
"H. Peter Anvin" <hpa@zytor.com>,
Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH] Text Edit Lock - Architecture Independent Code
Date: Mon, 2 Mar 2009 19:00:54 -0500 [thread overview]
Message-ID: <20090303000054.GC3906@Krystal> (raw)
In-Reply-To: <20090302234910.GA17956@elte.hu>
This is an architecture independant synchronization around kernel text
modifications through use of a global mutex.
A mutex has been chosen so that kprobes, the main user of this, can sleep during
memory allocation between the memory read of the instructions it must replace
and the memory write of the breakpoint.
Other user of this interface: immediate values.
Paravirt and alternatives are always done when SMP is inactive, so there is no
need to use locks.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Andi Kleen <andi@firstfloor.org>
CC: Ingo Molnar <mingo@elte.hu>
---
include/linux/memory.h | 7 +++++++
mm/memory.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
Index: linux-2.6-lttng/include/linux/memory.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/memory.h 2009-01-30 09:47:59.000000000 -0500
+++ linux-2.6-lttng/include/linux/memory.h 2009-01-30 10:25:33.000000000 -0500
@@ -99,4 +99,11 @@ enum mem_add_context { BOOT, HOTPLUG };
#define hotplug_memory_notifier(fn, pri) do { } while (0)
#endif
+/*
+ * Take and release the kernel text modification lock, used for code patching.
+ * Users of this lock can sleep.
+ */
+extern void kernel_text_lock(void);
+extern void kernel_text_unlock(void);
+
#endif /* _LINUX_MEMORY_H_ */
Index: linux-2.6-lttng/mm/memory.c
===================================================================
--- linux-2.6-lttng.orig/mm/memory.c 2009-01-30 09:47:59.000000000 -0500
+++ linux-2.6-lttng/mm/memory.c 2009-01-30 10:26:01.000000000 -0500
@@ -48,6 +48,8 @@
#include <linux/rmap.h>
#include <linux/module.h>
#include <linux/delayacct.h>
+#include <linux/kprobes.h>
+#include <linux/mutex.h>
#include <linux/init.h>
#include <linux/writeback.h>
#include <linux/memcontrol.h>
@@ -99,6 +101,12 @@ int randomize_va_space __read_mostly =
2;
#endif
+/*
+ * mutex protecting text section modification (dynamic code patching).
+ * some users need to sleep (allocating memory...) while they hold this lock.
+ */
+static DEFINE_MUTEX(text_mutex);
+
static int __init disable_randmaps(char *s)
{
randomize_va_space = 0;
@@ -3192,3 +3200,29 @@ void might_fault(void)
}
EXPORT_SYMBOL(might_fault);
#endif
+
+/**
+ * kernel_text_lock - Take the kernel text modification lock
+ *
+ * Insures mutual write exclusion of kernel and modules text live text
+ * modification. Should be used for code patching.
+ * Users of this lock can sleep.
+ */
+void __kprobes kernel_text_lock(void)
+{
+ mutex_lock(&text_mutex);
+}
+EXPORT_SYMBOL_GPL(kernel_text_lock);
+
+/**
+ * kernel_text_unlock - Release the kernel text modification lock
+ *
+ * Insures mutual write exclusion of kernel and modules text live text
+ * modification. Should be used for code patching.
+ * Users of this lock can sleep.
+ */
+void __kprobes kernel_text_unlock(void)
+{
+ mutex_unlock(&text_mutex);
+}
+EXPORT_SYMBOL_GPL(kernel_text_unlock);
--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2009-03-03 0:02 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-20 1:13 [git pull] changes for tip, and a nasty x86 page table bug Steven Rostedt
2009-02-20 1:13 ` [PATCH 1/6] x86: check PMD in spurious_fault handler Steven Rostedt
2009-02-20 1:13 ` [PATCH 2/6] x86: keep pmd rw bit set when creating 4K level pages Steven Rostedt
2009-02-20 1:13 ` [PATCH 3/6] ftrace: allow archs to preform pre and post process for code modification Steven Rostedt
2009-02-20 1:13 ` [PATCH 4/6] ftrace, x86: make kernel text writable only for conversions Steven Rostedt
2009-02-20 1:32 ` Andrew Morton
2009-02-20 1:44 ` Steven Rostedt
2009-02-20 2:05 ` [PATCH][git pull] update to tip/tracing/ftrace Steven Rostedt
2009-02-22 17:50 ` [PATCH 4/6] ftrace, x86: make kernel text writable only for conversions Andi Kleen
2009-02-22 22:53 ` Steven Rostedt
2009-02-23 0:29 ` Andi Kleen
2009-02-23 2:33 ` Mathieu Desnoyers
2009-02-23 4:29 ` Steven Rostedt
2009-02-23 4:53 ` Mathieu Desnoyers
2009-02-23 14:48 ` Steven Rostedt
2009-02-23 15:42 ` Mathieu Desnoyers
2009-02-23 15:51 ` Steven Rostedt
2009-02-23 15:55 ` Steven Rostedt
2009-02-23 16:13 ` Mathieu Desnoyers
2009-02-23 16:48 ` Steven Rostedt
2009-02-23 17:31 ` Mathieu Desnoyers
2009-02-23 18:17 ` Steven Rostedt
2009-02-23 18:34 ` Mathieu Desnoyers
2009-02-27 17:52 ` Masami Hiramatsu
2009-02-27 18:07 ` Mathieu Desnoyers
2009-02-27 18:34 ` Masami Hiramatsu
2009-02-27 18:53 ` Mathieu Desnoyers
2009-02-27 20:57 ` Masami Hiramatsu
2009-03-02 17:01 ` [RFC][PATCH] x86: make text_poke() atomic Masami Hiramatsu
2009-03-02 17:19 ` Mathieu Desnoyers
2009-03-02 22:15 ` Masami Hiramatsu
2009-03-02 22:22 ` Ingo Molnar
2009-03-02 22:55 ` Masami Hiramatsu
2009-03-02 23:09 ` Ingo Molnar
2009-03-02 23:38 ` Masami Hiramatsu
2009-03-02 23:49 ` Ingo Molnar
2009-03-03 0:00 ` Mathieu Desnoyers
2009-03-03 0:00 ` Mathieu Desnoyers [this message]
2009-03-03 0:32 ` [PATCH] Text Edit Lock - Architecture Independent Code Ingo Molnar
2009-03-03 0:39 ` Mathieu Desnoyers
2009-03-03 1:30 ` [PATCH] Text Edit Lock - Architecture Independent Code (v2) Mathieu Desnoyers
2009-03-03 1:31 ` [PATCH] Text Edit Lock - kprobes architecture independent support (v2) Mathieu Desnoyers
2009-03-03 9:27 ` Ingo Molnar
2009-03-03 12:06 ` Ananth N Mavinakayanahalli
2009-03-03 14:28 ` Mathieu Desnoyers
2009-03-03 14:33 ` [PATCH] Text Edit Lock - kprobes architecture independent support (v3) Mathieu Desnoyers
2009-03-03 14:53 ` [PATCH] Text Edit Lock - kprobes architecture independent support (v2) Ingo Molnar
2009-03-03 0:01 ` [PATCH] Text Edit Lock - kprobes architecture independent support Mathieu Desnoyers
2009-03-03 0:10 ` Masami Hiramatsu
2009-03-03 0:05 ` [RFC][PATCH] x86: make text_poke() atomic Masami Hiramatsu
2009-03-03 0:22 ` Ingo Molnar
2009-03-03 0:31 ` Masami Hiramatsu
2009-03-03 16:31 ` [PATCH] x86: make text_poke() atomic using fixmap Masami Hiramatsu
2009-03-03 17:08 ` Mathieu Desnoyers
2009-03-05 10:38 ` Ingo Molnar
2009-03-06 14:06 ` Ingo Molnar
2009-03-06 14:49 ` Masami Hiramatsu
2009-03-02 18:28 ` [RFC][PATCH] x86: make text_poke() atomic Arjan van de Ven
2009-03-02 18:36 ` Mathieu Desnoyers
2009-03-02 18:55 ` Arjan van de Ven
2009-03-02 19:13 ` Masami Hiramatsu
2009-03-02 19:23 ` H. Peter Anvin
2009-03-02 19:47 ` Mathieu Desnoyers
2009-03-02 18:42 ` Linus Torvalds
2009-03-03 4:54 ` Nick Piggin
2009-02-23 18:23 ` [PATCH 4/6] ftrace, x86: make kernel text writable only for conversions Steven Rostedt
2009-02-23 9:02 ` Ingo Molnar
2009-02-27 21:08 ` Pavel Machek
2009-02-28 16:56 ` Andi Kleen
2009-02-28 22:08 ` Pavel Machek
[not found] ` <87wsba1a9f.fsf@basil.nowhere.org>
2009-02-28 22:19 ` Pavel Machek
2009-02-28 23:52 ` Andi Kleen
2009-02-20 1:13 ` [PATCH 5/6] ftrace: immediately stop code modification if failure is detected Steven Rostedt
2009-02-20 1:13 ` [PATCH 6/6] ftrace: break out modify loop immediately on detection of error Steven Rostedt
2009-02-20 2:00 ` [git pull] changes for tip, and a nasty x86 page table bug Linus Torvalds
2009-02-20 2:08 ` Steven Rostedt
2009-02-20 3:44 ` Linus Torvalds
2009-02-20 4:00 ` Steven Rostedt
2009-02-20 4:17 ` Linus Torvalds
2009-02-20 4:34 ` Steven Rostedt
2009-02-20 5:02 ` Huang Ying
2009-02-20 7:29 ` [PATCH] x86: use the right protections for split-up pagetables Ingo Molnar
2009-02-20 7:39 ` [PATCH, v2] " Ingo Molnar
2009-02-20 8:02 ` Ingo Molnar
2009-02-20 10:24 ` Ingo Molnar
2009-02-20 13:57 ` [PATCH] " Steven Rostedt
2009-02-20 15:40 ` Linus Torvalds
2009-02-20 16:59 ` Ingo Molnar
2009-02-20 18:33 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090303000054.GC3906@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=arjan@infradead.org \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@redhat.com \
--cc=mingo@elte.hu \
--cc=npiggin@suse.de \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=srostedt@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox