Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 141046
b: refs/heads/master
c: 1a17662
h: refs/heads/master
v: v3
  • Loading branch information
Li Zefan authored and Ingo Molnar committed Mar 21, 2009
1 parent 943dbf9 commit 69809d6
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 474 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fee039a1d05c6e0f71b0fe270d847742a02d56c4
refs/heads/master: 1a17662ea033674a58bad3603531b0b5d42572f6
63 changes: 23 additions & 40 deletions trunk/arch/x86/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
*
* 1) Put the instruction pointer into the IP buffer
* and the new code into the "code" buffer.
* 2) Wait for any running NMIs to finish and set a flag that says
* we are modifying code, it is done in an atomic operation.
* 3) Write the code
* 4) clear the flag.
* 5) Wait for any running NMIs to finish.
* 2) Set a flag that says we are modifying code
* 3) Wait for any running NMIs to finish.
* 4) Write the code
* 5) clear the flag.
* 6) Wait for any running NMIs to finish.
*
* If an NMI is executed, the first thing it does is to call
* "ftrace_nmi_enter". This will check if the flag is set to write
Expand All @@ -95,9 +95,9 @@ static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
* are the same as what exists.
*/

#define MOD_CODE_WRITE_FLAG (1 << 31) /* set when NMI should do the write */
static atomic_t nmi_running = ATOMIC_INIT(0);
static int mod_code_status; /* holds return value of text write */
static int mod_code_write; /* set when NMI should do the write */
static void *mod_code_ip; /* holds the IP to write to */
static void *mod_code_newcode; /* holds the text to write to the IP */

Expand All @@ -114,20 +114,6 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
return r;
}

static void clear_mod_flag(void)
{
int old = atomic_read(&nmi_running);

for (;;) {
int new = old & ~MOD_CODE_WRITE_FLAG;

if (old == new)
break;

old = atomic_cmpxchg(&nmi_running, old, new);
}
}

static void ftrace_mod_code(void)
{
/*
Expand All @@ -141,39 +127,27 @@ static void ftrace_mod_code(void)

/* if we fail, then kill any new writers */
if (mod_code_status)
clear_mod_flag();
mod_code_write = 0;
}

void ftrace_nmi_enter(void)
{
if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
smp_rmb();
atomic_inc(&nmi_running);
/* Must have nmi_running seen before reading write flag */
smp_mb();
if (mod_code_write) {
ftrace_mod_code();
atomic_inc(&nmi_update_count);
}
/* Must have previous changes seen before executions */
smp_mb();
}

void ftrace_nmi_exit(void)
{
/* Finish all executions before clearing nmi_running */
smp_mb();
smp_wmb();
atomic_dec(&nmi_running);
}

static void wait_for_nmi_and_set_mod_flag(void)
{
if (!atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG))
return;

do {
cpu_relax();
} while (atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG));

nmi_wait_count++;
}

static void wait_for_nmi(void)
{
if (!atomic_read(&nmi_running))
Expand All @@ -193,19 +167,28 @@ do_ftrace_mod_code(unsigned long ip, void *new_code)
mod_code_newcode = new_code;

/* The buffers need to be visible before we let NMIs write them */
smp_wmb();

mod_code_write = 1;

/* Make sure write bit is visible before we wait on NMIs */
smp_mb();

wait_for_nmi_and_set_mod_flag();
wait_for_nmi();

/* Make sure all running NMIs have finished before we write the code */
smp_mb();

ftrace_mod_code();

/* Make sure the write happens before clearing the bit */
smp_wmb();

mod_code_write = 0;

/* make sure NMIs see the cleared bit */
smp_mb();

clear_mod_flag();
wait_for_nmi();

return mod_code_status;
Expand Down
17 changes: 8 additions & 9 deletions trunk/arch/x86/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
#else
" pushf\n"
/*
* Skip cs, ip, orig_ax and gs.
* Skip cs, ip, orig_ax.
* trampoline_handler() will plug in these values
*/
" subl $16, %esp\n"
" subl $12, %esp\n"
" pushl %fs\n"
" pushl %es\n"
" pushl %ds\n"
" pushl %es\n"
" pushl %eax\n"
" pushl %ebp\n"
" pushl %edi\n"
Expand All @@ -655,19 +655,19 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
" movl %esp, %eax\n"
" call trampoline_handler\n"
/* Move flags to cs */
" movl 56(%esp), %edx\n"
" movl %edx, 52(%esp)\n"
" movl 52(%esp), %edx\n"
" movl %edx, 48(%esp)\n"
/* Replace saved flags with true return address. */
" movl %eax, 56(%esp)\n"
" movl %eax, 52(%esp)\n"
" popl %ebx\n"
" popl %ecx\n"
" popl %edx\n"
" popl %esi\n"
" popl %edi\n"
" popl %ebp\n"
" popl %eax\n"
/* Skip ds, es, fs, gs, orig_ax and ip */
" addl $24, %esp\n"
/* Skip ip, orig_ax, es, ds, fs */
" addl $20, %esp\n"
" popf\n"
#endif
" ret\n");
Expand All @@ -691,7 +691,6 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
regs->cs = __KERNEL_CS;
#else
regs->cs = __KERNEL_CS | get_kernel_rpl();
regs->gs = 0;
#endif
regs->ip = trampoline_address;
regs->orig_ax = ~0UL;
Expand Down
14 changes: 2 additions & 12 deletions trunk/kernel/extable.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,11 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/ftrace.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/init.h>

#include <asm/sections.h>
#include <linux/ftrace.h>
#include <asm/uaccess.h>

/*
* mutex protecting text section modification (dynamic code patching).
* some users need to sleep (allocating memory...) while they hold this lock.
*
* NOT exported to modules - patching kernel text is a really delicate matter.
*/
DEFINE_MUTEX(text_mutex);
#include <asm/sections.h>

extern struct exception_table_entry __start___ex_table[];
extern struct exception_table_entry __stop___ex_table[];
Expand Down
1 change: 0 additions & 1 deletion trunk/kernel/trace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ obj-$(CONFIG_EVENT_TRACER) += trace_events.o
obj-$(CONFIG_EVENT_TRACER) += events.o
obj-$(CONFIG_EVENT_TRACER) += trace_export.o
obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o

libftrace-y := ftrace.o
2 changes: 1 addition & 1 deletion trunk/kernel/trace/blktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (!blk_tree_root) {
blk_tree_root = debugfs_create_dir("block", NULL);
if (!blk_tree_root)
return -ENOMEM;
goto err;
}

dir = debugfs_create_dir(buts->name, blk_tree_root);
Expand Down
1 change: 1 addition & 0 deletions trunk/kernel/trace/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
#include "trace_events_stage_2.h"
#include "trace_events_stage_3.h"

#include <trace/trace_event_types.h>
8 changes: 4 additions & 4 deletions trunk/kernel/trace/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
extern int ring_buffer_page_too_big(void);

#ifdef CONFIG_HOTPLUG_CPU
static int rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu);
static int __cpuinit rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu);
#endif

/**
Expand Down Expand Up @@ -2784,8 +2784,8 @@ static __init int rb_init_debugfs(void)
fs_initcall(rb_init_debugfs);

#ifdef CONFIG_HOTPLUG_CPU
static int rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
static int __cpuinit rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
{
struct ring_buffer *buffer =
container_of(self, struct ring_buffer, cpu_notify);
Expand Down
Loading

0 comments on commit 69809d6

Please sign in to comment.