Merge branch 'perf-probes-for-linus-2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-probes-for-linus-2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86: Issue at least one memory barrier in stop_machine_text_poke() perf probe: Correct probe syntax on command line help perf probe: Add lazy line matching support perf probe: Show more lines after last line perf probe: Check function address range strictly in line finder perf probe: Use libdw callback routines perf probe: Use elfutils-libdw for analyzing debuginfo perf probe: Rename probe finder functions perf probe: Fix bugs in line range finder perf probe: Update perf probe document perf probe: Do not show --line option without dwarf support kprobes: Add documents of jump optimization kprobes/x86: Support kprobes jump optimization on x86 x86: Add text_poke_smp for SMP cross modifying code kprobes/x86: Cleanup save/restore registers kprobes/x86: Boost probes when reentering kprobes: Jump optimization sysctl interface kprobes: Introduce kprobes jump optimization kprobes: Introduce generic insn_slot framework kprobes/x86: Cleanup RELATIVEJUMP_INSTRUCTION to RELATIVEJUMP_OPCODE
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/memory.h>
|
||||
#include <linux/stop_machine.h>
|
||||
#include <asm/alternative.h>
|
||||
#include <asm/sections.h>
|
||||
#include <asm/pgtable.h>
|
||||
@ -572,3 +573,62 @@ void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
|
||||
local_irq_restore(flags);
|
||||
return addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cross-modifying kernel text with stop_machine().
|
||||
* This code originally comes from immediate value.
|
||||
*/
|
||||
static atomic_t stop_machine_first;
|
||||
static int wrote_text;
|
||||
|
||||
struct text_poke_params {
|
||||
void *addr;
|
||||
const void *opcode;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
static int __kprobes stop_machine_text_poke(void *data)
|
||||
{
|
||||
struct text_poke_params *tpp = data;
|
||||
|
||||
if (atomic_dec_and_test(&stop_machine_first)) {
|
||||
text_poke(tpp->addr, tpp->opcode, tpp->len);
|
||||
smp_wmb(); /* Make sure other cpus see that this has run */
|
||||
wrote_text = 1;
|
||||
} else {
|
||||
while (!wrote_text)
|
||||
cpu_relax();
|
||||
smp_mb(); /* Load wrote_text before following execution */
|
||||
}
|
||||
|
||||
flush_icache_range((unsigned long)tpp->addr,
|
||||
(unsigned long)tpp->addr + tpp->len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* text_poke_smp - Update instructions on a live kernel on SMP
|
||||
* @addr: address to modify
|
||||
* @opcode: source of the copy
|
||||
* @len: length to copy
|
||||
*
|
||||
* Modify multi-byte instruction by using stop_machine() on SMP. This allows
|
||||
* user to poke/set multi-byte text on SMP. Only non-NMI/MCE code modifying
|
||||
* should be allowed, since stop_machine() does _not_ protect code against
|
||||
* NMI and MCE.
|
||||
*
|
||||
* Note: Must be called under get_online_cpus() and text_mutex.
|
||||
*/
|
||||
void *__kprobes text_poke_smp(void *addr, const void *opcode, size_t len)
|
||||
{
|
||||
struct text_poke_params tpp;
|
||||
|
||||
tpp.addr = addr;
|
||||
tpp.opcode = opcode;
|
||||
tpp.len = len;
|
||||
atomic_set(&stop_machine_first, 1);
|
||||
wrote_text = 0;
|
||||
stop_machine(stop_machine_text_poke, (void *)&tpp, NULL);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user