From: Borislav Petkov <bp@suse.de>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Jiri Olsa <jolsa@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
X86 ML <x86@kernel.org>, Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@redhat.com>, Robert Richter <rric@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Jan Stancek <jstancek@redhat.com>
Subject: Re: [BUG/RFC] perf test fails on AMD CPUs
Date: Tue, 18 Aug 2015 10:52:11 +0200 [thread overview]
Message-ID: <20150818085211.GA28738@nazgul.tnic> (raw)
In-Reply-To: <CALCETrXADuwEi-=kX0GyNt=h2RPCcVRtOtkOao-KBSdy11xr8g@mail.gmail.com>
On Mon, Aug 17, 2015 at 09:06:59AM -0700, Andy Lutomirski wrote:
> >> expected course of actions is:
> >> 1) CPU hits 'test_function'
> >> 2) DB exception is triggered, with RFLAGS.RF=0
> >> 3) DB exception handler sets regs->RFLAGS.RF=1 and perf handler
> >> triggers irq_work pending work
> >> 4) DB exception executes iretd
> >> 5) irq_work interrupt is triggered, with RFLAGS.RF=1
> >> 6) irq_work interrupt calls kill_fasync with SIGIO signal
> >> 7) irq_work interrupt on return to userspace calls prepare_exit_to_usermode
> >> which actually delivers the SIGIO signal
> >> 8) sigreturn syscall prepare registers to return to the
> >> instruction from step 1) and sets RFLAGS.RF to the its original
> >> value from step 5) (RFLAGS.RF=1)
> >> 9) CPU hits 'test_function' and DB exception is NOT triggered
> >> due to RFLAGS.RF=1
> >>
> >> this is how I see it works on Intel
> >>
> >> But AMD gives me RFLAGS.RF=0 on step 5, which makes the step 9 to
> >> trigger the DB exception once again and makes the test fail.
Waaaiit a minute!
APM says #DB exception handler must set RF in the EFLAGS image on the
exception stack (or whereever it is running) so that the breakpoint
doesn't trigger again.
Now: do_debug() *doesn't* do that but hw_breakpoint_handler() does. So
do we call hw_breakpoint_handler() in those steps above?
Because if we don't, that could explain the issue...
> > Adding Andy, he might have an idea. Leaving in the rest for reference.
>
> Gee thanks :-p
For what, adding you to CC or leaving in the rest? :-P
> Jiri, did you instrument the code and observe do_IRQ sees RF clear in
> its pt_regs? Also, it might be worth checking that regs->ip in the
> irq_work matches regs->ip.
Hohumm.
> It's *possible* that I messed up and broke RF restore with
> opportunistic sysret, but the code looks correct:
>
> testq $(X86_EFLAGS_RF|X86_EFLAGS_TF), %r11
> jnz opportunistic_sysret_failed
Yeah, I was looking at that too.
> >> An IRET that sets the RF bit.
> >> JMP, CALL, or INTn through a task gate.
> >> In both of the above cases, RF is not cleared to 0 until the next instruction successfully executes.
> >> When an exception occurs (or when a string instruction is interrupted), the processor normally sets
> >> RF=1 in the RFLAGS image saved on the interrupt stack. However, when a #DB exception occurs as a
> >> result of an instruction breakpoint, the processor clears the RF bit to 0 in the interrupt-stack RFLAGS
> >> image.
>
> That's a little weird, I think. Shouldn't RF be zero on #DB due to a
> *watchpoint* so that a watchpoint followed immediately by a breakpoint
> works?
What is a watchpoint? R/Wn bit = 1?
Btw, that sounds weird - why would the #DB exception clear RF just so
that the #DB handler to set it right after... I'm probably missing
something obvious.
> >> • For other cases, the value pushed for RF is the value that was in EFLAG.RF at the time the event handler was
> >> called. This includes:
> >> — Debug exceptions generated in response to instruction breakpoints
> >> — Hardware-generated interrupts arriving between instructions (including those arriving after the last
> >> iteration of a repeated string instruction)
>
> This appears to be why it works on Intel. Does AMD not do that? We
> could probably work around this in software (by not using irq work for
> this), but yuck.
See above.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--
next prev parent reply other threads:[~2015-08-18 8:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-16 22:29 Jiri Olsa
2015-08-17 4:36 ` Borislav Petkov
2015-08-17 7:33 ` Jiri Olsa
2015-08-17 16:06 ` Andy Lutomirski
2015-08-18 8:52 ` Borislav Petkov [this message]
2015-08-18 10:10 ` Jiri Olsa
2015-08-19 3:55 ` Borislav Petkov
2015-08-19 8:55 ` Jiri Olsa
2015-08-19 15:47 ` Borislav Petkov
2015-08-19 15:58 ` Jiri Olsa
2015-08-19 16:12 ` Borislav Petkov
2015-08-21 7:45 ` Jiri Olsa
2015-08-24 22:37 ` sherry hurwitz
2015-12-10 19:26 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150818085211.GA28738@nazgul.tnic \
--to=bp@suse.de \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=hpa@zytor.com \
--cc=jolsa@redhat.com \
--cc=jstancek@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=rric@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®