Skip to contentSkip to conversation

perf fixes

GIT PULL Ingo Molnar 3 participants 4 messages May 23, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perf-urgent-for-linus

Thanks,

Ingo

------------------>
Frederic Weisbecker (8):
perf tools: Check we are able to read the event size on mmap perf tools: Remove junk code in mmap size handling perf tools: Move evlist sample helpers to evlist area perf tools: Pre-check sample size before parsing perf tools: Robustify dynamic sample content fetch perf tools: Propagate event parse error handling perf tools: Fix ommitted mmap data update on remap perf tools: Fix sample size bit operations

Mandeep Singh Baines (4):
watchdog: Fix rounding bug in get_sample_period()
watchdog: Only disable/enable watchdog if neccessary
watchdog: Disable watchdog when thresh is zero
watchdog: Change the default timeout and configure nmi watchdog period based on watchdog_thresh

 arch/x86/kernel/apic/hw_nmi.c        |    4 +-
 include/linux/nmi.h                  |    7 ++--
 include/linux/sched.h                |    1 -
 kernel/sysctl.c                      |   12 +++++--
 kernel/watchdog.c                    |   52 +++++++++++++++++++--------------
 tools/perf/builtin-test.c            |    9 +++++-
 tools/perf/builtin-top.c             |    7 ++++-
 tools/perf/util/event.c              |   46 ++++++++++++++++++++----------
 tools/perf/util/event.h              |   12 +++++++-
 tools/perf/util/evlist.c             |   31 ++++++++++++++++++++
 tools/perf/util/evlist.h             |    3 ++
 tools/perf/util/evsel.c              |   32 ++++++++++++++++++++-
 tools/perf/util/header.c             |   31 --------------------
 tools/perf/util/header.h             |    2 -
 tools/perf/util/include/linux/list.h |    2 +
 tools/perf/util/python.c             |   13 ++++++--
 tools/perf/util/session.c            |   50 ++++++++++++++++++++++++--------
 tools/perf/util/session.h            |    2 +
 18 files changed, 216 insertions(+), 100 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +2 -2
index 5260fe9..d5e57db0 100644
@@ -19,9 +19,9 @@
 #include <linux/delay.h>
 
 #ifdef CONFIG_HARDLOCKUP_DETECTOR
-u64 hw_nmi_get_sample_period(void)
+u64 hw_nmi_get_sample_period(int watchdog_thresh)
 {
-	return (u64)(cpu_khz) * 1000 * 60;
+	return (u64)(cpu_khz) * 1000 * watchdog_thresh;
 }
 #endif
 
include/linux/nmi.h +4 -3
index c536f85..2d304ef 100644
@@ -45,11 +45,12 @@ static inline bool trigger_all_cpu_backtrace(void)
 
 #ifdef CONFIG_LOCKUP_DETECTOR
 int hw_nmi_is_cpu_stuck(struct pt_regs *);
-u64 hw_nmi_get_sample_period(void);
+u64 hw_nmi_get_sample_period(int watchdog_thresh);
 extern int watchdog_enabled;
+extern int watchdog_thresh;
 struct ctl_table;
-extern int proc_dowatchdog_enabled(struct ctl_table *, int ,
-			void __user *, size_t *, loff_t *);
+extern int proc_dowatchdog(struct ctl_table *, int ,
+			   void __user *, size_t *, loff_t *);
 #endif
 
 #endif
include/linux/sched.h +0 -1
index 12211e1..d8b2d0b 100644
@@ -315,7 +315,6 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 				  void __user *buffer,
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
-extern int softlockup_thresh;
 void lockup_detector_init(void);
 #else
 static inline void touch_softlockup_watchdog(void)
kernel/sysctl.c +8 -4
index c0bb324..3dd0c46 100644
@@ -730,14 +730,16 @@ static struct ctl_table kern_table[] = {
 		.data           = &watchdog_enabled,
 		.maxlen         = sizeof (int),
 		.mode           = 0644,
-		.proc_handler   = proc_dowatchdog_enabled,
+		.proc_handler   = proc_dowatchdog,
+		.extra1		= &zero,
+		.extra2		= &one,
 	},
 	{
 		.procname	= "watchdog_thresh",
-		.data		= &softlockup_thresh,
+		.data		= &watchdog_thresh,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dowatchdog_thresh,
+		.proc_handler	= proc_dowatchdog,
 		.extra1		= &neg_one,
 		.extra2		= &sixty,
 	},
@@ -755,7 +757,9 @@ static struct ctl_table kern_table[] = {
 		.data           = &watchdog_enabled,
 		.maxlen         = sizeof (int),
 		.mode           = 0644,
-		.proc_handler   = proc_dowatchdog_enabled,
+		.proc_handler   = proc_dowatchdog,
+		.extra1		= &zero,
+		.extra2		= &one,
 	},
 #endif
 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
kernel/watchdog.c +30 -22

97 lines not on this page · raw message

tools/perf/builtin-test.c +8 -1
index 2f9a337..b671862 100644
@@ -474,6 +474,7 @@ static int test__basic_mmap(void)
 	unsigned int nr_events[nsyscalls],
 		     expected_nr_events[nsyscalls], i, j;
 	struct perf_evsel *evsels[nsyscalls], *evsel;
+	int sample_size = perf_sample_size(attr.sample_type);
 
 	for (i = 0; i < nsyscalls; ++i) {
 		char name[64];
@@ -558,7 +559,13 @@ static int test__basic_mmap(void)
 			goto out_munmap;
 		}
 
-		perf_event__parse_sample(event, attr.sample_type, false, &sample);
+		err = perf_event__parse_sample(event, attr.sample_type, sample_size,
+					       false, &sample);
+		if (err) {
+			pr_err("Can't parse sample, err = %d\n", err);
+			goto out_munmap;
+		}
+
 		evsel = perf_evlist__id2evsel(evlist, sample.id);
 		if (evsel == NULL) {
 			pr_debug("event with id %" PRIu64
tools/perf/builtin-top.c +6 -1
index ebfc7cf..2d7934e 100644
@@ -805,9 +805,14 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
 {
 	struct perf_sample sample;
 	union perf_event *event;
+	int ret;
 
 	while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) {
-		perf_session__parse_sample(self, event, &sample);
+		ret = perf_session__parse_sample(self, event, &sample);
+		if (ret) {
+			pr_err("Can't parse sample, err = %d\n", ret);
+			continue;
+		}
 
 		if (event->header.type == PERF_RECORD_SAMPLE)
 			perf_event__process_sample(event, &sample, self);
tools/perf/util/event.c +31 -15

58 lines not on this page · raw message

tools/perf/util/event.h +11 -1
index 9c35170..c083328 100644
@@ -56,6 +56,13 @@ struct read_event {
 	u64 id;
 };
 
+
+#define PERF_SAMPLE_MASK				\
+	(PERF_SAMPLE_IP | PERF_SAMPLE_TID |		\
+	 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |		\
+	PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID |	\
+	 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
+
 struct sample_event {
 	struct perf_event_header        header;
 	u64 array[];
@@ -75,6 +82,8 @@ struct perf_sample {
 	struct ip_callchain *callchain;
 };
 
+int perf_sample_size(u64 sample_type);
+
 #define BUILD_ID_SIZE 20
 
 struct build_id_event {
@@ -178,6 +187,7 @@ int perf_event__preprocess_sample(const union perf_event *self,
 const char *perf_event__name(unsigned int id);
 
 int perf_event__parse_sample(const union perf_event *event, u64 type,
-			     bool sample_id_all, struct perf_sample *sample);
+			     int sample_size, bool sample_id_all,
+			     struct perf_sample *sample);
 
 #endif /* __PERF_RECORD_H */
tools/perf/util/evlist.c +31 -0
index 23eb22b..50aa348 100644
@@ -459,3 +459,34 @@ int perf_evlist__set_filters(struct perf_evlist *evlist)
 
 	return 0;
 }
+
+u64 perf_evlist__sample_type(struct perf_evlist *evlist)
+{
+	struct perf_evsel *pos;
+	u64 type = 0;
+
+	list_for_each_entry(pos, &evlist->entries, node) {
+		if (!type)
+			type = pos->attr.sample_type;
+		else if (type != pos->attr.sample_type)
+			die("non matching sample_type");
+	}
+
+	return type;
+}
+
+bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
+{
+	bool value = false, first = true;
+	struct perf_evsel *pos;
+
+	list_for_each_entry(pos, &evlist->entries, node) {
+		if (first) {
+			value = pos->attr.sample_id_all;
+			first = false;
+		} else if (value != pos->attr.sample_id_all)
+			die("non matching sample_id_all");
+	}
+
+	return value;
+}
tools/perf/util/evlist.h +3 -0
index 7109d7a..0a1ef1f 100644
@@ -66,4 +66,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
 void perf_evlist__delete_maps(struct perf_evlist *evlist);
 int perf_evlist__set_filters(struct perf_evlist *evlist);
 
+u64 perf_evlist__sample_type(struct perf_evlist *evlist);
+bool perf_evlist__sample_id_all(const struct perf_evlist *evlist);
+
 #endif /* __PERF_EVLIST_H */
tools/perf/util/evsel.c +31 -1
index d6fd59b..ee0fe0d 100644
@@ -303,8 +303,20 @@ static int perf_event__parse_id_sample(const union perf_event *event, u64 type,
 	return 0;
 }
 
+static bool sample_overlap(const union perf_event *event,
+			   const void *offset, u64 size)
+{
+	const void *base = event;
+
+	if (offset + size > base + event->header.size)
+		return true;
+
+	return false;
+}
+
 int perf_event__parse_sample(const union perf_event *event, u64 type,
-			     bool sample_id_all, struct perf_sample *data)
+			     int sample_size, bool sample_id_all,
+			     struct perf_sample *data)
 {
 	const u64 *array;
 
@@ -319,6 +331,9 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 
 	array = event->sample.array;
 
+	if (sample_size + sizeof(event->header) > event->header.size)
+		return -EFAULT;
+
 	if (type & PERF_SAMPLE_IP) {
 		data->ip = event->ip.ip;
 		array++;
@@ -369,14 +384,29 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 	}
 
 	if (type & PERF_SAMPLE_CALLCHAIN) {
+		if (sample_overlap(event, array, sizeof(data->callchain->nr)))
+			return -EFAULT;
+
 		data->callchain = (struct ip_callchain *)array;
+
+		if (sample_overlap(event, array, data->callchain->nr))
+			return -EFAULT;
+
 		array += 1 + data->callchain->nr;
 	}
 
 	if (type & PERF_SAMPLE_RAW) {
 		u32 *p = (u32 *)array;
+
+		if (sample_overlap(event, array, sizeof(u32)))
+			return -EFAULT;
+
 		data->raw_size = *p;
 		p++;
+
+		if (sample_overlap(event, p, data->raw_size))
+			return -EFAULT;
+
 		data->raw_data = p;
 	}
 
tools/perf/util/header.c +0 -31
index 93862a8..0717beb 100644
@@ -934,37 +934,6 @@ out_delete_evlist:
 	return -ENOMEM;
 }
 
-u64 perf_evlist__sample_type(struct perf_evlist *evlist)
-{
-	struct perf_evsel *pos;
-	u64 type = 0;
-
-	list_for_each_entry(pos, &evlist->entries, node) {
-		if (!type)
-			type = pos->attr.sample_type;
-		else if (type != pos->attr.sample_type)
-			die("non matching sample_type");
-	}
-
-	return type;
-}
-
-bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
-{
-	bool value = false, first = true;
-	struct perf_evsel *pos;
-
-	list_for_each_entry(pos, &evlist->entries, node) {
-		if (first) {
-			value = pos->attr.sample_id_all;
-			first = false;
-		} else if (value != pos->attr.sample_id_all)
-			die("non matching sample_id_all");
-	}
-
-	return value;
-}
-
 int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
 				perf_event__handler_t process,
 				struct perf_session *session)
tools/perf/util/header.h +0 -2
index 456661d..1886256 100644
@@ -64,8 +64,6 @@ int perf_header__write_pipe(int fd);
 int perf_header__push_event(u64 id, const char *name);
 char *perf_header__find_event(u64 id);
 
-u64 perf_evlist__sample_type(struct perf_evlist *evlist);
-bool perf_evlist__sample_id_all(const struct perf_evlist *evlist);
 void perf_header__set_feat(struct perf_header *header, int feat);
 void perf_header__clear_feat(struct perf_header *header, int feat);
 bool perf_header__has_feat(const struct perf_header *header, int feat);
tools/perf/util/include/linux/list.h +2 -0
index 356c7e4..ed33609 100644
@@ -1,4 +1,6 @@
 #include <linux/kernel.h>
+#include <linux/prefetch.h>
+
 #include "../../../../include/linux/list.h"
 
 #ifndef PERF_LIST_H
tools/perf/util/python.c +10 -3
index b5c7d81..69436b3 100644
@@ -675,6 +675,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 	union perf_event *event;
 	int sample_id_all = 1, cpu;
 	static char *kwlist[] = {"sample_id_all", NULL, NULL};
+	int err;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist,
 					 &cpu, &sample_id_all))
@@ -690,11 +691,17 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 			return PyErr_NoMemory();
 
 		first = list_entry(evlist->entries.next, struct perf_evsel, node);
-		perf_event__parse_sample(event, first->attr.sample_type, sample_id_all,
-					 &pevent->sample);
+		err = perf_event__parse_sample(event, first->attr.sample_type,
+					       perf_sample_size(first->attr.sample_type),
+					       sample_id_all, &pevent->sample);
+		if (err) {
+			pr_err("Can't parse sample, err = %d\n", err);
+			goto end;
+		}
+
 		return pyevent;
 	}
-
+end:
 	Py_INCREF(Py_None);
 	return Py_None;
 }
tools/perf/util/session.c +37 -13

86 lines not on this page · raw message

tools/perf/util/session.h +2 -0
index 8daaa2d..66d4e14 100644
@@ -43,6 +43,7 @@ struct perf_session {
 	 */
 	struct hists		hists;
 	u64			sample_type;
+	int			sample_size;
 	int			fd;
 	bool			fd_pipe;
 	bool			repipe;
@@ -159,6 +160,7 @@ static inline int perf_session__parse_sample(struct perf_session *session,
 					     struct perf_sample *sample)
 {
 	return perf_event__parse_sample(event, session->sample_type,
+					session->sample_size,
 					session->sample_id_all, sample);
 }
 
#1 lore raw
Quoted 8 lines · Ingo Molnar

Linus,

Please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perf-urgent-for-linus

Thanks,

Hi Ingo

I just tried latest "perf top" from linux-2.6 tree on my 32bit x86 host.

It outputs endless errors, I dont know if you guys already are aware of this ?

Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14

Thanks

#2 lore raw
Quoted 17 lines · Eric Dumazet
Quoted 8 lines · Ingo Molnar

Linus,

Please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perf-urgent-for-linus

Thanks,

Hi Ingo

I just tried latest "perf top" from linux-2.6 tree on my 32bit x86 host.

It outputs endless errors, I dont know if you guys already are aware of this ?

Quoted 8 lines

Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14

Hi Eric,

Does that fix the issue?

tools/perf/util/event.c +1 -1
index 252b72a..6635fcd 100644
@@ -42,7 +42,7 @@ int perf_sample_size(u64 sample_type)
 	int i;
 
 	for (i = 0; i < 64; i++) {
-		if (mask & (1UL << i))
+		if (mask & (1ULL << i))
 			size++;
 	}
 
#3 lore raw
Quoted 37 lines · Frederic Weisbecker
Quoted 17 lines · Eric Dumazet
Quoted 8 lines · Ingo Molnar

Linus,

Please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perf-urgent-for-linus

Thanks,

Hi Ingo

I just tried latest "perf top" from linux-2.6 tree on my 32bit x86 host.

It outputs endless errors, I dont know if you guys already are aware of this ?

Quoted 8 lines

Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14
Can't parse sample, err = -14

Hi Eric,

Does that fix the issue?

tools/perf/util/event.c +0 -0
index 252b72a..6635fcd 100644

tools/perf/util/event.c int perf_sample_size(u64 sample_type) · line 48

Quoted 8 lines
tools/perf/util/event.c +1 -1
@@ -42,7 +42,7 @@ int perf_sample_size(u64 sample_type)
 	int i;
 
 	for (i = 0; i < 64; i++) {
-		if (mask & (1UL << i))
+		if (mask & (1ULL << i))
 			size++;
 	}
 

It does, thanks Frederic !