Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f22f9a89 authored by Abhishek Sagar's avatar Abhishek Sagar Committed by Ingo Molnar
Browse files

ftrace: avoid modifying kprobe'd records



Avoid modifying the mcount call-site if there is a kprobe installed on it.
These records are not marked as failed however. This allowed the filter
rules on them to remain up-to-date. Whenever the kprobe on the corresponding
record is removed, the record gets updated as normal.

Signed-off-by: default avatarAbhishek Sagar <sagar.abhishek@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent ecea656d
Loading
Loading
Loading
Loading
+31 −4
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <linux/hardirq.h>
#include <linux/hardirq.h>
#include <linux/kthread.h>
#include <linux/kthread.h>
#include <linux/uaccess.h>
#include <linux/uaccess.h>
#include <linux/kprobes.h>
#include <linux/ftrace.h>
#include <linux/ftrace.h>
#include <linux/sysctl.h>
#include <linux/sysctl.h>
#include <linux/ctype.h>
#include <linux/ctype.h>
@@ -500,6 +501,10 @@ static void ftrace_replace_code(int enable)
			if (rec->flags & FTRACE_FL_FAILED)
			if (rec->flags & FTRACE_FL_FAILED)
				continue;
				continue;


			/* ignore updates to this record's mcount site */
			if (get_kprobe((void *)rec->ip))
				continue;

			failed = __ftrace_replace_code(rec, old, new, enable);
			failed = __ftrace_replace_code(rec, old, new, enable);
			if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
			if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
				rec->flags |= FTRACE_FL_FAILED;
				rec->flags |= FTRACE_FL_FAILED;
@@ -692,11 +697,11 @@ unsigned long ftrace_update_tot_cnt;


static int __ftrace_update_code(void *ignore)
static int __ftrace_update_code(void *ignore)
{
{
	int i, save_ftrace_enabled;
	cycle_t start, stop;
	struct dyn_ftrace *p;
	struct dyn_ftrace *p;
	struct hlist_node *t, *n;
	struct hlist_node *t, *n;
	int save_ftrace_enabled;
	struct hlist_head *head, temp_list;
	cycle_t start, stop;
	int i;


	/* Don't be recording funcs now */
	/* Don't be recording funcs now */
	ftrace_record_suspend++;
	ftrace_record_suspend++;
@@ -708,8 +713,11 @@ static int __ftrace_update_code(void *ignore)


	/* No locks needed, the machine is stopped! */
	/* No locks needed, the machine is stopped! */
	for (i = 0; i < FTRACE_HASHSIZE; i++) {
	for (i = 0; i < FTRACE_HASHSIZE; i++) {
		INIT_HLIST_HEAD(&temp_list);
		head = &ftrace_hash[i];

		/* all CPUS are stopped, we are safe to modify code */
		/* all CPUS are stopped, we are safe to modify code */
		hlist_for_each_entry_safe(p, t, n, &ftrace_hash[i], node) {
		hlist_for_each_entry_safe(p, t, n, head, node) {
			/* Skip over failed records which have not been
			/* Skip over failed records which have not been
			 * freed. */
			 * freed. */
			if (p->flags & FTRACE_FL_FAILED)
			if (p->flags & FTRACE_FL_FAILED)
@@ -723,6 +731,19 @@ static int __ftrace_update_code(void *ignore)
			if (p->flags & (FTRACE_FL_CONVERTED))
			if (p->flags & (FTRACE_FL_CONVERTED))
				break;
				break;


			/* Ignore updates to this record's mcount site.
			 * Reintroduce this record at the head of this
			 * bucket to attempt to "convert" it again if
			 * the kprobe on it is unregistered before the
			 * next run. */
			if (get_kprobe((void *)p->ip)) {
				ftrace_del_hash(p);
				INIT_HLIST_NODE(&p->node);
				hlist_add_head(&p->node, &temp_list);
				continue;
			}

			/* convert record (i.e, patch mcount-call with NOP) */
			if (ftrace_code_disable(p)) {
			if (ftrace_code_disable(p)) {
				p->flags |= FTRACE_FL_CONVERTED;
				p->flags |= FTRACE_FL_CONVERTED;
				ftrace_update_cnt++;
				ftrace_update_cnt++;
@@ -734,6 +755,12 @@ static int __ftrace_update_code(void *ignore)
				}
				}
			}
			}
		}
		}

		hlist_for_each_entry_safe(p, t, n, &temp_list, node) {
			hlist_del(&p->node);
			INIT_HLIST_NODE(&p->node);
			hlist_add_head(&p->node, head);
		}
	}
	}


	stop = ftrace_now(raw_smp_processor_id());
	stop = ftrace_now(raw_smp_processor_id());