Skip to contentSkip to conversation

perf, signal x86: Fix breakpoint events overflow handling

PATCH Superseded Jiri Olsa 5 participants 16 messages Mar 10, 2013 – Apr 24, 2013

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

v2 cover perf, signal x86: Fix breakpoint events overflow handling

hi,
sendign v2 for initial RFC patchset:
https://lkml.org/lkml/2013/3/1/324

v2 changes:
- added patch to merge EFLAGS bit clearing into single statement

Also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/linux.git
perf/RF5

thanks,
jirka

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>

---
Jiri Olsa (6):
signal x86: Propage RF EFLAGS bit throught the signal restore call signal x86: Clear RF EFLAGS bit for signal handler signal x86: Merge EFLAGS bit clearing into single statement
perf: Fix hw breakpoints overflow period sampling
perf tests: Test breakpoint overflow signal handler perf tests: Test breakpoint overflow signal handler counts

 arch/x86/ia32/ia32_signal.c           |   2 -
 arch/x86/include/asm/sighandling.h    |   4 +-
 arch/x86/kernel/signal.c              |  16 +++-----
 include/linux/perf_event.h            |   2 +
 kernel/events/core.c                  |   2 +-
 kernel/events/hw_breakpoint.c         |   5 +++
 tools/perf/Makefile                   |   2 +
 tools/perf/tests/bp_signal.c          | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/bp_signal_overflow.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c       |   8 ++++
 tools/perf/tests/tests.h              |   2 +
 11 files changed, 341 insertions(+), 15 deletions(-)
 create mode 100644 tools/perf/tests/bp_signal.c
 create mode 100644 tools/perf/tests/bp_signal_overflow.c
author
#1 lore raw

PATCH v2 1/6 signal x86: Propage RF EFLAGS bit throught the signal restore call

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 arch/x86/ia32/ia32_signal.c        | 2 --
 arch/x86/include/asm/sighandling.h | 4 ++--
 arch/x86/kernel/signal.c           | 6 ------
 3 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/ia32/ia32_signal.c +0 -2
index cf1a471..bccfca6 100644
@@ -34,8 +34,6 @@
 #include <asm/sys_ia32.h>
 #include <asm/smap.h>
 
-#define FIX_EFLAGS	__FIX_EFLAGS
-
 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
 {
 	int err = 0;
arch/x86/include/asm/sighandling.h +2 -2
index beff97f..7a95816 100644
@@ -7,10 +7,10 @@
 
 #include <asm/processor-flags.h>
 
-#define __FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
+#define FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
 			 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
 			 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
-			 X86_EFLAGS_CF)
+			 X86_EFLAGS_CF | X86_EFLAGS_RF)
 
 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
 
arch/x86/kernel/signal.c +0 -6
index 6956299..9df4c0b 100644
@@ -43,12 +43,6 @@
 
 #include <asm/sigframe.h>
 
-#ifdef CONFIG_X86_32
-# define FIX_EFLAGS	(__FIX_EFLAGS | X86_EFLAGS_RF)
-#else
-# define FIX_EFLAGS	__FIX_EFLAGS
-#endif
-
 #define COPY(x)			do {			\
 	get_user_ex(regs->x, &sc->x);			\
 } while (0)
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [PATCH 1/6] signal x86: Propage RF EFLAGS bit throught the signal restore call

Quoted 5 lines · Jiri Olsa

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

So that happens if, say, we get a breakpoint exception and then we run a signal handler before returning to the ip that triggered the breakpoint?

[...]

Quoted 20 lines
arch/x86/include/asm/sighandling.h +2 -2
@@ -7,10 +7,10 @@
 
 #include <asm/processor-flags.h>
 
-#define __FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
+#define FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
 			 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
 			 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
-			 X86_EFLAGS_CF)
+			 X86_EFLAGS_CF | X86_EFLAGS_RF)
 
 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
 
arch/x86/kernel/signal.c +0 -0
index 6956299..9df4c0b 100644

arch/x86/kernel/signal.c line 50

Quoted 8 lines
arch/x86/kernel/signal.c +0 -5
@@ -43,12 +43,6 @@
 
 #include <asm/sigframe.h>
 
-#ifdef CONFIG_X86_32
-# define FIX_EFLAGS	(__FIX_EFLAGS | X86_EFLAGS_RF)
-#else
-# define FIX_EFLAGS	__FIX_EFLAGS
-#endif

So, I'm a bit confused here. Why was that only hapenning in X86_64?

Quoted 7 lines
arch/x86/kernel/signal.c +0 -1
-
 #define COPY(x)			do {			\
 	get_user_ex(regs->x, &sc->x);			\
 } while (0)
Signature · 1 line
1.7.11.7
#3 lore raw

Re: [PATCH 1/6] signal x86: Propage RF EFLAGS bit throught the signal restore call

Quoted 11 lines · Frederic Weisbecker
Quoted 5 lines · Jiri Olsa

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

So that happens if, say, we get a breakpoint exception and then we run a signal handler before returning to the ip that triggered the breakpoint?

Afaics these changes (1 and 2) should fix the bug.

Suppose that the first insn in the signal handler should trigger another bp, we should clear X86_EFLAGS_RF (2/6).

Otoh, we should restore it when we return to the original insn which triggered the trap to avoid another trap.

But. it seems that we have yet another problem? Suppose that the signal handler does siglongjmp() and jumps to yet another insn which should trigger the trap?

Oleg.

#4 lore raw

Re: [PATCH 1/6] signal x86: Propage RF EFLAGS bit throught the signal restore call

Quoted 14 lines · Oleg Nesterov
Quoted 11 lines · Frederic Weisbecker
Quoted 5 lines · Jiri Olsa

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

So that happens if, say, we get a breakpoint exception and then we run a signal handler before returning to the ip that triggered the breakpoint?

Quoted 7 lines

Afaics these changes (1 and 2) should fix the bug.

Suppose that the first insn in the signal handler should trigger another bp, we should clear X86_EFLAGS_RF (2/6).

Otoh, we should restore it when we return to the original insn which triggered the trap to avoid another trap.

I applied 1 and 2, and this fixes the test-case below.

Quoted 3 lines

But. it seems that we have yet another problem? Suppose that the signal handler does siglongjmp() and jumps to yet another insn which should trigger the trap?

Argh. Sorry for confusion. I tried to say that the signal handler can play with sigcontext->ip before sigreturn(). But probably we can ignore this.

Oleg.

-------------------------------------------------------------------------------
#define _GNU_SOURCE 1
#include <stdio.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/debugreg.h>
#include <sys/user.h>
#include <sys/wait.h>
#include <assert.h>
#include <assert.h>
#include <stddef.h>

#define DR_GLOBAL_ENABLE 0x2
#define DR_LOCAL_ENABLE 0x1

unsigned long encode_dr7(int drnum, int enable, unsigned int type, unsigned int len)

{
	unsigned long dr7;

	dr7 = ((len | type) & 0xf)
		<< (DR_CONTROL_SHIFT + drnum * DR_CONTROL_SIZE);
	if (enable)
		dr7 |= (DR_GLOBAL_ENABLE << (drnum * DR_ENABLE_SIZE));

	return dr7;
}

int write_dr(int pid, int dr, unsigned long val)
{
return ptrace(PTRACE_POKEUSER, pid,
offsetof (struct user, u_debugreg[dr]), val);
}

#define GET_REG(pid, reg)				\
	ptrace(PTRACE_PEEKUSER, (pid),			\
		offsetof(struct user, regs.reg), 0)

void *get_ip(int pid)

{
	return (void*)GET_REG(pid, rip);
}

void func(void)

{
	printf("bp_1 passed\n");
}

void sigh(int sig)

{
	printf("bp_2 passed\n");
}

int main(void)

{
	int pid, stat;
	unsigned long dr7;

	pid = fork();
	if (!pid) {
		assert(ptrace(PTRACE_TRACEME, 0,0,0) == 0);
		kill(getpid(), SIGHUP);

		signal(SIGINT, sigh);

		func();

		return 0x13;
	}

	assert(pid == waitpid(-1, &stat, 0));
	assert(WSTOPSIG(stat) == SIGHUP);

	assert(write_dr(pid, 0, (long)func) == 0);
	assert(write_dr(pid, 1, (long)sigh) == 0);

	dr7 = 0;
	dr7 |= encode_dr7(0, 1, DR_RW_EXECUTE, DR_LEN_1);
	dr7 |= encode_dr7(1, 1, DR_RW_EXECUTE, DR_LEN_1);

	assert(write_dr(pid, 7, dr7) == 0);

	assert(ptrace(PTRACE_CONT, pid, 0,0) == 0);
	assert(pid == waitpid(-1, &stat, 0));
	assert(WSTOPSIG(stat) == SIGTRAP);
	assert(get_ip(pid) == func);

	kill(pid, SIGINT);
	assert(ptrace(PTRACE_CONT, pid, 0,0) == 0);
	assert(pid == waitpid(-1, &stat, 0));
	assert(WSTOPSIG(stat) == SIGINT);

	assert(ptrace(PTRACE_CONT, pid, 0,SIGINT) == 0);
	assert(pid == waitpid(-1, &stat, 0));
	assert(WSTOPSIG(stat) == SIGTRAP);
	assert(get_ip(pid) == sigh);

	assert(ptrace(PTRACE_CONT, pid, 0,0) == 0);
	assert(pid == waitpid(-1, &stat, 0));
	assert(stat == 0x1300);

	return 0;
}
#5 lore raw

Re: [PATCH 1/6] signal x86: Propage RF EFLAGS bit throught the signal restore call

Quoted 25 lines · Oleg Nesterov
Quoted 14 lines · Oleg Nesterov
Quoted 11 lines · Frederic Weisbecker
Quoted 5 lines · Jiri Olsa

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

So that happens if, say, we get a breakpoint exception and then we run a signal handler before returning to the ip that triggered the breakpoint?

Quoted 7 lines

Afaics these changes (1 and 2) should fix the bug.

Suppose that the first insn in the signal handler should trigger another bp, we should clear X86_EFLAGS_RF (2/6).

Otoh, we should restore it when we return to the original insn which triggered the trap to avoid another trap.

I applied 1 and 2, and this fixes the test-case below.

Quoted 7 lines
Quoted 3 lines

But. it seems that we have yet another problem? Suppose that the signal handler does siglongjmp() and jumps to yet another insn which should trigger the trap?

Argh. Sorry for confusion. I tried to say that the signal handler can play with sigcontext->ip before sigreturn(). But probably we can ignore this.

Hmm, ok.

Anyway patches 1-3 look good!

Thanks!

#6 lore raw

Re: [PATCH 1/6] signal x86: Propage RF EFLAGS bit throught the signal restore call

In reply to Jiri Olsa
Quoted 60 lines · Jiri Olsa

Adding RF EFLAGS bit to be restored on return from signal from the original register context before the signal was entered.

This will prevent the RF flag to disappear when returning from exception due to the signal handler being executed.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 arch/x86/ia32/ia32_signal.c        | 2 --
 arch/x86/include/asm/sighandling.h | 4 ++--
 arch/x86/kernel/signal.c           | 6 ------
 3 files changed, 2 insertions(+), 10 deletions(-)
arch/x86/ia32/ia32_signal.c +0 -2
index cf1a471..bccfca6 100644
@@ -34,8 +34,6 @@
 #include <asm/sys_ia32.h>
 #include <asm/smap.h>
 
-#define FIX_EFLAGS	__FIX_EFLAGS
-
 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
 {
 	int err = 0;
arch/x86/include/asm/sighandling.h +2 -2
index beff97f..7a95816 100644
@@ -7,10 +7,10 @@
 
 #include <asm/processor-flags.h>
 
-#define __FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
+#define FIX_EFLAGS	(X86_EFLAGS_AC | X86_EFLAGS_OF | \
 			 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
 			 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
-			 X86_EFLAGS_CF)
+			 X86_EFLAGS_CF | X86_EFLAGS_RF)
 
 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
 
arch/x86/kernel/signal.c +0 -0
index 6956299..9df4c0b 100644

arch/x86/kernel/signal.c line 47

Quoted 5 lines
arch/x86/kernel/signal.c +0 -2
@@ -43,12 +43,6 @@
 
 #include <asm/sigframe.h>
 
-#ifdef CONFIG_X86_32
-# define FIX_EFLAGS	(__FIX_EFLAGS | X86_EFLAGS_RF)

Does anybody know why we had RF not restored in x86-32?

author
#7 lore raw

PATCH v2 2/6 signal x86: Clear RF EFLAGS bit for signal handler

In reply to Jiri Olsa

Clearing RF EFLAGS bit for signal handler. The reason is, that this flag is set by debug exception code to prevent the recursive exception entry.

Leaving it set for signal handler might prevent debug exception of the signal handler itself.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 arch/x86/kernel/signal.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/kernel/signal.c +6 -0
index 9df4c0b..cb12fc9 100644
@@ -665,6 +665,12 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 		 */
 		regs->flags &= ~X86_EFLAGS_DF;
 		/*
+		 * Clear RF when entering the signal handler, because
+		 * it might disable possible debug exception from the
+		 * signal handler.
+		 */
+		regs->flags &= ~X86_EFLAGS_RF;
+		/*
 		 * Clear TF when entering the signal handler, but
 		 * notify any tracer that was single-stepping it.
 		 * The tracer may want to single-step inside the
Signature · 1 line
1.7.11.7
author
#8 lore raw

PATCH v2 3/6 signal x86: Merge EFLAGS bit clearing into single statement

In reply to Jiri Olsa

Merging EFLAGS bit clearing into a single statement, to ensure EFLAGS bits being cleared in single instruction.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 arch/x86/kernel/signal.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/x86/kernel/signal.c +3 -7
index cb12fc9..cf91358 100644
@@ -662,21 +662,17 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 	if (!failed) {
 		/*
 		 * Clear the direction flag as per the ABI for function entry.
-		 */
-		regs->flags &= ~X86_EFLAGS_DF;
-		/*
+		 *
 		 * Clear RF when entering the signal handler, because
 		 * it might disable possible debug exception from the
 		 * signal handler.
-		 */
-		regs->flags &= ~X86_EFLAGS_RF;
-		/*
+		 *
 		 * Clear TF when entering the signal handler, but
 		 * notify any tracer that was single-stepping it.
 		 * The tracer may want to single-step inside the
 		 * handler too.
 		 */
-		regs->flags &= ~X86_EFLAGS_TF;
+		regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
 	}
 	signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
 }
Signature · 1 line
1.7.11.7
author
#9 lore raw

PATCH v2 4/6 perf: Fix hw breakpoints overflow period sampling

In reply to Jiri Olsa

The hw breakpoint pmu 'add' function is missing the period_left update needed for SW events.

The perf HW breakpoint events use SW events framework for to process the overflow, so it needs to be properly initialized during PMU 'add' method.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 include/linux/perf_event.h    | 2 ++
 kernel/events/core.c          | 2 +-
 kernel/events/hw_breakpoint.c | 5 +++++
 3 files changed, 8 insertions(+), 1 deletion(-)
include/linux/perf_event.h +2 -0
index 8737e1c..24befdf 100644
@@ -738,6 +738,7 @@ extern unsigned int perf_output_skip(struct perf_output_handle *handle,
 				     unsigned int len);
 extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
+extern u64 perf_swevent_set_period(struct perf_event *event);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
 extern int __perf_event_disable(void *info);
@@ -777,6 +778,7 @@ static inline void perf_event_fork(struct task_struct *tsk)		{ }
 static inline void perf_event_init(void)				{ }
 static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
+static inline u64 perf_swevent_set_period(struct perf_event *event)	{ return 0; }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
 static inline int __perf_event_disable(void *info)			{ return -1; }
kernel/events/core.c +1 -1
index 5976a2a..bd076b8 100644
@@ -4972,7 +4972,7 @@ static DEFINE_PER_CPU(struct swevent_htable, swevent_htable);
  * sign as trigger.
  */
 
-static u64 perf_swevent_set_period(struct perf_event *event)
+u64 perf_swevent_set_period(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
 	u64 period = hwc->last_period;
kernel/events/hw_breakpoint.c +5 -0
index a64f8ae..966a241 100644
@@ -612,6 +612,11 @@ static int hw_breakpoint_add(struct perf_event *bp, int flags)
 	if (!(flags & PERF_EF_START))
 		bp->hw.state = PERF_HES_STOPPED;
 
+	if (is_sampling_event(bp)) {
+		bp->hw.last_period = bp->hw.sample_period;
+		perf_swevent_set_period(bp);
+	}
+
 	return arch_install_hw_breakpoint(bp);
 }
 
Signature · 1 line
1.7.11.7
#10 lore raw

Re: [PATCH 4/6] perf: Fix hw breakpoints overflow period sampling

Quoted 6 lines · Jiri Olsa

The hw breakpoint pmu 'add' function is missing the period_left update needed for SW events.

The perf HW breakpoint events use SW events framework for to process the overflow, so it needs to be properly initialized during PMU 'add' method.

Yeah looks about right..

author
#11 lore raw

PATCH v2 5/6 perf tests: Test breakpoint overflow signal handler

In reply to Jiri Olsa

Adding automated test for breakpoint event signal handler checking if it's executed properly.

The test is related to the proper handling of the RF EFLAGS bit on x86_64, but it's generic for all archs.

First we check the signal handler is properly called and that the following debug exception return to user space wouldn't trigger recursive breakpoint.

This is related to x86_64 RF EFLAGS bit being managed in a wrong way.

Second we check that we can set breakpoint in signal handler, which is not possible on x86_64 if the signal handler is executed with RF EFLAG set.

This test is inpired by overflow tests done by Vince Weaver.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Makefile             |   1 +
 tools/perf/tests/bp_signal.c    | 187 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |   4 +
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 193 insertions(+)
 create mode 100644 tools/perf/tests/bp_signal.c
tools/perf/Makefile +1 -0
index a2108ca..bea66fe 100644
@@ -497,6 +497,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
 LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
+LIB_OBJS += $(OUTPUT)tests/bp_signal.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/bp_signal.c new file +187 -0

187 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index acb98e0..37b108b 100644
@@ -78,6 +78,10 @@ static struct test {
 		.func = test__python_use,
 	},
 	{
+		.desc = "Test breakpoint overflow signal handler",
+		.func = test__bp_signal,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 5de0be1..05d0e58 100644
@@ -23,5 +23,6 @@ int test__dso_data(void);
 int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
+int test__bp_signal(void);
 
 #endif /* TESTS_H */
Signature · 1 line
1.7.11.7
#12 lore raw

[tip:perf/core] perf tests: Test breakpoint overflow signal handler

perf tests: Test breakpoint overflow signal handler
Commit-ID:  5a6bef47b418676546ab86d25631c3cfb9ffaf2a
Gitweb:     http://git.kernel.org/tip/5a6bef47b418676546ab86d25631c3cfb9ffaf2a
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 10 Mar 2013 19:41:10 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 15 Mar 2013 13:06:10 -0300

perf tests: Test breakpoint overflow signal handler

Adding automated test for breakpoint event signal handler checking if it's executed properly.

The test is related to the proper handling of the RF EFLAGS bit on x86_64, but it's generic for all archs.

First we check the signal handler is properly called and that the following debug exception return to user space wouldn't trigger recursive breakpoint.

This is related to x86_64 RF EFLAGS bit being managed in a wrong way.

Second we check that we can set breakpoint in signal handler, which is not possible on x86_64 if the signal handler is executed with RF EFLAG set.

This test is inpired by overflow tests done by Vince Weaver.

Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
[ committer note: s/pr_err/pr_debug/g i.e. print just OK or FAILED in non verbose mode ]
---
 tools/perf/Makefile             |   1 +
 tools/perf/tests/bp_signal.c    | 186 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |   4 +
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 192 insertions(+)
tools/perf/Makefile +1 -0
index 3dcd627..21e0b4b 100644
@@ -511,6 +511,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
 LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
+LIB_OBJS += $(OUTPUT)tests/bp_signal.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/bp_signal.c new file +186 -0

186 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index acb98e0..37b108b 100644
@@ -78,6 +78,10 @@ static struct test {
 		.func = test__python_use,
 	},
 	{
+		.desc = "Test breakpoint overflow signal handler",
+		.func = test__bp_signal,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 5de0be1..05d0e58 100644
@@ -23,5 +23,6 @@ int test__dso_data(void);
 int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
+int test__bp_signal(void);
 
 #endif /* TESTS_H */
author
#13 lore raw

PATCH v2 6/6 perf tests: Test breakpoint overflow signal handler counts

In reply to Jiri Olsa

Adding automated test to check the exact number of breakpoint event overflows and counts.

This test was originally done by Vince Weaver for
perf_event_tests.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Vince Weaver <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Makefile                   |   1 +
 tools/perf/tests/bp_signal_overflow.c | 126 ++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c       |   4 ++
 tools/perf/tests/tests.h              |   1 +
 4 files changed, 132 insertions(+)
 create mode 100644 tools/perf/tests/bp_signal_overflow.c
tools/perf/Makefile +1 -0
index bea66fe..34a63ce 100644
@@ -498,6 +498,7 @@ LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
 LIB_OBJS += $(OUTPUT)tests/bp_signal.o
+LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/bp_signal_overflow.c new file +126 -0

126 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index 37b108b..45d9ad4 100644
@@ -82,6 +82,10 @@ static struct test {
 		.func = test__bp_signal,
 	},
 	{
+		.desc = "Test breakpoint overflow sampling",
+		.func = test__bp_signal_overflow,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 05d0e58..6cf1ec4 100644
@@ -24,5 +24,6 @@ int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
 int test__bp_signal(void);
+int test__bp_signal_overflow(void);
 
 #endif /* TESTS_H */
Signature · 1 line
1.7.11.7
#14 lore raw

[tip:perf/core] perf tests: Test breakpoint overflow signal handler counts

perf tests: Test breakpoint overflow signal handler counts
Commit-ID:  06933e3a732bb305b0721f1051a45264588e0519
Gitweb:     http://git.kernel.org/tip/06933e3a732bb305b0721f1051a45264588e0519
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 10 Mar 2013 19:41:11 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 15 Mar 2013 13:06:10 -0300

perf tests: Test breakpoint overflow signal handler counts

Adding automated test to check the exact number of breakpoint event overflows and counts.

This test was originally done by Vince Weaver for perf_event_tests.

Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
[ committer note: s/pr_err/pr_debug/g i.e. print just OK or FAILED in non verbose mode ]
---
 tools/perf/Makefile                   |   1 +
 tools/perf/tests/bp_signal_overflow.c | 126 ++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c       |   4 ++
 tools/perf/tests/tests.h              |   1 +
 4 files changed, 132 insertions(+)
tools/perf/Makefile +1 -0
index 21e0b4b..990e9a1 100644
@@ -512,6 +512,7 @@ LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
 LIB_OBJS += $(OUTPUT)tests/bp_signal.o
+LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/bp_signal_overflow.c new file +126 -0

126 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index 37b108b..45d9ad4 100644
@@ -82,6 +82,10 @@ static struct test {
 		.func = test__bp_signal,
 	},
 	{
+		.desc = "Test breakpoint overflow sampling",
+		.func = test__bp_signal_overflow,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 05d0e58..6cf1ec4 100644
@@ -24,5 +24,6 @@ int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
 int test__bp_signal(void);
+int test__bp_signal_overflow(void);
 
 #endif /* TESTS_H */