From: tip-bot for Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
mathieu.desnoyers@efficios.com, rusty@rustcorp.com.au,
ananth@in.ibm.com, masami.hiramatsu.pt@hitachi.com,
fweisbec@gmail.com, jbeulich@novell.com, rostedt@goodmis.org,
jbaron@redhat.com, tglx@linutronix.de, mhiramat@redhat.com,
mingo@elte.hu
Subject: [tip:perf/core] x86: Introduce text_poke_smp_batch() for batch-code modifying
Date: Mon, 6 Dec 2010 18:17:32 GMT [thread overview]
Message-ID: <tip-7deb18dcf0478940ac979de002db1ed8ba6531dc@git.kernel.org> (raw)
In-Reply-To: <20101203095422.2961.51217.stgit@ltc236.sdl.hitachi.co.jp>
Commit-ID: 7deb18dcf0478940ac979de002db1ed8ba6531dc
Gitweb: http://git.kernel.org/tip/7deb18dcf0478940ac979de002db1ed8ba6531dc
Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Fri, 3 Dec 2010 18:54:22 +0900
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 6 Dec 2010 17:59:31 +0100
x86: Introduce text_poke_smp_batch() for batch-code modifying
Introduce text_poke_smp_batch(). This function modifies several
text areas with one stop_machine() on SMP. Because calling
stop_machine() is heavy task, it is better to aggregate
text_poke requests.
( Note: I've talked with Rusty about this interface, and
he would not like to expand stop_machine() interface, since
it is not for generic use. )
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: 2nddept-manager@sdl.hitachi.co.jp
LKML-Reference: <20101203095422.2961.51217.stgit@ltc236.sdl.hitachi.co.jp>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/include/asm/alternative.h | 7 +++++
arch/x86/kernel/alternative.c | 49 +++++++++++++++++++++++++++++------
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
index 76561d2..4a2adaa 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -180,8 +180,15 @@ extern void *text_poke_early(void *addr, const void *opcode, size_t len);
* On the local CPU you need to be protected again NMI or MCE handlers seeing an
* inconsistent instruction while you patch.
*/
+struct text_poke_param {
+ void *addr;
+ const void *opcode;
+ size_t len;
+};
+
extern void *text_poke(void *addr, const void *opcode, size_t len);
extern void *text_poke_smp(void *addr, const void *opcode, size_t len);
+extern void text_poke_smp_batch(struct text_poke_param *params, int n);
#if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
#define IDEAL_NOP_SIZE_5 5
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 5079f24..553d0b0 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -591,17 +591,21 @@ static atomic_t stop_machine_first;
static int wrote_text;
struct text_poke_params {
- void *addr;
- const void *opcode;
- size_t len;
+ struct text_poke_param *params;
+ int nparams;
};
static int __kprobes stop_machine_text_poke(void *data)
{
struct text_poke_params *tpp = data;
+ struct text_poke_param *p;
+ int i;
if (atomic_dec_and_test(&stop_machine_first)) {
- text_poke(tpp->addr, tpp->opcode, tpp->len);
+ for (i = 0; i < tpp->nparams; i++) {
+ p = &tpp->params[i];
+ text_poke(p->addr, p->opcode, p->len);
+ }
smp_wmb(); /* Make sure other cpus see that this has run */
wrote_text = 1;
} else {
@@ -610,8 +614,12 @@ static int __kprobes stop_machine_text_poke(void *data)
smp_mb(); /* Load wrote_text before following execution */
}
- flush_icache_range((unsigned long)tpp->addr,
- (unsigned long)tpp->addr + tpp->len);
+ for (i = 0; i < tpp->nparams; i++) {
+ p = &tpp->params[i];
+ flush_icache_range((unsigned long)p->addr,
+ (unsigned long)p->addr + p->len);
+ }
+
return 0;
}
@@ -631,10 +639,13 @@ static int __kprobes stop_machine_text_poke(void *data)
void *__kprobes text_poke_smp(void *addr, const void *opcode, size_t len)
{
struct text_poke_params tpp;
+ struct text_poke_param p;
- tpp.addr = addr;
- tpp.opcode = opcode;
- tpp.len = len;
+ p.addr = addr;
+ p.opcode = opcode;
+ p.len = len;
+ tpp.params = &p;
+ tpp.nparams = 1;
atomic_set(&stop_machine_first, 1);
wrote_text = 0;
/* Use __stop_machine() because the caller already got online_cpus. */
@@ -642,6 +653,26 @@ void *__kprobes text_poke_smp(void *addr, const void *opcode, size_t len)
return addr;
}
+/**
+ * text_poke_smp_batch - Update instructions on a live kernel on SMP
+ * @params: an array of text_poke parameters
+ * @n: the number of elements in params.
+ *
+ * Modify multi-byte instruction by using stop_machine() on SMP. Since the
+ * stop_machine() is heavy task, it is better to aggregate text_poke requests
+ * and do it once if possible.
+ *
+ * Note: Must be called under get_online_cpus() and text_mutex.
+ */
+void __kprobes text_poke_smp_batch(struct text_poke_param *params, int n)
+{
+ struct text_poke_params tpp = {.params = params, .nparams = n};
+
+ atomic_set(&stop_machine_first, 1);
+ wrote_text = 0;
+ stop_machine(stop_machine_text_poke, (void *)&tpp, NULL);
+}
+
#if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
#ifdef CONFIG_X86_64
next prev parent reply other threads:[~2010-12-06 18:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-03 9:53 [PATCH -tip v5 0/8] Kprobes/x86: Batch optimization support Masami Hiramatsu
2010-12-03 9:53 ` [PATCH -tip v5 1/8] [CLEANUP] kprobes: Rename old_p to more appropriate name Masami Hiramatsu
2010-12-06 18:15 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03 9:53 ` [PATCH -tip v5 2/8] [CLEANUP]kprobes: Cleanup disabling and unregistering path Masami Hiramatsu
2010-12-06 18:16 ` [tip:perf/core] kprobes: " tip-bot for Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 3/8] [CLEANUP]kprobes: Separate kprobe optimizing code from optimizer Masami Hiramatsu
2010-12-06 18:16 ` [tip:perf/core] kprobes: " tip-bot for Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 4/8] kprobes: Support delayed unoptimizing Masami Hiramatsu
2010-12-06 18:16 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 5/8] kprobes: Reuse unused kprobe Masami Hiramatsu
2010-12-06 18:17 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 6/8] x86: Introduce text_poke_smp_batch() for batch-code modifying Masami Hiramatsu
2010-12-03 14:44 ` Steven Rostedt
2010-12-06 18:17 ` tip-bot for Masami Hiramatsu [this message]
2011-02-11 21:07 ` [tip:perf/core] " Peter Zijlstra
2011-02-12 1:36 ` [tip:perf/urgent] x86: Fix text_poke_smp_batch() deadlock tip-bot for Peter Zijlstra
2011-02-14 1:25 ` [tip:perf/core] x86: Introduce text_poke_smp_batch() for batch-code modifying Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 7/8] kprobes: Use text_poke_smp_batch for optimizing Masami Hiramatsu
2010-12-06 18:17 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03 9:54 ` [PATCH -tip v5 8/8] kprobes: Use text_poke_smp_batch for unoptimizing Masami Hiramatsu
2010-12-06 18:18 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
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=tip-7deb18dcf0478940ac979de002db1ed8ba6531dc@git.kernel.org \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=ananth@in.ibm.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=jbaron@redhat.com \
--cc=jbeulich@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@redhat.com \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
/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