Re: [BUG/RFC] perf test fails on AMD CPUs

From: Jiri Olsa
Date: Wed Aug 19 2015 - 04:56:13 EST


On Wed, Aug 19, 2015 at 05:55:19AM +0200, Borislav Petkov wrote:
> On Tue, Aug 18, 2015 at 12:10:25PM +0200, Jiri Olsa wrote:
> > buuuuuut anyway, it looks like latest AMD firmware issue:
> >
> > [root@amd-pike-07 ~]# cat /sys/devices/system/cpu/cpu0/microcode/version
> > 0x6000822
> > [root@amd-pike-07 perf]# ./perf test 18
> > 18: Test breakpoint overflow signal handler : Ok
> >
> > [root@amd-pike-07 perf]# cat /sys/devices/system/cpu/cpu0/microcode/version
> > 0x6000832
> > [root@amd-pike-07 perf]# ./perf test 18
> > 18: Test breakpoint overflow signal handler : FAILED!
> >
> >
> > [root@amd-pike-07 ~]# cat /proc/cpuinfo
> > processor : 7
> > vendor_id : AuthenticAMD
> > cpu family : 21
> > model : 2
> > model name : AMD Opteron(tm) Processor 3380
> > stepping : 0
> > microcode : 0x6000832
> >
> > SNIP
>
> Whoops.
>
> Can you please confirm with your debugging code that with version
> 0x6000822 EFLAGS.RF is set and with 0x6000832 it isn't when running the
> aforementioned test?
>

please check the attached patch (over current tip/master a987577)


this is the perf breakpoint address:
000000000045b260 <test_function>:

this is trace_printk output for NEW microcode 0x6000832:

DEBUG EX
perf-893 [003] d... 1358.053633: sync_regs: sync_regs eregs ffff88012ecc7f58, regs ffff8800c9f1bf58
perf-893 [003] d... 1358.053635: do_debug: do_debug-1 regs ffff8800c9f1bf58, eflags 217, rip 45b260
perf-893 [003] d.h. 1358.053641: do_debug: do_debug-2 eflags 10217, rip 45b260
perf-893 [003] d... 1358.053642: prepare_exit_to_usermode: prepare_exit_to_usermode1 regs ffff8800c9f1bf58, eflags 10217, rip 45b260
perf-893 [003] d... 1358.053643: prepare_exit_to_usermode: prepare_exit_to_usermode3 regs ffff8800c9f1bf58, eflags 10217, rip 45b260

WORK_IRQ
---> perf-893 [003] d... 1358.053645: smp_irq_work_interrupt: smp_irq_work_interrupt1 regs ffff8800c9f1bf58, eflags 217, rip 45b260
perf-893 [003] d.h. 1358.053650: perf_event_wakeup: irq_work SIGIO
perf-893 [003] d... 1358.053651: smp_irq_work_interrupt: smp_irq_work_interrupt2 regs ffff8800c9f1bf58, eflags 217, rip 45b260

perf-893 [003] d... 1358.053652: prepare_exit_to_usermode: prepare_exit_to_usermode1 regs ffff8800c9f1bf58, eflags 217, rip 45b260



this is trace_printk output for OLD microcode 0x6000822:

DEBUG EX
perf-898 [005] d... 87.098816: sync_regs: sync_regs eregs ffff88012ed47f58, regs ffff8800c9c8ff58
perf-898 [005] d... 87.098817: do_debug: do_debug-1 regs ffff8800c9c8ff58, eflags 217, rip 45b260
perf-898 [005] d.h. 87.098823: do_debug: do_debug-2 eflags 10217, rip 45b260
perf-898 [005] d... 87.098824: prepare_exit_to_usermode: prepare_exit_to_usermode1 regs ffff8800c9c8ff58, eflags 10217, rip 45b260
perf-898 [005] d... 87.098825: prepare_exit_to_usermode: prepare_exit_to_usermode3 regs ffff8800c9c8ff58, eflags 10217, rip 45b260

WORK_IRQ
---> perf-898 [005] d... 87.098827: smp_irq_work_interrupt: smp_irq_work_interrupt1 regs ffff8800c9c8ff58, eflags 10217, rip 45b260
perf-898 [005] d.h. 87.098832: perf_event_wakeup: irq_work SIGIO
perf-898 [005] d... 87.098833: smp_irq_work_interrupt: smp_irq_work_interrupt2 regs ffff8800c9c8ff58, eflags 10217, rip 45b260

perf-898 [005] d... 87.098833: prepare_exit_to_usermode: prepare_exit_to_usermode1 regs ffff8800c9c8ff58, eflags 10217, rip 45b260


thanks,
jirka


---
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index 80dcc92..d52d598 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -217,6 +217,8 @@ static struct thread_info *pt_regs_to_thread_info(struct pt_regs *regs)
/* Called with IRQs disabled. */
__visible void prepare_exit_to_usermode(struct pt_regs *regs)
{
+ trace_printk("prepare_exit_to_usermode1 regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
+
if (WARN_ON(!irqs_disabled()))
local_irq_disable();

@@ -263,6 +265,7 @@ __visible void prepare_exit_to_usermode(struct pt_regs *regs)
}

user_enter();
+ trace_printk("prepare_exit_to_usermode3 regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
}

/*
diff --git a/arch/x86/kernel/irq_work.c b/arch/x86/kernel/irq_work.c
index dc5fa6a..52fe376 100644
--- a/arch/x86/kernel/irq_work.c
+++ b/arch/x86/kernel/irq_work.c
@@ -18,9 +18,13 @@ static inline void __smp_irq_work_interrupt(void)

__visible void smp_irq_work_interrupt(struct pt_regs *regs)
{
+ trace_printk("smp_irq_work_interrupt1 regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
+
ipi_entering_ack_irq();
__smp_irq_work_interrupt();
exiting_irq();
+
+ trace_printk("smp_irq_work_interrupt2 regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
}

__visible void smp_trace_irq_work_interrupt(struct pt_regs *regs)
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index da52e6b..cb199dc 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -398,6 +398,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
regs->ss = __USER_DS;
regs->cs = __USER_CS;

+trace_printk("__setup_rt_frame regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
return 0;
}
#else /* !CONFIG_X86_32 */
@@ -583,6 +584,7 @@ asmlinkage long sys_rt_sigreturn(void)
if (restore_altstack(&frame->uc.uc_stack))
goto badframe;

+trace_printk("sys_rt_sigreturn regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
return regs->ax;

badframe:
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index bfc4f90..cee75d8 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -536,6 +536,7 @@ asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs)
{
struct pt_regs *regs = task_pt_regs(current);
*regs = *eregs;
+trace_printk("sync_regs eregs %p, regs %p\n", eregs, regs);
return regs;
}
NOKPROBE_SYMBOL(sync_regs);
@@ -602,6 +603,8 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
unsigned long dr6;
int si_code;

+trace_printk("do_debug-1 regs %p, eflags %lx, rip %lx\n", regs, regs->flags, regs->ip);
+
ist_enter(regs);

get_debugreg(dr6, 6);
@@ -677,6 +680,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
debug_stack_usage_dec();

exit:
+ trace_printk("do_debug-2 eflags %lx, rip %lx\n", regs->flags, regs->ip);
ist_exit(regs);
}
NOKPROBE_SYMBOL(do_debug);
diff --git a/kernel/events/core.c b/kernel/events/core.c
index ae16867..6977f20 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4803,6 +4803,7 @@ void perf_event_wakeup(struct perf_event *event)

if (event->pending_kill) {
kill_fasync(perf_event_fasync(event), SIGIO, event->pending_kill);
+trace_printk("irq_work SIGIO\n");
event->pending_kill = 0;
}
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/